mpdf.php 1.1 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584
  1. <?php
  2. // ******************************************************************************
  3. // Software: mPDF, Unicode-HTML Free PDF generator *
  4. // Version: 4.6 based on *
  5. // FPDF 1.52 by Olivier PLATHEY *
  6. // UFPDF 0.1 by Steven Wittens *
  7. // HTML2FPDF 3.0.2beta by Renato Coelho *
  8. // Date: 2010-06-07 *
  9. // Author: Ian Back <ianb@bpm1.com> *
  10. // License: GPL *
  11. // *
  12. // Changes: See changelog.txt *
  13. // ******************************************************************************
  14. define('mPDF_VERSION','4.6');
  15. define('AUTOFONT_CJK',1);
  16. define('AUTOFONT_THAIVIET',2);
  17. define('AUTOFONT_RTL',4);
  18. define('AUTOFONT_INDIC',8);
  19. define('AUTOFONT_ALL',15);
  20. define('_BORDER_ALL',15);
  21. define('_BORDER_TOP',8);
  22. define('_BORDER_RIGHT',4);
  23. define('_BORDER_BOTTOM',2);
  24. define('_BORDER_LEFT',1);
  25. if (!defined('_MPDF_PATH')) define('_MPDF_PATH', dirname(preg_replace('/\\\\/','/',__FILE__)) . '/'); // mPDF 4.2 \ to /
  26. require_once(_MPDF_PATH.'includes/functions.php');
  27. require_once(_MPDF_PATH.'config_cp.php');
  28. if (!defined('_JPGRAPH_PATH')) define("_JPGRAPH_PATH", _MPDF_PATH.'jpgraph/');
  29. // Removed by Ivan Tcholakov, 28-JUN-2010.
  30. //if (!defined('_MPDF_TEMP_PATH')) define("_MPDF_TEMP_PATH", _MPDF_PATH.'tmp/'); // mPDF 4.3.007E
  31. //
  32. // Added by Ivan Tcholakov, 28-JUN-2010.
  33. // The directories ".../chamilo/main/inc/lib/mpdf/graph_cache/" and ".../chamilo/main/inc/lib/mpdf/tmp/"
  34. // are moved at new locations ".../chamilo/arcive/mpdf/graph_cache/" and ".../chamilo/arcive/mpdf/tmp/"
  35. // where access for writting is guaranteed.
  36. define('_MPDF_GRAPH_CHACHE_PATH', api_get_path(SYS_ARCHIVE_PATH).'mpdf/graph_cache/');
  37. if (!file_exists(_MPDF_GRAPH_CHACHE_PATH)) {
  38. @mkdir(_MPDF_GRAPH_CHACHE_PATH, api_get_permissions_for_new_directories(), true);
  39. }
  40. define('_MPDF_TEMP_PATH', api_get_path(SYS_ARCHIVE_PATH).'mpdf/tmp/');
  41. if (!file_exists(_MPDF_TEMP_PATH)) {
  42. @mkdir(_MPDF_TEMP_PATH, api_get_permissions_for_new_directories(), true);
  43. }
  44. //
  45. $errorlevel=error_reporting();
  46. $errorlevel=error_reporting($errorlevel & ~E_NOTICE);
  47. //error_reporting(E_ALL);
  48. if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get"))
  49. @date_default_timezone_set(@date_default_timezone_get());
  50. // Disabled by Ivan Tcholakov, 28-JAN-2010.
  51. //if (!function_exists("mb_strlen")) { die("Error - mPDF requires mb_string functions. Ensure that PHP is compiled with php_mbstring.dll enabled."); }
  52. //
  53. class mPDF
  54. {
  55. ///////////////////////////////
  56. // EXTERNAL (PUBLIC) VARIABLES
  57. // Define these in config.php
  58. ///////////////////////////////
  59. var $tableMinSizePriority; // mPDF 4.5.006
  60. var $dpi; // mPDF 4.4.003
  61. var $watermarkImgAlphaBlend; // mPDF 4.4.002
  62. var $watermarkImgBehind; // mPDF 4.3.018
  63. var $justifyB4br; // mPDF 4.3.003
  64. var $packTableData; // mPDF 4.3.009
  65. var $pgsIns; // mPDF 4.2.020
  66. var $PDFA; // mPDF 4.2.018
  67. var $PDFAauto; // mPDF 4.2.018
  68. var $ICCProfile; // mPDF 4.2.018
  69. var $simpleTables; // mPDF 4.2.017
  70. var $enableImports; // mPDF 4.2.006 Adding mPDFI
  71. var $debug;
  72. var $showStats;
  73. var $setAutoTopMargin;
  74. var $setAutoBottomMargin;
  75. var $autoMarginPadding;
  76. // mPDF 4.2
  77. var $collapseBlockMargins;
  78. var $useSubstitutionsMB;
  79. var $falseBoldWeight;
  80. var $normalLineheight;
  81. var $progressBar;
  82. var $incrementFPR1;
  83. var $incrementFPR2;
  84. var $incrementFPR3;
  85. var $incrementFPR4;
  86. var $hyphenate;
  87. var $hyphenateTables;
  88. var $SHYlang;
  89. var $SHYleftmin;
  90. var $SHYrightmin;
  91. var $SHYcharmin;
  92. var $SHYcharmax;
  93. var $SHYlanguages;
  94. // PageNumber Conditional Text
  95. var $pagenumPrefix;
  96. var $pagenumSuffix;
  97. var $nbpgPrefix;
  98. var $nbpgSuffix;
  99. var $showImageErrors;
  100. var $allow_output_buffering;
  101. var $autoPadding;
  102. var $useGraphs;
  103. var $autoFontGroupSize;
  104. var $disableMultilingualJustify;
  105. var $tabSpaces;
  106. var $useLang;
  107. var $restoreBlockPagebreaks;
  108. var $watermarkTextAlpha;
  109. var $watermarkImageAlpha;
  110. var $watermark_size;
  111. var $watermark_pos;
  112. var $annotSize;
  113. var $annotMargin;
  114. var $annotOpacity;
  115. var $title2annots;
  116. var $keepColumns;
  117. var $keep_table_proportions;
  118. var $ignore_table_widths;
  119. var $ignore_table_percents;
  120. var $list_align_style;
  121. var $list_number_suffix;
  122. var $useSubstitutions;
  123. var $CSSselectMedia; // mPDF 4.3.001
  124. // $disablePrintCSS depracated
  125. var $forcePortraitHeaders;
  126. var $forcePortraitMargins;
  127. var $displayDefaultOrientation;
  128. var $ignore_invalid_utf8;
  129. var $allowedCSStags;
  130. var $useOnlyCoreFonts;
  131. var $use_CJK_only;
  132. var $allow_charset_conversion;
  133. var $jSpacing;
  134. var $jSWord;
  135. var $jSmaxChar;
  136. var $jSmaxCharLast;
  137. var $jSmaxWordLast;
  138. var $orphansAllowed;
  139. var $max_colH_correction;
  140. var $table_error_report;
  141. var $table_error_report_param;
  142. var $biDirectional;
  143. var $text_input_as_HTML;
  144. var $anchor2Bookmark;
  145. var $list_indent_first_level;
  146. var $shrink_tables_to_fit;
  147. var $rtlCSS;
  148. var $allow_html_optional_endtags;
  149. var $img_dpi;
  150. var $defaultheaderfontsize;
  151. var $defaultheaderfontstyle;
  152. var $defaultheaderline;
  153. var $defaultfooterfontsize;
  154. var $defaultfooterfontstyle;
  155. var $defaultfooterline;
  156. var $header_line_spacing;
  157. var $footer_line_spacing;
  158. var $textarea_lineheight;
  159. var $pregRTLchars;
  160. var $pregUHCchars;
  161. var $pregSJISchars;
  162. var $pregCJKchars;
  163. var $pregASCIIchars1;
  164. var $pregASCIIchars2;
  165. var $pregASCIIchars3;
  166. var $pregVIETchars;
  167. var $pregVIETPluschars;
  168. var $pregHEBchars;
  169. var $pregARABICchars;
  170. var $pregNonARABICchars;
  171. // INDIC
  172. var $pregHIchars;
  173. var $pregBNchars;
  174. var $pregPAchars;
  175. var $pregGUchars;
  176. var $pregORchars;
  177. var $pregTAchars;
  178. var $pregTEchars;
  179. var $pregKNchars;
  180. var $pregMLchars;
  181. var $pregSHchars;
  182. var $pregINDextra;
  183. var $mirrorMargins;
  184. var $default_lineheight_correction;
  185. var $watermarkText;
  186. var $watermarkImage;
  187. var $showWatermarkText;
  188. var $showWatermarkImage;
  189. var $fontsizes;
  190. // Aliases for backward compatability
  191. var $UnvalidatedText; // alias = $watermarkText
  192. var $TopicIsUnvalidated; // alias = $showWatermarkText
  193. var $use_embeddedfonts_1252; // alias = $useOnlyCoreFonts
  194. var $useOddEven; // alias = $mirrorMargins
  195. //////////////////////
  196. // INTERNAL VARIABLES
  197. //////////////////////
  198. var $watermarkImgAlpha; // mPDF 4.3.018
  199. var $PDFAwarnings; // mPDF 4.2.018
  200. var $MetadataRoot; // mPDF 4.2.018
  201. var $OutputIntentRoot; // mPDF 4.2.018
  202. var $InfoRoot; // mPDF 4.2.018
  203. // mPDF 4.2.006 From mPDFI
  204. var $current_filename;
  205. var $parsers;
  206. var $current_parser;
  207. var $_obj_stack;
  208. var $_don_obj_stack;
  209. var $_current_obj_id;
  210. var $tpls;
  211. var $tpl;
  212. var $tplprefix;
  213. var $_res;
  214. var $pdf_version;
  215. // mPDF 4.2
  216. var $noImageFile;
  217. var $lastblockbottommargin;
  218. var $baselineC;
  219. var $subPos;
  220. var $subArrMB;
  221. var $ReqFontStyle; // mPDF 4.2
  222. var $tableClipPath ; // mPDF 4.2
  223. var $forceExactLineheight; // mPDF 4.2
  224. var $listOcc; // mPDF 4.2
  225. // mPDF 4.1
  226. var $fullImageHeight;
  227. // mPDF 4.0
  228. var $inFixedPosBlock; // Internal flag for position:fixed block
  229. var $fixedPosBlock; // Buffer string for position:fixed block
  230. var $fixedPosBlockDepth;
  231. var $fixedPosBlockBBox;
  232. var $fixedPosBlockSave;
  233. var $maxPosL;
  234. var $maxPosR;
  235. var $loaded;
  236. var $useSubsets;
  237. var $extraFontSubsets;
  238. var $docTemplateStart; // Internal flag for page (page no. -1) that docTemplate starts on
  239. var $time0;
  240. // Classes
  241. var $t1asm;
  242. var $indic;
  243. var $barcode;
  244. var $SHYpatterns;
  245. var $loadedSHYpatterns;
  246. var $loadedSHYdictionary;
  247. var $SHYdictionary;
  248. var $SHYdictionaryWords;
  249. var $spanbgcolorarray;
  250. var $default_font;
  251. var $list_lineheight;
  252. var $headerbuffer;
  253. var $lastblocklevelchange;
  254. var $nestedtablejustfinished;
  255. var $linebreakjustfinished;
  256. var $cell_border_dominance_L;
  257. var $cell_border_dominance_R;
  258. var $cell_border_dominance_T;
  259. var $cell_border_dominance_B;
  260. var $tbCSSlvl;
  261. var $listCSSlvl;
  262. var $table_keep_together;
  263. var $plainCell_properties;
  264. var $inherit_lineheight;
  265. var $listitemtype;
  266. var $shrin_k1;
  267. var $outerfilled;
  268. var $blockContext;
  269. var $floatDivs;
  270. var $tablecascadeCSS;
  271. var $listcascadeCSS;
  272. var $patterns;
  273. var $pageBackgrounds;
  274. var $bodyBackgroundGradient;
  275. var $bodyBackgroundImage;
  276. var $bodyBackgroundColor;
  277. var $writingHTMLheader; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block
  278. var $writingHTMLfooter;
  279. var $autoFontGroups;
  280. var $angle;
  281. var $gradients;
  282. var $kwt_Reference;
  283. var $kwt_BMoutlines;
  284. var $kwt_toc;
  285. var $tbrot_Reference;
  286. var $tbrot_BMoutlines;
  287. var $tbrot_toc;
  288. var $col_Reference;
  289. var $col_BMoutlines;
  290. var $col_toc;
  291. var $currentGraphId;
  292. var $graphs;
  293. var $floatbuffer;
  294. var $floatmargins;
  295. var $bullet;
  296. var $bulletarray;
  297. var $rtlAsArabicFarsi; // DEPRACATED
  298. var $currentLang;
  299. var $default_lang;
  300. var $default_jSpacing;
  301. var $default_available_fonts;
  302. var $default_dir;
  303. var $pageTemplate;
  304. var $docTemplate;
  305. var $docTemplateContinue;
  306. var $arabGlyphs;
  307. var $arabHex;
  308. var $persianGlyphs;
  309. var $persianHex;
  310. var $arabVowels;
  311. var $arabPrevLink;
  312. var $arabNextLink;
  313. var $formobjects; // array of Form Objects for WMF
  314. var $gdiObjectArray; // array of GDI objects for WMF
  315. var $InlineProperties; // Should have done this a long time ago
  316. var $InlineAnnots;
  317. var $ktAnnots;
  318. var $tbrot_Annots;
  319. var $kwt_Annots;
  320. var $columnAnnots;
  321. var $PageAnnots;
  322. var $pageDim; // Keep track of page wxh for orientation changes - set in _beginpage, used in _putannots
  323. var $breakpoints;
  324. var $tableLevel;
  325. var $tbctr;
  326. var $innermostTableLevel;
  327. var $saveTableCounter;
  328. var $cellBorderBuffer;
  329. var $saveHTMLFooter_height;
  330. var $saveHTMLFooterE_height;
  331. var $firstPageBoxHeader;
  332. var $firstPageBoxHeaderEven;
  333. var $firstPageBoxFooter;
  334. var $firstPageBoxFooterEven;
  335. var $page_box;
  336. var $show_marks; // crop or cross marks
  337. var $basepathIsLocal;
  338. var $use_kwt;
  339. var $kwt;
  340. var $kwt_height;
  341. var $kwt_y0;
  342. var $kwt_x0;
  343. var $kwt_buffer;
  344. var $kwt_Links;
  345. var $kwt_moved;
  346. var $kwt_saved;
  347. // NOT USED???
  348. var $formBgColor;
  349. var $formBgColorSmall; // Color used for background of form fields if reduced in size (so border disappears)
  350. var $PageNumSubstitutions;
  351. var $table_borders_separate;
  352. var $base_table_properties;
  353. var $borderstyles;
  354. // doesn't include none or hidden
  355. var $listjustfinished;
  356. var $blockjustfinished;
  357. var $orig_bMargin;
  358. var $orig_tMargin;
  359. var $orig_lMargin;
  360. var $orig_rMargin;
  361. var $orig_hMargin;
  362. var $orig_fMargin;
  363. var $pageheaders;
  364. var $pagefooters;
  365. var $pageHTMLheaders;
  366. var $pageHTMLfooters;
  367. var $saveHTMLHeader;
  368. var $saveHTMLFooter;
  369. var $HTMLheaderPageLinks;
  370. // See config_fonts.php for these next 5 values
  371. var $available_fonts;
  372. var $available_unifonts;
  373. var $sans_fonts;
  374. var $serif_fonts;
  375. var $mono_fonts;
  376. // List of ALL available CJK fonts (incl. styles) (Adobe add-ons) hw removed
  377. var $available_CJK_fonts;
  378. var $cascadeCSS;
  379. var $HTMLHeader;
  380. var $HTMLFooter;
  381. var $HTMLHeaderE; // for Even pages
  382. var $HTMLFooterE; // for Even pages
  383. var $bufferoutput;
  384. var $showdefaultpagenos; // DEPRACATED -left for backward compatability
  385. var $chrs;
  386. var $ords;
  387. // CJK fonts
  388. var $Big5_widths;
  389. var $GB_widths;
  390. var $SJIS_widths;
  391. var $UHC_widths;
  392. // SetProtection
  393. var $encrypted; //whether document is protected
  394. var $Uvalue; //U entry in pdf document
  395. var $Ovalue; //O entry in pdf document
  396. var $Pvalue; //P entry in pdf document
  397. var $enc_obj_id; //encryption object id
  398. var $last_rc4_key; //last RC4 key encrypted (cached for optimisation)
  399. var $last_rc4_key_c; //last RC4 computed key
  400. var $encryption_key;
  401. var $padding; //used for encryption
  402. // Bookmark
  403. var $BMoutlines;
  404. var $OutlineRoot;
  405. // TOC
  406. var $_toc;
  407. var $TOCmark;
  408. var $TOCfont;
  409. var $TOCfontsize;
  410. var $TOCindent;
  411. var $TOCheader;
  412. var $TOCfooter;
  413. var $TOCpreHTML;
  414. var $TOCpostHTML;
  415. var $TOCbookmarkText;
  416. var $TOCusePaging;
  417. var $TOCuseLinking;
  418. var $TOCorientation;
  419. var $TOC_margin_left;
  420. var $TOC_margin_right;
  421. var $TOC_margin_top;
  422. var $TOC_margin_bottom;
  423. var $TOC_margin_header;
  424. var $TOC_margin_footer;
  425. var $TOC_odd_header_name;
  426. var $TOC_even_header_name;
  427. var $TOC_odd_footer_name;
  428. var $TOC_even_footer_name;
  429. var $TOC_odd_header_value;
  430. var $TOC_even_header_value;
  431. var $TOC_odd_footer_value;
  432. var $TOC_even_footer_value;
  433. var $TOC_start;
  434. var $TOC_end;
  435. var $TOC_npages;
  436. var $m_TOC;
  437. // INDEX
  438. var $ColActive;
  439. var $ChangePage; //Flag indicating that a page break has occurred
  440. var $Reference;
  441. var $CurrCol;
  442. var $NbCol;
  443. var $y0; //Top ordinate of columns
  444. var $ColL;
  445. var $ColWidth;
  446. var $ColGap;
  447. // COLUMNS
  448. var $ColR;
  449. var $ChangeColumn;
  450. var $columnbuffer;
  451. var $ColDetails;
  452. var $columnLinks;
  453. var $colvAlign;
  454. // Substitutions
  455. var $substitute; // Array of substitution strings e.g. <ttz>112</ttz>
  456. var $entsearch; // Array of HTML entities (>ASCII 127) to substitute
  457. var $entsubstitute; // Array of substitution decimal unicode for the Hi entities
  458. // Default values if no style sheet offered (cf. http://www.w3.org/TR/CSS21/sample.html)
  459. var $defaultCSS;
  460. var $form_element_spacing;
  461. var $linemaxfontsize;
  462. var $lineheight_correction;
  463. var $lastoptionaltag; // Save current block item which HTML specifies optionsl endtag
  464. var $pageoutput;
  465. var $charset_in;
  466. var $blk;
  467. var $blklvl;
  468. var $ColumnAdjust;
  469. var $ws; // Word spacing
  470. var $HREF;
  471. var $pgwidth;
  472. var $fontlist;
  473. var $issetfont;
  474. var $issetcolor;
  475. var $oldx;
  476. var $oldy;
  477. var $B;
  478. var $U;
  479. var $I;
  480. var $tdbegin;
  481. var $table;
  482. var $cell;
  483. var $col;
  484. var $row;
  485. var $divbegin;
  486. var $divalign;
  487. var $divwidth;
  488. var $divheight;
  489. var $divrevert;
  490. var $spanbgcolor;
  491. var $spanlvl;
  492. var $listlvl;
  493. var $listnum;
  494. var $listtype;
  495. var $listoccur;
  496. var $listlist;
  497. var $listitem;
  498. var $pjustfinished;
  499. var $ignorefollowingspaces;
  500. var $SUP;
  501. var $SUB;
  502. var $SMALL;
  503. var $BIG;
  504. var $toupper;
  505. var $tolower;
  506. var $dash_on;
  507. var $dotted_on;
  508. var $strike;
  509. var $CSS;
  510. var $textbuffer;
  511. var $currentfontstyle;
  512. var $currentfontfamily;
  513. var $currentfontsize;
  514. var $colorarray;
  515. var $bgcolorarray;
  516. var $internallink;
  517. var $enabledtags;
  518. var $lineheight;
  519. var $basepath;
  520. var $outlineparam;
  521. var $outline_on;
  522. var $specialcontent;
  523. var $selectoption;
  524. var $usecss;
  525. var $usepre;
  526. var $usetableheader;
  527. var $tableheadernrows;
  528. var $tablefooternrows; // mPDF 4.0
  529. var $objectbuffer;
  530. // Table Rotation
  531. var $table_rotate;
  532. var $tbrot_maxw;
  533. var $tbrot_maxh;
  534. var $tablebuffer;
  535. var $tbrot_align;
  536. var $tbrot_Links;
  537. var $divbuffer; // Buffer used when keeping DIV on one page
  538. var $keep_block_together; // Keep a Block from page-break-inside: avoid
  539. var $ktLinks; // Keep-together Block links array
  540. var $ktBlock; // Keep-together Block array
  541. var $ktReference;
  542. var $ktBMoutlines;
  543. var $_kttoc;
  544. var $tbrot_y0;
  545. var $tbrot_x0;
  546. var $tbrot_w;
  547. var $tbrot_h;
  548. var $is_MB; // renamed from isunicode
  549. var $codepage;
  550. var $isCJK;
  551. var $mb_enc;
  552. var $directionality;
  553. var $extgstates; // Used for alpha channel - Transparency (Watermark)
  554. var $tt_savefont;
  555. var $mgl;
  556. var $mgt;
  557. var $mgr;
  558. var $mgb;
  559. var $tts;
  560. var $ttz;
  561. var $tta;
  562. var $headerDetails;
  563. var $footerDetails;
  564. // Best to alter the below variables using default stylesheet above
  565. var $div_margin_bottom;
  566. var $div_bottom_border;
  567. var $p_margin_bottom;
  568. var $p_bottom_border;
  569. var $page_break_after_avoid;
  570. var $margin_bottom_collapse;
  571. var $img_margin_top; // default is set at top of fn.openTag 'IMG'
  572. var $img_margin_bottom;
  573. var $list_indent;
  574. var $list_align;
  575. var $list_margin_bottom;
  576. var $default_font_size; // in pts
  577. var $original_default_font_size; // used to save default sizes when using table default
  578. var $original_default_font;
  579. var $watermark_font;
  580. var $defaultAlign;
  581. // TABLE
  582. var $defaultTableAlign;
  583. var $tablethead;
  584. var $thead_font_weight;
  585. var $thead_font_style;
  586. var $thead_valign_default;
  587. var $thead_textalign_default;
  588. var $tabletfoot;
  589. var $tfoot_font_weight;
  590. var $tfoot_font_style;
  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 $diffs; //array of encoding differences
  650. var $images; //array of used images
  651. var $PageLinks; //array of links in pages
  652. var $links; //array of internal links
  653. var $FontFamily; //current font family
  654. var $FontStyle; //current font style
  655. var $underline; //underlining flag
  656. var $CurrentFont; //current font info
  657. var $FontSizePt; //current font size in points
  658. var $FontSize; //current font size in user unit
  659. var $DrawColor; //commands for drawing color
  660. var $FillColor; //commands for filling color
  661. var $TextColor; //commands for text color
  662. var $ColorFlag; //indicates whether fill and text colors are different
  663. var $autoPageBreak; //automatic page breaking
  664. var $PageBreakTrigger; //threshold used to trigger page breaks
  665. var $InFooter; //flag set when processing footer
  666. var $InHTMLFooter;
  667. var $processingFooter; //flag set when processing footer - added for columns
  668. var $processingHeader; //flag set when processing header - added for columns
  669. var $ZoomMode; //zoom display mode
  670. var $LayoutMode; //layout display mode
  671. var $title; //title
  672. var $subject; //subject
  673. var $author; //author
  674. var $keywords; //keywords
  675. var $creator; //creator
  676. var $aliasNbPg; //alias for total number of pages
  677. var $aliasNbPgGp; //alias for total number of pages in page group
  678. var $ispre;
  679. var $outerblocktags;
  680. var $innerblocktags;
  681. // NOT Currently used
  682. var $inlinetags;
  683. var $listtags;
  684. var $tabletags;
  685. var $formtags;
  686. // **********************************
  687. // **********************************
  688. // **********************************
  689. // **********************************
  690. // **********************************
  691. // **********************************
  692. // **********************************
  693. // **********************************
  694. // **********************************
  695. function mPDF($codepage='win-1252',$format='A4',$default_font_size=0,$default_font='',$mgl=15,$mgr=15,$mgt=16,$mgb=16,$mgh=9,$mgf=9, $orientation='P') {
  696. // mPDF 4.0
  697. $this->time0 = microtime(true);
  698. $unit='mm';
  699. if (strlen($codepage)==0) { $codepage='win-1252'; }
  700. //Some checks
  701. $this->_dochecks();
  702. // Set up Aliases for backwards compatability
  703. $this->UnvalidatedText =& $this->watermarkText;
  704. $this->TopicIsUnvalidated =& $this->showWatermarkText;
  705. $this->AliasNbPg =& $this->aliasNbPg;
  706. $this->AliasNbPgGp =& $this->aliasNbPgGp;
  707. $this->BiDirectional =& $this->biDirectional;
  708. $this->Anchor2Bookmark =& $this->anchor2Bookmark;
  709. $this->KeepColumns =& $this->keepColumns;
  710. $this->use_embeddedfonts_1252 =& $this->useOnlyCoreFonts;
  711. $this->useOddEven =& $this->mirrorMargins;
  712. //Initialization of properties
  713. $this->page=0;
  714. $this->n=2;
  715. $this->buffer='';
  716. $this->objectbuffer = array();
  717. $this->pages=array();
  718. $this->OrientationChanges=array();
  719. $this->state=0;
  720. $this->fonts=array();
  721. $this->FontFiles=array();
  722. $this->diffs=array();
  723. $this->images=array();
  724. $this->links=array();
  725. $this->InFooter=false;
  726. $this->processingFooter=false;
  727. $this->processingHeader=false;
  728. $this->lasth=0;
  729. $this->FontFamily='';
  730. $this->FontStyle='';
  731. $this->FontSizePt=9;
  732. $this->underline=false;
  733. $this->DrawColor='0 G';
  734. $this->FillColor='0 g';
  735. $this->TextColor='0 g';
  736. $this->ColorFlag=false;
  737. $this->extgstates = array();
  738. $this->is_MB=false; // renamed from isunicode
  739. $this->isCJK = false;
  740. $this->mb_enc='windows-1252';
  741. $this->directionality='ltr';
  742. $this->defaultAlign = 'L';
  743. $this->defaultTableAlign = 'L';
  744. // mPDF 4.0
  745. $this->fixedPosBlockSave = array();
  746. $this->useSubsets = false;
  747. $this->extraFontSubsets = 0;
  748. $this->loaded = array();
  749. $this->SHYpatterns = array();
  750. $this->loadedSHYdictionary = false;
  751. $this->SHYdictionary = array();
  752. $this->SHYdictionaryWords = array();
  753. $this->blockContext = 1;
  754. $this->floatDivs = array();
  755. $this->DisplayPreferences='';
  756. $this->tablecascadeCSS = array();
  757. $this->listcascadeCSS = array();
  758. $this->patterns = array(); // Tiling patterns used for backgrounds
  759. $this->pageBackgrounds = array();
  760. $this->writingHTMLheader = false; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block
  761. $this->writingHTMLfooter = false; // internal flag - used both for writing HTMLHeaders/Footers and FixedPos block
  762. $this->gradients = array();
  763. $this->kwt_Reference = array();
  764. $this->kwt_BMoutlines = array();
  765. $this->kwt_toc = array();
  766. $this->tbrot_Reference = array();
  767. $this->tbrot_BMoutlines = array();
  768. $this->tbrot_toc = array();
  769. $this->col_Reference = array();
  770. $this->col_BMoutlines = array();
  771. $this->col_toc = array();
  772. $this->graphs = array();
  773. $this->pgsIns = array(); // mPDF 4.2.020
  774. $this->PDFAwarnings = array(); // mPDF 4.2.018
  775. // mPDF 4.2
  776. $this->baselineC = 0.35; // Baseline for text
  777. $this->noImageFile = str_replace("\\","/",dirname(__FILE__)) . '/includes/no_image.jpg';
  778. $this->subPos = 0;
  779. $this->forceExactLineheight = false;
  780. $this->listOcc = 0;
  781. $this->normalLineheight = 1.3;
  782. // These are intended as configuration variables, and should be set in config.php - which will override these values;
  783. // set here as failsafe as will cause an error if not defined
  784. $this->incrementFPR1 = 10;
  785. $this->incrementFPR2 = 10;
  786. $this->incrementFPR3 = 10;
  787. $this->incrementFPR4 = 10;
  788. // mPDF 4.1
  789. $this->fullImageHeight = false;
  790. $this->floatbuffer = array();
  791. $this->floatmargins = array();
  792. $this->autoFontGroups = 0;
  793. $this->formobjects=array(); // array of Form Objects for WMF
  794. $this->InlineProperties=array();
  795. $this->InlineAnnots=array();
  796. $this->ktAnnots=array();
  797. $this->tbrot_Annots=array();
  798. $this->kwt_Annots=array();
  799. $this->columnAnnots=array();
  800. $this->pageDim=array();
  801. $this->breakpoints = array(); // used in columnbuffer
  802. $this->tableLevel=0;
  803. $this->tbctr=array(); // counter for nested tables at each level
  804. $this->page_box = array();
  805. $this->show_marks = ''; // crop or cross marks
  806. $this->kwt = false;
  807. $this->kwt_height = 0;
  808. $this->kwt_y0 = 0;
  809. $this->kwt_x0 = 0;
  810. $this->kwt_buffer = array();
  811. $this->kwt_Links = array();
  812. $this->kwt_moved = false;
  813. $this->kwt_saved = false;
  814. $this->PageNumSubstitutions = array();
  815. $this->base_table_properties=array();
  816. $this->borderstyles = array('inset','groove','outset','ridge','dotted','dashed','solid','double');
  817. $this->tbrot_align = 'C';
  818. $this->pageheaders=array();
  819. $this->pagefooters=array();
  820. $this->pageHTMLheaders=array();
  821. $this->pageHTMLfooters=array();
  822. $this->HTMLheaderPageLinks = array();
  823. /*-- CJK --*/
  824. $this->available_CJK_fonts = array(
  825. 'gb','big5','sjis','uhc',
  826. 'gbB','big5B','sjisB','uhcB',
  827. 'gbI','big5I','sjisI','uhcI',
  828. 'gbBI','big5BI','sjisBI','uhcBI',
  829. );
  830. /*-- END CJK --*/
  831. $this->cascadeCSS = array();
  832. $this->bufferoutput = false;
  833. $this->encrypted=false; //whether document is protected
  834. $this->BMoutlines=array();
  835. $this->_toc=array();
  836. $this->TOCheader=false;
  837. $this->TOCfooter=false;
  838. $this->ColActive=0; //Flag indicating that columns are on (the index is being processed)
  839. $this->ChangePage=0; //Flag indicating that a page break has occurred
  840. $this->Reference=array(); //Array containing the references
  841. $this->CurrCol=0; //Current column number
  842. $this->ColL = array(0); // Array of Left pos of columns - absolute - needs Margin correction for Odd-Even
  843. $this->ColR = array(0); // Array of Right pos of columns - absolute pos - needs Margin correction for Odd-Even
  844. $this->ChangeColumn = 0;
  845. $this->columnbuffer = array();
  846. $this->ColDetails = array(); // Keeps track of some column details
  847. $this->columnLinks = array(); // Cross references PageLinks
  848. $this->substitute = array(); // Array of substitution strings e.g. <ttz>112</ttz>
  849. $this->entsearch = array(); // Array of HTML entities (>ASCII 127) to substitute
  850. $this->entsubstitute = array(); // Array of substitution decimal unicode for the Hi entities
  851. $this->lastoptionaltag = '';
  852. $this->charset_in = '';
  853. $this->blk = array();
  854. $this->blklvl = 0;
  855. $this->TOCmark = 0;
  856. $this->tts = false;
  857. $this->ttz = false;
  858. $this->tta = false;
  859. $this->ispre=false;
  860. $this->headerDetails=array();
  861. $this->footerDetails=array();
  862. $this->div_bottom_border = '';
  863. $this->p_bottom_border = '';
  864. $this->page_break_after_avoid = false;
  865. $this->margin_bottom_collapse = false;
  866. $this->tablethead = 0;
  867. $this->tabletfoot = 0;
  868. $this->table_border_attr_set = 0;
  869. $this->table_border_css_set = 0;
  870. $this->shrin_k = 1.0;
  871. $this->shrink_this_table_to_fit = 0;
  872. $this->MarginCorrection = 0;
  873. $this->tabletheadjustfinished = false;
  874. $this->usingCoreFont = false;
  875. $this->charspacing=0;
  876. $this->outlines=array();
  877. $this->autoPageBreak = true;
  878. /*-- FORMS --*/
  879. // FORM ELEMENT SPACING
  880. $this->form_element_spacing['select']['outer']['h'] = 0.5; // Horizontal spacing around SELECT
  881. $this->form_element_spacing['select']['outer']['v'] = 0.5; // Vertical spacing around SELECT
  882. $this->form_element_spacing['select']['inner']['h'] = 0.7; // Horizontal padding around SELECT
  883. $this->form_element_spacing['select']['inner']['v'] = 0.7; // Vertical padding around SELECT
  884. $this->form_element_spacing['input']['outer']['h'] = 0.5;
  885. $this->form_element_spacing['input']['outer']['v'] = 0.5;
  886. $this->form_element_spacing['input']['inner']['h'] = 0.7;
  887. $this->form_element_spacing['input']['inner']['v'] = 0.7;
  888. $this->form_element_spacing['textarea']['outer']['h'] = 0.5;
  889. $this->form_element_spacing['textarea']['outer']['v'] = 0.5;
  890. $this->form_element_spacing['textarea']['inner']['h'] = 1;
  891. $this->form_element_spacing['textarea']['inner']['v'] = 0.5;
  892. $this->form_element_spacing['button']['outer']['h'] = 0.5;
  893. $this->form_element_spacing['button']['outer']['v'] = 0.5;
  894. $this->form_element_spacing['button']['inner']['h'] = 2;
  895. $this->form_element_spacing['button']['inner']['v'] = 1;
  896. /*-- END FORMS --*/
  897. require(_MPDF_PATH.'config.php'); // config data
  898. //Scale factor
  899. $this->k=72/25.4; // Will only use mm
  900. $this->_setPageSize($format, $orientation); // mPDF 4.2.024
  901. $this->DefOrientation=$orientation;
  902. $this->margin_header=$mgh;
  903. $this->margin_footer=$mgf;
  904. $bmargin=$mgb;
  905. $this->DeflMargin = $mgl;
  906. $this->DefrMargin = $mgr;
  907. // v1.4 Save orginal settings in case of changed orientation
  908. $this->orig_tMargin = $mgt;
  909. $this->orig_bMargin = $bmargin;
  910. $this->orig_lMargin = $this->DeflMargin;
  911. $this->orig_rMargin = $this->DefrMargin;
  912. $this->orig_hMargin = $this->margin_header;
  913. $this->orig_fMargin = $this->margin_footer;
  914. // mPDF 4.0
  915. if ($this->setAutoTopMargin=='pad') { $mgt += $this->margin_header; }
  916. if ($this->setAutoBottomMargin=='pad') { $mgb += $this->margin_footer; }
  917. $this->SetMargins($this->DeflMargin,$this->DefrMargin,$mgt); // sets l r t margin
  918. //Automatic page break
  919. $this->SetAutoPageBreak($this->autoPageBreak,$bmargin); // sets $this->bMargin & PageBreakTrigger
  920. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  921. //Interior cell margin (1 mm) ? not used
  922. $this->cMarginL = 1;
  923. $this->cMarginR = 1;
  924. //Line width (0.2 mm)
  925. $this->LineWidth=.567/$this->k;
  926. //To make the function Footer() work - replaces {nb} with page number
  927. $this->AliasNbPages();
  928. $this->AliasNbPageGroups();
  929. //Enable all tags as default
  930. $this->DisableTags();
  931. //Full width display mode
  932. $this->SetDisplayMode(100); // fullwidth? 'fullpage'
  933. //Compression
  934. $this->SetCompression(true);
  935. //Set default display preferences
  936. $this->SetDisplayPreferences(''); // mPDF 3.0
  937. // mPDF 4.0
  938. if (substr($codepage,-2)=='-s') {
  939. $codepage = substr($codepage,0,(strlen($codepage)-2));
  940. $useSubsets = true;
  941. }
  942. require(_MPDF_PATH.'config_fonts.php'); // font data
  943. //Standard fonts
  944. $this->CoreFonts=array('courier'=>'Courier','courierB'=>'Courier-Bold','courierI'=>'Courier-Oblique','courierBI'=>'Courier-BoldOblique',
  945. 'helvetica'=>'Helvetica','helveticaB'=>'Helvetica-Bold','helveticaI'=>'Helvetica-Oblique','helveticaBI'=>'Helvetica-BoldOblique',
  946. 'times'=>'Times-Roman','timesB'=>'Times-Bold','timesI'=>'Times-Italic','timesBI'=>'Times-BoldItalic',
  947. 'symbol'=>'Symbol','zapfdingbats'=>'ZapfDingbats');
  948. $this->fontlist=array("times","courier","helvetica","symbol","zapfdingbats");
  949. switch(strtolower($codepage)){
  950. case 'utf-8': $codepage='UTF-8';break;
  951. case 'big5': case 'big-5': $codepage='BIG5';break;
  952. case 'gbk': case 'cp936': $codepage='GBK';break;
  953. case 'uhc': case 'cp949': $codepage='UHC';break;
  954. case 'shift_jis': case 'shift-jis': case 'sjis': $codepage='SHIFT_JIS';break;
  955. case 'win-1251': case 'windows-1251': case 'cp1251': $codepage='win-1251';break;
  956. case 'win-1252': case 'windows-1252': case 'cp1252': $codepage='win-1252';break;
  957. case 'iso-8859-2': $codepage='iso-8859-2';break;
  958. case 'iso-8859-4': $codepage='iso-8859-4';break;
  959. case 'iso-8859-7': $codepage='iso-8859-7';break;
  960. case 'iso-8859-9': $codepage='iso-8859-9';break;
  961. }
  962. $this->default_available_fonts = $this->available_unifonts;
  963. // Autodetect IF codepage is a language_country string (en-GB or en_GB or en)
  964. if ((strlen($codepage) == 5 && $codepage != 'UTF-8') || strlen($codepage) == 2) {
  965. // in HTMLToolkit
  966. list ($codepage,$mpdf_pdf_unifonts,$mpdf_directionality,$mpdf_jSpacing) = GetCodepage($codepage);
  967. $this->jSpacing = $mpdf_jSpacing;
  968. if (($codepage != 'BIG5') && ($codepage != 'GBK') && ($codepage != 'UHC') && ($codepage != 'SHIFT_JIS')) {
  969. if ($mpdf_pdf_unifonts) {
  970. $this->RestrictUnicodeFonts($mpdf_pdf_unifonts);
  971. $this->default_available_fonts = $mpdf_pdf_unifonts;
  972. }
  973. }
  974. $this->SetDirectionality($mpdf_directionality);
  975. $this->currentLang = $codepage;
  976. $this->default_lang = $codepage;
  977. $this->default_jSpacing = $mpdf_jSpacing;
  978. $this->default_dir = $mpdf_directionality;
  979. }
  980. // mPDF 4.0 TEMPORARY FIX to disable win-1251 dejavu fonts
  981. if ($codepage=='win-1251') {
  982. foreach($this->available_fonts AS $k=>$v) {
  983. if (substr($v,0,6)=='dejavu') { unset($this->available_fonts[$k]); }
  984. }
  985. }
  986. $this->codepage = $codepage;
  987. // mPDF 4.0
  988. if ($useSubsets && $codepage=='UTF-8') {
  989. $this->useSubsets = true;
  990. }
  991. if ($codepage == 'UTF-8') { $this->is_MB = true; }
  992. /*-- CJK --*/
  993. if ($codepage == 'BIG5' || $codepage == 'GBK' || $codepage == 'UHC' || $codepage == 'SHIFT_JIS') {
  994. $this->isCJK = true;
  995. require(_MPDF_PATH . 'includes/CJKdata.php');
  996. // FONTS
  997. if ($codepage == 'BIG5') { $this->AddCJKFont('big5'); $default_font = 'big5';}
  998. else if ($codepage == 'GBK') { $this->AddCJKFont('gb'); $default_font = 'gb'; }
  999. else if ($codepage == 'SHIFT_JIS') { $this->AddCJKFont('sjis'); $default_font = 'sjis'; }
  1000. else if ($codepage == 'UHC') { $this->AddCJKFont('uhc'); $default_font = 'uhc';}
  1001. $this->is_MB = true;
  1002. $this->use_CJK_only = true;
  1003. }
  1004. /*-- END CJK --*/
  1005. // mPDF 4.2.018
  1006. if (($codepage=='win-1252' || $codepage=='win-1251' || $codepage=='iso-8859-2' || $codepage=='iso-8859-4' || $codepage=='iso-8859-7' || $codepage=='iso-8859-9' || $codepage == 'BIG5' || $codepage == 'GBK' || $codepage == 'UHC' || $codepage == 'SHIFT_JIS') && !$this->PDFA) {
  1007. $this->useSubstitutions = true;
  1008. $this->SetSubstitutions();
  1009. }
  1010. else { $this->useSubstitutions = false; }
  1011. if (!defined('MPDF_FONTPATH')) {
  1012. if ($this->is_MB) { define('MPDF_FONTPATH',_MPDF_PATH.'unifont/'); }
  1013. else { define('MPDF_FONTPATH',_MPDF_PATH.'font/'); }
  1014. }
  1015. if (file_exists(_MPDF_PATH.'mpdf.css')) {
  1016. $css = file_get_contents(_MPDF_PATH.'mpdf.css');
  1017. $css2 = $this->ReadDefaultCSS($css);
  1018. $this->defaultCSS = $this->array_merge_recursive_unique($this->defaultCSS,$css2);
  1019. }
  1020. if ($default_font=='') {
  1021. if ($codepage == 'win-1252') {
  1022. if (in_array(strtolower($this->defaultCSS['BODY']['FONT-FAMILY']),$this->mono_fonts)) { $default_font = 'courier'; }
  1023. else if (in_array(strtolower($this->defaultCSS['BODY']['FONT-FAMILY']),$this->sans_fonts)) { $default_font = 'helvetica'; }
  1024. else { $default_font = 'times'; }
  1025. }
  1026. else { $default_font = $this->defaultCSS['BODY']['FONT-FAMILY']; }
  1027. }
  1028. if (!$default_font_size) {
  1029. $mmsize = $this->ConvertSize($this->defaultCSS['BODY']['FONT-SIZE']);
  1030. $default_font_size = $mmsize*($this->k);
  1031. }
  1032. if ($default_font) { $this->SetDefaultFont($default_font); }
  1033. if ($default_font_size) { $this->SetDefaultFontSize($default_font_size); }
  1034. $this->setMBencoding($this->codepage); // sets $this->mb_enc
  1035. // Modified by Ivan Tcholakov, 28-JAN-2010.
  1036. //@mb_regex_encoding('UTF-8');
  1037. _api_mb_regex_encoding('UTF-8');
  1038. //
  1039. $this->setHiEntitySubstitutions();
  1040. $this->SetLineHeight(); // lineheight is in mm
  1041. $this->SetFillColor(255);
  1042. $this->HREF='';
  1043. $this->oldy=-1;
  1044. $this->B=0;
  1045. $this->U=0;
  1046. $this->I=0;
  1047. $this->listlvl=0;
  1048. $this->listnum=0;
  1049. $this->listtype='';
  1050. $this->listoccur=array();
  1051. $this->listlist=array();
  1052. $this->listitem=array();
  1053. $this->tdbegin=false;
  1054. $this->table=array();
  1055. $this->cell=array();
  1056. $this->col=-1;
  1057. $this->row=-1;
  1058. $this->cellBorderBuffer = array();
  1059. $this->divbegin=false;
  1060. $this->divalign=$this->defaultAlign;
  1061. $this->divwidth=0;
  1062. $this->divheight=0;
  1063. $this->spanbgcolor=false;
  1064. $this->divrevert=false;
  1065. $this->issetfont=false;
  1066. $this->issetcolor=false;
  1067. $this->blockjustfinished=false;
  1068. $this->listjustfinished=false;
  1069. $this->ignorefollowingspaces = true; //in order to eliminate exceeding left-side spaces
  1070. $this->toupper=false;
  1071. $this->tolower=false;
  1072. $this->dash_on=false;
  1073. $this->dotted_on=false;
  1074. $this->SUP=false;
  1075. $this->SUB=false;
  1076. $this->strike=false;
  1077. $this->currentfontfamily='';
  1078. $this->currentfontsize='';
  1079. $this->currentfontstyle='';
  1080. $this->colorarray=array();
  1081. $this->spanbgcolorarray=array();
  1082. $this->textbuffer=array();
  1083. $this->CSS=array();
  1084. $this->internallink=array();
  1085. $this->basepath = "";
  1086. $this->SetBasePath('');
  1087. $this->outlineparam = array();
  1088. $this->outline_on = false;
  1089. $this->specialcontent = '';
  1090. $this->selectoption = array();
  1091. $this->usetableheader=false;
  1092. $this->usecss=true;
  1093. $this->usepre=true;
  1094. for($i=0;$i<256;$i++) {
  1095. $this->chrs[$i] = chr($i);
  1096. $this->ords[chr($i)] = $i;
  1097. }
  1098. /*-- IMPORTS --*/
  1099. // mPDF 4.2.006
  1100. $this->tpls = array();
  1101. $this->tpl = 0;
  1102. $this->tplprefix = "/TPL";
  1103. $this->res = array();
  1104. if ($this->enableImports) {
  1105. $this->SetImportUse();
  1106. }
  1107. /*-- END IMPORTS --*/
  1108. if ($this->progressBar) { $this->StartProgressBarOutput($this->progressBar) ; } // *PROGRESS-BAR*
  1109. }
  1110. // mPDF 4.2.024
  1111. function _setPageSize($format, &$orientation) {
  1112. //Page format
  1113. if(is_string($format))
  1114. {
  1115. if ($format=='') { $format = 'A4'; }
  1116. $pfo = 'P'; // mPDF 4.2.025
  1117. if(preg_match('/([0-9a-zA-Z]*)-L/i',$format,$m)) { // e.g. A4-L = A$ landscape
  1118. $format=$m[1];
  1119. $pfo='L'; // mPDF 4.2.025
  1120. }
  1121. $format = $this->_getPageFormat($format);
  1122. if (!$format) { $this->Error('Unknown page format: '.$format); }
  1123. else { $orientation = $pfo; } // mPDF 4.2.025
  1124. $this->fwPt=$format[0];
  1125. $this->fhPt=$format[1];
  1126. }
  1127. else
  1128. {
  1129. if (!$format[0] || !$format[1]) { $this->Error('Invalid page format: '.$format[0].' '.$format[1]); }
  1130. $this->fwPt=$format[0]*$this->k;
  1131. $this->fhPt=$format[1]*$this->k;
  1132. }
  1133. $this->fw=$this->fwPt/$this->k;
  1134. $this->fh=$this->fhPt/$this->k;
  1135. //Page orientation
  1136. $orientation=strtolower($orientation);
  1137. if($orientation=='p' or $orientation=='portrait')
  1138. {
  1139. $orientation='P';
  1140. $this->wPt=$this->fwPt;
  1141. $this->hPt=$this->fhPt;
  1142. }
  1143. elseif($orientation=='l' or $orientation=='landscape')
  1144. {
  1145. $orientation='L';
  1146. $this->wPt=$this->fhPt;
  1147. $this->hPt=$this->fwPt;
  1148. }
  1149. else $this->Error('Incorrect orientation: '.$orientation);
  1150. $this->CurOrientation=$orientation;
  1151. $this->w=$this->wPt/$this->k;
  1152. $this->h=$this->hPt/$this->k;
  1153. }
  1154. // mPDF 4.2.024
  1155. function _getPageFormat($format) {
  1156. switch (strtoupper($format)) {
  1157. case '4A0': {$format = array(4767.87,6740.79); break;}
  1158. case '2A0': {$format = array(3370.39,4767.87); break;}
  1159. case 'A0': {$format = array(2383.94,3370.39); break;}
  1160. case 'A1': {$format = array(1683.78,2383.94); break;}
  1161. case 'A2': {$format = array(1190.55,1683.78); break;}
  1162. case 'A3': {$format = array(841.89,1190.55); break;}
  1163. case 'A4': default: {$format = array(595.28,841.89); break;}
  1164. case 'A5': {$format = array(419.53,595.28); break;}
  1165. case 'A6': {$format = array(297.64,419.53); break;}
  1166. case 'A7': {$format = array(209.76,297.64); break;}
  1167. case 'A8': {$format = array(147.40,209.76); break;}
  1168. case 'A9': {$format = array(104.88,147.40); break;}
  1169. case 'A10': {$format = array(73.70,104.88); break;}
  1170. case 'B0': {$format = array(2834.65,4008.19); break;}
  1171. case 'B1': {$format = array(2004.09,2834.65); break;}
  1172. case 'B2': {$format = array(1417.32,2004.09); break;}
  1173. case 'B3': {$format = array(1000.63,1417.32); break;}
  1174. case 'B4': {$format = array(708.66,1000.63); break;}
  1175. case 'B5': {$format = array(498.90,708.66); break;}
  1176. case 'B6': {$format = array(354.33,498.90); break;}
  1177. case 'B7': {$format = array(249.45,354.33); break;}
  1178. case 'B8': {$format = array(175.75,249.45); break;}
  1179. case 'B9': {$format = array(124.72,175.75); break;}
  1180. case 'B10': {$format = array(87.87,124.72); break;}
  1181. case 'C0': {$format = array(2599.37,3676.54); break;}
  1182. case 'C1': {$format = array(1836.85,2599.37); break;}
  1183. case 'C2': {$format = array(1298.27,1836.85); break;}
  1184. case 'C3': {$format = array(918.43,1298.27); break;}
  1185. case 'C4': {$format = array(649.13,918.43); break;}
  1186. case 'C5': {$format = array(459.21,649.13); break;}
  1187. case 'C6': {$format = array(323.15,459.21); break;}
  1188. case 'C7': {$format = array(229.61,323.15); break;}
  1189. case 'C8': {$format = array(161.57,229.61); break;}
  1190. case 'C9': {$format = array(113.39,161.57); break;}
  1191. case 'C10': {$format = array(79.37,113.39); break;}
  1192. case 'RA0': {$format = array(2437.80,3458.27); break;}
  1193. case 'RA1': {$format = array(1729.13,2437.80); break;}
  1194. case 'RA2': {$format = array(1218.90,1729.13); break;}
  1195. case 'RA3': {$format = array(864.57,1218.90); break;}
  1196. case 'RA4': {$format = array(609.45,864.57); break;}
  1197. case 'SRA0': {$format = array(2551.18,3628.35); break;}
  1198. case 'SRA1': {$format = array(1814.17,2551.18); break;}
  1199. case 'SRA2': {$format = array(1275.59,1814.17); break;}
  1200. case 'SRA3': {$format = array(907.09,1275.59); break;}
  1201. case 'SRA4': {$format = array(637.80,907.09); break;}
  1202. case 'LETTER': {$format = array(612.00,792.00); break;}
  1203. case 'LEGAL': {$format = array(612.00,1008.00); break;}
  1204. case 'EXECUTIVE': {$format = array(521.86,756.00); break;}
  1205. case 'FOLIO': {$format = array(612.00,936.00); break;}
  1206. case 'B': {$format=array(362.83,561.26 ); break;} // 'B' format paperback size 128x198mm
  1207. case 'A': {$format=array(314.65,504.57 ); break;} // 'A' format paperback size 111x178mm
  1208. case 'DEMY': {$format=array(382.68,612.28 ); break;} // 'Demy' format paperback size 135x216mm
  1209. case 'ROYAL': {$format=array(433.70,663.30 ); break;} // 'Royal' format paperback size 153x234mm
  1210. default: $format = false;
  1211. }
  1212. return $format;
  1213. }
  1214. /*-- PROGRESS-BAR --*/
  1215. function StartProgressBarOutput($mode=1) {
  1216. // must be relative path, or URI (not a file system path)
  1217. if (!defined('_MPDF_URI')) {
  1218. $this->progressBar = false;
  1219. if ($this->debug) { $this->Error("You need to define _MPDF_URI to use the progress bar!"); }
  1220. else return false;
  1221. }
  1222. $this->progressBar = $mode;
  1223. echo '<html>
  1224. <head>
  1225. <title>mPDF File Progress</title>
  1226. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  1227. <style type="text/css">
  1228. img { padding: 0px; margin: 0px; border: none;}
  1229. body {
  1230. margin : 0 auto;
  1231. width:100%;
  1232. font-family: \'Verdana\';
  1233. color: #40454b;
  1234. font-size: 12px;
  1235. text-align:center;
  1236. }
  1237. table {
  1238. font-family: \'Verdana\';
  1239. color: #40454b;
  1240. font-size: 12px;
  1241. }
  1242. body h1 {
  1243. font-size:14px;
  1244. font-weight:bold;
  1245. color:#CC0000;
  1246. padding:5px;
  1247. margin-left:10px;
  1248. border-bottom:solid;
  1249. border-bottom-width:1px;
  1250. border-bottom-color:#333333;
  1251. }
  1252. .demo {
  1253. margin : 0 auto;
  1254. width:100%;
  1255. margin:20px;
  1256. }
  1257. td {
  1258. vertical-align: top;
  1259. padding: 0 0.5em 0 0;
  1260. }
  1261. .code {
  1262. font-family: "Courier New", Courier, monospace;
  1263. font-size: 10px;
  1264. }
  1265. .code2 {
  1266. font-family: "Courier New", Courier, monospace;
  1267. font-size: 11px; font-weight: bold; color: red;
  1268. }
  1269. </style>
  1270. </head>
  1271. <body>
  1272. <div style="width:540px; margin: 0 auto; text-align:left;" >
  1273. <h1>mPDF file progress</h1>
  1274. <div class="demo">
  1275. ';
  1276. if ($this->progressBar==2) { echo ' <table width="100%"><tr><td style="width: 50%;">
  1277. <span style="color:#006600;font-weight:bold;">Writing HTML code</span> <br/>
  1278. <span class="progressBar" id="element1">0%</span> <span class="code2" id="box11"></span><br />
  1279. <span class="code" id="box1"></span>
  1280. </td><td style="width: 50%;">
  1281. <span style="color:#006600;font-weight:bold;">Autosizing elements</span> <br/>
  1282. <span class="progressBar" id="element4">0%</span><br />
  1283. <span class="code" id="box4"></span>
  1284. <br/><br/>
  1285. <span style="color:#006600;font-weight:bold;">Writing Tables</span> <br/>
  1286. <span class="progressBar" id="element7">0%</span><br />
  1287. <span class="code" id="box7"></span>
  1288. </td></tr>
  1289. <tr><td><br /><br /></td><td></td></tr>
  1290. <tr><td style="width: 50%;">
  1291. '; }
  1292. echo ' <span style="color:#006600;font-weight:bold;">Writing PDF file</span> <br/>
  1293. <span class="progressBar" id="element2">0%</span><br />
  1294. <span class="code" id="box2"></span>
  1295. ';
  1296. if ($this->progressBar==2) { echo '
  1297. </td><td style="width: 50%;">
  1298. <span style="color:#006600;font-weight:bold;">Memory usage</span> <br/>
  1299. <span class="progressBar" id="element5">0%</span> '.ini_get("memory_limit").'<br />
  1300. <span class="code" id="box5"></span>
  1301. <br/><br/>
  1302. <span style="color:#006600;font-weight:bold;">Memory usage (peak)</span> <br/>
  1303. <span class="progressBar" id="element6">0%</span> '.ini_get("memory_limit").'<br />
  1304. <span class="code" id="box6"></span>
  1305. </td></tr>
  1306. </table>
  1307. '; }
  1308. // mPDF 4.2.007
  1309. echo ' <br/><br/>
  1310. <span style="font-weight: bold; " id="box3"></span>
  1311. </div>
  1312. <script type="text/javascript" src="'._MPDF_URI.'progress/prototype.js.php"></script>
  1313. <script type="text/javascript">';
  1314. include(_MPDF_PATH.'progress/jsProgressBarHandler.js.php');
  1315. echo '</script>';
  1316. ob_flush();
  1317. flush();
  1318. }
  1319. function UpdateProgressBar($el,$val,$txt='') {
  1320. // $val should be a string - 5 = actual value, +15 = increment
  1321. if ($this->progressBar<2) {
  1322. if ($el>3) { return; }
  1323. else if ($el ==1) { $el = 2; }
  1324. }
  1325. echo '<script type="text/javascript">';
  1326. if ($val) { echo ' myJsProgressBarHandler.setPercentage(\'element'.$el.'\',\''.$val.'\'); '; }
  1327. if ($txt) { echo ' document.getElementById(\'box'.$el.'\').innerHTML=\''.$txt.'\'; '; }
  1328. if ($this->progressBar==2) {
  1329. $m = round(memory_get_usage()/1048576);
  1330. $mem = $m * 100 / (ini_get("memory_limit")+0);
  1331. $m2 = round(memory_get_peak_usage()/1048576);
  1332. $mem2 = $m2 * 100 / (ini_get("memory_limit")+0);
  1333. echo ' myJsProgressBarHandler.setPercentage(\'element5\',\''.$mem.'\'); ';
  1334. echo ' document.getElementById(\'box5\').innerHTML=\''.$m.' MB\'; ';
  1335. echo ' myJsProgressBarHandler.setPercentage(\'element6\',\''.$mem2.'\'); ';
  1336. echo ' document.getElementById(\'box6\').innerHTML=\''.$m2.' MB\'; ';
  1337. }
  1338. echo '</script>'."\n";
  1339. ob_flush();
  1340. flush();
  1341. }
  1342. /*-- END PROGRESS-BAR --*/
  1343. function RestrictUnicodeFonts($res) {
  1344. // $res = array of (Unicode) fonts to restrict to: e.g. norasi|norasiB - language specific
  1345. if (count($res)) { // Leave full list of available fonts if passed blank array
  1346. $this->available_unifonts = $res;
  1347. }
  1348. else { $this->available_unifonts = $this->default_available_fonts; }
  1349. if (count($this->available_unifonts) == 0) { $this->available_unifonts[] = $this->default_available_fonts[0]; }
  1350. $this->available_unifonts = array_values($this->available_unifonts);
  1351. }
  1352. function setMBencoding($enc) {
  1353. // only call mb_internal_encoding if need to change
  1354. $curr = $this->mb_enc;
  1355. // Sets encoding string for use in mb_string functions
  1356. if ($enc == 'win-1252') { $this->mb_enc = 'windows-1252'; }
  1357. else if ($enc == 'win-1251') { $this->mb_enc = 'windows-1251'; }
  1358. else if ($enc == 'UTF-8') { $this->mb_enc = 'UTF-8'; }
  1359. else if ($enc == 'BIG5') { $this->mb_enc = 'UTF-8'; }
  1360. else if ($enc == 'GBK') { $this->mb_enc = 'UTF-8'; } // cp936
  1361. else if ($enc == 'SHIFT_JIS') { $this->mb_enc = 'UTF-8'; }
  1362. else if ($enc == 'UHC') { $this->mb_enc = 'UTF-8'; } // cp949
  1363. else { $this->mb_enc = $enc; } // works for iso-8859-n
  1364. if ($this->mb_enc && $curr != $this->mb_enc) {
  1365. // Modified by Ivan Tcholakov, 28-JAN-2010.
  1366. //mb_internal_encoding($this->mb_enc);
  1367. _api_mb_internal_encoding($this->mb_enc);
  1368. //
  1369. }
  1370. }
  1371. function getMBencoding() {
  1372. return $this->mb_enc;
  1373. }
  1374. function SetMargins($left,$right,$top) {
  1375. //Set left, top and right margins
  1376. $this->lMargin=$left;
  1377. $this->rMargin=$right;
  1378. $this->tMargin=$top;
  1379. }
  1380. function ResetMargins() {
  1381. //ReSet left, top margins
  1382. if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P' && $this->CurOrientation=='L') {
  1383. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  1384. $this->tMargin=$this->orig_rMargin;
  1385. $this->bMargin=$this->orig_lMargin;
  1386. }
  1387. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS
  1388. $this->tMargin=$this->orig_lMargin;
  1389. $this->bMargin=$this->orig_rMargin;
  1390. }
  1391. $this->lMargin=$this->DeflMargin;
  1392. $this->rMargin=$this->DefrMargin;
  1393. $this->MarginCorrection = 0;
  1394. $this->PageBreakTrigger=$this->h-$this->bMargin;
  1395. }
  1396. else if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  1397. $this->lMargin=$this->DefrMargin;
  1398. $this->rMargin=$this->DeflMargin;
  1399. $this->MarginCorrection = $this->DefrMargin-$this->DeflMargin;
  1400. }
  1401. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS
  1402. $this->lMargin=$this->DeflMargin;
  1403. $this->rMargin=$this->DefrMargin;
  1404. if ($this->mirrorMargins) { $this->MarginCorrection = $this->DeflMargin-$this->DefrMargin; }
  1405. }
  1406. $this->x=$this->lMargin;
  1407. }
  1408. function SetLeftMargin($margin) {
  1409. //Set left margin
  1410. $this->lMargin=$margin;
  1411. if($this->page>0 and $this->x<$margin) $this->x=$margin;
  1412. }
  1413. function SetTopMargin($margin) {
  1414. //Set top margin
  1415. $this->tMargin=$margin;
  1416. }
  1417. function SetRightMargin($margin) {
  1418. //Set right margin
  1419. $this->rMargin=$margin;
  1420. }
  1421. function SetAutoPageBreak($auto,$margin=0) {
  1422. //Set auto page break mode and triggering margin
  1423. $this->autoPageBreak=$auto;
  1424. $this->bMargin=$margin;
  1425. $this->PageBreakTrigger=$this->h-$margin;
  1426. }
  1427. function SetDisplayMode($zoom,$layout='continuous') {
  1428. //Set display mode in viewer
  1429. if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom))
  1430. $this->ZoomMode=$zoom;
  1431. else
  1432. $this->Error('Incorrect zoom display mode: '.$zoom);
  1433. if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default')
  1434. $this->LayoutMode=$layout;
  1435. else
  1436. $this->Error('Incorrect layout display mode: '.$layout);
  1437. }
  1438. function SetCompression($compress) {
  1439. //Set page compression
  1440. if(function_exists('gzcompress')) $this->compress=$compress;
  1441. else $this->compress=false;
  1442. }
  1443. function SetTitle($title) {
  1444. //Title of document // Arrives as UTF-8
  1445. $this->title = $title;
  1446. }
  1447. function SetSubject($subject) {
  1448. //Subject of document
  1449. $this->subject= $subject;
  1450. }
  1451. function SetAuthor($author) {
  1452. //Author of document
  1453. $this->author= $author;
  1454. }
  1455. function SetKeywords($keywords) {
  1456. //Keywords of document
  1457. $this->keywords= $keywords;
  1458. }
  1459. function SetCreator($creator) {
  1460. //Creator of document
  1461. $this->creator= $creator;
  1462. }
  1463. function SetAnchor2Bookmark($x) {
  1464. $this->anchor2Bookmark = $x;
  1465. }
  1466. function AliasNbPages($alias='{nb}') {
  1467. //Define an alias for total number of pages
  1468. $this->aliasNbPg=$alias;
  1469. }
  1470. function AliasNbPageGroups($alias='{nbpg}') {
  1471. //Define an alias for total number of pages in a group
  1472. $this->aliasNbPgGp=$alias;
  1473. }
  1474. function SetAlpha($alpha, $bm='Normal', $return=false) { // mPDF 4.3.017
  1475. // alpha: real value from 0 (transparent) to 1 (opaque)
  1476. // bm: blend mode, one of the following:
  1477. // Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn,
  1478. // HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
  1479. // set alpha for stroking (CA) and non-stroking (ca) operations
  1480. // mPDF 4.2.018
  1481. if ($this->PDFA && $alpha!=1) {
  1482. if (!$this->PDFAauto) { $this->PDFAwarnings[] = "Image opacity must be 100% (Opacity changed to 100%)"; }
  1483. $alpha = 1;
  1484. }
  1485. $gs = $this->AddExtGState(array('ca'=>$alpha, 'CA'=>$alpha, 'BM'=>'/'.$bm));
  1486. if ($return) { return sprintf('/GS%d gs', $gs); } // mPDF 4.3.017
  1487. else { $this->_out(sprintf('/GS%d gs', $gs)); }
  1488. }
  1489. function AddExtGState($parms) {
  1490. $n = count($this->extgstates);
  1491. // check if graphics state already exists
  1492. for ($i=1; $i<=$n; $i++) {
  1493. if ($this->extgstates[$i]['parms']['ca']==$parms['ca'] && $this->extgstates[$i]['parms']['CA']==$parms['CA'] && $this->extgstates[$i]['parms']['BM']==$parms['BM']) {
  1494. return $i;
  1495. }
  1496. }
  1497. $n++;
  1498. $this->extgstates[$n]['parms'] = $parms;
  1499. return $n;
  1500. }
  1501. function Error($msg) {
  1502. //Fatal error
  1503. header('Content-Type: text/html; charset=utf-8');
  1504. die('<B>mPDF error: </B>'.$msg);
  1505. }
  1506. function Open() {
  1507. //Begin document
  1508. if($this->state==0) $this->_begindoc();
  1509. }
  1510. function Close() {
  1511. if ($this->progressBar) { $this->UpdateProgressBar(2,'2','Closing last page'); } // *PROGRESS-BAR*
  1512. //Terminate document
  1513. if($this->state==3) return;
  1514. if($this->page==0) $this->AddPage($this->CurOrientation);
  1515. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); } // *TABLES*
  1516. if (count($this->tablebuffer)) { $this->printtablebuffer(); } // *TABLES*
  1517. /*-- COLUMNS --*/
  1518. // mPDF 4.0
  1519. if ($this->ColActive) {
  1520. $this->SetColumns(0);
  1521. $this->ColActive = 0;
  1522. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  1523. }
  1524. /*-- END COLUMNS --*/
  1525. if (count($this->divbuffer)) { $this->printdivbuffer(); }
  1526. // BODY Backgrounds
  1527. $s = '';
  1528. $bby = $this->h;
  1529. $bbw = $this->w;
  1530. $bbh = $this->h;
  1531. if ($this->bodyBackgroundColor) {
  1532. $s .= sprintf('%.3f %.3f %.3f rg',$this->bodyBackgroundColor['R']/255,$this->bodyBackgroundColor['G']/255,$this->bodyBackgroundColor['B']/255)."\n";
  1533. $s .= sprintf('%.3f %.3f %.3f %.3f re f',0,$bby*$this->k,$bbw*$this->k,-$bbh*$this->k)."\n";
  1534. }
  1535. /*-- GRADIENTS --*/
  1536. if ($this->bodyBackgroundGradient) {
  1537. $g = $this->parseBackgroundGradient($this->bodyBackgroundGradient);
  1538. if ($g) {
  1539. // mPDF 4.2 direct output, else overwrites background-image
  1540. //$this->pageBackgrounds[0][] = array('gradient'=>true, 'x'=>0, 'y'=>0, 'w'=>$this->w, 'h'=>$this->h, 'gradtype'=>$g['type'], 'col'=>$g['col'], 'col2'=>$g['col2'], 'coords'=>$g['coords'], 'extend'=>$g['extend']);
  1541. $s .= $this->Gradient(0, 0, $this->w, $this->h, $g['gradtype'], $g['col'], $g['col2'], $g['coords'], $g['extend'], true);
  1542. }
  1543. }
  1544. /*-- END GRADIENTS --*/
  1545. /*-- BACKGROUND-IMAGES --*/
  1546. if ($this->bodyBackgroundImage) {
  1547. if ($this->bodyBackgroundImage['image_id']) { // Background pattern
  1548. $n = count($this->patterns)+1;
  1549. // mPDF 4.3.015
  1550. list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($this->bodyBackgroundImage['orig_w'], $this->bodyBackgroundImage['orig_h'], $bbw, $bbh, $this->bodyBackgroundImage['resize'], $this->bodyBackgroundImage['x_repeat'], $this->bodyBackgroundImage['y_repeat']);
  1551. // mPDF 3.1 $bbx = 0, 'y'=>0
  1552. $this->patterns[$n] = array('x'=>0, 'y'=>0, 'w'=>$bbw, 'h'=>$bbh, '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); // mPDF 4.3.015
  1553. // mPDF 4.3.017
  1554. if ($this->bodyBackgroundImage['opacity']>0 && $this->bodyBackgroundImage['opacity']<1) { $opac = $this->SetAlpha($this->bodyBackgroundImage['opacity'],'Normal',true); }
  1555. else { $opac = ''; }
  1556. $s .= sprintf('q /Pattern cs /P%d scn %s %.3f %.3f %.3f %.3f re f Q', $n, $opac, 0,$bby*$this->k,$bbw*$this->k,-$bbh*$this->k) ."\n";
  1557. }
  1558. }
  1559. /*-- END BACKGROUND-IMAGES --*/
  1560. $s .= $this->PrintPageBackgrounds();
  1561. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->pages[$this->page]);
  1562. $this->pageBackgrounds = array();
  1563. if (!$this->TOCmark) { //Page footer
  1564. $this->InFooter=true;
  1565. $this->Footer();
  1566. $this->InFooter=false;
  1567. }
  1568. if ($this->TOCmark || count($this->m_TOC)) { $this->insertTOC(); } // *TOC*
  1569. //Close page
  1570. $this->_endpage();
  1571. //Close document
  1572. $this->_enddoc();
  1573. }
  1574. // mPDF 4.3.015
  1575. function _resizeBackgroundImage($imw, $imh, $cw, $ch, $resize=0, $repx, $repy) {
  1576. $cw = $cw*$this->k;
  1577. $ch = $ch*$this->k;
  1578. if (!$resize) { return array($imw, $imh, $repx, $repy); }
  1579. if ($resize==1 && $imw > $cw) {
  1580. $h = $imh * $cw/$imw;
  1581. $repx = false;
  1582. return array($cw, $h, $repx, $repy);
  1583. }
  1584. else if ($resize==2 && $imh > $ch) {
  1585. $w = $imw * $ch/$imh;
  1586. $repy = false;
  1587. return array($w, $ch, $repx, $repy);
  1588. }
  1589. else if ($resize==3) {
  1590. $w = $imw;
  1591. $h = $imh;
  1592. $saverepx = $repx;
  1593. if ($w > $cw) {
  1594. $h = $h * $cw/$w;
  1595. $w = $cw;
  1596. $repx = false;
  1597. }
  1598. if ($h > $ch) {
  1599. $w = $w * $ch/$h;
  1600. $h = $ch;
  1601. $repy = false;
  1602. $repx = $saverepx;
  1603. }
  1604. return array($w, $h, $repx, $repy);
  1605. }
  1606. else if ($resize==4) {
  1607. $h = $imh * $cw/$imw;
  1608. $repx = false;
  1609. return array($cw, $h, $repx, $repy);
  1610. }
  1611. else if ($resize==5) {
  1612. $w = $imw * $ch/$imh;
  1613. $repy = false;
  1614. return array($w, $ch, $repx, $repy);
  1615. }
  1616. else if ($resize==6) {
  1617. $repx = false;
  1618. $repy = false;
  1619. return array($cw, $ch, $repx, $repy);
  1620. }
  1621. return array($imw, $imh, $repx, $repy);
  1622. }
  1623. function PrintPageBackgrounds($adjustmenty=0) { // mPDF 4.2.014 Adjustment added for HTMLFooters
  1624. $s = '';
  1625. ksort($this->pageBackgrounds);
  1626. foreach($this->pageBackgrounds AS $bl=>$pbs) {
  1627. foreach ($pbs AS $pb) {
  1628. if (!isset($pb['image_id']) && !isset($pb['gradient'])) { // Background colour
  1629. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1630. $s .= sprintf('%.3f %.3f %.3f rg',$pb['col']['R']/255,$pb['col']['G']/255,$pb['col']['B']/255)."\n";
  1631. $s .= sprintf('%.3f %.3f %.3f %.3f re f',$pb['x']*$this->k,($this->h-$pb['y'])*$this->k,$pb['w']*$this->k,-$pb['h']*$this->k)."\n";
  1632. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1633. }
  1634. }
  1635. /*-- GRADIENTS --*/
  1636. foreach ($pbs AS $pb) {
  1637. if (isset($pb['gradient']) && $pb['gradient']) {
  1638. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1639. $s .= $this->Gradient($pb['x'], $pb['y'], $pb['w'], $pb['h'], $pb['gradtype'], $pb['col'], $pb['col2'], $pb['coords'], $pb['extend'], true);
  1640. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1641. }
  1642. }
  1643. /*-- END GRADIENTS --*/
  1644. /*-- BACKGROUND-IMAGES --*/
  1645. foreach ($pbs AS $pb) {
  1646. if (isset($pb['image_id']) && $pb['image_id']) { // Background pattern
  1647. $pb['y'] -= $adjustmenty; // mPDF 4.2.014
  1648. $pb['h'] += $adjustmenty; // mPDF 4.2.014
  1649. $n = count($this->patterns)+1;
  1650. // mPDF 4.3.015
  1651. 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']);
  1652. $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); // mPDF 4.3.015
  1653. $x = $pb['x']*$this->k;
  1654. $y = ($this->h - $pb['y'])*$this->k;
  1655. $w = $pb['w']*$this->k;
  1656. $h = -$pb['h']*$this->k;
  1657. if (isset($pb['clippath']) && $pb['clippath']) { $s .= $pb['clippath']."\n"; }
  1658. // mPDF 4.0
  1659. if ($this->writingHTMLfooter || $this->writingHTMLheader) {
  1660. $iw = $pb['orig_w']/$this->k;
  1661. $ih = $pb['orig_h']/$this->k;
  1662. $w = $pb['w'];
  1663. $h = $pb['h'];
  1664. $x0 = $pb['x'];
  1665. $y0 = $pb['y'];
  1666. // Number to repeat
  1667. if ($pb['x_repeat']) { $nx = ceil($w/$iw); }
  1668. else { $nx = 1; }
  1669. if ($pb['y_repeat']) { $ny = ceil($h/$ih); }
  1670. else { $ny = 1; }
  1671. $x_pos = $pb['x_pos'];
  1672. if (stristr($x_pos ,'%') ) {
  1673. $x_pos += 0;
  1674. $x_pos /= 100;
  1675. $x_pos = ($w * $x_pos) - ($iw * $x_pos);
  1676. }
  1677. $y_pos = $pb['y_pos'];
  1678. if (stristr($y_pos ,'%') ) {
  1679. $y_pos += 0;
  1680. $y_pos /= 100;
  1681. $y_pos = ($h * $y_pos) - ($ih * $y_pos);
  1682. }
  1683. if ($nx>1) {
  1684. while($x_pos>0) { $x_pos -= $iw; }
  1685. }
  1686. if ($ny>1) {
  1687. while($y_pos>0) { $y_pos -= $ih; }
  1688. }
  1689. for($xi=0;$xi<$nx;$xi++) {
  1690. for($yi=0;$yi<$ny;$yi++) {
  1691. $x = $x0 + $x_pos + ($iw*$xi);
  1692. $y = $y0 + $y_pos + ($ih*$yi);
  1693. // mPDF 4.3.017
  1694. if ($pb['opacity']>0 && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); }
  1695. else { $opac = ''; }
  1696. $s .= sprintf("q %s %.3f 0 0 %.3f %.3f %.3f cm /I%d Do Q", $opac,$iw*$this->k,$ih*$this->k,$x*$this->k,($this->h-($y+$ih))*$this->k,$pb['image_id']) ."\n";
  1697. }
  1698. }
  1699. }
  1700. else {
  1701. // mPDF 4.3.017
  1702. if ($pb['opacity']>0 && $pb['opacity']<1) { $opac = $this->SetAlpha($pb['opacity'],'Normal',true); }
  1703. else { $opac = ''; }
  1704. $s .= sprintf('q /Pattern cs /P%d scn %s %.3f %.3f %.3f %.3f re f Q', $n, $opac, $x, $y, $w, $h) ."\n";
  1705. }
  1706. if (isset($pb['clippath']) && $pb['clippath']) { $s .= 'Q'."\n"; }
  1707. }
  1708. }
  1709. /*-- END BACKGROUND-IMAGES --*/
  1710. }
  1711. return $s;
  1712. }
  1713. // Depracated - can use AddPage for all
  1714. 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='')
  1715. {
  1716. $this->AddPage($orientation,$condition,$resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf, $ohname, $ehname, $ofname, $efname, $ohvalue, $ehvalue, $ofvalue, $efvalue,$pagesel,$newformat='');
  1717. }
  1718. // mPDF 4.2 Added $pagesel, $newformat [4.2.024]
  1719. 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='')
  1720. {
  1721. /*-- CSS-FLOAT --*/
  1722. // Float DIV
  1723. // Cannot do with columns on, or if any change in page orientation/margins etc.
  1724. // If next page already exists - i.e background /headers and footers already written
  1725. if ($this->state > 0 && $this->page < count($this->pages)) {
  1726. $bak_cml = $this->cMarginL;
  1727. $bak_cmr = $this->cMarginR;
  1728. $bak_dw = $this->divwidth;
  1729. // Paint Div Border if necessary
  1730. if ($this->blklvl > 0) {
  1731. $save_tr = $this->table_rotate; // *TABLES*
  1732. $this->table_rotate = 0; // *TABLES*
  1733. if ($this->y == $this->blk[$this->blklvl]['y0']) { $this->blk[$this->blklvl]['startpage']++; }
  1734. if (($this->y > $this->blk[$this->blklvl]['y0']) || $this->flowingBlockAttr['is_table'] ) { $toplvl = $this->blklvl; }
  1735. else { $toplvl = $this->blklvl-1; }
  1736. $sy = $this->y;
  1737. for ($bl=1;$bl<=$toplvl;$bl++) {
  1738. $this->PaintDivBB('pagebottom',0,$bl);
  1739. }
  1740. $this->y = $sy;
  1741. $this->table_rotate = $save_tr; // *TABLES*
  1742. }
  1743. $s = $this->PrintPageBackgrounds();
  1744. // Writes after the marker so not overwritten later by page background etc.
  1745. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  1746. $this->pageBackgrounds = array();
  1747. $family=$this->FontFamily;
  1748. $style=$this->FontStyle.($this->underline ? 'U' : '');
  1749. $size=$this->FontSizePt;
  1750. $lw=$this->LineWidth;
  1751. $dc=$this->DrawColor;
  1752. $fc=$this->FillColor;
  1753. $tc=$this->TextColor;
  1754. $cf=$this->ColorFlag;
  1755. $this->printfloatbuffer();
  1756. //Move to next page
  1757. $this->page++;
  1758. $this->ResetMargins();
  1759. $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin);
  1760. $this->x=$this->lMargin;
  1761. $this->y=$this->tMargin;
  1762. $this->FontFamily='';
  1763. $this->_out('2 J');
  1764. $this->LineWidth=$lw;
  1765. $this->_out(sprintf('%.3f w',$lw*$this->k));
  1766. if($family) $this->SetFont($family,$style,$size,true,true);
  1767. $this->DrawColor=$dc;
  1768. if($dc!='0 G') $this->_out($dc);
  1769. $this->FillColor=$fc;
  1770. if($fc!='0 g') $this->_out($fc);
  1771. $this->TextColor=$tc;
  1772. $this->ColorFlag=$cf;
  1773. for($bl=1;$bl<=$this->blklvl;$bl++) {
  1774. $this->blk[$bl]['y0'] = $this->y;
  1775. // Don't correct more than once for background DIV containing a Float
  1776. if (!isset($this->blk[$bl]['marginCorrected'][$this->page])) { $this->blk[$bl]['x0'] += $this->MarginCorrection; }
  1777. $this->blk[$bl]['marginCorrected'][$this->page] = true;
  1778. }
  1779. $this->cMarginL = $bak_cml;
  1780. $this->cMarginR = $bak_cmr;
  1781. $this->divwidth = $bak_dw;
  1782. return '';
  1783. }
  1784. /*-- END CSS-FLOAT --*/
  1785. //Start a new page
  1786. if($this->state==0) $this->Open();
  1787. // mPDF 3.0 - Moved here from WriteFlowingBlock, FinishFlowingBlock and printbuffer
  1788. $bak_cml = $this->cMarginL;
  1789. $bak_cmr = $this->cMarginR;
  1790. $bak_dw = $this->divwidth;
  1791. // mPDF 4.2
  1792. $bak_lh = $this->lineheight;
  1793. $orientation = substr(strtoupper($orientation),0,1);
  1794. $condition = strtoupper($condition);
  1795. // mPDF 4.2
  1796. if ($condition == 'NEXT-EVEN') { // always adds at least one new page to create an Even page
  1797. if (!$this->mirrorMargins) { $condition = ''; }
  1798. else {
  1799. if ($pagesel) { $pbch = $pagesel; $pagesel = ''; } // *CSS-PAGE*
  1800. else { $pbch = false; } // *CSS-PAGE*
  1801. $this->AddPage($this->CurOrientation,'O');
  1802. if ($pbch ) { $pagesel = $pbch; } // *CSS-PAGE*
  1803. $condition = '';
  1804. }
  1805. }
  1806. if ($condition == 'NEXT-ODD') { // always adds at least one new page to create an Odd page
  1807. if (!$this->mirrorMargins) { $condition = ''; }
  1808. else {
  1809. if ($pagesel) { $pbch = $pagesel; $pagesel = ''; } // *CSS-PAGE*
  1810. else { $pbch = false; } // *CSS-PAGE*
  1811. $this->AddPage($this->CurOrientation,'E');
  1812. if ($pbch ) { $pagesel = $pbch; } // *CSS-PAGE*
  1813. $condition = '';
  1814. }
  1815. }
  1816. if ($condition == 'E') { // only adds new page if needed to create an Even page
  1817. if (!$this->mirrorMargins || ($this->page)%2==0) { return false; }
  1818. }
  1819. if ($condition == 'O') { // only adds new page if needed to create an Odd page
  1820. if (!$this->mirrorMargins || ($this->page)%2==1) { return false; }
  1821. }
  1822. if ($resetpagenum || $pagenumstyle || $suppress) {
  1823. $this->PageNumSubstitutions[] = array('from'=>($this->page+1), 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=>$suppress);
  1824. }
  1825. // mPDF 4.0
  1826. $save_tr = $this->table_rotate; // *TABLES*
  1827. $this->table_rotate = 0; // *TABLES*
  1828. $save_kwt = $this->kwt;
  1829. $this->kwt = 0;
  1830. // Paint Div Border if necessary
  1831. //PAINTS BACKGROUND COLOUR OR BORDERS for DIV - DISABLED FOR COLUMNS (cf. AcceptPageBreak) AT PRESENT in ->PaintDivBB
  1832. if (!$this->ColActive && $this->blklvl > 0) {
  1833. if (isset($this->blk[$this->blklvl]['y0']) && $this->y == $this->blk[$this->blklvl]['y0']) {
  1834. if (isset($this->blk[$this->blklvl]['startpage'])) { $this->blk[$this->blklvl]['startpage']++; }
  1835. else { $this->blk[$this->blklvl]['startpage'] = 1; }
  1836. }
  1837. if ((isset($this->blk[$this->blklvl]['y0']) && $this->y > $this->blk[$this->blklvl]['y0']) || $this->flowingBlockAttr['is_table'] ) { $toplvl = $this->blklvl; }
  1838. else { $toplvl = $this->blklvl-1; }
  1839. $sy = $this->y;
  1840. for ($bl=1;$bl<=$toplvl;$bl++) {
  1841. $this->PaintDivBB('pagebottom',0,$bl);
  1842. }
  1843. $this->y = $sy;
  1844. // RESET block y0 and x0 - see below
  1845. }
  1846. // BODY Backgrounds
  1847. if ($this->page > 0) {
  1848. $s = '';
  1849. $bby = $this->h;
  1850. $bbw = $this->w;
  1851. $bbh = $this->h;
  1852. if ($this->bodyBackgroundColor) {
  1853. $s .= sprintf('%.3f %.3f %.3f rg',$this->bodyBackgroundColor['R']/255,$this->bodyBackgroundColor['G']/255,$this->bodyBackgroundColor['B']/255)."\n";
  1854. $s .= sprintf('%.3f %.3f %.3f %.3f re f',0,$bby*$this->k,$bbw*$this->k,-$bbh*$this->k)."\n";
  1855. }
  1856. /*-- GRADIENTS --*/
  1857. if ($this->bodyBackgroundGradient) {
  1858. $g = $this->parseBackgroundGradient($this->bodyBackgroundGradient);
  1859. if ($g) {
  1860. // mPDF 4.2 direct output, else overwrites background-image
  1861. // $this->pageBackgrounds[0][] = array('gradient'=>true, 'x'=>0, 'y'=>0, 'w'=>$this->w, 'h'=>$this->h, 'gradtype'=>$g['type'], 'col'=>$g['col'], 'col2'=>$g['col2'], 'coords'=>$g['coords'], 'extend'=>$g['extend']);
  1862. $s .= $this->Gradient(0, 0, $this->w, $this->h, $g['gradtype'], $g['col'], $g['col2'], $g['coords'], $g['extend'], true);
  1863. }
  1864. }
  1865. /*-- END GRADIENTS --*/
  1866. /*-- BACKGROUND-IMAGES --*/
  1867. if ($this->bodyBackgroundImage) {
  1868. if ($this->bodyBackgroundImage['image_id']) { // Background pattern
  1869. $n = count($this->patterns)+1;
  1870. // mPDF 4.3.015
  1871. list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($this->bodyBackgroundImage['orig_w'], $this->bodyBackgroundImage['orig_h'], $bbw, $bbh, $this->bodyBackgroundImage['resize'],$this->bodyBackgroundImage['x_repeat'],$this->bodyBackgroundImage['y_repeat']);
  1872. // mPDF 3.1 'y'=>0
  1873. $this->patterns[$n] = array('x'=>0, 'y'=>0, 'w'=>$bbw, 'h'=>$bbh, '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); // mPDF 4.3.015
  1874. // mPDF 4.3.017
  1875. if ($this->bodyBackgroundImage['opacity']>0 && $this->bodyBackgroundImage['opacity']<1) { $opac = $this->SetAlpha($this->bodyBackgroundImage['opacity'],'Normal',true); }
  1876. else { $opac = ''; }
  1877. $s .= sprintf('q /Pattern cs /P%d scn %s %.3f %.3f %.3f %.3f re f Q', $n, $opac, 0,$bby*$this->k,$bbw*$this->k,-$bbh*$this->k) ."\n";
  1878. }
  1879. }
  1880. /*-- END BACKGROUND-IMAGES --*/
  1881. $s .= $this->PrintPageBackgrounds();
  1882. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->pages[$this->page]);
  1883. $this->pageBackgrounds = array();
  1884. }
  1885. $save_cols = false;
  1886. /*-- COLUMNS --*/
  1887. if ($this->ColActive) {
  1888. $save_cols = true;
  1889. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  1890. $this->SetColumns(0);
  1891. }
  1892. /*-- END COLUMNS --*/
  1893. $family=$this->FontFamily;
  1894. $style=$this->FontStyle.($this->underline ? 'U' : '');
  1895. $size=$this->FontSizePt;
  1896. $this->ColumnAdjust = true; // enables column height adjustment for the page
  1897. $lw=$this->LineWidth;
  1898. $dc=$this->DrawColor;
  1899. $fc=$this->FillColor;
  1900. $tc=$this->TextColor;
  1901. $cf=$this->ColorFlag;
  1902. if($this->page>0)
  1903. {
  1904. //Page footer
  1905. $this->InFooter=true;
  1906. // mPDF 3.0
  1907. $this->Reset();
  1908. $this->pageoutput[$this->page] = array();
  1909. $this->Footer();
  1910. //Close page
  1911. $this->_endpage();
  1912. }
  1913. //Start new page
  1914. // mPDF 4.2 pagesel,$newformat 4.2.024
  1915. $this->_beginpage($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat);
  1916. // mPDF 4.2 Moved here from Header() - so it goes before ___BACKGROUND___PATTERNS marker
  1917. if ($this->docTemplate) {
  1918. $pagecount = $this->SetSourceFile($this->docTemplate);
  1919. if (($this->page - $this->docTemplateStart) > $pagecount) {
  1920. if ($this->docTemplateContinue) {
  1921. $tplIdx = $this->ImportPage($pagecount);
  1922. $this->UseTemplate($tplIdx);
  1923. }
  1924. }
  1925. else {
  1926. $tplIdx = $this->ImportPage(($this->page - $this->docTemplateStart));
  1927. $this->UseTemplate($tplIdx);
  1928. }
  1929. }
  1930. if ($this->pageTemplate) {
  1931. $this->UseTemplate($this->pageTemplate);
  1932. }
  1933. // Tiling Patterns // Moved here mPDF 4.0
  1934. $this->_out('___BACKGROUND___PATTERNS'.date('jY'));
  1935. $this->pageBackgrounds = array();
  1936. //Set line cap style to square
  1937. $this->_out('2 J');
  1938. //Set line width
  1939. $this->LineWidth=$lw;
  1940. $this->_out(sprintf('%.3f w',$lw*$this->k));
  1941. //Set font
  1942. if($family) $this->SetFont($family,$style,$size,true,true); // forces write
  1943. //Set colors
  1944. $this->DrawColor=$dc;
  1945. if($dc!='0 G') $this->_out($dc);
  1946. $this->FillColor=$fc;
  1947. if($fc!='0 g') $this->_out($fc);
  1948. $this->TextColor=$tc;
  1949. $this->ColorFlag=$cf;
  1950. //Page header
  1951. $this->Header();
  1952. //Restore line width
  1953. if($this->LineWidth!=$lw)
  1954. {
  1955. $this->LineWidth=$lw;
  1956. $this->_out(sprintf('%.3f w',$lw*$this->k));
  1957. }
  1958. //Restore font
  1959. if($family) $this->SetFont($family,$style,$size,true,true); // forces write
  1960. //Restore colors
  1961. if($this->DrawColor!=$dc)
  1962. {
  1963. $this->DrawColor=$dc;
  1964. $this->_out($dc);
  1965. }
  1966. if($this->FillColor!=$fc)
  1967. {
  1968. $this->FillColor=$fc;
  1969. $this->_out($fc);
  1970. }
  1971. $this->TextColor=$tc;
  1972. $this->ColorFlag=$cf;
  1973. $this->InFooter=false;
  1974. /*-- COLUMNS --*/
  1975. if ($save_cols) {
  1976. // Restore columns
  1977. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  1978. }
  1979. if ($this->ColActive) { $this->SetCol(0); }
  1980. /*-- END COLUMNS --*/
  1981. //RESET BLOCK BORDER TOP
  1982. if (!$this->ColActive) {
  1983. for($bl=1;$bl<=$this->blklvl;$bl++) {
  1984. $this->blk[$bl]['y0'] = $this->y;
  1985. if (isset($this->blk[$bl]['x0'])) { $this->blk[$bl]['x0'] += $this->MarginCorrection; }
  1986. else { $this->blk[$bl]['x0'] = $this->MarginCorrection; }
  1987. // Added mPDF 3.0 Float DIV
  1988. $this->blk[$bl]['marginCorrected'][$this->page] = true;
  1989. }
  1990. }
  1991. // mPDF 4.0
  1992. $this->table_rotate = $save_tr; // *TABLES*
  1993. $this->kwt = $save_kwt;
  1994. $this->cMarginL = $bak_cml;
  1995. $this->cMarginR = $bak_cmr;
  1996. $this->divwidth = $bak_dw;
  1997. // mPDF 4.2
  1998. $this->lineheight = $bak_lh;
  1999. }
  2000. function PageNo() {
  2001. //Get current page number
  2002. return $this->page;
  2003. }
  2004. function SetDrawColor($r,$g=-1,$b=-1,$col4=-1) {
  2005. //Set color for all stroking operations
  2006. if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) $this->DrawColor=sprintf('%.3f G',$r/255);
  2007. else if ($col4 == -1) $this->DrawColor=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255);
  2008. else {
  2009. // CMYK
  2010. // mPDF 4.2.018
  2011. if ($this->PDFA) { $this->Error("PDFA1-b does not permit CMYK colours (fn. SetDrawColor)."); }
  2012. $this->DrawColor = sprintf('%.3f %.3f %.3f %.3f K', $r/100, $g/100, $b/100, $col4/100);
  2013. }
  2014. 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); }
  2015. $this->pageoutput[$this->page]['DrawColor'] = $this->DrawColor;
  2016. }
  2017. function SetFillColor($r,$g=-1,$b=-1,$col4=-1) {
  2018. //Set color for all filling operations
  2019. if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) $this->FillColor=sprintf('%.3f g',$r/255);
  2020. else if ($col4 == -1) $this->FillColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
  2021. else {
  2022. // CMYK
  2023. // mPDF 4.2.018
  2024. if ($this->PDFA) { $this->Error("PDFA1-b does not permit CMYK colours (fn. SetFillColor)."); }
  2025. $this->FillColor = sprintf('%.3f %.3f %.3f %.3f k', $r/100, $g/100, $b/100, $col4/100);
  2026. }
  2027. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2028. 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); }
  2029. $this->pageoutput[$this->page]['FillColor'] = $this->FillColor;
  2030. }
  2031. function SetTextColor($r,$g=-1,$b=-1,$col4=-1) {
  2032. //Set color for text
  2033. if(($r==0 and $g==0 and $b==0 && $col4 == -1) or $g==-1) $this->TextColor=sprintf('%.3f g',$r/255);
  2034. else if ($col4 == -1) $this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
  2035. else {
  2036. // CMYK
  2037. // mPDF 4.2.018
  2038. if ($this->PDFA) { $this->Error("PDFA1-b does not permit CMYK colours (fn. SetTextColor)."); }
  2039. $this->TextColor = sprintf('%.3f %.3f %.3f %.3f k', $r/100, $g/100, $b/100, $col4/100);
  2040. }
  2041. $this->ColorFlag = ($this->FillColor != $this->TextColor);
  2042. }
  2043. function GetStringWidth($s) {
  2044. //Get width of a string in the current font
  2045. $s = (string)$s;
  2046. $cw = &$this->CurrentFont['cw'];
  2047. $w = 0;
  2048. /*-- UNICODE-FONTS --*/
  2049. if ($this->is_MB && !$this->usingCoreFont) {
  2050. $unicode = $this->UTF8StringToArray($s);
  2051. foreach($unicode as $char) {
  2052. if ($char == 173) { continue; } // Soft Hyphens
  2053. elseif (isset($cw[$char])) { $w+=$cw[$char]; }
  2054. elseif(isset($this->chrs[$char]) && isset($cw[$this->chrs[$char]])) { $w+=$cw[$this->chrs[$char]]; }
  2055. elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; }
  2056. elseif(isset($this->CurrentFont['MissingWidth'])) { $w += $this->CurrentFont['MissingWidth']; }
  2057. else { $w += 500; }
  2058. }
  2059. }
  2060. else {
  2061. /*-- END UNICODE-FONTS --*/
  2062. $l = strlen($s);
  2063. for($i=0; $i<$l; $i++) {
  2064. // Soft Hyphens chr(173)
  2065. // mPDF 4.4.012
  2066. if ($s[$i] == chr(173) && $this->FontFamily!='symbol' && $this->FontFamily!='zapfdingbats') {
  2067. continue;
  2068. }
  2069. else if (isset($cw[$s[$i]])) { $w += $cw[$s[$i]]; }
  2070. else if (isset($cw[ord($s[$i])])) { $w += $cw[ord($s[$i])]; }
  2071. }
  2072. /*-- UNICODE-FONTS --*/
  2073. }
  2074. /*-- END UNICODE-FONTS --*/
  2075. unset($cw);
  2076. return ($w * $this->FontSize/ 1000);
  2077. }
  2078. function SetLineWidth($width) {
  2079. //Set line width
  2080. $this->LineWidth=$width;
  2081. $lwout = (sprintf('%.3f w',$width*$this->k));
  2082. 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)) {
  2083. $this->_out($lwout);
  2084. }
  2085. $this->pageoutput[$this->page]['LineWidth'] = $lwout;
  2086. }
  2087. function Line($x1,$y1,$x2,$y2) {
  2088. //Draw a line
  2089. $this->_out(sprintf('%.3f %.3f m %.3f %.3f l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k));
  2090. }
  2091. function Arrow($x1,$y1,$x2,$y2,$headsize=3,$fill='B',$angle=25) {
  2092. //F == fill //S == stroke //B == stroke and fill
  2093. // angle = splay of arrowhead - 1 - 89 degrees
  2094. if($fill=='F') $fill='f';
  2095. elseif($fill=='FD' or $fill=='DF' or $fill=='B') $fill='B';
  2096. else $fill='S';
  2097. $a = atan2(($y2-$y1),($x2-$x1));
  2098. $b = $a + deg2rad($angle);
  2099. $c = $a - deg2rad($angle);
  2100. $x3 = $x2 - ($headsize* cos($b));
  2101. $y3 = $this->h-($y2 - ($headsize* sin($b)));
  2102. $x4 = $x2 - ($headsize* cos($c));
  2103. $y4 = $this->h-($y2 - ($headsize* sin($c)));
  2104. $x5 = $x3-($x3-$x4)/2; // mid point of base of arrowhead - to join arrow line to
  2105. $y5 = $y3-($y3-$y4)/2;
  2106. $s = '';
  2107. $s.=sprintf('%.3f %.3f m %.3f %.3f l S',$x1*$this->k,($this->h-$y1)*$this->k,$x5*$this->k,$y5*$this->k);
  2108. $this->_out($s);
  2109. $s = '';
  2110. $s.=sprintf('%.3f %.3f m %.3f %.3f l %.3f %.3f l %.3f %.3f l %.3f %.3f l ',$x5*$this->k,$y5*$this->k,$x3*$this->k,$y3*$this->k,$x2*$this->k,($this->h-$y2)*$this->k,$x4*$this->k,$y4*$this->k,$x5*$this->k,$y5*$this->k);
  2111. $s.=$fill;
  2112. $this->_out($s);
  2113. }
  2114. function Rect($x,$y,$w,$h,$style='') {
  2115. //Draw a rectangle
  2116. if($style=='F') $op='f';
  2117. elseif($style=='FD' or $style=='DF') $op='B';
  2118. else $op='S';
  2119. $this->_out(sprintf('%.3f %.3f %.3f %.3f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
  2120. }
  2121. function AddFont($family,$style='',$file='') {
  2122. if ($this->isCJK && $this->use_CJK_only) { return; }
  2123. if(empty($family)) { return; }
  2124. $family = strtolower($family);
  2125. $style=strtoupper($style);
  2126. $style=str_replace('U','',$style);
  2127. if($style=='IB') $style='BI';
  2128. $fontkey = $family.$style;
  2129. // check if the font has been already added
  2130. if(isset($this->fonts[$fontkey])) {
  2131. return;
  2132. }
  2133. /*-- UNICODE-FONTS --*/
  2134. if (($this->is_MB) && (!$this->usingCoreFont)) {
  2135. if($file=='') {
  2136. $file = str_replace(' ', '', $family).strtolower($style).'.php';
  2137. }
  2138. if(!file_exists(MPDF_FONTPATH.$file)) {
  2139. // try to load the basic file without styles
  2140. $file = str_replace(' ', '', $family).'.php';
  2141. }
  2142. include(MPDF_FONTPATH.$file);
  2143. // mPDF 4.1
  2144. if ($this->useSubsets && file_exists(MPDF_FONTPATH.substr($file,0,(strpos($file,'.'))).'.dat')) { $type = "Type1subset"; }
  2145. if(!isset($name)) {
  2146. $this->Error('Could not include font definition file');
  2147. }
  2148. $i = count($this->fonts)+$this->extraFontSubsets+1;
  2149. // mPDF 4.0
  2150. $sbarr = range(0,32);
  2151. // Always include space, and 0-9 in first subset for use in page number aliases {nb} {nbpg}
  2152. for($ctr=0; $ctr<10; $ctr++) { $sbarr[($ctr+33)] = ($ctr+48); }
  2153. $this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file, 'ctg'=>$ctg, 'subsets'=>array(0=>$sbarr), 'subsetfontids'=>array($i), 'used'=>false);
  2154. /* mPDF 4.2 Not required in MB document/fonts
  2155. if(isset($diff) AND (!empty($diff))) {
  2156. //Search existing encodings
  2157. $d=0;
  2158. $nb=count($this->diffs);
  2159. for($i=1;$i<=$nb;$i++) {
  2160. if($this->diffs[$i]==$diff) {
  2161. $d=$i;
  2162. break;
  2163. }
  2164. }
  2165. if($d==0) {
  2166. $d=$nb+1;
  2167. $this->diffs[$d]=$diff;
  2168. }
  2169. $this->fonts[$fontkey]['diff']=$d;
  2170. }
  2171. */
  2172. if(!empty($file)) {
  2173. // mPDF 4.0
  2174. if ($this->useSubsets && $type == "Type1subset") {
  2175. $this->FontFiles[$file]=array('type'=>"Type1subset");
  2176. }
  2177. else if((strcasecmp($type,"TrueType") == 0) OR (strcasecmp($type,"TrueTypeUnicode") == 0)) {
  2178. $this->FontFiles[$file]=array('length1'=>$originalsize);
  2179. }
  2180. else {
  2181. $this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2);
  2182. }
  2183. }
  2184. }
  2185. else { // if not unicode (or embedded)
  2186. /*-- END UNICODE-FONTS --*/
  2187. if($file=='') {
  2188. $file=str_replace(' ','',$family).strtolower($style);
  2189. if ($this->is_MB) {
  2190. $file=$file.'.php';
  2191. }
  2192. else if ($this->codepage != 'win-1252') {
  2193. $file=$file.'-'.$this->codepage.'.php';
  2194. }
  2195. else { // is there any other?
  2196. $file=$file.'.php';
  2197. }
  2198. }
  2199. if(defined('MPDF_FONTPATH')) { $file=MPDF_FONTPATH.$file; }
  2200. include($file);
  2201. if(!isset($name)) $this->Error('Could not include font definition file - '.$family.' '.$style);
  2202. $i=count($this->fonts)+$this->extraFontSubsets+1;
  2203. $this->fonts[$family.$style]=array('i'=>$i,'type'=>$type,'name'=>$name,'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw,'enc'=>$enc,'file'=>$file, 'used'=>false);
  2204. if($diff)
  2205. {
  2206. //Search existing encodings
  2207. $d=0;
  2208. $nb=count($this->diffs);
  2209. for($i=1;$i<=$nb;$i++)
  2210. if($this->diffs[$i]==$diff) {
  2211. $d=$i;
  2212. break;
  2213. }
  2214. if($d==0) {
  2215. $d=$nb+1;
  2216. $this->diffs[$d]=$diff;
  2217. }
  2218. $this->fonts[$family.$style]['diff']=$d;
  2219. }
  2220. if($file) {
  2221. if($type=='TrueType') $this->FontFiles[$file]=array('length1'=>$originalsize);
  2222. else $this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2);
  2223. }
  2224. // ADDED fontlist is defined in html2fpdf
  2225. if (isset($this->fontlist)) { $this->fontlist[] = strtolower($family); }
  2226. else { $this->fontlist = array(strtolower($family)); }
  2227. } // *UNICODE-FONTS*
  2228. }
  2229. function SetFont($family,$style='',$size=0, $write=true, $forcewrite=false) {
  2230. $family=strtolower($family);
  2231. // save previous values - ? not required mPDF 4.0
  2232. // $this->prevFontFamily = $this->FontFamily;
  2233. // $this->prevFontStyle = $this->FontStyle;
  2234. // Select a font; size given in points
  2235. if($family=='') {
  2236. if ($this->FontFamily) { $family=$this->FontFamily; }
  2237. else if ($this->default_font) { $family=$this->default_font; }
  2238. else { $this->Error("No font or default font set!"); }
  2239. }
  2240. // mPDF 4.2
  2241. $this->ReqFontStyle = $style; // required or requested style - used later for artificial bold/italic
  2242. if (($family == 'symbol') || ($family == 'zapfdingbats') || ($family == 'times') || ($family == 'courier') || ($family == 'helvetica')) {
  2243. // mPDF 4.2.018
  2244. if ($this->PDFA) {
  2245. if ($family == 'symbol' || $family == 'zapfdingbats') {
  2246. $this->Error("Symbol and Zapfdingbats cannot be embedded in mPDF (required for PDFA1-b).");
  2247. }
  2248. if ($family == 'times' || $family == 'courier') {
  2249. if (!$this->PDFAauto) { $this->PDFAwarnings[] = "Core Adobe font ".ucfirst($family)." cannot be embedded in mPDF, which is required for PDFA1-b. (Embedded font will be substituted.)"; }
  2250. if ($family == 'times') { $family = 'serif'; }
  2251. if ($family == 'courier') { $family = 'mono'; }
  2252. }
  2253. $this->usingCoreFont = false;
  2254. }
  2255. else { $this->usingCoreFont = true; }
  2256. }
  2257. else { $this->usingCoreFont = false; }
  2258. if($family=='symbol' or $family=='zapfdingbats') { $style=''; }
  2259. $style=strtoupper($style);
  2260. if(is_int(strpos($style,'U'))) {
  2261. $this->underline=true;
  2262. $style=str_replace('U','',$style);
  2263. }
  2264. else { $this->underline=false; }
  2265. if ($style=='IB') $style='BI';
  2266. if ($size==0) $size=$this->FontSizePt;
  2267. $fontkey=$family.$style;
  2268. /*-- UNICODE-FONTS --*/
  2269. if ($this->is_MB && !$this->usingCoreFont) {
  2270. // CJK fonts
  2271. /*-- CJK --*/
  2272. if (in_array($fontkey,$this->available_CJK_fonts)) {
  2273. if(!isset($this->fonts[$fontkey])) { // already added
  2274. if (empty($this->Big5_widths)) { require(_MPDF_PATH . 'includes/CJKdata.php'); }
  2275. $this->AddCJKFont($family); // don't need to add style
  2276. }
  2277. $this->isCJK = true;
  2278. $this->setMBencoding('UTF-8');
  2279. }
  2280. else if ($this->use_CJK_only) {
  2281. $family = $this->default_font;
  2282. $this->isCJK = true;
  2283. $this->setMBencoding('UTF-8');
  2284. }
  2285. // Test to see if requested font/style is available - or substitute
  2286. else
  2287. /*-- END CJK --*/
  2288. if (!in_array($fontkey,$this->available_unifonts)) {
  2289. // If font[nostyle] exists - set it
  2290. if (in_array($family,$this->available_unifonts)) {
  2291. $style = '';
  2292. }
  2293. // Else if only one font available - set it (assumes if only one font available it will not have a style)
  2294. else if (count($this->available_unifonts) == 1) {
  2295. $family = $this->available_unifonts[0];
  2296. $style = '';
  2297. }
  2298. else {
  2299. $found = 0;
  2300. // else substitute font of similar type
  2301. if (in_array($family,$this->sans_fonts)) {
  2302. $i = array_intersect($this->sans_fonts,$this->available_unifonts);
  2303. if (count($i)) {
  2304. $i = array_values($i);
  2305. // with requested style if possible
  2306. if (!in_array(($i[0].$style),$this->available_unifonts)) {
  2307. $style = '';
  2308. }
  2309. $family = $i[0];
  2310. $found = 1;
  2311. }
  2312. }
  2313. else if (in_array($family,$this->serif_fonts)) {
  2314. $i = array_intersect($this->serif_fonts,$this->available_unifonts);
  2315. if (count($i)) {
  2316. $i = array_values($i);
  2317. // with requested style if possible
  2318. if (!in_array(($i[0].$style),$this->available_unifonts)) {
  2319. $style = '';
  2320. }
  2321. $family = $i[0];
  2322. $found = 1;
  2323. }
  2324. }
  2325. else if (in_array($family,$this->mono_fonts)) {
  2326. $i = array_intersect($this->mono_fonts,$this->available_unifonts);
  2327. if (count($i)) {
  2328. $i = array_values($i);
  2329. // with requested style if possible
  2330. if (!in_array(($i[0].$style),$this->available_unifonts)) {
  2331. $style = '';
  2332. }
  2333. $family = $i[0];
  2334. $found = 1;
  2335. }
  2336. }
  2337. if (!$found) {
  2338. // set first available font
  2339. $fs = $this->available_unifonts[0];
  2340. // mPDF 4.0 Added 0-9
  2341. preg_match('/^([a-z_0-9]+)([BI]{0,2})$/',$fs,$fas);
  2342. // with requested style if possible
  2343. $ws = $fas[1].$style;
  2344. if (in_array($ws,$this->available_unifonts)) {
  2345. $family = $fas[1]; // leave $style as is
  2346. }
  2347. else if (in_array($fas[1],$this->available_unifonts)) {
  2348. // or without style
  2349. $family = $fas[1];
  2350. $style = '';
  2351. }
  2352. else {
  2353. // or with the style specified
  2354. $family = $fas[1];
  2355. $style = $fas[2];
  2356. }
  2357. }
  2358. }
  2359. $this->isCJK = false;
  2360. $this->setMBencoding('UTF-8');
  2361. $fontkey = $family.$style;
  2362. }
  2363. else {
  2364. $this->isCJK = false;
  2365. $this->setMBencoding('UTF-8');
  2366. }
  2367. // try to add font (if not already added)
  2368. $this->AddFont($family, $style);
  2369. //Test if font is already selected
  2370. if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size) && !$forcewrite) {
  2371. return $family;
  2372. }
  2373. $fontkey = $family.$style;
  2374. //Select it
  2375. $this->FontFamily = $family;
  2376. $this->FontStyle = $style;
  2377. $this->FontSizePt = $size;
  2378. $this->FontSize = $size / $this->k;
  2379. $this->CurrentFont = &$this->fonts[$fontkey];
  2380. if ($write) {
  2381. $fontout = (sprintf('BT /F%d %.3f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  2382. // Edited mPDF 3.0
  2383. 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); }
  2384. $this->pageoutput[$this->page]['Font'] = $fontout;
  2385. }
  2386. // Added - currentfont (lowercase) used in HTML2PDF
  2387. $this->currentfontfamily=$family;
  2388. $this->currentfontsize=$size;
  2389. $this->currentfontstyle=$style.($this->underline ? 'U' : '');
  2390. }
  2391. else { // if not unicode/CJK - or core embedded font
  2392. /*-- END UNICODE-FONTS --*/
  2393. // mPDF 4.2.018
  2394. if ($this->PDFA && $this->useOnlyCoreFonts) {
  2395. $this->Error('Core Adobe fonts cannot be embedded in mPDF (required for PDFA1-b) - cannot use <i>$mpdf->useOnlyCoreFonts</i>.');
  2396. }
  2397. $this->isCJK = false;
  2398. $this->setMBencoding($this->codepage);
  2399. //Test if font is already selected
  2400. if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size) && !$forcewrite) {
  2401. return $family;
  2402. }
  2403. // ALWAYS SUBSTITUTE ARIAL TIMES COURIER IN 1252
  2404. if (!isset($this->CoreFonts[$fontkey]) && ($this->useOnlyCoreFonts) && ($this->codepage == 'win-1252')) {
  2405. if (in_array($family,$this->serif_fonts)) { $family = 'times'; }
  2406. else if (in_array($family,$this->mono_fonts)) { $family = 'courier'; }
  2407. else { $family = 'helvetica'; }
  2408. $this->usingCoreFont = true;
  2409. $fontkey = $family.$style;
  2410. }
  2411. // Test to see if requested font/style is available - or substitute
  2412. if (!in_array($fontkey,$this->available_fonts) && (!$this->usingCoreFont) ) {
  2413. // If font[nostyle] exists - set it
  2414. if (in_array($family,$this->available_fonts)) {
  2415. $style = '';
  2416. }
  2417. // Else if only one font available - set it (assumes if only one font available it will not have a style)
  2418. else if (count($this->available_fonts) == 1) {
  2419. $family = $this->available_fonts[0];
  2420. $style = '';
  2421. }
  2422. else {
  2423. $found = 0;
  2424. // else substitute font of similar type
  2425. if (in_array($family,$this->sans_fonts)) {
  2426. $i = array_intersect($this->sans_fonts,$this->available_fonts);
  2427. if (count($i)) {
  2428. $i = array_values($i);
  2429. // with requested style if possible
  2430. if (!in_array(($i[0].$style),$this->available_fonts)) {
  2431. $style = '';
  2432. }
  2433. $family = $i[0];
  2434. $found = 1;
  2435. }
  2436. }
  2437. else if (in_array($family,$this->serif_fonts)) {
  2438. $i = array_intersect($this->serif_fonts,$this->available_fonts);
  2439. if (count($i)) {
  2440. $i = array_values($i);
  2441. // with requested style if possible
  2442. if (!in_array(($i[0].$style),$this->available_fonts)) {
  2443. $style = '';
  2444. }
  2445. $family = $i[0];
  2446. $found = 1;
  2447. }
  2448. }
  2449. else if (in_array($family,$this->mono_fonts)) {
  2450. $i = array_intersect($this->mono_fonts,$this->available_fonts);
  2451. if (count($i)) {
  2452. $i = array_values($i);
  2453. // with requested style if possible
  2454. if (!in_array(($i[0].$style),$this->available_fonts)) {
  2455. $style = '';
  2456. }
  2457. $family = $i[0];
  2458. $found = 1;
  2459. }
  2460. }
  2461. if (!$found) {
  2462. // set first available font
  2463. $fs = $this->available_unifonts[0];
  2464. // mPDF 4.0 Added 0-9
  2465. preg_match('/^([a-z_0-9]+)([BI]{0,2})$/',$fs,$fas);
  2466. // with requested style if possible
  2467. $ws = $fas[1].$style;
  2468. if (in_array($ws,$this->available_fonts)) {
  2469. $family = $fas[1]; // leave $style as is
  2470. }
  2471. else if (in_array($fas[1],$this->available_fonts)) {
  2472. // or without style
  2473. $family = $fas[1];
  2474. $style = '';
  2475. }
  2476. else {
  2477. // or with the style specified
  2478. $family = $fas[1];
  2479. $style = $fas[2];
  2480. }
  2481. }
  2482. }
  2483. $fontkey = $family.$style;
  2484. }
  2485. // mPDF 4.0
  2486. if(!isset($this->fonts[$fontkey])) {
  2487. // STANDARD CORE FONTS
  2488. if (isset($this->CoreFonts[$fontkey])) {
  2489. //Load metric file
  2490. $file=$family;
  2491. if($family=='times' || $family=='helvetica' || $family=='courier') { $file.=strtolower($style); }
  2492. $file.='.php';
  2493. include(_MPDF_PATH.'font/'.$file);
  2494. if(!isset($cw)) { $this->Error('Could not include font metric file'); }
  2495. $i=count($this->fonts)+$this->extraFontSubsets+1;
  2496. $this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw);
  2497. }
  2498. else {
  2499. // try to add font
  2500. $this->AddFont($family, $style);
  2501. }
  2502. }
  2503. //Test if font is already selected
  2504. if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size) && !$forcewrite) {
  2505. return $family;
  2506. }
  2507. //Select it
  2508. $this->FontFamily=$family;
  2509. $this->FontStyle=$style;
  2510. $this->FontSizePt=$size;
  2511. $this->FontSize=$size/$this->k;
  2512. $this->CurrentFont=&$this->fonts[$fontkey];
  2513. if ($write) {
  2514. $fontout = (sprintf('BT /F%d %.3f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  2515. 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); }
  2516. $this->pageoutput[$this->page]['Font'] = $fontout;
  2517. }
  2518. // Added - currentfont (lowercase) used in HTML2PDF
  2519. $this->currentfontfamily=$family;
  2520. $this->currentfontsize=$size;
  2521. $this->currentfontstyle=$style.($this->underline ? 'U' : '');
  2522. } // *UNICODE-FONTS*
  2523. return $family;
  2524. }
  2525. function SetFontSize($size,$write=true) {
  2526. //Set font size in points
  2527. if($this->FontSizePt==$size) return;
  2528. $this->FontSizePt=$size;
  2529. $this->FontSize=$size/$this->k;
  2530. $this->currentfontsize=$size;
  2531. if ($write) {
  2532. $fontout = (sprintf('BT /F%d %.3f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  2533. // Edited mPDF 3.0
  2534. 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); }
  2535. $this->pageoutput[$this->page]['Font'] = $fontout;
  2536. }
  2537. }
  2538. function AddLink() {
  2539. //Create a new internal link
  2540. $n=count($this->links)+1;
  2541. $this->links[$n]=array(0,0);
  2542. return $n;
  2543. }
  2544. function SetLink($link,$y=0,$page=-1) {
  2545. //Set destination of internal link
  2546. if($y==-1) $y=$this->y;
  2547. if($page==-1) $page=$this->page;
  2548. $this->links[$link]=array($page,$y);
  2549. }
  2550. function Link($x,$y,$w,$h,$link) {
  2551. if ($this->keep_block_together) { // Save to array - don't write yet
  2552. $this->ktLinks[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link);
  2553. return;
  2554. }
  2555. else if ($this->table_rotate) { // *TABLES*
  2556. $this->tbrot_Links[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link); // *TABLES*
  2557. return; // *TABLES*
  2558. } // *TABLES*
  2559. else if ($this->kwt) {
  2560. $this->kwt_Links[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link);
  2561. return;
  2562. }
  2563. // mPDF 4.0
  2564. if ($this->writingHTMLheader || $this->writingHTMLfooter) {
  2565. $this->HTMLheaderPageLinks[]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link);
  2566. return;
  2567. }
  2568. //Put a link on the page
  2569. $this->PageLinks[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link);
  2570. // Save cross-reference to Column buffer
  2571. $ref = count($this->PageLinks[$this->page])-1; // *COLUMNS*
  2572. $this->columnLinks[$this->CurrCol][INTVAL($this->x)][INTVAL($this->y)] = $ref; // *COLUMNS*
  2573. }
  2574. function Text($x,$y,$txt) {
  2575. // Output a string
  2576. // Called (only) by Watermark
  2577. // Expects input to be mb_encoded if necessary and RTL reversed
  2578. // NON_BREAKING SPACE
  2579. // mPDF 4.0
  2580. $this->CurrentFont['used']= true;
  2581. // mPDF 4.0 Subset fonts are unibyte at output stage
  2582. /*-- UNICODE-FONTS --*/
  2583. if ($this->is_MB && !$this->usingCoreFont && (!$this->useSubsets || $this->CurrentFont['type']!='Type1subset')) {
  2584. $txt2 = str_replace($this->chrs[194].$this->chrs[160],$this->chrs[32],$txt);
  2585. if (!$this->usingCoreFont) {
  2586. //Convert string to UTF-16BE without BOM
  2587. $txt2= $this->UTF8ToUTF16BE($txt2, false);
  2588. }
  2589. $s=sprintf('BT %.3f %.3f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt2));
  2590. }
  2591. // mPDF 4.0 Subset fonts
  2592. else
  2593. /*-- END UNICODE-FONTS --*/
  2594. if ($this->useSubsets && $this->CurrentFont['type']=='Type1subset' && !$this->isCJK && !$this->usingCoreFont) {
  2595. $txt2 = str_replace($this->chrs[160],$this->chrs[32],$txt);
  2596. $txt2 = $this->UTF8toSubset($txt2);
  2597. $s=sprintf('BT %.3f %.3f Td %s Tj ET',$x*$this->k,($this->h-$y)*$this->k,$txt2);
  2598. }
  2599. else {
  2600. $txt2 = str_replace($this->chrs[160],$this->chrs[32],$txt);
  2601. $s=sprintf('BT %.3f %.3f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt2));
  2602. }
  2603. if($this->underline and $txt!='') {
  2604. $s.=' '.$this->_dounderline($x,$y + (0.1* $this->FontSize),$txt);
  2605. }
  2606. if($this->ColorFlag) $s='q '.$this->TextColor.' '.$s.' Q';
  2607. $this->_out($s);
  2608. }
  2609. /*-- DIRECTW --*/
  2610. function WriteText($x,$y,$txt) {
  2611. // Output a string using Text() but does encoding and text reversing of RTL
  2612. $txt = $this->purify_utf8_text($txt);
  2613. if ($this->text_input_as_HTML) {
  2614. $txt = $this->all_entities_to_utf8($txt);
  2615. }
  2616. // Modified by Ivan Tcholakov, 28-JAN-2010.
  2617. //if (!$this->is_MB) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  2618. if (!$this->is_MB) { $txt = api_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  2619. //
  2620. // DIRECTIONALITY
  2621. $this->magic_reverse_dir($txt); // *RTL*
  2622. // mPDF 4.0 Font-specific ligature substitution for Indic fonts
  2623. $this->ConvertIndic($txt); // *INDIC*
  2624. $this->Text($x,$y,$txt);
  2625. }
  2626. function WriteCell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='', $currentx=0) {
  2627. //Output a cell using Cell() but does encoding and text reversing of RTL
  2628. $txt = $this->purify_utf8_text($txt);
  2629. if ($this->text_input_as_HTML) {
  2630. $txt = $this->all_entities_to_utf8($txt);
  2631. }
  2632. // Modified by Ivan Tcholakov, 28-JAN-2010.
  2633. //if (!$this->is_MB) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  2634. if (!$this->is_MB) { $txt = api_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  2635. //
  2636. // DIRECTIONALITY
  2637. $this->magic_reverse_dir($txt); // *RTL*
  2638. // mPDF 4.0 Font-specific ligature substitution for Indic fonts
  2639. $this->ConvertIndic($txt); // *INDIC*
  2640. $this->Cell($w,$h,$txt,$border,$ln,$align,$fill,$link, $currentx);
  2641. }
  2642. /*-- END DIRECTW --*/
  2643. // mPDF 4.0
  2644. function ResetSpacing() {
  2645. if ($this->ws != 0) { $this->_out('BT 0 Tw ET'); }
  2646. $this->ws=0;
  2647. if ($this->charspacing != 0) { $this->_out('BT 0 Tc ET'); }
  2648. $this->charspacing=0;
  2649. }
  2650. // mPDF 4.0
  2651. function SetSpacing($cs,$ws) {
  2652. if ($cs) { $this->_out(sprintf('BT %.3f Tc ET',$cs)); }
  2653. else if ($this->charspacing != 0) { $this->_out('BT 0 Tc ET'); }
  2654. $this->charspacing=$cs;
  2655. if ($ws) { $this->_out(sprintf('BT %.3f Tw ET',$ws)); }
  2656. else if ($this->ws != 0) { $this->_out('BT 0 Tw ET'); }
  2657. $this->ws=$ws;
  2658. }
  2659. // WORD SPACING
  2660. function GetJspacing($nc,$ns,$w) {
  2661. $ws = 0;
  2662. $charspacing = 0;
  2663. $ww = $this->jSWord;
  2664. $ncx = $nc-1;
  2665. if ($nc == 0 && $ns == 0) { return array(0,0); }
  2666. if ($nc==1) { $charspacing = $w; }
  2667. else if ($this->jSpacing == 'C') {
  2668. if ($nc) { $charspacing = $w / ($ncx ); }
  2669. }
  2670. else if ($this->jSpacing == 'W') {
  2671. if ($ns) { $ws = $w / $ns; }
  2672. }
  2673. else if (!$ns) {
  2674. if ($nc) { $charspacing = $w / ($ncx ); }
  2675. if (($this->jSmaxChar > 0) && ($charspacing > $this->jSmaxChar)) {
  2676. $charspacing = $this->jSmaxChar;
  2677. }
  2678. }
  2679. else if ($ns == ($ncx )) {
  2680. $charspacing = $w / $ns;
  2681. }
  2682. else {
  2683. if ($nc) {
  2684. /*-- UNICODE-FONTS --*/
  2685. if ($this->is_MB && !$this->usingCoreFont) {
  2686. $cs = ($w * (1 - $this->jSWord)) / ($ncx -$ns);
  2687. if (($this->jSmaxChar > 0) && ($cs > $this->jSmaxChar)) {
  2688. $cs = $this->jSmaxChar;
  2689. $ww = 1 - (($cs * ($ncx -$ns))/$w);
  2690. }
  2691. $charspacing = $cs;
  2692. $ws = (($w * ($ww) ) / $ns) - $charspacing;
  2693. }
  2694. else {
  2695. /*-- END UNICODE-FONTS --*/
  2696. $cs = ($w * (1 - $this->jSWord)) / ($ncx );
  2697. if (($this->jSmaxChar > 0) && ($cs > $this->jSmaxChar)) {
  2698. $cs = $this->jSmaxChar;
  2699. $ww = 1 - (($cs * ($ncx ))/$w);
  2700. }
  2701. $charspacing = $cs;
  2702. $ws = ($w * ($ww) ) / $ns;
  2703. } // *UNICODE-FONTS*
  2704. }
  2705. }
  2706. return array($charspacing,$ws);
  2707. }
  2708. // mPDF 4.2 Last parameters added above and below font
  2709. 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) {
  2710. //Output a cell
  2711. // Expects input to be mb_encoded if necessary and RTL reversed
  2712. // NON_BREAKING SPACE
  2713. if ($this->is_MB) { // *UNICODE-FONTS*
  2714. $txt = str_replace($this->chrs[194].$this->chrs[160],$this->chrs[32],$txt); // *UNICODE-FONTS*
  2715. } // *UNICODE-FONTS*
  2716. else { // *UNICODE-FONTS*
  2717. $txt = str_replace($this->chrs[160],$this->chrs[32],$txt);
  2718. } // *UNICODE-FONTS*
  2719. $k=$this->k;
  2720. $oldcolumn = $this->CurrCol;
  2721. // Automatic page break
  2722. // Allows PAGE-BREAK-AFTER = avoid to work
  2723. // mPDF 4.2.008
  2724. if (!$this->tableLevel && (($this->y+$this->divheight>$this->PageBreakTrigger) || ($this->y+$h>$this->PageBreakTrigger) ||
  2725. ($this->y+($h*2)>$this->PageBreakTrigger && $this->blk[$this->blklvl]['page_break_after_avoid'])) and !$this->InFooter and $this->AcceptPageBreak()) {
  2726. $x=$this->x;//Current X position
  2727. // WORD SPACING
  2728. $ws=$this->ws;//Word Spacing
  2729. $charspacing=$this->charspacing;//Character Spacing
  2730. // mPDF 4.0
  2731. $this->ResetSpacing();
  2732. $this->AddPage($this->CurOrientation);
  2733. // Added to correct for OddEven Margins
  2734. $x += $this->MarginCorrection;
  2735. if ($currentx) {
  2736. $currentx += $this->MarginCorrection;
  2737. }
  2738. $this->x=$x;
  2739. // WORD SPACING
  2740. // mPDF 4.0
  2741. $this->SetSpacing($charspacing,$ws);
  2742. }
  2743. // Test: to put border round each cell: $border=1;
  2744. // Test: to put line through centre of cell: $this->Line($this->x,$this->y+($h/2),$this->x+50,$this->y+($h/2));
  2745. /*-- COLUMNS --*/
  2746. // COLS
  2747. // COLUMN CHANGE
  2748. if ($this->CurrCol != $oldcolumn) {
  2749. if ($currentx) {
  2750. $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  2751. }
  2752. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  2753. }
  2754. // COLUMNS Update/overwrite the lowest bottom of printing y value for a column
  2755. if ($this->ColActive) {
  2756. if ($h) { $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$h; }
  2757. else { $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$this->divheight; }
  2758. }
  2759. /*-- END COLUMNS --*/
  2760. // KEEP BLOCK TOGETHER Update/overwrite the lowest bottom of printing y value on first page
  2761. if ($this->keep_block_together) {
  2762. if ($h) { $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$h; }
  2763. // else { $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$this->divheight; }
  2764. }
  2765. if($w==0) $w = $this->w-$this->rMargin-$this->x;
  2766. $s='';
  2767. if($fill==1 && $this->FillColor) {
  2768. 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.' '; }
  2769. $this->pageoutput[$this->page]['FillColor'] = $this->FillColor;
  2770. }
  2771. // mPDF 4.0
  2772. $boxtop = $this->y;
  2773. $boxheight = $h;
  2774. $boxbottom = $this->y+$h;
  2775. if($txt!='') {
  2776. // FONT SIZE - this determines the baseline caculation
  2777. if ($this->linemaxfontsize && !$this->processingHeader) { $bfs = $this->linemaxfontsize; }
  2778. else { $bfs = $this->FontSize; }
  2779. //Calculate baseline Superscript and Subscript Y coordinate adjustment
  2780. $bfx = $this->baselineC; // mPDF 4.2
  2781. $baseline = $bfx*$bfs;
  2782. if($this->SUP) { $baseline += ($bfx-1.05)*$this->FontSize; }
  2783. else if($this->SUB) { $baseline += ($bfx + 0.04)*$this->FontSize; }
  2784. else if($this->bullet) { $baseline += ($bfx-0.7)*$this->FontSize; }
  2785. // Vertical align (for Images)
  2786. // mPDF 4.2
  2787. if ($abovefont || $belowfont) { // from flowing block - valign always M
  2788. $va = $abovefont + (0.5*$bfs);
  2789. }
  2790. else if ($this->lineheight_correction) {
  2791. if ($valign == 'T') { $va = (0.5 * $bfs * $this->lineheight_correction); }
  2792. else if ($valign == 'B') { $va = $h-(0.5 * $bfs * $this->lineheight_correction); }
  2793. else { $va = 0.5*$h; } // Middle
  2794. }
  2795. else {
  2796. if ($valign == 'T') { $va = (0.5 * $bfs * $this->default_lineheight_correction); }
  2797. else if ($valign == 'B') { $va = $h-(0.5 * $bfs * $this->default_lineheight_correction); }
  2798. else { $va = 0.5*$h; } // Middle
  2799. }
  2800. // ONLY SET THESE IF WANT TO CONFINE BORDER +- FILL TO FIT FONTSIZE - NOT FULL CELL
  2801. if ($spanfill) {
  2802. $boxtop = $this->y+$baseline+$va-($this->FontSize*(0.5+$bfx));
  2803. $boxheight = $this->FontSize;
  2804. $boxbottom = $boxtop + $boxheight;
  2805. }
  2806. }
  2807. if($fill==1 or $border==1) {
  2808. if ($fill==1) $op=($border==1) ? 'B' : 'f';
  2809. else $op='S';
  2810. $s.=sprintf('%.3f %.3f %.3f %.3f re %s ',$this->x*$k,($this->h-$boxtop)*$k,$w*$k,-$boxheight*$k,$op);
  2811. }
  2812. if(is_string($border)) {
  2813. $x=$this->x;
  2814. $y=$this->y;
  2815. if(is_int(strpos($border,'L')))
  2816. $s.=sprintf('%.3f %.3f m %.3f %.3f l S ',$x*$k,($this->h-$boxtop)*$k,$x*$k,($this->h-($boxbottom))*$k);
  2817. if(is_int(strpos($border,'T')))
  2818. $s.=sprintf('%.3f %.3f m %.3f %.3f l S ',$x*$k,($this->h-$boxtop)*$k,($x+$w)*$k,($this->h-$boxtop)*$k);
  2819. if(is_int(strpos($border,'R')))
  2820. $s.=sprintf('%.3f %.3f m %.3f %.3f l S ',($x+$w)*$k,($this->h-$boxtop)*$k,($x+$w)*$k,($this->h-($boxbottom))*$k);
  2821. if(is_int(strpos($border,'B')))
  2822. $s.=sprintf('%.3f %.3f m %.3f %.3f l S ',$x*$k,($this->h-($boxbottom))*$k,($x+$w)*$k,($this->h-($boxbottom))*$k);
  2823. }
  2824. if($txt!='') {
  2825. // Modified by Ivan Tcholakov, 28-JAN-2010.
  2826. //$stringWidth = $this->GetStringWidth($txt) + ( $this->charspacing * mb_strlen( $txt, $this->mb_enc ) / $k )
  2827. // + ( $this->ws * mb_substr_count( $txt, ' ', $this->mb_enc ) / $k );
  2828. $stringWidth = $this->GetStringWidth($txt) + ( $this->charspacing * api_strlen( $txt, $this->mb_enc ) / $k )
  2829. + ( $this->ws * api_substr_count( $txt, ' ', $this->mb_enc ) / $k );
  2830. //
  2831. // Set x OFFSET FOR PRINTING
  2832. if($align=='R') {
  2833. $dx=$w-$this->cMarginR - $stringWidth - $lcpaddingR;
  2834. }
  2835. elseif($align=='C') {
  2836. $dx=(($w - $stringWidth )/2);
  2837. }
  2838. elseif($align=='L' or $align=='J') $dx=$this->cMarginL + $lcpaddingL;
  2839. else $dx = 0;
  2840. if($this->ColorFlag) $s.='q '.$this->TextColor.' ';
  2841. // OUTLINE
  2842. if($this->outline_on) {
  2843. $s.=' '.sprintf('%.3f w',$this->LineWidth*$k).' ';
  2844. $s.=" $this->DrawColor ";
  2845. $s.=" 2 Tr ";
  2846. }
  2847. // mPDF 4.2 Artificial BOLD
  2848. else if ($this->falseBoldWeight && strpos($this->ReqFontStyle,"B") !== false && strpos($this->FontStyle,"B") === false) { // can't use together with OUTLINE
  2849. $s .= ' 2 Tr 1 J 1 j ';
  2850. $s .= ' '.sprintf('%.3f w',($this->FontSize/130)*$k*$this->falseBoldWeight).' ';
  2851. $tc = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  2852. if($this->FillColor!=$tc) { $s .= ' '.$tc.' '; } // stroke (outline) = same colour as text(fill)
  2853. }
  2854. // mPDF 4.2 Artificial ITALIC
  2855. if (strpos($this->ReqFontStyle,"I") !== false && strpos($this->FontStyle,"I") === false) { // Artificial italic
  2856. $aix = '1 0 0.261799 1 %.3f %.3f Tm ';
  2857. }
  2858. else { $aix = '%.3f %.3f Td '; }
  2859. // THE TEXT
  2860. // mPDF 4.0
  2861. $this->CurrentFont['used']= true;
  2862. // WORD SPACING
  2863. // IF multibyte - Tw has no effect - need to do word spacing by setting character spacing for spaces between words
  2864. // mPDF 4.0 Subset fonts are unibyte at output stage
  2865. /*-- UNICODE-FONTS --*/
  2866. if ($this->ws && $this->is_MB && (!$this->useSubsets || $this->CurrentFont['type']!='Type1subset')) {
  2867. $space = ' ';
  2868. if ($this->is_MB && !$this->usingCoreFont) {
  2869. //Convert string to UTF-16BE without BOM
  2870. $space= $this->UTF8ToUTF16BE($space , false);
  2871. }
  2872. $space=$this->_escape($space );
  2873. $s.=sprintf('BT '.$aix,($this->x+$dx)*$k,($this->h-($this->y+$baseline+$va))*$k);
  2874. $t = explode(' ',$txt); // mPDF 4.4.012
  2875. for($i=0;$i<count($t);$i++) {
  2876. $tx = $t[$i];
  2877. if ($this->is_MB && !$this->usingCoreFont) {
  2878. //Convert string to UTF-16BE without BOM
  2879. $tx = $this->UTF8ToUTF16BE($tx , false);
  2880. }
  2881. $tx = $this->_escape($tx);
  2882. $s.=sprintf(' %.3f Tc (%s) Tj',$this->charspacing,$tx);
  2883. if (($i+1)<count($t)) {
  2884. $s.=sprintf(' %.3f Tc (%s) Tj',$this->ws+$this->charspacing,$space);
  2885. }
  2886. }
  2887. $s.=' ET';
  2888. }
  2889. else {
  2890. /*-- END UNICODE-FONTS --*/
  2891. $txt2= $txt;
  2892. // mPDF 4.0 Subset fonts
  2893. if ($this->useSubsets && $this->CurrentFont['type']=='Type1subset' && !$this->isCJK && !$this->usingCoreFont) {
  2894. $txt2 = $this->UTF8toSubset($txt2);
  2895. $s.=sprintf('BT '.$aix.' %s Tj ET',($this->x+$dx)*$k,($this->h-($this->y+$baseline+$va))*$k,$txt2);
  2896. }
  2897. else {
  2898. /*-- UNICODE-FONTS --*/
  2899. if ($this->is_MB && !$this->usingCoreFont) {
  2900. //Convert string to UTF-16BE without BOM
  2901. $txt2= $this->UTF8ToUTF16BE($txt2, false);
  2902. }
  2903. /*-- END UNICODE-FONTS --*/
  2904. $txt2=$this->_escape($txt2);
  2905. $s.=sprintf('BT '.$aix.' (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+$baseline+$va))*$k,$txt2);
  2906. }
  2907. } // *UNICODE-FONTS*
  2908. // UNDERLINE
  2909. // mPDF 4.0
  2910. if($this->underline) {
  2911. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  2912. if($this->FillColor!=$c) { $s.= ' '.$c.' '; }
  2913. if (isset($this->CurrentFont['up'])) { $up=$this->CurrentFont['up']; }
  2914. else { $up = -100; }
  2915. $adjusty = (-$up/1000* $this->FontSize);
  2916. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  2917. else { $ut = 60/1000* $this->FontSize; }
  2918. $olw = $this->LineWidth;
  2919. $s.=' '.(sprintf(' %.3f w',$ut*$this->k));
  2920. $s.=' '.$this->_dounderline($this->x+$dx,$this->y+$baseline+$va+$adjusty,$txt);
  2921. $s.=' '.(sprintf(' %.3f w',$olw*$this->k));
  2922. if($this->FillColor!=$c) { $s.= ' '.$this->FillColor.' '; }
  2923. }
  2924. // STRIKETHROUGH
  2925. // mPDF 4.0
  2926. if($this->strike) {
  2927. $c = strtoupper($this->TextColor); // change 0 0 0 rg to 0 0 0 RG
  2928. if($this->FillColor!=$c) { $s.= ' '.$c.' '; }
  2929. //Superscript and Subscript Y coordinate adjustment (now for striked-through texts)
  2930. if (isset($this->CurrentFont['desc']['CapHeight'])) { $ch=$this->CurrentFont['desc']['CapHeight']; }
  2931. else { $ch = 700; }
  2932. $adjusty = (-$ch/1000* $this->FontSize) * 0.35;
  2933. if (isset($this->CurrentFont['ut'])) { $ut=$this->CurrentFont['ut']/1000* $this->FontSize; }
  2934. else { $ut = 60/1000* $this->FontSize; }
  2935. $olw = $this->LineWidth;
  2936. $s.=' '.(sprintf(' %.3f w',$ut*$this->k));
  2937. $s.=' '.$this->_dounderline($this->x+$dx,$this->y+$baseline+$va+$adjusty,$txt);
  2938. $s.=' '.(sprintf(' %.3f w',$olw));
  2939. if($this->FillColor!=$c) { $s.= ' '.$this->FillColor.' '; }
  2940. }
  2941. // COLOR
  2942. if($this->ColorFlag) $s.=' Q';
  2943. // LINK
  2944. if($link!='') {
  2945. $this->Link($this->x+$dx,$this->y+$va-.5*$this->FontSize,$stringWidth,$this->FontSize,$link);
  2946. }
  2947. }
  2948. if($s) $this->_out($s);
  2949. // WORD SPACING
  2950. if ($this->ws && $this->is_MB) { // *UNICODE-FONTS*
  2951. $this->_out(sprintf('BT %.3f Tc ET',$this->charspacing)); // *UNICODE-FONTS*
  2952. } // *UNICODE-FONTS*
  2953. $this->lasth=$h;
  2954. if( strpos($txt,"\n") !== false) $ln=1; // cell recognizes \n from <BR> tag
  2955. if($ln>0)
  2956. {
  2957. //Go to next line
  2958. $this->y += $h;
  2959. if($ln==1) {
  2960. //Move to next line
  2961. if ($currentx != 0) { $this->x=$currentx; }
  2962. else { $this->x=$this->lMargin; }
  2963. }
  2964. }
  2965. else $this->x+=$w;
  2966. }
  2967. function MultiCell($w,$h,$txt,$border=0,$align='',$fill=0,$link='',$directionality='ltr',$encoded=false)
  2968. {
  2969. // Parameter (pre-)encoded - When called internally from ToC or textarea: mb_encoding already done - but not reverse RTL/Indic
  2970. if (!$encoded) {
  2971. $txt = $this->purify_utf8_text($txt);
  2972. if ($this->text_input_as_HTML) {
  2973. $txt = $this->all_entities_to_utf8($txt);
  2974. }
  2975. // Modified by Ivan Tcholakov, 28-JAN-2010.
  2976. //if (!$this->is_MB) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  2977. if (!$this->is_MB) { $txt = api_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  2978. //
  2979. // mPDF 4.0 Font-specific ligature substitution for Indic fonts
  2980. else if ($this->is_MB) { // *INDIC*
  2981. $this->ConvertIndic($tmp); // *INDIC*
  2982. } // *INDIC*
  2983. }
  2984. if (!$align) { $align = $this->defaultAlign; }
  2985. //Output text with automatic or explicit line breaks
  2986. $cw=&$this->CurrentFont['cw'];
  2987. if($w==0) $w=$this->w-$this->rMargin-$this->x;
  2988. /*-- UNICODE-FONTS --*/
  2989. if ($this->is_MB) {
  2990. $wmax = ($w - ($this->cMarginL+$this->cMarginR));
  2991. $s=str_replace("\r",'',$txt); // mPDF 4.4.012
  2992. // Modified by Ivan Tcholakov, 28-JAN-2010.
  2993. //$nb=mb_strlen($s, $this->mb_enc );
  2994. //while($nb>0 and mb_substr($s,$nb-1,1,$this->mb_enc )=="\n") $nb--;
  2995. $nb=api_strlen($s, $this->mb_enc );
  2996. while($nb>0 and api_substr($s,$nb-1,1,$this->mb_enc )=="\n") $nb--;
  2997. //
  2998. }
  2999. else {
  3000. /*-- END UNICODE-FONTS --*/
  3001. $wmax=($w- ($this->cMarginL+$this->cMarginR))*1000/$this->FontSize;
  3002. $s=str_replace("\r",'',$txt);
  3003. $nb=strlen($s);
  3004. while($nb>0 and $s[$nb-1]=="\n") $nb--;
  3005. } // *UNICODE-FONTS*
  3006. $b=0;
  3007. if($border) {
  3008. if($border==1) {
  3009. $border='LTRB';
  3010. $b='LRT';
  3011. $b2='LR';
  3012. }
  3013. else {
  3014. $b2='';
  3015. if(is_int(strpos($border,'L'))) $b2.='L';
  3016. if(is_int(strpos($border,'R'))) $b2.='R';
  3017. $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2;
  3018. }
  3019. }
  3020. $sep=-1;
  3021. $i=0;
  3022. $j=0;
  3023. $l=0;
  3024. $ns=0;
  3025. $nl=1;
  3026. /*-- UNICODE-FONTS --*/
  3027. if ($this->is_MB) {
  3028. while($i<$nb) {
  3029. //Get next character
  3030. // Modified by Ivan Tcholakov, 28-JAN-2010.
  3031. //$c = mb_substr($s,$i,1,$this->mb_enc );
  3032. $c = api_substr($s,$i,1,$this->mb_enc);
  3033. //
  3034. if($c == "\n") { // mPDF 4.4.012
  3035. //Explicit line break
  3036. // WORD SPACING
  3037. // mPDF 4.0
  3038. $this->ResetSpacing();
  3039. // Modified by Ivan Tcholakov, 28-JUN-2010.
  3040. //$tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc)); // mPDF 4.4.012
  3041. $tmp = rtrim(api_substr($s,$j,$i-$j,$this->mb_enc)); // mPDF 4.4.012
  3042. //
  3043. // DIRECTIONALITY
  3044. $this->magic_reverse_dir($tmp); // *RTL*
  3045. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3046. $i++;
  3047. $sep=-1;
  3048. $j=$i;
  3049. $l=0;
  3050. $ns=0;
  3051. $nl++;
  3052. if($border and $nl==2) $b=$b2;
  3053. continue;
  3054. }
  3055. if($c == " ") { // mPDF 4.4.012
  3056. $sep=$i;
  3057. $ls=$l;
  3058. $ns++;
  3059. }
  3060. // Modified by Ivan Tcholakov, 28-JAN-2010.
  3061. //$l = $this->GetStringWidth(mb_substr($s, $j, $i-$j,$this->mb_enc ));
  3062. $l = $this->GetStringWidth(api_substr($s, $j, $i-$j,$this->mb_enc ));
  3063. //
  3064. if($l>$wmax) {
  3065. //Automatic line break
  3066. if($sep==-1) { // Only one word
  3067. if($i==$j) $i++;
  3068. // WORD SPACING
  3069. // mPDF 4.0
  3070. $this->ResetSpacing();
  3071. // Modified by Ivan Tcholakov, 28-JUN-2010.
  3072. //$tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc)); // mPDF 4.4.012
  3073. $tmp = rtrim(api_substr($s,$j,$i-$j,$this->mb_enc)); // mPDF 4.4.012
  3074. //
  3075. // DIRECTIONALITY
  3076. $this->magic_reverse_dir($tmp); // *RTL*
  3077. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3078. }
  3079. else {
  3080. // Modified by Ivan Tcholakov, 28-JUN-2010.
  3081. //$tmp = rtrim(mb_substr($s,$j,$sep-$j,$this->mb_enc)); // mPDF 4.4.012
  3082. $tmp = rtrim(api_substr($s,$j,$sep-$j,$this->mb_enc)); // mPDF 4.4.012
  3083. //
  3084. if($align=='J') {
  3085. //$this->ws=($ns>1) ? ((($wmax-$ls)/($ns-1))) : 0;
  3086. //$this->_out(sprintf('%.3f Tw',$this->ws*$this->k));
  3087. //////////////////////////////////////////
  3088. // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
  3089. // WORD SPACING UNICODE
  3090. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
  3091. $tmp = str_replace($this->chrs[194].$this->chrs[160],$this->chrs[32],$tmp );
  3092. $len_ligne = $this->GetStringWidth($tmp );
  3093. // Modified by Ivan Tcholakov, 28-JAN-2010.
  3094. //$nb_carac = mb_strlen( $tmp , $this->mb_enc ) ;
  3095. //$nb_spaces = mb_substr_count( $tmp ,' ', $this->mb_enc ) ;
  3096. $nb_carac = api_strlen( $tmp , $this->mb_enc ) ;
  3097. $nb_spaces = api_substr_count( $tmp ,' ', $this->mb_enc ) ;
  3098. //
  3099. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($w-2) - $len_ligne) * $this->k));
  3100. // mPDF 4.0
  3101. $this->SetSpacing($charspacing,$ws);
  3102. //////////////////////////////////////////
  3103. }
  3104. // DIRECTIONALITY
  3105. $this->magic_reverse_dir($tmp); // *RTL*
  3106. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3107. $i=$sep+1;
  3108. }
  3109. $sep=-1;
  3110. $j=$i;
  3111. $l=0;
  3112. $ns=0;
  3113. $nl++;
  3114. if($border and $nl==2) $b=$b2;
  3115. }
  3116. else $i++;
  3117. }
  3118. //Last chunk
  3119. // WORD SPACING
  3120. // mPDF 4.0
  3121. $this->ResetSpacing();
  3122. }
  3123. else {
  3124. /*-- END UNICODE-FONTS --*/
  3125. while($i<$nb) {
  3126. //Get next character
  3127. $c=$s[$i]; // mPDF 4.4.012
  3128. if($c == "\n") { // mPDF 4.4.012
  3129. //Explicit line break
  3130. // WORD SPACING
  3131. // mPDF 4.0
  3132. $this->ResetSpacing();
  3133. $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link);
  3134. $i++;
  3135. $sep=-1;
  3136. $j=$i;
  3137. $l=0;
  3138. $ns=0;
  3139. $nl++;
  3140. if($border and $nl==2) $b=$b2;
  3141. continue;
  3142. }
  3143. if($c == " ") { // mPDF 4.4.012
  3144. $sep=$i;
  3145. $ls=$l;
  3146. $ns++;
  3147. }
  3148. $l+=$cw[$c];
  3149. if($l>$wmax) {
  3150. //Automatic line break
  3151. if($sep==-1) {
  3152. if($i==$j) $i++;
  3153. // WORD SPACING
  3154. // mPDF 4.0
  3155. $this->ResetSpacing();
  3156. $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link);
  3157. }
  3158. else {
  3159. if($align=='J') {
  3160. $tmp = rtrim(substr($s,$j,$sep-$j));
  3161. //////////////////////////////////////////
  3162. // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
  3163. // WORD SPACING NON_UNICDOE/CJK
  3164. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
  3165. $tmp = str_replace($this->chrs[160],$this->chrs[32],$tmp);
  3166. $len_ligne = $this->GetStringWidth($tmp );
  3167. $nb_carac = strlen( $tmp ) ;
  3168. $nb_spaces = substr_count( $tmp ,' ' ) ;
  3169. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($w-2) - $len_ligne) * $this->k));
  3170. // mPDF 4.0
  3171. $this->SetSpacing($charspacing,$ws);
  3172. //////////////////////////////////////////
  3173. }
  3174. $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill,$link);
  3175. $i=$sep+1;
  3176. }
  3177. $sep=-1;
  3178. $j=$i;
  3179. $l=0;
  3180. $ns=0;
  3181. $nl++;
  3182. if($border and $nl==2) $b=$b2;
  3183. }
  3184. else $i++;
  3185. }
  3186. //Last chunk
  3187. // WORD SPACING
  3188. // mPDF 4.0
  3189. $this->ResetSpacing();
  3190. } // *UNICODE-FONTS*
  3191. //Last chunk
  3192. if($border and is_int(strpos($border,'B'))) $b.='B';
  3193. if ($this->is_MB) {
  3194. // Modified by Ivan Tcholakov, 28-JUN-2010.
  3195. //$tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc)); // mPDF 4.4.012
  3196. $tmp = rtrim(api_substr($s,$j,$i-$j,$this->mb_enc)); // mPDF 4.4.012
  3197. //
  3198. // DIRECTIONALITY
  3199. $this->magic_reverse_dir($tmp); // *RTL*
  3200. $this->Cell($w,$h,$tmp,$b,2,$align,$fill,$link);
  3201. }
  3202. else { $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link); }
  3203. $this->x=$this->lMargin;
  3204. }
  3205. /*-- DIRECTW --*/
  3206. function Write($h,$txt,$currentx=0,$link='',$directionality='ltr',$align='') {
  3207. if (!$align) { $align = $this->defaultAlign; } // NB Cannot use Align=J or C using Write??
  3208. if ($h == 0) { $this->SetLineHeight(); $h = $this->lineheight; }
  3209. //Output text in flowing mode
  3210. $cw = &$this->CurrentFont['cw'];
  3211. $w = $this->w - $this->rMargin - $this->x;
  3212. /*-- UNICODE-FONTS --*/
  3213. if ($this->is_MB) {
  3214. $wmax = ($w - ($this->cMarginL+$this->cMarginR));
  3215. $s=str_replace("\r",'',$txt); // mPDF 4.4.012
  3216. // Modified by Ivan Tcholakov, 28-JAN-2010.
  3217. //$nb=mb_strlen($s, $this->mb_enc );
  3218. $nb=api_strlen($s, $this->mb_enc );
  3219. //
  3220. // handle single space character
  3221. if(($nb==1) && $s == " ") { // mPDF 4.4.012
  3222. $this->x += $this->GetStringWidth($s);
  3223. return;
  3224. }
  3225. }
  3226. else {
  3227. /*-- END UNICODE-FONTS --*/
  3228. $wmax=($w- ($this->cMarginL+$this->cMarginR))*1000/$this->FontSize;
  3229. $s=str_replace("\r",'',$txt);
  3230. $nb=strlen($s);
  3231. } // *UNICODE-FONTS*
  3232. $sep=-1;
  3233. $i=0;
  3234. $j=0;
  3235. $l=0;
  3236. $nl=1;
  3237. /*-- UNICODE-FONTS --*/
  3238. if ($this->is_MB) {
  3239. while($i<$nb) {
  3240. //Get next character
  3241. // Modified by Ivan Tcholakov, 28-JAN-2010.
  3242. //$c = mb_substr($s,$i,1,$this->mb_enc );
  3243. $c = api_substr($s,$i,1,$this->mb_enc );
  3244. //
  3245. if($c == "\n") { // mPDF 4.4.012
  3246. // WORD SPACING
  3247. // mPDF 4.0
  3248. $this->ResetSpacing();
  3249. //Explicit line break
  3250. // Modified by Ivan Tcholakov, 28-JUN-2010.
  3251. //$tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc)); // mPDF 4.4.012
  3252. $tmp = rtrim(api_substr($s,$j,$i-$j,$this->mb_enc)); // mPDF 4.4.012
  3253. //
  3254. if ($this->directionality == 'rtl') { // *RTL*
  3255. if ($align == 'J') { $align = 'R'; } // *RTL*
  3256. } // *RTL*
  3257. // DIRECTIONALITY
  3258. $this->magic_reverse_dir($tmp); // *RTL*
  3259. $this->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
  3260. $i++;
  3261. $sep = -1;
  3262. $j = $i;
  3263. $l = 0;
  3264. if($nl == 1) {
  3265. if ($currentx != 0) $this->x=$currentx;
  3266. else $this->x=$this->lMargin;
  3267. $w = $this->w - $this->rMargin - $this->x;
  3268. $wmax = ($w - ($this->cMarginL+$this->cMarginR));
  3269. }
  3270. $nl++;
  3271. continue;
  3272. }
  3273. if($c == " ") { // mPDF 4.4.012
  3274. $sep= $i;
  3275. }
  3276. // Modified by Ivan Tcholakov, 28-JAN-2010.
  3277. //$l = $this->GetStringWidth(mb_substr($s, $j, $i-$j,$this->mb_enc));
  3278. $l = $this->GetStringWidth(api_substr($s, $j, $i-$j,$this->mb_enc));
  3279. //
  3280. if($l > $wmax) {
  3281. //Automatic line break (word wrapping)
  3282. if($sep == -1) {
  3283. // WORD SPACING
  3284. // mPDF 4.0
  3285. $this->ResetSpacing();
  3286. if($this->x > $this->lMargin) {
  3287. //Move to next line
  3288. if ($currentx != 0) $this->x=$currentx;
  3289. else $this->x=$this->lMargin;
  3290. $this->y+=$h;
  3291. $w=$this->w-$this->rMargin-$this->x;
  3292. $wmax = ($w - ($this->cMarginL+$this->cMarginR));
  3293. $i++;
  3294. $nl++;
  3295. continue;
  3296. }
  3297. if($i==$j) {
  3298. $i++;
  3299. }
  3300. // Modified by Ivan Tcholakov, 28-JUN-2010.
  3301. //$tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mb_enc)); // mPDF 4.4.012
  3302. $tmp = rtrim(api_substr($s,$j,$i-$j,$this->mb_enc)); // mPDF 4.4.012
  3303. //
  3304. if ($this->directionality == 'rtl') { // *RTL*
  3305. if ($align == 'J') { $align = 'R'; } // *RTL*
  3306. } // *RTL*
  3307. // DIRECTIONALITY
  3308. $this->magic_reverse_dir($tmp); // *RTL*
  3309. $this->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
  3310. }
  3311. else {
  3312. // Modified by Ivan Tcholakov, 28-JUN-2010.
  3313. //$tmp = rtrim(mb_substr($s,$j,$sep-$j,$this->mb_enc)); // mPDF 4.4.012
  3314. $tmp = rtrim(api_substr($s,$j,$sep-$j,$this->mb_enc)); // mPDF 4.4.012
  3315. //
  3316. if ($this->directionality == 'rtl') { // *RTL*
  3317. if ($align == 'J') { $align = 'R'; } // *RTL*
  3318. } // *RTL*
  3319. // DIRECTIONALITY
  3320. $this->magic_reverse_dir($tmp); // *RTL*
  3321. if($align=='J') {
  3322. //////////////////////////////////////////
  3323. // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
  3324. // WORD SPACING
  3325. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
  3326. $tmp = str_replace($this->chrs[194].$this->chrs[160],$this->chrs[32],$tmp );
  3327. $len_ligne = $this->GetStringWidth($tmp );
  3328. // Modified by Ivan Tcholakov, 28-JAN-2010.
  3329. //$nb_carac = mb_strlen( $tmp , $this->mb_enc ) ;
  3330. //$nb_spaces = mb_substr_count( $tmp ,' ', $this->mb_enc ) ;
  3331. $nb_carac = api_strlen( $tmp , $this->mb_enc ) ;
  3332. $nb_spaces = api_substr_count( $tmp ,' ', $this->mb_enc ) ;
  3333. //
  3334. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($w-2) - $len_ligne) * $this->k));
  3335. // mPDF 4.0
  3336. $this->SetSpacing($charspacing,$ws);
  3337. //////////////////////////////////////////
  3338. }
  3339. $this->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
  3340. $i=$sep+1;
  3341. }
  3342. $sep = -1;
  3343. $j = $i;
  3344. $l = 0;
  3345. if($nl==1) {
  3346. if ($currentx != 0) $this->x=$currentx;
  3347. else $this->x=$this->lMargin;
  3348. $w=$this->w-$this->rMargin-$this->x;
  3349. $wmax = ($w - ($this->cMarginL+$this->cMarginR));
  3350. }
  3351. $nl++;
  3352. }
  3353. else {
  3354. $i++;
  3355. }
  3356. }
  3357. //Last chunk
  3358. // WORD SPACING
  3359. // mPDF 4.0
  3360. $this->ResetSpacing();
  3361. }
  3362. else {
  3363. /*-- END UNICODE-FONTS --*/
  3364. while($i<$nb) {
  3365. //Get next character
  3366. $c=$s[$i]; // mPDF 4.4.012
  3367. if($c == "\n") { // mPDF 4.4.012
  3368. //Explicit line break
  3369. // WORD SPACING
  3370. // mPDF 4.0
  3371. $this->ResetSpacing();
  3372. $this->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, $align, $fill, $link);
  3373. $i++;
  3374. $sep = -1;
  3375. $j = $i;
  3376. $l = 0;
  3377. if($nl == 1) {
  3378. if ($currentx != 0) $this->x=$currentx;
  3379. else $this->x=$this->lMargin;
  3380. $w = $this->w - $this->rMargin - $this->x;
  3381. $wmax=($w-($this->cMarginL+$this->cMarginR))*1000/$this->FontSize;
  3382. }
  3383. $nl++;
  3384. continue;
  3385. }
  3386. if($c == " ") { // mPDF 4.4.012
  3387. $sep= $i;
  3388. }
  3389. $l += $cw[$c];
  3390. if($l > $wmax) {
  3391. //Automatic line break (word wrapping)
  3392. if($sep == -1) {
  3393. // WORD SPACING
  3394. // mPDF 4.0
  3395. $this->ResetSpacing();
  3396. if($this->x > $this->lMargin) {
  3397. //Move to next line
  3398. if ($currentx != 0) $this->x=$currentx;
  3399. else $this->x=$this->lMargin;
  3400. $this->y+=$h;
  3401. $w=$this->w-$this->rMargin-$this->x;
  3402. $wmax=($w-($this->cMarginL+$this->cMarginR))*1000/$this->FontSize;
  3403. $i++;
  3404. $nl++;
  3405. continue;
  3406. }
  3407. if($i==$j) {
  3408. $i++;
  3409. }
  3410. $this->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, $align, $fill, $link);
  3411. }
  3412. else {
  3413. $tmp = substr($s, $j, $sep-$j);
  3414. if($align=='J') {
  3415. //////////////////////////////////////////
  3416. // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
  3417. // WORD SPACING
  3418. // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
  3419. $tmp = str_replace($this->chrs[160],$this->chrs[32],$tmp );
  3420. $len_ligne = $this->GetStringWidth($tmp );
  3421. $nb_carac = strlen( $tmp ) ;
  3422. $nb_spaces = substr_count( $tmp ,' ' ) ;
  3423. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,((($w-2) - $len_ligne) * $this->k));
  3424. // mPDF 4.0
  3425. $this->SetSpacing($charspacing,$ws);
  3426. //////////////////////////////////////////
  3427. }
  3428. $this->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
  3429. $i=$sep+1;
  3430. }
  3431. $sep = -1;
  3432. $j = $i;
  3433. $l = 0;
  3434. if($nl==1) {
  3435. if ($currentx != 0) $this->x=$currentx;
  3436. else $this->x=$this->lMargin;
  3437. $w=$this->w-$this->rMargin-$this->x;
  3438. $wmax=($w-($this->cMarginL+$this->cMarginR))*1000/$this->FontSize;
  3439. }
  3440. $nl++;
  3441. }
  3442. else {
  3443. $i++;
  3444. }
  3445. }
  3446. //Last chunk
  3447. // WORD SPACING
  3448. // mPDF 4.0
  3449. $this->ResetSpacing();
  3450. } // *UNICODE-FONTS*
  3451. //Last chunk
  3452. if($i!=$j) {
  3453. // mPDF 4.0
  3454. if ($currentx != 0) $this->mpdf->x=$currentx;
  3455. else $this->mpdf->x=$this->mpdf->lMargin + $this->mpdf->cMarginL;
  3456. /*-- UNICODE-FONTS --*/
  3457. if (($this->is_MB) && (!$this->usingCoreFont)) {
  3458. // Modified by Ivan Tcholakov, 28-JAN-2010.
  3459. //$tmp = mb_substr($s,$j,$i-$j,$this->mb_enc);
  3460. $tmp = api_substr($s,$j,$i-$j,$this->mb_enc);
  3461. //
  3462. if ($this->directionality == 'rtl') { // *RTL*
  3463. if ($align == 'J') { $align = 'R'; } // *RTL*
  3464. } // *RTL*
  3465. // DIRECTIONALITY
  3466. $this->magic_reverse_dir($tmp); // *RTL*
  3467. }
  3468. else {
  3469. /*-- END UNICODE-FONTS --*/
  3470. $tmp = substr($s,$j,$i-$j); // Including CJK which has processed each byte (not multibyte)
  3471. } // *UNICODE-FONTS*
  3472. $this->Cell($this->GetStringWidth($tmp),$h,$tmp,0,0,'C',$fill,$link);
  3473. }
  3474. }
  3475. /*-- END DIRECTW --*/
  3476. function saveInlineProperties() {
  3477. $saved = array();
  3478. $saved[ 'family' ] = $this->FontFamily;
  3479. $saved[ 'style' ] = $this->FontStyle;
  3480. $saved[ 'sizePt' ] = $this->FontSizePt;
  3481. $saved[ 'size' ] = $this->FontSize;
  3482. $saved[ 'HREF' ] = $this->HREF;
  3483. $saved[ 'underline' ] = $this->underline;
  3484. $saved[ 'strike' ] = $this->strike;
  3485. $saved[ 'SUP' ] = $this->SUP;
  3486. $saved[ 'SUB' ] = $this->SUB;
  3487. $saved[ 'linewidth' ] = $this->LineWidth;
  3488. $saved[ 'drawcolor' ] = $this->DrawColor;
  3489. $saved[ 'is_outline' ] = $this->outline_on;
  3490. $saved[ 'outlineparam' ] = $this->outlineparam;
  3491. $saved[ 'toupper' ] = $this->toupper;
  3492. $saved[ 'tolower' ] = $this->tolower;
  3493. $saved[ 'I' ] = $this->I;
  3494. $saved[ 'B' ] = $this->B;
  3495. $saved[ 'colorarray' ] = $this->colorarray;
  3496. $saved[ 'bgcolorarray' ] = $this->spanbgcolorarray;
  3497. $saved[ 'color' ] = $this->TextColor;
  3498. $saved[ 'bgcolor' ] = $this->FillColor;
  3499. $saved['lang'] = $this->currentLang;
  3500. return $saved;
  3501. }
  3502. function restoreInlineProperties( $saved) {
  3503. // mPDF 4.0 $this->FontFamily Resets below - don't change here - change via SetFont()
  3504. // or it will not change $this->CurrentFont
  3505. //$this->FontFamily = $saved[ 'family' ];
  3506. $FontFamily = $saved[ 'family' ];
  3507. $this->FontStyle = $saved[ 'style' ];
  3508. $this->FontSizePt = $saved[ 'sizePt' ];
  3509. $this->FontSize = $saved[ 'size' ];
  3510. $this->currentLang = $saved['lang'];
  3511. /*-- UNICODE-FONTS --*/
  3512. if ($this->useLang && $this->is_MB && $this->currentLang != $this->default_lang && ((strlen($this->currentLang) == 5 && $this->currentLang != 'UTF-8') || strlen($this->currentLang ) == 2)) {
  3513. list ($codepage,$mpdf_pdf_unifonts,$mpdf_directionality,$mpdf_jSpacing) = GetCodepage($this->currentLang);
  3514. if ($codepage == 'SHIFT_JIS') { $FontFamily = 'sjis'; } // mPDF 4.0 see above
  3515. else if ($codepage == 'UHC') { $FontFamily = 'uhc'; } // mPDF 4.0 see above
  3516. else if ($codepage == 'BIG5') { $FontFamily = 'big5'; } // mPDF 4.0 see above
  3517. else if ($codepage == 'GBK') { $FontFamily = 'gb'; } // mPDF 4.0 see above
  3518. else if ($mpdf_pdf_unifonts) { $this->RestrictUnicodeFonts($mpdf_pdf_unifonts); }
  3519. else { $this->RestrictUnicodeFonts($this->default_available_fonts ); }
  3520. }
  3521. else if ($this->useLang && $this->is_MB ) {
  3522. $this->RestrictUnicodeFonts($this->default_available_fonts );
  3523. }
  3524. /*-- END UNICODE-FONTS --*/
  3525. $this->ColorFlag = ($this->FillColor != $this->TextColor); //Restore ColorFlag as well
  3526. $this->HREF = $saved[ 'HREF' ];
  3527. $this->underline = $saved[ 'underline' ];
  3528. $this->strike = $saved[ 'strike' ];
  3529. $this->SUP = $saved[ 'SUP' ];
  3530. $this->SUB = $saved[ 'SUB' ];
  3531. $this->LineWidth = $saved[ 'linewidth' ];
  3532. $this->DrawColor = $saved[ 'drawcolor' ];
  3533. $this->outline_on = $saved[ 'is_outline' ];
  3534. $this->outlineparam = $saved[ 'outlineparam' ];
  3535. $this->toupper = $saved[ 'toupper' ];
  3536. $this->tolower = $saved[ 'tolower' ];
  3537. // mPDF 4.0
  3538. $this->SetFont($FontFamily, $saved[ 'style' ].($this->underline ? 'U' : ''),$saved[ 'sizePt' ],false);
  3539. //$this->currentfontfamily = $saved[ 'family' ];
  3540. $this->currentfontstyle = $saved[ 'style' ].($this->underline ? 'U' : '');
  3541. $this->currentfontsize = $saved[ 'sizePt' ];
  3542. $this->SetStyle('U',$this->underline);
  3543. $this->SetStyle('B',$saved[ 'B' ]);
  3544. $this->SetStyle('I',$saved[ 'I' ]);
  3545. $this->TextColor = $saved[ 'color' ];
  3546. $this->FillColor = $saved[ 'bgcolor' ];
  3547. $this->colorarray = $saved[ 'colorarray' ];
  3548. $cor = $saved[ 'colorarray' ];
  3549. if ($cor) $this->SetTextColor($cor['R'],$cor['G'],$cor['B']);
  3550. $this->spanbgcolorarray = $saved[ 'bgcolorarray' ];
  3551. $cor = $saved[ 'bgcolorarray' ];
  3552. if ($cor) $this->SetFillColor($cor['R'],$cor['G'],$cor['B']);
  3553. }
  3554. // mPDF 3.0
  3555. // Used when ColActive for tables - updated to return first block with background fill OR borders
  3556. function GetFirstBlockFill() {
  3557. // Returns the first blocklevel that uses a bgcolor fill
  3558. $startfill = 0;
  3559. for ($i=1;$i<=$this->blklvl;$i++) {
  3560. 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'] ) {
  3561. $startfill = $i;
  3562. break;
  3563. }
  3564. }
  3565. return $startfill;
  3566. }
  3567. function SetBlockFill($blvl) {
  3568. if ($this->blk[$blvl]['bgcolor']) {
  3569. $this->SetFillColor($this->blk[$blvl]['bgcolorarray']['R'],$this->blk[$blvl]['bgcolorarray']['G'],$this->blk[$blvl]['bgcolorarray']['B']);
  3570. return 1;
  3571. }
  3572. else {
  3573. $this->SetFillColor(255);
  3574. return 0;
  3575. }
  3576. }
  3577. //-------------------------FLOWING BLOCK------------------------------------//
  3578. //The following functions were originally written by Damon Kohler //
  3579. //--------------------------------------------------------------------------//
  3580. function saveFont() {
  3581. $saved = array();
  3582. $saved[ 'family' ] = $this->FontFamily;
  3583. $saved[ 'style' ] = $this->FontStyle;
  3584. $saved[ 'sizePt' ] = $this->FontSizePt;
  3585. $saved[ 'size' ] = $this->FontSize;
  3586. $saved[ 'curr' ] = &$this->CurrentFont;
  3587. $saved[ 'color' ] = $this->TextColor;
  3588. $saved[ 'spanbgcolor' ] = $this->spanbgcolor;
  3589. $saved[ 'spanbgcolorarray' ] = $this->spanbgcolorarray;
  3590. $saved[ 'HREF' ] = $this->HREF;
  3591. $saved[ 'underline' ] = $this->underline;
  3592. $saved[ 'strike' ] = $this->strike;
  3593. $saved[ 'SUP' ] = $this->SUP;
  3594. $saved[ 'SUB' ] = $this->SUB;
  3595. $saved[ 'linewidth' ] = $this->LineWidth;
  3596. $saved[ 'drawcolor' ] = $this->DrawColor;
  3597. $saved[ 'is_outline' ] = $this->outline_on;
  3598. $saved[ 'outlineparam' ] = $this->outlineparam;
  3599. // mPDF 4.2
  3600. $saved[ 'ReqFontStyle' ] = $this->ReqFontStyle;
  3601. return $saved;
  3602. }
  3603. function restoreFont( $saved, $write=true) {
  3604. if (!isset($saved) || empty($saved)) return;
  3605. $this->FontFamily = $saved[ 'family' ];
  3606. $this->FontStyle = $saved[ 'style' ];
  3607. $this->FontSizePt = $saved[ 'sizePt' ];
  3608. $this->FontSize = $saved[ 'size' ];
  3609. $this->CurrentFont = &$saved[ 'curr' ];
  3610. $this->TextColor = $saved[ 'color' ];
  3611. $this->spanbgcolor = $saved[ 'spanbgcolor' ];
  3612. $this->spanbgcolorarray = $saved[ 'spanbgcolorarray' ];
  3613. $this->ColorFlag = ($this->FillColor != $this->TextColor); //Restore ColorFlag as well
  3614. $this->HREF = $saved[ 'HREF' ];
  3615. $this->underline = $saved[ 'underline' ];
  3616. $this->strike = $saved[ 'strike' ];
  3617. $this->SUP = $saved[ 'SUP' ];
  3618. $this->SUB = $saved[ 'SUB' ];
  3619. $this->LineWidth = $saved[ 'linewidth' ];
  3620. $this->DrawColor = $saved[ 'drawcolor' ];
  3621. $this->outline_on = $saved[ 'is_outline' ];
  3622. $this->outlineparam = $saved[ 'outlineparam' ];
  3623. if ($write) {
  3624. $this->SetFont($saved[ 'family' ],$saved[ 'style' ].($this->underline ? 'U' : ''),$saved[ 'sizePt' ],true,true); // force output
  3625. $fontout = (sprintf('BT /F%d %.3f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  3626. 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); }
  3627. $this->pageoutput[$this->page]['Font'] = $fontout;
  3628. }
  3629. else
  3630. $this->SetFont($saved[ 'family' ],$saved[ 'style' ].($this->underline ? 'U' : ''),$saved[ 'sizePt' ]);
  3631. // mPDF 4.2
  3632. $this->ReqFontStyle = $saved[ 'ReqFontStyle' ];
  3633. }
  3634. function newFlowingBlock( $w, $h, $a = '', $is_table = false, $is_list = false, $blockstate = 0, $newblock=true )
  3635. {
  3636. if (!$a) { $a = $this->defaultAlign; }
  3637. // cell width in points
  3638. $this->flowingBlockAttr[ 'width' ] = ($w * $this->k);
  3639. // line height in user units
  3640. $this->flowingBlockAttr[ 'is_table' ] = $is_table;
  3641. $this->flowingBlockAttr[ 'is_list' ] = $is_list;
  3642. $this->flowingBlockAttr[ 'height' ] = $h;
  3643. $this->flowingBlockAttr[ 'lineCount' ] = 0;
  3644. $this->flowingBlockAttr[ 'align' ] = $a;
  3645. $this->flowingBlockAttr[ 'font' ] = array();
  3646. $this->flowingBlockAttr[ 'content' ] = array();
  3647. $this->flowingBlockAttr[ 'contentWidth' ] = 0;
  3648. $this->flowingBlockAttr[ 'blockstate' ] = $blockstate;
  3649. $this->flowingBlockAttr[ 'newblock' ] = $newblock;
  3650. $this->flowingBlockAttr[ 'valign' ] = 'M';
  3651. }
  3652. function finishFlowingBlock($endofblock=false, $next='') { // mPDF 4.3.003
  3653. $currentx = $this->x;
  3654. //prints out the last chunk
  3655. $is_table = $this->flowingBlockAttr[ 'is_table' ];
  3656. $is_list = $this->flowingBlockAttr[ 'is_list' ];
  3657. $maxWidth =& $this->flowingBlockAttr[ 'width' ];
  3658. $lineHeight =& $this->flowingBlockAttr[ 'height' ];
  3659. $align =& $this->flowingBlockAttr[ 'align' ];
  3660. $content =& $this->flowingBlockAttr[ 'content' ];
  3661. $font =& $this->flowingBlockAttr[ 'font' ];
  3662. $contentWidth =& $this->flowingBlockAttr[ 'contentWidth' ];
  3663. $lineCount =& $this->flowingBlockAttr[ 'lineCount' ];
  3664. $valign =& $this->flowingBlockAttr[ 'valign' ];
  3665. $blockstate = $this->flowingBlockAttr[ 'blockstate' ];
  3666. $newblock = $this->flowingBlockAttr[ 'newblock' ];
  3667. // *********** BLOCK BACKGROUND COLOR *****************//
  3668. if ($this->blk[$this->blklvl]['bgcolor'] && !$is_table) {
  3669. // mPDF 3.0 - Tiling Patterns
  3670. $fill = 0;
  3671. // $fill = 1;
  3672. // $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  3673. // $this->SetFillColor($bcor['R'],$bcor['G'],$bcor['B']);
  3674. }
  3675. else {
  3676. $this->SetFillColor(255);
  3677. $fill = 0;
  3678. }
  3679. // mPDF 4.0
  3680. // if ($this->ws != 0) { $this->_out('BT 0 Tw ET'); }
  3681. // $this->ws=0;
  3682. // if ($this->charspacing != 0) { $this->_out('BT 0 Tc ET'); }
  3683. // $this->charspacing=0;
  3684. // mPDF 4.3.003
  3685. // Right trim content and adjust width if need to justify (later)
  3686. if (!$endofblock && $align=='J' && ($next=='image' || $next=='select' || $next=='input' || $next=='textarea' || ($next=='br' && $this->justifyB4br))) {
  3687. if (preg_match('/[ ]+$/',$content[count($content)-1], $m)) {
  3688. $strip = strlen($m[0]);
  3689. $content[count($content)-1] = substr($content[count($content)-1],0,(strlen($content[count($content)-1])-$strip));
  3690. $this->restoreFont( $font[ count($content)-1 ],false );
  3691. $contentWidth -= $this->GetStringWidth($m[0]) * $this->k;
  3692. }
  3693. }
  3694. // the amount of space taken up so far in user units
  3695. $usedWidth = 0;
  3696. // COLS
  3697. $oldcolumn = $this->CurrCol;
  3698. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  3699. // Print out each chunk
  3700. /*-- TABLES --*/
  3701. if ($is_table) {
  3702. $ipaddingL = 0;
  3703. $ipaddingR = 0;
  3704. $paddingL = 0;
  3705. $paddingR = 0;
  3706. }
  3707. else {
  3708. /*-- END TABLES --*/
  3709. $ipaddingL = $this->blk[$this->blklvl]['padding_left'];
  3710. $ipaddingR = $this->blk[$this->blklvl]['padding_right'];
  3711. $paddingL = ($ipaddingL * $this->k);
  3712. $paddingR = ($ipaddingR * $this->k);
  3713. $this->cMarginL = $this->blk[$this->blklvl]['border_left']['w'];
  3714. $this->cMarginR = $this->blk[$this->blklvl]['border_right']['w'];
  3715. // Added mPDF 3.0 Float DIV
  3716. $fpaddingR = 0;
  3717. $fpaddingL = 0;
  3718. /*-- CSS-FLOAT --*/
  3719. if (count($this->floatDivs)) {
  3720. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  3721. if ($r_exists) { $fpaddingR = $r_width; }
  3722. if ($l_exists) { $fpaddingL = $l_width; }
  3723. }
  3724. /*-- END CSS-FLOAT --*/
  3725. $usey = $this->y + 0.002;
  3726. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  3727. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  3728. }
  3729. /*-- CSS-IMAGE-FLOAT --*/
  3730. // If float exists at this level
  3731. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  3732. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  3733. /*-- END CSS-IMAGE-FLOAT --*/
  3734. } // *TABLES*
  3735. // Set Current lineheight (correction factor)
  3736. $lhfixed = false;
  3737. /*-- LISTS --*/
  3738. if ($is_list) {
  3739. if (preg_match('/([0-9.,]+)mm/',$this->list_lineheight[$this->listlvl][$this->listOcc],$am)) {
  3740. $lhfixed = true;
  3741. $def_fontsize = $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listOcc][$this->listnum]['size'];
  3742. $this->lineheight_correction = $am[1] / $def_fontsize ;
  3743. }
  3744. else {
  3745. $this->lineheight_correction = $this->list_lineheight[$this->listlvl][$this->listOcc];
  3746. }
  3747. }
  3748. else
  3749. /*-- END LISTS --*/
  3750. /*-- TABLES --*/
  3751. if ($is_table) {
  3752. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight,$am)) {
  3753. $lhfixed = true;
  3754. $def_fontsize = $this->FontSize; // needs to be default font-size for block ****
  3755. $this->lineheight_correction = $lineHeight / $def_fontsize ;
  3756. }
  3757. else {
  3758. $this->lineheight_correction = $this->table_lineheight;
  3759. }
  3760. }
  3761. else
  3762. /*-- END TABLES --*/
  3763. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  3764. if (preg_match('/([0-9.,]+)mm/',$this->blk[$this->blklvl]['line_height'],$am)) {
  3765. $lhfixed = true;
  3766. $def_fontsize = $this->blk[$this->blklvl]['InlineProperties']['size']; // needs to be default font-size for block ****
  3767. $this->lineheight_correction = $am[1] / $def_fontsize ;
  3768. }
  3769. else {
  3770. $this->lineheight_correction = $this->blk[$this->blklvl]['line_height'];
  3771. }
  3772. }
  3773. else {
  3774. $this->lineheight_correction = $this->normalLineheight;
  3775. }
  3776. // mPDF 4.2
  3777. // correct lineheight to maximum fontsize
  3778. if ($lhfixed) { $maxlineHeight = $this->lineheight; }
  3779. else { $maxlineHeight = 0; }
  3780. $this->forceExactLineheight = true;
  3781. $maxfontsize = 0;
  3782. foreach ( $content as $k => $chunk )
  3783. {
  3784. $this->restoreFont( $font[ $k ],false );
  3785. if (!isset($this->objectbuffer[$k])) {
  3786. /*-- UNICODE-FONTS --*/
  3787. if ($this->is_MB) {
  3788. $content[$k] = $chunk = str_replace("\xc2\xad",'',$chunk );
  3789. }
  3790. // mPDF 3.0 Soft Hyphens chr(173)
  3791. else
  3792. /*-- END UNICODE-FONTS --*/
  3793. if ($this->FontFamily!='symbol' && $this->FontFamily!='zapfdingbats') {
  3794. $content[$k] = $chunk = str_replace($this->chrs[173],'',$chunk );
  3795. }
  3796. // Special case of sub/sup carried over on its own to last line
  3797. if (($this->SUB || $this->SUP) && count($content)==1) { $actfs = $this->FontSize*100/55; } // 55% is font change for sub/sup
  3798. else { $actfs = $this->FontSize; }
  3799. // mPDF 4.2
  3800. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); }
  3801. if ($lhfixed && ($actfs > $def_fontsize || ($actfs > ($lineHeight * $this->lineheight_correction) && $is_list))) {
  3802. $this->forceExactLineheight = false;
  3803. }
  3804. $maxfontsize = max($maxfontsize,$actfs);
  3805. }
  3806. }
  3807. // mPDF 4.2 $lastitalic to shorten if line ends with artificial ITALIC
  3808. $lastfontreqstyle = $font[count($font)-1]['ReqFontStyle'];
  3809. $lastfontstyle = $font[count($font)-1]['style'];
  3810. if ($this->directionality == 'ltr' && strpos($lastfontreqstyle,"I") !== false && strpos($lastfontstyle,"I") === false) { // Artificial italic
  3811. $lastitalic = $this->FontSize*0.15*$this->k;
  3812. }
  3813. else { $lastitalic = 0; }
  3814. /*-- LISTS --*/
  3815. // mPDF 4.2 Moved here from later
  3816. if ($is_list && is_array($this->bulletarray) && count($this->bulletarray)) {
  3817. $actfs = $this->bulletarray['fontsize'];
  3818. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); } // mPDF 4.2
  3819. if ($lhfixed && $actfs > $def_fontsize) { $this->forceExactLineheight = false; }
  3820. $maxfontsize = max($maxfontsize,$actfs);
  3821. }
  3822. /*-- END LISTS --*/
  3823. // when every text item checked i.e. $maxfontsize is set properly
  3824. $af = 0; // Above font
  3825. $bf = 0; // Below font
  3826. $mta = 0; // Maximum top-aligned
  3827. $mba = 0; // Maximum bottom-aligned
  3828. foreach ( $content as $k => $chunk )
  3829. {
  3830. if (isset($this->objectbuffer[$k])) {
  3831. $oh = $this->objectbuffer[$k]['OUTER-HEIGHT'];
  3832. $va = $this->objectbuffer[$k]['vertical-align']; // = $objattr['vertical-align'] = set as M,T,B,S
  3833. if ($lhfixed && $oh > $def_fontsize) { $this->forceExactLineheight = false; }
  3834. if ($va == 'BS') { // (BASELINE default)
  3835. $af = max($af, ($oh - ($maxfontsize * (0.5 + $this->baselineC))));
  3836. }
  3837. else if ($va == 'M') {
  3838. $af = max($af, ($oh - $maxfontsize)/2);
  3839. $bf = max($bf, ($oh - $maxfontsize)/2);
  3840. }
  3841. else if ($va == 'TT') {
  3842. $bf = max($bf, ($oh - $maxfontsize));
  3843. }
  3844. else if ($va == 'TB') {
  3845. $af = max($af, ($oh - $maxfontsize));
  3846. }
  3847. else if ($va == 'T') {
  3848. $mta = max($mta, $oh);
  3849. }
  3850. else if ($va == 'B') {
  3851. $mba = max($mba, $oh);
  3852. }
  3853. }
  3854. }
  3855. if ((!$lhfixed || !$this->forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) {
  3856. $maxlineHeight = $maxfontsize + $af + $bf;
  3857. }
  3858. else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; }
  3859. if ($mta > $maxlineHeight) {
  3860. $bf += ($mta - $maxlineHeight);
  3861. $maxlineHeight = $mta;
  3862. }
  3863. if ($mba > $maxlineHeight) {
  3864. $af += ($mba - $maxlineHeight);
  3865. $maxlineHeight = $mba;
  3866. }
  3867. $lineHeight = $maxlineHeight;
  3868. // mPDF 4.2 If NOT images, and maxfontsize NOT > lineHeight - this value determines text baseline positioning
  3869. if ($lhfixed && $af==0 && $bf==0 && $maxfontsize<=($def_fontsize * $this->lineheight_correction * 0.8 )) {
  3870. $this->linemaxfontsize = $def_fontsize;
  3871. }
  3872. else { $this->linemaxfontsize = $maxfontsize; }
  3873. // Get PAGEBREAK TO TEST for height including the bottom border/padding
  3874. $check_h = max($this->divheight,$lineHeight);
  3875. if ($this->blklvl > 0 && !$is_table) {
  3876. if ($endofblock && $blockstate > 1) {
  3877. if ($this->blk[$this->blklvl]['page_break_after_avoid']) { $check_h += $lineHeight; }
  3878. $check_h += ($this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w']);
  3879. }
  3880. if (($newblock && ($blockstate==1 || $blockstate==3) && $lineCount == 0) || ($endofblock && $blockstate > 1 && $lineCount == 0)) {
  3881. $check_h += ($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['border_top']['w']);
  3882. }
  3883. }
  3884. // mPDF 4.2 Force PAGE break if column height cannot take check-height
  3885. if ($this->ColActive && $check_h > ($this->PageBreakTrigger - $this->y0)) { $this->CurrCol = $this->NbCol; }
  3886. // PAGEBREAK
  3887. //'If' below used in order to fix "first-line of other page with justify on" bug
  3888. // mPDF 4.2.008 Disable in Tables
  3889. if(!$is_table && $this->y+$check_h > $this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) {
  3890. $bak_x=$this->x;//Current X position
  3891. // WORD SPACING
  3892. $ws=$this->ws;//Word Spacing
  3893. $charspacing=$this->charspacing;//Character Spacing
  3894. // mPDF 4.0
  3895. $this->ResetSpacing();
  3896. $this->AddPage($this->CurOrientation);
  3897. $this->x=$bak_x;
  3898. // Added to correct for OddEven Margins
  3899. $currentx += $this->MarginCorrection;
  3900. $this->x += $this->MarginCorrection;
  3901. // WORD SPACING
  3902. // mPDF 4.0
  3903. $this->SetSpacing($charspacing,$ws);
  3904. }
  3905. /*-- COLUMNS --*/
  3906. // COLS
  3907. // COLUMN CHANGE
  3908. if ($this->CurrCol != $oldcolumn) {
  3909. $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  3910. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  3911. $oldcolumn = $this->CurrCol;
  3912. }
  3913. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; }
  3914. /*-- END COLUMNS --*/
  3915. // TOP MARGIN
  3916. if ($newblock && ($blockstate==1 || $blockstate==3) && ($this->blk[$this->blklvl]['margin_top']) && $lineCount == 0 && !$is_table && !$is_list) {
  3917. $this->DivLn($this->blk[$this->blklvl]['margin_top'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']);
  3918. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  3919. }
  3920. if ($newblock && ($blockstate==1 || $blockstate==3) && $lineCount == 0 && !$is_table && !$is_list) {
  3921. $this->blk[$this->blklvl]['y0'] = $this->y;
  3922. $this->blk[$this->blklvl]['startpage'] = $this->page;
  3923. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  3924. }
  3925. // ADDED for Paragraph_indent
  3926. $WidthCorrection = 0;
  3927. if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align != 'C')) {
  3928. // mPDF 4.0
  3929. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  3930. $WidthCorrection = ($ti*$this->k);
  3931. }
  3932. // PADDING and BORDER spacing/fill
  3933. if (($newblock) && ($blockstate==1 || $blockstate==3) && (($this->blk[$this->blklvl]['padding_top']) || ($this->blk[$this->blklvl]['border_top'])) && ($lineCount == 0) && (!$is_table) && (!$is_list)) {
  3934. // mPDF 3.0 Also does border when Columns active
  3935. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  3936. $this->DivLn($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'],-3,true,false,1);
  3937. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  3938. $this->x = $currentx;
  3939. }
  3940. // Added mPDF 3.0 Float DIV
  3941. $fpaddingR = 0;
  3942. $fpaddingL = 0;
  3943. /*-- CSS-FLOAT --*/
  3944. if (count($this->floatDivs)) {
  3945. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  3946. if ($r_exists) { $fpaddingR = $r_width; }
  3947. if ($l_exists) { $fpaddingL = $l_width; }
  3948. }
  3949. /*-- END CSS-FLOAT --*/
  3950. $usey = $this->y + 0.002;
  3951. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  3952. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  3953. }
  3954. /*-- CSS-IMAGE-FLOAT --*/
  3955. // If float exists at this level
  3956. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  3957. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  3958. /*-- END CSS-IMAGE-FLOAT --*/
  3959. if ($content) {
  3960. // mPDF 4.2 $lastitalic to shorten if line ends with artificial ITALIC
  3961. $empty = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* $this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) );
  3962. $empty /= $this->k;
  3963. // In FinishFlowing Block no lines are justified as it is always last line
  3964. // but if orphansAllowed have allowed content width to go over max width, use J charspacing to compress line
  3965. // JUSTIFICATION J - NOT!
  3966. $nb_carac = 0;
  3967. $nb_spaces = 0;
  3968. foreach ( $content as $k => $chunk ) {
  3969. if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
  3970. /*-- UNICODE-FONTS --*/
  3971. if ($this->is_MB) {
  3972. $chunk = str_replace($this->chrs[194].$this->chrs[160],$this->chrs[32],$chunk );
  3973. }
  3974. else {
  3975. /*-- END UNICODE-FONTS --*/
  3976. $chunk = str_replace($this->chrs[160],$this->chrs[32],$chunk );
  3977. } // *UNICODE-FONTS*
  3978. // Modified by Ivan Tcholakov, 28-JAN-2010.
  3979. //$nb_carac += mb_strlen( $chunk, $this->mb_enc );
  3980. //$nb_spaces += mb_substr_count( $chunk,' ', $this->mb_enc );
  3981. $nb_carac += api_strlen( $chunk, $this->mb_enc );
  3982. $nb_spaces += api_substr_count( $chunk,' ', $this->mb_enc );
  3983. //
  3984. }
  3985. }
  3986. // 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)
  3987. // If "orphans" in fact is just a final space - ignore this
  3988. // mPDF 4.2 $lastitalic to shorten if line ends with artificial ITALIC
  3989. // mPDF 4.3.003 Justify line if following is object - image etc.
  3990. if (((($contentWidth + $lastitalic) > $maxWidth) && ($content[count($content)-1] != ' ') ) ||
  3991. (!$endofblock && $align=='J' && ($next=='image' || $next=='select' || $next=='input' || $next=='textarea' || ($next=='br' && $this->justifyB4br)))
  3992. ) {
  3993. // WORD SPACING
  3994. // mPDF 4.2 $lastitalic to shorten if line ends with artificial ITALIC
  3995. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,($maxWidth-$lastitalic-$contentWidth-$WidthCorrection-(($this->cMarginL+$this->cMarginR)*$this->k)-($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) )));
  3996. // mPDF 4.0
  3997. $this->SetSpacing($charspacing,$ws);
  3998. }
  3999. // mPDF 4.0 Check if will fit at word/char spacing of previous line - if so continue it
  4000. // but only allow a maximum of $this->jSmaxWordLast and $this->jSmaxCharLast
  4001. // mPDF 4.2 $lastitalic to shorten if line ends with artificial ITALIC
  4002. else if ($contentWidth < ($maxWidth - $lastitalic-$WidthCorrection - (($this->cMarginL+$this->cMarginR)* $this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k)))) {
  4003. if ($this->ws > $this->jSmaxWordLast) {
  4004. $ws=$this->jSmaxWord;
  4005. $this->_out(sprintf('BT %.3f Tw ET',$ws));
  4006. $this->ws=$ws;
  4007. }
  4008. if ($this->charspacing > $this->jSmaxCharLast) {
  4009. $charspacing=$this->jSmaxCharLast;
  4010. $this->_out(sprintf('BT %.3f Tc ET',$charspacing));
  4011. $this->charspacing=$charspacing;
  4012. }
  4013. // mPDF 4.2 $lastitalic to shorten if line ends with artificial ITALIC
  4014. $check = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* $this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) ) - ( $this->charspacing * $nb_carac) - ( $this->ws * $nb_spaces);
  4015. if ($check <= 0) {
  4016. // mPDF 4.0
  4017. $this->ResetSpacing();
  4018. }
  4019. }
  4020. else {
  4021. // mPDF 4.0
  4022. $this->ResetSpacing();
  4023. }
  4024. // mPDF 4.2 $lastitalic to shorten if line ends with artificial ITALIC
  4025. $empty = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* $this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) ) - ( $this->charspacing * $nb_carac) - ( $this->ws * $nb_spaces);
  4026. $empty /= $this->k;
  4027. // mPDF 4.0
  4028. if (!$is_table) {
  4029. $this->maxPosR = max($this->maxPosR , ($this->w - $this->rMargin - $this->blk[$this->blklvl]['outer_right_margin'] - $empty));
  4030. $this->maxPosL = min($this->maxPosL , ($this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $empty));
  4031. }
  4032. $arraysize = count($content);
  4033. $margins = ($this->cMarginL+$this->cMarginR) + ($ipaddingL+$ipaddingR + $fpaddingR + $fpaddingR );
  4034. if (!$is_table) { $this->DivLn($lineHeight,$this->blklvl,false); } // false -> don't advance y
  4035. // DIRECTIONALITY RTL
  4036. $all_rtl = false;
  4037. $contains_rtl = false;
  4038. /*-- RTL --*/
  4039. if (($this->directionality == 'rtl') || (($this->directionality == 'ltr') && ($this->biDirectional))) {
  4040. $all_rtl = true;
  4041. foreach ( $content as $k => $chunk ) {
  4042. $reversed = $this->magic_reverse_dir($chunk, false);
  4043. if ($reversed > 0) { $contains_rtl = true; }
  4044. if ($reversed < 2) { $all_rtl = false; }
  4045. $content[$k] = $chunk;
  4046. }
  4047. if ($this->directionality == 'rtl') {
  4048. if ($contains_rtl) {
  4049. $content = array_reverse($content,false);
  4050. }
  4051. }
  4052. else if (($this->directionality == 'ltr') && ($this->biDirectional)) {
  4053. if ($all_rtl) {
  4054. $content = array_reverse($content,false);
  4055. }
  4056. }
  4057. }
  4058. /*-- END RTL --*/
  4059. $this->x = $currentx + $this->cMarginL + $ipaddingL + $fpaddingL;
  4060. if ($align == 'R') { $this->x += $empty; }
  4061. else if ($align == 'J') {
  4062. if ($this->directionality == 'rtl' && $contains_rtl) { $this->x += $empty; }
  4063. else if ($this->directionality == 'ltr' && $all_rtl) { $this->x += $empty; }
  4064. }
  4065. else if ($align == 'C') { $this->x += ($empty / 2); }
  4066. // Paragraph INDENT
  4067. $WidthCorrection = 0;
  4068. if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align !='C')) {
  4069. // mPDF 4.0
  4070. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  4071. $this->x += $ti;
  4072. }
  4073. foreach ( $content as $k => $chunk )
  4074. {
  4075. // FOR IMAGES
  4076. if (($this->directionality=='rtl' && $contains_rtl) || $all_rtl) { $dirk = $arraysize-1 - $k; } else { $dirk = $k; }
  4077. // mPDF 4.2
  4078. $va = 'M'; // default for text
  4079. if (isset($this->objectbuffer[$dirk]) && $this->objectbuffer[$dirk]) {
  4080. $xadj = $this->x - $this->objectbuffer[$dirk]['OUTER-X'];
  4081. $this->objectbuffer[$dirk]['OUTER-X'] += $xadj;
  4082. $this->objectbuffer[$dirk]['BORDER-X'] += $xadj;
  4083. $this->objectbuffer[$dirk]['INNER-X'] += $xadj;
  4084. // mPDF 4.2
  4085. $va = $this->objectbuffer[$dirk]['vertical-align'];
  4086. $yadj = $this->y - $this->objectbuffer[$dirk]['OUTER-Y'];
  4087. if ($va == 'BS') {
  4088. $yadj += $af + ($this->linemaxfontsize * (0.5 + $this->baselineC)) - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  4089. }
  4090. else if ($va == 'M' || $va == '') {
  4091. $yadj += $af + ($this->linemaxfontsize /2) - ($this->objectbuffer[$dirk]['OUTER-HEIGHT']/2);
  4092. }
  4093. else if ($va == 'TB') {
  4094. $yadj += $af + $this->linemaxfontsize - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  4095. }
  4096. else if ($va == 'TT') {
  4097. $yadj += $af;
  4098. }
  4099. else if ($va == 'B') {
  4100. $yadj += $af + $this->linemaxfontsize + $bf - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  4101. }
  4102. else if ($va == 'T') {
  4103. $yadj += 0;
  4104. }
  4105. $this->objectbuffer[$dirk]['OUTER-Y'] += $yadj;
  4106. $this->objectbuffer[$dirk]['BORDER-Y'] += $yadj;
  4107. $this->objectbuffer[$dirk]['INNER-Y'] += $yadj;
  4108. }
  4109. // DIRECTIONALITY RTL
  4110. if ((($this->directionality == 'rtl') && ($contains_rtl )) || ($all_rtl )) { $this->restoreFont( $font[ $arraysize-1 - $k ] ); }
  4111. else { $this->restoreFont( $font[ $k ] ); }
  4112. // *********** SPAN BACKGROUND COLOR ***************** //
  4113. if (isset($this->spanbgcolor) && $this->spanbgcolor) {
  4114. $cor = $this->spanbgcolorarray;
  4115. $this->SetFillColor($cor['R'],$cor['G'],$cor['B']);
  4116. $save_fill = $fill; $spanfill = 1; $fill = 1;
  4117. }
  4118. // WORD SPACING
  4119. // Modified by Ivan Tcholakov, 28-JAN-2010.
  4120. // $stringWidth = $this->GetStringWidth($chunk ) + ( $this->charspacing * mb_strlen($chunk,$this->mb_enc ) / $this->k )
  4121. // + ( $this->ws * mb_substr_count($chunk,' ',$this->mb_enc ) / $this->k );
  4122. $stringWidth = $this->GetStringWidth($chunk ) + ( $this->charspacing * api_strlen($chunk,$this->mb_enc ) / $this->k )
  4123. + ( $this->ws * api_substr_count($chunk,' ',$this->mb_enc ) / $this->k );
  4124. //
  4125. if (isset($this->objectbuffer[$dirk])) {
  4126. // mPDF 4.2.031
  4127. if ($this->objectbuffer[$dirk]['type']=='dottab') {
  4128. $this->objectbuffer[$dirk]['OUTER-WIDTH'] +=$empty;
  4129. }
  4130. $stringWidth = $this->objectbuffer[$dirk]['OUTER-WIDTH'];
  4131. }
  4132. // mPDF 4.2 af , bf above and below font
  4133. if ($k == $arraysize-1) $this->Cell( $stringWidth, $lineHeight, $chunk, '', 1, '', $fill, $this->HREF , $currentx,0,0,'M', $fill, $af, $bf ); //mono-style line or last part (skips line)
  4134. else $this->Cell( $stringWidth, $lineHeight, $chunk, '', 0, '', $fill, $this->HREF, 0, 0,0,'M', $fill, $af, $bf );//first or middle part
  4135. // *********** SPAN BACKGROUND COLOR OFF - RESET BLOCK BGCOLOR ***************** //
  4136. if (isset($spanfill) && $spanfill) {
  4137. $fill = $save_fill; $spanfill = 0;
  4138. if ($fill) { $this->SetFillColor($bcor['R'],$bcor['G'],$bcor['B']); }
  4139. }
  4140. }
  4141. $this->printobjectbuffer($is_table);
  4142. $this->objectbuffer = array();
  4143. // mPDF 4.0
  4144. $this->ResetSpacing();
  4145. /*-- LISTS --*/
  4146. // LIST BULLETS/NUMBERS
  4147. if ($is_list && is_array($this->bulletarray) && ($lineCount == 0) ) {
  4148. // mPDF 4.0
  4149. $savedFont = $this->saveFont();
  4150. $bull = $this->bulletarray;
  4151. if (isset($bull['level']) && isset($bull['occur']) && isset($this->InlineProperties['LIST'][$bull['level']][$bull['occur']])) {
  4152. $this->restoreInlineProperties($this->InlineProperties['LIST'][$bull['level']][$bull['occur']]);
  4153. }
  4154. 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']]); }
  4155. if (isset($bull['font']) && $bull['font'] == 'zapfdingbats') {
  4156. $this->bullet = true;
  4157. $this->SetFont('zapfdingbats','',$this->FontSizePt/2.5);
  4158. }
  4159. else { $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); } // force output
  4160. //Output bullet
  4161. $this->x = $currentx;
  4162. if (isset($bull['x'])) { $this->x += $bull['x']; }
  4163. $this->y -= $lineHeight;
  4164. // mPDF 4.0
  4165. if (isset($bull['txt'])) { $this->Cell($bull['w'], $lineHeight,$bull['txt'],'','',$bull['align'],0,'',0,-$this->cMarginL, -$this->cMarginR ); }
  4166. if (isset($bull['font']) && $bull['font'] == 'zapfdingbats') {
  4167. $this->bullet = false;
  4168. }
  4169. $this->x = $currentx; // Reset
  4170. $this->y += $lineHeight;
  4171. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4172. // mPDF 3.0 ? does nothing as $savedFont is not defined
  4173. // mPDF 4.0
  4174. $this->restoreFont( $savedFont );
  4175. // $font = array( $savedFont );
  4176. $this->bulletarray = array(); // prevents repeat of bullet/number if <li>....<br />.....</li>
  4177. }
  4178. /*-- END LISTS --*/
  4179. } // END IF CONTENT
  4180. /*-- CSS-IMAGE-FLOAT --*/
  4181. // Update values if set to skipline
  4182. if ($this->floatmargins) { $this->_advanceFloatMargins(); }
  4183. if ($endofblock && $blockstate>1) {
  4184. // If float exists at this level
  4185. if (isset($this->floatmargins['R']['y1'])) { $fry1 = $this->floatmargins['R']['y1']; }
  4186. else { $fry1 = 0; }
  4187. if (isset($this->floatmargins['L']['y1'])) { $fly1 = $this->floatmargins['L']['y1']; }
  4188. else { $fly1 = 0; }
  4189. if ($this->y < $fry1 || $this->y < $fly1) {
  4190. $drop = max($fry1,$fly1) - $this->y;
  4191. $this->DivLn($drop);
  4192. $this->x = $currentx;
  4193. }
  4194. }
  4195. /*-- END CSS-IMAGE-FLOAT --*/
  4196. // PADDING and BORDER spacing/fill
  4197. 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)) {
  4198. // mPDF 4.0 If CSS height set, extend bottom - if on same page as block started, and CSS HEIGHT > actual height,
  4199. // and does not force pagebreak
  4200. $extra = 0;
  4201. if ($this->blk[$this->blklvl]['css_set_height'] && $this->blk[$this->blklvl]['startpage']==$this->page) {
  4202. // predicted height
  4203. $h1 = ($this->y-$this->blk[$this->blklvl]['y0']) + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'];
  4204. if ($h1 < $this->blk[$this->blklvl]['css_set_height']) { $extra = $this->blk[$this->blklvl]['css_set_height'] - $h1; }
  4205. if($this->y + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $extra > $this->PageBreakTrigger) {
  4206. $extra = $this->PageBreakTrigger - ($this->y + $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w']);
  4207. }
  4208. }
  4209. // mPDF 3.0 Also does border when Columns active
  4210. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  4211. $this->DivLn($this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $extra,-3,true,false,2);
  4212. $this->x = $currentx;
  4213. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4214. }
  4215. // SET Bottom y1 of block (used for painting borders)
  4216. if (($endofblock) && ($blockstate > 1) && (!$is_table) && (!$is_list)) {
  4217. $this->blk[$this->blklvl]['y1'] = $this->y;
  4218. }
  4219. // BOTTOM MARGIN
  4220. if (($endofblock) && ($blockstate > 1) && ($this->blk[$this->blklvl]['margin_bottom']) && (!$is_table) && (!$is_list)) {
  4221. if($this->y+$this->blk[$this->blklvl]['margin_bottom'] < $this->PageBreakTrigger and !$this->InFooter) {
  4222. $this->DivLn($this->blk[$this->blklvl]['margin_bottom'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']);
  4223. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4224. }
  4225. }
  4226. // Reset lineheight
  4227. $lineHeight = $this->divheight;
  4228. }
  4229. function printobjectbuffer($is_table=false) {
  4230. if ($is_table && $this->shrin_k > 1) { $k = $this->shrin_k; }
  4231. else { $k = 1; }
  4232. $save_y = $this->y;
  4233. $save_x = $this->x;
  4234. $save_currentfontfamily = $this->FontFamily;
  4235. $save_currentfontsize = $this->FontSizePt;
  4236. $save_currentfontstyle = $this->FontStyle.($this->underline ? 'U' : '');
  4237. if ($this->directionality == 'rtl') { $rtlalign = 'R'; } else { $rtlalign = 'L'; }
  4238. foreach ($this->objectbuffer AS $ib => $objattr) {
  4239. // mPDF 3.0
  4240. if ($objattr['type'] == 'bookmark' || $objattr['type'] == 'indexentry' || $objattr['type'] == 'toc') {
  4241. $x = $objattr['OUTER-X'];
  4242. $y = $objattr['OUTER-Y'];
  4243. $this->y = $y - $this->FontSize/2;
  4244. $this->x = $x;
  4245. if ($objattr['type'] == 'bookmark' ) { $this->Bookmark($objattr['CONTENT'],$objattr['bklevel'] ,$y - $this->FontSize); } // *BOOKMARKS*
  4246. if ($objattr['type'] == 'indexentry') { $this->IndexEntry($objattr['CONTENT']); } // *INDEX*
  4247. if ($objattr['type'] == 'toc') { $this->TOC_Entry($objattr['CONTENT'], $objattr['toclevel'], $objattr['toc_id']); } // *TOC*
  4248. }
  4249. /*-- ANNOTATIONS --*/
  4250. else if ($objattr['type'] == 'annot') {
  4251. if ($objattr['POS-X']) { $x = $objattr['POS-X']; }
  4252. else if ($this->annotMargin<>0) { $x = -$objattr['OUTER-X']; }
  4253. else { $x = $objattr['OUTER-X']; }
  4254. if ($objattr['POS-Y']) { $y = $objattr['POS-Y']; }
  4255. else { $y = $objattr['OUTER-Y'] - $this->FontSize/2; }
  4256. // Create a dummy entry in the _out/columnBuffer with position sensitive data,
  4257. // linking $y-1 in the Columnbuffer with entry in $this->columnAnnots
  4258. // and when columns are split in length will not break annotation from current line
  4259. $this->y = $y-1;
  4260. $this->x = $x-1;
  4261. $this->Line($x-1,$y-1,$x-1,$y-1);
  4262. $this->Annotation($objattr['CONTENT'], $x , $y , $objattr['ICON'], $objattr['AUTHOR'], $objattr['SUBJECT'], $objattr['OPACITY'], $objattr['COLOR'], $objattr['POPUP']); // mPDF 4.2.027
  4263. }
  4264. /*-- END ANNOTATIONS --*/
  4265. else {
  4266. $y = $objattr['OUTER-Y'];
  4267. $x = $objattr['OUTER-X'];
  4268. $w = $objattr['OUTER-WIDTH'];
  4269. $h = $objattr['OUTER-HEIGHT'];
  4270. if (isset($objattr['text'])) { $texto = $objattr['text']; }
  4271. $this->y = $y;
  4272. $this->x = $x;
  4273. if (isset($objattr['fontfamily'])) { $this->SetFont($objattr['fontfamily'],'',$objattr['fontsize'] ); }
  4274. }
  4275. // HR
  4276. if ($objattr['type'] == 'hr') {
  4277. $this->SetDrawColor($objattr['color']['R'],$objattr['color']['G'],$objattr['color']['B']);
  4278. switch($objattr['align']) {
  4279. case 'C':
  4280. $empty = $objattr['OUTER-WIDTH'] - $objattr['INNER-WIDTH'];
  4281. $empty /= 2;
  4282. $x += $empty;
  4283. break;
  4284. case 'R':
  4285. $empty = $objattr['OUTER-WIDTH'] - $objattr['INNER-WIDTH'];
  4286. $x += $empty;
  4287. break;
  4288. }
  4289. $oldlinewidth = $this->LineWidth;
  4290. $this->SetLineWidth($objattr['linewidth']/$k );
  4291. $this->y += ($objattr['linewidth']/2) + $objattr['margin_top']/$k;
  4292. $this->Line($x,$this->y,$x+$objattr['INNER-WIDTH'],$this->y);
  4293. $this->SetLineWidth($oldlinewidth);
  4294. $this->SetDrawColor(0);
  4295. }
  4296. // IMAGE
  4297. if ($objattr['type'] == 'image') {
  4298. if (isset($objattr['opacity'])) { $this->SetAlpha($objattr['opacity']); }
  4299. // mPDF 4.3.016
  4300. $rotate = 0;
  4301. $obiw = $objattr['INNER-WIDTH'];
  4302. $obih = $objattr['INNER-HEIGHT'];
  4303. $sx = $objattr['INNER-WIDTH']*$this->k / $objattr['orig_w'];
  4304. $sy = abs($objattr['INNER-HEIGHT'])*$this->k / abs($objattr['orig_h']);
  4305. $sx = ($objattr['INNER-WIDTH']*$this->k / $objattr['orig_w']);
  4306. $sy = ($objattr['INNER-HEIGHT']*$this->k / $objattr['orig_h']);
  4307. if (isset($objattr['ROTATE'])) { $rotate = $objattr['ROTATE']; }
  4308. if ($rotate==90) {
  4309. // Clockwise
  4310. $obiw = $objattr['INNER-HEIGHT'];
  4311. $obih = $objattr['INNER-WIDTH'];
  4312. $tr = $this->transformTranslate(0, -$objattr['INNER-WIDTH'], true) ;
  4313. $tr .= ' '. $this->transformRotate(90, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-WIDTH'] ),true) ;
  4314. $sx = $obiw*$this->k / $objattr['orig_h'];
  4315. $sy = $obih*$this->k / $objattr['orig_w']; // mPDF 4.4.013
  4316. }
  4317. else if ($rotate==-90) {
  4318. // AntiClockwise
  4319. $obiw = $objattr['INNER-HEIGHT'];
  4320. $obih = $objattr['INNER-WIDTH'];
  4321. $tr = $this->transformTranslate($objattr['INNER-WIDTH'], ($objattr['INNER-HEIGHT']-$objattr['INNER-WIDTH']), true) ;
  4322. $tr .= ' '. $this->transformRotate(-90, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-WIDTH'] ),true) ;
  4323. $sx = $obiw*$this->k / $objattr['orig_h'];
  4324. $sy = $obih*$this->k / $objattr['orig_w']; // mPDF 4.4.013
  4325. }
  4326. else if ($rotate==180) {
  4327. // Mirror
  4328. $tr = $this->transformTranslate($objattr['INNER-WIDTH'], -$objattr['INNER-HEIGHT'], true) ;
  4329. $tr .= ' '. $this->transformRotate(180, $objattr['INNER-X'],($objattr['INNER-Y'] +$objattr['INNER-HEIGHT'] ),true) ;
  4330. }
  4331. else { $tr = ''; }
  4332. $tr = trim($tr); // mPDF 4.5.007
  4333. if ($tr) { $tr .= ' '; } // mPDF 4.5.007
  4334. /*-- IMAGES-WMF --*/
  4335. if (isset($objattr['itype']) && $objattr['itype']=='wmf') {
  4336. $outstring = sprintf('q '.$tr.'%.3f 0 0 %.3f %.3f %.3f cm /FO%d Do Q', $sx, -$sy, $objattr['INNER-X']*$this->k-$sx*$objattr['wmf_x'], (($this->h-$objattr['INNER-Y'])*$this->k)+$sy*$objattr['wmf_y'], $objattr['ID']); // mPDF 4.3.016 // mPDF 4.5.007
  4337. }
  4338. else
  4339. /*-- END IMAGES-WMF --*/
  4340. // mPDF 4.3.013 SVG files
  4341. if (isset($objattr['itype']) && $objattr['itype']=='svg') {
  4342. $outstring = sprintf('q '.$tr.'%.3f 0 0 %.3f %.3f %.3f cm /FO%d Do Q', $sx, -$sy, $objattr['INNER-X']*$this->k-$sx*$objattr['wmf_x'], (($this->h-$objattr['INNER-Y'])*$this->k)+$sy*$objattr['wmf_y'], $objattr['ID']); // mPDF 4.3.016 // mPDF 4.5.007
  4343. }
  4344. else {
  4345. $outstring = sprintf("q ".$tr."%.3f 0 0 %.3f %.3f %.3f cm /I%d Do Q",$obiw*$this->k, $obih*$this->k, $objattr['INNER-X'] *$this->k, ($this->h-($objattr['INNER-Y'] +$obih ))*$this->k,$objattr['ID'] ); // mPDF 4.3.016 // mPDF 4.5.007
  4346. }
  4347. $this->_out($outstring);
  4348. // LINK
  4349. if (isset($objattr['link'])) $this->Link($objattr['INNER-X'],$objattr['INNER-Y'],$objattr['INNER-WIDTH'],$objattr['INNER-HEIGHT'],$objattr['link']);
  4350. if (isset($objattr['BORDER-WIDTH'])) { $this->PaintImgBorder($objattr,$is_table); }
  4351. if (isset($objattr['opacity'])) { $this->SetAlpha(1); }
  4352. }
  4353. /*-- BARCODES --*/
  4354. // mPDF 4.0
  4355. // BARCODE
  4356. if ($objattr['type'] == 'barcode') {
  4357. $bgcol = array('R'=>255, 'G'=>255, 'B'=>255);
  4358. if (isset($objattr['bgcolor']) && is_array($objattr['bgcolor'])) {
  4359. $bgcol = $objattr['bgcolor'];
  4360. }
  4361. $col = array('R'=>0, 'G'=>0, 'B'=>0);
  4362. if (isset($objattr['color']) && is_array($objattr['color'])) {
  4363. $col = $objattr['color'];
  4364. }
  4365. $this->SetFillColor($bgcol['R'],$bgcol['G'],$bgcol['B']);
  4366. $this->Rect($objattr['BORDER-X'], $objattr['BORDER-Y'], $objattr['BORDER-WIDTH'], $objattr['BORDER-HEIGHT'], 'F');
  4367. $this->SetFillColor(255);
  4368. if (isset($objattr['BORDER-WIDTH'])) { $this->PaintImgBorder($objattr,$is_table); }
  4369. if ($objattr['btype'] == 'EAN13' || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN' || $objattr['btype'] == 'UPCA' || $objattr['btype'] == 'UPCE' || $objattr['btype'] == 'EAN8') {
  4370. $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);
  4371. }
  4372. else {
  4373. $this->WriteBarcode2($objattr['code'], $objattr['INNER-X'], $objattr['INNER-Y'], $objattr['bsize'], $objattr['bheight'], $bgcol, $col, $objattr['btype'], $objattr['pr_ratio'], $k);
  4374. }
  4375. }
  4376. /*-- END BARCODES --*/
  4377. // mPDF 3.0 Normal spacing
  4378. // mPDF 4.0
  4379. $this->ResetSpacing();
  4380. // mPDF 4.2.031
  4381. if ($objattr['type'] == 'dottab') {
  4382. $sp = $this->GetStringWidth(' ');
  4383. $nb=floor(($w-2*$sp)/$this->GetStringWidth('.'));
  4384. if ($nb>0) { $dots=' '.str_repeat('.',$nb).' '; }
  4385. else { $dots=' '; }
  4386. $this->Cell($w,$h,$dots,0,0,'C');
  4387. }
  4388. /*-- FORMS --*/
  4389. // mPDF - 1.4 Active Forms edited all the form elements below
  4390. // TEXT/PASSWORD INPUT
  4391. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'TEXT' || $objattr['subtype'] == 'PASSWORD')) {
  4392. $w -= $this->form_element_spacing['input']['outer']['h']*2 /$k;
  4393. $h -= $this->form_element_spacing['input']['outer']['v']*2 /$k;
  4394. $this->x += $this->form_element_spacing['input']['outer']['h'] /$k;
  4395. $this->y += $this->form_element_spacing['input']['outer']['v'] /$k;
  4396. // Chop texto to max length $w-inner-padding
  4397. while ($this->GetStringWidth($texto) > $w-($this->form_element_spacing['input']['inner']['h']*2)) {
  4398. // Modified by Ivan Tcholakov, 28-JAN-2010.
  4399. //$texto = mb_substr($texto,0,mb_strlen($texto,$this->mb_enc)-1,$this->mb_enc);
  4400. $texto = api_substr($texto,0,api_strlen($texto,$this->mb_enc)-1,$this->mb_enc);
  4401. //
  4402. }
  4403. // DIRECTIONALITY
  4404. $this->SetLineWidth(0.2 /$k );
  4405. $this->magic_reverse_dir($texto, false); // *RTL*
  4406. if (isset($objattr['disabled']) && $objattr['disabled']) {
  4407. $this->SetFillColor(225);
  4408. $this->SetTextColor(127);
  4409. }
  4410. else if (isset($objattr['readonly']) && $objattr['readonly']) {
  4411. $this->SetFillColor(225);
  4412. $this->SetTextColor(0);
  4413. }
  4414. else {
  4415. $this->SetFillColor(250);
  4416. $this->SetTextColor(0);
  4417. }
  4418. $this->Cell($w,$h,$texto,1,0,$rtlalign,1,'',0,$this->form_element_spacing['input']['inner']['h'] /$k ,$this->form_element_spacing['input']['inner']['h'] /$k , 'M');
  4419. $this->SetFillColor(255);
  4420. $this->SetTextColor(0);
  4421. }
  4422. // SELECT
  4423. if ($objattr['type'] == 'select') {
  4424. // DIRECTIONALITY
  4425. $this->magic_reverse_dir($texto, false); // *RTL*
  4426. $this->SetLineWidth(0.2 /$k );
  4427. if (isset($objattr['disabled']) && $objattr['disabled']) {
  4428. $this->SetFillColor(225);
  4429. $this->SetTextColor(127);
  4430. }
  4431. else {
  4432. $this->SetFillColor(250);
  4433. $this->SetTextColor(0);
  4434. }
  4435. $w -= $this->form_element_spacing['select']['outer']['h']*2 /$k ;
  4436. $h -= $this->form_element_spacing['select']['outer']['v']*2 /$k ;
  4437. $this->x += $this->form_element_spacing['select']['outer']['h'] /$k ;
  4438. $this->y += $this->form_element_spacing['select']['outer']['v'] /$k ;
  4439. $this->Cell($w-($this->FontSize*1.4),$h,$texto,1,0,$rtlalign,1,'',0,$this->form_element_spacing['select']['inner']['h'] /$k,$this->form_element_spacing['select']['inner']['h'] /$k , 'M') ;
  4440. $this->SetFillColor(190);
  4441. $save_font = $this->FontFamily;
  4442. $save_currentfont = $this->currentfontfamily;
  4443. // mPDF 4.2.018
  4444. if ($this->PDFA) {
  4445. if (!$this->PDFAauto) { $this->PDFAwarnings[] = "Core Adobe font Zapfdingbats cannot be embedded in mPDF - used in Form element: Select - which is required for PDFA1-b. (Different character/font will be substituted.)"; }
  4446. $this->SetFont('sans');
  4447. $this->Cell(($this->FontSize*1.4),$h,'=',1,0,'C',1,'',0,0,0, 'M') ;
  4448. }
  4449. else {
  4450. $this->SetFont('zapfdingbats','',0);
  4451. $this->Cell(($this->FontSize*1.4),$h,$this->chrs[116],1,0,'C',1,'',0,0,0, 'M') ;
  4452. }
  4453. $this->SetFont($save_font,'',0);
  4454. $this->currentfontfamily = $save_currentfont;
  4455. $this->SetFillColor(255);
  4456. $this->SetTextColor(0);
  4457. }
  4458. // INPUT/BUTTON as IMAGE
  4459. if ($objattr['type'] == 'input' && $objattr['subtype'] == 'IMAGE') {
  4460. $this->y = $objattr['INNER-Y'];
  4461. $this->_out( sprintf("q %.3f 0 0 %.3f %.3f %.3f cm /I%d Do Q",$objattr['INNER-WIDTH'] *$this->k,$objattr['INNER-HEIGHT'] *$this->k,$objattr['INNER-X'] *$this->k,($this->h-($objattr['INNER-Y'] +$objattr['INNER-HEIGHT'] ))*$this->k,$objattr['ID'] ) );
  4462. if (isset($objattr['BORDER-WIDTH']) && $objattr['BORDER-WIDTH']) { $this->PaintImgBorder($objattr,$is_table); }
  4463. }
  4464. // BUTTON
  4465. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'SUBMIT' || $objattr['subtype'] == 'RESET' || $objattr['subtype'] == 'BUTTON')) {
  4466. $this->SetLineWidth(0.2 /$k );
  4467. $this->SetFillColor(190,190,190);
  4468. $w -= $this->form_element_spacing['button']['outer']['h']*2 /$k ;
  4469. $h -= $this->form_element_spacing['button']['outer']['v']*2 /$k ;
  4470. $this->x += $this->form_element_spacing['button']['outer']['h'] /$k ;
  4471. $this->y += $this->form_element_spacing['button']['outer']['v'] /$k ;
  4472. $this->RoundedRect($this->x, $this->y, $w, $h, 0.5 /$k , 'DF');
  4473. $w -= $this->form_element_spacing['button']['inner']['h']*2 /$k ;
  4474. $h -= $this->form_element_spacing['button']['inner']['v']*2 /$k ;
  4475. $this->x += $this->form_element_spacing['button']['inner']['h'] /$k ;
  4476. $this->y += $this->form_element_spacing['button']['inner']['v'] /$k ;
  4477. $this->magic_reverse_dir($texto, false); // *RTL*
  4478. $this->Cell($w,$h,$texto,'',0,'C',0,'',0,0,0, 'M') ;
  4479. $this->SetFillColor(255);
  4480. }
  4481. // TEXTAREA
  4482. if ($objattr['type'] == 'textarea') {
  4483. $w -= $this->form_element_spacing['textarea']['outer']['h']*2 /$k ;
  4484. $h -= $this->form_element_spacing['textarea']['outer']['v']*2 /$k ;
  4485. $this->x += $this->form_element_spacing['textarea']['outer']['h'] /$k ;
  4486. $this->y += $this->form_element_spacing['textarea']['outer']['v'] /$k ;
  4487. $this->SetLineWidth(0.2 /$k );
  4488. if (isset($objattr['disabled']) && $objattr['disabled']) {
  4489. $this->SetFillColor(225);
  4490. $this->SetTextColor(127);
  4491. }
  4492. else if (isset($objattr['readonly']) && $objattr['readonly']) {
  4493. $this->SetFillColor(225);
  4494. $this->SetTextColor(0);
  4495. }
  4496. else {
  4497. $this->SetFillColor(250);
  4498. $this->SetTextColor(0);
  4499. }
  4500. $this->Rect($this->x,$this->y,$w,$h,'DF');
  4501. $w -= $this->form_element_spacing['textarea']['inner']['h']*2 /$k ;
  4502. $this->x += $this->form_element_spacing['textarea']['inner']['h'] /$k ;
  4503. $this->y += $this->form_element_spacing['textarea']['inner']['v'] /$k ;
  4504. $linesneeded = $this->WordWrap($texto,$w);
  4505. if ($linesneeded > $objattr['rows']) { //Too many words inside textarea
  4506. $textoaux = explode("\n",$texto); // mPDF 4.4.012
  4507. $texto = '';
  4508. for($i=0;$i<$objattr['rows'];$i++) {
  4509. if ($i == ($objattr['rows']-1)) $texto .= $textoaux[$i];
  4510. else $texto .= $textoaux[$i] . "\n";
  4511. }
  4512. // Modified by Ivan Tcholakov, 28-JAN-2010.
  4513. //$texto = mb_substr($texto,0,mb_strlen($texto,$this->mb_enc)-4,$this->mb_enc) . "...";
  4514. $texto = api_substr($texto,0,api_strlen($texto,$this->mb_enc)-4,$this->mb_enc) . "...";
  4515. //
  4516. }
  4517. if ($texto != '') $this->MultiCell($w,$this->FontSize*$this->textarea_lineheight,$texto,0,'',0,'',$this->directionality,true);
  4518. $this->SetFillColor(255);
  4519. $this->SetTextColor(0);
  4520. }
  4521. // CHECKBOX
  4522. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'CHECKBOX')) {
  4523. $iw = $w * 0.7;
  4524. $ih = $h * 0.7;
  4525. $lx = $x + (($w-$iw)/2);
  4526. $ty = $y + (($h-$ih)/2);
  4527. $rx = $lx + $iw;
  4528. $by = $ty + $ih;
  4529. $this->SetLineWidth(0.2 /$k );
  4530. if (isset($objattr['disabled']) && $objattr['disabled']) {
  4531. $this->SetFillColor(225);
  4532. $this->SetDrawColor(127);
  4533. }
  4534. else {
  4535. $this->SetFillColor(250);
  4536. $this->SetDrawColor(0);
  4537. }
  4538. $this->Rect($lx,$ty,$iw,$ih,'DF');
  4539. if (isset($objattr['checked']) && $objattr['checked']) {
  4540. //Round join and cap
  4541. $this->_out('1 J');
  4542. $this->Line($lx,$ty,$rx,$by);
  4543. $this->Line($lx,$by,$rx,$ty);
  4544. //Set line cap style back to square
  4545. $this->_out('2 J');
  4546. }
  4547. $this->SetFillColor(255);
  4548. $this->SetDrawColor(0);
  4549. }
  4550. // RADIO
  4551. if ($objattr['type'] == 'input' && ($objattr['subtype'] == 'RADIO')) {
  4552. $this->SetLineWidth(0.2 /$k );
  4553. $radius = $this->FontSize *0.35;
  4554. $cx = $x + ($w/2);
  4555. $cy = $y + ($h/2);
  4556. if (isset($objattr['disabled']) && $objattr['disabled']) {
  4557. $this->SetFillColor(127);
  4558. $this->SetDrawColor(127);
  4559. }
  4560. else {
  4561. $this->SetFillColor(0);
  4562. $this->SetDrawColor(0);
  4563. }
  4564. $this->Circle($cx,$cy,$radius,'D');
  4565. if (isset($objattr['checked']) && $objattr['checked']) {
  4566. $this->Circle($cx,$cy,$radius*0.4,'DF');
  4567. }
  4568. $this->SetFillColor(255);
  4569. $this->SetDrawColor(0);
  4570. }
  4571. /*-- END FORMS --*/
  4572. }
  4573. $this->SetFont($save_currentfontfamily,$save_currentfontstyle,$save_currentfontsize);
  4574. $this->y = $save_y;
  4575. $this->x = $save_x;
  4576. unset($content);
  4577. }
  4578. function WriteFlowingBlock( $s)
  4579. {
  4580. $currentx = $this->x;
  4581. $is_table = $this->flowingBlockAttr[ 'is_table' ];
  4582. $is_list = $this->flowingBlockAttr[ 'is_list' ];
  4583. // width of all the content so far in points
  4584. $contentWidth =& $this->flowingBlockAttr[ 'contentWidth' ];
  4585. // cell width in points
  4586. $maxWidth =& $this->flowingBlockAttr[ 'width' ];
  4587. $lineCount =& $this->flowingBlockAttr[ 'lineCount' ];
  4588. // line height in user units
  4589. $lineHeight =& $this->flowingBlockAttr[ 'height' ];
  4590. $align =& $this->flowingBlockAttr[ 'align' ];
  4591. $content =& $this->flowingBlockAttr[ 'content' ];
  4592. $font =& $this->flowingBlockAttr[ 'font' ];
  4593. $valign =& $this->flowingBlockAttr[ 'valign' ];
  4594. $blockstate = $this->flowingBlockAttr[ 'blockstate' ];
  4595. $newblock = $this->flowingBlockAttr[ 'newblock' ];
  4596. // *********** BLOCK BACKGROUND COLOR ***************** //
  4597. if ($this->blk[$this->blklvl]['bgcolor'] && !$is_table) {
  4598. // mPDF 3.0 - Tiling Patterns
  4599. $fill = 0;
  4600. // $fill = 1;
  4601. // $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  4602. // $this->SetFillColor($bcor['R'],$bcor['G'],$bcor['B']);
  4603. }
  4604. else {
  4605. $this->SetFillColor(255);
  4606. $fill = 0;
  4607. }
  4608. $font[] = $this->saveFont();
  4609. $content[] = '';
  4610. $currContent =& $content[ count( $content ) - 1 ];
  4611. // where the line should be cutoff if it is to be justified
  4612. $cutoffWidth = $contentWidth;
  4613. // Modified by Ivan Tcholakov, 28-JAN-2010.
  4614. //$curlyquote = mb_convert_encoding("\xe2\x80\x9e",$this->mb_enc,'UTF-8');
  4615. //$curlylowquote = mb_convert_encoding("\xe2\x80\x9d",$this->mb_enc,'UTF-8');
  4616. $curlyquote = api_convert_encoding("\xe2\x80\x9e",$this->mb_enc,'UTF-8');
  4617. $curlylowquote = api_convert_encoding("\xe2\x80\x9d",$this->mb_enc,'UTF-8');
  4618. //
  4619. // COLS
  4620. $oldcolumn = $this->CurrCol;
  4621. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  4622. /*-- TABLES --*/
  4623. if ($is_table) {
  4624. $ipaddingL = 0;
  4625. $ipaddingR = 0;
  4626. $paddingL = 0;
  4627. $paddingR = 0;
  4628. $cpaddingadjustL = 0;
  4629. $cpaddingadjustR = 0;
  4630. // Added mPDF 3.0
  4631. $fpaddingR = 0;
  4632. $fpaddingL = 0;
  4633. }
  4634. else {
  4635. /*-- END TABLES --*/
  4636. $ipaddingL = $this->blk[$this->blklvl]['padding_left'];
  4637. $ipaddingR = $this->blk[$this->blklvl]['padding_right'];
  4638. $paddingL = ($ipaddingL * $this->k);
  4639. $paddingR = ($ipaddingR * $this->k);
  4640. $this->cMarginL = $this->blk[$this->blklvl]['border_left']['w'];
  4641. $cpaddingadjustL = -$this->cMarginL;
  4642. $this->cMarginR = $this->blk[$this->blklvl]['border_right']['w'];
  4643. $cpaddingadjustR = -$this->cMarginR;
  4644. // Added mPDF 3.0 Float DIV
  4645. $fpaddingR = 0;
  4646. $fpaddingL = 0;
  4647. /*-- CSS-FLOAT --*/
  4648. if (count($this->floatDivs)) {
  4649. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  4650. if ($r_exists) { $fpaddingR = $r_width; }
  4651. if ($l_exists) { $fpaddingL = $l_width; }
  4652. }
  4653. /*-- END CSS-FLOAT --*/
  4654. $usey = $this->y + 0.002;
  4655. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  4656. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  4657. }
  4658. /*-- CSS-IMAGE-FLOAT --*/
  4659. // If float exists at this level
  4660. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  4661. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  4662. /*-- END CSS-IMAGE-FLOAT --*/
  4663. } // *TABLES*
  4664. //OBJECTS - IMAGES & FORM Elements (NB has already skipped line/page if required - in printbuffer)
  4665. if (substr($s,0,3) == "\xbb\xa4\xac") { //identifier has been identified!
  4666. // mPDF 4.0
  4667. $objattr = $this->_getObjAttr($s);
  4668. $h_corr = 0;
  4669. if ($is_table) { // *TABLES*
  4670. $maximumW = ($maxWidth/$this->k) - ($this->cellPaddingL + $this->cMarginL + $this->cellPaddingR + $this->cMarginR); // *TABLES*
  4671. } // *TABLES*
  4672. else { // *TABLES*
  4673. 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']; }
  4674. $maximumW = ($maxWidth/$this->k) - ($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 );
  4675. } // *TABLES*
  4676. $objattr = $this->inlineObject($objattr['type'],$this->lMargin + $fpaddingL + ($contentWidth/$this->k),($this->y + $h_corr), $objattr, $this->lMargin,($contentWidth/$this->k),$maximumW,$lineHeight,true,$is_table);
  4677. // SET LINEHEIGHT for this line ================ RESET AT END
  4678. $lineHeight = MAX($lineHeight,$objattr['OUTER-HEIGHT']);
  4679. $this->objectbuffer[count($content)-1] = $objattr;
  4680. // mPDF 4.2
  4681. // if (isset($objattr['vertical-align'])) { $valign = $objattr['vertical-align']; }
  4682. // else { $valign = ''; }
  4683. $contentWidth += ($objattr['OUTER-WIDTH'] * $this->k);
  4684. return;
  4685. }
  4686. /*-- UNICODE-FONTS --*/
  4687. if ($this->is_MB && !$this->usingCoreFont) {
  4688. // Modified by Ivan Tcholakov, 28-JAN-2010.
  4689. //$tmp = mb_strlen( $s, $this->mb_enc );
  4690. $tmp = api_strlen( $s, $this->mb_enc );
  4691. //
  4692. }
  4693. else {
  4694. /*-- END UNICODE-FONTS --*/
  4695. $tmp = strlen( $s );
  4696. } // *UNICODE-FONTS*
  4697. $orphs = 0;
  4698. $check = 0;
  4699. // for every character in the string
  4700. for ( $i = 0; $i < $tmp; $i++ ) {
  4701. // extract the current character
  4702. // get the width of the character in points
  4703. /*-- UNICODE-FONTS --*/
  4704. if ($this->is_MB && !$this->usingCoreFont) {
  4705. // Modified by Ivan Tcholakov, 28-JAN-2010.
  4706. // $c = mb_substr($s,$i,1,$this->mb_enc );
  4707. $c = api_substr($s,$i,1,$this->mb_enc );
  4708. //
  4709. $cw = ($this->GetStringWidth($c) * $this->k);
  4710. }
  4711. else {
  4712. /*-- END UNICODE-FONTS --*/
  4713. $c = $s[$i]; // mPDF 4.4.012
  4714. // mPDF 3.0 Soft Hyphens chr(173)
  4715. if ($c == chr(173) && ($this->FontFamily!='symbol' && $this->FontFamily!='zapfdingbats')) { $cw = 0; }
  4716. else { $cw = $this->CurrentFont[ 'cw' ][ $c ] * ( $this->FontSizePt / 1000 ); }
  4717. } // *UNICODE-FONTS*
  4718. if ($c==' ') { $check = 1; }
  4719. // CHECK for ORPHANS
  4720. else if ($c=='.' || $c==',' || $c==')' || $c==';' || $c==':' || $c=='!' || $c=='?'|| $c=='"' || $c==$curlyquote || $c==$curlylowquote || $c=="\xef\xbc\x8c" || $c=="\xe3\x80\x82") {$check++; }
  4721. else { $check = 0; }
  4722. // There's an orphan '. ' or ', ' or <sup>32</sup> about to be cut off at the end of line
  4723. if($check==1) {
  4724. $currContent .= $c;
  4725. $cutoffWidth = $contentWidth;
  4726. $contentWidth += $cw;
  4727. continue;
  4728. }
  4729. if(($this->SUP || $this->SUB) && ($orphs < $this->orphansAllowed)) { // ? disable orphans in table if borders used
  4730. $currContent .= $c;
  4731. $cutoffWidth = $contentWidth;
  4732. $contentWidth += $cw;
  4733. $orphs++;
  4734. continue;
  4735. }
  4736. else { $orphs = 0; }
  4737. // ADDED for Paragraph_indent
  4738. $WidthCorrection = 0;
  4739. if (($newblock) && ($blockstate==1 || $blockstate==3) && isset($this->blk[$this->blklvl]['text_indent']) && ($lineCount == 0) && (!$is_table) && (!$is_list) && ($align != 'C')) {
  4740. // mPDF 4.0
  4741. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  4742. $WidthCorrection = ($ti*$this->k);
  4743. }
  4744. // Added mPDF 3.0 Float DIV
  4745. $fpaddingR = 0;
  4746. $fpaddingL = 0;
  4747. /*-- CSS-FLOAT --*/
  4748. if (count($this->floatDivs)) {
  4749. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  4750. if ($r_exists) { $fpaddingR = $r_width; }
  4751. if ($l_exists) { $fpaddingL = $l_width; }
  4752. }
  4753. /*-- END CSS-FLOAT --*/
  4754. $usey = $this->y + 0.002;
  4755. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 0) ) {
  4756. $usey += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  4757. }
  4758. /*-- CSS-IMAGE-FLOAT --*/
  4759. // If float exists at this level
  4760. if (isset($this->floatmargins['R']) && $usey <= $this->floatmargins['R']['y1'] && $usey >= $this->floatmargins['R']['y0'] && !$this->floatmargins['R']['skipline']) { $fpaddingR += $this->floatmargins['R']['w']; }
  4761. if (isset($this->floatmargins['L']) && $usey <= $this->floatmargins['L']['y1'] && $usey >= $this->floatmargins['L']['y0'] && !$this->floatmargins['L']['skipline']) { $fpaddingL += $this->floatmargins['L']['w']; }
  4762. /*-- END CSS-IMAGE-FLOAT --*/
  4763. // try adding another char
  4764. if (( $contentWidth + $cw > $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*$this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) ) + 0.001)) {// 0.001 is to correct for deviations converting mm=>pts
  4765. // it won't fit, output what we already have
  4766. $lineCount++;
  4767. // contains any content that didn't make it into this print
  4768. $savedContent = '';
  4769. $savedFont = array();
  4770. // mPDF 4.2.031 Dot Tabs
  4771. $savedObj = array();
  4772. /*-- CJK --*/
  4773. // Change &#x3000; = CJK space
  4774. if ($this->isCJK) {
  4775. if ($this->currentfontfamily == 'sjis' && preg_match("/( |\xe3\x80\x80)/",$currContent) ) { $words = preg_split( "/( |\xe3\x80\x80)/", $currContent ); }
  4776. // If CJK break at space if in ASCII string else break after current character
  4777. else if (isset($this->ords[$c]) && $this->ords[$c]>127) { $words = array(); $words[] = $currContent; }
  4778. else { $words = explode( ' ', $currContent ); }
  4779. }
  4780. // cut off and save any partial words at the end of the string
  4781. else {
  4782. /*-- END CJK --*/
  4783. $words = explode( ' ', $currContent );
  4784. ///////////////////
  4785. // HYPHENATION
  4786. $currWord = $words[count($words)-1] ;
  4787. $success = false;
  4788. /*-- HYPHENATION --*/
  4789. // mPDF 3.0 Soft Hyphens chr(173)
  4790. /*-- UNICODE-FONTS --*/
  4791. if (($this->is_MB && preg_match("/\xc2\xad/",$currWord)) || (!$this->is_MB && preg_match("/".chr(173)."/",$currWord) && ($this->FontFamily!='symbol' && $this->FontFamily!='zapfdingbats')) ) {
  4792. $rem = $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*$this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) );
  4793. list($success,$pre,$post,$prelength) = $this->softHyphenate($currWord, (($rem-$cutoffWidth)/$this->k -$this->GetStringWidth(" ")) );
  4794. }
  4795. /*-- END UNICODE-FONTS --*/
  4796. if (!$success && ($this->hyphenate || ($this->hyphenateTables && $is_table))) {
  4797. // Look ahead to get current word
  4798. // Modified by Ivan Tcholakov, 28-JAN-2010.
  4799. //for($ac = $i; $ac<(mb_strlen($s)-1); $ac++) {
  4800. // $addc = mb_substr($s,$ac,1,$this->mb_enc );
  4801. for($ac = $i; $ac<(api_strlen($s, $this->mb_enc)-1); $ac++) {
  4802. $addc = api_substr($s,$ac,1,$this->mb_enc );
  4803. //
  4804. if ($addc == ' ') { break; }
  4805. $currWord .= $addc;
  4806. }
  4807. $rem = $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*$this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) );
  4808. list($success,$pre,$post,$prelength) = $this->hyphenateWord($currWord, (($rem-$cutoffWidth)/$this->k -$this->GetStringWidth(" ")) );
  4809. }
  4810. if ($success) {
  4811. $already = array_pop( $words );
  4812. // Modified by Ivan Tcholakov, 28-JAN-2010.
  4813. //$forward = mb_substr($already,$prelength,mb_strlen($already, $this->mb_enc), $this->mb_enc);
  4814. $forward = api_substr($already,$prelength,api_strlen($already, $this->mb_enc), $this->mb_enc);
  4815. //
  4816. $words[] = $pre.'-';
  4817. $words[] = $forward;
  4818. // Modified by Ivan Tcholakov, 28-JUN-2010.
  4819. //$currContent = mb_substr($currContent,0,mb_strlen($currContent, $this->mb_enc)+1-mb_strlen($post, $this->mb_enc), $this->mb_enc) . '-'; // mPDF 4.2.009 +1 as $post returned longer
  4820. $currContent = api_substr($currContent,0,api_strlen($currContent, $this->mb_enc)+1-api_strlen($post, $this->mb_enc), $this->mb_enc) . '-'; // mPDF 4.2.009 +1 as $post returned longer
  4821. //
  4822. }
  4823. /*-- END HYPHENATION --*/
  4824. } // *CJK*
  4825. // if it looks like we didn't finish any words for this chunk
  4826. if ( count( $words ) == 1 ) {
  4827. // TO correct for error when word too wide for page - but only when one long word from left to right margin
  4828. if (count($content) == 1 && $currContent != ' ') {
  4829. $lastContent = $words[0];
  4830. $savedFont = $this->saveFont();
  4831. // replace the current content with the cropped version
  4832. $currContent = rtrim( $lastContent ); // mPDF 4.4.012
  4833. }
  4834. else {
  4835. // save and crop off the content currently on the stack
  4836. $savedContent = array_pop( $content );
  4837. $savedFont = array_pop( $font );
  4838. // trim any trailing spaces off the last bit of content
  4839. $currContent =& $content[ count( $content ) - 1 ];
  4840. $currContent = rtrim( $currContent ); // mPDF 4.4.012
  4841. }
  4842. }
  4843. else { // otherwise, we need to find which bit to cut off
  4844. $lastContent = '';
  4845. // mPDF 3.0
  4846. for ( $w = 0; $w < count( $words ) - 1; $w++) { $lastContent .= $words[ $w ]." "; }
  4847. $savedContent = $words[ count( $words ) - 1 ];
  4848. $savedFont = $this->saveFont();
  4849. // replace the current content with the cropped version
  4850. $currContent = rtrim( $lastContent ); // mPDF 4.4.012
  4851. }
  4852. // mPDF 4.2.031 Dot Tabs
  4853. if (isset($this->objectbuffer[(count($content)-1)]) && $this->objectbuffer[(count($content)-1)]['type']=='dottab') {
  4854. $savedObj = array_pop( $this->objectbuffer );
  4855. $contentWidth -= ($this->objectbuffer[(count($content)-1)]['OUTER-WIDTH'] * $this->k);
  4856. }
  4857. // Set Current lineheight (correction factor)
  4858. $lhfixed = false;
  4859. /*-- LISTS --*/
  4860. if ($is_list) {
  4861. if (preg_match('/([0-9.,]+)mm/',$this->list_lineheight[$this->listlvl][$this->listOcc],$am)) {
  4862. $lhfixed = true;
  4863. $def_fontsize = $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listOcc][$this->listnum]['size'];
  4864. $this->lineheight_correction = $am[1] / $def_fontsize ;
  4865. }
  4866. else {
  4867. $this->lineheight_correction = $this->list_lineheight[$this->listlvl][$this->listOcc];
  4868. }
  4869. }
  4870. else
  4871. /*-- END LISTS --*/
  4872. /*-- TABLES --*/
  4873. if ($is_table) {
  4874. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight,$am)) {
  4875. $lhfixed = true;
  4876. $def_fontsize = $this->FontSize; // needs to be default font-size for block ****
  4877. $this->lineheight_correction = $lineHeight / $def_fontsize ;
  4878. }
  4879. else {
  4880. $this->lineheight_correction = $this->table_lineheight;
  4881. }
  4882. }
  4883. else
  4884. /*-- END TABLES --*/
  4885. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  4886. if (preg_match('/([0-9.,]+)mm/',$this->blk[$this->blklvl]['line_height'],$am)) {
  4887. $lhfixed = true;
  4888. $def_fontsize = $this->blk[$this->blklvl]['InlineProperties']['size']; // needs to be default font-size for block ****
  4889. $this->lineheight_correction = $am[1] / $def_fontsize ;
  4890. }
  4891. else {
  4892. $this->lineheight_correction = $this->blk[$this->blklvl]['line_height'];
  4893. }
  4894. }
  4895. else {
  4896. $this->lineheight_correction = $this->normalLineheight;
  4897. }
  4898. // update $contentWidth and $cutoffWidth since they changed with cropping
  4899. // Also correct lineheight to maximum fontsize (not for tables)
  4900. $contentWidth = 0;
  4901. // mPDF 4.2
  4902. // correct lineheight to maximum fontsize
  4903. if ($lhfixed) { $maxlineHeight = $this->lineheight; }
  4904. else { $maxlineHeight = 0; }
  4905. $this->forceExactLineheight = true;
  4906. $maxfontsize = 0;
  4907. foreach ( $content as $k => $chunk )
  4908. {
  4909. $this->restoreFont( $font[ $k ]);
  4910. if (!isset($this->objectbuffer[$k])) {
  4911. /*-- UNICODE-FONTS --*/
  4912. if ($this->is_MB) {
  4913. $content[$k] = $chunk = str_replace("\xc2\xad",'',$chunk );
  4914. }
  4915. // mPDF 3.0 Soft Hyphens chr(173)
  4916. else
  4917. /*-- END UNICODE-FONTS --*/
  4918. if ($this->FontFamily!='symbol' && $this->FontFamily!='zapfdingbats') {
  4919. $content[$k] = $chunk = str_replace($this->chrs[173],'',$chunk );
  4920. }
  4921. $contentWidth += $this->GetStringWidth( $chunk ) * $this->k;
  4922. // mPDF 4.2
  4923. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$this->FontSize * $this->lineheight_correction ); }
  4924. if ($lhfixed && ($this->FontSize > $def_fontsize || ($this->FontSize > ($lineHeight * $this->lineheight_correction) && $is_list))) {
  4925. $this->forceExactLineheight = false;
  4926. }
  4927. $maxfontsize = max($maxfontsize,$this->FontSize);
  4928. }
  4929. }
  4930. // mPDF 4.2 $lastitalic to shorten if line ends with artificial ITALIC
  4931. $lastfontreqstyle = $font[count($font)-1]['ReqFontStyle'];
  4932. $lastfontstyle = $font[count($font)-1]['style'];
  4933. if ($this->directionality == 'ltr' && strpos($lastfontreqstyle,"I") !== false && strpos($lastfontstyle,"I") === false) { // Artificial italic
  4934. $lastitalic = $this->FontSize*0.15*$this->k;
  4935. }
  4936. else { $lastitalic = 0; }
  4937. /*-- LISTS --*/
  4938. // mPDF 4.2 Moved here from later
  4939. if ($is_list && is_array($this->bulletarray) && $this->bulletarray) {
  4940. $actfs = $this->bulletarray['fontsize'];
  4941. if (!$lhfixed) { $maxlineHeight = max($maxlineHeight,$actfs * $this->lineheight_correction ); } // mPDF 4.2
  4942. if ($lhfixed && $actfs > $def_fontsize) { $this->forceExactLineheight = false; }
  4943. $maxfontsize = max($maxfontsize,$actfs);
  4944. }
  4945. /*-- END LISTS --*/
  4946. // when every text item checked i.e. $maxfontsize is set properly
  4947. $af = 0; // Above font
  4948. $bf = 0; // Below font
  4949. $mta = 0; // Maximum top-aligned
  4950. $mba = 0; // Maximum bottom-aligned
  4951. foreach ( $content as $k => $chunk ) {
  4952. if (isset($this->objectbuffer[$k]) && $this->objectbuffer[$k]) {
  4953. $contentWidth += $this->objectbuffer[$k]['OUTER-WIDTH'] * $this->k;
  4954. $oh = $this->objectbuffer[$k]['OUTER-HEIGHT'];
  4955. $va = $this->objectbuffer[$k]['vertical-align']; // = $objattr['vertical-align'] = set as M,T,B,S
  4956. if ($lhfixed && $oh > $def_fontsize) { $this->forceExactLineheight = false; }
  4957. if ($va == 'BS') { // (BASELINE default)
  4958. $af = max($af, ($oh - ($maxfontsize * (0.5 + $this->baselineC))));
  4959. }
  4960. else if ($va == 'M') {
  4961. $af = max($af, ($oh - $maxfontsize)/2);
  4962. $bf = max($bf, ($oh - $maxfontsize)/2);
  4963. }
  4964. else if ($va == 'TT') {
  4965. $bf = max($bf, ($oh - $maxfontsize));
  4966. }
  4967. else if ($va == 'TB') {
  4968. $af = max($af, ($oh - $maxfontsize));
  4969. }
  4970. else if ($va == 'T') {
  4971. $mta = max($mta, $oh);
  4972. }
  4973. else if ($va == 'B') {
  4974. $mba = max($mba, $oh);
  4975. }
  4976. }
  4977. }
  4978. if ((!$lhfixed || !$this->forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) {
  4979. $maxlineHeight = $maxfontsize + $af + $bf;
  4980. }
  4981. else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; }
  4982. if ($mta > $maxlineHeight) {
  4983. $bf += ($mta - $maxlineHeight);
  4984. $maxlineHeight = $mta;
  4985. }
  4986. if ($mba > $maxlineHeight) {
  4987. $af += ($mba - $maxlineHeight);
  4988. $maxlineHeight = $mba;
  4989. }
  4990. $lineHeight = $maxlineHeight;
  4991. $cutoffWidth = $contentWidth;
  4992. // mPDF 4.2 If NOT images, and maxfontsize NOT > lineHeight - this value determines text baseline positioning
  4993. if ($lhfixed && $af==0 && $bf==0 && $maxfontsize<=($def_fontsize * $this->lineheight_correction * 0.8 )) {
  4994. $this->linemaxfontsize = $def_fontsize;
  4995. }
  4996. else { $this->linemaxfontsize = $maxfontsize; }
  4997. // JUSTIFICATION J
  4998. $nb_carac = 0;
  4999. $nb_spaces = 0;
  5000. // 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)
  5001. // mPDF 4.2 $lastitalic to shorten if line ends with artificial ITALIC
  5002. if(( $align == 'J' ) || ($cutoffWidth + $lastitalic > $maxWidth - $WidthCorrection - (($this->cMarginL+$this->cMarginR)*$this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) ) + 0.001)) { // 0.001 is to correct for deviations converting mm=>pts
  5003. // JUSTIFY J (Use character spacing)
  5004. // WORD SPACING
  5005. foreach ( $content as $k => $chunk ) {
  5006. if (!isset($this->objectbuffer[$k]) || (isset($this->objectbuffer[$k]) && !$this->objectbuffer[$k])) {
  5007. /*-- UNICODE-FONTS --*/
  5008. if ($this->is_MB) {
  5009. $chunk = str_replace($this->chrs[194].$this->chrs[160],$this->chrs[32],$chunk );
  5010. }
  5011. else {
  5012. /*-- END UNICODE-FONTS --*/
  5013. $chunk = str_replace($this->chrs[160],$this->chrs[32],$chunk );
  5014. } // *UNICODE-FONTS*
  5015. // Modified by Ivan Tcholakov, 28-JAN-2010.
  5016. //$nb_carac += mb_strlen( $chunk, $this->mb_enc ) ;
  5017. //$nb_spaces += mb_substr_count( $chunk,' ', $this->mb_enc ) ;
  5018. $nb_carac += api_strlen( $chunk, $this->mb_enc ) ;
  5019. $nb_spaces += api_substr_count( $chunk,' ', $this->mb_enc ) ;
  5020. //
  5021. }
  5022. }
  5023. // mPDF 4.2 $lastitalic to shorten if line ends with artificial ITALIC
  5024. list($charspacing,$ws) = $this->GetJspacing($nb_carac,$nb_spaces,($maxWidth-$lastitalic-$cutoffWidth-$WidthCorrection-(($this->cMarginL+$this->cMarginR)*$this->k)-($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) )));
  5025. // mPDF 4.0
  5026. $this->SetSpacing($charspacing,$ws);
  5027. }
  5028. // otherwise, we want normal spacing
  5029. else {
  5030. // mPDF 4.0
  5031. $this->ResetSpacing();
  5032. }
  5033. // WORD SPACING
  5034. // mPDF 4.2 $lastitalic to shorten if line ends with artificial ITALIC
  5035. $empty = $maxWidth - $lastitalic-$WidthCorrection - $contentWidth - (($this->cMarginL+$this->cMarginR)* $this->k) - ($paddingL+$paddingR +(($fpaddingL + $fpaddingR) * $this->k) ) - ( $this->charspacing * $nb_carac) - ( $this->ws * $nb_spaces);
  5036. $empty /= $this->k;
  5037. $b = ''; //do not use borders
  5038. // Get PAGEBREAK TO TEST for height including the top border/padding
  5039. $check_h = max($this->divheight,$lineHeight);
  5040. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($this->blklvl > 0) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5041. $check_h += ($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['border_top']['w']);
  5042. }
  5043. // mPDF 4.2 Force PAGE break if column height cannot take check-height
  5044. if ($this->ColActive && $check_h > ($this->PageBreakTrigger - $this->y0)) { $this->CurrCol = $this->NbCol; }
  5045. // PAGEBREAK
  5046. // 'If' below used in order to fix "first-line of other page with justify on" bug
  5047. // mPDF 4.2.008 Disable in Tables
  5048. if(!$is_table && ($this->y+$check_h) > $this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) {
  5049. $bak_x=$this->x;//Current X position
  5050. // WORD SPACING
  5051. $ws=$this->ws;//Word Spacing
  5052. $charspacing=$this->charspacing;//Character Spacing
  5053. // mPDF 4.0
  5054. $this->ResetSpacing();
  5055. $this->AddPage($this->CurOrientation);
  5056. $this->x = $bak_x;
  5057. // Added to correct for OddEven Margins
  5058. $currentx += $this->MarginCorrection;
  5059. $this->x += $this->MarginCorrection;
  5060. // WORD SPACING
  5061. // mPDF 4.0
  5062. $this->SetSpacing($charspacing,$ws);
  5063. }
  5064. /*-- COLUMNS --*/
  5065. // COLS
  5066. // COLUMN CHANGE
  5067. if ($this->CurrCol != $oldcolumn) {
  5068. $currentx += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5069. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5070. $oldcolumn = $this->CurrCol;
  5071. }
  5072. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5073. /*-- END COLUMNS --*/
  5074. // TOP MARGIN
  5075. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($this->blk[$this->blklvl]['margin_top']) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5076. $this->DivLn($this->blk[$this->blklvl]['margin_top'],$this->blklvl-1,true,$this->blk[$this->blklvl]['margin_collapse']);
  5077. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5078. }
  5079. // Update y0 for top of block (used to paint border)
  5080. if (($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5081. $this->blk[$this->blklvl]['y0'] = $this->y;
  5082. $this->blk[$this->blklvl]['startpage'] = $this->page;
  5083. }
  5084. // TOP PADDING and BORDER spacing/fill
  5085. if (($newblock) && ($blockstate==1 || $blockstate==3) && (($this->blk[$this->blklvl]['padding_top']) || ($this->blk[$this->blklvl]['border_top'])) && ($lineCount == 1) && (!$is_table) && (!$is_list)) {
  5086. // mPDF 3.0 Also does border when Columns active
  5087. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  5088. $this->DivLn($this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'],-3,true,false,1);
  5089. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5090. }
  5091. $arraysize = count($content);
  5092. $margins = ($this->cMarginL+$this->cMarginR) + ($ipaddingL+$ipaddingR + $fpaddingR + $fpaddingR );
  5093. // PAINT BACKGROUND FOR THIS LINE
  5094. if (!$is_table) { $this->DivLn($lineHeight,$this->blklvl,false); } // false -> don't advance y
  5095. $this->x = $currentx + $this->cMarginL + $ipaddingL + $fpaddingL ;
  5096. if ($align == 'R') { $this->x += $empty; }
  5097. else if ($align == 'C') { $this->x += ($empty / 2); }
  5098. // Paragraph INDENT
  5099. if (isset($this->blk[$this->blklvl]['text_indent']) && ($newblock) && ($blockstate==1 || $blockstate==3) && ($lineCount == 1) && (!$is_table) && ($this->directionality!='rtl') && ($align !='C')) {
  5100. // mPDF 4.0
  5101. $ti = $this->ConvertSize($this->blk[$this->blklvl]['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  5102. $this->x += $ti;
  5103. }
  5104. // DIRECTIONALITY RTL
  5105. $all_rtl = false;
  5106. $contains_rtl = false;
  5107. /*-- RTL --*/
  5108. if (($this->directionality == 'rtl') || (($this->directionality == 'ltr') && ($this->biDirectional))) {
  5109. $all_rtl = true;
  5110. foreach ( $content as $k => $chunk ) {
  5111. $reversed = $this->magic_reverse_dir($chunk, false);
  5112. if ($reversed > 0) { $contains_rtl = true; }
  5113. if ($reversed < 2) { $all_rtl = false; }
  5114. $content[$k] = $chunk;
  5115. }
  5116. if ($this->directionality == 'rtl') {
  5117. if ($contains_rtl) {
  5118. $content = array_reverse($content,false);
  5119. }
  5120. }
  5121. else if (($this->directionality == 'ltr') && ($this->biDirectional)) {
  5122. if ($all_rtl) {
  5123. $content = array_reverse($content,false);
  5124. }
  5125. }
  5126. }
  5127. /*-- END RTL --*/
  5128. foreach ( $content as $k => $chunk ) {
  5129. // FOR IMAGES - UPDATE POSITION
  5130. if (($this->directionality=='rtl' && $contains_rtl) || $all_rtl) { $dirk = $arraysize-1 - $k ; } else { $dirk = $k; }
  5131. // mPDF 4.2
  5132. $va = 'M'; // default for text
  5133. if (isset($this->objectbuffer[$dirk]) && $this->objectbuffer[$dirk]) {
  5134. $xadj = $this->x - $this->objectbuffer[$dirk]['OUTER-X'] ;
  5135. $this->objectbuffer[$dirk]['OUTER-X'] += $xadj;
  5136. $this->objectbuffer[$dirk]['BORDER-X'] += $xadj;
  5137. $this->objectbuffer[$dirk]['INNER-X'] += $xadj;
  5138. // mPDF 4.2
  5139. $va = $this->objectbuffer[$dirk]['vertical-align'];
  5140. $yadj = $this->y - $this->objectbuffer[$dirk]['OUTER-Y'];
  5141. if ($va == 'BS') {
  5142. $yadj += $af + ($this->linemaxfontsize * (0.5 + $this->baselineC)) - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  5143. }
  5144. else if ($va == 'M' || $va == '') {
  5145. $yadj += $af + ($this->linemaxfontsize /2) - ($this->objectbuffer[$dirk]['OUTER-HEIGHT']/2);
  5146. }
  5147. else if ($va == 'TB') {
  5148. $yadj += $af + $this->linemaxfontsize - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  5149. }
  5150. else if ($va == 'TT') {
  5151. $yadj += $af;
  5152. }
  5153. else if ($va == 'B') {
  5154. $yadj += $af + $this->linemaxfontsize + $bf - $this->objectbuffer[$dirk]['OUTER-HEIGHT'];
  5155. }
  5156. else if ($va == 'T') {
  5157. $yadj += 0;
  5158. }
  5159. $this->objectbuffer[$dirk]['OUTER-Y'] += $yadj;
  5160. $this->objectbuffer[$dirk]['BORDER-Y'] += $yadj;
  5161. $this->objectbuffer[$dirk]['INNER-Y'] += $yadj;
  5162. }
  5163. // DIRECTIONALITY RTL
  5164. if ((($this->directionality == 'rtl') && ($contains_rtl )) || ($all_rtl )) { $this->restoreFont($font[$arraysize-1 - $k]); }
  5165. else { $this->restoreFont( $font[ $k ] ); }
  5166. // *********** SPAN BACKGROUND COLOR ***************** //
  5167. if ($this->spanbgcolor) {
  5168. $cor = $this->spanbgcolorarray;
  5169. $this->SetFillColor($cor['R'],$cor['G'],$cor['B']);
  5170. $save_fill = $fill; $spanfill = 1; $fill = 1;
  5171. }
  5172. // WORD SPACING
  5173. // Modified by Ivan Tcholakov, 28-JAN-2010.
  5174. // $stringWidth = $this->GetStringWidth($chunk ) + ( $this->charspacing * mb_strlen($chunk,$this->mb_enc ) / $this->k )
  5175. // + ( $this->ws * mb_substr_count($chunk,' ',$this->mb_enc ) / $this->k );
  5176. $stringWidth = $this->GetStringWidth($chunk ) + ( $this->charspacing * api_strlen($chunk,$this->mb_enc ) / $this->k )
  5177. + ( $this->ws * api_substr_count($chunk,' ',$this->mb_enc ) / $this->k );
  5178. //
  5179. if (isset($this->objectbuffer[$dirk])) { $stringWidth = $this->objectbuffer[$dirk]['OUTER-WIDTH']; }
  5180. if ($stringWidth > 0) {
  5181. if ($k == $arraysize-1) {
  5182. $stringWidth -= ( $this->charspacing / $this->k );
  5183. // mPDF 4.2 af , bf above and below font
  5184. $this->Cell( $stringWidth, $lineHeight, $chunk, '', 1, '', $fill, $this->HREF , $currentx,0,0,'M', $fill, $af, $bf ); //mono-style line or last part (skips line)
  5185. }
  5186. else $this->Cell( $stringWidth, $lineHeight, $chunk, '', 0, '', $fill, $this->HREF, 0, 0,0,'M', $fill, $af, $bf );//first or middle part
  5187. }
  5188. else { // If a space started a new chunk at the end of a line
  5189. $this->x = $currentx; $this->y += $lineHeight;
  5190. }
  5191. // *********** SPAN BACKGROUND COLOR OFF - RESET BLOCK BGCOLOR ***************** //
  5192. if (isset($spanfill) && $spanfill) {
  5193. $fill = $save_fill; $spanfill = 0;
  5194. if ($fill) { $this->SetFillColor($bcor['R'],$bcor['G'],$bcor['B']); }
  5195. }
  5196. }
  5197. // mPDF 4.0
  5198. if (!$is_table) {
  5199. $this->maxPosR = max($this->maxPosR , ($this->w - $this->rMargin - $this->blk[$this->blklvl]['outer_right_margin']));
  5200. $this->maxPosL = min($this->maxPosL , ($this->lMargin + $this->blk[$this->blklvl]['outer_left_margin']));
  5201. }
  5202. // move on to the next line, reset variables, tack on saved content and current char
  5203. $this->printobjectbuffer($is_table);
  5204. $this->objectbuffer = array();
  5205. /*-- LISTS --*/
  5206. // LIST BULLETS/NUMBERS
  5207. if ($is_list && is_array($this->bulletarray) && ($lineCount == 1) ) {
  5208. // mPDF 4.0
  5209. $this->ResetSpacing();
  5210. $bull = $this->bulletarray;
  5211. if (isset($bull['level']) && isset($bull['occur']) && isset($this->InlineProperties['LIST'][$bull['level']][$bull['occur']])) {
  5212. $this->restoreInlineProperties($this->InlineProperties['LIST'][$bull['level']][$bull['occur']]);
  5213. }
  5214. 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']]); }
  5215. if (isset($bull['font']) && $bull['font'] == 'zapfdingbats') {
  5216. $this->bullet = true;
  5217. $this->SetFont('zapfdingbats','',$this->FontSizePt/2.5);
  5218. }
  5219. else { $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); } // force output
  5220. //Output bullet
  5221. $this->x = $currentx;
  5222. if (isset($bull['x'])) { $this->x += $bull['x']; }
  5223. $this->y -= $lineHeight;
  5224. // mPDF 4.0
  5225. if (isset($bull['txt'])) { $this->Cell($bull['w'], $lineHeight,$bull['txt'],'','',$bull['align'],0,'',0,-$this->cMarginL, -$this->cMarginR ); }
  5226. if (isset($bull['font']) && $bull['font'] == 'zapfdingbats') {
  5227. $this->bullet = false;
  5228. }
  5229. $this->x = $currentx; // Reset
  5230. $this->y += $lineHeight;
  5231. if ($this->ColActive && !$is_table) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  5232. $this->bulletarray = array(); // prevents repeat of bullet/number if <li>....<br />.....</li>
  5233. }
  5234. /*-- END LISTS --*/
  5235. /*-- CSS-IMAGE-FLOAT --*/
  5236. // Update values if set to skipline
  5237. if ($this->floatmargins) { $this->_advanceFloatMargins(); }
  5238. /*-- END CSS-IMAGE-FLOAT --*/
  5239. // Reset lineheight
  5240. $lineHeight = $this->divheight;
  5241. $valign = 'M';
  5242. $this->restoreFont( $savedFont );
  5243. // mPDF 4.2.031 Dot Tabs
  5244. $font = array();
  5245. $content = array();
  5246. $contentWidth = 0;
  5247. if (!empty($savedObj)) {
  5248. $this->objectbuffer[] = $savedObj;
  5249. $font[] = $savedFont;
  5250. $content[] = '';
  5251. $contentWidth += $savedObj['OUTER-WIDTH'] * $this->k;
  5252. }
  5253. $font[] = $savedFont;
  5254. $content[] = $savedContent . $c;
  5255. $currContent =& $content[ (count($content)-1) ];
  5256. $contentWidth += $this->GetStringWidth( $currContent ) * $this->k;
  5257. $cutoffWidth = $contentWidth;
  5258. }
  5259. // another character will fit, so add it on
  5260. else {
  5261. $contentWidth += $cw;
  5262. $currContent .= $c;
  5263. }
  5264. }
  5265. unset($content);
  5266. }
  5267. //----------------------END OF FLOWING BLOCK------------------------------------//
  5268. /*-- CSS-IMAGE-FLOAT --*/
  5269. // Update values if set to skipline
  5270. function _advanceFloatMargins() {
  5271. // Update floatmargins - L
  5272. if (isset($this->floatmargins['L']) && $this->floatmargins['L']['skipline'] && $this->floatmargins['L']['y0'] != $this->y) {
  5273. $yadj = $this->y - $this->floatmargins['L']['y0'];
  5274. $this->floatmargins['L']['y0'] = $this->y;
  5275. $this->floatmargins['L']['y1'] += $yadj;
  5276. // Update objattr in floatbuffer
  5277. if ($this->floatbuffer[$this->floatmargins['L']['id']]['border_left']['w']) {
  5278. $this->floatbuffer[$this->floatmargins['L']['id']]['BORDER-Y'] += $yadj;
  5279. }
  5280. $this->floatbuffer[$this->floatmargins['L']['id']]['INNER-Y'] += $yadj;
  5281. $this->floatbuffer[$this->floatmargins['L']['id']]['OUTER-Y'] += $yadj;
  5282. // Unset values
  5283. $this->floatbuffer[$this->floatmargins['L']['id']]['skipline'] = false;
  5284. $this->floatmargins['L']['skipline'] = false;
  5285. $this->floatmargins['L']['id'] = '';
  5286. }
  5287. // Update floatmargins - R
  5288. if (isset($this->floatmargins['R']) && $this->floatmargins['R']['skipline'] && $this->floatmargins['R']['y0'] != $this->y) {
  5289. $yadj = $this->y - $this->floatmargins['R']['y0'];
  5290. $this->floatmargins['R']['y0'] = $this->y;
  5291. $this->floatmargins['R']['y1'] += $yadj;
  5292. // Update objattr in floatbuffer
  5293. if ($this->floatbuffer[$this->floatmargins['R']['id']]['border_left']['w']) {
  5294. $this->floatbuffer[$this->floatmargins['R']['id']]['BORDER-Y'] += $yadj;
  5295. }
  5296. $this->floatbuffer[$this->floatmargins['R']['id']]['INNER-Y'] += $yadj;
  5297. $this->floatbuffer[$this->floatmargins['R']['id']]['OUTER-Y'] += $yadj;
  5298. // Unset values
  5299. $this->floatbuffer[$this->floatmargins['R']['id']]['skipline'] = false;
  5300. $this->floatmargins['R']['skipline'] = false;
  5301. $this->floatmargins['R']['id'] = '';
  5302. }
  5303. }
  5304. /*-- END CSS-IMAGE-FLOAT --*/
  5305. ////////////////////////////////////////////////////////////////////////////////
  5306. // ADDED forcewrap - to call from inline OBJECT functions to breakwords if necessary in cell
  5307. ////////////////////////////////////////////////////////////////////////////////
  5308. function WordWrap(&$text, $maxwidth, $forcewrap = 0) {
  5309. $biggestword=0;
  5310. $toonarrow=false;
  5311. $text = trim($text); // mPDF 4.4.012
  5312. if ($text==='') return 0;
  5313. $space = $this->GetStringWidth(' ');
  5314. $lines = explode("\n", $text); // mPDF 4.4.012
  5315. $text = '';
  5316. $count = 0;
  5317. foreach ($lines as $line) {
  5318. $words = explode(' ', $line); // mPDF 4.4.012
  5319. $width = 0;
  5320. foreach ($words as $word) {
  5321. $word = trim($word); // mPDF 4.4.012
  5322. $wordwidth = $this->GetStringWidth($word);
  5323. //Warn user that maxwidth is insufficient
  5324. if ($wordwidth > $maxwidth + 0.0001) {
  5325. if ($wordwidth > $biggestword) { $biggestword = $wordwidth; }
  5326. $toonarrow=true;
  5327. // ADDED
  5328. if ($forcewrap) {
  5329. while($wordwidth > $maxwidth) {
  5330. $chw = 0; // check width
  5331. // Modified by Ivan Tcholakov, 28-JAN-2010.
  5332. //for ( $i = 0; $i < mb_strlen($word, $this->mb_enc ); $i++ ) {
  5333. // $chw = $this->GetStringWidth(mb_substr($word,0,$i+1,$this->mb_enc ));
  5334. for ( $i = 0; $i < api_strlen($word, $this->mb_enc ); $i++ ) {
  5335. $chw = $this->GetStringWidth(api_substr($word,0,$i+1,$this->mb_enc ));
  5336. //
  5337. if ($chw > $maxwidth ) {
  5338. if ($text) {
  5339. // Modified by Ivan Tcholakov, 28-JUN-2010.
  5340. //$text = rtrim($text)."\n".mb_substr($word,0,$i,$this->mb_enc ); // mPDF 4.4.012
  5341. $text = rtrim($text)."\n".api_substr($word,0,$i,$this->mb_enc ); // mPDF 4.4.012
  5342. //
  5343. $count++;
  5344. }
  5345. else {
  5346. // Modified by Ivan Tcholakov, 28-JAN-2010.
  5347. //$text = mb_substr($word,0,$i,$this->mb_enc );
  5348. $text = api_substr($word,0,$i,$this->mb_enc );
  5349. //
  5350. }
  5351. // Modified by Ivan Tcholakov, 28-JAN-2010.
  5352. //$word = mb_substr($word,$i,mb_strlen($word, $this->mb_enc )-$i,$this->mb_enc );
  5353. $word = api_substr($word,$i,api_strlen($word, $this->mb_enc )-$i,$this->mb_enc );
  5354. //
  5355. $wordwidth = $this->GetStringWidth($word);
  5356. $width = $maxwidth;
  5357. break;
  5358. }
  5359. }
  5360. }
  5361. }
  5362. }
  5363. if ($width + $wordwidth < $maxwidth - 0.0001) {
  5364. $width += $wordwidth + $space;
  5365. $text .= $word.' ';
  5366. }
  5367. else {
  5368. $width = $wordwidth + $space;
  5369. $text = rtrim($text)."\n".$word.' '; // mPDF 4.4.012
  5370. $count++;
  5371. }
  5372. }
  5373. $text = rtrim($text)."\n"; // mPDF 4.4.012
  5374. $count++;
  5375. }
  5376. $text = rtrim($text); // mPDF 4.4.012
  5377. //Return -(wordsize) if word is bigger than maxwidth
  5378. // ADDED
  5379. if ($forcewrap) { return $count; }
  5380. if (($toonarrow) && ($this->table_error_report)) {
  5381. $this->Error("Word is too long to fit in table - ".$this->table_error_report_param);
  5382. }
  5383. if ($toonarrow) return -$biggestword;
  5384. else return $count;
  5385. }
  5386. function _SetTextRendering($mode) {
  5387. if (!(($mode == 0) || ($mode == 1) || ($mode == 2)))
  5388. $this->Error("Text rendering mode should be 0, 1 or 2 (value : $mode)");
  5389. $tr = ($mode.' Tr');
  5390. 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); }
  5391. $this->pageoutput[$this->page]['TextRendering'] = $tr;
  5392. }
  5393. function SetTextOutline($width, $r=0, $g=-1, $b=-1) {
  5394. if ($width == false) //Now resets all values
  5395. {
  5396. $this->outline_on = false;
  5397. $this->SetLineWidth(0.2);
  5398. $this->SetDrawColor(0);
  5399. $this->_SetTextRendering(0);
  5400. $tr = ('0 Tr');
  5401. 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); }
  5402. $this->pageoutput[$this->page]['TextRendering'] = $tr;
  5403. }
  5404. else
  5405. {
  5406. $this->SetLineWidth($width);
  5407. $this->SetDrawColor($r, $g , $b);
  5408. $tr = ('2 Tr');
  5409. 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); }
  5410. $this->pageoutput[$this->page]['TextRendering'] = $tr;
  5411. }
  5412. }
  5413. // mPDF 4.2
  5414. function Image($file,$x,$y,$w=0,$h=0,$type='',$link='',$paint=true, $constrain=true, $watermark=false, $shownoimg=true, $allowvector=true) {
  5415. $orig_srcpath = $file; // mPDF 4.2.029
  5416. $this->GetFullPath($file); // mPDF 4.2.029
  5417. $info=$this->_getImage($file, true, $allowvector, $orig_srcpath ); // mPDF 4.2.029
  5418. if(!$info && $paint) {
  5419. $info = $this->_getImage($this->noImageFile);
  5420. if ($info) {
  5421. $file = $this->noImageFile;
  5422. $w = ($info['w'] * (25.4/$this->dpi)); // 14 x 16px
  5423. $h = ($info['h'] * (25.4/$this->dpi)); // 14 x 16px
  5424. }
  5425. }
  5426. if(!$info) return false; // mPDF 4.2
  5427. //Automatic width and height calculation if needed
  5428. if($w==0 and $h==0) {
  5429. /*-- IMAGES-WMF --*/
  5430. if ($info['type']=='wmf') {
  5431. // WMF units are twips (1/20pt)
  5432. // divide by 20 to get points
  5433. // divide by k to get user units
  5434. $w = abs($info['w'])/(20*$this->k);
  5435. $h = abs($info['h']) / (20*$this->k);
  5436. }
  5437. else
  5438. /*-- END IMAGES-WMF --*/
  5439. if ($info['type']=='svg') {
  5440. // returned SVG units are pts
  5441. // divide by k to get user units (mm)
  5442. $w = abs($info['w'])/$this->k;
  5443. $h = abs($info['h']) /$this->k;
  5444. }
  5445. else {
  5446. //Put image at default image dpi
  5447. $w=($info['w']/$this->k) * (72/$this->img_dpi);
  5448. $h=($info['h']/$this->k) * (72/$this->img_dpi);
  5449. }
  5450. }
  5451. if($w==0) $w=abs($h*$info['w']/$info['h']);
  5452. if($h==0) $h=abs($w*$info['h']/$info['w']);
  5453. /*-- WATERMARK --*/
  5454. if ($watermark) {
  5455. $maxw = $this->w;
  5456. $maxh = $this->h;
  5457. // Size = D PF or array
  5458. if (is_array($this->watermark_size)) {
  5459. $w = $this->watermark_size[0];
  5460. $h = $this->watermark_size[1];
  5461. }
  5462. else if (!is_string($this->watermark_size)) {
  5463. $maxw -= $this->watermark_size*2;
  5464. $maxh -= $this->watermark_size*2;
  5465. $w = $maxw;
  5466. $h=abs($w*$info['h']/$info['w']);
  5467. if ($h > $maxh ) {
  5468. $h = $maxh ; $w=abs($h*$info['w']/$info['h']);
  5469. }
  5470. }
  5471. else if ($this->watermark_size == 'F') {
  5472. if ($this->ColActive) { $maxw = $this->w - ($this->DeflMargin + $this->DefrMargin); }
  5473. else { $maxw = $this->pgwidth; }
  5474. $maxh = $this->h - ($this->tMargin + $this->bMargin);
  5475. $w = $maxw;
  5476. $h=abs($w*$info['h']/$info['w']);
  5477. if ($h > $maxh ) {
  5478. $h = $maxh ; $w=abs($h*$info['w']/$info['h']);
  5479. }
  5480. }
  5481. else if ($this->watermark_size == 'P') { // Default P
  5482. $w = $maxw;
  5483. $h=abs($w*$info['h']/$info['w']);
  5484. if ($h > $maxh ) {
  5485. $h = $maxh ; $w=abs($h*$info['w']/$info['h']);
  5486. }
  5487. }
  5488. // Automatically resize to maximum dimensions of page if too large
  5489. if ($w > $maxw) {
  5490. $w = $maxw;
  5491. $h=abs($w*$info['h']/$info['w']);
  5492. }
  5493. if ($h > $maxh ) {
  5494. $h = $maxh ;
  5495. $w=abs($h*$info['w']/$info['h']);
  5496. }
  5497. // Position
  5498. if (is_array($this->watermark_pos)) {
  5499. $x = $this->watermark_pos[0];
  5500. $y = $this->watermark_pos[1];
  5501. }
  5502. else if ($this->watermark_pos == 'F') { // centred on printable area
  5503. if ($this->ColActive) { // *COLUMNS*
  5504. if (($this->mirrorMargins) && (($this->page)%2==0)) { $xadj = $this->DeflMargin-$this->DefrMargin; } // *COLUMNS*
  5505. else { $xadj = 0; } // *COLUMNS*
  5506. $x = ($this->DeflMargin - $xadj + ($this->w - ($this->DeflMargin + $this->DefrMargin))/2) - ($w/2); // *COLUMNS*
  5507. } // *COLUMNS*
  5508. else { // *COLUMNS*
  5509. $x = ($this->lMargin + ($this->pgwidth)/2) - ($w/2);
  5510. } // *COLUMNS*
  5511. $y = ($this->tMargin + ($this->h - ($this->tMargin + $this->bMargin))/2) - ($h/2);
  5512. }
  5513. else { // default P - centred on whole page
  5514. $x = ($this->w/2) - ($w/2);
  5515. $y = ($this->h/2) - ($h/2);
  5516. }
  5517. /*-- IMAGES-WMF --*/
  5518. if ($info['type']=='wmf') {
  5519. $sx = $w*$this->k / $info['w'];
  5520. $sy = -$h*$this->k / $info['h'];
  5521. $outstring = sprintf('q %.3f 0 0 %.3f %.3f %.3f cm /FO%d Do Q', $sx, $sy, $x*$this->k-$sx*$info['x'], (($this->h-$y)*$this->k)-$sy*$info['y'], $info['i']); // mPDF 4.5.007
  5522. }
  5523. else
  5524. /*-- END IMAGES-WMF --*/
  5525. // mPDF 4.3.013
  5526. if ($info['type']=='svg') {
  5527. $sx = $w*$this->k / $info['w'];
  5528. $sy = -$h*$this->k / $info['h'];
  5529. $outstring = sprintf('q %.3f 0 0 %.3f %.3f %.3f cm /FO%d Do Q', $sx, $sy, $x*$this->k-$sx*$info['x'], (($this->h-$y)*$this->k)-$sy*$info['y'], $info['i']);
  5530. }
  5531. else {
  5532. $outstring = sprintf("q %.3f 0 0 %.3f %.3f %.3f cm /I%d Do Q",$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i']);
  5533. }
  5534. // mPDF 4.3.018
  5535. if ($this->watermarkImgBehind) {
  5536. $outstring = $this->watermarkImgAlpha . "\n" . $outstring . "\n" . $this->SetAlpha(1, 'Normal', true) . "\n";
  5537. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$outstring."\n".'\\1', $this->pages[$this->page]);
  5538. }
  5539. else { $this->_out($outstring); }
  5540. return 0;
  5541. } // end of IF watermark
  5542. /*-- END WATERMARK --*/
  5543. if ($constrain) {
  5544. // Automatically resize to maximum dimensions of page if too large
  5545. if (isset($this->blk[$this->blklvl]['inner_width']) && $this->blk[$this->blklvl]['inner_width']) { $maxw = $this->blk[$this->blklvl]['inner_width']; }
  5546. else { $maxw = $this->pgwidth; }
  5547. if ($w > $maxw) {
  5548. $w = $maxw;
  5549. $h=abs($w*$info['h']/$info['w']);
  5550. }
  5551. if ($h > $this->h - ($this->tMargin + $this->bMargin + 10)) { // see below - +10 to avoid drawing too close to border of page
  5552. $h = $this->h - ($this->tMargin + $this->bMargin + 10) ; // mPDF 4.1
  5553. if ($this->fullImageHeight) { $h = $this->fullImageHeight; } // mPDF 4.1
  5554. $w=abs($h*$info['w']/$info['h']);
  5555. }
  5556. //Avoid drawing out of the paper(exceeding width limits).
  5557. //if ( ($x + $w) > $this->fw ) {
  5558. if ( ($x + $w) > $this->w ) {
  5559. $x = $this->lMargin;
  5560. $y += 5;
  5561. }
  5562. $changedpage = false;
  5563. $oldcolumn = $this->CurrCol;
  5564. //Avoid drawing out of the page.
  5565. if($y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) {
  5566. $this->AddPage($this->CurOrientation);
  5567. // Added to correct for OddEven Margins
  5568. $x=$x +$this->MarginCorrection;
  5569. $y = $tMargin + $this->margin_header;
  5570. $changedpage = true;
  5571. }
  5572. /*-- COLUMNS --*/
  5573. // COLS
  5574. // COLUMN CHANGE
  5575. if ($this->CurrCol != $oldcolumn) {
  5576. $y = $this->y0;
  5577. $x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5578. $this->x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  5579. }
  5580. /*-- END COLUMNS --*/
  5581. } // end of IF constrain
  5582. /*-- IMAGES-WMF --*/
  5583. if ($info['type']=='wmf') {
  5584. $sx = $w*$this->k / $info['w'];
  5585. $sy = -$h*$this->k / $info['h'];
  5586. $outstring = sprintf('q %.3f 0 0 %.3f %.3f %.3f cm /FO%d Do Q', $sx, $sy, $x*$this->k-$sx*$info['x'], (($this->h-$y)*$this->k)-$sy*$info['y'], $info['i']); // mPDF 4.5.007
  5587. }
  5588. else
  5589. /*-- END IMAGES-WMF --*/
  5590. // mPDF 4.3.013
  5591. if ($info['type']=='svg') {
  5592. $sx = $w*$this->k / $info['w'];
  5593. $sy = -$h*$this->k / $info['h'];
  5594. $outstring = sprintf('q %.3f 0 0 %.3f %.3f %.3f cm /FO%d Do Q', $sx, $sy, $x*$this->k-$sx*$info['x'], (($this->h-$y)*$this->k)-$sy*$info['y'], $info['i']); // mPDF 4.5.007
  5595. }
  5596. else {
  5597. $outstring = sprintf("q %.3f 0 0 %.3f %.3f %.3f cm /I%d Do Q",$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i']);
  5598. }
  5599. if($paint) {
  5600. $this->_out($outstring);
  5601. if($link) $this->Link($x,$y,$w,$h,$link);
  5602. // Avoid writing text on top of the image. // THIS WAS OUTSIDE THE if ($paint) bit!!!!!!!!!!!!!!!!
  5603. $this->y = $y + $h;
  5604. }
  5605. //Return width-height array
  5606. $sizesarray['WIDTH'] = $w;
  5607. $sizesarray['HEIGHT'] = $h;
  5608. $sizesarray['X'] = $x; //Position before painting image
  5609. $sizesarray['Y'] = $y; //Position before painting image
  5610. $sizesarray['OUTPUT'] = $outstring;
  5611. // mPDF 3.0 Tiling patterns
  5612. $sizesarray['IMAGE_ID'] = $info['i'];
  5613. return $sizesarray;
  5614. }
  5615. //=============================================================
  5616. //=============================================================
  5617. //=============================================================
  5618. //=============================================================
  5619. //=============================================================
  5620. // mPDF 4.0
  5621. function _getObjAttr($t) {
  5622. $c = explode("\xbb\xa4\xac",$t,2);
  5623. $c = explode(",",$c[1],2);
  5624. foreach($c as $v) {
  5625. $v = explode("=",$v,2);
  5626. $sp[$v[0]] = $v[1];
  5627. }
  5628. return (unserialize($sp['objattr']));
  5629. }
  5630. function inlineObject($type,$x,$y,$objattr,$Lmargin,$widthUsed,$maxWidth,$lineHeight,$paint=false,$is_table=false)
  5631. {
  5632. if ($is_table) { $k = $this->shrin_k; } else { $k = 1; }
  5633. // NB $x is only used when paint=true
  5634. // Lmargin not used
  5635. $w = 0;
  5636. if (isset($objattr['width'])) { $w = $objattr['width']/$k; }
  5637. $h = 0;
  5638. if (isset($objattr['height'])) { $h = abs($objattr['height']/$k); }
  5639. $widthLeft = $maxWidth - $widthUsed;
  5640. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 10) ; // mPDF 4.1
  5641. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; } // mPDF 4.1
  5642. // For Images
  5643. if (isset($objattr['border_left'])) {
  5644. $extraWidth = ($objattr['border_left']['w'] + $objattr['border_right']['w'] + $objattr['margin_left']+ $objattr['margin_right'])/$k;
  5645. $extraHeight = ($objattr['border_top']['w'] + $objattr['border_bottom']['w'] + $objattr['margin_top']+ $objattr['margin_bottom'])/$k;
  5646. // mPDF 4.0
  5647. if ($type == 'image' || $type == 'barcode') {
  5648. $extraWidth += ($objattr['padding_left'] + $objattr['padding_right'])/$k;
  5649. $extraHeight += ($objattr['padding_top'] + $objattr['padding_bottom'])/$k;
  5650. }
  5651. }
  5652. // mPDF 4.2 Failsafe (e.g. for HR)
  5653. if (!isset($objattr['vertical-align'])) { $objattr['vertical-align'] = 'M'; }
  5654. if ($type == 'image' || (isset($objattr['subtype']) && $objattr['subtype'] == 'IMAGE')) {
  5655. if (isset($objattr['itype']) && ($objattr['itype'] == 'wmf' || $objattr['itype'] == 'svg')) { // mPDF 4.3.013
  5656. $file = $objattr['file'];
  5657. $info=$this->formobjects[$file];
  5658. }
  5659. else if (isset($objattr['file'])) {
  5660. $file = $objattr['file'];
  5661. $info=$this->images[$file];
  5662. }
  5663. }
  5664. // mPDF 3.0
  5665. if ($type == 'annot' || $type == 'bookmark' || $type == 'indexentry' || $type == 'toc') {
  5666. $w = 0.00001;
  5667. $h = 0.00001;
  5668. }
  5669. // TEST whether need to skipline
  5670. if (!$paint) {
  5671. if ($type == 'hr') { // always force new line
  5672. if (($y + $h + $lineHeight > $this->PageBreakTrigger) && !$this->InFooter && !$is_table) { return array(-2, $w ,$h ); } // New page + new line
  5673. else { return array(1, $w ,$h ); } // new line
  5674. }
  5675. else {
  5676. if ($widthUsed > 0 && $w > $widthLeft && (!$is_table || $type != 'image')) { // New line needed
  5677. if (($y + $h + $lineHeight > $this->PageBreakTrigger) && !$this->InFooter) { return array(-2,$w ,$h ); } // New page + new line
  5678. return array(1,$w ,$h ); // new line
  5679. }
  5680. // mPDF 4.2.011
  5681. else if ($widthUsed > 0 && $w > $widthLeft && $is_table) { // New line needed in TABLE
  5682. return array(1,$w ,$h ); // new line
  5683. }
  5684. // Will fit on line but NEW PAGE REQUIRED
  5685. else if (($y + $h > $this->PageBreakTrigger) && !$this->InFooter && !$is_table) { return array(-1,$w ,$h ); }
  5686. else { return array(0,$w ,$h ); }
  5687. }
  5688. }
  5689. // mPDF 3.0
  5690. if ($type == 'annot' || $type == 'bookmark' || $type == 'indexentry' || $type == 'toc') {
  5691. $w = 0.00001;
  5692. $h = 0.00001;
  5693. $objattr['BORDER-WIDTH'] = 0;
  5694. $objattr['BORDER-HEIGHT'] = 0;
  5695. $objattr['BORDER-X'] = $x;
  5696. $objattr['BORDER-Y'] = $y;
  5697. $objattr['INNER-WIDTH'] = 0;
  5698. $objattr['INNER-HEIGHT'] = 0;
  5699. $objattr['INNER-X'] = $x;
  5700. $objattr['INNER-Y'] = $y;
  5701. }
  5702. if ($type == 'image') {
  5703. // Automatically resize to width remaining
  5704. if ($w > $widthLeft && !$is_table) {
  5705. $w = $widthLeft ;
  5706. $h=abs($w*$info['h']/$info['w']);
  5707. }
  5708. $img_w = $w - $extraWidth ;
  5709. $img_h = $h - $extraHeight ;
  5710. // mPDF 4.0
  5711. $objattr['BORDER-WIDTH'] = $img_w + $objattr['padding_left']/$k + $objattr['padding_right']/$k + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ;
  5712. $objattr['BORDER-HEIGHT'] = $img_h + $objattr['padding_top']/$k + $objattr['padding_bottom']/$k + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ;
  5713. $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ;
  5714. $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ;
  5715. $objattr['INNER-WIDTH'] = $img_w;
  5716. $objattr['INNER-HEIGHT'] = $img_h;
  5717. $objattr['INNER-X'] = $x + $objattr['padding_left']/$k + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k);
  5718. $objattr['INNER-Y'] = $y + $objattr['padding_top']/$k + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ;
  5719. $objattr['ID'] = $info['i'];
  5720. }
  5721. if ($type == 'input' && $objattr['subtype'] == 'IMAGE') {
  5722. $img_w = $w - $extraWidth ;
  5723. $img_h = $h - $extraHeight ;
  5724. $objattr['BORDER-WIDTH'] = $img_w + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ;
  5725. $objattr['BORDER-HEIGHT'] = $img_h + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ;
  5726. $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ;
  5727. $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ;
  5728. $objattr['INNER-WIDTH'] = $img_w;
  5729. $objattr['INNER-HEIGHT'] = $img_h;
  5730. $objattr['INNER-X'] = $x + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k);
  5731. $objattr['INNER-Y'] = $y + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ;
  5732. $objattr['ID'] = $info['i'];
  5733. }
  5734. /*-- BARCODES --*/
  5735. // mPDF 4.0
  5736. if ($type == 'barcode') {
  5737. $b_w = $w - $extraWidth ;
  5738. $b_h = $h - $extraHeight ;
  5739. $objattr['BORDER-WIDTH'] = $b_w + $objattr['padding_left']/$k + $objattr['padding_right']/$k + (($objattr['border_left']['w']/$k + $objattr['border_right']['w']/$k)/2) ;
  5740. $objattr['BORDER-HEIGHT'] = $b_h + $objattr['padding_top']/$k + $objattr['padding_bottom']/$k + (($objattr['border_top']['w']/$k + $objattr['border_bottom']['w']/$k)/2) ;
  5741. $objattr['BORDER-X'] = $x + $objattr['margin_left']/$k + (($objattr['border_left']['w']/$k)/2) ;
  5742. $objattr['BORDER-Y'] = $y + $objattr['margin_top']/$k + (($objattr['border_top']['w']/$k)/2) ;
  5743. $objattr['INNER-WIDTH'] = $img_w;
  5744. $objattr['INNER-HEIGHT'] = $img_h;
  5745. $objattr['INNER-X'] = $x + $objattr['padding_left']/$k + $objattr['margin_left']/$k + ($objattr['border_left']['w']/$k);
  5746. $objattr['INNER-Y'] = $y + $objattr['padding_top']/$k + $objattr['margin_top']/$k + ($objattr['border_top']['w']/$k) ;
  5747. }
  5748. /*-- END BARCODES --*/
  5749. if ($type == 'textarea') {
  5750. // Automatically resize to width remaining
  5751. if ($w > $widthLeft && !$is_table) {
  5752. $w = $widthLeft ;
  5753. }
  5754. if (($y + $h > $this->PageBreakTrigger) && !$this->InFooter) {
  5755. $h=$this->h - $y - $this->bMargin;
  5756. }
  5757. }
  5758. if ($type == 'hr') {
  5759. if ($is_table) {
  5760. $objattr['INNER-WIDTH'] = $maxWidth * $objattr['W-PERCENT']/100;
  5761. $objattr['width'] = $objattr['INNER-WIDTH'];
  5762. // mPDF 3.0
  5763. $w = $maxWidth;
  5764. }
  5765. else {
  5766. if ($w>$maxWidth) { $w = $maxWidth; }
  5767. $objattr['INNER-WIDTH'] = $w;
  5768. // mPDF 3.0
  5769. $w = $maxWidth;
  5770. }
  5771. }
  5772. if (($type == 'select') || ($type == 'input' && ($objattr['subtype'] == 'TEXT' || $objattr['subtype'] == 'PASSWORD'))) {
  5773. // Automatically resize to width remaining
  5774. if ($w > $widthLeft && !$is_table) {
  5775. $w = $widthLeft;
  5776. }
  5777. }
  5778. if ($type == 'textarea' || $type == 'select' || $type == 'input') {
  5779. if (isset($objattr['fontsize'])) $objattr['fontsize'] /= $k;
  5780. if (isset($objattr['linewidth'])) $objattr['linewidth'] /= $k;
  5781. }
  5782. // mPDF 3.0
  5783. if (!isset($objattr['BORDER-Y'])) { $objattr['BORDER-Y'] = 0; }
  5784. if (!isset($objattr['BORDER-X'])) { $objattr['BORDER-X'] = 0; }
  5785. if (!isset($objattr['INNER-Y'])) { $objattr['INNER-Y'] = 0; }
  5786. if (!isset($objattr['INNER-X'])) { $objattr['INNER-X'] = 0; }
  5787. //Return width-height array
  5788. $objattr['OUTER-WIDTH'] = $w;
  5789. $objattr['OUTER-HEIGHT'] = $h;
  5790. $objattr['OUTER-X'] = $x;
  5791. $objattr['OUTER-Y'] = $y;
  5792. return $objattr;
  5793. }
  5794. //=============================================================
  5795. //=============================================================
  5796. //=============================================================
  5797. //=============================================================
  5798. //=============================================================
  5799. function SetDash($black=false,$white=false)
  5800. {
  5801. if($black and $white) $s=sprintf('[%.3f %.3f] 0 d',$black*$this->k,$white*$this->k);
  5802. else $s='[] 0 d';
  5803. 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); }
  5804. $this->pageoutput[$this->page]['Dash'] = $s;
  5805. }
  5806. function SetDisplayPreferences($preferences) {
  5807. // String containing any or none of /HideMenubar/HideToolbar/HideWindowUI/DisplayDocTitle/CenterWindow/FitWindow
  5808. $this->DisplayPreferences .= $preferences;
  5809. }
  5810. function Ln($h='',$collapsible=0)
  5811. {
  5812. // Added collapsible to allow collapsible top-margin on new page
  5813. //Line feed; default value is last cell height
  5814. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  5815. if ($collapsible && ($this->y==$this->tMargin) && (!$this->ColActive)) { $h = 0; }
  5816. if(is_string($h)) $this->y+=$this->lasth;
  5817. else $this->y+=$h;
  5818. }
  5819. // mPDF 3.0 Also does border when Columns active
  5820. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  5821. function DivLn($h,$level=-3,$move_y=true,$collapsible=false,$state=0) {
  5822. // this->x is returned as it was
  5823. // adds lines (y) where DIV bgcolors are filled in
  5824. // mPDF 4.2 allows .00001 as nominal height used for bookmarks/annotations etc.
  5825. if ($collapsible && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->tMargin)) && (!$this->ColActive)) { return; }
  5826. if ($collapsible && (sprintf("%0.4f", $this->y)==sprintf("%0.4f", $this->y0)) && ($this->ColActive) && $this->CurrCol == 0) { return; } // *COLUMNS*
  5827. // mPDF 3.0
  5828. // Still use this method if columns or page-break-inside: avoid, as it allows repositioning later
  5829. // otherwise, now uses PaintDivBB()
  5830. if (!$this->ColActive && !$this->keep_block_together && !$this->kwt) { // mPDF 4.0 added kwt
  5831. if ($move_y && !$this->ColActive) { $this->y += $h; }
  5832. return;
  5833. }
  5834. if ($level == -3) { $level = $this->blklvl; }
  5835. $firstblockfill = $this->GetFirstBlockFill();
  5836. if ($firstblockfill && $this->blklvl > 0 && $this->blklvl >= $firstblockfill) {
  5837. $last_x = 0;
  5838. $last_w = 0;
  5839. $last_fc = $this->FillColor;
  5840. $bak_x = $this->x;
  5841. $bak_h = $this->divheight;
  5842. $this->divheight = 0; // Temporarily turn off divheight - as Cell() uses it to check for PageBreak
  5843. for ($blvl=$firstblockfill;$blvl<=$level;$blvl++) {
  5844. $this->SetBlockFill($blvl);
  5845. $this->x = $this->lMargin + $this->blk[$blvl]['outer_left_margin'];
  5846. if ($last_x != $this->lMargin + $this->blk[$blvl]['outer_left_margin'] || $last_w != $this->blk[$blvl]['width'] || $last_fc != $this->FillColor) {
  5847. $x = $this->x; // mPDF 3.0
  5848. $this->Cell( ($this->blk[$blvl]['width']), $h, '', '', 0, '', 1);
  5849. // mPDF 3.0 Also does border when Columns active
  5850. if (!$this->keep_block_together && !$this->writingHTMLheader && !$this->writingHTMLfooter) {
  5851. $this->x = $x;
  5852. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  5853. if ($blvl == $this->blklvl) { $this->PaintDivLnBorder($state,$blvl,$h); }
  5854. else { $this->PaintDivLnBorder(0,$blvl,$h); }
  5855. }
  5856. }
  5857. $last_x = $this->lMargin + $this->blk[$blvl]['outer_left_margin'];
  5858. $last_w = $this->blk[$blvl]['width'];
  5859. $last_fc = $this->FillColor;
  5860. }
  5861. // Reset current block fill
  5862. if (isset($this->blk[$this->blklvl]['bgcolorarray'])) {
  5863. $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  5864. $this->SetFillColor($bcor['R'],$bcor['G'],$bcor['B']);
  5865. }
  5866. $this->x = $bak_x;
  5867. $this->divheight = $bak_h;
  5868. }
  5869. if ($move_y) { $this->y += $h; }
  5870. }
  5871. function GetX()
  5872. {
  5873. //Get x position
  5874. return $this->x;
  5875. }
  5876. function SetX($x)
  5877. {
  5878. //Set x position
  5879. if($x >= 0) $this->x=$x;
  5880. else $this->x = $this->w + $x;
  5881. }
  5882. function GetY()
  5883. {
  5884. //Get y position
  5885. return $this->y;
  5886. }
  5887. function SetY($y)
  5888. {
  5889. //Set y position and reset x
  5890. $this->x=$this->lMargin;
  5891. if($y>=0)
  5892. $this->y=$y;
  5893. else
  5894. $this->y=$this->h+$y;
  5895. }
  5896. function SetXY($x,$y)
  5897. {
  5898. //Set x and y positions
  5899. $this->SetY($y);
  5900. $this->SetX($x);
  5901. }
  5902. function Output($name='',$dest='')
  5903. {
  5904. //Output PDF to some destination
  5905. global $_SERVER;
  5906. // mPDF 4.0
  5907. if ($this->showStats) {
  5908. echo '<div>Generated in '.sprintf('%.2f',(microtime(true) - $this->time0)).' seconds</div>';
  5909. }
  5910. //Finish document if necessary
  5911. if ($this->progressBar) { $this->UpdateProgressBar(1,'100','Finished'); } // *PROGRESS-BAR*
  5912. if($this->state < 3) $this->Close();
  5913. if ($this->progressBar) { $this->UpdateProgressBar(2,'100','Finished'); } // *PROGRESS-BAR*
  5914. // fn. error_get_last is only in PHP>=5.2
  5915. if ($this->debug && function_exists('error_get_last') && error_get_last()) {
  5916. $e = error_get_last();
  5917. if (($e['type'] < 2048 && $e['type'] != 8) || (intval($e['type']) & intval(ini_get("error_reporting")))) {
  5918. echo "<p>Error message detected - PDF file generation aborted.</p>";
  5919. echo $e['message'].'<br />';
  5920. echo 'File: '.$e['file'].'<br />';
  5921. echo 'Line: '.$e['line'].'<br />';
  5922. exit;
  5923. }
  5924. }
  5925. // mPDF 4.2.018
  5926. if ($this->PDFA && $this->encrypted) { $this->Error("PDFA1-b does not permit encryption of documents."); }
  5927. if (count($this->PDFAwarnings) && $this->PDFA && !$this->PDFAauto) {
  5928. echo '<div>WARNING - This file could not be generated as it stands as a PDFA1-b compliant file.</div>';
  5929. echo '<div>These issues can be automatically fixed by mPDF using <i>$mpdf-&gt;PDFAauto=true;</i></div>';
  5930. echo '<div>Action that mPDF will take to automatically force PDFA1-b compliance are shown in brackets.</div>';
  5931. echo '<div>Warning(s) generated:</div><ul>';
  5932. foreach($this->PDFAwarnings AS $w) {
  5933. echo '<li>'.$w.'</li>';
  5934. }
  5935. echo '</ul>';
  5936. exit;
  5937. }
  5938. // mPDF 4.0
  5939. if ($this->showStats) {
  5940. echo '<div>Compiled in '.sprintf('%.2f',(microtime(true) - $this->time0)).' seconds (total)</div>';
  5941. echo '<div>Peak Memory usage '.number_format((memory_get_peak_usage(true)/(1024*1024)),2).' MB</div>';
  5942. echo '<div>PDF file size '.number_format((strlen($this->buffer)/1024)).' kB</div>';
  5943. echo '<div>Number of fonts '.count($this->fonts).'</div>';
  5944. exit;
  5945. }
  5946. if(is_bool($dest)) $dest=$dest ? 'D' : 'F';
  5947. $dest=strtoupper($dest);
  5948. if($dest=='') {
  5949. if($name=='') {
  5950. $name='mpdf.pdf';
  5951. $dest='I';
  5952. }
  5953. else { $dest='F'; }
  5954. }
  5955. /*-- PROGRESS-BAR --*/
  5956. // mPDF 4.2 Progress bar
  5957. if ($this->progressBar && ($dest=='D' || $dest=='I')) {
  5958. if($name=='') { $name='mpdf.pdf'; }
  5959. $tempfile = '_tempPDF'.RAND(1,10000);
  5960. //Save to local file
  5961. $f=fopen(_MPDF_TEMP_PATH.$tempfile.'.pdf','wb'); // mPDF 4.3.007E
  5962. if(!$f) $this->Error('Unable to create temporary output file: '.$tempfile.'.pdf');
  5963. fwrite($f,$this->buffer,strlen($this->buffer));
  5964. fclose($f);
  5965. $this->UpdateProgressBar(3,'','Finished');
  5966. echo '<script type="text/javascript">
  5967. location.href="'._MPDF_URI.'progress/out.php?filename='.$tempfile.'&dest='.$dest.'&opname='.$name.'";
  5968. </script>
  5969. </div>
  5970. </body>
  5971. </html>';
  5972. exit;
  5973. }
  5974. else {
  5975. if ($this->progressBar) { $this->UpdateProgressBar(3,'','Finished'); }
  5976. /*-- END PROGRESS-BAR --*/
  5977. switch($dest) {
  5978. case 'I':
  5979. // mPDF 3.0 // Edited mPDF 3.1
  5980. 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; }
  5981. //Send to standard output
  5982. if(isset($_SERVER['SERVER_NAME']))
  5983. {
  5984. //We send to a browser
  5985. header('Content-Type: application/pdf');
  5986. if(headers_sent())
  5987. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  5988. header('Content-Length: '.strlen($this->buffer));
  5989. header('Content-disposition: inline; filename="'.$name.'"'); // mPDF 4.3.007B
  5990. // mPDF 4.2
  5991. header('Pragma: no-cache');
  5992. // mPDF 4.3.012B IE6 : this header avoid IE6 to open directly the pdf file
  5993. //header('Cache-Control: no-cache, must-revalidate');
  5994. header('Cache-Control: maxage=0');
  5995. }
  5996. echo $this->buffer;
  5997. break;
  5998. case 'D':
  5999. //Download file
  6000. // mPDF 4.0
  6001. if(isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) {
  6002. if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') {
  6003. header('HTTP/1.1 200 OK');
  6004. header('Status: 200 OK');
  6005. header('Pragma: anytextexeptno-cache', true);
  6006. header("Cache-Control: public, must-revalidate");
  6007. }
  6008. else {
  6009. header('Pragma: no-cache');
  6010. // mPDF 4.3.012B IE6 : this header avoid IE6 to open directly the pdf file
  6011. //header('Cache-Control: no-cache, must-revalidate');
  6012. header('Cache-Control: maxage=0');
  6013. }
  6014. header('Content-Type: application/force-download');
  6015. }
  6016. else {
  6017. header('Content-Type: application/octet-stream');
  6018. }
  6019. if(headers_sent())
  6020. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  6021. header('Content-Length: '.strlen($this->buffer));
  6022. header('Content-disposition: attachment; filename="'.$name.'"'); // mPDF 4.3.007B
  6023. echo $this->buffer;
  6024. break;
  6025. case 'F':
  6026. //Save to local file
  6027. $f=fopen($name,'wb');
  6028. if(!$f) $this->Error('Unable to create output file: '.$name);
  6029. fwrite($f,$this->buffer,strlen($this->buffer));
  6030. fclose($f);
  6031. break;
  6032. case 'S':
  6033. //Return as a string
  6034. return $this->buffer;
  6035. default:
  6036. $this->Error('Incorrect output destination: '.$dest);
  6037. }
  6038. /*-- PROGRESS-BAR --*/
  6039. }
  6040. /*-- END PROGRESS-BAR --*/
  6041. return '';
  6042. }
  6043. // *****************************************************************************
  6044. // *
  6045. // Protected methods *
  6046. // *
  6047. // *****************************************************************************
  6048. function _dochecks()
  6049. {
  6050. //Check for locale-related bug
  6051. if(1.1==1)
  6052. $this->Error('Don\'t alter the locale before including class file');
  6053. //Check for decimal separator
  6054. if(sprintf('%.1f',1.0)!='1.0')
  6055. setlocale(LC_NUMERIC,'C');
  6056. }
  6057. function _begindoc()
  6058. {
  6059. //Start document
  6060. $this->state=1;
  6061. $this->_out('%PDF-'.$this->pdf_version);
  6062. $this->_out('%'.chr(226).chr(227).chr(207).chr(211)); // mPDF 4.2.018 4 chars > 128 to show binary file
  6063. }
  6064. /*-- HTMLHEADERS-FOOTERS --*/
  6065. // mPDF 4.0 Write out all HTML Headers and Footers
  6066. function _puthtmlheaders() {
  6067. $this->state=2;
  6068. $nb=$this->page;
  6069. for($n=1;$n<=$nb;$n++) {
  6070. if ($this->mirrorMargins && $n%2==0) { $OE = 'E'; } // EVEN
  6071. else { $OE = 'O'; }
  6072. $this->page = $n;
  6073. if (isset($this->saveHTMLHeader[$n][$OE])) {
  6074. $html = $this->saveHTMLHeader[$n][$OE]['html'];
  6075. $this->lMargin = $this->saveHTMLHeader[$n][$OE]['ml'];
  6076. $this->rMargin = $this->saveHTMLHeader[$n][$OE]['mr'];
  6077. $this->tMargin = $this->saveHTMLHeader[$n][$OE]['mh'];
  6078. $this->bMargin = $this->saveHTMLHeader[$n][$OE]['mf'];
  6079. $this->margin_header = $this->saveHTMLHeader[$n][$OE]['mh'];
  6080. $this->margin_footer = $this->saveHTMLHeader[$n][$OE]['mf'];
  6081. $this->w = $this->saveHTMLHeader[$n][$OE]['pw'];
  6082. $this->h = $this->saveHTMLHeader[$n][$OE]['ph'];
  6083. $rotate = $this->saveHTMLHeader[$n][$OE]['rotate'];
  6084. $this->Reset();
  6085. $this->pageoutput[$n] = array();
  6086. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  6087. $this->x = $this->lMargin;
  6088. $this->y = $this->margin_header;
  6089. $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($n).$this->pagenumSuffix,$html);
  6090. $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($n).$this->nbpgSuffix,$html ); // {nbpg}
  6091. $html = str_replace($this->aliasNbPg,$nb,$html ); // {nb}
  6092. $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
  6093. $this->HTMLheaderPageLinks = array();
  6094. $this->pageBackgrounds = array();
  6095. $this->writingHTMLheader = true;
  6096. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  6097. $this->writingHTMLheader = false;
  6098. $this->Reset();
  6099. $this->pageoutput[$n] = array();
  6100. $s = $this->PrintPageBackgrounds();
  6101. $this->headerbuffer = $s . $this->headerbuffer;
  6102. $os = '';
  6103. if ($rotate) {
  6104. $os .= sprintf('q 0 -1 1 0 0 %.3f cm ',($this->w*$this->k));
  6105. }
  6106. $os .= $this->headerbuffer ;
  6107. if ($rotate) {
  6108. $os .= ' Q' . "\n";
  6109. }
  6110. // Writes over the page background but behind any other output on page
  6111. $os = preg_replace('/\\\\/','\\\\\\\\',$os); // mPDF 4.3.012C
  6112. $this->pages[$n] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$os."\n".'\\1', $this->pages[$n]);
  6113. // mPDF 4.0
  6114. $lks = $this->HTMLheaderPageLinks;
  6115. foreach($lks AS $lk) {
  6116. if ($rotate) {
  6117. $lw = $lk[2];
  6118. $lh = $lk[3];
  6119. $lk[2] = $lh;
  6120. $lk[3] = $lw; // swap width and height
  6121. $ax = $lk[0]/$this->k;
  6122. $ay = $lk[1]/$this->k;
  6123. $bx = $ay-($lh/$this->k);
  6124. $by = $this->w-$ax;
  6125. $lk[0] = $bx*$this->k;
  6126. $lk[1] = ($this->h-$by)*$this->k - $lw;
  6127. }
  6128. $this->PageLinks[$n][]=$lk;
  6129. }
  6130. }
  6131. if (isset($this->saveHTMLFooter[$n][$OE])) {
  6132. $html = $this->saveHTMLFooter[$this->page][$OE]['html'];
  6133. $this->lMargin = $this->saveHTMLFooter[$n][$OE]['ml'];
  6134. $this->rMargin = $this->saveHTMLFooter[$n][$OE]['mr'];
  6135. $this->tMargin = $this->saveHTMLFooter[$n][$OE]['mh'];
  6136. $this->bMargin = $this->saveHTMLFooter[$n][$OE]['mf'];
  6137. $this->margin_header = $this->saveHTMLFooter[$n][$OE]['mh'];
  6138. $this->margin_footer = $this->saveHTMLFooter[$n][$OE]['mf'];
  6139. $this->w = $this->saveHTMLFooter[$n][$OE]['pw'];
  6140. $this->h = $this->saveHTMLFooter[$n][$OE]['ph'];
  6141. $rotate = $this->saveHTMLFooter[$n][$OE]['rotate'];
  6142. $this->Reset();
  6143. $this->pageoutput[$n] = array();
  6144. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  6145. $this->x = $this->lMargin;
  6146. $top_y = $this->y = $this->h - $this->margin_footer;
  6147. // if bottom-margin==0, corrects to avoid division by zero
  6148. if ($this->y == $this->h) { $top_y = $this->y = ($this->h - 0.1); }
  6149. $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($n).$this->pagenumSuffix,$html);
  6150. $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($n).$this->nbpgSuffix,$html ); // {nbpg}
  6151. $html = str_replace($this->aliasNbPg,$nb,$html ); // {nb}
  6152. $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
  6153. $this->HTMLheaderPageLinks = array();
  6154. $this->pageBackgrounds = array();
  6155. $this->writingHTMLfooter = true;
  6156. $this->InFooter = true;
  6157. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  6158. $this->writingHTMLfooter = false;
  6159. $this->InFooter = false;
  6160. $this->Reset();
  6161. $this->pageoutput[$n] = array();
  6162. $fheight = $this->y - $top_y;
  6163. $adj = -$fheight;
  6164. $s = $this->PrintPageBackgrounds(-$adj); // mPDF 4.2.014
  6165. $this->headerbuffer = $s . $this->headerbuffer;
  6166. $os = '';
  6167. $os .= $this->StartTransform(true)."\n";
  6168. if ($rotate) {
  6169. $os .= sprintf('q 0 -1 1 0 0 %.3f cm ',($this->w*$this->k));
  6170. }
  6171. $os .= $this->transformTranslate(0, $adj, true)."\n";
  6172. $os .= $this->headerbuffer ;
  6173. if ($rotate) {
  6174. $os .= ' Q' . "\n";
  6175. }
  6176. $os .= $this->StopTransform(true)."\n";
  6177. // Writes over the page background but behind any other output on page
  6178. $os = preg_replace('/\\\\/','\\\\\\\\',$os); // mPDF 4.3.012C
  6179. $this->pages[$n] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$os."\n".'\\1', $this->pages[$n]);
  6180. // mPDF 4.0
  6181. $lks = $this->HTMLheaderPageLinks;
  6182. foreach($lks AS $lk) {
  6183. $lk[1] -= $adj*$this->k;
  6184. if ($rotate) {
  6185. $lw = $lk[2];
  6186. $lh = $lk[3];
  6187. $lk[2] = $lh;
  6188. $lk[3] = $lw; // swap width and height
  6189. $ax = $lk[0]/$this->k;
  6190. $ay = $lk[1]/$this->k;
  6191. $bx = $ay-($lh/$this->k);
  6192. $by = $this->w-$ax;
  6193. $lk[0] = $bx*$this->k;
  6194. $lk[1] = ($this->h-$by)*$this->k - $lw;
  6195. }
  6196. $this->PageLinks[$n][]=$lk;
  6197. }
  6198. }
  6199. }
  6200. $this->page=$nb;
  6201. $this->state=1;
  6202. }
  6203. /*-- END HTMLHEADERS-FOOTERS --*/
  6204. function _putpages()
  6205. {
  6206. $nb=$this->page;
  6207. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  6208. // mPDF 4.2.024 Changed to 'def'
  6209. if($this->DefOrientation=='P') {
  6210. $defwPt=$this->fwPt;
  6211. $defhPt=$this->fhPt;
  6212. }
  6213. else {
  6214. $defwPt=$this->fhPt;
  6215. $defhPt=$this->fwPt;
  6216. }
  6217. $annotid=(3+2*$nb);
  6218. for($n=1;$n<=$nb;$n++)
  6219. {
  6220. // mPDF 4.2.024
  6221. if(isset($this->OrientationChanges[$n])) {
  6222. $hPt=$this->pageDim[$n]['w']*$this->k;
  6223. $wPt=$this->pageDim[$n]['h']*$this->k;
  6224. }
  6225. else {
  6226. $wPt=$this->pageDim[$n]['w']*$this->k;
  6227. $hPt=$this->pageDim[$n]['h']*$this->k;
  6228. }
  6229. // mPDF 4.0 Moved
  6230. //Replace number of pages
  6231. if(!empty($this->aliasNbPg)) {
  6232. // mPDF 4.0
  6233. if ($this->is_MB && !$this->useSubsets) { $s1 = $this->UTF8ToUTF16BE($this->aliasNbPg, false); }
  6234. else { $s1 = $this->aliasNbPg; }
  6235. if ($this->useSubsets) {
  6236. $r = '';
  6237. $nstr = "$nb";
  6238. for($i=0;$i<strlen($nstr);$i++) {
  6239. $r .= sprintf("%02s", strtoupper(dechex(intval($nstr[$i])+33)));
  6240. }
  6241. }
  6242. else if ($this->is_MB) { $r = $this->UTF8ToUTF16BE($nb, false); } // *UNICODE-FONTS*
  6243. else { $r = $nb; }
  6244. if (preg_match_all('/{mpdfheadernbpg (C|R) ff=(\S*) fs=(\S*) fz=(.*?)}/',$this->pages[$n],$m)) {
  6245. for($hi=0;$hi<count($m[0]);$hi++) {
  6246. $pos = $m[1][$hi];
  6247. $hff = $m[2][$hi];
  6248. $hfst = $m[3][$hi];
  6249. $hfsz = $m[4][$hi];
  6250. $this->SetFont($hff,$hfst,$hfsz, false);
  6251. $x1 = $this->GetStringWidth($this->aliasNbPg);
  6252. $x2 = $this->GetStringWidth($nb);
  6253. $xadj = $x1 - $x2;
  6254. if ($pos=='C') { $xadj /= 2; }
  6255. $rep = sprintf(' q 1 0 0 1 %.3f 0 cm ', $xadj*$this->k);
  6256. $this->pages[$n] = str_replace($m[0][$hi], $rep, $this->pages[$n]);
  6257. }
  6258. }
  6259. $this->pages[$n]=str_replace($s1,$r,$this->pages[$n]);
  6260. }
  6261. //Replace number of pages in group
  6262. if(!empty($this->aliasNbPgGp)) {
  6263. // mPDF 4.0
  6264. if ($this->is_MB && !$this->useSubsets) { $s2 = $this->UTF8ToUTF16BE($this->aliasNbPgGp, false); }
  6265. else { $s2 = $this->aliasNbPgGp; }
  6266. $nbt = $this->docPageNumTotal($n);
  6267. if ($this->useSubsets) {
  6268. $r = '';
  6269. $nstr = "$nbt";
  6270. for($i=0;$i<strlen($nstr);$i++) {
  6271. $r .= sprintf("%02s", strtoupper(dechex(intval($nstr[$i])+33)));
  6272. }
  6273. }
  6274. else if ($this->is_MB) { $r = $this->UTF8ToUTF16BE($nbt, false); } // *UNICODE-FONTS*
  6275. else { $r = $nbt; }
  6276. if (preg_match_all('/{mpdfheadernbpggp (C|R) ff=(\S*) fs=(\S*) fz=(.*?)}/',$this->pages[$n],$m)) {
  6277. for($hi=0;$hi<count($m[0]);$hi++) {
  6278. $pos = $m[1][$hi];
  6279. $hff = $m[2][$hi];
  6280. $hfst = $m[3][$hi];
  6281. $hfsz = $m[4][$hi];
  6282. $this->SetFont($hff,$hfst,$hfsz, false);
  6283. $x1 = $this->GetStringWidth($this->aliasNbPgGp);
  6284. // mPDF 3.0
  6285. $x2 = $this->GetStringWidth($nbt);
  6286. $xadj = $x1 - $x2;
  6287. if ($pos=='C') { $xadj /= 2; }
  6288. $rep = sprintf(' q 1 0 0 1 %.3f 0 cm ', $xadj*$this->k);
  6289. $this->pages[$n] = str_replace($m[0][$hi], $rep, $this->pages[$n]);
  6290. }
  6291. }
  6292. $this->pages[$n]=str_replace($s2,$r,$this->pages[$n]);
  6293. }
  6294. // mPDF 3.0 Remove Pattern marker
  6295. $this->pages[$n] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n", $this->pages[$n]);
  6296. //Page
  6297. $this->_newobj();
  6298. $this->_out('<</Type /Page');
  6299. $this->_out('/Parent 1 0 R');
  6300. if(isset($this->OrientationChanges[$n])) {
  6301. $this->_out(sprintf('/MediaBox [0 0 %.3f %.3f]',$hPt,$wPt));
  6302. if (isset($this->OrientationChanges[$n]) && $this->displayDefaultOrientation) {
  6303. if ($this->DefOrientation=='P') { $this->_out('/Rotate 270'); }
  6304. else { $this->_out('/Rotate 90'); }
  6305. }
  6306. }
  6307. // mPDF 4.2.024
  6308. else if($wPt != $defwPt || $hPt != $defhPt) {
  6309. $this->_out(sprintf('/MediaBox [0 0 %.3f %.3f]',$wPt,$hPt));
  6310. }
  6311. $this->_out('/Resources 2 0 R');
  6312. $annotsnum = 0;
  6313. if (isset($this->PageLinks[$n])) { $annotsnum += count($this->PageLinks[$n]); }
  6314. /*-- ANNOTATIONS --*/
  6315. // mPDF 4.2.027
  6316. if (isset($this->PageAnnots[$n])) {
  6317. foreach ($this->PageAnnots[$n] as $pl) {
  6318. if (!empty($pl['opt']['popup'])) { $annotsnum += 2 ; }
  6319. else { $annotsnum++; }
  6320. }
  6321. }
  6322. /*-- END ANNOTATIONS --*/
  6323. if ($annotsnum ) {
  6324. $s = '/Annots [ ';
  6325. for($i=0;$i<$annotsnum;$i++) {
  6326. $s .= ($annotid + $i) . ' 0 R ';
  6327. }
  6328. $annotid += $annotsnum;
  6329. $s .= '] ';
  6330. $this->_out($s);
  6331. }
  6332. $this->_out('/Contents '.($this->n+1).' 0 R>>');
  6333. $this->_out('endobj');
  6334. //Page content
  6335. $this->_newobj();
  6336. $p=($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n];
  6337. $this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
  6338. $this->_putstream($p);
  6339. $this->_out('endobj');
  6340. }
  6341. $this->_putannots($n);
  6342. //Pages root
  6343. $this->offsets[1]=strlen($this->buffer);
  6344. $this->_out('1 0 obj');
  6345. $this->_out('<</Type /Pages');
  6346. $kids='/Kids [';
  6347. for($i=0;$i<$nb;$i++)
  6348. $kids.=(3+2*$i).' 0 R ';
  6349. $this->_out($kids.']');
  6350. $this->_out('/Count '.$nb);
  6351. $this->_out(sprintf('/MediaBox [0 0 %.3f %.3f]',$defwPt,$defhPt)); // mPDF 4.2.024
  6352. $this->_out('>>');
  6353. $this->_out('endobj');
  6354. }
  6355. function _putannots($n) {
  6356. $nb=$this->page;
  6357. for($n=1;$n<=$nb;$n++)
  6358. {
  6359. $annotobjs = array();
  6360. if(isset($this->PageLinks[$n]) || isset($this->PageAnnots[$n])) {
  6361. $wPt=$this->pageDim[$n]['w']*$this->k;
  6362. $hPt=$this->pageDim[$n]['h']*$this->k;
  6363. //Links
  6364. if(isset($this->PageLinks[$n])) {
  6365. foreach($this->PageLinks[$n] as $key => $pl) {
  6366. $this->_newobj();
  6367. $annot='';
  6368. $rect=sprintf('%.3f %.3f %.3f %.3f',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
  6369. $annot .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.']';
  6370. $annot .= ' /Contents '.$this->_UTF16BEtextstring($pl[4]);
  6371. $annot .= ' /NM ('.sprintf('%04u-%04u', $n, $key).')';
  6372. $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis'));
  6373. $annot .= ' /Border [0 0 0]';
  6374. // mPDF 4.2.018
  6375. if ($this->PDFA) { $annot .= ' /F 28'; }
  6376. if (strpos($pl[4],'@')===0) {
  6377. $p=substr($pl[4],1);
  6378. // $h=isset($this->OrientationChanges[$p]) ? $wPt : $hPt;
  6379. $htarg=$this->pageDim[$p]['h']*$this->k;
  6380. $annot.=sprintf(' /Dest [%d 0 R /XYZ 0 %.3f null]>>',1+2*$p,$htarg);
  6381. }
  6382. else if(is_string($pl[4])) {
  6383. $annot .= ' /A <</S /URI /URI '.$this->_textstring($pl[4]).'>> >>';
  6384. }
  6385. else {
  6386. $l=$this->links[$pl[4]];
  6387. // mPDF 3.0
  6388. // may not be set if #link points to non-existent target
  6389. if (isset($this->pageDim[$l[0]]['h'])) { $htarg=$this->pageDim[$l[0]]['h']*$this->k; }
  6390. else { $htarg=$this->h*$this->k; } // doesn't really matter
  6391. $annot.=sprintf(' /Dest [%d 0 R /XYZ 0 %.3f null]>>',1+2*$l[0],$htarg-$l[1]*$this->k);
  6392. }
  6393. $this->_out($annot);
  6394. $this->_out('endobj');
  6395. }
  6396. }
  6397. /*-- ANNOTATIONS --*/
  6398. if(isset($this->PageAnnots[$n])) {
  6399. foreach ($this->PageAnnots[$n] as $key => $pl) {
  6400. $this->_newobj();
  6401. $annot='';
  6402. $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER);
  6403. $x = $pl['x'];
  6404. if ($this->annotMargin <> 0 || $x==0 || $x<0) { // Odd page
  6405. $x = ($wPt/$this->k) - $this->annotMargin;
  6406. }
  6407. $w = $h = ($this->annotSize * $this->k);
  6408. $a = $x * $this->k;
  6409. // mPDF 3.0
  6410. $b = $hPt - ($pl['y'] * $this->k);
  6411. $rect = sprintf('%.3f %.3f %.3f %.3f', $a, $b-$h, $a+$w, $b);
  6412. $annot .= '<</Type /Annot /Subtype /Text /Rect ['.$rect.']';
  6413. $annot .= ' /Contents '.$this->_UTF16BEtextstring($pl['txt']);
  6414. $annot .= ' /NM ('.sprintf('%04u-%04u', $n, (2000 + $key)).')';
  6415. $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis'));
  6416. $annot .= ' /CreationDate '.$this->_textstring('D:'.date('YmdHis'));
  6417. $annot .= ' /Border [0 0 0]';
  6418. // mPDF 4.2.018
  6419. if ($this->PDFA) {
  6420. $annot .= ' /F 28';
  6421. $annot .= ' /CA 1';
  6422. }
  6423. else if ($pl['opt']['ca']>0) { $annot .= ' /CA '.$pl['opt']['ca']; }
  6424. $annot .= ' /C [';
  6425. if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c']))) {
  6426. foreach ($pl['opt']['c'] as $col) {
  6427. $col = intval($col);
  6428. $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
  6429. $annot .= sprintf(" %.4f", $color);
  6430. }
  6431. }
  6432. else { $annot .= '1 1 0'; } // mPDF 4.2.026
  6433. $annot .= ']';
  6434. // Usually Author
  6435. if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
  6436. $annot .= ' /T '.$this->_UTF16BEtextstring($pl['opt']['t']);
  6437. }
  6438. if (isset($pl['opt']['subj'])) {
  6439. $annot .= ' /Subj '.$this->_UTF16BEtextstring($pl['opt']['subj']);
  6440. }
  6441. $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
  6442. if (isset($pl['opt']['icon']) AND in_array($pl['opt']['icon'], $iconsapp)) {
  6443. $annot .= ' /Name /'.$pl['opt']['icon'];
  6444. }
  6445. else { $annot .= ' /Name /Note'; }
  6446. // mPDF 4.2.027
  6447. if (!empty($pl['opt']['popup'])) {
  6448. $annot .= ' /Open true';
  6449. $annot .= ' /Popup '.($this->n+1).' 0 R'; // mPDF 4.2.027
  6450. }
  6451. else { $annot .= ' /Open false'; } // mPDF 4.2.027
  6452. $annot .= ' /P 3 0 R'; // mPDF 4.2.027
  6453. $annot .= '>>';
  6454. $this->_out($annot);
  6455. $this->_out('endobj');
  6456. // mPDF 4.2.027
  6457. if (!empty($pl['opt']['popup'])) {
  6458. $this->_newobj();
  6459. $annot='';
  6460. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][0])) { $x = $pl['opt']['popup'][0] * $this->k; }
  6461. else { $x = $pl['x'] * $this->k; }
  6462. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][1])) { $y = $hPt - ($pl['opt']['popup'][1] * $this->k); }
  6463. else { $y = $hPt - ($pl['y'] * $this->k); }
  6464. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][2])) { $w = $pl['opt']['popup'][2] * $this->k; }
  6465. else { $w = 180; }
  6466. if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][3])) { $h = $pl['opt']['popup'][3] * $this->k; }
  6467. else { $h = 120; }
  6468. $rect = sprintf('%.3f %.3f %.3f %.3f', $x, $y-$h, $x+$w, $y);
  6469. $annot .= '<</Type /Annot /Subtype /Popup /Rect ['.$rect.']';
  6470. $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis'));
  6471. if ($this->PDFA) { $annot .= ' /F 28'; }
  6472. $annot .= ' /P 3 0 R';
  6473. $annot .= ' /Parent '.($this->n-1).' 0 R';
  6474. $annot .= '>>';
  6475. $this->_out($annot);
  6476. $this->_out('endobj');
  6477. }
  6478. }
  6479. }
  6480. /*-- END ANNOTATIONS --*/
  6481. }
  6482. }
  6483. }
  6484. /*-- ANNOTATIONS --*/
  6485. function Annotation($text, $x=0, $y=0, $icon='Note', $author='', $subject='', $opacity=0, $colarray=array(255,255,0), $popup='') { // mPDF 4.2.027
  6486. if ($x==0) { $x = $this->x; }
  6487. if ($y==0) { $y = $this->y; }
  6488. $page = $this->page;
  6489. if ($page < 1) { // Document has not been started - assume it's for first page
  6490. $page = 1;
  6491. if ($x==0) { $x = $this->lMargin; }
  6492. if ($y==0) { $y = $this->tMargin; }
  6493. }
  6494. // mPDF 4.2.018
  6495. if ($this->PDFA) {
  6496. if (!$this->PDFAauto) { $this->PDFAwarnings[] = "Annotation markers cannot be semi-transparent in PDFA1-b, so they may make underlying text unreadable. (Annotation markers moved to right margin)"; }
  6497. $x = ($this->w) - $this->rMargin*0.66;
  6498. }
  6499. if (!$this->annotMargin) { $y -= $this->FontSize / 2; }
  6500. if (!$opacity && $this->annotMargin) { $opacity = 1; }
  6501. else if (!$opacity) { $opacity = $this->annotOpacity; }
  6502. if ($this->keep_block_together) { // Save to array - don't write yet
  6503. $this->ktAnnots[$this->page][]=array('txt' => $text, 'x' => $x, 'y' => $y, 'opt' => array('Icon'=>$icon, 'T'=>$author, 'Subj'=>$subject, 'C'=>$colarray, 'CA'=>$opacity, 'popup'=>$popup)); // mPDF 4.2.027
  6504. return;
  6505. }
  6506. else if ($this->table_rotate) {
  6507. $this->tbrot_Annots[$this->page][]=array('txt' => $text, 'x' => $x, 'y' => $y, 'opt' => array('Icon'=>$icon, 'T'=>$author, 'Subj'=>$subject, 'C'=>$colarray, 'CA'=>$opacity, 'popup'=>$popup)); // mPDF 4.2.027
  6508. return;
  6509. }
  6510. else if ($this->kwt) {
  6511. $this->kwt_Annots[$this->page][]=array('txt' => $text, 'x' => $x, 'y' => $y, 'opt' => array('Icon'=>$icon, 'T'=>$author, 'Subj'=>$subject, 'C'=>$colarray, 'CA'=>$opacity, 'popup'=>$popup)); // mPDF 4.2.027
  6512. return;
  6513. }
  6514. //Put an Annotation on the page
  6515. $this->PageAnnots[$page][] = array('txt' => $text, 'x' => $x, 'y' => $y, 'opt' => array('Icon'=>$icon, 'T'=>$author, 'Subj'=>$subject, 'C'=>$colarray, 'CA'=>$opacity, 'popup'=>$popup)); // mPDF 4.2.027
  6516. /*-- COLUMNS --*/
  6517. // Save cross-reference to Column buffer
  6518. $ref = count($this->PageAnnots[$this->page])-1;
  6519. $this->columnAnnots[$this->CurrCol][INTVAL($this->x)][INTVAL($this->y)] = $ref;
  6520. /*-- END COLUMNS --*/
  6521. }
  6522. /*-- END ANNOTATIONS --*/
  6523. function _putfonts() {
  6524. /*-- UNICODE-FONTS --*/
  6525. if ($this->is_MB) {
  6526. $nf=$this->n;
  6527. /* mPDF 4.2 Not required in MB document/fonts
  6528. foreach($this->diffs as $diff) {
  6529. //Encodings
  6530. $this->_newobj();
  6531. $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');
  6532. $this->_out('endobj');
  6533. }
  6534. */
  6535. // mPDF 4.1
  6536. $mqr=ini_get("magic_quotes_runtime");
  6537. if ($mqr) { set_magic_quotes_runtime(0); }
  6538. foreach($this->FontFiles as $file=>$info) {
  6539. // mPDF 4.0
  6540. if (!isset($info['type']) || $info['type']!='Type1subset') {
  6541. // mPDF 4.0
  6542. $used = true;
  6543. foreach($this->fonts AS $f) {
  6544. if ($f['file'] == $file && $f['type']=='TrueTypeUnicode') { $used = $f['used']; }
  6545. }
  6546. if ($used) {
  6547. //Font file embedding
  6548. $this->_newobj();
  6549. $this->FontFiles[$file]['n']=$this->n;
  6550. $font='';
  6551. $f=fopen(MPDF_FONTPATH.$file,'rb',1);
  6552. if(!$f) {
  6553. $this->Error('Font file not found');
  6554. }
  6555. while(!feof($f)) {
  6556. $font .= fread($f, 2048);
  6557. }
  6558. fclose($f);
  6559. $compressed=(substr($file,-2)=='.z');
  6560. if(!$compressed && isset($info['length2'])) {
  6561. $header=($this->ords[substr($font,0,1)]==128);
  6562. if($header) {
  6563. //Strip first binary header
  6564. $font=substr($font,6);
  6565. }
  6566. if($header && $this->ords[substr($font,$info['length1'],1)]==128) {
  6567. //Strip second binary header
  6568. $font=substr($font,0,$info['length1']).substr($font,$info['length1']+6);
  6569. }
  6570. }
  6571. $this->_out('<</Length '.strlen($font));
  6572. if($compressed) {
  6573. $this->_out('/Filter /FlateDecode');
  6574. }
  6575. $this->_out('/Length1 '.$info['length1']);
  6576. if(isset($info['length2'])) {
  6577. $this->_out('/Length2 '.$info['length2'].' /Length3 0');
  6578. }
  6579. $this->_out('>>');
  6580. $this->_putstream($font);
  6581. $this->_out('endobj');
  6582. }
  6583. }
  6584. }
  6585. // mPDF 4.1
  6586. if ($mqr) { set_magic_quotes_runtime($mqr); }
  6587. foreach($this->fonts as $k=>$font) {
  6588. //Font objects
  6589. $type=$font['type'];
  6590. $name=$font['name'];
  6591. if($type=='Type0') {
  6592. $this->fonts[$k]['n']=$this->n+1;
  6593. $this->_newobj();
  6594. $this->_out('<</Type /Font');
  6595. $this->_putType0($font);
  6596. }
  6597. else if($type=='core') {
  6598. //Standard font
  6599. // mPDF 4.2.018
  6600. if ($this->PDFA) { $this->Error('Core fonts are not allowed in PDF/A1-b files (Times, Helvetica, Courier etc.)'); }
  6601. $this->fonts[$k]['n']=$this->n+1;
  6602. $this->_newobj();
  6603. $this->_out('<</Type /Font');
  6604. $this->_out('/BaseFont /'.$name);
  6605. $this->_out('/Subtype /Type1');
  6606. if($name!='Symbol' && $name!='ZapfDingbats') {
  6607. $this->_out('/Encoding /WinAnsiEncoding');
  6608. }
  6609. $this->_out('>>');
  6610. $this->_out('endobj');
  6611. }
  6612. // Only uses Type 1 when utf-8 encoded for embedded SUBSETS
  6613. else if ($type=='Type1subset') {
  6614. // mPDF 4.5.014
  6615. if (!$font['used']) { continue; }
  6616. $ssfaid="A";
  6617. if (!class_exists('t1asm')) { include(_MPDF_PATH .'classes/t1asm.php'); }
  6618. // Create Type1 file using t1asm
  6619. $asm = new t1asm();
  6620. $asm->LoadFontFile(MPDF_FONTPATH.substr($font['file'],0,(strpos($font['file'],'.'))));
  6621. for($sfid=0;$sfid<count($font['subsetfontids']);$sfid++) {
  6622. if ($this->progressBar) { $this->UpdateProgressBar(2,'+2','Font subsets'); } // *PROGRESS-BAR*
  6623. $this->fonts[$k]['n'][$sfid]=$this->n+1; // NB an array for subset
  6624. $subsetname = 'MPDFA'.$ssfaid.'+'.$name;
  6625. $ssfaid++;
  6626. $asm->DefineChars($font['subsets'][$sfid], $this->PDFA); // mPDF 4.2.018
  6627. $fontstream = $asm->OutputPFB('');
  6628. ///$font'subsets'][0] = array(charpoint[0-255] => decimal char e.g. 193)
  6629. $widthstring = '';
  6630. $toUnistring = '';
  6631. foreach($font['subsets'][$sfid] AS $cp=>$u) {
  6632. if (isset($font['cw'][$u])) {
  6633. $widthstring .= $font['cw'][$u].' ';
  6634. }
  6635. else if ($cp <32) {
  6636. $widthstring .= '0'.' ';
  6637. }
  6638. else {
  6639. $widthstring .= $font['desc']['MissingWidth'].' ';
  6640. }
  6641. $toUnistring .= sprintf("<%02s> <%04s>\n", strtoupper(dechex($cp)), strtoupper(dechex($u)));
  6642. }
  6643. //Additional Type1 or TrueType font
  6644. $this->_newobj();
  6645. $this->_out('<</Type /Font');
  6646. $this->_out('/BaseFont /'.$subsetname);
  6647. $this->_out('/Subtype /Type1');
  6648. $this->_out('/FirstChar 0 /LastChar '.(count($font['subsets'][$sfid])-1));
  6649. $this->_out('/Widths '.($this->n+1).' 0 R');
  6650. $this->_out('/FontDescriptor '.($this->n+2).' 0 R');
  6651. // mPDF 4.0
  6652. $this->_out('/Encoding '.($this->n + 3).' 0 R');
  6653. $this->_out('/ToUnicode '.($this->n + 4).' 0 R');
  6654. $this->_out('>>');
  6655. $this->_out('endobj');
  6656. //Widths
  6657. $this->_newobj();
  6658. $this->_out('['.$widthstring.']');
  6659. $this->_out('endobj');
  6660. //Descriptor
  6661. $this->_newobj();
  6662. $s='<</Type /FontDescriptor /FontName /'.$subsetname;
  6663. foreach($font['desc'] as $kd=>$v) {
  6664. $s.=' /'.$kd.' '.$v;
  6665. }
  6666. // mPDF 4.2.018 CharSet for PDF/A
  6667. if ($this->PDFA) {
  6668. $s.=' /CharSet ('.$asm->pdfa_charset.')';
  6669. }
  6670. $s.=' /FontFile '.($this->n + 3).' 0 R';
  6671. $this->_out($s.'>>');
  6672. $this->_out('endobj');
  6673. //Encodings
  6674. $this->_newobj();
  6675. $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [ '.$asm->pdf_diffstr .' ]>>');
  6676. $this->_out('endobj');
  6677. // mPDF 4.0
  6678. // ToUnicode
  6679. // Uses the .map files to determine mapping of 7F-FF to Unicode characters
  6680. // Allows copying and pasting of PDF text to another editor
  6681. $toUni = "stream\n";
  6682. $toUni .= "/CIDInit /ProcSet findresource begin\n";
  6683. $toUni .= "12 dict begin\n";
  6684. $toUni .= "begincmap\n";
  6685. $toUni .= "/CIDSystemInfo\n";
  6686. $toUni .= "<</Registry (Adobe)\n";
  6687. $toUni .= "/Ordering (UCS)\n";
  6688. $toUni .= "/Supplement 0\n";
  6689. $toUni .= ">> def\n";
  6690. $toUni .= "/CMapName /Adobe-Identity-UCS def\n";
  6691. $toUni .= "/CMapType 2 def\n";
  6692. $toUni .= "1 begincodespacerange\n";
  6693. $toUni .= "<00> <FF>\n";
  6694. $toUni .= "endcodespacerange\n";
  6695. $toUni .= count($font['subsets'][$sfid])." beginbfchar\n";
  6696. $toUni .= $toUnistring;
  6697. $toUni .= "endbfchar\n";
  6698. $toUni .= "endcmap\n";
  6699. $toUni .= "CMapName currentdict /CMap defineresource pop\n";
  6700. $toUni .= "end\n";
  6701. $toUni .= "end\n";
  6702. $toUni .= "endstream\n";
  6703. $toUni .= "endobj";
  6704. $this->_newobj();
  6705. $this->_out('<</Length '.(strlen($toUni)-24).'>>');
  6706. $this->_out($toUni);
  6707. //Font file
  6708. $this->_newobj();
  6709. $this->_out('<</Length '.strlen($fontstream));
  6710. $this->_out('/Filter /FlateDecode');
  6711. $this->_out('/Length1 '.$asm->of_size1);
  6712. if(isset($asm->of_size2)) {
  6713. $this->_out('/Length2 '.$asm->of_size2.' /Length3 0');
  6714. }
  6715. $this->_out('>>');
  6716. $this->_putstream($fontstream);
  6717. $this->_out('endobj');
  6718. } // foreach subset
  6719. unset($asm );
  6720. }
  6721. else {
  6722. // mPDF 4.0
  6723. if (!$font['used'] && $type=='TrueTypeUnicode') { continue; }
  6724. //Allow for additional types
  6725. $mtd='_put'.strtolower($type);
  6726. if(!method_exists($this, $mtd)) {
  6727. $this->Error('Unsupported font type: '.$type.' ('.$name.')');
  6728. }
  6729. $this->fonts[$k]['n']=$this->n+1;
  6730. $this->$mtd($font);
  6731. }
  6732. }
  6733. }
  6734. else {
  6735. /*-- END UNICODE-FONTS --*/
  6736. $nf=$this->n;
  6737. foreach($this->diffs as $diff)
  6738. {
  6739. //Encodings
  6740. $this->_newobj();
  6741. $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');
  6742. $this->_out('endobj');
  6743. }
  6744. // mPDF 4.1
  6745. $mqr=ini_get("magic_quotes_runtime");
  6746. if ($mqr) { set_magic_quotes_runtime(0); }
  6747. foreach($this->FontFiles as $file=>$info)
  6748. {
  6749. //Font file embedding
  6750. $this->_newobj();
  6751. $this->FontFiles[$file]['n']=$this->n;
  6752. if(defined('MPDF_FONTPATH'))
  6753. $file=MPDF_FONTPATH.$file;
  6754. $size=filesize($file);
  6755. if(!$size)
  6756. $this->Error('Font file not found');
  6757. $this->_out('<</Length '.$size);
  6758. if(substr($file,-2)=='.z')
  6759. $this->_out('/Filter /FlateDecode');
  6760. $this->_out('/Length1 '.$info['length1']);
  6761. if(isset($info['length2']))
  6762. $this->_out('/Length2 '.$info['length2'].' /Length3 0');
  6763. $this->_out('>>');
  6764. $f=fopen($file,'rb');
  6765. $s = '';
  6766. while (!feof($f)) {
  6767. $s .= fread($f, 2048);
  6768. }
  6769. $this->_putstream($s);
  6770. fclose($f);
  6771. $this->_out('endobj');
  6772. }
  6773. // mPDF 4.1
  6774. if ($mqr) { set_magic_quotes_runtime($mqr); }
  6775. foreach($this->fonts as $k=>$font)
  6776. {
  6777. //Font objects
  6778. $this->fonts[$k]['n']=$this->n+1;
  6779. $type=$font['type'];
  6780. $name=$font['name'];
  6781. if($type=='core')
  6782. {
  6783. //Standard font
  6784. // mPDF 4.2.018
  6785. if ($this->PDFA) { $this->Error('Core fonts are not allowed in PDF/A1-b files (Times, Helvetica, Courier etc.)'); }
  6786. $this->_newobj();
  6787. $this->_out('<</Type /Font');
  6788. $this->_out('/BaseFont /'.$name);
  6789. $this->_out('/Subtype /Type1');
  6790. if($name!='Symbol' and $name!='ZapfDingbats')
  6791. $this->_out('/Encoding /WinAnsiEncoding');
  6792. $this->_out('>>');
  6793. $this->_out('endobj');
  6794. }
  6795. elseif($type=='Type1' or $type=='TrueType')
  6796. {
  6797. //Additional Type1 or TrueType font
  6798. $this->_newobj();
  6799. $this->_out('<</Type /Font');
  6800. $this->_out('/BaseFont /'.$name);
  6801. $this->_out('/Subtype /'.$type);
  6802. $this->_out('/FirstChar 32 /LastChar 255');
  6803. $this->_out('/Widths '.($this->n+1).' 0 R');
  6804. $this->_out('/FontDescriptor '.($this->n+2).' 0 R');
  6805. // mPDF 4.0
  6806. $mapdata = false;
  6807. if($font['enc']) {
  6808. if(isset($font['diff'])) {
  6809. $this->_out('/Encoding '.($nf+$font['diff']).' 0 R');
  6810. $mapdata = @file(_MPDF_PATH .'maps/'.$font['enc'].'.map');
  6811. if ($mapdata) {
  6812. $this->_out('/ToUnicode '.($this->n + 3).' 0 R');
  6813. }
  6814. }
  6815. else
  6816. $this->_out('/Encoding /WinAnsiEncoding');
  6817. }
  6818. $this->_out('>>');
  6819. $this->_out('endobj');
  6820. //Widths
  6821. $this->_newobj();
  6822. $cw=&$font['cw'];
  6823. $s='[';
  6824. for($i=32;$i<=255;$i++)
  6825. $s.=$cw[$this->chrs[$i]].' ';
  6826. $this->_out($s.']');
  6827. $this->_out('endobj');
  6828. //Descriptor
  6829. $this->_newobj();
  6830. $s='<</Type /FontDescriptor /FontName /'.$name;
  6831. foreach($font['desc'] as $k=>$v)
  6832. $s.=' /'.$k.' '.$v;
  6833. $file=$font['file'];
  6834. if($file)
  6835. $s.=' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R';
  6836. $this->_out($s.'>>');
  6837. $this->_out('endobj');
  6838. // mPDF 4.0
  6839. // ToUnicode
  6840. // Uses the .map files to determine mapping of 7F-FF to Unicode characters
  6841. // Allows copying and pasting of PDF text to another editor
  6842. if($mapdata) {
  6843. $toUni = "stream\n";
  6844. $toUni .= "/CIDInit /ProcSet findresource begin\n";
  6845. $toUni .= "12 dict begin\n";
  6846. $toUni .= "begincmap\n";
  6847. $toUni .= "/CIDSystemInfo\n";
  6848. $toUni .= "<</Registry (Adobe)\n";
  6849. $toUni .= "/Ordering (UCS)\n";
  6850. $toUni .= "/Supplement 0\n";
  6851. $toUni .= ">> def\n";
  6852. $toUni .= "/CMapName /Adobe-Identity-UCS def\n";
  6853. $toUni .= "/CMapType 2 def\n";
  6854. $toUni .= "1 begincodespacerange\n";
  6855. $toUni .= "<00> <FF>\n";
  6856. $toUni .= "endcodespacerange\n";
  6857. $toUni .= "1 beginbfrange\n";
  6858. $toUni .= "<00> <7F> <0000>\n";
  6859. $toUni .= "endbfrange\n";
  6860. $unip = array();
  6861. foreach($mapdata AS $ms) {
  6862. $tp = hexdec(substr($ms, 1, 2));
  6863. if ($tp > 127) {
  6864. $unip[$tp] = substr($ms, 6, 4);
  6865. }
  6866. }
  6867. $toUni .= count($unip)." beginbfchar\n";
  6868. foreach($unip AS $cp=>$u) {
  6869. $toUni .= sprintf("<%02s> <%04s>\n", strtoupper(dechex($cp)), $u);
  6870. }
  6871. $toUni .= "endbfchar\n";
  6872. $toUni .= "endcmap\n";
  6873. $toUni .= "CMapName currentdict /CMap defineresource pop\n";
  6874. $toUni .= "end\n";
  6875. $toUni .= "end\n";
  6876. $toUni .= "endstream\n";
  6877. $toUni .= "endobj";
  6878. $this->_newobj();
  6879. $this->_out('<</Length '.(strlen($toUni)-24).'>>');
  6880. $this->_out($toUni);
  6881. }
  6882. }
  6883. else
  6884. {
  6885. //Allow for additional types including TrueTypeUnicode
  6886. $mtd='_put'.strtolower($type);
  6887. if(!method_exists($this,$mtd))
  6888. $this->Error('Unsupported font type: '.$type.' ('.$name.')');
  6889. $this->$mtd($font);
  6890. }
  6891. }
  6892. } // *UNICODE-FONTS*
  6893. }
  6894. /*-- UNICODE-FONTS --*/
  6895. // Unicode fonts
  6896. function _puttruetypeunicode($font) {
  6897. // Type0 Font
  6898. // A composite font - a font composed of other fonts, organized hierarchically
  6899. $this->_newobj();
  6900. $this->_out('<</Type /Font');
  6901. $this->_out('/Subtype /Type0');
  6902. $this->_out('/BaseFont /'.$font['name'].'');
  6903. $this->_out('/Encoding /Identity-H'); //The horizontal identity mapping for 2-byte CIDs; may be used with CIDFonts using any Registry, Ordering, and Supplement values.
  6904. $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
  6905. $this->_out('/ToUnicode '.($this->n + 2).' 0 R');
  6906. $this->_out('>>');
  6907. $this->_out('endobj');
  6908. // CIDFontType2
  6909. // A CIDFont whose glyph descriptions are based on TrueType font technology
  6910. $this->_newobj();
  6911. $this->_out('<</Type /Font');
  6912. $this->_out('/Subtype /CIDFontType2');
  6913. $this->_out('/BaseFont /'.$font['name'].'');
  6914. $this->_out('/CIDSystemInfo '.($this->n + 2).' 0 R');
  6915. $this->_out('/FontDescriptor '.($this->n + 3).' 0 R');
  6916. if (isset($font['desc']['MissingWidth'])){
  6917. $this->_out('/DW '.$font['desc']['MissingWidth'].''); // The default width for glyphs in the CIDFont MissingWidth
  6918. }
  6919. $w = "";
  6920. // mPDF 4.5.013
  6921. $lastcid=-1;
  6922. $lastw=-1;
  6923. foreach ($font['cw'] as $cid => $width) {
  6924. if ($lastcid==-1) {
  6925. $w .= ''.$cid.' ['.$width;
  6926. }
  6927. else if ($cid==$lastcid+1) {
  6928. $w .= ' '.$width;
  6929. }
  6930. else {
  6931. $w .= '] '.$cid.' ['.$width;
  6932. }
  6933. $lastcid=$cid;
  6934. $lastw=$width;
  6935. }
  6936. $w .= '] ';
  6937. $this->_out('/W ['.$w.']'); // A description of the widths for the glyphs in the CIDFont
  6938. $this->_out('/CIDToGIDMap '.($this->n + 4).' 0 R');
  6939. $this->_out('>>');
  6940. $this->_out('endobj');
  6941. // ToUnicode
  6942. // is a stream object that contains the definition of the CMap
  6943. // (PDF Reference 1.3 chap. 5.9)
  6944. $this->_newobj();
  6945. $this->_out('<</Length 345>>');
  6946. $this->_out('stream');
  6947. $this->_out('/CIDInit /ProcSet findresource begin');
  6948. $this->_out('12 dict begin');
  6949. $this->_out('begincmap');
  6950. $this->_out('/CIDSystemInfo');
  6951. $this->_out('<</Registry (Adobe)');
  6952. $this->_out('/Ordering (UCS)');
  6953. $this->_out('/Supplement 0');
  6954. $this->_out('>> def');
  6955. $this->_out('/CMapName /Adobe-Identity-UCS def');
  6956. $this->_out('/CMapType 2 def');
  6957. $this->_out('1 begincodespacerange');
  6958. $this->_out('<0000> <FFFF>');
  6959. $this->_out('endcodespacerange');
  6960. $this->_out('1 beginbfrange');
  6961. $this->_out('<0000> <FFFF> <0000>');
  6962. $this->_out('endbfrange');
  6963. $this->_out('endcmap');
  6964. $this->_out('CMapName currentdict /CMap defineresource pop');
  6965. $this->_out('end');
  6966. $this->_out('end');
  6967. $this->_out('endstream');
  6968. $this->_out('endobj');
  6969. // CIDSystemInfo dictionary
  6970. // A dictionary containing entries that define the character collection of the CIDFont.
  6971. $this->_newobj();
  6972. $this->_out('<</Registry (Adobe)'); // A string identifying an issuer of character collections
  6973. $this->_out('/Ordering (UCS)'); // A string that uniquely names a character collection issued by a specific registry
  6974. $this->_out('/Supplement 0'); // The supplement number of the character collection.
  6975. $this->_out('>>');
  6976. $this->_out('endobj');
  6977. // Font descriptor
  6978. // A font descriptor describing the CIDFont's default metrics other than its glyph widths
  6979. $this->_newobj();
  6980. $this->_out('<</Type /FontDescriptor');
  6981. $this->_out('/FontName /'.$font['name']);
  6982. foreach ($font['desc'] as $key => $value) {
  6983. $this->_out('/'.$key.' '.$value);
  6984. }
  6985. if ($font['file']) {
  6986. // obj ID of a stream containing a TrueType font program
  6987. $this->_out('/FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R');
  6988. }
  6989. $this->_out('>>');
  6990. $this->_out('endobj');
  6991. // Embed CIDToGIDMap
  6992. // A specification of the mapping from CIDs to glyph indices
  6993. $this->_newobj();
  6994. $ctgfile = MPDF_FONTPATH.$font['ctg'];
  6995. if(!file_exists($ctgfile)) {
  6996. $this->Error('Font file not found: '.$ctgfile);
  6997. }
  6998. $size = filesize($ctgfile);
  6999. $this->_out('<</Length '.$size.'');
  7000. if(substr($ctgfile, -2) == '.z') { // check file extension
  7001. // Decompresses data encoded using the public-domain
  7002. // zlib/deflate compression method, reproducing the
  7003. // original text or binary data
  7004. $this->_out('/Filter /FlateDecode');
  7005. }
  7006. $this->_out('>>');
  7007. $this->_putstream(file_get_contents($ctgfile));
  7008. $this->_out('endobj');
  7009. }
  7010. function _putfontwidths($font, $cidoffset=0) {
  7011. ksort($font['cw']);
  7012. $rangeid = 0;
  7013. $range = array();
  7014. $prevcid = -2;
  7015. $prevwidth = -1;
  7016. $interval = false;
  7017. // for each character
  7018. foreach ($font['cw'] as $cid => $width) {
  7019. $cid -= $cidoffset;
  7020. if (!isset($font['dw']) || (isset($font['dw']) && $width != $font['dw'])) {
  7021. if ($cid == ($prevcid + 1)) {
  7022. // consecutive CID
  7023. if ($width == $prevwidth) {
  7024. if ($width == $range[$rangeid][0]) {
  7025. $range[$rangeid][] = $width;
  7026. } else {
  7027. array_pop($range[$rangeid]);
  7028. // new range
  7029. $rangeid = $prevcid;
  7030. $range[$rangeid] = array();
  7031. $range[$rangeid][] = $prevwidth;
  7032. $range[$rangeid][] = $width;
  7033. }
  7034. $interval = true;
  7035. $range[$rangeid]['interval'] = true;
  7036. } else {
  7037. if ($interval) {
  7038. // new range
  7039. $rangeid = $cid;
  7040. $range[$rangeid] = array();
  7041. $range[$rangeid][] = $width;
  7042. } else {
  7043. $range[$rangeid][] = $width;
  7044. }
  7045. $interval = false;
  7046. }
  7047. } else {
  7048. // new range
  7049. $rangeid = $cid;
  7050. $range[$rangeid] = array();
  7051. $range[$rangeid][] = $width;
  7052. $interval = false;
  7053. }
  7054. $prevcid = $cid;
  7055. $prevwidth = $width;
  7056. }
  7057. }
  7058. // optimize ranges
  7059. $prevk = -1;
  7060. $nextk = -1;
  7061. $prevint = false;
  7062. foreach ($range as $k => $ws) {
  7063. $cws = count($ws);
  7064. if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) {
  7065. if (isset($range[$k]['interval'])) {
  7066. unset($range[$k]['interval']);
  7067. }
  7068. $range[$prevk] = array_merge($range[$prevk], $range[$k]);
  7069. unset($range[$k]);
  7070. } else {
  7071. $prevk = $k;
  7072. }
  7073. $nextk = $k + $cws;
  7074. if (isset($ws['interval'])) {
  7075. if ($cws > 3) {
  7076. $prevint = true;
  7077. } else {
  7078. $prevint = false;
  7079. }
  7080. unset($range[$k]['interval']);
  7081. --$nextk;
  7082. } else {
  7083. $prevint = false;
  7084. }
  7085. }
  7086. // output data
  7087. $w = '';
  7088. foreach ($range as $k => $ws) {
  7089. if (count(array_count_values($ws)) == 1) {
  7090. // interval mode is more compact
  7091. $w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0];
  7092. } else {
  7093. // range mode
  7094. $w .= ' '.$k.' [ '.implode(' ', $ws).' ]';
  7095. }
  7096. }
  7097. $this->_out('/W ['.$w.' ]');
  7098. }
  7099. /*-- END UNICODE-FONTS --*/
  7100. /*-- CJK --*/
  7101. // from class PDF_Chinese CJK EXTENSIONS
  7102. function _putType0($font)
  7103. {
  7104. //Type0
  7105. $this->_out('/Subtype /Type0');
  7106. $this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']);
  7107. $this->_out('/Encoding /'.$font['CMap']);
  7108. $this->_out('/DescendantFonts ['.($this->n+1).' 0 R]');
  7109. $this->_out('>>');
  7110. $this->_out('endobj');
  7111. //CIDFont
  7112. $this->_newobj();
  7113. $this->_out('<</Type /Font');
  7114. $this->_out('/Subtype /CIDFontType0');
  7115. $this->_out('/BaseFont /'.$font['name']);
  7116. $cidinfo = '/Registry '.$this->_textstring('Adobe');
  7117. $cidinfo .= ' /Ordering '.$this->_textstring($font['registry']['ordering']);
  7118. $cidinfo .= ' /Supplement '.$font['registry']['supplement'];
  7119. $this->_out('/CIDSystemInfo <<'.$cidinfo.'>>');
  7120. $this->_out('/FontDescriptor '.($this->n+1).' 0 R');
  7121. if (isset($font['MissingWidth'])){
  7122. $this->_out('/DW '.$font['MissingWidth'].'');
  7123. }
  7124. $this->_putfontwidths($font, 31);
  7125. $this->_out('>>');
  7126. $this->_out('endobj');
  7127. //Font descriptor
  7128. $this->_newobj();
  7129. $s = '<</Type /FontDescriptor /FontName /'.$font['name'];
  7130. foreach ($font['desc'] as $k => $v) {
  7131. if ($k != 'Style') {
  7132. $s .= ' /'.$k.' '.$v.'';
  7133. }
  7134. }
  7135. $this->_out($s.'>>');
  7136. $this->_out('endobj');
  7137. }
  7138. /*-- END CJK --*/
  7139. function _putimages()
  7140. {
  7141. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  7142. reset($this->images);
  7143. while(list($file,$info)=each($this->images))
  7144. {
  7145. $this->_newobj();
  7146. $this->images[$file]['n']=$this->n;
  7147. $this->_out('<</Type /XObject');
  7148. $this->_out('/Subtype /Image');
  7149. $this->_out('/Width '.$info['w']);
  7150. $this->_out('/Height '.$info['h']);
  7151. // mPDF 4.0
  7152. if (isset($info['masked'])) {
  7153. $this->_out('/SMask '.($this->n - 1).' 0 R');
  7154. }
  7155. if($info['cs']=='Indexed')
  7156. $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]');
  7157. else
  7158. {
  7159. $this->_out('/ColorSpace /'.$info['cs']);
  7160. if($info['cs']=='DeviceCMYK') {
  7161. // mPDF 4.2.018
  7162. if ($this->PDFA) { $this->Error("PDFA1-b does not permit Images using DeviceCMYK colour space (".$file.")."); }
  7163. $this->_out('/Decode [1 0 1 0 1 0 1 0]');
  7164. }
  7165. }
  7166. $this->_out('/BitsPerComponent '.$info['bpc']);
  7167. // mPDF 4.0
  7168. if (isset($info['f']) && $info['f']) { $this->_out('/Filter /'.$info['f']); }
  7169. if(isset($info['parms'])) { $this->_out($info['parms']); }
  7170. if(isset($info['trns']) and is_array($info['trns']))
  7171. {
  7172. $trns='';
  7173. for($i=0;$i<count($info['trns']);$i++)
  7174. $trns.=$info['trns'][$i].' '.$info['trns'][$i].' ';
  7175. $this->_out('/Mask ['.$trns.']');
  7176. }
  7177. $this->_out('/Length '.strlen($info['data']).'>>');
  7178. $this->_putstream($info['data']);
  7179. unset($this->images[$file]['data']);
  7180. $this->_out('endobj');
  7181. //Palette
  7182. if($info['cs']=='Indexed')
  7183. {
  7184. $this->_newobj();
  7185. $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  7186. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
  7187. $this->_putstream($pal);
  7188. $this->_out('endobj');
  7189. }
  7190. }
  7191. }
  7192. function _putinfo()
  7193. {
  7194. $this->_out('/Producer '.$this->_UTF16BEtextstring('mPDF '.mPDF_VERSION));
  7195. if(!empty($this->title))
  7196. $this->_out('/Title '.$this->_UTF16BEtextstring($this->title));
  7197. if(!empty($this->subject))
  7198. $this->_out('/Subject '.$this->_UTF16BEtextstring($this->subject));
  7199. if(!empty($this->author))
  7200. $this->_out('/Author '.$this->_UTF16BEtextstring($this->author));
  7201. if(!empty($this->keywords))
  7202. $this->_out('/Keywords '.$this->_UTF16BEtextstring($this->keywords));
  7203. if(!empty($this->creator))
  7204. $this->_out('/Creator '.$this->_UTF16BEtextstring($this->creator));
  7205. // mPDF 4.2.018
  7206. $z = date('O'); // +0200
  7207. $offset = substr($z,0,3)."'".substr($z,3,2)."'";
  7208. $this->_out('/CreationDate '.$this->_textstring(date('YmdHis').$offset));
  7209. $this->_out('/ModDate '.$this->_textstring(date('YmdHis').$offset));
  7210. }
  7211. // mPDF 4.2.018
  7212. function _putmetadata() {
  7213. $this->_newobj();
  7214. $this->MetadataRoot = $this->n;
  7215. $Producer = 'mPDF '.mPDF_VERSION;
  7216. $z = date('O'); // +0200
  7217. $offset = substr($z,0,3).':'.substr($z,3,2);
  7218. $CreationDate = date('Y-m-d\TH:i:s').$offset; // 2006-03-10T10:47:26-05:00 2006-06-19T09:05:17Z
  7219. $uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff),
  7220. mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000,
  7221. mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) );
  7222. $m = '<?xpacket begin="'.chr(239).chr(187).chr(191).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n"; // begin = FEFF BOM
  7223. $m .= ' <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="3.1-701">'."\n";
  7224. $m .= ' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
  7225. $m .= ' <rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
  7226. $m .= ' <pdf:Producer>'.$Producer.'</pdf:Producer>'."\n";
  7227. if(!empty($this->keywords)) {
  7228. $m .= ' <pdf:Keywords>'.$this->keywords.'</pdf:Keywords>'."\n";
  7229. }
  7230. $m .= ' </rdf:Description>'."\n";
  7231. $m .= ' <rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
  7232. $m .= ' <xmp:CreateDate>'.$CreationDate.'</xmp:CreateDate>'."\n";
  7233. $m .= ' <xmp:ModifyDate>'.$CreationDate.'</xmp:ModifyDate>'."\n";
  7234. $m .= ' <xmp:MetadataDate>'.$CreationDate.'</xmp:MetadataDate>'."\n";
  7235. if(!empty($this->creator)) {
  7236. $m .= ' <xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n";
  7237. }
  7238. $m .= ' </rdf:Description>'."\n";
  7239. $m .= ' <rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
  7240. $m .= ' <dc:format>application/pdf</dc:format>'."\n";
  7241. if(!empty($this->title)) {
  7242. $m .= ' <dc:title>
  7243. <rdf:Alt>
  7244. <rdf:li xml:lang="x-default">'.$this->title.'</rdf:li>
  7245. </rdf:Alt>
  7246. </dc:title>'."\n";
  7247. }
  7248. if(!empty($this->keywords)) {
  7249. $m .= ' <dc:subject>
  7250. <rdf:Bag>
  7251. <rdf:li>'.$this->keywords.'</rdf:li>
  7252. </rdf:Bag>
  7253. </dc:subject>'."\n";
  7254. }
  7255. if(!empty($this->subject)) {
  7256. $m .= ' <dc:description>
  7257. <rdf:Alt>
  7258. <rdf:li xml:lang="x-default">'.$this->subject.'</rdf:li>
  7259. </rdf:Alt>
  7260. </dc:description>'."\n";
  7261. }
  7262. if(!empty($this->author)) {
  7263. $m .= ' <dc:creator>
  7264. <rdf:Seq>
  7265. <rdf:li>'.$this->author.'</rdf:li>
  7266. </rdf:Seq>
  7267. </dc:creator>'."\n";
  7268. }
  7269. $m .= ' </rdf:Description>'."\n";
  7270. // This bit is specific to PDFA-1b
  7271. $m .= ' <rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/" >'."\n";
  7272. $m .= ' <pdfaid:part>1</pdfaid:part>'."\n";
  7273. $m .= ' <pdfaid:conformance>B</pdfaid:conformance>'."\n";
  7274. $m .= ' <pdfaid:amd>2005</pdfaid:amd>'."\n";
  7275. $m .= ' </rdf:Description>'."\n";
  7276. $m .= ' <rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
  7277. $m .= ' <xmpMM:DocumentID>uuid:'.$uuid.'</xmpMM:DocumentID>'."\n";
  7278. $m .= ' </rdf:Description>'."\n";
  7279. $m .= ' </rdf:RDF>'."\n";
  7280. $m .= ' </x:xmpmeta>'."\n";
  7281. $m .= str_repeat(str_repeat(' ',100)."\n",20); // 2-4kB whitespace padding required
  7282. $m .= '<?xpacket end="w"?>'; // "r" read only
  7283. $this->_out('<</Type/Metadata/Subtype/XML/Length '.strlen($m).'>>');
  7284. $this->_putstream($m);
  7285. $this->_out('endobj');
  7286. }
  7287. // mPDF 4.2.018
  7288. function _putoutputintent() {
  7289. $this->_newobj();
  7290. $this->OutputIntentRoot = $this->n;
  7291. if ($this->compress) { $s = gzcompress($s); }
  7292. $this->_out('<</Type /OutputIntent');
  7293. if ($this->ICCProfile)
  7294. $this->_out('/Info ('.$this->ICCProfile.')');
  7295. else
  7296. $this->_out('/Info (sRGB)');
  7297. $this->_out('/S /GTS_PDFA1');
  7298. $this->_out('/OutputConditionIdentifier (Custom)');
  7299. $this->_out('/OutputCondition ()');
  7300. $this->_out('/DestOutputProfile '.($this->n+1).' 0 R >>');
  7301. $this->_out('endobj');
  7302. $this->_newobj();
  7303. if ($this->ICCProfile)
  7304. $s = file_get_contents(_MPDF_PATH.'iccprofiles/'.$this->ICCProfile.'.icc');
  7305. else
  7306. $s = file_get_contents(_MPDF_PATH.'iccprofiles/sRGB_IEC61966-2-1.icc');
  7307. if ($this->compress) { $s = gzcompress($s); }
  7308. $this->_out('<</N 3');
  7309. if ($this->compress)
  7310. $this->_out('/Filter /FlateDecode ');
  7311. $this->_out('/Length '.strlen($s).'>>');
  7312. $this->_putstream($s);
  7313. $this->_out('endobj');
  7314. }
  7315. function _putcatalog() {
  7316. $this->_out('/Type /Catalog');
  7317. $this->_out('/Pages 1 0 R');
  7318. if($this->ZoomMode=='fullpage') $this->_out('/OpenAction [3 0 R /Fit]');
  7319. elseif($this->ZoomMode=='fullwidth') $this->_out('/OpenAction [3 0 R /FitH null]');
  7320. elseif($this->ZoomMode=='real') $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
  7321. elseif(!is_string($this->ZoomMode)) $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']');
  7322. else $this->_out('/OpenAction [3 0 R /XYZ null null null]'); // mPDF 4.3.007F
  7323. if($this->LayoutMode=='single') $this->_out('/PageLayout /SinglePage');
  7324. elseif($this->LayoutMode=='continuous') $this->_out('/PageLayout /OneColumn');
  7325. elseif($this->LayoutMode=='two') {
  7326. if ($this->mirrorMargins) { $this->_out('/PageLayout /TwoColumnRight'); }
  7327. else { $this->_out('/PageLayout /TwoColumnLeft'); }
  7328. }
  7329. /*-- BOOKMARKS --*/
  7330. if(count($this->BMoutlines)>0) {
  7331. $this->_out('/Outlines '.$this->OutlineRoot.' 0 R');
  7332. $this->_out('/PageMode /UseOutlines');
  7333. }
  7334. /*-- END BOOKMARKS --*/
  7335. if(is_int(strpos($this->DisplayPreferences,'FullScreen'))) $this->_out('/PageMode /FullScreen');
  7336. // mPDF 4.2.018 - Metadata
  7337. if ($this->PDFA) {
  7338. $this->_out('/Metadata '.$this->MetadataRoot.' 0 R');
  7339. }
  7340. // mPDF 4.2.018 - OutputIntents
  7341. if ($this->PDFA || $this->ICCProfile) {
  7342. $this->_out('/OutputIntents ['.$this->OutputIntentRoot.' 0 R]');
  7343. }
  7344. if($this->DisplayPreferences || $this->directionality == 'rtl' || $this->mirrorMargins) {
  7345. $this->_out('/ViewerPreferences<<');
  7346. if(is_int(strpos($this->DisplayPreferences,'HideMenubar'))) $this->_out('/HideMenubar true');
  7347. if(is_int(strpos($this->DisplayPreferences,'HideToolbar'))) $this->_out('/HideToolbar true');
  7348. if(is_int(strpos($this->DisplayPreferences,'HideWindowUI'))) $this->_out('/HideWindowUI true');
  7349. if(is_int(strpos($this->DisplayPreferences,'DisplayDocTitle'))) $this->_out('/DisplayDocTitle true');
  7350. if(is_int(strpos($this->DisplayPreferences,'CenterWindow'))) $this->_out('/CenterWindow true');
  7351. if(is_int(strpos($this->DisplayPreferences,'FitWindow'))) $this->_out('/FitWindow true');
  7352. if($this->directionality == 'rtl') $this->_out('/Direction /R2L');
  7353. // mPDF 4.0
  7354. if($this->mirrorMargins) {
  7355. // if ($this->DefOrientation=='P') $this->_out('/Duplex /DuplexFlipShortEdge');
  7356. $this->_out('/Duplex /DuplexFlipLongEdge'); // PDF v1.7+
  7357. }
  7358. $this->_out('>>');
  7359. }
  7360. }
  7361. // Inactive function left for backwards compatability
  7362. function SetUserRights($enable=true, $annots="", $form="", $signature="") {
  7363. // Does nothing
  7364. }
  7365. function _enddoc() {
  7366. if ($this->progressBar) { $this->UpdateProgressBar(2,'+10','Writing Headers & Footers'); } // *PROGRESS-BAR*
  7367. $this->_puthtmlheaders(); // *HTMLHEADERS-FOOTERS*
  7368. if ($this->progressBar) { $this->UpdateProgressBar(2,'+10','Writing Pages'); } // *PROGRESS-BAR*
  7369. // mPDF 4.5.014
  7370. // Remove references to unused fonts (usually default font)
  7371. foreach($this->fonts as $fk=>$font) {
  7372. if (!$font['used'] && ($font['type']=='TrueTypeUnicode' || $font['type']=='Type1subset')) {
  7373. if ($font['type']=='Type1subset') {
  7374. foreach($font['subsetfontids'] AS $k => $fid) {
  7375. foreach($this->pages AS $pn=>$page) {
  7376. $this->pages[$pn] = preg_replace('/\s\/F'.$fid.' \d[\d.]* Tf\s/is',' ',$this->pages[$pn]);
  7377. }
  7378. }
  7379. }
  7380. else {
  7381. foreach($this->pages AS $pn=>$page) {
  7382. $this->pages[$pn] = preg_replace('/\s\/F'.$font['i'].' \d[\d.]* Tf\s/is',' ',$this->pages[$pn]);
  7383. }
  7384. }
  7385. }
  7386. }
  7387. $this->_putpages();
  7388. if ($this->progressBar) { $this->UpdateProgressBar(2,'+10','Writing document resources'); } // *PROGRESS-BAR*
  7389. $this->_putresources();
  7390. //Info
  7391. $this->_newobj();
  7392. $this->InfoRoot = $this->n;
  7393. $this->_out('<<');
  7394. if ($this->progressBar) { $this->UpdateProgressBar(2,'+10','Writing document info'); } // *PROGRESS-BAR*
  7395. $this->_putinfo();
  7396. $this->_out('>>');
  7397. $this->_out('endobj');
  7398. // mPDF 4.2.018
  7399. // METADATA
  7400. if ($this->PDFA) { $this->_putmetadata(); }
  7401. // OUTPUTINTENT
  7402. if ($this->PDFA || $this->ICCProfile) { $this->_putoutputintent(); }
  7403. //Catalog
  7404. $this->_newobj();
  7405. $this->_out('<<');
  7406. if ($this->progressBar) { $this->UpdateProgressBar(2,'+10','Writing document catalog'); } // *PROGRESS-BAR*
  7407. $this->_putcatalog();
  7408. $this->_out('>>');
  7409. $this->_out('endobj');
  7410. //Cross-ref
  7411. $o=strlen($this->buffer);
  7412. $this->_out('xref');
  7413. $this->_out('0 '.($this->n+1));
  7414. $this->_out('0000000000 65535 f ');
  7415. for($i=1; $i <= $this->n ; $i++)
  7416. $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i]));
  7417. //Trailer
  7418. $this->_out('trailer');
  7419. $this->_out('<<');
  7420. $this->_puttrailer();
  7421. $this->_out('>>');
  7422. $this->_out('startxref');
  7423. $this->_out($o);
  7424. // mPDF 4.2.010
  7425. $this->buffer .= '%%EOF';
  7426. $this->state=3;
  7427. /*-- IMPORTS --*/
  7428. // mPDF 4.2.006
  7429. if ($this->enableImports && count($this->parsers) > 0) {
  7430. foreach ($this->parsers as $k => $_){
  7431. $this->parsers[$k]->closeFile();
  7432. $this->parsers[$k] = null;
  7433. unset($this->parsers[$k]);
  7434. }
  7435. }
  7436. /*-- END IMPORTS --*/
  7437. }
  7438. // mPDF 4.2 pagesel, $newformat [4.2.024]
  7439. function _beginpage($orientation,$mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0,$pagesel='',$newformat='') {
  7440. $this->page++;
  7441. $this->pages[$this->page]='';
  7442. $this->state=2;
  7443. $resetHTMLHeadersrequired = false;
  7444. // mPDF 4.2.024
  7445. if ($newformat) { $this->_setPageSize($newformat, $orientation); }
  7446. /*-- CSS-PAGE --*/
  7447. // Paged media (page-box)
  7448. // mPDF 4.2
  7449. if ($pagesel || (isset($this->page_box['using']) && $this->page_box['using'])) {
  7450. if ($pagesel || $this->page==1) { $first = true; }
  7451. else { $first = false; }
  7452. if ($this->mirrorMargins && ($this->page % 2==0)) { $oddEven = 'E'; }
  7453. else { $oddEven = 'O'; }
  7454. if ($pagesel) { $psel = $pagesel; }
  7455. else if ($this->page_box['current']) { $psel = $this->page_box['current']; }
  7456. else { $psel = ''; }
  7457. list($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS($psel, $first, $oddEven);
  7458. if ($this->mirrorMargins && ($this->page % 2==0)) {
  7459. if ($hname) { $ehvalue = 1; $ehname = $hname; } else { $ehvalue = -1; }
  7460. if ($fname) { $efvalue = 1; $efname = $fname; } else { $efvalue = -1; }
  7461. }
  7462. else {
  7463. if ($hname) { $ohvalue = 1; $ohname = $hname; } else { $ohvalue = -1; }
  7464. if ($fname) { $ofvalue = 1; $ofname = $fname; } else { $ofvalue = -1; }
  7465. }
  7466. if ($resetpagenum || $pagenumstyle || $suppress) {
  7467. $this->PageNumSubstitutions[] = array('from'=>($this->page), 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=>$suppress);
  7468. }
  7469. // PAGED MEDIA - CROP / CROSS MARKS from @PAGE
  7470. $this->show_marks = $marks;
  7471. // Background color
  7472. if (isset($bg['BACKGROUND-COLOR'])) {
  7473. $cor = $this->ConvertColor($bg['BACKGROUND-COLOR']);
  7474. if ($cor) {
  7475. $this->bodyBackgroundColor = $cor;
  7476. }
  7477. }
  7478. else { $this->bodyBackgroundColor = false; } // mPDF 4.2
  7479. /*-- GRADIENTS --*/
  7480. if (isset($bg['BACKGROUND-GRADIENT'])) {
  7481. $this->bodyBackgroundGradient = $bg['BACKGROUND-GRADIENT'];
  7482. }
  7483. else { $this->bodyBackgroundGradient = false; } // mPDF 4.2
  7484. /*-- END GRADIENTS --*/
  7485. /*-- BACKGROUND-IMAGES --*/
  7486. // Tiling Patterns
  7487. if (isset($bg['BACKGROUND-IMAGE']) && $bg['BACKGROUND-IMAGE']) { // mPDF 4.3.011
  7488. $file = $bg['BACKGROUND-IMAGE'];
  7489. $sizesarray = $this->Image($file,0,0,0,0,'','',false, false, false, false, false); // mPDF 4.3.032
  7490. if (isset($sizesarray['IMAGE_ID'])) {
  7491. $image_id = $sizesarray['IMAGE_ID'];
  7492. $orig_w = $sizesarray['WIDTH']*$this->k; // in user units i.e. mm
  7493. $orig_h = $sizesarray['HEIGHT']*$this->k; // (using $this->img_dpi)
  7494. $x_repeat = true;
  7495. $y_repeat = true;
  7496. if ($bg['BACKGROUND-REPEAT']=='no-repeat' || $bg['BACKGROUND-REPEAT']=='repeat-x') { $y_repeat = false; }
  7497. if ($bg['BACKGROUND-REPEAT']=='no-repeat' || $bg['BACKGROUND-REPEAT']=='repeat-y') { $x_repeat = false; }
  7498. $x_pos = 0;
  7499. $y_pos = 0;
  7500. if ($bg['BACKGROUND-POSITION']) {
  7501. $ppos = preg_split('/\s+/',$bg['BACKGROUND-POSITION']);
  7502. $x_pos = $ppos[0];
  7503. $y_pos = $ppos[1];
  7504. if (!stristr($x_pos ,'%') ) { $x_pos = $this->ConvertSize($x_pos ,$this->pgwidth,$this->FontSize); }
  7505. if (!stristr($y_pos ,'%') ) { $y_pos = $this->ConvertSize($y_pos ,$this->pgwidth,$this->FontSize); }
  7506. }
  7507. // mPDF 4.3.015
  7508. if (isset($bg['BACKGROUND-IMAGE-RESIZE'])) { $resize = $bg['BACKGROUND-IMAGE-RESIZE']; }
  7509. else { $resize = 0; }
  7510. // mPDF 4.3.017
  7511. if (isset($bg['BACKGROUND-IMAGE-OPACITY'])) { $opacity = $bg['BACKGROUND-IMAGE-OPACITY']; }
  7512. else { $opacity = 1; }
  7513. $this->bodyBackgroundImage = 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); // mPDF 4.3.015 4.3.017
  7514. // $this->bodyBackgroundGradient = false; // mPDF 4.2
  7515. }
  7516. }
  7517. else { $this->bodyBackgroundImage = false; } // mPDF 4.2
  7518. /*-- END BACKGROUND-IMAGES --*/
  7519. $this->page_box['current'] = $psel;
  7520. $this->page_box['using'] = true;
  7521. }
  7522. /*-- END CSS-PAGE --*/
  7523. //Page orientation
  7524. if(!$orientation)
  7525. $orientation=$this->DefOrientation;
  7526. else {
  7527. $orientation=strtoupper(substr($orientation,0,1));
  7528. if($orientation!=$this->DefOrientation)
  7529. $this->OrientationChanges[$this->page]=true;
  7530. }
  7531. if($orientation!=$this->CurOrientation || $newformat) { // mPDF 4.2.024
  7532. //Change orientation
  7533. if($orientation=='P') {
  7534. $this->wPt=$this->fwPt;
  7535. $this->hPt=$this->fhPt;
  7536. $this->w=$this->fw;
  7537. $this->h=$this->fh;
  7538. if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P') {
  7539. $this->tMargin = $this->orig_tMargin;
  7540. $this->bMargin = $this->orig_bMargin;
  7541. $this->DeflMargin = $this->orig_lMargin;
  7542. $this->DefrMargin = $this->orig_rMargin;
  7543. $this->margin_header = $this->orig_hMargin;
  7544. $this->margin_footer = $this->orig_fMargin;
  7545. }
  7546. else { $resetHTMLHeadersrequired = true; } // *HTMLHEADERS-FOOTERS*
  7547. }
  7548. else {
  7549. $this->wPt=$this->fhPt;
  7550. $this->hPt=$this->fwPt;
  7551. $this->w=$this->fh;
  7552. $this->h=$this->fw;
  7553. if (($this->forcePortraitHeaders || $this->forcePortraitMargins) && $this->DefOrientation=='P') {
  7554. $this->tMargin = $this->orig_lMargin;
  7555. $this->bMargin = $this->orig_rMargin;
  7556. $this->DeflMargin = $this->orig_bMargin;
  7557. $this->DefrMargin = $this->orig_tMargin;
  7558. $this->margin_header = $this->orig_hMargin;
  7559. $this->margin_footer = $this->orig_fMargin;
  7560. }
  7561. else { $resetHTMLHeadersrequired = true; } // *HTMLHEADERS-FOOTERS*
  7562. }
  7563. $this->CurOrientation=$orientation;
  7564. $this->ResetMargins();
  7565. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  7566. $this->PageBreakTrigger=$this->h-$this->bMargin;
  7567. }
  7568. $this->pageDim[$this->page]['w']=$this->w ;
  7569. $this->pageDim[$this->page]['h']=$this->h ;
  7570. // If Page Margins are re-defined
  7571. // strlen()>0 is used to pick up (integer) 0, (string) '0', or set value
  7572. 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)) {
  7573. if (strlen($mgl)>0) $this->DeflMargin = $mgl;
  7574. if (strlen($mgr)>0) $this->DefrMargin = $mgr;
  7575. if (strlen($mgt)>0) $this->tMargin = $mgt;
  7576. if (strlen($mgb)>0) $this->bMargin = $mgb;
  7577. if (strlen($mgh)>0) $this->margin_header=$mgh;
  7578. if (strlen($mgf)>0) $this->margin_footer=$mgf;
  7579. $this->ResetMargins();
  7580. $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin);
  7581. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  7582. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  7583. }
  7584. // mPDF 4.2 Moved page-box stuff
  7585. // Moved in v1.4 to allow for changes in page orientation (Sets lMargin, rMargin, MarginCorrection)
  7586. $this->ResetMargins();
  7587. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; // mPDF 4.3.007C
  7588. $this->SetAutoPageBreak($this->autoPageBreak,$this->bMargin);
  7589. // Reset column top margin
  7590. $this->y0 = $this->tMargin;
  7591. $this->x=$this->lMargin;
  7592. $this->y=$this->tMargin;
  7593. $this->FontFamily='';
  7594. // HEADERS AND FOOTERS
  7595. if ($ohvalue<0 || strtoupper($ohvalue)=='OFF') {
  7596. $this->HTMLHeader = '';
  7597. $this->headerDetails['odd'] = array();
  7598. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  7599. }
  7600. else if ($ohname && $ohvalue>0) {
  7601. /*-- HTMLHEADERS-FOOTERS --*/
  7602. if (preg_match('/^html_(.*)$/i',$ohname,$n)) {
  7603. if (isset($this->pageHTMLheaders[$n[1]])) { $this->HTMLHeader = $this->pageHTMLheaders[$n[1]]; }
  7604. else { $this->HTMLHeader = ''; }
  7605. $this->headerDetails['odd'] = array();
  7606. $resetHTMLHeadersrequired = true;
  7607. }
  7608. else {
  7609. /*-- END HTMLHEADERS-FOOTERS --*/
  7610. if (isset($this->pageheaders[$ohname])) { $this->headerDetails['odd'] = $this->pageheaders[$ohname]; }
  7611. else { $this->headerDetails['odd'] = array(); }
  7612. $this->HTMLHeader = '';
  7613. /*-- HTMLHEADERS-FOOTERS --*/
  7614. $resetHTMLHeadersrequired = false;
  7615. }
  7616. /*-- END HTMLHEADERS-FOOTERS --*/
  7617. }
  7618. if ($ehvalue<0 || strtoupper($ehvalue)=='OFF') {
  7619. $this->HTMLHeaderE = '';
  7620. $this->headerDetails['even'] = array();
  7621. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  7622. }
  7623. else if ($ehname && $ehvalue>0) {
  7624. /*-- HTMLHEADERS-FOOTERS --*/
  7625. if (preg_match('/^html_(.*)$/i',$ehname,$n)) {
  7626. if (isset($this->pageHTMLheaders[$n[1]])) { $this->HTMLHeaderE = $this->pageHTMLheaders[$n[1]]; }
  7627. else { $this->HTMLHeaderE = ''; }
  7628. $this->headerDetails['even'] = array();
  7629. $resetHTMLHeadersrequired = true;
  7630. }
  7631. else {
  7632. /*-- END HTMLHEADERS-FOOTERS --*/
  7633. if (isset($this->pageheaders[$ehname])) { $this->headerDetails['even'] = $this->pageheaders[$ehname]; }
  7634. else { $this->headerDetails['even'] = array(); }
  7635. $this->HTMLHeaderE = '';
  7636. /*-- HTMLHEADERS-FOOTERS --*/
  7637. $resetHTMLHeadersrequired = false;
  7638. }
  7639. /*-- END HTMLHEADERS-FOOTERS --*/
  7640. }
  7641. if ($ofvalue<0 || strtoupper($ofvalue)=='OFF') {
  7642. $this->HTMLFooter = '';
  7643. $this->footerDetails['odd'] = array();
  7644. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  7645. }
  7646. else if ($ofname && $ofvalue>0) {
  7647. /*-- HTMLHEADERS-FOOTERS --*/
  7648. if (preg_match('/^html_(.*)$/i',$ofname,$n)) {
  7649. if (isset($this->pageHTMLfooters[$n[1]])) { $this->HTMLFooter = $this->pageHTMLfooters[$n[1]]; }
  7650. else { $this->HTMLFooter = ''; }
  7651. $this->footerDetails['odd'] = array();
  7652. $resetHTMLHeadersrequired = true;
  7653. }
  7654. else {
  7655. /*-- END HTMLHEADERS-FOOTERS --*/
  7656. if (isset($this->pagefooters[$ofname])) { $this->footerDetails['odd'] = $this->pagefooters[$ofname]; }
  7657. else { $this->footerDetails['odd'] = array(); }
  7658. $this->HTMLFooter = '';
  7659. /*-- HTMLHEADERS-FOOTERS --*/
  7660. $resetHTMLHeadersrequired = true;
  7661. }
  7662. /*-- END HTMLHEADERS-FOOTERS --*/
  7663. }
  7664. if ($efvalue<0 || strtoupper($efvalue)=='OFF') {
  7665. $this->HTMLFooterE = '';
  7666. $this->footerDetails['even'] = array();
  7667. $resetHTMLHeadersrequired = true; // *HTMLHEADERS-FOOTERS*
  7668. }
  7669. else if ($efname && $efvalue>0) {
  7670. /*-- HTMLHEADERS-FOOTERS --*/
  7671. if (preg_match('/^html_(.*)$/i',$efname,$n)) {
  7672. if (isset($this->pageHTMLfooters[$n[1]])) { $this->HTMLFooterE = $this->pageHTMLfooters[$n[1]]; }
  7673. else { $this->HTMLFooterE = ''; }
  7674. $this->footerDetails['even'] = array();
  7675. $resetHTMLHeadersrequired = true;
  7676. }
  7677. else {
  7678. /*-- END HTMLHEADERS-FOOTERS --*/
  7679. if (isset($this->pagefooters[$efname])) { $this->footerDetails['even'] = $this->pagefooters[$efname]; }
  7680. else { $this->footerDetails['even'] = array(); }
  7681. $this->HTMLFooterE = '';
  7682. /*-- HTMLHEADERS-FOOTERS --*/
  7683. $resetHTMLHeadersrequired = true;
  7684. }
  7685. /*-- END HTMLHEADERS-FOOTERS --*/
  7686. }
  7687. /*-- HTMLHEADERS-FOOTERS --*/
  7688. if ($resetHTMLHeadersrequired) {
  7689. $this->SetHTMLHeader($this->HTMLHeader );
  7690. $this->SetHTMLHeader($this->HTMLHeaderE ,'E');
  7691. $this->SetHTMLFooter($this->HTMLFooter );
  7692. $this->SetHTMLFooter($this->HTMLFooterE ,'E');
  7693. }
  7694. /*-- END HTMLHEADERS-FOOTERS --*/
  7695. // mPDF 4.0
  7696. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  7697. $this->_setAutoHeaderHeight($this->headerDetails['even'], $this->HTMLHeaderE);
  7698. $this->_setAutoFooterHeight($this->footerDetails['even'], $this->HTMLFooterE);
  7699. }
  7700. else { // ODD or DEFAULT
  7701. $this->_setAutoHeaderHeight($this->headerDetails['odd'], $this->HTMLHeader);
  7702. $this->_setAutoFooterHeight($this->footerDetails['odd'], $this->HTMLFooter);
  7703. }
  7704. // Reset column top margin
  7705. $this->y0 = $this->tMargin;
  7706. $this->x=$this->lMargin;
  7707. $this->y=$this->tMargin;
  7708. }
  7709. // mPDF 4.0
  7710. function _setAutoHeaderHeight(&$det, &$htmlh) {
  7711. if ($this->setAutoTopMargin=='pad') {
  7712. if ($htmlh['h']) { $h = $htmlh['h']; }
  7713. else if ($det) { $h = $this->_getHFHeight($det,'H'); }
  7714. else { $h = 0; }
  7715. $this->tMargin = $this->margin_header + $h + $this->orig_tMargin;
  7716. }
  7717. else if ($this->setAutoTopMargin=='stretch') {
  7718. if ($htmlh['h']) { $h = $htmlh['h']; }
  7719. else if ($det) { $h = $this->_getHFHeight($det,'H'); }
  7720. else { $h = 0; }
  7721. $this->tMargin = max($this->orig_tMargin, $this->margin_header + $h + $this->autoMarginPadding);
  7722. }
  7723. }
  7724. // mPDF 4.0
  7725. function _setAutoFooterHeight(&$det, &$htmlf) {
  7726. if ($this->setAutoBottomMargin=='pad') {
  7727. if ($htmlf['h']) { $h = $htmlf['h']; }
  7728. else if ($det) { $h = $this->_getHFHeight($det,'F'); }
  7729. else { $h = 0; }
  7730. $this->bMargin = $this->margin_footer + $h + $this->orig_bMargin;
  7731. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  7732. }
  7733. else if ($this->setAutoBottomMargin=='stretch') {
  7734. if ($htmlf['h']) { $h = $htmlf['h']; }
  7735. else if ($det) { $h = $this->_getHFHeight($det,'F'); }
  7736. else { $h = 0; }
  7737. $this->bMargin = max($this->orig_bMargin, $this->margin_footer + $h + $this->autoMarginPadding);
  7738. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  7739. }
  7740. }
  7741. // mPDF 4.0
  7742. function _getHFHeight(&$det,$end) {
  7743. $h = 0;
  7744. if(count($det)) {
  7745. foreach(array('L','C','R') AS $pos) {
  7746. if (isset($det[$pos]['content']) && $det[$pos]['content']) {
  7747. if (isset($det[$pos]['font-size']) && $det[$pos]['font-size']) { $hfsz = $det[$pos]['font-size']; }
  7748. else { $hfsz = $this->default_font_size; }
  7749. $h = max($h,$hfsz/$this->k);
  7750. }
  7751. }
  7752. if ($det['line'] && $end=='H') { $h += $h/$this->k*$this->header_line_spacing; }
  7753. else if ($det['line'] && $end=='F') { $h += $h/$this->k*$this->footer_line_spacing; }
  7754. }
  7755. return $h;
  7756. }
  7757. function _endpage() {
  7758. /*-- CSS-IMAGE-FLOAT --*/
  7759. $this->printfloatbuffer();
  7760. /*-- END CSS-IMAGE-FLOAT --*/
  7761. //End of page contents
  7762. $this->state=1;
  7763. }
  7764. // mPDF 4.2.006
  7765. function _newobj($obj_id=false,$onlynewobj=false) {
  7766. if (!$obj_id) {
  7767. $obj_id = ++$this->n;
  7768. }
  7769. //Begin a new object
  7770. if (!$onlynewobj) {
  7771. $this->offsets[$obj_id] = strlen($this->buffer);
  7772. $this->_out($obj_id.' 0 obj');
  7773. $this->_current_obj_id = $obj_id; // for later use with encryption
  7774. }
  7775. }
  7776. function _dounderline($x,$y,$txt) {
  7777. // mPDF 4.0 changed to line instead of rectangle
  7778. // Now print line exactly where $y secifies - called from Text() and Cell() - adjust position there
  7779. // WORD SPACING
  7780. // Modified by Ivan Tcholakov, 28-JAN-2010.
  7781. // $w =($this->GetStringWidth($txt)*$this->k) + ($this->charspacing * mb_strlen( $txt, $this->mb_enc ))
  7782. // + ( $this->ws * mb_substr_count( $txt, ' ', $this->mb_enc ));
  7783. $w =($this->GetStringWidth($txt)*$this->k) + ($this->charspacing * api_strlen( $txt, $this->mb_enc ))
  7784. + ( $this->ws * api_substr_count( $txt, ' ', $this->mb_enc ));
  7785. //
  7786. //Draw a line
  7787. return sprintf('%.3f %.3f m %.3f %.3f l S',$x*$this->k,($this->h-$y)*$this->k,($x*$this->k)+$w,($this->h-$y)*$this->k);
  7788. }
  7789. // mPDF 4.2
  7790. function _imageError($file, $firsttime, $msg) {
  7791. // Save re-trying image URL's which have already failed
  7792. $this->failedimages[$file] = true;
  7793. if ($firsttime && ($this->showImageErrors || $this->debug)) {
  7794. $this->Error("IMAGE Error (".$file."): ".$msg);
  7795. }
  7796. return false;
  7797. }
  7798. // mPDF 4.2
  7799. function _getImage(&$file, $firsttime=true, $allowvector=true, $orig_srcpath=false) { // mPDF 4.2.029 / 4.3.012
  7800. // firsttime i.e. whether to add to this->images - use false when calling iteratively
  7801. // Image Data passed directly as var:varname
  7802. if (preg_match('/var:\s*(.*)/',$file, $v)) {
  7803. $data = $this->$v[1];
  7804. $file = md5($data);
  7805. }
  7806. // mPDF 4.2.016
  7807. if ($firsttime && preg_match('/(.*\/)([^\/]*)/',$file,$fm)) {
  7808. if (strlen($fm[2])) { $file = $fm[1].preg_replace('/ /','%20',$fm[2]); }
  7809. }
  7810. // mPDF 4.2.029
  7811. if ($orig_srcpath && isset($this->images[$orig_srcpath])) { $file=$orig_srcpath; return $this->images[$orig_srcpath]; }
  7812. if (isset($this->images[$file])) { return $this->images[$file]; }
  7813. else if ($orig_srcpath && isset($this->formobjects[$orig_srcpath])) { $file=$orig_srcpath; return $this->formobjects[$file]; }
  7814. else if (isset($this->formobjects[$file])) { return $this->formobjects[$file]; }
  7815. // Save re-trying image URL's which have already failed
  7816. else if ($firsttime && isset($this->failedimages[$file])) { return $this->_imageError($file, $firsttime, ''); }
  7817. if (!$data) {
  7818. $type = '';
  7819. $data = '';
  7820. $mqr=ini_get("magic_quotes_runtime");
  7821. if ($mqr) { set_magic_quotes_runtime(0); }
  7822. // mPDF 4.2.029
  7823. if ($orig_srcpath && $this->basepathIsLocal && $check = @fopen($orig_srcpath,"rb")) {
  7824. fclose($check);
  7825. $file=$orig_srcpath;
  7826. // An adaptation by Ivan Tcholakov, 29-JAN-2010.
  7827. // When the image is URL inside a course, the security system blocks reading it.
  7828. // A workaround: Let us use system paths when it is possible.
  7829. //$data = file_get_contents($file);
  7830. if (api_is_internal_path($file)) {
  7831. $data = file_get_contents(api_get_path(TO_SYS, $file));
  7832. } else {
  7833. $data = file_get_contents($file);
  7834. }
  7835. //
  7836. $type = $this->_imageTypeFromString($data);
  7837. }
  7838. if (!$data && $check = @fopen($file,"rb")) { // mPDF 4.2.029
  7839. fclose($check);
  7840. // Modified by Ivan Tcholakov, 28-JUN-2010.
  7841. //$data = file_get_contents($file);
  7842. if (api_is_internal_path($file)) {
  7843. $data = file_get_contents(api_get_path(TO_SYS, $file));
  7844. } else {
  7845. $data = file_get_contents($file);
  7846. }
  7847. //
  7848. $type = $this->_imageTypeFromString($data);
  7849. }
  7850. if ((!$data || !$type) && !ini_get('allow_url_fopen')) { // only worth trying if remote file and !ini_get('allow_url_fopen')
  7851. $this->file_get_contents_by_socket($file, $data); // needs full url?? even on local (never needed for local)
  7852. if ($data) { $type = $this->_imageTypeFromString($data); }
  7853. }
  7854. if ((!$data || !$type) && !ini_get('allow_url_fopen') && function_exists("curl_init")) {
  7855. $this->file_get_contents_by_curl($file, $data); // needs full url?? even on local (never needed for local)
  7856. if ($data) { $type = $this->_imageTypeFromString($data); }
  7857. }
  7858. if ($mqr) { set_magic_quotes_runtime($mqr); }
  7859. }
  7860. if (!$data) { return $this->_imageError($file, $firsttime, 'Could not find image file'); }
  7861. if (!$type) { $type = $this->_imageTypeFromString($data); }
  7862. // mPDF 4.3.013 SVG files
  7863. if (($type == 'wmf' || $type == 'svg') && !$allowvector) { return $this->_imageError($file, $firsttime, 'WMF or SVG image file not supported in this context'); }
  7864. // mPDF 4.3.013 SVG files
  7865. // SVG
  7866. if ($type == 'svg') {
  7867. if (!class_exists('SVG')) { include(_MPDF_PATH .'classes/svg.php'); }
  7868. $svg = new SVG($this);
  7869. $family=$this->FontFamily;
  7870. $style=$this->FontStyle;
  7871. $size=$this->FontSizePt;
  7872. $info = $svg->ImageSVG($data);
  7873. //Restore font
  7874. if($family) $this->SetFont($family,$style,$size,false);
  7875. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing SVG file'); }
  7876. $info['type']='svg';
  7877. $info['i']=count($this->formobjects)+1;
  7878. $this->formobjects[$file]=$info;
  7879. return $info;
  7880. }
  7881. // JPEG
  7882. if ($type == 'jpeg' || $type == 'jpg') {
  7883. $hdr = $this->_jpgHeaderFromString($data);
  7884. if (!$hdr) { return $this->_imageError($file, $firsttime, 'Error parsing JPG header'); }
  7885. $a = $this->_jpgDataFromHeader($hdr);
  7886. // mPDF 4.2.018
  7887. if ($a[2] == 'DeviceCMYK' && $this->PDFA) {
  7888. if (!function_exists("gd_info")) { $this->Error("JPG image may not use CMYK color space (".$file.")."); }
  7889. if (!$this->PDFAauto) { $this->PDFAwarnings[] = "JPG image may not use CMYK color space - ".$file." - (Image converted to RGB. NB This will alter the colour profile of the image.)"; }
  7890. // convert to RGB image
  7891. $im = @imagecreatefromstring($data);
  7892. if ($im) {
  7893. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png'; // mPDF 4.3.007E
  7894. imageinterlace($im, false);
  7895. $check = @imagepng($im, $tempfile);
  7896. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse JPG(CMYK) image'); }
  7897. $info = $this->_getImage($tempfile, false);
  7898. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse JPG(CMYK) image'); }
  7899. imagedestroy($im);
  7900. unlink($tempfile);
  7901. $info['type']='jpg';
  7902. if ($firsttime) {
  7903. $info['i']=count($this->images)+1;
  7904. $this->images[$file]=$info;
  7905. }
  7906. return $info;
  7907. }
  7908. else { return $this->_imageError($file, $firsttime, 'Error creating GD image file from JPG(CMYK) image'); }
  7909. }
  7910. $info = array('w'=>$a[0],'h'=>$a[1],'cs'=>$a[2],'bpc'=>$a[3],'f'=>'DCTDecode','data'=>$data);
  7911. $info['type']='jpg';
  7912. if ($firsttime) {
  7913. $info['i']=count($this->images)+1;
  7914. $this->images[$file]=$info;
  7915. }
  7916. return $info;
  7917. }
  7918. // PNG
  7919. else if ($type == 'png') {
  7920. //Check signature
  7921. if(substr($data,0,8)!=$this->chrs[137].'PNG'.$this->chrs[13].$this->chrs[10].$this->chrs[26].$this->chrs[10]) {
  7922. return $this->_imageError($file, $firsttime, 'Error parsing PNG identifier');
  7923. }
  7924. //Read header chunk
  7925. if(substr($data,12,4)!='IHDR') {
  7926. return $this->_imageError($file, $firsttime, 'Incorrect PNG file (no IHDR block found)');
  7927. }
  7928. $w=$this->_fourbytes2int(substr($data,16,4));
  7929. $h=$this->_fourbytes2int(substr($data,20,4));
  7930. $bpc=$this->ords[substr($data,24,1)];
  7931. $errpng = false;
  7932. $pngalpha = false;
  7933. if($bpc>8) { $errpng = 'not 8-bit depth'; }
  7934. $ct=$this->ords[substr($data,25,1)];
  7935. if($ct==0) { $colspace='DeviceGray'; }
  7936. elseif($ct==2) { $colspace='DeviceRGB'; }
  7937. elseif($ct==3) { $colspace='Indexed'; }
  7938. else { $errpng = 'alpha channel'; $pngalpha = true; }
  7939. if($this->ords[substr($data,26,1)]!=0) { $errpng = 'compression method'; }
  7940. if($this->ords[substr($data,27,1)]!=0) { $errpng = 'filter method'; }
  7941. if($this->ords[substr($data,28,1)]!=0) { $errpng = 'interlaced file'; }
  7942. if ($errpng || $pngalpha) {
  7943. if (function_exists('gd_info')) { $gd = gd_info(); }
  7944. else {$gd = array(); }
  7945. if (!isset($gd['PNG Support'])) { return $this->_imageError($file, $firsttime, 'GD library required for PNG image ('.$errpng.')'); }
  7946. $im = imagecreatefromstring($data);
  7947. if (!$im) { return $this->_imageError($file, $firsttime, 'Error creating GD image from PNG file ('.$errpng.')'); }
  7948. $w = imagesx($im);
  7949. $h = imagesy($im);
  7950. if ($im) {
  7951. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png'; // mPDF 4.3.007E
  7952. // Alpha channel set
  7953. if ($pngalpha) {
  7954. // mPDF 4.2.018
  7955. if ($this->PDFA) { $this->Error("PDFA1-b does not permit images with alpha channel transparency (".$file.")."); }
  7956. $imgalpha = imagecreate($w, $h);
  7957. // generate gray scale pallete
  7958. for ($c = 0; $c < 256; ++$c) { ImageColorAllocate($imgalpha, $c, $c, $c); }
  7959. // extract alpha channel
  7960. for ($xpx = 0; $xpx < $w; ++$xpx) {
  7961. for ($ypx = 0; $ypx < $h; ++$ypx) {
  7962. $colorindex = imagecolorat($im, $xpx, $ypx);
  7963. $col = imagecolorsforindex($im, $colorindex);
  7964. $gammacorr = 2.2; // gamma correction
  7965. $gamma = (pow((((127 - $col['alpha']) * 255 / 127) / 255), $gammacorr) * 255);
  7966. imagesetpixel($imgalpha, $xpx, $ypx, $gamma);
  7967. }
  7968. }
  7969. // create temp alpha file
  7970. $tempfile_alpha = _MPDF_TEMP_PATH.'_tempMskPNG'.RAND(1,10000).'.png'; // mPDF 4.3.007E
  7971. $check = @imagepng($imgalpha, $tempfile_alpha);
  7972. if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile_alpha.') parsing PNG image with alpha channel ('.$errpng.')'); }
  7973. imagedestroy($imgalpha);
  7974. // extract image without alpha channel
  7975. $imgplain = imagecreatetruecolor($w, $h);
  7976. imagecopy($imgplain, $im, 0, 0, 0, 0, $w, $h);
  7977. // create temp image file
  7978. $check = @imagepng($imgplain, $tempfile);
  7979. if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile.') parsing PNG image with alpha channel ('.$errpng.')'); }
  7980. imagedestroy($imgplain);
  7981. // embed mask image
  7982. $minfo = $this->_getImage($tempfile_alpha, false);
  7983. unlink($tempfile_alpha);
  7984. if (!$minfo) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile_alpha.') created with GD library to parse PNG image'); }
  7985. $imgmask = count($this->images)+1;
  7986. $minfo['cs'] = 'DeviceGray';
  7987. $minfo['i']=$imgmask ;
  7988. $this->images[$tempfile_alpha] = $minfo;
  7989. // embed image, masked with previously embedded mask
  7990. $info = $this->_getImage($tempfile, false);
  7991. unlink($tempfile);
  7992. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse PNG image'); }
  7993. $info['masked'] = $imgmask;
  7994. $info['i']=count($this->images)+1;
  7995. $info['type']='png';
  7996. $this->images[$file]=$info;
  7997. return $info;
  7998. }
  7999. else { // No alpha/transparency set
  8000. imagealphablending($im, false);
  8001. imagesavealpha($im, false);
  8002. imageinterlace($im, false);
  8003. $check = @imagepng($im, $tempfile );
  8004. if (!$check) { return $this->_imageError($file, $firsttime, 'Failed to create temporary image file ('.$tempfile.') parsing PNG image ('.$errpng.')'); }
  8005. imagedestroy($im);
  8006. $info = $this->_getImage($tempfile, false) ;
  8007. unlink($tempfile );
  8008. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse PNG image'); }
  8009. $info['i']=count($this->images)+1;
  8010. $info['type']='png';
  8011. $this->images[$file]=$info;
  8012. return $info;
  8013. }
  8014. }
  8015. }
  8016. $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
  8017. //Scan chunks looking for palette, transparency and image data
  8018. $pal='';
  8019. $trns='';
  8020. $pngdata='';
  8021. $p = 33;
  8022. do {
  8023. $n=$this->_fourbytes2int(substr($data,$p,4)); $p += 4;
  8024. $type=substr($data,$p,4); $p += 4;
  8025. if($type=='PLTE') {
  8026. //Read palette
  8027. $pal=substr($data,$p,$n); $p += $n;
  8028. $p += 4;
  8029. }
  8030. elseif($type=='tRNS') {
  8031. //Read transparency info
  8032. $t=substr($data,$p,$n); $p += $n;
  8033. if($ct==0) $trns=array($this->ords[substr($t,1,1)]);
  8034. elseif($ct==2) $trns=array($this->ords[substr($t,1,1)],$this->ords[substr($t,3,1)],$this->ords[substr($t,5,1)]);
  8035. else
  8036. {
  8037. $pos=strpos($t,$this->chrs[0]);
  8038. if(is_int($pos)) $trns=array($pos);
  8039. }
  8040. $p += 4;
  8041. }
  8042. elseif($type=='IDAT') {
  8043. $pngdata.=substr($data,$p,$n); $p += $n;
  8044. $p += 4;
  8045. }
  8046. elseif($type=='IEND') { break; }
  8047. else if (preg_match('/[a-zA-Z]{4}/',$type)) { $p += $n+4; }
  8048. else { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data'); }
  8049. }
  8050. while($n);
  8051. if (!$pngdata) { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data - no IDAT data found'); }
  8052. if($colspace=='Indexed' and empty($pal)) { return $this->_imageError($file, $firsttime, 'Error parsing PNG image data - missing colour palette'); }
  8053. $info = array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$pngdata);
  8054. $info['type']='png';
  8055. if ($firsttime) {
  8056. $info['i']=count($this->images)+1;
  8057. $this->images[$file]=$info;
  8058. }
  8059. return $info;
  8060. }
  8061. // GIF
  8062. else if ($type == 'gif') {
  8063. if (function_exists('gd_info')) { $gd = gd_info(); }
  8064. else {$gd = array(); }
  8065. if (isset($gd['GIF Read Support']) && $gd['GIF Read Support']) {
  8066. $im = @imagecreatefromstring($data);
  8067. if ($im) {
  8068. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png'; // mPDF 4.3.007E
  8069. imagealphablending($im, false);
  8070. imagesavealpha($im, false);
  8071. imageinterlace($im, false);
  8072. $check = @imagepng($im, $tempfile);
  8073. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse GIF image'); }
  8074. $info = $this->_getImage($tempfile, false);
  8075. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse GIF image'); }
  8076. imagedestroy($im);
  8077. unlink($tempfile);
  8078. $info['type']='gif';
  8079. if ($firsttime) {
  8080. $info['i']=count($this->images)+1;
  8081. $this->images[$file]=$info;
  8082. }
  8083. return $info;
  8084. }
  8085. else { return $this->_imageError($file, $firsttime, 'Error creating GD image file from GIF image'); }
  8086. }
  8087. if (!class_exists('gif')) {
  8088. include_once(_MPDF_PATH.'classes/gif.php');
  8089. $gif=new CGIF();
  8090. }
  8091. $h=0;
  8092. $w=0;
  8093. $gif->loadFile($data, 0);
  8094. if(isset($gif->m_img->m_gih->m_bLocalClr) && $gif->m_img->m_gih->m_bLocalClr) {
  8095. $nColors = $gif->m_img->m_gih->m_nTableSize;
  8096. $pal = $gif->m_img->m_gih->m_colorTable->toString();
  8097. if($bgColor != -1) {
  8098. $bgColor = $gif->m_img->m_gih->m_colorTable->colorIndex($bgColor);
  8099. }
  8100. $colspace='Indexed';
  8101. } elseif(isset($gif->m_gfh->m_bGlobalClr) && $gif->m_gfh->m_bGlobalClr) {
  8102. $nColors = $gif->m_gfh->m_nTableSize;
  8103. $pal = $gif->m_gfh->m_colorTable->toString();
  8104. if((isset($bgColor)) and $bgColor != -1) {
  8105. $bgColor = $gif->m_gfh->m_colorTable->colorIndex($bgColor);
  8106. }
  8107. $colspace='Indexed';
  8108. } else {
  8109. $nColors = 0;
  8110. $bgColor = -1;
  8111. $colspace='DeviceGray';
  8112. $pal='';
  8113. }
  8114. $trns='';
  8115. if(isset($gif->m_img->m_bTrans) && $gif->m_img->m_bTrans && ($nColors > 0)) {
  8116. $trns=array($gif->m_img->m_nTrans);
  8117. }
  8118. $gifdata=$gif->m_img->m_data;
  8119. $w=$gif->m_gfh->m_nWidth;
  8120. $h=$gif->m_gfh->m_nHeight;
  8121. $gif->ClearData();
  8122. if($colspace=='Indexed' and empty($pal)) {
  8123. return $this->_imageError($file, $firsttime, 'Error parsing GIF image - missing colour palette');
  8124. }
  8125. if ($this->compress) {
  8126. $gifdata=gzcompress($gifdata);
  8127. $info = array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'f'=>'FlateDecode', 'pal'=>$pal, 'trns'=>$trns, 'data'=>$gifdata);
  8128. }
  8129. else {
  8130. $info = array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'pal'=>$pal, 'trns'=>$trns, 'data'=>$gifdata);
  8131. }
  8132. $info['type']='gif';
  8133. if ($firsttime) {
  8134. $info['i']=count($this->images)+1;
  8135. $this->images[$file]=$info;
  8136. }
  8137. return $info;
  8138. }
  8139. // mPDF 4.5.011
  8140. // BMP (Windows Bitmap)
  8141. else if ($type == 'bmp') {
  8142. // Adapted from script by Valentin Schmidt
  8143. // http://staff.dasdeck.de/valentin/fpdf/fpdf_bmp/
  8144. $bfOffBits=$this->_fourbytes2int_le(substr($data,10,4));
  8145. $width=$this->_fourbytes2int_le(substr($data,18,4));
  8146. $height=$this->_fourbytes2int_le(substr($data,22,4));
  8147. $flip = ($height<0);
  8148. if ($flip) $height =-$height;
  8149. $biBitCount=$this->_twobytes2int_le(substr($data,28,2));
  8150. $biCompression=$this->_fourbytes2int_le(substr($data,30,4));
  8151. $info = array('w'=>$width, 'h'=>$height);
  8152. if ($biBitCount<16){
  8153. $info['cs'] = 'Indexed';
  8154. $info['bpc'] = $biBitCount;
  8155. $palStr = substr($data,54,($bfOffBits-54));
  8156. $pal = '';
  8157. $cnt = strlen($palStr)/4;
  8158. for ($i=0;$i<$cnt;$i++){
  8159. $n = 4*$i;
  8160. $pal .= $palStr{$n+2}.$palStr{$n+1}.$palStr{$n};
  8161. }
  8162. $info['pal'] = $pal;
  8163. }
  8164. else{
  8165. $info['cs'] = 'DeviceRGB';
  8166. $info['bpc'] = 8;
  8167. }
  8168. switch ($biCompression){
  8169. case 0:
  8170. $str = substr($data,$bfOffBits);
  8171. break;
  8172. case 1: # BI_RLE8
  8173. $str = $this->rle8_decode(substr($data,$bfOffBits), $width);
  8174. break;
  8175. case 2: # BI_RLE4
  8176. $str = $this->rle4_decode(substr($data,$bfOffBits), $width);
  8177. break;
  8178. }
  8179. $bmpdata = '';
  8180. $padCnt = (4-ceil(($width/(8/$biBitCount)))%4)%4;
  8181. switch ($biBitCount){
  8182. case 1:
  8183. case 4:
  8184. case 8:
  8185. $w = floor($width/(8/$biBitCount)) + ($width%(8/$biBitCount)?1:0);
  8186. $w_row = $w + $padCnt;
  8187. if ($flip){
  8188. for ($y=0;$y<$height;$y++){
  8189. $y0 = $y*$w_row;
  8190. for ($x=0;$x<$w;$x++)
  8191. $bmpdata .= $str{$y0+$x};
  8192. }
  8193. }else{
  8194. for ($y=$height-1;$y>=0;$y--){
  8195. $y0 = $y*$w_row;
  8196. for ($x=0;$x<$w;$x++)
  8197. $bmpdata .= $str{$y0+$x};
  8198. }
  8199. }
  8200. break;
  8201. case 16:
  8202. $w_row = $width*2 + $padCnt;
  8203. if ($flip){
  8204. for ($y=0;$y<$height;$y++){
  8205. $y0 = $y*$w_row;
  8206. for ($x=0;$x<$width;$x++){
  8207. $n = (ord( $str{$y0 + 2*$x + 1})*256 + ord( $str{$y0 + 2*$x}));
  8208. $b = ($n & 31)<<3; $g = ($n & 992)>>2; $r = ($n & 31744)>>7128;
  8209. $bmpdata .= chr($r) . chr($g) . chr($b);
  8210. }
  8211. }
  8212. }else{
  8213. for ($y=$height-1;$y>=0;$y--){
  8214. $y0 = $y*$w_row;
  8215. for ($x=0;$x<$width;$x++){
  8216. $n = (ord( $str{$y0 + 2*$x + 1})*256 + ord( $str{$y0 + 2*$x}));
  8217. $b = ($n & 31)<<3; $g = ($n & 992)>>2; $r = ($n & 31744)>>7;
  8218. $bmpdata .= chr($r) . chr($g) . chr($b);
  8219. }
  8220. }
  8221. }
  8222. break;
  8223. case 24:
  8224. case 32:
  8225. $byteCnt = $biBitCount/8;
  8226. $w_row = $width*$byteCnt + $padCnt;
  8227. if ($flip){
  8228. for ($y=0;$y<$height;$y++){
  8229. $y0 = $y*$w_row;
  8230. for ($x=0;$x<$width;$x++){
  8231. $i = $y0 + $x*$byteCnt ; # + 1
  8232. $bmpdata .= $str{$i+2}.$str{$i+1}.$str{$i};
  8233. }
  8234. }
  8235. }else{
  8236. for ($y=$height-1;$y>=0;$y--){
  8237. $y0 = $y*$w_row;
  8238. for ($x=0;$x<$width;$x++){
  8239. $i = $y0 + $x*$byteCnt ; # + 1
  8240. $bmpdata .= $str{$i+2}.$str{$i+1}.$str{$i};
  8241. }
  8242. }
  8243. }
  8244. break;
  8245. default:
  8246. return $this->_imageError($file, $firsttime, 'Error parsing BMP image - Unsupported image biBitCount');
  8247. }
  8248. if ($this->compress) {
  8249. $bmpdata=gzcompress($bmpdata);
  8250. $info['f']='FlateDecode';
  8251. }
  8252. $info['data']=$bmpdata;
  8253. $info['type']='bmp';
  8254. if ($firsttime) {
  8255. $info['i']=count($this->images)+1;
  8256. $this->images[$file]=$info;
  8257. }
  8258. return $info;
  8259. }
  8260. /*-- IMAGES-WMF --*/
  8261. // WMF
  8262. else if ($type == 'wmf') {
  8263. $this->gdiObjectArray = array();
  8264. $a=unpack('stest',"\1\0");
  8265. if ($a['test']!=1)
  8266. return $this->_imageError($file, $firsttime, 'Error parsing WMF image - Big-endian architecture not supported');
  8267. // check for Aldus placeable metafile header
  8268. $key = unpack('Lmagic', substr($data, 0, 4));
  8269. $p = 18; // WMF header
  8270. if ($key['magic'] == (int)0x9AC6CDD7) { $p +=22; } // Aldus header
  8271. // define some state variables
  8272. $wo=null; // window origin
  8273. $we=null; // window extent
  8274. $polyFillMode = 0;
  8275. $nullPen = false;
  8276. $nullBrush = false;
  8277. $endRecord = false;
  8278. $wmfdata = '';
  8279. while ($p < strlen($data) && !$endRecord) {
  8280. $recordInfo = unpack('Lsize/Sfunc', substr($data, $p, 6)); $p += 6;
  8281. // size of record given in WORDs (= 2 bytes)
  8282. $size = $recordInfo['size'];
  8283. // func is number of GDI function
  8284. $func = $recordInfo['func'];
  8285. if ($size > 3) {
  8286. $parms = substr($data, $p, 2*($size-3)); $p += 2*($size-3);
  8287. }
  8288. switch ($func) {
  8289. case 0x020b: // SetWindowOrg
  8290. // do not allow window origin to be changed
  8291. // after drawing has begun
  8292. if (!$wmfdata)
  8293. $wo = array_reverse(unpack('s2', $parms));
  8294. break;
  8295. case 0x020c: // SetWindowExt
  8296. // do not allow window extent to be changed
  8297. // after drawing has begun
  8298. if (!$wmfdata)
  8299. $we = array_reverse(unpack('s2', $parms));
  8300. break;
  8301. case 0x02fc: // CreateBrushIndirect
  8302. $brush = unpack('sstyle/Cr/Cg/Cb/Ca/Shatch', $parms);
  8303. $brush['type'] = 'B';
  8304. $this->_AddGDIObject($brush);
  8305. break;
  8306. case 0x02fa: // CreatePenIndirect
  8307. $pen = unpack('Sstyle/swidth/sdummy/Cr/Cg/Cb/Ca', $parms);
  8308. // convert width from twips to user unit
  8309. $pen['width'] /= (20 * $this->k);
  8310. $pen['type'] = 'P';
  8311. $this->_AddGDIObject($pen);
  8312. break;
  8313. // MUST create other GDI objects even if we don't handle them
  8314. case 0x06fe: // CreateBitmap
  8315. case 0x02fd: // CreateBitmapIndirect
  8316. case 0x00f8: // CreateBrush
  8317. case 0x02fb: // CreateFontIndirect
  8318. case 0x00f7: // CreatePalette
  8319. case 0x01f9: // CreatePatternBrush
  8320. case 0x06ff: // CreateRegion
  8321. case 0x0142: // DibCreatePatternBrush
  8322. $dummyObject = array('type'=>'D');
  8323. $this->_AddGDIObject($dummyObject);
  8324. break;
  8325. case 0x0106: // SetPolyFillMode
  8326. $polyFillMode = unpack('smode', $parms);
  8327. $polyFillMode = $polyFillMode['mode'];
  8328. break;
  8329. case 0x01f0: // DeleteObject
  8330. $idx = unpack('Sidx', $parms);
  8331. $idx = $idx['idx'];
  8332. $this->_DeleteGDIObject($idx);
  8333. break;
  8334. case 0x012d: // SelectObject
  8335. $idx = unpack('Sidx', $parms);
  8336. $idx = $idx['idx'];
  8337. $obj = $this->_GetGDIObject($idx);
  8338. switch ($obj['type']) {
  8339. case 'B':
  8340. $nullBrush = false;
  8341. if ($obj['style'] == 1) { $nullBrush = true; }
  8342. else {
  8343. $wmfdata .= sprintf("%.3f %.3f %.3f rg\n",$obj['r']/255,$obj['g']/255,$obj['b']/255);
  8344. }
  8345. break;
  8346. case 'P':
  8347. $nullPen = false;
  8348. $dashArray = array();
  8349. // dash parameters are custom
  8350. switch ($obj['style']) {
  8351. case 0: // PS_SOLID
  8352. break;
  8353. case 1: // PS_DASH
  8354. $dashArray = array(3,1);
  8355. break;
  8356. case 2: // PS_DOT
  8357. $dashArray = array(0.5,0.5);
  8358. break;
  8359. case 3: // PS_DASHDOT
  8360. $dashArray = array(2,1,0.5,1);
  8361. break;
  8362. case 4: // PS_DASHDOTDOT
  8363. $dashArray = array(2,1,0.5,1,0.5,1);
  8364. break;
  8365. case 5: // PS_NULL
  8366. $nullPen = true;
  8367. break;
  8368. }
  8369. if (!$nullPen) {
  8370. $wmfdata .= sprintf("%.3f %.3f %.3f RG\n",$obj['r']/255,$obj['g']/255,$obj['b']/255);
  8371. $wmfdata .= sprintf("%.3f w\n",$obj['width']*$this->k);
  8372. }
  8373. if (!empty($dashArray)) {
  8374. $s = '[';
  8375. for ($i=0; $i<count($dashArray);$i++) {
  8376. $s .= $dashArray[$i] * $this->k;
  8377. if ($i != count($dashArray)-1) { $s .= ' '; }
  8378. }
  8379. $s .= '] 0 d';
  8380. $wmfdata .= $s."\n";
  8381. }
  8382. break;
  8383. }
  8384. break;
  8385. case 0x0325: // Polyline
  8386. case 0x0324: // Polygon
  8387. $coords = unpack('s'.($size-3), $parms);
  8388. $numpoints = $coords[1];
  8389. for ($i = $numpoints; $i > 0; $i--) {
  8390. $px = $coords[2*$i];
  8391. $py = $coords[2*$i+1];
  8392. if ($i < $numpoints) { $wmfdata .= $this->_LineTo($px, $py); }
  8393. else { $wmfdata .= $this->_MoveTo($px, $py); }
  8394. }
  8395. if ($func == 0x0325) { $op = 's'; }
  8396. else if ($func == 0x0324) {
  8397. if ($nullPen) {
  8398. if ($nullBrush) { $op = 'n'; } // no op
  8399. else { $op = 'f'; } // fill
  8400. }
  8401. else {
  8402. if ($nullBrush) { $op = 's'; } // stroke
  8403. else { $op = 'b'; } // stroke and fill
  8404. }
  8405. if ($polyFillMode==1 && ($op=='b' || $op=='f')) { $op .= '*'; } // use even-odd fill rule
  8406. }
  8407. $wmfdata .= $op."\n";
  8408. break;
  8409. case 0x0538: // PolyPolygon
  8410. $coords = unpack('s'.($size-3), $parms);
  8411. $numpolygons = $coords[1];
  8412. $adjustment = $numpolygons;
  8413. for ($j = 1; $j <= $numpolygons; $j++) {
  8414. $numpoints = $coords[$j + 1];
  8415. for ($i = $numpoints; $i > 0; $i--) {
  8416. $px = $coords[2*$i + $adjustment];
  8417. $py = $coords[2*$i+1 + $adjustment];
  8418. if ($i == $numpoints) { $wmfdata .= $this->_MoveTo($px, $py); }
  8419. else { $wmfdata .= $this->_LineTo($px, $py); }
  8420. }
  8421. $adjustment += $numpoints * 2;
  8422. }
  8423. if ($nullPen) {
  8424. if ($nullBrush) { $op = 'n'; } // no op
  8425. else { $op = 'f'; } // fill
  8426. }
  8427. else {
  8428. if ($nullBrush) { $op = 's'; } // stroke
  8429. else { $op = 'b'; } // stroke and fill
  8430. }
  8431. if ($polyFillMode==1 && ($op=='b' || $op=='f')) { $op .= '*'; } // use even-odd fill rule
  8432. $wmfdata .= $op."\n";
  8433. break;
  8434. case 0x0000:
  8435. $endRecord = true;
  8436. break;
  8437. }
  8438. }
  8439. if (!$wmfdata) { return $this->_imageError($file, $firsttime, 'Error parsing WMF image'); }
  8440. $info = array('x'=>$wo[0],'y'=>$wo[1],'w'=>$we[0],'h'=>$we[1],'data'=>$wmfdata);
  8441. $info['i']=count($this->formobjects)+1;
  8442. $info['type']='wmf';
  8443. $this->formobjects[$file]=$info;
  8444. return $info;
  8445. }
  8446. /*-- END IMAGES-WMF --*/
  8447. // UNKNOWN TYPE - try GD imagecreatefromstring
  8448. else {
  8449. if (function_exists('gd_info')) { $gd = gd_info(); }
  8450. else {$gd = array(); }
  8451. if (isset($gd['PNG Support']) && $gd['PNG Support']) {
  8452. $im = @imagecreatefromstring($data);
  8453. if (!$im) { return $this->_imageError($file, $firsttime, 'Error parsing image file - image type not recognised, and not supported by GD imagecreate'); }
  8454. $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png'; // mPDF 4.3.007E
  8455. imagealphablending($im, false);
  8456. imagesavealpha($im, false);
  8457. imageinterlace($im, false);
  8458. $check = @imagepng($im, $tempfile);
  8459. if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary file ('.$tempfile.') whilst using GD library to parse unknown image type'); }
  8460. $info = $this->_getImage($tempfile, false);
  8461. imagedestroy($im);
  8462. unlink($tempfile);
  8463. if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file ('.$tempfile.') created with GD library to parse unknown image type'); }
  8464. $info['type']='png';
  8465. if ($firsttime) {
  8466. $info['i']=count($this->images)+1;
  8467. $this->images[$file]=$info;
  8468. }
  8469. return $info;
  8470. }
  8471. }
  8472. return $this->_imageError($file, $firsttime, 'Error parsing image file - image type not recognised');
  8473. }
  8474. //==============================================================
  8475. // mPDF 4.5.011
  8476. # Decoder for RLE8 compression in windows bitmaps
  8477. # see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_6x0u.asp
  8478. function rle8_decode ($str, $width){
  8479. $lineWidth = $width + (3 - ($width-1) % 4);
  8480. $out = '';
  8481. $cnt = strlen($str);
  8482. for ($i=0;$i<$cnt;$i++){
  8483. $o = ord($str{$i});
  8484. switch ($o){
  8485. case 0: # ESCAPE
  8486. $i++;
  8487. switch (ord($str{$i})){
  8488. case 0: # NEW LINE
  8489. $padCnt = $lineWidth - strlen($out)%$lineWidth;
  8490. if ($padCnt<$lineWidth) $out .= str_repeat(chr(0), $padCnt); # pad line
  8491. break;
  8492. case 1: # END OF FILE
  8493. $padCnt = $lineWidth - strlen($out)%$lineWidth;
  8494. if ($padCnt<$lineWidth) $out .= str_repeat(chr(0), $padCnt); # pad line
  8495. break 3;
  8496. case 2: # DELTA
  8497. $i += 2;
  8498. break;
  8499. default: # ABSOLUTE MODE
  8500. $num = ord($str{$i});
  8501. for ($j=0;$j<$num;$j++)
  8502. $out .= $str{++$i};
  8503. if ($num % 2) $i++;
  8504. }
  8505. break;
  8506. default:
  8507. $out .= str_repeat($str{++$i}, $o);
  8508. }
  8509. }
  8510. return $out;
  8511. }
  8512. // mPDF 4.5.011
  8513. # Decoder for RLE4 compression in windows bitmaps
  8514. # see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_6x0u.asp
  8515. function rle4_decode ($str, $width){
  8516. $w = floor($width/2) + ($width % 2);
  8517. $lineWidth = $w + (3 - ( ($width-1) / 2) % 4);
  8518. $pixels = array();
  8519. $cnt = strlen($str);
  8520. for ($i=0;$i<$cnt;$i++){
  8521. $o = ord($str{$i});
  8522. switch ($o){
  8523. case 0: # ESCAPE
  8524. $i++;
  8525. switch (ord($str{$i})){
  8526. case 0: # NEW LINE
  8527. while (count($pixels)%$lineWidth!=0)
  8528. $pixels[]=0;
  8529. break;
  8530. case 1: # END OF FILE
  8531. while (count($pixels)%$lineWidth!=0)
  8532. $pixels[]=0;
  8533. break 3;
  8534. case 2: # DELTA
  8535. $i += 2;
  8536. break;
  8537. default: # ABSOLUTE MODE
  8538. $num = ord($str{$i});
  8539. for ($j=0;$j<$num;$j++){
  8540. if ($j%2==0){
  8541. $c = ord($str{++$i});
  8542. $pixels[] = ($c & 240)>>4;
  8543. } else
  8544. $pixels[] = $c & 15;
  8545. }
  8546. if ($num % 2) $i++;
  8547. }
  8548. break;
  8549. default:
  8550. $c = ord($str{++$i});
  8551. for ($j=0;$j<$o;$j++)
  8552. $pixels[] = ($j%2==0 ? ($c & 240)>>4 : $c & 15);
  8553. }
  8554. }
  8555. $out = '';
  8556. if (count($pixels)%2) $pixels[]=0;
  8557. $cnt = count($pixels)/2;
  8558. for ($i=0;$i<$cnt;$i++)
  8559. $out .= chr(16*$pixels[2*$i] + $pixels[2*$i+1]);
  8560. return $out;
  8561. }
  8562. //==============================================================
  8563. // mPDF 4.5.011
  8564. function _fourbytes2int_le($s) {
  8565. //Read a 4-byte integer from string
  8566. return (ord($s[3])<<24) + (ord($s[2])<<16) + (ord($s[1])<<8) + ord($s[0]); // mPDF 4.4.012
  8567. }
  8568. //==============================================================
  8569. // mPDF 4.5.011
  8570. function _twobytes2int_le($s) {
  8571. //Read a 2-byte integer from string
  8572. return (ord(substr($s, 1, 1))<<8) + ord(substr($s, 0, 1));
  8573. }
  8574. // mPDF 4.2
  8575. function _fourbytes2int($s) {
  8576. //Read a 4-byte integer from string
  8577. return (ord($s[0])<<24) + (ord($s[1])<<16) + (ord($s[2])<<8) + ord($s[3]); // mPDF 4.4.012
  8578. }
  8579. //==============================================================
  8580. // mPDF 4.2
  8581. function _twobytes2int($s) {
  8582. //Read a 2-byte integer from string
  8583. return (ord(substr($s, 0, 1))<<8) + ord(substr($s, 1, 1));
  8584. }
  8585. //==============================================================
  8586. // mPDF 4.2
  8587. function _jpgHeaderFromString(&$data) {
  8588. $p = 4;
  8589. $p += $this->_twobytes2int(substr($data, $p, 2)); // Length of initial marker block
  8590. $marker = substr($data, $p, 2);
  8591. while($marker != chr(255).chr(192) && $marker != chr(255).chr(194) && $p<strlen($data)) {
  8592. // Start of frame marker (FFC0) or (FFC2) mPDF 4.4.004
  8593. $p += ($this->_twobytes2int(substr($data, $p+2, 2))) + 2; // Length of marker block
  8594. $marker = substr($data, $p, 2);
  8595. }
  8596. if ($marker != chr(255).chr(192) && $marker != chr(255).chr(194)) { return false; } // mPDF 4.4.004
  8597. return substr($data, $p+2, 10);
  8598. }
  8599. //==============================================================
  8600. // mPDF 4.2
  8601. function _jpgDataFromHeader($hdr) {
  8602. $bpc = ord(substr($hdr, 2, 1));
  8603. if (!$bpc) { $bpc = 8; }
  8604. $h = $this->_twobytes2int(substr($hdr, 3, 2));
  8605. $w = $this->_twobytes2int(substr($hdr, 5, 2));
  8606. $channels = ord(substr($hdr, 7, 1));
  8607. if ($channels==3) { $colspace='DeviceRGB'; }
  8608. elseif($channels==4) { $colspace='DeviceCMYK'; }
  8609. else { $colspace='DeviceGray'; }
  8610. return array($w, $h, $colspace, $bpc);
  8611. }
  8612. //==============================================================
  8613. // mPDF 4.2
  8614. function file_get_contents_by_curl($url, &$data) {
  8615. $timeout = 5;
  8616. $ch = curl_init($url);
  8617. curl_setopt($ch, CURLOPT_HEADER, 0);
  8618. curl_setopt($ch, CURLOPT_NOBODY, 0);
  8619. curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
  8620. curl_setopt ( $ch , CURLOPT_CONNECTTIMEOUT , $timeout );
  8621. $data = curl_exec($ch);
  8622. curl_close($ch);
  8623. }
  8624. //==============================================================
  8625. // mPDF 4.2
  8626. function file_get_contents_by_socket($url, &$data) {
  8627. $timeout = 1;
  8628. $p = parse_url($url);
  8629. $file = $p['path'];
  8630. if ($p['query']) { $file .= '?'.$p['query']; }
  8631. if(!($fh = @fsockopen($p['host'], 80, $errno, $errstr, $timeout))) { return false; }
  8632. $getstring =
  8633. "GET ".$file." HTTP/1.0 \r\n" .
  8634. "Host: ".$p['host']." \r\n" .
  8635. "Connection: close\r\n\r\n";
  8636. fwrite($fh, $getstring);
  8637. // Get rid of HTTP header
  8638. $s = fgets($fh, 1024);
  8639. if (!$s) { return false; }
  8640. $httpheader .= $s;
  8641. while (!feof($fh)) {
  8642. $s = fgets($fh, 1024);
  8643. if ( $s == "\r\n" ) { break; }
  8644. }
  8645. $data = '';
  8646. while (!feof($fh)) {
  8647. $data .= fgets($fh, 1024);
  8648. }
  8649. fclose($fh);
  8650. }
  8651. //==============================================================
  8652. // mPDF 4.2
  8653. function _imageTypeFromString(&$data) {
  8654. $type = '';
  8655. if (substr($data, 6, 4)== 'JFIF' || substr($data, 6, 4)== 'Exif') { // mPDF 4.5.001
  8656. $type = 'jpeg';
  8657. }
  8658. else if (substr($data, 0, 6)== "GIF87a" || substr($data, 0, 6)== "GIF89a") {
  8659. $type = 'gif';
  8660. }
  8661. else if (substr($data, 0, 8)== chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  8662. $type = 'png';
  8663. }
  8664. /*-- IMAGES-WMF --*/
  8665. else if (substr($data, 0, 4)== chr(215).chr(205).chr(198).chr(154)) {
  8666. $type = 'wmf';
  8667. }
  8668. /*-- END IMAGES-WMF --*/
  8669. // mPDF 4.3.013 SVG files
  8670. else if (preg_match('/<svg.*<\/svg>/is',$data)) {
  8671. $type = 'svg';
  8672. }
  8673. // mPDF 4.5.011 BMP images
  8674. else if (substr($data, 0, 2)== "BM") {
  8675. $type = 'bmp';
  8676. }
  8677. return $type;
  8678. }
  8679. //==============================================================
  8680. /*-- IMAGES-WMF --*/
  8681. // WMF functions
  8682. function _MoveTo($x, $y) {
  8683. return "$x $y m\n";
  8684. }
  8685. // a line must have been started using _MoveTo() first
  8686. function _LineTo($x, $y) {
  8687. return "$x $y l\n";
  8688. }
  8689. function _AddGDIObject($obj) {
  8690. // find next available slot
  8691. $idx = 0;
  8692. if (!empty($this->gdiObjectArray)) {
  8693. $empty = false;
  8694. $i = 0;
  8695. while (!$empty) {
  8696. $empty = !isset($this->gdiObjectArray[$i]);
  8697. $i++;
  8698. }
  8699. $idx = $i-1;
  8700. }
  8701. $this->gdiObjectArray[$idx] = $obj;
  8702. }
  8703. function _GetGDIObject($idx) {
  8704. return $this->gdiObjectArray[$idx];
  8705. }
  8706. function _DeleteGDIObject($idx) {
  8707. unset($this->gdiObjectArray[$idx]);
  8708. }
  8709. // END of WMF functions
  8710. /*-- END IMAGES-WMF --*/
  8711. // mPDF 4.3.013 SVG files
  8712. // Moved outside WMF as also needed for SVG
  8713. function _putformobjects() {
  8714. reset($this->formobjects);
  8715. while(list($file,$info)=each($this->formobjects)) {
  8716. $this->_newobj();
  8717. $this->formobjects[$file]['n']=$this->n;
  8718. $this->_out('<</Type /XObject');
  8719. $this->_out('/Subtype /Form');
  8720. $this->_out('/Group '.($this->n+1).' 0 R'); // mPDF 4.3.017
  8721. $this->_out('/BBox ['.$info['x'].' '.$info['y'].' '.($info['w']+$info['x']).' '.($info['h']+$info['y']).']');
  8722. if ($this->compress)
  8723. $this->_out('/Filter /FlateDecode');
  8724. $data=($this->compress) ? gzcompress($info['data']) : $info['data'];
  8725. $this->_out('/Length '.strlen($data).'>>');
  8726. $this->_putstream($data);
  8727. unset($this->formobjects[$file]['data']);
  8728. $this->_out('endobj');
  8729. // mPDF 4.3.017 Required for SVG transparency (opacity) to work
  8730. $this->_newobj();
  8731. $this->_out('<</Type /Group');
  8732. $this->_out('/S /Transparency');
  8733. $this->_out('>>');
  8734. $this->_out('endobj');
  8735. }
  8736. }
  8737. function _freadint($f)
  8738. {
  8739. //Read a 4-byte integer from file
  8740. $i=$this->ords[fread($f,1)]<<24;
  8741. $i+=$this->ords[fread($f,1)]<<16;
  8742. $i+=$this->ords[fread($f,1)]<<8;
  8743. $i+=$this->ords[fread($f,1)];
  8744. return $i;
  8745. }
  8746. function _UTF16BEtextstring($s) {
  8747. $s = $this->UTF8ToUTF16BE($s, true);
  8748. /*-- ENCRYPTION --*/
  8749. if ($this->encrypted) {
  8750. $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s); // mPDF 4.2.006
  8751. }
  8752. /*-- END ENCRYPTION --*/
  8753. return '('. $this->_escape($s).')';
  8754. }
  8755. function _textstring($s) {
  8756. /*-- ENCRYPTION --*/
  8757. if ($this->encrypted) {
  8758. $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s); // mPDF 4.2.006
  8759. }
  8760. /*-- END ENCRYPTION --*/
  8761. return '('. $this->_escape($s).')';
  8762. }
  8763. function _escape($s)
  8764. {
  8765. // the chr(13) substitution fixes the Bugs item #1421290.
  8766. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', $this->chrs[13] => '\r'));
  8767. }
  8768. function _putstream($s) {
  8769. /*-- ENCRYPTION --*/
  8770. if ($this->encrypted) {
  8771. $s = $this->_RC4($this->_objectkey($this->_current_obj_id), $s); // mPDF 4.2.006
  8772. }
  8773. /*-- END ENCRYPTION --*/
  8774. $this->_out('stream');
  8775. $this->_out($s);
  8776. $this->_out('endstream');
  8777. }
  8778. function _out($s,$ln=true) {
  8779. if($this->state==2) {
  8780. if ($this->bufferoutput) {
  8781. $this->headerbuffer.= $s."\n";
  8782. }
  8783. /*-- COLUMNS --*/
  8784. else if (($this->ColActive) && (!$this->processingHeader) && (!$this->processingFooter)) {
  8785. // Captures everything in buffer for columns; Almost everything is sent from fn. Cell() except:
  8786. // Images sent from Image() or
  8787. // later sent as _out($textto) in printbuffer
  8788. // Line()
  8789. 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 // mPDF 4.5.007
  8790. $h = ($m[1]/$this->k);
  8791. // Update/overwrite the lowest bottom of printing y value for a column
  8792. $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y+$h;
  8793. }
  8794. /*-- TABLES --*/
  8795. 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
  8796. $h = ($m[1]/$this->k);
  8797. // Update/overwrite the lowest bottom of printing y value for a column
  8798. $this->ColDetails[$this->CurrCol]['bottom_margin'] = max($this->ColDetails[$this->CurrCol]['bottom_margin'],($this->y+$h));
  8799. }
  8800. /*-- END TABLES --*/
  8801. else { // Td Text Set in Cell()
  8802. if (isset($this->ColDetails[$this->CurrCol]['bottom_margin'])) { $h = $this->ColDetails[$this->CurrCol]['bottom_margin'] - $this->y; }
  8803. else { $h = 0; }
  8804. }
  8805. if ($h < 0) { $h = -$h; }
  8806. $this->columnbuffer[] = array(
  8807. 's' => $s, // Text string to output
  8808. 'col' => $this->CurrCol, // Column when printed
  8809. 'x' => $this->x, // x when printed
  8810. 'y' => $this->y, // this->y when printed (after column break)
  8811. 'h' => $h // actual y at bottom when printed = y+h
  8812. );
  8813. }
  8814. /*-- END COLUMNS --*/
  8815. /*-- TABLES --*/
  8816. else if ($this->table_rotate && !$this->processingHeader && !$this->processingFooter) {
  8817. // Captures eveything in buffer for rotated tables;
  8818. $this->tablebuffer[] = array(
  8819. 's' => $s, // Text string to output
  8820. 'x' => $this->x, // x when printed
  8821. 'y' => $this->y, // y when printed (after column break)
  8822. );
  8823. }
  8824. /*-- END TABLES --*/
  8825. else if ($this->kwt && !$this->processingHeader && !$this->processingFooter) {
  8826. // Captures eveything in buffer for keep-with-table (h1-6);
  8827. $this->kwt_buffer[] = array(
  8828. 's' => $s, // Text string to output
  8829. 'x' => $this->x, // x when printed
  8830. 'y' => $this->y, // y when printed
  8831. );
  8832. }
  8833. else if (($this->keep_block_together) && (!$this->processingHeader) && (!$this->processingFooter)) {
  8834. // mPDF 4.5.007
  8835. if (!isset($this->ktBlock[$this->page]['bottom_margin'])) {
  8836. $this->ktBlock[$this->page]['bottom_margin'] = $this->y;
  8837. }
  8838. // Captures eveything in buffer;
  8839. 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 // mPDF 4.5.007
  8840. $h = ($m[1]/$this->k);
  8841. // Update/overwrite the lowest bottom of printing y value for Keep together block
  8842. $this->ktBlock[$this->page]['bottom_margin'] = $this->y+$h;
  8843. }
  8844. else { // Td Text Set in Cell()
  8845. if (isset($this->ktBlock[$this->page]['bottom_margin'])) { $h = $this->ktBlock[$this->page]['bottom_margin'] - $this->y; }
  8846. else { $h = 0; }
  8847. }
  8848. if ($h < 0) { $h = -$h; }
  8849. $this->divbuffer[] = array(
  8850. 'page' => $this->page,
  8851. 's' => $s, // Text string to output
  8852. 'x' => $this->x, // x when printed
  8853. 'y' => $this->y, // y when printed (after column break)
  8854. 'h' => $h // actual y at bottom when printed = y+h
  8855. );
  8856. }
  8857. else {
  8858. $this->pages[$this->page] .= $s.($ln == true ? "\n" : '');
  8859. }
  8860. }
  8861. else {
  8862. $this->buffer .= $s.($ln == true ? "\n" : '');
  8863. }
  8864. }
  8865. /*-- WATERMARK --*/
  8866. // add a watermark
  8867. function watermark( $texte, $angle=45, $fontsize=96, $alpha=0.2 )
  8868. {
  8869. if ($this->PDFA) { $this->Error('PDFA does not permit transparency, so mPDF does not allow Watermarks!'); } // mPDF 4.2.018
  8870. if (!$this->watermark_font) { $this->watermark_font = $this->default_font; }
  8871. $this->SetFont( $this->watermark_font, "B", $fontsize, false ); // Don't output
  8872. $texte= $this->purify_utf8_text($texte);
  8873. if ($this->text_input_as_HTML) {
  8874. $texte= $this->all_entities_to_utf8($texte);
  8875. }
  8876. // Modified by Ivan Tcholakov, 28-JAN-2010.
  8877. //if (!$this->is_MB) { $texte = mb_convert_encoding($texte,$this->mb_enc,'UTF-8'); }
  8878. if (!$this->is_MB) { $texte = api_convert_encoding($texte,$this->mb_enc,'UTF-8'); }
  8879. //
  8880. // DIRECTIONALITY
  8881. $this->magic_reverse_dir($texte); // *RTL*
  8882. // mPDF 4.0 Font-specific ligature substitution for Indic fonts
  8883. $this->ConvertIndic($texte); // *INDIC*
  8884. $this->SetAlpha($alpha);
  8885. $this->SetTextColor(0);
  8886. $szfont = $fontsize;
  8887. $loop = 0;
  8888. $maxlen = (min($this->w,$this->h) ); // sets max length of text as 7/8 width/height of page
  8889. while ( $loop == 0 )
  8890. {
  8891. $this->SetFont( $this->watermark_font, "B", $szfont, false ); // Don't output
  8892. $offset = ((sin(deg2rad($angle))) * ($szfont/$this->k));
  8893. $strlen = $this->GetStringWidth($texte);
  8894. if ( $strlen > $maxlen - $offset )
  8895. $szfont --;
  8896. else
  8897. $loop ++;
  8898. }
  8899. $this->SetFont( $this->watermark_font, "B", $szfont-0.1, true, true); // Output The -0.1 is because SetFont above is not written to PDF
  8900. // Repeating it will not output anything as mPDF thinks it is set
  8901. $adj = ((cos(deg2rad($angle))) * ($strlen/2));
  8902. $opp = ((sin(deg2rad($angle))) * ($strlen/2));
  8903. $wx = ($this->w/2) - $adj + $offset/3;
  8904. $wy = ($this->h/2) + $opp;
  8905. $this->Rotate($angle,$wx,$wy);
  8906. $this->Text($wx,$wy,$texte);
  8907. $this->Rotate(0);
  8908. $this->SetTextColor(0,0,0);
  8909. $this->SetAlpha(1);
  8910. }
  8911. // add a watermark Image
  8912. function watermarkImg( $src, $alpha=0.2 ) {
  8913. if ($this->PDFA) { $this->Error('PDFA does not permit transparency, so mPDF does not allow Watermarks!'); } // mPDF 4.2.018
  8914. // mPDF 4.3.018
  8915. if ($this->watermarkImgBehind) { $this->watermarkImgAlpha = $this->SetAlpha($alpha, 'Normal', true); }
  8916. else { $this->SetAlpha($alpha, $this->watermarkImgAlphaBlend); } // mPDF 4.4.002
  8917. $this->Image($src,0,0,0,0,'','', true, true, true);
  8918. // mPDF 4.3.018
  8919. if (!$this->watermarkImgBehind) { $this->SetAlpha(1); }
  8920. }
  8921. /*-- END WATERMARK --*/
  8922. function Rotate($angle,$x=-1,$y=-1)
  8923. {
  8924. if($x==-1)
  8925. $x=$this->x;
  8926. if($y==-1)
  8927. $y=$this->y;
  8928. if($this->angle!=0)
  8929. $this->_out('Q');
  8930. $this->angle=$angle;
  8931. if($angle!=0)
  8932. {
  8933. $angle*=M_PI/180;
  8934. $c=cos($angle);
  8935. $s=sin($angle);
  8936. $cx=$x*$this->k;
  8937. $cy=($this->h-$y)*$this->k;
  8938. $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));
  8939. }
  8940. }
  8941. // From Invoice
  8942. function RoundedRect($x, $y, $w, $h, $r, $style = '')
  8943. {
  8944. $k = $this->k;
  8945. $hp = $this->h;
  8946. if($style=='F')
  8947. $op='f';
  8948. elseif($style=='FD' or $style=='DF')
  8949. $op='B';
  8950. else
  8951. $op='S';
  8952. $MyArc = 4/3 * (sqrt(2) - 1);
  8953. $this->_out(sprintf('%.3f %.3f m',($x+$r)*$k,($hp-$y)*$k ));
  8954. $xc = $x+$w-$r ;
  8955. $yc = $y+$r;
  8956. $this->_out(sprintf('%.3f %.3f l', $xc*$k,($hp-$y)*$k ));
  8957. $this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc);
  8958. $xc = $x+$w-$r ;
  8959. $yc = $y+$h-$r;
  8960. $this->_out(sprintf('%.3f %.3f l',($x+$w)*$k,($hp-$yc)*$k));
  8961. $this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r);
  8962. $xc = $x+$r ;
  8963. $yc = $y+$h-$r;
  8964. $this->_out(sprintf('%.3f %.3f l',$xc*$k,($hp-($y+$h))*$k));
  8965. $this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc);
  8966. $xc = $x+$r ;
  8967. $yc = $y+$r;
  8968. $this->_out(sprintf('%.3f %.3f l',($x)*$k,($hp-$yc)*$k ));
  8969. $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
  8970. $this->_out($op);
  8971. }
  8972. function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
  8973. {
  8974. $h = $this->h;
  8975. $this->_out(sprintf('%.3f %.3f %.3f %.3f %.3f %.3f c ', $x1*$this->k, ($h-$y1)*$this->k,
  8976. $x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k));
  8977. }
  8978. /*-- GRADIENTS --*/
  8979. // mPDF 3.0 added - GRADIENTS
  8980. // type = linear:2; radial: 3;
  8981. // Linear: $coords - array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg).
  8982. // The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
  8983. // Radial: $coords - array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1,
  8984. // (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg).
  8985. // (fx, fy) should be inside the circle, otherwise some areas will not be defined
  8986. // $col = array(R,G,B); or array(G)
  8987. function Gradient($x, $y, $w, $h, $type, $col1=array(), $col2=array(), $coords='', $extend='', $return=false) {
  8988. if (strtoupper(substr($type,0,1)) == 'L') { $type = 2; }
  8989. else if (strtoupper(substr($type,0,1)) == 'R') { $type = 3; }
  8990. if ($type < 1) { $type = 2; }
  8991. if (!isset($col1[1])) { $col1[1]=$col1[2]=$col1[0]; }
  8992. if (!isset($col2[1])) { $col2[1] = $col2[2] = $col2[0]; }
  8993. if (!is_array($coords) || count($coords) <1) {
  8994. if ($type == 2) { $coords=array(0,0,1,0); }
  8995. else { $coords=array(0.5,0.5,0.5,0.5,1); }
  8996. }
  8997. if (!is_array($extend) || count($extend) <1) {
  8998. $extend=array('true', 'true'); // These are supposed to be quoted - appear in PDF file as text
  8999. }
  9000. $s = ' q';
  9001. $s .= sprintf(' %.3F %.3F %.3F %.3F re W n', $x*$this->k, ($this->h-$y)*$this->k, $w*$this->k, -$h*$this->k)."\n";
  9002. $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k)."\n";
  9003. $n = count($this->gradients) + 1;
  9004. $this->gradients[$n]['type'] = $type;
  9005. $this->gradients[$n]['col1'] = sprintf('%.3F %.3F %.3F', ($col1[0]/255), ($col1[1]/255), ($col1[2]/255));
  9006. $this->gradients[$n]['col2'] = sprintf('%.3F %.3F %.3F', ($col2[0]/255), ($col2[1]/255), ($col2[2]/255));
  9007. $this->gradients[$n]['coords'] = $coords;
  9008. $this->gradients[$n]['extend'] = $extend;
  9009. //paint the gradient
  9010. $s .= '/Sh'.$n.' sh '."\n";
  9011. //restore previous Graphic State
  9012. $s .= ' Q '."\n";
  9013. if ($return) { return $s; }
  9014. else { $this->_out($s); }
  9015. }
  9016. /*-- END GRADIENTS --*/
  9017. //====================================================
  9018. /*-- DIRECTW --*/
  9019. function Shaded_box( $text,$font='',$fontstyle='B',$szfont='',$width='70%',$style='DF',$radius=2.5,$fill='#FFFFFF',$color='#000000',$pad=2 )
  9020. {
  9021. // F (shading - no line),S (line, no shading),DF (both)
  9022. if (!$font) { $font= $this->default_font; }
  9023. if (!$szfont) { $szfont = ($this->default_font_size * 1.8); }
  9024. $text = $this->purify_utf8_text($text);
  9025. if ($this->text_input_as_HTML) {
  9026. $text = $this->all_entities_to_utf8($text);
  9027. }
  9028. // Modified by Ivan Tcholakov, 28-JAN-2010.
  9029. //if (!$this->is_MB) { $text = mb_convert_encoding($text,$this->mb_enc,'UTF-8'); }
  9030. if (!$this->is_MB) { $text = api_convert_encoding($text,$this->mb_enc,'UTF-8'); }
  9031. //
  9032. // DIRECTIONALITY
  9033. $this->magic_reverse_dir($text); // *RTL*
  9034. // mPDF 4.0 Font-specific ligature substitution for Indic fonts
  9035. $this->ConvertIndic($text); // *INDIC*
  9036. $text = ' '.$text.' ';
  9037. if (!$width) { $width = $this->pgwidth; } else { $width=$this->ConvertSize($width,$this->pgwidth); }
  9038. $midpt = $this->lMargin+($this->pgwidth/2);
  9039. $r1 = $midpt-($width/2); //($this->w / 2) - 40;
  9040. $r2 = $r1 + $width; //$r1 + 80;
  9041. $y1 = $this->y;
  9042. $mid = ($r1 + $r2 ) / 2;
  9043. $loop = 0;
  9044. while ( $loop == 0 )
  9045. {
  9046. $this->SetFont( $font, $fontstyle, $szfont );
  9047. $sz = $this->GetStringWidth( $text );
  9048. if ( ($r1+$sz) > $r2 )
  9049. $szfont --;
  9050. else
  9051. $loop ++;
  9052. }
  9053. $y2 = $this->FontSize+($pad*2);
  9054. $this->SetLineWidth(0.1);
  9055. $fc = $this->ConvertColor($fill);
  9056. $tc = $this->ConvertColor($color);
  9057. $this->SetFillColor($fc['R'],$fc['G'],$fc['B']);
  9058. $this->SetTextColor($tc['R'],$tc['G'],$tc['B']);
  9059. $this->RoundedRect($r1, $y1, ($r2 - $r1), $y2, $radius, $style);
  9060. $this->SetX( $r1);
  9061. $this->Cell($r2-$r1, $y2, $text, 0, 1, "C" );
  9062. $this->SetY($y1+$y2+2); // +2 = mm margin below shaded box
  9063. $this->Reset();
  9064. }
  9065. /*-- END DIRECTW --*/
  9066. // mPDF 4.4.012
  9067. function UTF8StringToArray($str) {
  9068. $out = array();
  9069. $len = strlen($str);
  9070. for ($i = 0; $i < $len; $i++) {
  9071. $h = ord($str[$i]);
  9072. if ( $h <= 0x7F )
  9073. $out[] = $h;
  9074. elseif ( $h >= 0xC2 ) {
  9075. if ( ($h <= 0xDF) && ($i < $len -1) )
  9076. $out[] = ($h & 0x1F) << 6 | (ord($str{++$i}) & 0x3F);
  9077. elseif ( ($h <= 0xEF) && ($i < $len -2) )
  9078. $out[] = ($h & 0x0F) << 12 | (ord($str{++$i}) & 0x3F) << 6
  9079. | (ord($str{++$i}) & 0x3F);
  9080. elseif ( ($h <= 0xF4) && ($i < $len -3) )
  9081. $out[] = ($h & 0x0F) << 18 | (ord($str{++$i}) & 0x3F) << 12
  9082. | (ord($str{++$i}) & 0x3F) << 6
  9083. | (ord($str{++$i}) & 0x3F);
  9084. }
  9085. }
  9086. return $out;
  9087. }
  9088. // mPDF 4.0 Convert utf-8 string to <HHHHHH> for Font Subsets
  9089. function UTF8toSubset($str) {
  9090. $ret = '<';
  9091. // mPDF 4.0
  9092. $str = preg_replace('/'.preg_quote($this->aliasNbPg,'/').'/', chr(7), $str );
  9093. $str = preg_replace('/'.preg_quote($this->aliasNbPgGp,'/').'/', chr(8), $str );
  9094. $unicode = $this->UTF8StringToArray($str);
  9095. $orig_fid = $this->CurrentFont['subsetfontids'][0];
  9096. $last_fid = $this->CurrentFont['subsetfontids'][0];
  9097. foreach($unicode as $c) {
  9098. // mPDF 4.0
  9099. if ($c == 7 || $c == 8) {
  9100. if ($orig_fid != $last_fid) {
  9101. $ret .= '> Tj /F'.$orig_fid.' '.$this->FontSizePt.' Tf <';
  9102. $last_fid = $orig_fid;
  9103. }
  9104. if ($c == 7) { $ret .= $this->aliasNbPg; }
  9105. else { $ret .= $this->aliasNbPgGp; }
  9106. continue;
  9107. }
  9108. for ($i=0; $i<99; $i++) {
  9109. // return c as decimal char
  9110. $init = array_search($c, $this->CurrentFont['subsets'][$i]);
  9111. if ($init!==false) {
  9112. if ($this->CurrentFont['subsetfontids'][$i] != $last_fid) {
  9113. $ret .= '> Tj /F'.$this->CurrentFont['subsetfontids'][$i].' '.$this->FontSizePt.' Tf <';
  9114. $last_fid = $this->CurrentFont['subsetfontids'][$i];
  9115. }
  9116. $ret .= sprintf("%02s", strtoupper(dechex($init)));
  9117. break;
  9118. }
  9119. else if (count($this->CurrentFont['subsets'][$i]) < 255) {
  9120. $n = count($this->CurrentFont['subsets'][$i]);
  9121. $this->CurrentFont['subsets'][$i][$n] = $c;
  9122. if ($this->CurrentFont['subsetfontids'][$i] != $last_fid) {
  9123. $ret .= '> Tj /F'.$this->CurrentFont['subsetfontids'][$i].' '.$this->FontSizePt.' Tf <';
  9124. $last_fid = $this->CurrentFont['subsetfontids'][$i];
  9125. }
  9126. $ret .= sprintf("%02s", strtoupper(dechex($n)));
  9127. break;
  9128. }
  9129. else if (!isset($this->CurrentFont['subsets'][($i+1)])) {
  9130. $this->CurrentFont['subsets'][($i+1)] = range(0,32);
  9131. $new_fid = count($this->fonts)+$this->extraFontSubsets+1;
  9132. $this->CurrentFont['subsetfontids'][($i+1)] = $new_fid;
  9133. $this->extraFontSubsets++;
  9134. }
  9135. }
  9136. }
  9137. $ret .= '>';
  9138. if ($last_fid != $orig_fid) {
  9139. $ret .= ' Tj /F'.$orig_fid.' '.$this->FontSizePt.' Tf <> ';
  9140. }
  9141. return $ret;
  9142. }
  9143. // Converts UTF-8 strings to UTF16-BE.
  9144. function UTF8ToUTF16BE($str, $setbom=true) {
  9145. $outstr = ""; // string to be returned
  9146. if ($setbom) {
  9147. $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
  9148. }
  9149. // Modified by Ivan Tcholakov, 28-JAN-2010.
  9150. //$outstr .= mb_convert_encoding($str, 'UTF-16BE', 'UTF-8');
  9151. $outstr .= api_convert_encoding($str, 'UTF-16BE', 'UTF-8');
  9152. //
  9153. return $outstr;
  9154. }
  9155. function _getfontpath() {
  9156. // mPDF 4.0 Depracated. Use MPDF_FONTPATH
  9157. return defined('MPDF_FONTPATH') ? MPDF_FONTPATH : '';
  9158. }
  9159. // ====================================================
  9160. // ====================================================
  9161. /*-- CJK --*/
  9162. // from class PDF_Chinese CJK EXTENSIONS
  9163. function AddCIDFont($family,$style,$name,$cw,$CMap,$registry,$desc)
  9164. {
  9165. $fontkey=strtolower($family).strtoupper($style);
  9166. if(isset($this->fonts[$fontkey]))
  9167. $this->Error("Font already added: $family $style");
  9168. $i=count($this->fonts)+$this->extraFontSubsets+1;
  9169. $name=str_replace(' ','',$name);
  9170. if ($family == 'sjis') { $up = -120; } else { $up = -130; }
  9171. // ? 'up' and 'ut' do not seem to be referenced anywhere
  9172. $this->fonts[$fontkey]=array('i'=>$i,'type'=>'Type0','name'=>$name,'up'=>$up,'ut'=>40,'cw'=>$cw,'CMap'=>$CMap,'registry'=>$registry,'MissingWidth'=>1000,'desc'=>$desc);
  9173. }
  9174. function AddCJKFont($family) {
  9175. // mPDF 4.2.018
  9176. if ($this->PDFA) {
  9177. $this->Error("Adobe CJK fonts cannot be embedded in mPDF (required for PDFA1-b).");
  9178. }
  9179. if ($family == 'big5') { $this->AddBig5Font(); }
  9180. else if ($family == 'gb') { $this->AddGBFont(); }
  9181. else if ($family == 'sjis') { $this->AddSJISFont(); }
  9182. else if ($family == 'uhc') { $this->AddUHCFont(); }
  9183. }
  9184. function AddBig5Font()
  9185. {
  9186. //Add Big5 font with proportional Latin
  9187. $family='big5';
  9188. $name='MSungStd-Light-Acro';
  9189. $cw=$this->Big5_widths;
  9190. //$CMap='ETenms-B5-H';
  9191. $CMap='UniCNS-UTF16-H';
  9192. $desc = array(
  9193. 'Ascent' => 880,
  9194. 'Descent' => -120,
  9195. 'CapHeight' => 880,
  9196. 'Flags' => 6,
  9197. 'FontBBox' => '[-160 -249 1015 1071]',
  9198. 'ItalicAngle' => 0,
  9199. 'StemV' => 93,
  9200. );
  9201. $registry=array('ordering'=>'CNS1','supplement'=>0);
  9202. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9203. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9204. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9205. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9206. }
  9207. function AddGBFont()
  9208. {
  9209. //Add GB font with proportional Latin
  9210. $family='gb';
  9211. $name='STSongStd-Light-Acro';
  9212. $cw=$this->GB_widths;
  9213. //$CMap='GBKp-EUC-H';
  9214. $CMap='UniGB-UTF16-H';
  9215. $registry=array('ordering'=>'GB1','supplement'=>2);
  9216. $desc = array(
  9217. 'Ascent' => 752,
  9218. 'Descent' => -271,
  9219. 'CapHeight' => 737,
  9220. 'Flags' => 6,
  9221. 'FontBBox' => '[-25 -254 1000 880]',
  9222. 'ItalicAngle' => 0,
  9223. 'StemV' => 58,
  9224. 'Style' => '<< /Panose <000000000400000000000000> >>',
  9225. );
  9226. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9227. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9228. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9229. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9230. }
  9231. function AddSJISFont()
  9232. {
  9233. //Add SJIS font with proportional Latin
  9234. $family='sjis';
  9235. $name='KozMinPro-Regular-Acro';
  9236. $cw=$this->SJIS_widths;
  9237. //$CMap='90msp-RKSJ-H';
  9238. $CMap='UniJIS-UTF16-H';
  9239. $desc = array(
  9240. 'Ascent' => 880,
  9241. 'Descent' => -120,
  9242. 'CapHeight' => 740,
  9243. 'Flags' => 6,
  9244. 'FontBBox' => '[-195 -272 1110 1075]',
  9245. 'ItalicAngle' => 0,
  9246. 'StemV' => 86,
  9247. 'XHeight' => 502,
  9248. );
  9249. $registry=array('ordering'=>'Japan1','supplement'=>2);
  9250. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9251. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9252. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9253. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9254. }
  9255. function AddUHCFont()
  9256. {
  9257. //Add UHC font with proportional Latin
  9258. $family='uhc';
  9259. $name='HYSMyeongJoStd-Medium-Acro';
  9260. $cw=$this->UHC_widths;
  9261. //$CMap='KSCms-UHC-H';
  9262. $CMap='UniKS-UTF16-H';
  9263. $registry=array('ordering'=>'Korea1','supplement'=>1);
  9264. $desc = array(
  9265. 'Ascent' => 880,
  9266. 'Descent' => -120,
  9267. 'CapHeight' => 720,
  9268. 'Flags' => 6,
  9269. 'FontBBox' => '[-28 -148 1001 880]',
  9270. 'ItalicAngle' => 0,
  9271. 'StemV' => 60,
  9272. 'Style' => '<< /Panose <000000000600000000000000> >>',
  9273. );
  9274. $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry,$desc);
  9275. $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry,$desc);
  9276. $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry,$desc);
  9277. $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry,$desc);
  9278. }
  9279. /*-- END CJK --*/
  9280. //////////////////////////////////////////////////////////////////////////////
  9281. //////////////////////////////////////////////////////////////////////////////
  9282. //////////////////////////////////////////////////////////////////////////////
  9283. //////////////////////////////////////////////////////////////////////////////
  9284. //////////////////////////////////////////////////////////////////////////////
  9285. //////////////////////////////////////////////////////////////////////////////
  9286. //////////////////////////////////////////////////////////////////////////////
  9287. function SetAutoFont($af = AUTOFONT_ALL) {
  9288. if (!$this->is_MB) { return false; }
  9289. if (!$af && $af !== 0) { $af = AUTOFONT_ALL; }
  9290. $this->autoFontGroups = $af;
  9291. if ($this->autoFontGroups ) {
  9292. $this->useSubstitutions = false;
  9293. $this->useLang = true;
  9294. // mPDF 4.0
  9295. if (AUTOFONT_RTL & $this->autoFontGroups) { $this->biDirectional = true; } // *RTL*
  9296. }
  9297. }
  9298. function SetDefaultFont($font) {
  9299. // Disallow embedded fonts to be used as defaults except in win-1252
  9300. if ($this->codepage != 'win-1252' || $this->PDFA) { // mPDF 4.2.018
  9301. if (strtolower($font) == 'times') { $font = 'serif'; }
  9302. if (strtolower($font) == 'courier') { $font = 'monospace'; }
  9303. if ((strtolower($font) == 'arial') || (strtolower($font) == 'helvetica')) { $font = 'sans-serif'; }
  9304. }
  9305. $font = $this->SetFont($font); // returns substituted font if necessary
  9306. $this->default_font = $font;
  9307. $this->original_default_font = $font;
  9308. if (!$this->watermark_font ) { $this->watermark_font = $font; } // *WATERMARK*
  9309. $this->defaultCSS['BODY']['FONT-FAMILY'] = $font; // mPDF 4.2
  9310. $this->CSS['BODY']['FONT-FAMILY'] = $font; // mPDF 4.2
  9311. }
  9312. function SetDefaultFontSize($fontsize) {
  9313. $this->default_font_size = $fontsize;
  9314. $this->original_default_font_size = $fontsize;
  9315. $this->SetFontSize($fontsize);
  9316. $this->defaultCSS['BODY']['FONT-SIZE'] = $fontsize . 'pt';
  9317. $this->CSS['BODY']['FONT-SIZE'] = $fontsize . 'pt'; // mPDF 4.2
  9318. }
  9319. // mPDF 4.2
  9320. function SetDefaultBodyCSS($prop, $val) {
  9321. if ($prop) {
  9322. $this->defaultCSS['BODY'][strtoupper($prop)] = $val;
  9323. $this->CSS['BODY'][strtoupper($prop)] = $val;
  9324. }
  9325. }
  9326. function SetDirectionality($dir='ltr') {
  9327. /*-- RTL --*/
  9328. if (strtolower($dir) == 'rtl') {
  9329. $this->directionality = 'rtl';
  9330. $this->defaultAlign = 'R';
  9331. $this->defaultTableAlign = 'R';
  9332. // Swop L/R Margins so page 1 RTL is an 'even' page
  9333. $tmp = $this->DeflMargin;
  9334. $this->DeflMargin = $this->DefrMargin;
  9335. $this->DefrMargin = $tmp;
  9336. $this->orig_lMargin = $this->DeflMargin;
  9337. $this->orig_rMargin = $this->DefrMargin;
  9338. $this->SetMargins($this->DeflMargin,$this->DefrMargin,$this->tMargin);
  9339. }
  9340. else {
  9341. /*-- END RTL --*/
  9342. $this->directionality = 'ltr';
  9343. $this->defaultAlign = 'L';
  9344. $this->defaultTableAlign = 'L';
  9345. } // *RTL*
  9346. }
  9347. function reverse_align(&$align) {
  9348. if (strtolower($align) == 'right') { $align = 'left'; }
  9349. else if (strtolower($align) == 'left') { $align = 'right'; }
  9350. if (strtoupper($align) == 'R') { $align = 'L'; }
  9351. else if (strtoupper($align) == 'L') { $align = 'R'; }
  9352. }
  9353. // Added to set line-height-correction
  9354. function SetLineHeightCorrection($val) {
  9355. if ($val > 0) { $this->default_lineheight_correction = $val; }
  9356. else { $this->default_lineheight_correction = 1.2; }
  9357. }
  9358. // Set a (fixed) lineheight to an actual value - either to named fontsize(pts) or default
  9359. // mPDF 4.2
  9360. function SetLineHeight($FontPt='',$spacing = '') {
  9361. if ($this->shrin_k > 1) { $k = $this->shrin_k; }
  9362. else { $k = 1; }
  9363. if ($spacing > 0) {
  9364. if (preg_match('/mm/',$spacing)) {
  9365. $this->lineheight = ($spacing + 0.0) / $k; // convert to number
  9366. }
  9367. else {
  9368. if ($FontPt) { $this->lineheight = (($FontPt/$this->k) *$spacing); }
  9369. else { $this->lineheight = (($this->FontSizePt/$this->k) *$spacing); }
  9370. }
  9371. }
  9372. else {
  9373. if ($FontPt) { $this->lineheight = (($FontPt/$this->k) *$this->normalLineheight); }
  9374. else { $this->lineheight = (($this->FontSizePt/$this->k) *$this->normalLineheight); }
  9375. }
  9376. }
  9377. // mPDF 4.2
  9378. function _computeLineheight($lh, $fs='') {
  9379. if ($this->shrin_k > 1) { $k = $this->shrin_k; }
  9380. else { $k = 1; }
  9381. if (!$fs) { $fs = $this->FontSize; }
  9382. if (preg_match('/mm/',$lh)) {
  9383. return (($lh + 0.0) / $k); // convert to number
  9384. }
  9385. else if ($lh > 0) {
  9386. return ($fs * $lh);
  9387. }
  9388. else if (isset($this->normalLineheight)) { return ($fs * $this->normalLineheight); }
  9389. else return ($fs * $this->default_lineheight_correction);
  9390. }
  9391. function SetBasePath($str='') {
  9392. // mPDF 4.2.029
  9393. if ( isset($_SERVER['HTTP_HOST']) ) { $host = $_SERVER['HTTP_HOST']; }
  9394. else if ( isset($_SERVER['SERVER_NAME']) ) { $host = $_SERVER['SERVER_NAME']; }
  9395. else { $host = ''; }
  9396. if (!$str) {
  9397. if ($_SERVER['SCRIPT_NAME']) { $currentPath = dirname($_SERVER['SCRIPT_NAME']); }
  9398. else { $currentPath = dirname($_SERVER['PHP_SELF']); }
  9399. $currentPath = str_replace("\\","/",$currentPath);
  9400. if ($currentPath == '/') { $currentPath = ''; }
  9401. if ($host) { $currpath = 'http://' . $host . $currentPath .'/'; }
  9402. else { $currpath = ''; }
  9403. $this->basepath = $currpath;
  9404. $this->basepathIsLocal = true;
  9405. return;
  9406. }
  9407. $str = preg_replace('/\?.*/','',$str);
  9408. if (!preg_match('/(http|https|ftp):\/\/.*\//i',$str)) { $str .= '/'; }
  9409. $str .= 'xxx'; // in case $str ends in / e.g. http://www.bbc.co.uk/
  9410. $this->basepath = dirname($str) . "/"; // returns e.g. e.g. http://www.google.com/dir1/dir2/dir3/
  9411. $this->basepath = str_replace("\\","/",$this->basepath); //If on Windows
  9412. $tr = parse_url($this->basepath);
  9413. if (isset($tr['host']) && ($tr['host'] == $host)) { $this->basepathIsLocal = true; }
  9414. else { $this->basepathIsLocal = false; }
  9415. }
  9416. // mPDF 4.0
  9417. function GetFullPath(&$path,$basepath='') {
  9418. // When parsing CSS need to pass temporary basepath - so links are relative to current stylesheet
  9419. if (!$basepath) { $basepath = $this->basepath; }
  9420. //Fix path value
  9421. $path = str_replace("\\","/",$path); //If on Windows
  9422. //Get link info and obtain its absolute path
  9423. $regexp = '|^./|'; // Inadvertently corrects "./path/etc" and "//www.domain.com/etc"
  9424. $path = preg_replace($regexp,'',$path);
  9425. if(substr($path,0,1) == '#') { return; }
  9426. if (stristr($path,"mailto:") !== false) { return; }
  9427. if (strpos($path,"../") !== false ) { //It is a Relative Link
  9428. $backtrackamount = substr_count($path,"../");
  9429. $maxbacktrack = substr_count($basepath,"/") - 1;
  9430. $filepath = str_replace("../",'',$path);
  9431. $path = $basepath;
  9432. //If it is an invalid relative link, then make it go to directory root
  9433. if ($backtrackamount > $maxbacktrack) $backtrackamount = $maxbacktrack;
  9434. //Backtrack some directories
  9435. for( $i = 0 ; $i < $backtrackamount + 1 ; $i++ ) $path = substr( $path, 0 , strrpos($path,"/") );
  9436. $path = $path . "/" . $filepath; //Make it an absolute path
  9437. }
  9438. else if( strpos($path,":/") === false || strpos($path,":/") > 10) { //It is a Local Link
  9439. if (substr($path,0,1) == "/") {
  9440. $tr = parse_url($basepath);
  9441. $root = $tr['scheme'].'://'.$tr['host'];
  9442. $path = $root . $path;
  9443. }
  9444. else { $path = $basepath . $path; }
  9445. }
  9446. //Do nothing if it is an Absolute Link
  9447. }
  9448. // Used for external CSS files
  9449. function _get_file($path) {
  9450. // If local file try using local path (? quicker, but also allowed even if allow_url_fopen false)
  9451. $contents = '';
  9452. // Modified by Ivan Tcholakov, 29-JUl-2010.
  9453. //$contents = @file_get_contents($path);
  9454. if (api_is_internal_path($path)) {
  9455. $contents = @file_get_contents(api_get_path(TO_SYS, $path));
  9456. } else {
  9457. $contents = @file_get_contents($path);
  9458. }
  9459. //
  9460. if ($contents) { return $contents; }
  9461. if ($this->basepathIsLocal) {
  9462. $tr = parse_url($path);
  9463. $lp=getenv("SCRIPT_NAME");
  9464. $ap=realpath($lp);
  9465. $ap=str_replace("\\","/",$ap);
  9466. $docroot=substr($ap,0,strpos($ap,$lp));
  9467. // WriteHTML parses all paths to full URLs; may be local file name from calling ->Image() directly
  9468. if ($tr['scheme'] && $tr['host'] && $_SERVER["DOCUMENT_ROOT"] ) {
  9469. $localpath = $_SERVER["DOCUMENT_ROOT"] . $tr['path'];
  9470. }
  9471. // DOCUMENT_ROOT is not returned on IIS
  9472. else if ($docroot) {
  9473. $localpath = $docroot . $tr['path'];
  9474. }
  9475. else { $localpath = $path; }
  9476. $contents = @file_get_contents($localpath);
  9477. }
  9478. // if not use full URL
  9479. else if (!$contents && !ini_get('allow_url_fopen') && function_exists("curl_init")) {
  9480. $ch = curl_init($path);
  9481. curl_setopt($ch, CURLOPT_HEADER, 0);
  9482. curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
  9483. $contents = curl_exec($ch);
  9484. curl_close($ch);
  9485. }
  9486. return $contents;
  9487. }
  9488. function UseCSS($opt=true)
  9489. {
  9490. $this->usecss=$opt;
  9491. }
  9492. function UseTableHeader($opt=true)
  9493. {
  9494. $this->usetableheader=$opt;
  9495. }
  9496. function UsePRE($opt=true)
  9497. {
  9498. $this->usepre=$opt;
  9499. }
  9500. // Edited mPDF 3.0 - added offset & extras (prefix/suffix)
  9501. function docPageNum($num = 0, $extras = false) {
  9502. if ($num < 1) { $num = $this->page; }
  9503. $type = '1'; // set default decimal
  9504. $ppgno = $num;
  9505. $suppress = 0;
  9506. $offset = 0;
  9507. // mPDF 4.2.020
  9508. $lastreset = 0;
  9509. foreach($this->PageNumSubstitutions AS $psarr) {
  9510. if ($num >= $psarr['from']) {
  9511. if ($psarr['reset']) {
  9512. if ($psarr['reset']>1) { $offset = $psarr['reset']-1; }
  9513. $ppgno = $num - $psarr['from'] + 1 + $offset;
  9514. // mPDF 4.2.020
  9515. $lastreset = $psarr['from'];
  9516. }
  9517. if ($psarr['type']) { $type = $psarr['type']; }
  9518. if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; }
  9519. else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; }
  9520. }
  9521. }
  9522. if ($suppress) { return ''; }
  9523. // mPDF 4.2.020
  9524. foreach($this->pgsIns AS $k=>$v) {
  9525. if ($k>$lastreset && $k<$num) {
  9526. $ppgno -= $v;
  9527. }
  9528. }
  9529. if ($type=='A') { $ppgno = $this->dec2alpha($ppgno,true); }
  9530. else if ($type=='a') { $ppgno = $this->dec2alpha($ppgno,false);}
  9531. else if ($type=='I') { $ppgno = $this->dec2roman($ppgno,true); }
  9532. else if ($type=='i') { $ppgno = $this->dec2roman($ppgno,false); }
  9533. if ($extras) { $ppgno = $this->pagenumPrefix . $ppgno . $this->pagenumSuffix; }
  9534. return $ppgno;
  9535. }
  9536. // mPDF 3.0
  9537. function docPageSettings($num = 0) {
  9538. // Returns current type (numberstyle), suppression state for this page number;
  9539. // reset is only returned if set for this page number
  9540. if ($num < 1) { $num = $this->page; }
  9541. $type = '1'; // set default decimal
  9542. $ppgno = $num;
  9543. $suppress = 0;
  9544. $offset = 0;
  9545. $reset = '';
  9546. foreach($this->PageNumSubstitutions AS $psarr) {
  9547. if ($num >= $psarr['from']) {
  9548. if ($psarr['reset']) {
  9549. if ($psarr['reset']>1) { $offset = $psarr['reset']-1; }
  9550. $ppgno = $num - $psarr['from'] + 1 + $offset;
  9551. }
  9552. if ($psarr['type']) { $type = $psarr['type']; }
  9553. if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; }
  9554. else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; }
  9555. }
  9556. if ($num == $psarr['from']) { $reset = $psarr['reset']; }
  9557. }
  9558. if ($suppress) { $suppress = 'on'; }
  9559. else { $suppress = 'off'; }
  9560. return array($type, $suppress, $reset);
  9561. }
  9562. function docPageNumTotal($num = 0, $extras = false) {
  9563. if ($num < 1) { $num = $this->page; }
  9564. $type = '1'; // set default decimal
  9565. $ppgstart = 1;
  9566. $ppgend = count($this->pages)+1;
  9567. $suppress = 0;
  9568. $offset = 0;
  9569. foreach($this->PageNumSubstitutions AS $psarr) {
  9570. if ($num >= $psarr['from']) {
  9571. if ($psarr['reset']) {
  9572. if ($psarr['reset']>1) { $offset = $psarr['reset']-1; }
  9573. $ppgstart = $psarr['from'] + $offset;
  9574. $ppgend = count($this->pages)+1 + $offset;
  9575. }
  9576. if ($psarr['type']) { $type = $psarr['type']; }
  9577. if (strtoupper($psarr['suppress'])=='ON' || $psarr['suppress']==1) { $suppress = 1; }
  9578. else if (strtoupper($psarr['suppress'])=='OFF') { $suppress = 0; }
  9579. }
  9580. if ($num < $psarr['from']) {
  9581. if ($psarr['reset']) {
  9582. $ppgend = $psarr['from'] + $offset;
  9583. break;
  9584. }
  9585. }
  9586. }
  9587. if ($suppress) { return ''; }
  9588. $ppgno = $ppgend-$ppgstart+$offset;
  9589. if ($extras) { $ppgno = $this->nbpgPrefix . $ppgno . $this->nbpgSuffix; }
  9590. return $ppgno;
  9591. }
  9592. function RestartDocTemplate() {
  9593. $this->docTemplateStart = $this->page;
  9594. }
  9595. //Page header
  9596. function Header($content='') {
  9597. $this->cMarginL = 0;
  9598. $this->cMarginR = 0;
  9599. // mPDF 4.2
  9600. // Template moved to AddPage()
  9601. /*-- HTMLHEADERS-FOOTERS --*/
  9602. // mPDF 4.0
  9603. if (($this->mirrorMargins && ($this->page%2==0) && $this->HTMLHeaderE) || ($this->mirrorMargins && ($this->page%2==1) && $this->HTMLHeader) || (!$this->mirrorMargins && $this->HTMLHeader)) {
  9604. $this->writeHTMLHeaders();
  9605. return;
  9606. }
  9607. /*-- END HTMLHEADERS-FOOTERS --*/
  9608. $this->processingHeader=true;
  9609. $h = $this->headerDetails;
  9610. if(count($h)) {
  9611. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  9612. $this->_out(sprintf('q 0 -1 1 0 0 %.3f cm ',($this->h*$this->k)));
  9613. $yadj = $this->w - $this->h;
  9614. $headerpgwidth = $this->h - $this->orig_lMargin - $this->orig_rMargin;
  9615. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  9616. $headerlmargin = $this->orig_rMargin;
  9617. }
  9618. else {
  9619. $headerlmargin = $this->orig_lMargin;
  9620. }
  9621. }
  9622. else {
  9623. $yadj = 0;
  9624. $headerpgwidth = $this->pgwidth;
  9625. $headerlmargin = $this->lMargin;
  9626. }
  9627. $this->y = $this->margin_header - $yadj ;
  9628. $this->SetTextColor(0);
  9629. $this->SUP = false;
  9630. $this->SUB = false;
  9631. $this->bullet = false;
  9632. // only show pagenumber if numbering on
  9633. // mPDF 3.0 Add PageNum prefix/suffix
  9634. $pgno = $this->docPageNum($this->page, true);
  9635. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  9636. $side = 'even';
  9637. }
  9638. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS = DEFAULT
  9639. $side = 'odd';
  9640. }
  9641. $maxfontheight = 0;
  9642. foreach(array('L','C','R') AS $pos) {
  9643. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  9644. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  9645. else { $hfsz = $this->default_font_size; }
  9646. $maxfontheight = max($maxfontheight,$hfsz);
  9647. }
  9648. }
  9649. // LEFT-CENTER-RIGHT
  9650. foreach(array('L','C','R') AS $pos) {
  9651. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  9652. $hd = str_replace('{PAGENO}',$pgno,$h[$side][$pos]['content']);
  9653. // mPDF 3.0
  9654. $hd = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->aliasNbPgGp.$this->nbpgSuffix,$hd); // {nbpg}
  9655. $hd = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$hd);
  9656. if (isset($h[$side][$pos]['font-family']) && $h[$side][$pos]['font-family']) { $hff = $h[$side][$pos]['font-family']; }
  9657. // mPDF 3.0 original_ in case pagebreak in middle of table
  9658. else { $hff = $this->original_default_font; }
  9659. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  9660. // mPDF 3.0 original_ in case pagebreak in middle of table
  9661. else { $hfsz = $this->original_default_font_size; } // pts
  9662. $maxfontheight = max($maxfontheight,$hfsz);
  9663. $hfst = '';
  9664. if (isset($h[$side][$pos]['font-style']) && $h[$side][$pos]['font-style']) {
  9665. $hfst = $h[$side][$pos]['font-style'];
  9666. }
  9667. if (isset($h[$side][$pos]['color']) && $h[$side][$pos]['color']) {
  9668. $hfcol = $h[$side][$pos]['color'];
  9669. $cor = $this->ConvertColor($hfcol);
  9670. if ($cor) { $this->SetTextColor($cor['R'],$cor['G'],$cor['B']); }
  9671. }
  9672. else { $hfcol = ''; }
  9673. // mPDF 3.0 Force output
  9674. $this->SetFont($hff,$hfst,$hfsz,true,true);
  9675. $this->x = $headerlmargin ;
  9676. $this->y = $this->margin_header - $yadj ;
  9677. $hd = $this->purify_utf8_text($hd);
  9678. if ($this->text_input_as_HTML) {
  9679. $hd = $this->all_entities_to_utf8($hd);
  9680. }
  9681. // CONVERT CODEPAGE
  9682. // Modified by Ivan Tcholakov, 28-JAN-2010.
  9683. //if (!$this->is_MB) { $hd = mb_convert_encoding($hd,$this->mb_enc,'UTF-8'); }
  9684. if (!$this->is_MB) { $hd = api_convert_encoding($hd,$this->mb_enc,'UTF-8'); }
  9685. //
  9686. // DIRECTIONALITY RTL
  9687. $this->magic_reverse_dir($hd); // *RTL*
  9688. // mPDF 4.0 Font-specific ligature substitution for Indic fonts
  9689. $this->ConvertIndic($hd); // *INDIC*
  9690. $align = $pos;
  9691. /*-- RTL --*/
  9692. if ($this->directionality == 'rtl') {
  9693. if ($pos == 'L') { $align = 'R'; }
  9694. else if ($pos == 'R') { $align = 'L'; }
  9695. }
  9696. /*-- END RTL --*/
  9697. if ($pos!='L' && (stripos($hd,$this->aliasNbPg)!==false || stripos($hd,$this->aliasNbPgGp)!==false)) {
  9698. if (stripos($hd,$this->aliasNbPgGp)!==false) { $type= 'nbpggp'; } else { $type= 'nbpg'; }
  9699. $this->_out('{mpdfheader'.$type.' '.$pos.' ff='.$hff.' fs='.$hfst.' fz='.$hfsz.'}');
  9700. $this->Cell($headerpgwidth ,$maxfontheight/$this->k ,$hd,0,0,$align,0,'',0,0,0,'M');
  9701. $this->_out('Q');
  9702. }
  9703. else {
  9704. $this->Cell($headerpgwidth ,$maxfontheight/$this->k ,$hd,0,0,$align,0,'',0,0,0,'M');
  9705. }
  9706. if ($hfcol) { $this->SetTextColor(0); }
  9707. }
  9708. }
  9709. //Return Font to normal
  9710. $this->SetFont($this->default_font,'',$this->original_default_font_size);
  9711. // LINE
  9712. if (isset($h[$side]['line']) && $h[$side]['line']) {
  9713. $this->SetLineWidth(0.1);
  9714. $this->SetDrawColor(0);
  9715. $this->Line($headerlmargin , $this->margin_header + ($maxfontheight*(1+$this->header_line_spacing)/$this->k) - $yadj , $headerlmargin + $headerpgwidth, $this->margin_header + ($maxfontheight*(1+$this->header_line_spacing)/$this->k) - $yadj );
  9716. }
  9717. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  9718. $this->_out('Q');
  9719. }
  9720. }
  9721. $this->SetY($this->tMargin);
  9722. if ($this->ColActive) { $this->pgwidth = $this->ColWidth; } // *COLUMNS*
  9723. $this->processingHeader=false;
  9724. }
  9725. /*-- TABLES --*/
  9726. function TableHeaderFooter($content='',$tablestartpage='',$tablestartcolumn ='',$horf = 'H') {
  9727. if((($this->usetableheader && $horf=='H') || $horf=='F') && !empty($content)) { // mPDF 3.0
  9728. $table = &$this->table[1][1];
  9729. // Advance down page by half width of top border
  9730. // mPDF 4.0
  9731. if ($horf=='H') { // Only if header
  9732. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2 + $table['border_details']['T']['w'] + $table['padding']['T']; }
  9733. else { $adv = $table['max_cell_border_width']['T'] /2 ; }
  9734. if ($adv) {
  9735. if ($this->table_rotate) {
  9736. $this->y += ($adv);
  9737. }
  9738. else {
  9739. $this->DivLn($adv,$this->blklvl,true);
  9740. }
  9741. }
  9742. }
  9743. if ($horf=='F') { // Table Footer
  9744. $firstrow = count($table['cells']) - $this->tablefooternrows;
  9745. $lastrow = count($table['cells']) - 1;
  9746. }
  9747. else { // Table Header
  9748. $firstrow = 0;
  9749. $lastrow = $this->tableheadernrows - 1;
  9750. }
  9751. $topy = $content[$firstrow][0]['y']-$this->y;
  9752. for ($i=$firstrow ; $i<=$lastrow; $i++) {
  9753. $y = $this->y;
  9754. /*-- COLUMNS --*/
  9755. // If outside columns, this is done in PaintDivBB
  9756. if ($this->ColActive) {
  9757. //OUTER FILL BGCOLOR of DIVS
  9758. if ($this->blklvl > 0) {
  9759. $firstblockfill = $this->GetFirstBlockFill();
  9760. if ($firstblockfill && $this->blklvl >= $firstblockfill) {
  9761. $divh = $content[$i][0]['h'];
  9762. $bak_x = $this->x;
  9763. $this->DivLn($divh,-3,false);
  9764. // Reset current block fill
  9765. $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  9766. $this->SetFillColor($bcor['R'],$bcor['G'],$bcor['B']);
  9767. $this->x = $bak_x;
  9768. }
  9769. }
  9770. }
  9771. /*-- END COLUMNS --*/
  9772. $colctr = 0;
  9773. foreach($content[$i] as $tablehf)
  9774. {
  9775. $colctr++;
  9776. $y = $tablehf['y'] - $topy;
  9777. $this->y = $y;
  9778. //Set some cell values
  9779. $x = $tablehf['x'];
  9780. if (($this->mirrorMargins) && ($tablestartpage == 'ODD') && (($this->page)%2==0)) { // EVEN
  9781. $x = $x +$this->MarginCorrection;
  9782. }
  9783. else if (($this->mirrorMargins) && ($tablestartpage == 'EVEN') && (($this->page)%2==1)) { // ODD
  9784. $x = $x +$this->MarginCorrection;
  9785. }
  9786. /*-- COLUMNS --*/
  9787. // Added to correct for Columns
  9788. if ($this->ColActive) {
  9789. if ($this->directionality == 'rtl') { // *RTL*
  9790. $x -= ($this->CurrCol - $tablestartcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  9791. } // *RTL*
  9792. else { // *RTL*
  9793. $x += ($this->CurrCol - $tablestartcolumn) * ($this->ColWidth+$this->ColGap);
  9794. } // *RTL*
  9795. }
  9796. /*-- END COLUMNS --*/
  9797. $w = $tablehf['w'];
  9798. $h = $tablehf['h'];
  9799. $va = $tablehf['va'];
  9800. $R = $tablehf['R'];
  9801. $mih = $tablehf['mih'];
  9802. $fill = $tablehf['bgcolor'];
  9803. $border = $tablehf['border'];
  9804. $border_details = $tablehf['border_details'];
  9805. $padding = $tablehf['padding'];
  9806. $this->tabletheadjustfinished = true;
  9807. $textbuffer = $tablehf['textbuffer'];
  9808. $align = $tablehf['a'];
  9809. //Align
  9810. $this->divalign=$align;
  9811. $this->x = $x;
  9812. if ($table['borders_separate']) {
  9813. $tablefill = isset($table['bgcolor'][-1]) ? $table['bgcolor'][-1] : 0; // mPDF 4.3.005
  9814. if ($tablefill) {
  9815. $color = $this->ConvertColor($tablefill);
  9816. if ($color) $this->SetFillColor($color['R'],$color['G'],$color['B']);
  9817. $xadj = ($table['border_spacing_H']/2);
  9818. $yadj = ($table['border_spacing_V']/2);
  9819. $wadj = $table['border_spacing_H'];
  9820. $hadj = $table['border_spacing_V'];
  9821. // mPDF 4.0
  9822. if ($i == $firstrow && $horf=='H') { // Top
  9823. $yadj += $table['padding']['T'];
  9824. $hadj += $table['padding']['T'];
  9825. }
  9826. if (($i == ($lastrow) || (isset($tablehf['rowspan']) && ($i+$tablehf['rowspan']) == ($lastrow+1)) || (!isset($tablehf['rowspan']) && ($i+1) == ($lastrow+1))) && $horf=='F') { // Bottom
  9827. $hadj += $table['padding']['B'];
  9828. }
  9829. if ($colctr == 1) { // Left
  9830. $xadj += $table['padding']['L'];
  9831. $wadj += $table['padding']['L'];
  9832. }
  9833. if ($colctr == count($content[$i]) ) { // Right
  9834. $wadj += $table['padding']['R'];
  9835. }
  9836. $this->Rect($x - $xadj, $y - $yadj, $w + $wadj, $h + $hadj, 'F');
  9837. }
  9838. }
  9839. // TABLE BORDER - if separate
  9840. if ($table['borders_separate'] && $table['border']) {
  9841. $halfspaceL = $table['padding']['L'] + ($table['border_spacing_H']/2);
  9842. $halfspaceR = $table['padding']['R'] + ($table['border_spacing_H']/2);
  9843. $halfspaceT = $table['padding']['T'] + ($table['border_spacing_V']/2);
  9844. $halfspaceB = $table['padding']['B'] + ($table['border_spacing_V']/2);
  9845. $tbx = $x;
  9846. $tby = $y;
  9847. $tbw = $w;
  9848. $tbh = $h;
  9849. $tab_bord = 0;
  9850. $corner = '';
  9851. if ($i == $firstrow && $horf=='H') { // Top
  9852. $tby -= $halfspaceT + ($table['border_details']['T']['w']/2);
  9853. $tbh += $halfspaceT + ($table['border_details']['T']['w']/2);
  9854. $this->setBorder($tab_bord , _BORDER_TOP);
  9855. $corner .= 'T';
  9856. }
  9857. if (($i == ($lastrow) || (isset($tablehf['rowspan']) && ($i+$tablehf['rowspan']) == ($lastrow+1)) || (!isset($tablehf['rowspan']) && ($i+1) == ($lastrow+1))) && $horf=='F') { // Bottom
  9858. $tbh += $halfspaceB + ($table['border_details']['B']['w']/2);
  9859. $this->setBorder($tab_bord , _BORDER_BOTTOM);
  9860. $corner .= 'B';
  9861. }
  9862. if ($colctr == 1) { // Top Left
  9863. $tbx -= $halfspaceL + ($table['border_details']['L']['w']/2);
  9864. $tbw += $halfspaceL + ($table['border_details']['L']['w']/2);
  9865. $this->setBorder($tab_bord , _BORDER_LEFT);
  9866. $corner .= 'L';
  9867. }
  9868. if ($colctr == count($content[$i])) { // Right // mPDF 4.4.014
  9869. $tbw += $halfspaceR + ($table['border_details']['R']['w']/2);
  9870. $this->setBorder($tab_bord , _BORDER_RIGHT);
  9871. $corner .= 'R';
  9872. }
  9873. $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'] );
  9874. }
  9875. if ($table['empty_cells']!='hide' || !empty($textbuffer) || !$table['borders_separate']) { $paintcell = true; }
  9876. else { $paintcell = false; }
  9877. //Vertical align
  9878. if ($R && INTVAL($R) > 0 && isset($va) && $va!='B') { $va='B';}
  9879. if (!isset($va) || empty($va) || $va=='M') $this->y += ($h-$mih)/2;
  9880. elseif (isset($va) && $va=='B') $this->y += $h-$mih;
  9881. if ($fill && $paintcell)
  9882. {
  9883. $color = $this->ConvertColor($fill);
  9884. if ($color) $this->SetFillColor($color['R'],$color['G'],$color['B']);
  9885. if ($table['borders_separate']) {
  9886. $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');
  9887. }
  9888. else {
  9889. $this->Rect($x, $y, $w, $h, 'F');
  9890. }
  9891. }
  9892. /*-- GRADIENTS --*/
  9893. if (isset($tablehf['gradient']) && $tablehf['gradient'] && $paintcell){ // mPDF 4.3.006
  9894. $g = $this->parseBackgroundGradient($tablehf['gradient']);
  9895. if ($g) {
  9896. if ($table['borders_separate']) {
  9897. $px = $x+ ($table['border_spacing_H']/2);
  9898. $py = $y+ ($table['border_spacing_V']/2);
  9899. $pw = $w- $table['border_spacing_H'];
  9900. $ph = $h- $table['border_spacing_V'];
  9901. }
  9902. else {
  9903. $px = $x;
  9904. $py = $y;
  9905. $pw = $w;
  9906. $ph = $h;
  9907. }
  9908. $this->Gradient($px, $py, $pw, $ph, $g['type'], $g['col'], $g['col2'], $g['coords'], $g['extend']);
  9909. }
  9910. }
  9911. /*-- END GRADIENTS --*/
  9912. /*-- BACKGROUND-IMAGES --*/
  9913. if (isset($tablehf['background-image']) && $paintcell){ // mPDF 4.3.006
  9914. if ($tablehf['background-image']['image_id']) { // Background pattern
  9915. $n = count($this->patterns)+1;
  9916. if ($table['borders_separate']) {
  9917. $px = $x+ ($table['border_spacing_H']/2);
  9918. $py = $y+ ($table['border_spacing_V']/2);
  9919. $pw = $w- $table['border_spacing_H'];
  9920. $ph = $h- $table['border_spacing_V'];
  9921. }
  9922. else {
  9923. $px = $x;
  9924. $py = $y;
  9925. $pw = $w;
  9926. $ph = $h;
  9927. }
  9928. // mPDF 4.3.015
  9929. 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']);
  9930. $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); // mPDF 4.3.015
  9931. // mPDF 4.3.017
  9932. if ($tablehf['background-image']['opacity']>0 && $tablehf['background-image']['opacity']<1) { $opac = $this->SetAlpha($tablehf['background-image']['opacity'],'Normal',true); }
  9933. else { $opac = ''; }
  9934. $this->_out(sprintf('q /Pattern cs /P%d scn %s %.3f %.3f %.3f %.3f re f Q', $n, $opac, $px*$this->k, ($this->h-$py)*$this->k, $pw*$this->k, -$ph*$this->k));
  9935. }
  9936. }
  9937. /*-- END BACKGROUND-IMAGES --*/
  9938. //Border
  9939. if ($table['borders_separate'] && $paintcell && $border) { // mPDF 4.2.017
  9940. $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']);
  9941. }
  9942. else if ($paintcell && $border) { // mPDF 4.2.017
  9943. $this->_tableRect($x, $y, $w, $h, $border, $border_details, true, $table['borders_separate']); // true causes buffer
  9944. }
  9945. //Print cell content
  9946. // $this->divheight = $this->table_lineheight*$this->lineheight; // mPDF 4.2
  9947. if (!empty($textbuffer)) {
  9948. if ($R) {
  9949. $cellPtSize = $textbuffer[0][11] / $this->shrin_k;
  9950. $cellFontHeight = ($cellPtSize/$this->k);
  9951. $opx = $this->x;
  9952. $opy = $this->y;
  9953. $angle = INTVAL($R);
  9954. // Only allow 45 - 90 degrees (when bottom-aligned) or -90
  9955. if ($angle > 90) { $angle = 90; }
  9956. else if ($angle > 0 && (isset($va) && $va!='B')) { $angle = 90; }
  9957. else if ($angle > 0 && $angle <45) { $angle = 45; }
  9958. else if ($angle < 0) { $angle = -90; }
  9959. $offset = ((sin(deg2rad($angle))) * 0.37 * $cellFontHeight);
  9960. if (isset($align) && $align =='R') {
  9961. $this->x += ($w) + ($offset) - ($cellFontHeight/3) - ($padding['R'] + $border_details['R']['w']);
  9962. }
  9963. else if (!isset($align ) || $align =='C') {
  9964. $this->x += ($w/2) + ($offset);
  9965. }
  9966. else {
  9967. $this->x += ($offset) + ($cellFontHeight/3)+($padding['L'] + $border_details['L']['w']);
  9968. }
  9969. $str = trim(implode(' ',$tablehf['text'])); // mPDF 4.4.012
  9970. if (!isset($va) || $va=='M') {
  9971. $this->y -= ($h-$mih)/2; //Undo what was added earlier VERTICAL ALIGN
  9972. 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'])); }
  9973. else if ($angle < 0) { $this->y += (($h-$mih)/2)+($padding['T'] + $border_details['T']['w']); }
  9974. }
  9975. else if (isset($va) && $va=='B') {
  9976. $this->y -= $h-$mih; //Undo what was added earlier VERTICAL ALIGN
  9977. if ($angle > 0) { $this->y += $h-($border_details['B']['w']+$padding['B']); }
  9978. else if ($angle < 0) { $this->y += $h-$mih+($padding['T'] + $border_details['T']['w']); }
  9979. }
  9980. else if (isset($va) && $va=='T') {
  9981. if ($angle > 0) { $this->y += $mih-($border_details['B']['w']+$padding['B']); }
  9982. else if ($angle < 0) { $this->y += ($padding['T'] + $border_details['T']['w']); }
  9983. }
  9984. $this->Rotate($angle,$this->x,$this->y);
  9985. $s_fs = $this->FontSizePt;
  9986. $s_f = $this->FontFamily; // mPDF 3.0
  9987. $s_st = $this->FontStyle; // mPDF 3.0
  9988. $this->SetFont($textbuffer[0][4],$textbuffer[0][2],$cellPtSize,true,true);
  9989. $this->Text($this->x,$this->y,$str);
  9990. $this->Rotate(0);
  9991. $this->SetFont($s_f,$s_st,$s_fs,true,true);
  9992. $this->x = $opx;
  9993. $this->y = $opy;
  9994. }
  9995. else {
  9996. if ($table['borders_separate']) { // NB twice border width
  9997. $xadj = $border_details['L']['w'] + $padding['L'] +($table['border_spacing_H']/2);
  9998. $wadj = $border_details['L']['w'] + $border_details['R']['w'] + $padding['L'] +$padding['R'] + $table['border_spacing_H'];
  9999. $yadj = $border_details['T']['w'] + $padding['T'] + ($table['border_spacing_H']/2);
  10000. }
  10001. else {
  10002. $xadj = $border_details['L']['w']/2 + $padding['L'];
  10003. $wadj = ($border_details['L']['w'] + $border_details['R']['w'])/2 + $padding['L'] + $padding['R'];
  10004. $yadj = $border_details['T']['w']/2 + $padding['T'];
  10005. }
  10006. $this->divwidth=$w-($wadj);
  10007. $this->x += $xadj;
  10008. $this->y += $yadj;
  10009. $this->printbuffer($textbuffer,'',true);
  10010. }
  10011. }
  10012. $textbuffer = array();
  10013. }
  10014. $this->y = $y + $h; //Update y coordinate
  10015. }
  10016. }//end of 'if usetableheader ...'
  10017. }
  10018. /*-- END TABLES --*/
  10019. /*-- HTMLHEADERS-FOOTERS --*/
  10020. function SetHTMLHeader($header='',$OE='',$write=false) {
  10021. // mPDF 4.0
  10022. $height = 0;
  10023. if (is_array($header) && isset($header['html']) && $header['html']) {
  10024. $Hhtml = $header['html'];
  10025. if ($this->setAutoTopMargin) {
  10026. if (isset($header['h'])) { $height = $header['h']; }
  10027. else { $height = $this->_gethtmlheight($Hhtml); }
  10028. }
  10029. }
  10030. else if (!is_array($header) && $header) {
  10031. $Hhtml = $header;
  10032. if ($this->setAutoTopMargin) { $height = $this->_gethtmlheight($Hhtml); }
  10033. }
  10034. else { $Hhtml = ''; }
  10035. // mPDF 4.0
  10036. if ($OE != 'E') { $OE = 'O'; }
  10037. if ($OE == 'E') {
  10038. // mPDF 4.0
  10039. if ($Hhtml) {
  10040. $this->HTMLHeaderE['html'] = $Hhtml;
  10041. $this->HTMLHeaderE['h'] = $height;
  10042. }
  10043. else { $this->HTMLHeaderE = ''; }
  10044. }
  10045. else {
  10046. // mPDF 4.0
  10047. if ($Hhtml) {
  10048. $this->HTMLHeader['html'] = $Hhtml;
  10049. $this->HTMLHeader['h'] = $height;
  10050. }
  10051. else { $this->HTMLHeader = ''; }
  10052. }
  10053. if (!$this->mirrorMargins && $OE == 'E') { return; }
  10054. if ($Hhtml=='') { return; }
  10055. if ($OE == 'E') {
  10056. $this->headerDetails['even'] = array(); // override and clear any other non-HTML header/footer
  10057. }
  10058. else {
  10059. $this->headerDetails['odd'] = array(); // override and clear any non-HTML other header/footer
  10060. }
  10061. // mPDF 4.0
  10062. if ($this->setAutoTopMargin=='pad') {
  10063. $this->tMargin = $this->margin_header + $height + $this->orig_tMargin;
  10064. if (isset($this->saveHTMLHeader[$this->page][$OE]['mt'])) { $this->saveHTMLHeader[$this->page][$OE]['mt'] = $this->tMargin; }
  10065. }
  10066. else if ($this->setAutoTopMargin=='stretch') {
  10067. $this->tMargin = max($this->orig_tMargin, $this->margin_header + $height + $this->autoMarginPadding);
  10068. if (isset($this->saveHTMLHeader[$this->page][$OE]['mt'])) { $this->saveHTMLHeader[$this->page][$OE]['mt'] = $this->tMargin; }
  10069. }
  10070. 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(); }
  10071. }
  10072. function SetHTMLFooter($footer='',$OE='') {
  10073. // mPDF 4.0
  10074. $height = 0;
  10075. if (is_array($footer) && isset($footer['html']) && $footer['html']) {
  10076. $Fhtml = $footer['html'];
  10077. if ($this->setAutoBottomMargin) {
  10078. if (isset($footer['h'])) { $height = $footer['h']; }
  10079. else { $height = $this->_gethtmlheight($Fhtml); }
  10080. }
  10081. }
  10082. else if (!is_array($footer) && $footer) {
  10083. $Fhtml = $footer;
  10084. if ($this->setAutoBottomMargin) { $height = $this->_gethtmlheight($Fhtml); }
  10085. }
  10086. else { $Fhtml = ''; }
  10087. // mPDF 4.0
  10088. if ($OE != 'E') { $OE = 'O'; }
  10089. if ($OE == 'E') {
  10090. // mPDF 4.0
  10091. if ($Fhtml) {
  10092. $this->HTMLFooterE['html'] = $Fhtml;
  10093. $this->HTMLFooterE['h'] = $height;
  10094. }
  10095. else { $this->HTMLFooterE = ''; }
  10096. }
  10097. else {
  10098. // mPDF 4.0
  10099. if ($Fhtml) {
  10100. $this->HTMLFooter['html'] = $Fhtml;
  10101. $this->HTMLFooter['h'] = $height;
  10102. }
  10103. else { $this->HTMLFooter = ''; }
  10104. }
  10105. if (!$this->mirrorMargins && $OE == 'E') { return; }
  10106. if ($Fhtml=='') { return false; }
  10107. if ($OE == 'E') {
  10108. $this->footerDetails['even'] = array(); // override and clear any other header/footer
  10109. }
  10110. else {
  10111. $this->footerDetails['odd'] = array(); // override and clear any other header/footer
  10112. }
  10113. // mPDF 4.0
  10114. if ($this->setAutoBottomMargin=='pad') {
  10115. $this->bMargin = $this->margin_footer + $height + $this->orig_bMargin;
  10116. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  10117. if (isset($this->saveHTMLHeader[$this->page][$OE]['mb'])) { $this->saveHTMLHeader[$this->page][$OE]['mb'] = $this->bMargin; }
  10118. }
  10119. else if ($this->setAutoBottomMargin=='stretch') {
  10120. $this->bMargin = max($this->orig_bMargin, $this->margin_footer + $height + $this->autoMarginPadding);
  10121. $this->PageBreakTrigger=$this->h-$this->bMargin ;
  10122. if (isset($this->saveHTMLHeader[$this->page][$OE]['mb'])) { $this->saveHTMLHeader[$this->page][$OE]['mb'] = $this->bMargin; }
  10123. }
  10124. }
  10125. // mPDF 4.0
  10126. function _getHtmlHeight($html) {
  10127. $save_state = $this->state;
  10128. $this->state = 2;
  10129. $this->Reset();
  10130. $this->pageoutput[$this->page] = array();
  10131. $save_x = $this->x;
  10132. $save_y = $this->y;
  10133. $this->x = $this->lMargin;
  10134. $this->y = $this->margin_header;
  10135. $html = str_replace('{PAGENO}',$this->pagenumPrefix.$this->docPageNum($this->page).$this->pagenumSuffix,$html);
  10136. $html = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->docPageNumTotal($this->page).$this->nbpgSuffix,$html );
  10137. $html = str_replace($this->aliasNbPg,$this->page,$html );
  10138. $html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );
  10139. $this->HTMLheaderPageLinks = array();
  10140. $savepb = $this->pageBackgrounds;
  10141. $this->writingHTMLheader = true;
  10142. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  10143. $this->writingHTMLheader = false;
  10144. $h = ($this->y - $this->margin_header);
  10145. $this->Reset();
  10146. $this->pageoutput[$this->page] = array();
  10147. $this->headerbuffer = '';
  10148. $this->pageBackgrounds = $savepb;
  10149. $this->x = $save_x;
  10150. $this->y = $save_y;
  10151. $this->state = $save_state;
  10152. return $h;
  10153. }
  10154. // Called internally from Header
  10155. function writeHTMLHeaders() {
  10156. // mPDF 4.0
  10157. if ($this->mirrorMargins && ($this->page)%2==0) { $OE = 'E'; } // EVEN
  10158. else { $OE = 'O'; }
  10159. if ($OE == 'E') {
  10160. $this->saveHTMLHeader[$this->page][$OE]['html'] = $this->HTMLHeaderE['html'] ;
  10161. }
  10162. else {
  10163. $this->saveHTMLHeader[$this->page][$OE]['html'] = $this->HTMLHeader['html'] ;
  10164. }
  10165. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10166. $this->saveHTMLHeader[$this->page][$OE]['rotate'] = true;
  10167. $this->saveHTMLHeader[$this->page][$OE]['ml'] = $this->tMargin;
  10168. $this->saveHTMLHeader[$this->page][$OE]['mr'] = $this->bMargin;
  10169. $this->saveHTMLHeader[$this->page][$OE]['mh'] = $this->margin_header;
  10170. $this->saveHTMLHeader[$this->page][$OE]['mf'] = $this->margin_footer;
  10171. $this->saveHTMLHeader[$this->page][$OE]['pw'] = $this->h;
  10172. $this->saveHTMLHeader[$this->page][$OE]['ph'] = $this->w;
  10173. }
  10174. else {
  10175. $this->saveHTMLHeader[$this->page][$OE]['ml'] = $this->lMargin;
  10176. $this->saveHTMLHeader[$this->page][$OE]['mr'] = $this->rMargin;
  10177. $this->saveHTMLHeader[$this->page][$OE]['mh'] = $this->margin_header;
  10178. $this->saveHTMLHeader[$this->page][$OE]['mf'] = $this->margin_footer;
  10179. $this->saveHTMLHeader[$this->page][$OE]['pw'] = $this->w;
  10180. $this->saveHTMLHeader[$this->page][$OE]['ph'] = $this->h;
  10181. }
  10182. }
  10183. function writeHTMLFooters() {
  10184. // mPDF 4.0
  10185. if ($this->mirrorMargins && ($this->page)%2==0) { $OE = 'E'; } // EVEN
  10186. else { $OE = 'O'; }
  10187. if ($OE == 'E') {
  10188. $this->saveHTMLFooter[$this->page][$OE]['html'] = $this->HTMLFooterE['html'] ;
  10189. }
  10190. else {
  10191. $this->saveHTMLFooter[$this->page][$OE]['html'] = $this->HTMLFooter['html'] ;
  10192. }
  10193. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10194. $this->saveHTMLFooter[$this->page][$OE]['rotate'] = true;
  10195. $this->saveHTMLFooter[$this->page][$OE]['ml'] = $this->tMargin;
  10196. $this->saveHTMLFooter[$this->page][$OE]['mr'] = $this->bMargin;
  10197. $this->saveHTMLFooter[$this->page][$OE]['mt'] = $this->rMargin;
  10198. $this->saveHTMLFooter[$this->page][$OE]['mb'] = $this->lMargin;
  10199. $this->saveHTMLFooter[$this->page][$OE]['mh'] = $this->margin_header;
  10200. $this->saveHTMLFooter[$this->page][$OE]['mf'] = $this->margin_footer;
  10201. $this->saveHTMLFooter[$this->page][$OE]['pw'] = $this->h;
  10202. $this->saveHTMLFooter[$this->page][$OE]['ph'] = $this->w;
  10203. }
  10204. else {
  10205. $this->saveHTMLFooter[$this->page][$OE]['ml'] = $this->lMargin;
  10206. $this->saveHTMLFooter[$this->page][$OE]['mr'] = $this->rMargin;
  10207. $this->saveHTMLFooter[$this->page][$OE]['mt'] = $this->tMargin;
  10208. $this->saveHTMLFooter[$this->page][$OE]['mb'] = $this->bMargin;
  10209. $this->saveHTMLFooter[$this->page][$OE]['mh'] = $this->margin_header;
  10210. $this->saveHTMLFooter[$this->page][$OE]['mf'] = $this->margin_footer;
  10211. $this->saveHTMLFooter[$this->page][$OE]['pw'] = $this->w;
  10212. $this->saveHTMLFooter[$this->page][$OE]['ph'] = $this->h;
  10213. }
  10214. }
  10215. /*-- END HTMLHEADERS-FOOTERS --*/
  10216. function DefHeaderByName($name,$arr) {
  10217. if (!$name) { $name = '_default'; }
  10218. $this->pageheaders[$name] = $arr;
  10219. }
  10220. function DefFooterByName($name,$arr) {
  10221. if (!$name) { $name = '_default'; }
  10222. $this->pagefooters[$name] = $arr;
  10223. }
  10224. function SetHeaderByName($name,$side='O',$write=false) {
  10225. if (!$name) { $name = '_default'; }
  10226. if ($side=='E') { $this->headerDetails['even'] = $this->pageheaders[$name]; }
  10227. else { $this->headerDetails['odd'] = $this->pageheaders[$name]; }
  10228. if ($write) { $this->Header(); }
  10229. }
  10230. function SetFooterByName($name,$side='O') {
  10231. if (!$name) { $name = '_default'; }
  10232. if ($side=='E') { $this->footerDetails['even'] = $this->pagefooters[$name]; }
  10233. else { $this->footerDetails['odd'] = $this->pagefooters[$name]; }
  10234. }
  10235. /*-- HTMLHEADERS-FOOTERS --*/
  10236. function DefHTMLHeaderByName($name,$html) {
  10237. if (!$name) { $name = '_default'; }
  10238. // mPDF 4.0
  10239. $this->pageHTMLheaders[$name]['html'] = $html;
  10240. $this->pageHTMLheaders[$name]['h'] = $this->_gethtmlheight($html);
  10241. }
  10242. function DefHTMLFooterByName($name,$html) {
  10243. if (!$name) { $name = '_default'; }
  10244. // mPDF 4.0
  10245. $this->pageHTMLfooters[$name]['html'] = $html;
  10246. $this->pageHTMLfooters[$name]['h'] = $this->_gethtmlheight($html);
  10247. }
  10248. function SetHTMLHeaderByName($name,$side='O',$write=false) {
  10249. if (!$name) { $name = '_default'; }
  10250. $this->SetHTMLHeader($this->pageHTMLheaders[$name],$side,$write);
  10251. }
  10252. function SetHTMLFooterByName($name,$side='O') {
  10253. if (!$name) { $name = '_default'; }
  10254. $this->SetHTMLFooter($this->pageHTMLfooters[$name],$side,$write);
  10255. }
  10256. /*-- END HTMLHEADERS-FOOTERS --*/
  10257. function SetHeader($Harray=array(),$side='',$write=false) {
  10258. if (is_string($Harray)) {
  10259. if (strlen($Harray)==0) {
  10260. if ($side=='O') { $this->headerDetails['odd'] = array(); }
  10261. else if ($side=='E') { $this->headerDetails['even'] = array(); }
  10262. else { $this->headerDetails = array(); }
  10263. }
  10264. else if (strpos($Harray,'|') || strpos($Harray,'|')===0) {
  10265. $hdet = explode('|',$Harray);
  10266. $this->headerDetails = array (
  10267. 'odd' => array (
  10268. 'L' => array ('content' => $hdet[0], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10269. 'C' => array ('content' => $hdet[1], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10270. 'R' => array ('content' => $hdet[2], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10271. 'line' => $this->defaultheaderline,
  10272. ),
  10273. 'even' => array (
  10274. 'R' => array ('content' => $hdet[0], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10275. 'C' => array ('content' => $hdet[1], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10276. 'L' => array ('content' => $hdet[2], 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10277. 'line' => $this->defaultheaderline,
  10278. )
  10279. );
  10280. }
  10281. else {
  10282. $this->headerDetails = array (
  10283. 'odd' => array (
  10284. 'R' => array ('content' => $Harray, 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10285. 'line' => $this->defaultheaderline,
  10286. ),
  10287. 'even' => array (
  10288. 'L' => array ('content' => $Harray, 'font-size' => $this->defaultheaderfontsize, 'font-style' => $this->defaultheaderfontstyle),
  10289. 'line' => $this->defaultheaderline,
  10290. )
  10291. );
  10292. }
  10293. }
  10294. else if (is_array($Harray)) {
  10295. if ($side=='O') { $this->headerDetails['odd'] = $Harray; }
  10296. else if ($side=='E') { $this->headerDetails['even'] = $Harray; }
  10297. else { $this->headerDetails = $Harray; }
  10298. }
  10299. /*-- HTMLHEADERS-FOOTERS --*/
  10300. // Overwrite any HTML Header previously set
  10301. if ($side=='E') { $this->SetHTMLHeader('','E'); }
  10302. else if ($side=='O') { $this->SetHTMLHeader(''); }
  10303. else {
  10304. $this->SetHTMLHeader('');
  10305. $this->SetHTMLHeader('','E');
  10306. }
  10307. /*-- END HTMLHEADERS-FOOTERS --*/
  10308. if ($write) {
  10309. $save_y = $this->y;
  10310. $this->Header();
  10311. $this->SetY($save_y) ;
  10312. }
  10313. }
  10314. function SetFooter($Farray=array(),$side='') {
  10315. if (is_string($Farray)) {
  10316. if (strlen($Farray)==0) {
  10317. if ($side=='O') { $this->footerDetails['odd'] = array(); }
  10318. else if ($side=='E') { $this->footerDetails['even'] = array(); }
  10319. else { $this->footerDetails = array(); }
  10320. }
  10321. else if (strpos($Farray,'|') || strpos($Farray,'|')===0) {
  10322. $fdet = explode('|',$Farray);
  10323. $this->footerDetails = array (
  10324. 'odd' => array (
  10325. 'L' => array ('content' => $fdet[0], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10326. 'C' => array ('content' => $fdet[1], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10327. 'R' => array ('content' => $fdet[2], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10328. 'line' => $this->defaultfooterline,
  10329. ),
  10330. 'even' => array (
  10331. 'R' => array ('content' => $fdet[0], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10332. 'C' => array ('content' => $fdet[1], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10333. 'L' => array ('content' => $fdet[2], 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10334. 'line' => $this->defaultfooterline,
  10335. )
  10336. );
  10337. }
  10338. else {
  10339. $this->footerDetails = array (
  10340. 'odd' => array (
  10341. 'R' => array ('content' => $Farray, 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10342. 'line' => $this->defaultfooterline,
  10343. ),
  10344. 'even' => array (
  10345. 'L' => array ('content' => $Farray, 'font-size' => $this->defaultfooterfontsize, 'font-style' => $this->defaultfooterfontstyle),
  10346. 'line' => $this->defaultfooterline,
  10347. )
  10348. );
  10349. }
  10350. }
  10351. else if (is_array($Farray)) {
  10352. if ($side=='O') { $this->footerDetails['odd'] = $Farray; }
  10353. else if ($side=='E') { $this->footerDetails['even'] = $Farray; }
  10354. else { $this->footerDetails = $Farray; }
  10355. }
  10356. /*-- HTMLHEADERS-FOOTERS --*/
  10357. // Overwrite any HTML Footer previously set
  10358. if ($side=='E') { $this->SetHTMLFooter('','E'); }
  10359. else if ($side=='O') { $this->SetHTMLFooter(''); }
  10360. else {
  10361. $this->SetHTMLFooter('');
  10362. $this->SetHTMLFooter('','E');
  10363. }
  10364. /*-- END HTMLHEADERS-FOOTERS --*/
  10365. }
  10366. /*-- WATERMARK --*/
  10367. function setUnvalidatedText($txt='', $alpha=-1) {
  10368. if ($alpha>=0) $this->watermarkTextAlpha = $alpha;
  10369. $this->watermarkText = $txt;
  10370. }
  10371. function SetWatermarkText($txt='', $alpha=-1) {
  10372. if ($alpha>=0) $this->watermarkTextAlpha = $alpha;
  10373. $this->watermarkText = $txt;
  10374. }
  10375. function SetWatermarkImage($src, $alpha=-1, $size='D', $pos='F') {
  10376. if ($alpha>=0) $this->watermarkImageAlpha = $alpha;
  10377. $this->watermarkImage = $src;
  10378. $this->watermark_size = $size;
  10379. $this->watermark_pos = $pos;
  10380. }
  10381. /*-- END WATERMARK --*/
  10382. //Page footer
  10383. function Footer() {
  10384. /*-- CSS-PAGE --*/
  10385. // PAGED MEDIA - CROP / CROSS MARKS from @PAGE
  10386. if ($this->show_marks == 'CROP') {
  10387. // Show TICK MARKS
  10388. $this->SetLineWidth(0.1); // = 0.1 mm
  10389. $this->SetDrawColor(0);
  10390. $l = 18; // Default length in mm of crop line
  10391. $m = 8; // Distance of crop mark from margin in mm
  10392. $b = 8; // Non-printable border at edge of paper sheet in mm
  10393. $ax1 = $b;
  10394. $bx = $this->page_box['outer_width_LR'] - $m;
  10395. $ax = max($ax1, $bx-$l);
  10396. $cx1 = $this->w - $b;
  10397. $dx = $this->w - $this->page_box['outer_width_LR'] + $m;
  10398. $cx = min($cx1, $dx+$l);
  10399. $ay1 = $b;
  10400. $by = $this->page_box['outer_width_TB'] - $m;
  10401. $ay = max($ay1, $by-$l);
  10402. $cy1 = $this->h - $b;
  10403. $dy = $this->h - $this->page_box['outer_width_TB'] + $m;
  10404. $cy = min($cy1, $dy+$l);
  10405. $this->Line($ax, $this->page_box['outer_width_TB'], $bx, $this->page_box['outer_width_TB']);
  10406. $this->Line($cx, $this->page_box['outer_width_TB'], $dx, $this->page_box['outer_width_TB']);
  10407. $this->Line($ax, $this->h - $this->page_box['outer_width_TB'], $bx, $this->h - $this->page_box['outer_width_TB']);
  10408. $this->Line($cx, $this->h - $this->page_box['outer_width_TB'], $dx, $this->h - $this->page_box['outer_width_TB']);
  10409. $this->Line($this->page_box['outer_width_LR'], $ay, $this->page_box['outer_width_LR'], $by);
  10410. $this->Line($this->page_box['outer_width_LR'], $cy, $this->page_box['outer_width_LR'], $dy);
  10411. $this->Line($this->w - $this->page_box['outer_width_LR'], $ay, $this->w - $this->page_box['outer_width_LR'], $by);
  10412. $this->Line($this->w - $this->page_box['outer_width_LR'], $cy, $this->w - $this->page_box['outer_width_LR'], $dy);
  10413. }
  10414. if ($this->show_marks == 'CROSS') {
  10415. $this->SetLineWidth(0.1); // = 0.1 mm
  10416. $this->SetDrawColor(0);
  10417. $l = 14 /2; // longer length of the cross line (half)
  10418. $w = 6 /2; // shorter width of the cross line (half)
  10419. $r = 1.2; // radius of circle
  10420. $m = 10; // Distance of cross mark from margin in mm
  10421. $x1 = $this->page_box['outer_width_LR'] - $m;
  10422. $x2 = $this->w - $this->page_box['outer_width_LR'] + $m;
  10423. $y1 = $this->page_box['outer_width_TB'] - $m;
  10424. $y2 = $this->h - $this->page_box['outer_width_TB'] + $m;
  10425. // Left
  10426. $this->Circle($x1, $this->h/2, $r, 'S') ;
  10427. $this->Line($x1-$w, $this->h/2, $x1+$w, $this->h/2);
  10428. $this->Line($x1, $this->h/2-$l, $x1, $this->h/2+$l);
  10429. // Right
  10430. $this->Circle($x2, $this->h/2, $r, 'S') ;
  10431. $this->Line($x2-$w, $this->h/2, $x2+$w, $this->h/2);
  10432. $this->Line($x2, $this->h/2-$l, $x2, $this->h/2+$l);
  10433. // Top
  10434. $this->Circle($this->w/2, $y1, $r, 'S') ;
  10435. $this->Line($this->w/2, $y1-$w, $this->w/2, $y1+$w);
  10436. $this->Line($this->w/2-$l, $y1, $this->w/2+$l, $y1);
  10437. // Bottom
  10438. $this->Circle($this->w/2, $y2, $r, 'S') ;
  10439. $this->Line($this->w/2, $y2-$w, $this->w/2, $y2+$w);
  10440. $this->Line($this->w/2-$l, $y2, $this->w/2+$l, $y2);
  10441. }
  10442. // If @page set non-HTML headers/footers named, they were not read until later in the HTML code - so now set them
  10443. if ($this->page==1) {
  10444. if ($this->firstPageBoxHeader) {
  10445. $this->headerDetails['odd'] = $this->pageheaders[$this->firstPageBoxHeader];
  10446. $this->Header();
  10447. }
  10448. if ($this->firstPageBoxFooter) {
  10449. $this->footerDetails['odd'] = $this->pagefooters[$this->firstPageBoxFooter];
  10450. }
  10451. $this->firstPageBoxHeader='';
  10452. $this->firstPageBoxFooter='';
  10453. }
  10454. /*-- END CSS-PAGE --*/
  10455. /*-- HTMLHEADERS-FOOTERS --*/
  10456. if (($this->mirrorMargins && ($this->page%2==0) && $this->HTMLFooterE) || ($this->mirrorMargins && ($this->page%2==1) && $this->HTMLFooter) || (!$this->mirrorMargins && $this->HTMLFooter)) {
  10457. $this->writeHTMLFooters();
  10458. /*-- WATERMARK --*/
  10459. if (($this->watermarkText) && ($this->showWatermarkText)) {
  10460. $this->watermark( $this->watermarkText, 45, 120, $this->watermarkTextAlpha); // Watermark text
  10461. }
  10462. if (($this->watermarkImage) && ($this->showWatermarkImage)) {
  10463. $this->watermarkImg( $this->watermarkImage, $this->watermarkImageAlpha); // Watermark image
  10464. }
  10465. /*-- END WATERMARK --*/
  10466. return;
  10467. }
  10468. /*-- END HTMLHEADERS-FOOTERS --*/
  10469. $this->processingHeader=true;
  10470. $this->ResetMargins(); // necessary after columns
  10471. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  10472. /*-- WATERMARK --*/
  10473. if (($this->watermarkText) && ($this->showWatermarkText)) {
  10474. $this->watermark( $this->watermarkText, 45, 120, $this->watermarkTextAlpha); // Watermark text
  10475. }
  10476. if (($this->watermarkImage) && ($this->showWatermarkImage)) {
  10477. $this->watermarkImg( $this->watermarkImage, $this->watermarkImageAlpha); // Watermark image
  10478. }
  10479. /*-- END WATERMARK --*/
  10480. $h = $this->footerDetails;
  10481. if(count($h)) {
  10482. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10483. $this->_out(sprintf('q 0 -1 1 0 0 %.3f cm ',($this->h*$this->k)));
  10484. $headerpgwidth = $this->h - $this->orig_lMargin - $this->orig_rMargin;
  10485. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  10486. $headerlmargin = $this->orig_rMargin;
  10487. }
  10488. else {
  10489. $headerlmargin = $this->orig_lMargin;
  10490. }
  10491. }
  10492. else {
  10493. $yadj = 0;
  10494. $headerpgwidth = $this->pgwidth;
  10495. $headerlmargin = $this->lMargin;
  10496. }
  10497. $this->SetY(-$this->margin_footer);
  10498. $this->SetTextColor(0);
  10499. $this->SUP = false;
  10500. $this->SUB = false;
  10501. $this->bullet = false;
  10502. // only show pagenumber if numbering on
  10503. // mPDF 3.0 Add PageNum prefix/suffix
  10504. $pgno = $this->docPageNum($this->page, true);
  10505. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  10506. $side = 'even';
  10507. }
  10508. else { // ODD // OR NOT MIRRORING MARGINS/FOOTERS = DEFAULT
  10509. $side = 'odd';
  10510. }
  10511. $maxfontheight = 0;
  10512. foreach(array('L','C','R') AS $pos) {
  10513. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  10514. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  10515. else { $hfsz = $this->default_font_size; }
  10516. $maxfontheight = max($maxfontheight,$hfsz);
  10517. }
  10518. }
  10519. // LEFT-CENTER-RIGHT
  10520. foreach(array('L','C','R') AS $pos) {
  10521. if (isset($h[$side][$pos]['content']) && $h[$side][$pos]['content']) {
  10522. $hd = str_replace('{PAGENO}',$pgno,$h[$side][$pos]['content']);
  10523. // mPDF 3.0
  10524. $hd = str_replace($this->aliasNbPgGp,$this->nbpgPrefix.$this->aliasNbPgGp.$this->nbpgSuffix,$hd); // {nbpg}
  10525. $hd = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$hd);
  10526. if (isset($h[$side][$pos]['font-family']) && $h[$side][$pos]['font-family']) { $hff = $h[$side][$pos]['font-family']; }
  10527. // mPDF 3.0 original_ in case pagebreak in middle of table
  10528. else { $hff = $this->original_default_font; }
  10529. if (isset($h[$side][$pos]['font-size']) && $h[$side][$pos]['font-size']) { $hfsz = $h[$side][$pos]['font-size']; }
  10530. // mPDF 3.0 original_ in case pagebreak in middle of table
  10531. else { $hfsz = $this->original_default_font_size; }
  10532. $maxfontheight = max($maxfontheight,$hfsz);
  10533. if (isset($h[$side][$pos]['font-style']) && $h[$side][$pos]['font-style']) { $hfst = $h[$side][$pos]['font-style']; }
  10534. else { $hfst = ''; }
  10535. if (isset($h[$side][$pos]['color']) && $h[$side][$pos]['color']) {
  10536. $hfcol = $h[$side][$pos]['color'];
  10537. $cor = $this->ConvertColor($hfcol);
  10538. if ($cor) { $this->SetTextColor($cor['R'],$cor['G'],$cor['B']); }
  10539. }
  10540. else { $hfcol = ''; }
  10541. // mPDF 3.0 Force output
  10542. $this->SetFont($hff,$hfst,$hfsz,true,true);
  10543. $this->x = $headerlmargin ;
  10544. // mPDF 4.0
  10545. // $this->y = $this->h - $this->margin_footer - ($maxfontheight/$this->k * 0.5) - 0.5;
  10546. $this->y = $this->h - $this->margin_footer - ($maxfontheight/$this->k);
  10547. $hd = $this->purify_utf8_text($hd);
  10548. if ($this->text_input_as_HTML) {
  10549. $hd = $this->all_entities_to_utf8($hd);
  10550. }
  10551. // CONVERT CODEPAGE
  10552. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10553. //if (!$this->is_MB) { $hd = mb_convert_encoding($hd,$this->mb_enc,'UTF-8'); }
  10554. if (!$this->is_MB) { $hd = api_convert_encoding($hd,$this->mb_enc,'UTF-8'); }
  10555. //
  10556. // DIRECTIONALITY RTL
  10557. $this->magic_reverse_dir($hd); // *RTL*
  10558. // mPDF 4.0 Font-specific ligature substitution for Indic fonts
  10559. $this->ConvertIndic($hd); // *INDIC*
  10560. $align = $pos;
  10561. if ($this->directionality == 'rtl') {
  10562. if ($pos == 'L') { $align = 'R'; }
  10563. else if ($pos == 'R') { $align = 'L'; }
  10564. }
  10565. if ($pos!='L' && (stripos($hd,$this->aliasNbPg)!==false || stripos($hd,$this->aliasNbPgGp)!==false)) {
  10566. if (stripos($hd,$this->aliasNbPgGp)!==false) { $type= 'nbpggp'; } else { $type= 'nbpg'; }
  10567. $this->_out('{mpdfheader'.$type.' '.$pos.' ff='.$hff.' fs='.$hfst.' fz='.$hfsz.'}');
  10568. // mPDF 4.0
  10569. $this->Cell($headerpgwidth ,$maxfontheight/$this->k ,$hd,0,0,$align,0,'',0,0,0,'M');
  10570. $this->_out('Q');
  10571. }
  10572. else {
  10573. // mPDF 4.0
  10574. $this->Cell($headerpgwidth ,$maxfontheight/$this->k ,$hd,0,0,$align,0,'',0,0,0,'M');
  10575. }
  10576. if ($hfcol) { $this->SetTextColor(0); }
  10577. }
  10578. }
  10579. // Return Font to normal
  10580. $this->SetFont($this->default_font,'',$this->original_default_font_size);
  10581. // LINE
  10582. // mPDF 4.0
  10583. if (isset($h[$side]['line']) && $h[$side]['line']) {
  10584. $this->SetLineWidth(0.1);
  10585. $this->SetDrawColor(0);
  10586. // mPDF 4.0
  10587. $this->Line($headerlmargin , $this->y-($maxfontheight*($this->footer_line_spacing)/$this->k), $headerlmargin +$headerpgwidth, $this->y-($maxfontheight*($this->footer_line_spacing)/$this->k));
  10588. }
  10589. if ($this->forcePortraitHeaders && $this->CurOrientation=='L' && $this->CurOrientation!=$this->DefOrientation) {
  10590. $this->_out('Q');
  10591. }
  10592. }
  10593. $this->processingHeader=false;
  10594. }
  10595. /*-- HYPHENATION --*/
  10596. ///////////////////
  10597. ///////////////////
  10598. // HYPHENATION
  10599. ///////////////////
  10600. // Soft hyphs
  10601. function softHyphenate($word, $maxWidth) {
  10602. // Don't hyphenate web addresses
  10603. if (preg_match('/^(http:|www\.)/',$word)) { return array(false,'','',''); }
  10604. // Get dictionary
  10605. $poss = array();
  10606. $softhyphens = array();
  10607. $offset = 0;
  10608. $p = true;
  10609. if ($this->is_MB) { // *UNICODE-FONTS*
  10610. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10611. //$wl = mb_strlen($word,'UTF-8'); // *UNICODE-FONTS*
  10612. $wl = api_strlen($word,'UTF-8'); // *UNICODE-FONTS*
  10613. //
  10614. } // *UNICODE-FONTS*
  10615. else { // *UNICODE-FONTS*
  10616. $wl = strlen($word);
  10617. } // *UNICODE-FONTS*
  10618. while($offset < $wl) {
  10619. /*-- UNICODE-FONTS --*/
  10620. if ($this->is_MB) {
  10621. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10622. //$p = mb_strpos($word, "\xc2\xad", $offset, 'UTF-8');
  10623. $p = api_strpos($word, "\xc2\xad", $offset, 'UTF-8');
  10624. //
  10625. }
  10626. // mPDF 3.0 Soft Hyphens chr(173)
  10627. else
  10628. /*-- END UNICODE-FONTS --*/
  10629. if ($this->FontFamily!='symbol' && $this->FontFamily!='zapfdingbats') {
  10630. $p = strpos($word, chr(173), $offset);
  10631. }
  10632. if ($p !== false) { $poss[] = $p - count($poss); }
  10633. else { break; }
  10634. $offset = $p+1;
  10635. }
  10636. $success = false;
  10637. foreach($poss AS $i) {
  10638. /*-- UNICODE-FONTS --*/
  10639. if ($this->is_MB) {
  10640. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10641. //$a = mb_substr($word,0,$i,'UTF-8');
  10642. $a = api_substr($word,0,$i,'UTF-8');
  10643. //
  10644. if ($this->GetStringWidth($a.'-') > $maxWidth) { break ; }
  10645. $pre = $a;
  10646. // Modified by Ivan Tcholakov, 28-JUN-2010.
  10647. //$post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8'); // mPDF 4.2.009
  10648. //$prelength = mb_strlen($pre, 'UTF-8');
  10649. $post = api_substr($word,$i,api_strlen($word,'UTF-8'),'UTF-8'); // mPDF 4.2.009
  10650. $prelength = api_strlen($pre, 'UTF-8');
  10651. //
  10652. }
  10653. else {
  10654. /*-- END UNICODE-FONTS --*/
  10655. $a = substr($word,0,$i);
  10656. if ($this->GetStringWidth($a.'-') > $maxWidth) { break ; }
  10657. $pre = $a;
  10658. $post = substr($word,$i,strlen($word)); // mPDF 4.2.009
  10659. $prelength = strlen($pre);
  10660. } // *UNICODE-FONTS*
  10661. $success = true;
  10662. }
  10663. return array($success,$pre,$post,$prelength);
  10664. }
  10665. ///////////////////
  10666. // Word hyphenation
  10667. function hyphenateWord($word, $maxWidth) {
  10668. // Do everything inside this function in utf-8
  10669. // Don't hyphenate web addresses
  10670. if (preg_match('/^(http:|www\.)/',$word)) { return array(false,'','',''); }
  10671. // Get dictionary
  10672. if (!$this->loadedSHYdictionary) {
  10673. if (file_exists(_MPDF_PATH.'patterns/dictionary.txt')) {
  10674. $this->SHYdictionary = file(_MPDF_PATH.'patterns/dictionary.txt',FILE_SKIP_EMPTY_LINES);
  10675. foreach($this->SHYdictionary as $entry) {
  10676. $entry = trim($entry);
  10677. $poss = array();
  10678. $offset = 0;
  10679. $p = true;
  10680. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10681. //$wl = mb_strlen($entry ,'UTF-8');
  10682. $wl = api_strlen($entry ,'UTF-8');
  10683. //
  10684. while($offset < $wl) {
  10685. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10686. //$p = mb_strpos($entry, '/', $offset, 'UTF-8');
  10687. $p = api_strpos($entry, '/', $offset, 'UTF-8');
  10688. //
  10689. if ($p !== false) { $poss[] = $p - count($poss); }
  10690. else { break; }
  10691. $offset = $p+1;
  10692. }
  10693. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10694. //if (count($poss)) { $this->SHYdictionaryWords[str_replace('/', '', mb_strtolower($entry))] = $poss; }
  10695. if (count($poss)) { $this->SHYdictionaryWords[str_replace('/', '', api_strtolower($entry))] = $poss; }
  10696. //
  10697. }
  10698. }
  10699. $this->loadedSHYdictionary = true;
  10700. }
  10701. if (!in_array($this->SHYlang,$this->SHYlanguages)) { return array(false,'','',''); }
  10702. // If no pattern loaded or not the best one
  10703. if (count($this->SHYpatterns) < 1 || ($this->loadedSHYpatterns && $this->loadedSHYpatterns != $this->SHYlang)) {
  10704. include(_MPDF_PATH."patterns/" . $this->SHYlang . ".php");
  10705. $patterns = explode(' ', $patterns); // mPDF 4.4.012
  10706. $new_patterns = array();
  10707. for($i = 0; $i < count($patterns); $i++) {
  10708. $value = $patterns[$i];
  10709. $new_patterns[preg_replace('/[0-9]/', '', $value)] = $value; // mPDF 4.4.012
  10710. }
  10711. $this->SHYpatterns = $new_patterns;
  10712. $this->loadedSHYpatterns = $this->SHYlang;
  10713. }
  10714. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10715. //if (!$this->is_MB) { $word = mb_convert_encoding($word,'UTF-8',$this->mb_enc); }
  10716. if (!$this->is_MB) { $word = api_convert_encoding($word,'UTF-8',$this->mb_enc); }
  10717. //
  10718. $prepre = '';
  10719. $postpost = '';
  10720. $startpunctuation = "\xc2\xab\xc2\xbf\xe2\x80\x98\xe2\x80\x9b\xe2\x80\x9c\xe2\x80\x9f";
  10721. $endpunctuation = "\xe2\x80\x9e\xe2\x80\x9d\xe2\x80\x9a\xe2\x80\x99\xc2\xbb";
  10722. $pre = '';
  10723. $post = '';
  10724. if (preg_match('/^(["\''.$startpunctuation .'])+(.{'.$this->SHYcharmin.',})$/u',$word,$m)) {
  10725. $prepre = $m[1];
  10726. $word = $m[2];
  10727. }
  10728. if (preg_match('/^(.{'.$this->SHYcharmin.',})([\'\.,;:!?"'.$endpunctuation .']+)$/u',$word,$m)) {
  10729. $word = $m[1];
  10730. $postpost = $m[2];
  10731. }
  10732. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10733. //if(mb_strlen($word,'UTF-8') < $this->SHYcharmin) {
  10734. if(api_strlen($word,'UTF-8') < $this->SHYcharmin) {
  10735. //
  10736. return array(false,'','','');
  10737. }
  10738. $success = false;
  10739. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10740. //if(isset($this->SHYdictionaryWords[mb_strtolower($word)])) {
  10741. // foreach($this->SHYdictionaryWords[mb_strtolower($word)] AS $i) {
  10742. // $a = $prepre . mb_substr($word,0,$i,'UTF-8');
  10743. // if (!$this->is_MB) { $testa = mb_convert_encoding($a,$this->mb_enc,'UTF-8'); }
  10744. if(isset($this->SHYdictionaryWords[api_strtolower($word)])) {
  10745. foreach($this->SHYdictionaryWords[api_strtolower($word)] AS $i) {
  10746. $a = $prepre . api_substr($word,0,$i,'UTF-8');
  10747. if (!$this->is_MB) { $testa = api_convert_encoding($a,$this->mb_enc,'UTF-8'); }
  10748. //
  10749. else { $testa = $a; }
  10750. if ($this->GetStringWidth($testa.'-') > $maxWidth) { break ; }
  10751. $pre = $a;
  10752. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10753. //$post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8') . $postpost; // mPDF 4.2.009
  10754. $post = api_substr($word,$i,api_strlen($word,'UTF-8'),'UTF-8') . $postpost; // mPDF 4.2.009
  10755. //
  10756. $success = true;
  10757. }
  10758. }
  10759. if (!$success) {
  10760. $text_word = '_' . $word . '_';
  10761. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10762. //$word_length = mb_strlen($text_word,'UTF-8');
  10763. $word_length = api_strlen($text_word,'UTF-8');
  10764. //
  10765. $single_character = preg_split('//u', $text_word);
  10766. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10767. //$text_word = mb_strtolower($text_word,'UTF-8');
  10768. $text_word = api_strtolower($text_word,'UTF-8');
  10769. //
  10770. $hyphenated_word = array();
  10771. $numb3rs = array('0' => true, '1' => true, '2' => true, '3' => true, '4' => true, '5' => true, '6' => true, '7' => true, '8' => true, '9' => true);
  10772. for($position = 0; $position <= ($word_length - $this->SHYcharmin); $position++) {
  10773. $maxwins = min(($word_length - $position), $this->SHYcharmax);
  10774. for($win = $this->SHYcharmin; $win <= $maxwins; $win++) {
  10775. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10776. //if(isset($this->SHYpatterns[mb_substr($text_word, $position, $win,'UTF-8')])) {
  10777. // $pattern = $this->SHYpatterns[mb_substr($text_word, $position, $win,'UTF-8')];
  10778. if(isset($this->SHYpatterns[api_substr($text_word, $position, $win,'UTF-8')])) {
  10779. $pattern = $this->SHYpatterns[api_substr($text_word, $position, $win,'UTF-8')];
  10780. //
  10781. $digits = 1;
  10782. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10783. //$pattern_length = mb_strlen($pattern,'UTF-8');
  10784. $pattern_length = api_strlen($pattern,'UTF-8');
  10785. //
  10786. for($i = 0; $i < $pattern_length; $i++) {
  10787. $char = $pattern[$i];
  10788. if(isset($numb3rs[$char])) {
  10789. $zero = ($i == 0) ? $position - 1 : $position + $i - $digits;
  10790. if(!isset($hyphenated_word[$zero]) || $hyphenated_word[$zero] != $char) $hyphenated_word[$zero] = $char;
  10791. $digits++;
  10792. }
  10793. }
  10794. }
  10795. }
  10796. }
  10797. // Modified by Ivan Tcholakov, 28-JUN-2010.
  10798. //for($i = $this->SHYleftmin; $i <= (mb_strlen($word,'UTF-8') - $this->SHYrightmin); $i++) {
  10799. //if(isset($hyphenated_word[$i]) && $hyphenated_word[$i] % 2 != 0) {
  10800. // $a = $prepre . mb_substr($word,0,$i,'UTF-8');
  10801. // if (!$this->is_MB) { $testa = mb_convert_encoding($a,$this->mb_enc,'UTF-8'); }
  10802. for($i = $this->SHYleftmin; $i <= (api_strlen($word,'UTF-8') - $this->SHYrightmin); $i++) {
  10803. if(isset($hyphenated_word[$i]) && $hyphenated_word[$i] % 2 != 0) {
  10804. $a = $prepre . api_substr($word,0,$i,'UTF-8');
  10805. if (!$this->is_MB) { $testa = api_convert_encoding($a,$this->mb_enc,'UTF-8'); }
  10806. //
  10807. else { $testa = $a; }
  10808. if ($this->GetStringWidth($testa.'-') > $maxWidth + 0.0001) { break ; }
  10809. $pre = $a;
  10810. // Modified by Ivan Tcholakov, 28-JUN-2010.
  10811. //$post = mb_substr($word,$i,mb_strlen($word,'UTF-8'),'UTF-8') . $postpost; // mPDF 4.2.009
  10812. $post = api_substr($word,$i,api_strlen($word,'UTF-8'),'UTF-8') . $postpost; // mPDF 4.2.009
  10813. //
  10814. $success = true;
  10815. }
  10816. }
  10817. }
  10818. if (!$this->is_MB) {
  10819. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10820. //$pre = mb_convert_encoding($pre,$this->mb_enc,'UTF-8');
  10821. //$post = mb_convert_encoding($post,$this->mb_enc,'UTF-8');
  10822. $pre = api_convert_encoding($pre,$this->mb_enc,'UTF-8');
  10823. $post = api_convert_encoding($post,$this->mb_enc,'UTF-8');
  10824. //
  10825. $prelength = strlen($pre);
  10826. }
  10827. else {
  10828. // Modified by Ivan Tcholakov, 28-JAN-2010.
  10829. //$prelength = mb_strlen($pre);
  10830. $prelength = api_strlen($pre);
  10831. //
  10832. }
  10833. return array($success,$pre,$post,$prelength);
  10834. }
  10835. /*-- END HYPHENATION --*/
  10836. ///////////////////
  10837. /// HTML parser ///
  10838. ///////////////////
  10839. function WriteHTML($html,$sub=0,$init=true,$close=true) {
  10840. // $sub ADDED - 0 = default; 1=headerCSS only; 2=HTML body (parts) only; 3 - HTML parses only
  10841. // 4 - writes HTML headers
  10842. // $close Leaves buffers etc. in current state, so that it can continue a block etc.
  10843. // $init - Clears and sets buffers to Top level block etc.
  10844. // mPDF 4.2.018
  10845. if ($this->PDFA) { // default font may be set as core when win-1252 and PDFA not set until runtime
  10846. reset($this->fonts);
  10847. $df = key($this->fonts);
  10848. if ($df=='times' || $df == 'helvetica' || $df == 'courier') {
  10849. unset($this->fonts[$df]);
  10850. }
  10851. }
  10852. // mPDF 4.2
  10853. if (empty($html)) { $html = ''; }
  10854. if ($this->progressBar) { $this->UpdateProgressBar(1,0,'Parsing CSS & Headers'); } // *PROGRESS-BAR*
  10855. if ($init) {
  10856. $this->headerbuffer='';
  10857. $this->textbuffer = array();
  10858. // mPDF 4.0 Fixed Pos block
  10859. $this->fixedPosBlockSave = array();
  10860. }
  10861. if ($sub == 1) { $html = '<style> '.$html.' </style>'; } // stylesheet only
  10862. if ($this->allow_charset_conversion) {
  10863. if ($sub < 1) {
  10864. $this->ReadCharset($html);
  10865. }
  10866. if ($this->charset_in) {
  10867. $success = iconv($this->charset_in,'UTF-8//TRANSLIT',$html);
  10868. if ($success) { $html = $success; }
  10869. }
  10870. }
  10871. $html = $this->purify_utf8($html,false);
  10872. if ($init) {
  10873. $this->blklvl = 0;
  10874. $this->lastblocklevelchange = 0;
  10875. $this->blk = array();
  10876. // mPDF 4.0
  10877. $this->initialiseBlock($this->blk[0]);
  10878. $this->blk[0]['width'] =& $this->pgwidth;
  10879. $this->blk[0]['inner_width'] =& $this->pgwidth;
  10880. // mPDF 3.0
  10881. $this->blk[0]['blockContext'] = $this->blockContext;
  10882. }
  10883. if ($sub < 2) {
  10884. $this->ReadMetaTags($html);
  10885. // NB default stylesheet now in mPDF.css - read on initialising class
  10886. $html = $this->ReadCSS($html);
  10887. }
  10888. // SET Blocklevel[0] CSS if defined in <body> or from default
  10889. $properties = $this->MergeCSS('BLOCK','BODY','');
  10890. if ($sub == 1) { $this->setCSS($properties,'','BODY'); return ''; }
  10891. if ($sub < 2) {
  10892. /*-- UNICODE-FONTS --*/
  10893. if ($this->useLang && $this->is_MB && preg_match('/<html [^>]*lang=[\'\"](.*?)[\'\"]/ism',$html,$m)) {
  10894. $html_lang = $m[1];
  10895. }
  10896. /*-- END UNICODE-FONTS --*/
  10897. // allow in-line CSS for body tag to be parsed // Get <body> tag inline CSS
  10898. if (preg_match('/<body([^>]*)>(.*?)<\/body>/ism',$html,$m) || preg_match('/<body([^>]*)>(.*)$/ism',$html,$m)) {
  10899. $html = $m[2];
  10900. // mPDF 3.0 - Tiling Patterns
  10901. // Changed to allow style="background: url('bg.jpg')"
  10902. if (preg_match('/style=[\"](.*?)[\"]/ism',$m[1],$mm) || preg_match('/style=[\'](.*?)[\']/ism',$m[1],$mm)) {
  10903. $zproperties = $this->readInlineCSS($mm[1]);
  10904. $properties = $this->array_merge_recursive_unique($properties,$zproperties);
  10905. }
  10906. /*-- UNICODE-FONTS --*/
  10907. if (isset($html_lang) && $html_lang) { $properties['LANG'] = $html_lang; }
  10908. if ($this->useLang && $this->is_MB && preg_match('/lang=[\'\"](.*?)[\'\"]/ism',$m[1],$mm)) {
  10909. $properties['LANG'] = $mm[1];
  10910. }
  10911. /*-- END UNICODE-FONTS --*/
  10912. }
  10913. }
  10914. $this->setCSS($properties,'','BODY');
  10915. if (!isset($this->CSS['BODY'])) { $this->CSS['BODY'] = array(); }
  10916. // mPDF 4.0 Not required(?) and messing up text-align for RTL
  10917. // $this->CSS['BODY'] = $this->array_merge_recursive_unique($this->CSS['BODY'], $properties);
  10918. /*-- GRADIENTS --*/
  10919. if (isset($properties['BACKGROUND-GRADIENT'])) {
  10920. $this->bodyBackgroundGradient = $properties['BACKGROUND-GRADIENT'];
  10921. }
  10922. /*-- END GRADIENTS --*/
  10923. /*-- BACKGROUND-IMAGES --*/
  10924. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE']) { // mPDF 4.3.011
  10925. $file = $properties['BACKGROUND-IMAGE'];
  10926. $sizesarray = $this->Image($file,0,0,0,0,'','',false, false, false, false, false); // mPDF 4.2.032
  10927. if (isset($sizesarray['IMAGE_ID'])) {
  10928. $image_id = $sizesarray['IMAGE_ID'];
  10929. $orig_w = $sizesarray['WIDTH']*$this->k; // in user units i.e. mm
  10930. $orig_h = $sizesarray['HEIGHT']*$this->k; // (using $this->img_dpi)
  10931. $x_repeat = true;
  10932. $y_repeat = true;
  10933. if (isset($properties['BACKGROUND-REPEAT'])) {
  10934. if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-x') { $y_repeat = false; }
  10935. if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-y') { $x_repeat = false; }
  10936. }
  10937. $x_pos = 0;
  10938. $y_pos = 0;
  10939. if (isset($properties['BACKGROUND-POSITION'])) {
  10940. $ppos = preg_split('/\s+/',$properties['BACKGROUND-POSITION']);
  10941. $x_pos = $ppos[0];
  10942. $y_pos = $ppos[1];
  10943. if (!stristr($x_pos ,'%') ) { $x_pos = $this->ConvertSize($x_pos ,$this->pgwidth,$this->FontSize); }
  10944. if (!stristr($y_pos ,'%') ) { $y_pos = $this->ConvertSize($y_pos ,$this->pgwidth,$this->FontSize); }
  10945. }
  10946. // mPDF 4.3.015
  10947. if (isset($properties['BACKGROUND-IMAGE-RESIZE'])) { $resize = $properties['BACKGROUND-IMAGE-RESIZE']; }
  10948. else { $resize = 0; }
  10949. // mPDF 4.3.017
  10950. if (isset($properties['BACKGROUND-IMAGE-OPACITY'])) { $opacity = $properties['BACKGROUND-IMAGE-OPACITY']; }
  10951. else { $opacity = 1; }
  10952. $this->bodyBackgroundImage = 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); // mPDF 4.3.015 4.3.017
  10953. }
  10954. }
  10955. /*-- END BACKGROUND-IMAGES --*/
  10956. /*-- CSS-PAGE --*/
  10957. // mPDF 4.2
  10958. // If page-box is set
  10959. if ($this->state==0 && $this->CSS['@PAGE']) {
  10960. $this->page_box['current'] = '';
  10961. $this->page_box['using'] = true;
  10962. // mPDF 4.2
  10963. list($pborientation,$pbmgl,$pbmgr,$pbmgt,$pbmgb,$pbmgh,$pbmgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS('', false, 'O');
  10964. $this->DefOrientation = $this->CurOrientation = $pborientation;
  10965. $this->orig_lMargin = $this->DeflMargin = $pbmgl;
  10966. $this->orig_rMargin = $this->DefrMargin = $pbmgr;
  10967. $this->orig_tMargin = $this->tMargin = $pbmgt;
  10968. $this->orig_bMargin = $this->bMargin = $pbmgb;
  10969. $this->orig_hMargin = $this->margin_header = $pbmgh;
  10970. $this->orig_fMargin = $this->margin_footer = $pbmgf;
  10971. list($pborientation,$pbmgl,$pbmgr,$pbmgt,$pbmgb,$pbmgh,$pbmgf,$hname,$fname,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat) = $this->SetPagedMediaCSS('', true, 'O'); // first page
  10972. $this->show_marks = $marks;
  10973. if ($hname && !preg_match('/^html_(.*)$/i',$hname)) $this->firstPageBoxHeader = $hname;
  10974. if ($fname && !preg_match('/^html_(.*)$/i',$fname)) $this->firstPageBoxFooter = $fname;
  10975. }
  10976. /*-- END CSS-PAGE --*/
  10977. if($this->state==0 && $sub!=1 && $sub!=3 && $sub!=4) {
  10978. $this->AddPage($this->CurOrientation);
  10979. }
  10980. $parseonly = false;
  10981. $this->bufferoutput = false;
  10982. if ($sub == 3) {
  10983. $parseonly = true;
  10984. // Close any open block tags
  10985. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  10986. // Output any text left in buffer
  10987. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); }
  10988. $this->textbuffer=array();
  10989. }
  10990. else if ($sub == 4) {
  10991. // Close any open block tags
  10992. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  10993. // Output any text left in buffer
  10994. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); }
  10995. $this->bufferoutput = true;
  10996. $this->textbuffer=array();
  10997. $this->headerbuffer='';
  10998. $properties = $this->MergeCSS('BLOCK','BODY','');
  10999. $this->setCSS($properties,'','BODY');
  11000. }
  11001. // Modified by Ivan Tcholakov, 28-JAN-2010.
  11002. //mb_internal_encoding('UTF-8');
  11003. _api_mb_internal_encoding('UTF-8');
  11004. //
  11005. $html = $this->AdjustHTML($html,$this->directionality,$this->usepre, $this->tabSpaces); //Try to make HTML look more like XHTML
  11006. if ($this->autoFontGroups) { $html = $this->AutoFont($html); }
  11007. /*-- HTMLHEADERS-FOOTERS --*/
  11008. preg_match_all('/<htmlpageheader([^>]*)>(.*?)<\/htmlpageheader>/si',$html,$h);
  11009. for($i=0;$i<count($h[1]);$i++) {
  11010. if (preg_match('/name=[\'|\"](.*?)[\'|\"]/',$h[1][$i],$n)) {
  11011. // mPDF 4.0
  11012. $this->pageHTMLheaders[$n[1]]['html'] = $h[2][$i];
  11013. $this->pageHTMLheaders[$n[1]]['h'] = $this->_gethtmlheight($h[2][$i]);
  11014. }
  11015. }
  11016. preg_match_all('/<htmlpagefooter([^>]*)>(.*?)<\/htmlpagefooter>/si',$html,$f);
  11017. for($i=0;$i<count($f[1]);$i++) {
  11018. if (preg_match('/name=[\'|\"](.*?)[\'|\"]/',$f[1][$i],$n)) {
  11019. // mPDF 4.0
  11020. $this->pageHTMLfooters[$n[1]]['html'] = $f[2][$i];
  11021. $this->pageHTMLfooters[$n[1]]['h'] = $this->_gethtmlheight($f[2][$i]);
  11022. }
  11023. }
  11024. /*-- END HTMLHEADERS-FOOTERS --*/
  11025. $html = preg_replace('/<htmlpageheader.*?<\/htmlpageheader>/si','',$html);
  11026. $html = preg_replace('/<htmlpagefooter.*?<\/htmlpagefooter>/si','',$html);
  11027. /*-- HTMLHEADERS-FOOTERS --*/
  11028. // mPDF 4.2
  11029. if (isset($hname) && preg_match('/^html_(.*)$/i',$hname,$n)) $this->SetHTMLHeader($this->pageHTMLheaders[$n[1]],'O',true);
  11030. if (isset($fname) && preg_match('/^html_(.*)$/i',$fname,$n)) $this->SetHTMLFooter($this->pageHTMLfooters[$n[1]],'O');
  11031. /*-- END HTMLHEADERS-FOOTERS --*/
  11032. $html=str_replace('<?','< ',$html); //Fix '<?XML' bug from HTML code generated by MS Word
  11033. $html = $this->SubstituteChars($html);
  11034. // mPDF 4.0
  11035. if (preg_match("/([".$this->pregRTLchars."])/u", $html)) { $this->biDirectional = true; } // *RTL*
  11036. // Don't allow non-breaking spaces that are converted to substituted chars or will break anyway and mess up table width calc.
  11037. $html = str_replace('<tta>160</tta>',$this->chrs[32],$html);
  11038. $html = str_replace('</tta><tta>','|',$html);
  11039. $html = str_replace('</tts><tts>','|',$html);
  11040. $html = str_replace('</ttz><ttz>','|',$html);
  11041. //Add new supported tags in the DisableTags function
  11042. $html=strip_tags($html,$this->enabledtags); //remove all unsupported tags, but the ones inside the 'enabledtags' string
  11043. //Explode the string in order to parse the HTML code
  11044. $a=preg_split('/<(.*?)>/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  11045. // ? more accurate regexp that allows e.g. <a name="Silly <name>">
  11046. // if changing - also change in fn.SubstituteChars()
  11047. // $a = preg_split ('/<((?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+)>/ms', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
  11048. if ($this->mb_enc) {
  11049. // Modified by Ivan Tcholakov, 28-JAN-2010.
  11050. //mb_internal_encoding($this->mb_enc);
  11051. _api_mb_internal_encoding($this->mb_enc);
  11052. //
  11053. }
  11054. $pbc = 0; // *PROGRESS-BAR*
  11055. if ($this->progressBar) { $this->UpdateProgressBar(1,0); } // *PROGRESS-BAR*
  11056. $this->subPos = 0;
  11057. $cnt = count($a); // mPDF 4.2
  11058. for($i=0;$i<$cnt; $i++) { // mPDF 4.2
  11059. $e = $a[$i];
  11060. if($i%2==0) {
  11061. //TEXT
  11062. if ($this->blk[$this->blklvl]['hide']) { continue; }
  11063. // mPDF 4.0
  11064. if ($this->inFixedPosBlock) { $this->fixedPosBlock .= $e; continue; } // *CSS-POSITION*
  11065. if (strlen($e) == 0) { continue; }
  11066. $e = strcode2utf($e);
  11067. $e = $this->lesser_entity_decode($e);
  11068. /*-- UNICODE-FONTS --*/
  11069. // mPDF 4.2
  11070. // mPDF 4.3.004 Not specialcontent (textarea / select)
  11071. if ($this->useSubstitutionsMB && $this->is_MB && !$this->isCJK && !$this->usingCoreFont && $this->subPos<$i && !$this->specialcontent) {
  11072. $cnt += $this->SubstituteCharsMB($a, $i, $e);
  11073. }
  11074. /*-- END UNICODE-FONTS --*/
  11075. if (($this->directionality == 'rtl') || (($this->directionality == 'ltr') && ($this->biDirectional))) { // *RTL*
  11076. // mPDF 4.0 Removed rtlAsArabicFarsi
  11077. $e = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $e); // *RTL*
  11078. } // *RTL*
  11079. // mPDF 4.0 Font-specific ligature substitution for Indic fonts
  11080. $this->ConvertIndic($e); // *INDIC*
  11081. // CONVERT CODEPAGE
  11082. // Modified by Ivan Tcholakov, 28-JAN-2010.
  11083. //if (!$this->is_MB) { $e = mb_convert_encoding($e,$this->mb_enc,'UTF-8'); }
  11084. if (!$this->is_MB) { $e = api_convert_encoding($e,$this->mb_enc,'UTF-8'); }
  11085. //
  11086. /*-- UNICODE-FONTS --*/
  11087. if (($this->is_MB && !$this->isCJK) && (!$this->usingCoreFont)) {
  11088. // Modified by Ivan Tcholakov, 28-JAN-2010.
  11089. //if ($this->toupper) { $e = mb_strtoupper($e,$this->mb_enc); }
  11090. //if ($this->tolower) { $e = mb_strtolower($e,$this->mb_enc); }
  11091. if ($this->toupper) { $e = api_strtoupper($e,$this->mb_enc); }
  11092. if ($this->tolower) { $e = api_strtolower($e,$this->mb_enc); }
  11093. //
  11094. }
  11095. else
  11096. /*-- END UNICODE-FONTS --*/
  11097. if (!$this->isCJK) {
  11098. if ($this->toupper) { $e = strtoupper($e); }
  11099. if ($this->tolower) { $e = strtolower($e); }
  11100. }
  11101. if (($this->tts) || ($this->ttz) || ($this->tta)) {
  11102. $es = explode('|',$e);
  11103. $e = '';
  11104. foreach($es AS $val) {
  11105. $e .= $this->chrs[$val];
  11106. }
  11107. }
  11108. //Adjust lineheight
  11109. //$this->SetLineHeight($this->FontSizePt); //should be inside printbuffer? // does nothing
  11110. /*-- FORMS --*/
  11111. // FORM ELEMENTS
  11112. if ($this->specialcontent) {
  11113. //SELECT tag (form element)
  11114. if ($this->specialcontent == "type=select") {
  11115. $e = ltrim($e);
  11116. $stringwidth = $this->GetStringWidth($e);
  11117. if (!isset($this->selectoption['MAXWIDTH']) || $stringwidth > $this->selectoption['MAXWIDTH']) { $this->selectoption['MAXWIDTH'] = $stringwidth; }
  11118. if (!isset($this->selectoption['SELECTED']) || $this->selectoption['SELECTED'] == '') { $this->selectoption['SELECTED'] = $e; }
  11119. // mPDD 1.4 Active Forms
  11120. if (isset($this->selectoption['ACTIVE']) && $this->selectoption['ACTIVE']) {
  11121. $this->selectoption['ITEMS'][]=array('exportValue'=>$this->selectoption['currentVAL'], 'content'=>$e, 'selected'=>$this->selectoption['currentSEL']);
  11122. }
  11123. }
  11124. // TEXTAREA
  11125. else {
  11126. $objattr = unserialize($this->specialcontent);
  11127. $objattr['text'] = $e;
  11128. $te = "\xbb\xa4\xactype=textarea,objattr=".serialize($objattr)."\xbb\xa4\xac";
  11129. if ($this->tdbegin) {
  11130. $this->cell[$this->row][$this->col]['textbuffer'][] = array($te,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  11131. }
  11132. else {
  11133. $this->textbuffer[] = array($te,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  11134. }
  11135. }
  11136. }
  11137. /*-- END FORMS --*/
  11138. // TABLE
  11139. /*-- TABLES --*/
  11140. else if ($this->tableLevel) {
  11141. if ($this->tdbegin) {
  11142. if (($this->ignorefollowingspaces) and !$this->ispre) { $e = ltrim($e); }
  11143. if ($e || $e==='0') {
  11144. // mPDF 3.0
  11145. if (($this->blockjustfinished || $this->listjustfinished) && $this->cell[$this->row][$this->col]['s']>0) {
  11146. $this->cell[$this->row][$this->col]['textbuffer'][] = array("\n",$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  11147. $this->cell[$this->row][$this->col]['text'][] = "\n";
  11148. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  11149. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  11150. }
  11151. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  11152. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  11153. }
  11154. $this->cell[$this->row][$this->col]['s'] = 0;// reset
  11155. }
  11156. // mPDF 3.0
  11157. $this->blockjustfinished=false;
  11158. $this->listjustfinished=false;
  11159. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  11160. $this->cell[$this->row][$this->col]['text'][] = $e;
  11161. if (!isset($this->cell[$this->row][$this->col]['R']) || !$this->cell[$this->row][$this->col]['R']) {
  11162. if (isset($this->cell[$this->row][$this->col]['s'])) {
  11163. $this->cell[$this->row][$this->col]['s'] += $this->GetStringWidth($e);
  11164. }
  11165. else { $this->cell[$this->row][$this->col]['s'] = $this->GetStringWidth($e); }
  11166. }
  11167. if ($this->tableLevel==1 && $this->useGraphs) {
  11168. $this->graphs[$this->currentGraphId]['data'][$this->row][$this->col] = $e;
  11169. }
  11170. $this->nestedtablejustfinished = false;
  11171. // mPDF 3.0
  11172. $this->linebreakjustfinished=false;
  11173. }
  11174. }
  11175. }
  11176. /*-- END TABLES --*/
  11177. // ALL ELSE
  11178. else {
  11179. if ($this->ignorefollowingspaces and !$this->ispre) { $e = ltrim($e); }
  11180. if ($e || $e==='0') $this->textbuffer[] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  11181. }
  11182. }
  11183. else { // TAG **
  11184. // mPDF 4.0
  11185. if($e[0]=='/') { // mPDF 4.4.012
  11186. /*-- PROGRESS-BAR --*/
  11187. // mPDF 4.2 Progress bar
  11188. if ($this->progressBar) { // 10% increments
  11189. if (intval($i*10/$cnt) != $pbc) { $pbc = intval($i*10/$cnt); $this->UpdateProgressBar(1,$pbc*10,$tag); }
  11190. }
  11191. /*-- END PROGRESS-BAR --*/
  11192. // Check for tags where HTML specifies optional end tags,
  11193. // and/or does not allow nesting e.g. P inside P, or
  11194. $endtag = strtoupper(substr($e,1));
  11195. // mPDF 4.0
  11196. if($this->blk[$this->blklvl]['hide']) {
  11197. if (in_array($endtag, $this->outerblocktags) || in_array($endtag, $this->innerblocktags)) {
  11198. unset($this->blk[$this->blklvl]);
  11199. $this->blklvl--;
  11200. }
  11201. continue;
  11202. }
  11203. /*-- CSS-POSITION --*/
  11204. if ($this->inFixedPosBlock) {
  11205. if (in_array($endtag, $this->outerblocktags) || in_array($endtag, $this->innerblocktags)) { $this->fixedPosBlockDepth--; }
  11206. if ($this->fixedPosBlockDepth == 0) {
  11207. $this->fixedPosBlockSave[] = array($this->fixedPosBlock, $this->fixedPosBlockBBox, $this->page);
  11208. $this->fixedPosBlock = '';
  11209. $this->inFixedPosBlock = false;
  11210. continue;
  11211. }
  11212. $this->fixedPosBlock .= '<'.$e.'>';
  11213. continue;
  11214. }
  11215. /*-- END CSS-POSITION --*/
  11216. if ($this->allow_html_optional_endtags && !$parseonly) {
  11217. if (($endtag == 'DIV' || $endtag =='FORM' || $endtag =='CENTER') && $this->lastoptionaltag == 'P') { $this->CloseTag($this->lastoptionaltag ); }
  11218. if ($this->lastoptionaltag == 'LI' && $endtag == 'OL') { $this->CloseTag($this->lastoptionaltag ); }
  11219. if ($this->lastoptionaltag == 'LI' && $endtag == 'UL') { $this->CloseTag($this->lastoptionaltag ); }
  11220. if ($this->lastoptionaltag == 'DD' && $endtag == 'DL') { $this->CloseTag($this->lastoptionaltag ); }
  11221. if ($this->lastoptionaltag == 'DT' && $endtag == 'DL') { $this->CloseTag($this->lastoptionaltag ); }
  11222. if ($this->lastoptionaltag == 'OPTION' && $endtag == 'SELECT') { $this->CloseTag($this->lastoptionaltag ); }
  11223. /*-- TABLES --*/
  11224. if ($endtag == 'TABLE') {
  11225. if ($this->lastoptionaltag == 'THEAD' || $this->lastoptionaltag == 'TBODY' || $this->lastoptionaltag == 'TFOOT') {
  11226. $this->CloseTag($this->lastoptionaltag);
  11227. }
  11228. if ($this->lastoptionaltag == 'TR') { $this->CloseTag('TR'); }
  11229. if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); }
  11230. }
  11231. if ($endtag == 'THEAD' || $endtag == 'TBODY' || $endtag == 'TFOOT') {
  11232. if ($this->lastoptionaltag == 'TR') { $this->CloseTag('TR'); }
  11233. if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); }
  11234. }
  11235. if ($endtag == 'TR') {
  11236. if ($this->lastoptionaltag == 'TD' || $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); }
  11237. }
  11238. /*-- END TABLES --*/
  11239. }
  11240. $this->CloseTag($endtag);
  11241. }
  11242. else { // OPENING TAG
  11243. if($this->blk[$this->blklvl]['hide']) {
  11244. if (strpos($e,' ')) { $te = strtoupper(substr($e,0,strpos($e,' '))); }
  11245. else { $te = strtoupper($e); }
  11246. if (in_array($te, $this->outerblocktags) || in_array($te, $this->innerblocktags)) {
  11247. $this->blklvl++;
  11248. $this->blk[$this->blklvl]['hide']=true;
  11249. }
  11250. continue;
  11251. }
  11252. /*-- CSS-POSITION --*/
  11253. if ($this->inFixedPosBlock) {
  11254. if (strpos($e,' ')) { $te = strtoupper(substr($e,0,strpos($e,' '))); }
  11255. else { $te = strtoupper($e); }
  11256. $this->fixedPosBlock .= '<'.$e.'>';
  11257. if (in_array($te, $this->outerblocktags) || in_array($te, $this->innerblocktags)) { $this->fixedPosBlockDepth++; }
  11258. continue;
  11259. }
  11260. /*-- END CSS-POSITION --*/
  11261. $regexp = '|=\'(.*?)\'|s'; // eliminate single quotes, if any
  11262. $e = preg_replace($regexp,"=\"\$1\"",$e);
  11263. // changes anykey=anyvalue to anykey="anyvalue" (only do this inside tags)
  11264. if (substr($e,0,10)!='pageheader' && substr($e,0,10)!='pagefooter') {
  11265. $regexp = '| (\\w+?)=([^\\s>"]+)|si';
  11266. $e = preg_replace($regexp," \$1=\"\$2\"",$e);
  11267. }
  11268. //Fix path values, if needed
  11269. $orig_srcpath = ''; // mPDF 4.2.029
  11270. if ((stristr($e,"href=") !== false) or (stristr($e,"src=") !== false) ) {
  11271. $regexp = '/ (href|src)="(.*?)"/i';
  11272. preg_match($regexp,$e,$auxiliararray);
  11273. if (isset($auxiliararray[2])) { $path = $auxiliararray[2]; }
  11274. else { $path = ''; }
  11275. // mPDF 4.2 Special case for img src="var:varname" - leave unchanged
  11276. // mPDF 3.0
  11277. if (trim($path) != '' && !(stristr($e,"src=") !== false && substr($path,0,4)=='var:')) {
  11278. $orig_srcpath = $path; // mPDF 4.2.029
  11279. $this->GetFullPath($path); // mPDF 4.0
  11280. $regexp = '/ (href|src)="(.*?)"/i';
  11281. $e = preg_replace($regexp,' \\1="'.$path.'"',$e);
  11282. }
  11283. }//END of Fix path values
  11284. //Extract attributes
  11285. $contents=array();
  11286. // mPDF 3.0 - Tiling Patterns
  11287. // Changed to allow style="background: url('bg.jpg')"
  11288. preg_match_all('/\\S*=["][^"]*["]/',$e,$contents1);
  11289. preg_match_all('/\\S*=[\'][^\']*[\']/',$e,$contents2);
  11290. $contents = array_merge($contents1, $contents2);
  11291. preg_match('/\\S+/',$e,$a2);
  11292. $tag=strtoupper($a2[0]);
  11293. $attr=array();
  11294. if ($orig_srcpath) { $attr['ORIG_SRC'] = $orig_srcpath; } // mPDF 4.2.029
  11295. if (!empty($contents)) {
  11296. foreach($contents[0] as $v) {
  11297. // mPDF 3.0 - Tiling Patterns
  11298. // Changed to allow style="background: url('bg.jpg')"
  11299. if(preg_match('/^([^=]*)=["]?([^"]*)["]?$/',$v,$a3) || preg_match('/^([^=]*)=[\']?([^\']*)[\']?$/',$v,$a3)) {
  11300. if (strtoupper($a3[1])=='ID' || strtoupper($a3[1])=='CLASS') { // 4.2.013 Omits STYLE
  11301. $attr[strtoupper($a3[1])]=trim(strtoupper($a3[2]));
  11302. }
  11303. // includes header-style-right etc. used for <pageheader>
  11304. else if (preg_match('/^(HEADER|FOOTER)-STYLE/i',$a3[1])) {
  11305. $attr[strtoupper($a3[1])]=trim(strtoupper($a3[2]));
  11306. }
  11307. else {
  11308. $attr[strtoupper($a3[1])]=trim($a3[2]);
  11309. }
  11310. }
  11311. }
  11312. }
  11313. $this->OpenTag($tag,$attr);
  11314. /*-- CSS-POSITION --*/
  11315. // mPDF 4.0 Fixed Pos block
  11316. if ($this->inFixedPosBlock) {
  11317. $this->fixedPosBlockBBox = array($tag,$attr, $this->x, $this->y);
  11318. $this->fixedPosBlock = '';
  11319. $this->fixedPosBlockDepth = 1;
  11320. }
  11321. /*-- END CSS-POSITION --*/
  11322. }
  11323. } // end TAG
  11324. } //end of foreach($a as $i=>$e)
  11325. if ($close) {
  11326. // Close any open block tags
  11327. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  11328. // Output any text left in buffer
  11329. if (count($this->textbuffer) && !$parseonly) { $this->printbuffer($this->textbuffer); }
  11330. if (!$parseonly) $this->textbuffer=array();
  11331. /*-- CSS-FLOAT --*/
  11332. // If ended with a float, need to move to end page
  11333. $currpos = $this->page*1000 + $this->y;
  11334. if (isset($this->blk[$this->blklvl]['float_endpos']) && $this->blk[$this->blklvl]['float_endpos'] > $currpos) {
  11335. $old_page = $this->page;
  11336. $new_page = intval($this->blk[$this->blklvl]['float_endpos'] /1000);
  11337. if ($old_page != $new_page) {
  11338. $s = $this->PrintPageBackgrounds();
  11339. // Writes after the marker so not overwritten later by page background etc.
  11340. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  11341. $this->pageBackgrounds = array();
  11342. $this->page = $new_page;
  11343. $this->ResetMargins();
  11344. $this->Reset();
  11345. $this->pageoutput[$this->page] = array();
  11346. }
  11347. $this->y = (($this->blk[$this->blklvl]['float_endpos'] *1000) % 1000000)/1000; // mod changes operands to integers before processing
  11348. }
  11349. /*-- END CSS-FLOAT --*/
  11350. /*-- CSS-IMAGE-FLOAT --*/
  11351. $this->printfloatbuffer();
  11352. /*-- END CSS-IMAGE-FLOAT --*/
  11353. //Create Internal Links, if needed
  11354. if (!empty($this->internallink) ) {
  11355. foreach($this->internallink as $k=>$v) {
  11356. if (strpos($k,"#") !== false ) { continue; } //ignore
  11357. $ypos = $v['Y'];
  11358. $pagenum = $v['PAGE'];
  11359. $sharp = "#";
  11360. while (array_key_exists($sharp.$k,$this->internallink)) {
  11361. $internallink = $this->internallink[$sharp.$k];
  11362. $this->SetLink($internallink,$ypos,$pagenum);
  11363. $sharp .= "#";
  11364. }
  11365. }
  11366. }
  11367. $this->linemaxfontsize = '';
  11368. $this->lineheight_correction = $this->default_lineheight_correction;
  11369. $this->bufferoutput = false;
  11370. /*-- CSS-POSITION --*/
  11371. // mPDF 4.0 Fixed Pos block
  11372. if (count($this->fixedPosBlockSave) && $sub != 4) {
  11373. foreach($this->fixedPosBlockSave AS $fpbs) {
  11374. $old_page = $this->page;
  11375. $this->page = $fpbs[2];
  11376. $this->WriteFixedPosHTML($fpbs[0], 0, 0, 100, 100,'auto', $fpbs[1]); // 0,0,10,10 are overwritten by bbox
  11377. $this->page = $old_page;
  11378. }
  11379. }
  11380. /*-- END CSS-POSITION --*/
  11381. }
  11382. }
  11383. /*-- CSS-POSITION --*/
  11384. // mPDF 4.0
  11385. function WriteFixedPosHTML($html='',$x, $y, $w, $h, $overflow='visible', $bounding=array()) {
  11386. // $overflow can be 'hidden', 'visible' or 'auto' - 'auto' causes autofit to size
  11387. // Annotations disabled
  11388. // Links do work
  11389. // Will always go on current page (or start Page 1 if required)
  11390. // Probably INCOMPATIBLE WITH keep with table, columns etc.
  11391. // Called externally or interally via <div style="position: [fixed|absolute]">
  11392. // When used internally, $x $y $w $h and $overflow are all overridden by $bounding
  11393. $overflow = strtolower($overflow);
  11394. if($this->state==0) {
  11395. $this->AddPage($this->CurOrientation);
  11396. }
  11397. $save_y = $this->y;
  11398. $save_x = $this->x;
  11399. // mPDF 4.1 // Allows Image in fixedposdiv to be full height
  11400. $this->fullImageHeight = $this->h;
  11401. $save_cols = false;
  11402. /*-- COLUMNS --*/
  11403. if ($this->ColActive) {
  11404. $save_cols = true;
  11405. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  11406. $this->SetColumns(0);
  11407. }
  11408. /*-- END COLUMNS --*/
  11409. $save_annots = $this->title2annots; // *ANNOTATIONS*
  11410. $this->writingHTMLheader = true; // a FIX to stop pagebreaks etc.
  11411. $this->writingHTMLfooter = true;
  11412. $this->InFooter = true; // suppresses autopagebreaks
  11413. $save_bgs = $this->pageBackgrounds;
  11414. $checkinnerhtml = preg_replace('/\s/','',$html); // mPDF 4.2
  11415. if ($w > $this->w) { $x = 0; $w = $this->w; }
  11416. if ($h > $this->h) { $y = 0; $h = $this->h; }
  11417. if ($x > $this->w) { $x = $this->w - $w; }
  11418. if ($y > $this->h) { $y = $this->h - $h; }
  11419. if (!empty($bounding)) {
  11420. // $cont_ containing block = full physical page (position: absolute) or page inside margins (position: fixed)
  11421. // $bbox_ Bounding box is the <div> which is positioned absolutely/fixed
  11422. // top/left/right/bottom/width/height/background*/border*/padding*/margin* are taken from bounding
  11423. // font*[family/size/style/weight]/line-height/text*[align/decoration/transform/indent]/color are transferred to $inner
  11424. // as an enclosing <div> (after having checked ID/CLASS)
  11425. // $x, $y, $w, $h are inside of $bbox_ = containing box for $inner_
  11426. // $inner_ InnerHTML is the contents of that block to be output
  11427. $tag = $bounding[0];
  11428. $attr = $bounding[1];
  11429. $orig_x0 = $bounding[2];
  11430. $orig_y0 = $bounding[3];
  11431. // As in WriteHTML() initialising
  11432. $this->blklvl = 0;
  11433. $this->lastblocklevelchange = 0;
  11434. $this->blk = array();
  11435. $this->initialiseBlock($this->blk[0]);
  11436. $this->blk[0]['width'] =& $this->pgwidth;
  11437. $this->blk[0]['inner_width'] =& $this->pgwidth;
  11438. $this->blk[0]['blockContext'] = $this->blockContext;
  11439. $properties = $this->MergeCSS('BLOCK','BODY','');
  11440. $this->setCSS($properties,'','BODY');
  11441. $this->blklvl = 1;
  11442. $this->initialiseBlock($this->blk[1]);
  11443. $this->blk[1]['tag'] = $tag;
  11444. $this->blk[1]['attr'] = $attr;
  11445. $this->Reset();
  11446. $p = $this->MergeCSS('BLOCK',$tag,$attr);
  11447. if (isset($p['OVERFLOW'])) { $overflow = strtolower($p['OVERFLOW']); }
  11448. if (strtolower($p['POSITION']) == 'fixed') {
  11449. $cont_w = $this->pgwidth; // $this->blk[0]['inner_width'];
  11450. $cont_h = $this->h - $this->tMargin - $this->bMargin;
  11451. $cont_x = $this->lMargin;
  11452. $cont_y = $this->tMargin;
  11453. }
  11454. else {
  11455. $cont_w = $this->w; // ABSOLUTE;
  11456. $cont_h = $this->h;
  11457. $cont_x = 0;
  11458. $cont_y = 0;
  11459. }
  11460. // Pass on in-line properties to the innerhtml
  11461. $css = '';
  11462. if (isset($p['TEXT-ALIGN'])) { $css .= 'text-align: '.strtolower($p['TEXT-ALIGN']).'; '; }
  11463. if (isset($p['TEXT-TRANSFORM'])) { $css .= 'text-transform: '.strtolower($p['TEXT-TRANSFORM']).'; '; }
  11464. if (isset($p['TEXT-INDENT'])) { $css .= 'text-indent: '.strtolower($p['TEXT-INDENT']).'; '; }
  11465. if (isset($p['TEXT-DECORATION'])) { $css .= 'text-decoration: '.strtolower($p['TEXT-DECORATION']).'; '; }
  11466. if (isset($p['FONT-FAMILY'])) { $css .= 'font-family: '.strtolower($p['FONT-FAMILY']).'; '; }
  11467. if (isset($p['FONT-STYLE'])) { $css .= 'font-style: '.strtolower($p['FONT-STYLE']).'; '; }
  11468. if (isset($p['FONT-WEIGHT'])) { $css .= 'font-weight: '.strtolower($p['FONT-WEIGHT']).'; '; }
  11469. if (isset($p['FONT-SIZE'])) { $css .= 'font-size: '.strtolower($p['FONT-SIZE']).'; '; }
  11470. if (isset($p['LINE-HEIGHT'])) { $css .= 'line-height: '.strtolower($p['LINE-HEIGHT']).'; '; }
  11471. if (isset($p['COLOR'])) { $css .= 'color: '.strtolower($p['COLOR']).'; '; }
  11472. if ($css) {
  11473. $html = '<div style="'.$css.'">'.$html.'</div>';
  11474. }
  11475. // Copy over (only) the properties to set for border and background
  11476. $pb = array();
  11477. $pb['MARGIN-TOP'] = $p['MARGIN-TOP'];
  11478. $pb['MARGIN-RIGHT'] = $p['MARGIN-RIGHT'];
  11479. $pb['MARGIN-BOTTOM'] = $p['MARGIN-BOTTOM'];
  11480. $pb['MARGIN-LEFT'] = $p['MARGIN-LEFT'];
  11481. $pb['PADDING-TOP'] = $p['PADDING-TOP'];
  11482. $pb['PADDING-RIGHT'] = $p['PADDING-RIGHT'];
  11483. $pb['PADDING-BOTTOM'] = $p['PADDING-BOTTOM'];
  11484. $pb['PADDING-LEFT'] = $p['PADDING-LEFT'];
  11485. $pb['BORDER-TOP'] = $p['BORDER-TOP'];
  11486. $pb['BORDER-RIGHT'] = $p['BORDER-RIGHT'];
  11487. $pb['BORDER-BOTTOM'] = $p['BORDER-BOTTOM'];
  11488. $pb['BORDER-LEFT'] = $p['BORDER-LEFT'];
  11489. if (isset($p['BACKGROUND-COLOR'])) { $pb['BACKGROUND-COLOR'] = $p['BACKGROUND-COLOR']; }
  11490. if (isset($p['BACKGROUND-IMAGE'])) { $pb['BACKGROUND-IMAGE'] = $p['BACKGROUND-IMAGE']; } // *BACKGROUND-IMAGES*
  11491. // mPDF 4.3.015
  11492. if (isset($p['BACKGROUND-IMAGE-RESIZE'])) { $pb['BACKGROUND-IMAGE-RESIZE'] = $p['BACKGROUND-IMAGE-RESIZE']; } // *BACKGROUND-IMAGES*
  11493. // mPDF 4.3.017
  11494. if (isset($p['BACKGROUND-IMAGE-OPACITY'])) { $pb['BACKGROUND-IMAGE-OPACITY'] = $p['BACKGROUND-IMAGE-OPACITY']; } // *BACKGROUND-IMAGES*
  11495. if (isset($p['BACKGROUND-REPEAT'])) { $pb['BACKGROUND-REPEAT'] = $p['BACKGROUND-REPEAT']; } // *BACKGROUND-IMAGES*
  11496. if (isset($p['BACKGROUND-POSITION'])) { $pb['BACKGROUND-POSITION'] = $p['BACKGROUND-POSITION']; } // *BACKGROUND-IMAGES*
  11497. if (isset($p['BACKGROUND-GRADIENT'])) { $pb['BACKGROUND-GRADIENT'] = $p['BACKGROUND-GRADIENT']; } // *GRADIENTS*
  11498. $this->setCSS($pb,'BLOCK',$tag);
  11499. //================================================================
  11500. $bbox_dir = $p['DIR'];
  11501. $bbox_br = $this->blk[1]['border_right']['w'];
  11502. $bbox_bl = $this->blk[1]['border_left']['w'];
  11503. $bbox_bt = $this->blk[1]['border_top']['w'];
  11504. $bbox_bb = $this->blk[1]['border_bottom']['w'];
  11505. $bbox_pr = $this->blk[1]['padding_right'];
  11506. $bbox_pl = $this->blk[1]['padding_left'];
  11507. $bbox_pt = $this->blk[1]['padding_top'];
  11508. $bbox_pb = $this->blk[1]['padding_bottom'];
  11509. $bbox_mr = $this->blk[1]['margin_right'];
  11510. if (strtolower($p['MARGIN-RIGHT'])=='auto') { $bbox_mr = 'auto'; }
  11511. $bbox_ml = $this->blk[1]['margin_left'];
  11512. if (strtolower($p['MARGIN-LEFT'])=='auto') { $bbox_ml = 'auto'; }
  11513. $bbox_mt = $this->blk[1]['margin_top'];
  11514. if (strtolower($p['MARGIN-TOP'])=='auto') { $bbox_mt = 'auto'; }
  11515. $bbox_mb = $this->blk[1]['margin_bottom'];
  11516. if (strtolower($p['MARGIN-BOTTOM'])=='auto') { $bbox_mb = 'auto'; }
  11517. if (isset($p['LEFT']) && strtolower($p['LEFT'])!='auto') { $bbox_left = $this->ConvertSize($p['LEFT'], $cont_w, $this->FontSize,false); }
  11518. else { $bbox_left = 'auto'; }
  11519. if (isset($p['TOP']) && strtolower($p['TOP'])!='auto') { $bbox_top = $this->ConvertSize($p['TOP'], $cont_h, $this->FontSize,false); }
  11520. else { $bbox_top = 'auto'; }
  11521. if (isset($p['RIGHT']) && strtolower($p['RIGHT'])!='auto') { $bbox_right = $this->ConvertSize($p['RIGHT'], $cont_w, $this->FontSize,false); }
  11522. else { $bbox_right = 'auto'; }
  11523. if (isset($p['BOTTOM']) && strtolower($p['BOTTOM'])!='auto') { $bbox_bottom = $this->ConvertSize($p['BOTTOM'], $cont_h, $this->FontSize,false); }
  11524. else { $bbox_bottom = 'auto'; }
  11525. if (isset($p['WIDTH']) && strtolower($p['WIDTH'])!='auto') { $inner_w = $this->ConvertSize($p['WIDTH'], $cont_w, $this->FontSize,false); }
  11526. else { $inner_w = 'auto'; }
  11527. if (isset($p['HEIGHT']) && strtolower($p['HEIGHT'])!='auto') { $inner_h = $this->ConvertSize($p['HEIGHT'], $cont_h, $this->FontSize,false); }
  11528. else { $inner_h = 'auto'; }
  11529. //================================================================
  11530. // mPDF 4.2
  11531. if ($checkinnerhtml=='' && $inner_h==='auto') { $inner_h = 0.0001; }
  11532. if ($checkinnerhtml=='' && $inner_w==='auto') { $inner_w = $this->GetStringWidth('WW'); }
  11533. //================================================================
  11534. // Algorithm from CSS2.1 See http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-height
  11535. if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom==='auto') {
  11536. if ($bbox_mt==='auto') { $bbox_mt = 0; }
  11537. if ($bbox_mb==='auto') { $bbox_mb = 0; }
  11538. $bbox_top = $orig_y0 - $bbox_mt - $cont_y;
  11539. // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto'
  11540. }
  11541. else if ($bbox_top!=='auto' && $inner_h!=='auto' && $bbox_bottom!=='auto') {
  11542. if ($bbox_mt==='auto' && $bbox_mb==='auto') {
  11543. $x = $cont_h - $bbox_top - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_bottom;
  11544. $bbox_mt = $bbox_mb = ($x/2);
  11545. }
  11546. else if ($bbox_mt==='auto') {
  11547. $bbox_mt = $cont_h - $bbox_top - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  11548. }
  11549. else if ($bbox_mb==='auto') {
  11550. $bbox_mb = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_bottom;
  11551. }
  11552. else {
  11553. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
  11554. }
  11555. }
  11556. else {
  11557. if ($bbox_mt==='auto') { $bbox_mt = 0; }
  11558. if ($bbox_mb==='auto') { $bbox_mb = 0; }
  11559. if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom!=='auto') {
  11560. // solve for $bbox_top when content_h known - $inner_h=='auto' && $bbox_top =='auto'
  11561. }
  11562. else if ($bbox_top==='auto' && $bbox_bottom==='auto' && $inner_h!=='auto') {
  11563. $bbox_top = $orig_y0 - $bbox_mt - $cont_y;
  11564. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
  11565. }
  11566. else if ($inner_h==='auto' && $bbox_bottom==='auto' && $bbox_top!=='auto') {
  11567. // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto'
  11568. }
  11569. else if ($bbox_top==='auto' && $inner_h!=='auto' && $bbox_bottom!=='auto') {
  11570. $bbox_top = $cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom;
  11571. }
  11572. else if ($inner_h==='auto' && $bbox_top!=='auto' && $bbox_bottom!=='auto') {
  11573. $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom;
  11574. }
  11575. else if ($bbox_bottom==='auto' && $bbox_top!=='auto' && $inner_h!=='auto') {
  11576. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt;
  11577. }
  11578. }
  11579. // THEN DO SAME FOR WIDTH
  11580. // http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width
  11581. if ($bbox_left==='auto' && $inner_w==='auto' && $bbox_right==='auto') {
  11582. if ($bbox_ml==='auto') { $bbox_ml = 0; }
  11583. if ($bbox_mr==='auto') { $bbox_mr = 0; }
  11584. // IF containing element RTL, should set $bbox_right
  11585. $bbox_left = $orig_x0 - $bbox_ml - $cont_x;
  11586. // solve for $bbox_right when content_w known - $inner_w=='auto' && $bbox_right=='auto'
  11587. }
  11588. else if ($bbox_left!=='auto' && $inner_w!=='auto' && $bbox_right!=='auto') {
  11589. if ($bbox_ml==='auto' && $bbox_mr==='auto') {
  11590. $x = $cont_w - $bbox_left - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_right;
  11591. $bbox_ml = $bbox_mr = ($x/2);
  11592. }
  11593. else if ($bbox_ml==='auto') {
  11594. $bbox_ml = $cont_w - $bbox_left - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_mr - $bbox_right;
  11595. }
  11596. else if ($bbox_mr==='auto') {
  11597. $bbox_mr = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_right;
  11598. }
  11599. else {
  11600. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  11601. }
  11602. }
  11603. else {
  11604. if ($bbox_ml==='auto') { $bbox_ml = 0; }
  11605. if ($bbox_mr==='auto') { $bbox_mr = 0; }
  11606. if ($bbox_left==='auto' && $inner_w==='auto' && $bbox_right!=='auto') {
  11607. // solve for $bbox_left when content_w known - $inner_w=='auto' && $bbox_left =='auto'
  11608. }
  11609. else if ($bbox_left==='auto' && $bbox_right==='auto' && $inner_w!=='auto') {
  11610. // IF containing element RTL, should set $bbox_right
  11611. $bbox_left = $orig_x0 - $bbox_ml - $cont_x;
  11612. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  11613. }
  11614. else if ($inner_w==='auto' && $bbox_right==='auto' && $bbox_left!=='auto') {
  11615. // solve for $bbox_right when content_w known - $inner_w=='auto' && $bbox_right=='auto'
  11616. }
  11617. else if ($bbox_left==='auto' && $inner_w!=='auto' && $bbox_right!=='auto') {
  11618. $bbox_left = $cont_w - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
  11619. }
  11620. else if ($inner_w==='auto' && $bbox_left!=='auto' && $bbox_right!=='auto') {
  11621. $inner_w = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
  11622. }
  11623. else if ($bbox_right==='auto' && $bbox_left!=='auto' && $inner_w!=='auto') {
  11624. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  11625. }
  11626. }
  11627. //================================================================
  11628. //================================================================
  11629. /*-- BACKGROUND-IMAGES --*/
  11630. if (isset($pb['BACKGROUND-IMAGE']) && $pb['BACKGROUND-IMAGE']) { // mPDF 4.3.011
  11631. $file = $pb['BACKGROUND-IMAGE'];
  11632. $sizesarray = $this->Image($file,0,0,0,0,'','',false, false, false, false, false); // mPDF 4.3.012D
  11633. if (isset($sizesarray['IMAGE_ID'])) {
  11634. $image_id = $sizesarray['IMAGE_ID'];
  11635. $orig_w = $sizesarray['WIDTH']*$this->k; // in user units i.e. mm
  11636. $orig_h = $sizesarray['HEIGHT']*$this->k; // (using $this->img_dpi)
  11637. $x_repeat = true;
  11638. $y_repeat = true;
  11639. if (isset($pb['BACKGROUND-REPEAT'])) {
  11640. if ($pb['BACKGROUND-REPEAT']=='no-repeat' || $pb['BACKGROUND-REPEAT']=='repeat-x') { $y_repeat = false; }
  11641. if ($pb['BACKGROUND-REPEAT']=='no-repeat' || $pb['BACKGROUND-REPEAT']=='repeat-y') { $x_repeat = false; }
  11642. }
  11643. $x_pos = 0;
  11644. $y_pos = 0;
  11645. if (isset($pb['BACKGROUND-POSITION'])) {
  11646. $ppos = preg_split('/\s+/',$pb['BACKGROUND-POSITION']);
  11647. $x_pos = $ppos[0];
  11648. $y_pos = $ppos[1];
  11649. if (!stristr($x_pos ,'%') ) { $x_pos = $this->ConvertSize($x_pos ,$this->blk[1]['inner_width'],$this->FontSize); }
  11650. if (!stristr($y_pos ,'%') ) { $y_pos = $this->ConvertSize($y_pos ,$this->blk[1]['inner_width'],$this->FontSize); }
  11651. }
  11652. // mPDF 4.3.015
  11653. if (isset($pb['BACKGROUND-IMAGE-RESIZE'])) { $resize = $pb['BACKGROUND-IMAGE-RESIZE']; }
  11654. else { $resize = 0; }
  11655. // mPDF 4.3.017
  11656. if (isset($pb['BACKGROUND-IMAGE-OPACITY'])) { $opacity = $pb['BACKGROUND-IMAGE-OPACITY']; }
  11657. else { $opacity = 1; }
  11658. $this->blk[1]['background-image'] = 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); // mPDF 4.3.015 4.3.017
  11659. }
  11660. }
  11661. /*-- END BACKGROUND-IMAGES --*/
  11662. //================================================================
  11663. $y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt;
  11664. $h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  11665. $x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl;
  11666. $w = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $bbox_pr - $bbox_br - $bbox_mr - $bbox_right;
  11667. // Set (temporary) values for x y w h to do first paint, if values are auto
  11668. if ($inner_h==='auto' && $bbox_top==='auto') {
  11669. $y = $cont_y + $bbox_mt + $bbox_bt + $bbox_pt;
  11670. $h = $cont_h - ($bbox_bottom + $bbox_mt + $bbox_mb + $bbox_bt + $bbox_bb + $bbox_pt + $bbox_pb);
  11671. }
  11672. else if ($inner_h==='auto' && $bbox_bottom==='auto') {
  11673. $y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt;
  11674. $h = $cont_h - ($bbox_top + $bbox_mt + $bbox_mb + $bbox_bt + $bbox_bb + $bbox_pt + $bbox_pb);
  11675. }
  11676. if ($inner_w==='auto' && $bbox_left==='auto') {
  11677. $x = $cont_x + $bbox_ml + $bbox_bl + $bbox_pl;
  11678. $w = $cont_w - ($bbox_right + $bbox_ml + $bbox_mr + $bbox_bl + $bbox_br + $bbox_pl + $bbox_pr);
  11679. }
  11680. else if ($inner_w==='auto' && $bbox_right==='auto') {
  11681. $x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl;
  11682. $w = $cont_w - ($bbox_left + $bbox_ml + $bbox_mr + $bbox_bl + $bbox_br + $bbox_pl + $bbox_pr);
  11683. }
  11684. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  11685. $bbox_x = $cont_x + $bbox_left + $bbox_ml;
  11686. $saved_block1 = $this->blk[1];
  11687. unset($p);
  11688. unset($pb);
  11689. //================================================================
  11690. if ($inner_w==='auto') { // do a first write
  11691. $this->lMargin=$x;
  11692. $this->rMargin=$this->w - $w - $x;
  11693. // SET POSITION & FONT VALUES
  11694. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  11695. $this->pageoutput[$this->page]=array();
  11696. $this->x = $x;
  11697. $this->y = $y;
  11698. $this->HTMLheaderPageLinks = array();
  11699. $this->pageBackgrounds = array();
  11700. $this->maxPosR = 0;
  11701. $this->maxPosL = $this->w; // For RTL
  11702. $this->WriteHTML($html , 4);
  11703. $inner_w = $this->maxPosR - $this->lMargin;
  11704. if ($bbox_right==='auto') {
  11705. $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml;
  11706. }
  11707. else if ($bbox_left==='auto') {
  11708. $bbox_left = $cont_w - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right;
  11709. $bbox_x = $cont_x + $bbox_left + $bbox_ml ;
  11710. $inner_x = $bbox_x + $bbox_bl + $bbox_pl;
  11711. $x = $inner_x;
  11712. }
  11713. $w = $inner_w;
  11714. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  11715. $bbox_x = $cont_x + $bbox_left + $bbox_ml;
  11716. }
  11717. if ($inner_h==='auto') { // do a first write
  11718. $this->lMargin=$x;
  11719. $this->rMargin=$this->w - $w - $x;
  11720. // SET POSITION & FONT VALUES
  11721. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  11722. $this->pageoutput[$this->page]=array();
  11723. $this->x = $x;
  11724. $this->y = $y;
  11725. $this->HTMLheaderPageLinks = array();
  11726. $this->pageBackgrounds = array();
  11727. $this->WriteHTML($html , 4);
  11728. $inner_h = $this->y - $y;
  11729. if ($overflow!='hidden' && $overflow!='visible') { // constrained
  11730. if (($this->y + $bbox_pb + $bbox_bb) > ($cont_y + $cont_h)) {
  11731. $adj = ($this->y + $bbox_pb + $bbox_bb) - ($cont_y + $cont_h);
  11732. $inner_h -= $adj;
  11733. }
  11734. }
  11735. if ($bbox_bottom==='auto') {
  11736. $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb;
  11737. }
  11738. else if ($bbox_top==='auto') {
  11739. $bbox_top = $cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  11740. if ($overflow!='hidden' && $overflow!='visible') { // constrained
  11741. if ($bbox_top < 0) {
  11742. $bbox_top = 0;
  11743. $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom;
  11744. }
  11745. }
  11746. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  11747. $inner_y = $bbox_y + $bbox_bt + $bbox_pt;
  11748. $y = $inner_y;
  11749. }
  11750. $h = $inner_h;
  11751. $bbox_y = $cont_y + $bbox_top + $bbox_mt;
  11752. $bbox_x = $cont_x + $bbox_left + $bbox_ml;
  11753. }
  11754. $inner_w = $w;
  11755. $inner_h = $h;
  11756. }
  11757. $this->lMargin=$x;
  11758. $this->rMargin=$this->w - $w - $x;
  11759. // SET POSITION & FONT VALUES
  11760. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  11761. $this->pageoutput[$this->page]=array();
  11762. $this->x = $x;
  11763. $this->y = $y;
  11764. $this->HTMLheaderPageLinks = array();
  11765. $this->pageBackgrounds = array();
  11766. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  11767. $actual_h = $this->y - $y;
  11768. $use_w = $w;
  11769. $use_h = $h;
  11770. $ratio = $actual_h / $use_w;
  11771. if ($overflow!='hidden' && $overflow!='visible') {
  11772. $target = $h/$w;
  11773. if (($ratio / $target ) > 1) {
  11774. $nl = CEIL($actual_h / $this->lineheight);
  11775. $l = $use_w * $nl;
  11776. $est_w = sqrt(($l * $this->lineheight) / $target) * 0.8;
  11777. $use_w += ($est_w - $use_w) - ($w/100);
  11778. }
  11779. $bpcstart = ($ratio / $target); // *PROGRESS-BAR*
  11780. $bpcctr = 1; // *PROGRESS-BAR*
  11781. while(($ratio / $target ) > 1) {
  11782. /*-- PROGRESS-BAR --*/
  11783. if ($this->progressBar) { $this->UpdateProgressBar(4,intval(100/($ratio/$target)),('Auto-sizing fixed-position block: '.$bpcctr++)); }
  11784. /*-- END PROGRESS-BAR --*/
  11785. $this->x = $x;
  11786. $this->y = $y;
  11787. // mPDF 4.2
  11788. if (($ratio / $target) > 1.5 || ($ratio / $target) < 0.6) {
  11789. $use_w += ($w/$this->incrementFPR1);
  11790. }
  11791. else if (($ratio / $target) > 1.2 || ($ratio / $target) < 0.85) {
  11792. $use_w += ($w/$this->incrementFPR2);
  11793. }
  11794. else if (($ratio / $target) > 1.1 || ($ratio / $target) < 0.91) {
  11795. $use_w += ($w/$this->incrementFPR3);
  11796. }
  11797. else {
  11798. $use_w += ($w/$this->incrementFPR4);
  11799. }
  11800. $use_h = $use_w * $target ;
  11801. $this->rMargin=$this->w - $use_w - $x;
  11802. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  11803. $this->HTMLheaderPageLinks = array();
  11804. $this->pageBackgrounds = array();
  11805. $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer
  11806. $actual_h = $this->y - $y;
  11807. $ratio = $actual_h / $use_w;
  11808. }
  11809. if ($this->progressBar) { $this->UpdateProgressBar(4,'100',' '); } // *PROGRESS-BAR*
  11810. }
  11811. $shrink_f = $w/$use_w;
  11812. //================================================================
  11813. $this->pages[$this->page] .= '___BEFORE_BORDERS___';
  11814. $block_s = $this->PrintPageBackgrounds(); // Save to print later inside clipping path
  11815. $this->pageBackgrounds = array();
  11816. //================================================================
  11817. if (!empty($bounding)) {
  11818. // WHEN HEIGHT // BOTTOM EDGE IS KNOWN and $this->y is set to the bottom
  11819. // Re-instate saved $this->blk[1]
  11820. $this->blk[1] = $saved_block1;
  11821. // These are only needed when painting border/background
  11822. $this->blk[1]['width'] = $bbox_w = $cont_w - $bbox_left - $bbox_ml - $bbox_mr - $bbox_right;
  11823. $this->blk[1]['x0'] = $bbox_x;
  11824. $this->blk[1]['y0'] = $bbox_y;
  11825. $this->blk[1]['startpage'] = $this->page;
  11826. $this->blk[1]['y1'] = $bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb ;
  11827. $this->PaintDivBB('',0,1); // Prints borders and sets backgrounds in $this->pageBackgrounds
  11828. }
  11829. $s = $this->PrintPageBackgrounds();
  11830. $this->pages[$this->page] = preg_replace('/___BEFORE_BORDERS___/', "\n".$s."\n", $this->pages[$this->page]);
  11831. $this->pageBackgrounds = array();
  11832. // Clipping Output
  11833. if ($overflow=='hidden') {
  11834. //Bounding rectangle to clip
  11835. $clip_y1 = $this->y;
  11836. if (!empty($bounding) && ($this->y + $bbox_pb + $bbox_bb) > ($bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb )) {
  11837. $clip_y1 = ($bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb ) - ($bbox_pb + $bbox_bb);
  11838. }
  11839. //$op = 'W* n'; // Clipping
  11840. $op = 'W n'; // Clipping alternative mode
  11841. $this->_out("q");
  11842. $ch = $clip_y1 - $y;
  11843. $this->_out(sprintf('%.3f %.3f %.3f %.3f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$ch*$this->k,$op));
  11844. if (!empty($block_s)) {
  11845. $tmp = "q\n".sprintf('%.3f %.3f %.3f %.3f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$ch*$this->k,$op);
  11846. $tmp .= "\n".$block_s."\nQ";
  11847. $block_s = $tmp ;
  11848. }
  11849. }
  11850. if (!empty($block_s)) {
  11851. if ($shrink_f != 1) { // i.e. autofit has resized the box
  11852. $tmp = "q\n".$this->transformScale(($shrink_f*100),($shrink_f*100), $x, $y, true);
  11853. $tmp .= "\n".$block_s."\nQ";
  11854. $block_s = $tmp ;
  11855. }
  11856. $this->_out($block_s);
  11857. }
  11858. if ($shrink_f != 1) { // i.e. autofit has resized the box
  11859. $this->StartTransform();
  11860. $this->transformScale(($shrink_f*100),($shrink_f*100), $x, $y);
  11861. }
  11862. $this->_out($this->headerbuffer);
  11863. if ($shrink_f != 1) { // i.e. autofit has resized the box
  11864. $this->StopTransform();
  11865. }
  11866. if ($overflow=='hidden') {
  11867. //End clipping
  11868. $this->_out("Q");
  11869. }
  11870. // Page Links
  11871. foreach($this->HTMLheaderPageLinks AS $lk) {
  11872. if ($shrink_f != 1) { // i.e. autofit has resized the box
  11873. $lx1 = (($lk[0]/$this->k)-$x);
  11874. $lx2 = $x + ($lx1 * $shrink_f);
  11875. $lk[0] = $lx2*$this->k;
  11876. $ly1 = (($this->h-($lk[1]/$this->k))-$y);
  11877. $ly2 = $y + ($ly1 * $shrink_f);
  11878. $lk[1] = ($this->h-$ly2)*$this->k;
  11879. $lk[2] *= $shrink_f; // width
  11880. $lk[3] *= $shrink_f; // height
  11881. }
  11882. $this->PageLinks[$this->page][]=$lk;
  11883. }
  11884. // Restore
  11885. $this->headerbuffer = '';
  11886. $this->HTMLheaderPageLinks = array();
  11887. $this->pageBackgrounds = $save_bgs;
  11888. $this->writingHTMLheader = false;
  11889. // mPDF 4.0
  11890. $this->writingHTMLfooter = false;
  11891. // mPDF 4.1
  11892. $this->fullImageHeight = false;
  11893. $this->ResetMargins();
  11894. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  11895. $this->SetXY($save_x,$save_y) ;
  11896. $this->title2annots = $save_annots; // *ANNOTATIONS*
  11897. $this->InFooter = false; // turns back on autopagebreaks
  11898. $this->pageoutput[$this->page]=array();
  11899. $this->pageoutput[$this->page]['Font']='';
  11900. /*-- COLUMNS --*/
  11901. if ($save_cols) {
  11902. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  11903. }
  11904. /*-- END COLUMNS --*/
  11905. }
  11906. /*-- END CSS-POSITION --*/
  11907. // mPDF 4.0
  11908. function initialiseBlock(&$blk) {
  11909. $blk['margin_top'] = 0;
  11910. $blk['margin_left'] = 0;
  11911. $blk['margin_bottom'] = 0;
  11912. $blk['margin_right'] = 0;
  11913. $blk['padding_top'] = 0;
  11914. $blk['padding_left'] = 0;
  11915. $blk['padding_bottom'] = 0;
  11916. $blk['padding_right'] = 0;
  11917. $blk['border_top']['w'] = 0;
  11918. $blk['border_left']['w'] = 0;
  11919. $blk['border_bottom']['w'] = 0;
  11920. $blk['border_right']['w'] = 0;
  11921. $blk['hide'] = false;
  11922. $blk['outer_left_margin'] = 0;
  11923. $blk['outer_right_margin'] = 0;
  11924. $blk['cascadeCSS'] = array();
  11925. $blk['block-align'] = false;
  11926. $blk['bgcolor'] = false;
  11927. $blk['page_break_after_avoid'] = false;
  11928. $blk['keep_block_together'] = false;
  11929. $blk['float'] = false;
  11930. $blk['line_height'] = '';
  11931. $blk['margin_collapse'] = false;
  11932. }
  11933. // mPDF 4.0
  11934. function border_details($bd) {
  11935. $prop = preg_split('/\s+/',trim($bd));
  11936. // mPDF 4.0
  11937. if (isset($this->blk[$this->blklvl]['inner_width'])) { $refw = $this->blk[$this->blklvl]['inner_width']; }
  11938. else if (isset($this->blk[$this->blklvl-1]['inner_width'])) { $refw = $this->blk[$this->blklvl-1]['inner_width']; }
  11939. else { $refw = $this->w; }
  11940. if ( count($prop) == 1 ) {
  11941. $bsize = $this->ConvertSize($prop[0],$refw,$this->FontSize,false);
  11942. if ($bsize > 0) {
  11943. return array('s' => 1, 'w' => $bsize, 'c' => array('R'=>0,'G'=>0,'B'=>0), 'style'=>'solid');
  11944. }
  11945. else { return array('w' => 0, 's' => 0); } // mPDF 3.0
  11946. }
  11947. // mPDF 4.0
  11948. else if (count($prop) == 2 ) {
  11949. // 1px solid
  11950. if (in_array($prop[1],$this->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden' ) { $prop[2] = ''; }
  11951. // solid #000000
  11952. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $prop[0] = ''; $prop[1] = $prop[0]; $prop[2] = $prop[1]; }
  11953. // 1px #000000
  11954. else { $prop[1] = ''; $prop[2] = $prop[1]; }
  11955. }
  11956. else if ( count($prop) == 3 ) {
  11957. // Change #000000 1px solid to 1px solid #000000 (proper)
  11958. if (substr($prop[0],0,1) == '#') { $tmp = $prop[0]; $prop[0] = $prop[1]; $prop[1] = $prop[2]; $prop[2] = $tmp; }
  11959. // Change solid #000000 1px to 1px solid #000000 (proper)
  11960. else if (substr($prop[0],1,1) == '#') { $tmp = $prop[1]; $prop[0] = $prop[2]; $prop[1] = $prop[0]; $prop[2] = $tmp; }
  11961. // Change solid 1px #000000 to 1px solid #000000 (proper)
  11962. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) {
  11963. $tmp = $prop[0]; $prop[0] = $prop[1]; $prop[1] = $tmp;
  11964. }
  11965. }
  11966. else { return array(); }
  11967. // Size
  11968. $bsize = $this->ConvertSize($prop[0],$refw,$this->FontSize,false);
  11969. //color
  11970. $coul = $this->ConvertColor($prop[2]); // returns array
  11971. // Style
  11972. $prop[1] = strtolower($prop[1]);
  11973. if (in_array($prop[1],$this->borderstyles) && $bsize > 0) { $on = 1; }
  11974. else if ($prop[1] == 'hidden') { $on = 1; $bsize = 0; $coul = ''; }
  11975. else if ($prop[1] == 'none') { $on = 0; $bsize = 0; $coul = ''; }
  11976. else { $on = 0; $bsize = 0; $coul = ''; $prop[1] = ''; }
  11977. return array('s' => $on, 'w' => $bsize, 'c' => $coul, 'style'=> $prop[1] );
  11978. }
  11979. // mPDF 4.0
  11980. function _fix_borderStr($bd) {
  11981. $prop = preg_split('/\s+/',trim($bd));
  11982. $w = 'medium'; // mPDF 4.3.010
  11983. $c = '#000000';
  11984. $s = 'none';
  11985. if ( count($prop) == 1 ) {
  11986. // solid
  11987. if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; }
  11988. // #000000
  11989. else if (is_array($this->ConvertColor($prop[0]))) { $c = $prop[0]; }
  11990. // 1px
  11991. else { $w = $prop[0]; }
  11992. }
  11993. else if (count($prop) == 2 ) {
  11994. // 1px solid
  11995. if (in_array($prop[1],$this->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden' ) { $w = $prop[0]; $s = $prop[1]; }
  11996. // solid #000000
  11997. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; $c = $prop[1]; }
  11998. // 1px #000000
  11999. else { $w = $prop[0]; $c = $prop[1]; }
  12000. }
  12001. else if ( count($prop) == 3 ) {
  12002. // Change #000000 1px solid to 1px solid #000000 (proper)
  12003. if (substr($prop[0],0,1) == '#') { $c = $prop[0]; $w = $prop[1]; $s = $prop[2]; }
  12004. // Change solid #000000 1px to 1px solid #000000 (proper)
  12005. else if (substr($prop[0],1,1) == '#') { $s = $prop[0]; $c = $prop[1]; $w = $prop[2]; }
  12006. // Change solid 1px #000000 to 1px solid #000000 (proper)
  12007. else if (in_array($prop[0],$this->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) {
  12008. $s = $prop[0]; $w = $prop[1]; $c = $prop[2];
  12009. }
  12010. else { $w = $prop[0]; $s = $prop[1]; $c = $prop[2]; }
  12011. }
  12012. else { return ''; }
  12013. $s = strtolower($s);
  12014. return $w.' '.$s.' '.$c;
  12015. }
  12016. // NEW FUNCTION FOR CSS MARGIN or PADDING called from SetCSS
  12017. function fixCSS($prop) {
  12018. if (!is_array($prop) || (count($prop)==0)) return array();
  12019. $newprop = array();
  12020. foreach($prop AS $k => $v) {
  12021. // mPDF 4.2.013 Change all CSS properties to lowercase, except those that are case sensitive
  12022. 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') {
  12023. $v = strtolower($v);
  12024. }
  12025. // mPDF 4.0 - FONT shorthand
  12026. if ($k == 'FONT') {
  12027. $s = trim($v);
  12028. preg_match_all('/\"(.*?)\"/',$s,$ff);
  12029. if (count($ff[1])) {
  12030. foreach($ff[1] AS $ffp) {
  12031. $w = preg_split('/\s+/',$ffp);
  12032. $s = preg_replace('/\"'.$ffp.'\"/',$w[0],$s);
  12033. }
  12034. }
  12035. preg_match_all('/\'(.*?)\'/',$s,$ff);
  12036. if (count($ff[1])) {
  12037. foreach($ff[1] AS $ffp) {
  12038. $w = preg_split('/\s+/',$ffp);
  12039. $s = preg_replace('/\''.$ffp.'\'/',$w[0],$s);
  12040. }
  12041. }
  12042. $s = preg_replace('/\s*,\s*/',',',$s);
  12043. $bits = preg_split('/\s+/',$s);
  12044. if (count($bits)>1) {
  12045. $k = 'FONT-FAMILY'; $v = $bits[(count($bits)-1)];
  12046. $fs = $bits[(count($bits)-2)];
  12047. if (preg_match('/(.*?)\/(.*)/',$fs, $fsp)) {
  12048. $newprop['FONT-SIZE'] = $fsp[1];
  12049. $newprop['LINE-HEIGHT'] = $fsp[2];
  12050. }
  12051. else { $newprop['FONT-SIZE'] = $fs; }
  12052. if (preg_match('/(italic|oblique)/i',$s)) { $newprop['FONT-STYLE'] = 'italic'; }
  12053. else { $newprop['FONT-STYLE'] = 'normal'; }
  12054. if (preg_match('/bold/i',$s)) { $newprop['FONT-WEIGHT'] = 'bold'; }
  12055. else { $newprop['FONT-WEIGHT'] = 'normal'; }
  12056. if (preg_match('/small-caps/i',$s)) { $newprop['TEXT-TRANSFORM'] = 'uppercase'; }
  12057. }
  12058. }
  12059. if ($k == 'FONT-FAMILY') {
  12060. $aux_fontlist = explode(",",$v);
  12061. $fonttype = trim($aux_fontlist[0]);
  12062. // mPDF 4.0
  12063. $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
  12064. $aux_fontlist = explode(" ",$fonttype);
  12065. $fonttype = $aux_fontlist[0];
  12066. $v = strtolower(trim($fonttype));
  12067. if (($this->is_MB && in_array($v,$this->available_unifonts)) ||
  12068. (!$this->is_MB && in_array($v,$this->available_fonts)) || in_array($v, array('sjis','uhc','big5','gb')) ||
  12069. in_array($v,$this->sans_fonts) || in_array($v,$this->serif_fonts) || in_array($v,$this->mono_fonts) ) {
  12070. $newprop[$k] = $v;
  12071. }
  12072. }
  12073. else if ($k == 'MARGIN') {
  12074. $tmp = $this->expand24($v);
  12075. $newprop['MARGIN-TOP'] = $tmp['T'];
  12076. $newprop['MARGIN-RIGHT'] = $tmp['R'];
  12077. $newprop['MARGIN-BOTTOM'] = $tmp['B'];
  12078. $newprop['MARGIN-LEFT'] = $tmp['L'];
  12079. }
  12080. /*-- BORDER-RADIUS --*/
  12081. 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') {
  12082. $tmp = $this->border_radius_expand($v,$k);
  12083. if (isset($tmp['TL-H'])) $newprop['BORDER-TOP-LEFT-RADIUS-H'] = $tmp['TL-H'];
  12084. if (isset($tmp['TL-V'])) $newprop['BORDER-TOP-LEFT-RADIUS-V'] = $tmp['TL-V'];
  12085. if (isset($tmp['TR-H'])) $newprop['BORDER-TOP-RIGHT-RADIUS-H'] = $tmp['TR-H'];
  12086. if (isset($tmp['TR-V'])) $newprop['BORDER-TOP-RIGHT-RADIUS-V'] = $tmp['TR-V'];
  12087. if (isset($tmp['BL-H'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-H'] = $tmp['BL-H'];
  12088. if (isset($tmp['BL-V'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-V'] = $tmp['BL-V'];
  12089. if (isset($tmp['BR-H'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $tmp['BR-H'];
  12090. if (isset($tmp['BR-V'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $tmp['BR-V'];
  12091. }
  12092. /*-- END BORDER-RADIUS --*/
  12093. else if ($k == 'PADDING') {
  12094. $tmp = $this->expand24($v);
  12095. $newprop['PADDING-TOP'] = $tmp['T'];
  12096. $newprop['PADDING-RIGHT'] = $tmp['R'];
  12097. $newprop['PADDING-BOTTOM'] = $tmp['B'];
  12098. $newprop['PADDING-LEFT'] = $tmp['L'];
  12099. }
  12100. // mPDF 4.0
  12101. else if ($k == 'BORDER') {
  12102. if ($v == '1') { $v = '1px solid #000000'; }
  12103. else { $v = $this->_fix_borderStr($v); }
  12104. $newprop['BORDER-TOP'] = $v;
  12105. $newprop['BORDER-RIGHT'] = $v;
  12106. $newprop['BORDER-BOTTOM'] = $v;
  12107. $newprop['BORDER-LEFT'] = $v;
  12108. }
  12109. else if ($k == 'BORDER-TOP') {
  12110. $newprop['BORDER-TOP'] = $this->_fix_borderStr($v);
  12111. }
  12112. else if ($k == 'BORDER-RIGHT') {
  12113. $newprop['BORDER-RIGHT'] = $this->_fix_borderStr($v);
  12114. }
  12115. else if ($k == 'BORDER-BOTTOM') {
  12116. $newprop['BORDER-BOTTOM'] = $this->_fix_borderStr($v);
  12117. }
  12118. else if ($k == 'BORDER-LEFT') {
  12119. $newprop['BORDER-LEFT'] = $this->_fix_borderStr($v);
  12120. }
  12121. // mPDF 4.0
  12122. else if ($k == 'BORDER-STYLE') {
  12123. $e = $this->expand24($v);
  12124. $newprop['BORDER-TOP-STYLE'] = $e['T'];
  12125. $newprop['BORDER-RIGHT-STYLE'] = $e['R'];
  12126. $newprop['BORDER-BOTTOM-STYLE'] = $e['B'];
  12127. $newprop['BORDER-LEFT-STYLE'] = $e['L'];
  12128. }
  12129. else if ($k == 'BORDER-WIDTH') {
  12130. $e = $this->expand24($v);
  12131. $newprop['BORDER-TOP-WIDTH'] = $e['T'];
  12132. $newprop['BORDER-RIGHT-WIDTH'] = $e['R'];
  12133. $newprop['BORDER-BOTTOM-WIDTH'] = $e['B'];
  12134. $newprop['BORDER-LEFT-WIDTH'] = $e['L'];
  12135. }
  12136. else if ($k == 'BORDER-COLOR') {
  12137. $e = $this->expand24($v);
  12138. $newprop['BORDER-TOP-COLOR'] = $e['T'];
  12139. $newprop['BORDER-RIGHT-COLOR'] = $e['R'];
  12140. $newprop['BORDER-BOTTOM-COLOR'] = $e['B'];
  12141. $newprop['BORDER-LEFT-COLOR'] = $e['L'];
  12142. }
  12143. else if ($k == 'BORDER-SPACING') {
  12144. $prop = preg_split('/\s+/',trim($v));
  12145. if (count($prop) == 1 ) {
  12146. $newprop['BORDER-SPACING-H'] = $prop[0];
  12147. $newprop['BORDER-SPACING-V'] = $prop[0];
  12148. }
  12149. else if (count($prop) == 2 ) {
  12150. $newprop['BORDER-SPACING-H'] = $prop[0];
  12151. $newprop['BORDER-SPACING-V'] = $prop[1];
  12152. }
  12153. }
  12154. else if ($k == 'SIZE') {
  12155. $prop = preg_split('/\s+/',trim($v));
  12156. if (preg_match('/(auto|portrait|landscape)/',$prop[0])) {
  12157. $newprop['SIZE'] = strtoupper($prop[0]);
  12158. }
  12159. else if (count($prop) == 1 ) {
  12160. $newprop['SIZE']['W'] = $this->ConvertSize($prop[0]);
  12161. $newprop['SIZE']['H'] = $this->ConvertSize($prop[0]);
  12162. }
  12163. else if (count($prop) == 2 ) {
  12164. $newprop['SIZE']['W'] = $this->ConvertSize($prop[0]);
  12165. $newprop['SIZE']['H'] = $this->ConvertSize($prop[1]);
  12166. }
  12167. }
  12168. // mPDF 4.2.024
  12169. else if ($k == 'SHEET-SIZE') {
  12170. $prop = preg_split('/\s+/',trim($v));
  12171. if (count($prop) == 2 ) {
  12172. $newprop['SHEET-SIZE'] = array($this->ConvertSize($prop[0]), $this->ConvertSize($prop[1]));
  12173. }
  12174. else {
  12175. if(preg_match('/([0-9a-zA-Z]*)-L/i',$v,$m)) { // e.g. A4-L = A$ landscape
  12176. $ft = $this->_getPageFormat($m[1]);
  12177. $format = array($ft[1],$ft[0]);
  12178. }
  12179. else { $format = $this->_getPageFormat($v); }
  12180. if ($format) { $newprop['SHEET-SIZE'] = array($format[0]/$this->k, $format[1]/$this->k); }
  12181. }
  12182. }
  12183. // mPDF 3.0 - Tiling Patterns
  12184. else if ($k == 'BACKGROUND') {
  12185. $bg = $this->parseCSSbackground($v);
  12186. if ($bg['c']) { $newprop['BACKGROUND-COLOR'] = $bg['c']; }
  12187. // mPDF 4.3.002
  12188. else { $newprop['BACKGROUND-COLOR'] = 'transparent'; } // mPDF 4.3.002
  12189. /*-- BACKGROUND-IMAGES --*/
  12190. if ($bg['i']) {
  12191. $newprop['BACKGROUND-IMAGE'] = $bg['i'];
  12192. if ($bg['r']) { $newprop['BACKGROUND-REPEAT'] = $bg['r']; }
  12193. if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; }
  12194. }
  12195. else { $newprop['BACKGROUND-IMAGE'] = ''; } // mPDF 4.3.002 / 4.3.011
  12196. /*-- END BACKGROUND-IMAGES --*/
  12197. }
  12198. /*-- BACKGROUND-IMAGES --*/
  12199. else if ($k == 'BACKGROUND-IMAGE') {
  12200. if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)/i',$v,$m)) { // 4.2.013
  12201. $newprop['BACKGROUND-IMAGE'] = $m[1];
  12202. }
  12203. // mPDF 4.3.011
  12204. else if (strtolower($v)=='none') { $newprop['BACKGROUND-IMAGE'] = ''; }
  12205. }
  12206. // mPDF 3.0 - Tiling Patterns
  12207. else if ($k == 'BACKGROUND-REPEAT') {
  12208. if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/i',$v,$m)) {
  12209. $newprop['BACKGROUND-REPEAT'] = strtolower($m[1]);
  12210. }
  12211. }
  12212. // mPDF 3.0 - Tiling Patterns
  12213. else if ($k == 'BACKGROUND-POSITION') {
  12214. $s = $v;
  12215. $bits = preg_split('/\s+/',trim($s));
  12216. // These should be Position x1 or x2
  12217. if (count($bits)==1) {
  12218. if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; }
  12219. else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; }
  12220. else { $bg['p'] = $bits[0] . ' 50%'; }
  12221. }
  12222. else if (count($bits)==2) {
  12223. // Can be either right center or center right
  12224. if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) {
  12225. $bg['p'] = $bits[1] . ' '.$bits[0];
  12226. }
  12227. else {
  12228. $bg['p'] = $bits[0] . ' '.$bits[1];
  12229. }
  12230. }
  12231. if ($bg['p']) {
  12232. $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']);
  12233. $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']);
  12234. $bg['p'] = preg_replace('/(center)/','50%',$bg['p']);
  12235. 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'])) {
  12236. $bg['p'] = false;
  12237. }
  12238. }
  12239. if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; }
  12240. }
  12241. /*-- END BACKGROUND-IMAGES --*/
  12242. else {
  12243. $newprop[$k] = $v;
  12244. }
  12245. }
  12246. // mPDF 4.0
  12247. // $this->_mergeBorders($newprop,$newprop);
  12248. return $newprop;
  12249. }
  12250. // mPDF 3.0 - Tiling Patterns
  12251. function parseCSSbackground($s) {
  12252. // $s = strtolower($s); // mPDF 4.2.013
  12253. $bg = array('c'=>false, 'i'=>false, 'r'=>false, 'p'=>false, );
  12254. if (preg_match('/url\(/i',$s)) { // mPDF 4.2.013
  12255. // If color, set and strip it off
  12256. if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|rgb\(.*?\)|[a-zA-Z]{3,})\s+(url\(.*)/i',$s,$m)) { // mPDF 4.2.013
  12257. $bg['c'] = strtolower($m[1]); // mPDF 4.2.013
  12258. $s = $m[2];
  12259. }
  12260. /*-- BACKGROUND-IMAGES --*/
  12261. if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)\s*(.*)/i',$s,$m)) { // mPDF 4.2.013
  12262. $bg['i'] = $m[1];
  12263. $s = strtolower($m[2]); // mPDF 4.2.013
  12264. if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/',$s,$m)) {
  12265. $bg['r'] = $m[1];
  12266. }
  12267. // Remove repeat, attachment (discarded) and also any inherit
  12268. $s = preg_replace('/(repeat-x|repeat-y|no-repeat|repeat|scroll|fixed|inherit)/','',$s);
  12269. $bits = preg_split('/\s+/',trim($s));
  12270. // These should be Position x1 or x2
  12271. if (count($bits)==1) {
  12272. if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; }
  12273. else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; }
  12274. else { $bg['p'] = $bits[0] . ' 50%'; }
  12275. }
  12276. else if (count($bits)==2) {
  12277. // Can be either right center or center right
  12278. if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) {
  12279. $bg['p'] = $bits[1] . ' '.$bits[0];
  12280. }
  12281. else {
  12282. $bg['p'] = $bits[0] . ' '.$bits[1];
  12283. }
  12284. }
  12285. if ($bg['p']) {
  12286. $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']);
  12287. $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']);
  12288. $bg['p'] = preg_replace('/(center)/','50%',$bg['p']);
  12289. 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'])) {
  12290. $bg['p'] = false;
  12291. }
  12292. }
  12293. }
  12294. /*-- END BACKGROUND-IMAGES --*/
  12295. }
  12296. else if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|rgb\(.*?\)|[a-zA-Z]{3,})/i',$s,$m)) { $bg['c'] = strtolower($m[1]); } // mPDF 4.2.013
  12297. return ($bg);
  12298. }
  12299. /*-- GRADIENTS --*/
  12300. // mPDF 3.0 Gradients
  12301. function parseBackgroundGradient($bg) {
  12302. // background-gradient: linear #00FFFF #FFFF00 0 0.5 1 0.5; or
  12303. // background-gradient: radial #00FFFF #FFFF00 0.5 0.5 1 1 1.2;
  12304. $v = trim($bg);
  12305. $bgr = preg_split('/\s+/',$v);
  12306. $g = array();
  12307. if (count($bgr)> 6) {
  12308. if (strtoupper(substr($bgr[0],0,1)) == 'L' && count($bgr)==7) { // linear
  12309. $g['type'] = 2;
  12310. //$coords = array(0,0,1,1 ); // 0 0 1 0 or 0 1 1 1 is L 2 R; 1,1,0,1 is R2L; 1,1,1,0 is T2B; 1,0,1,1 is B2T
  12311. // Linear: $coords - array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg).
  12312. // The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
  12313. $g['coords'] = array($bgr[3], $bgr[4], $bgr[5], $bgr[6]);
  12314. }
  12315. else if (count($bgr)==8) { // radial
  12316. $g['type'] = 3;
  12317. // Radial: $coords - array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1,
  12318. // (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg).
  12319. // (fx, fy) should be inside the circle, otherwise some areas will not be defined
  12320. $g['coords'] = array($bgr[3], $bgr[4], $bgr[5], $bgr[6], $bgr[7]);
  12321. }
  12322. $cor = $this->ConvertColor($bgr[1]);
  12323. if ($cor) { $g['col'] = array($cor['R'],$cor['G'],$cor['B']); }
  12324. else { $g['col'] = array(255); }
  12325. $cor = $this->ConvertColor($bgr[2]);
  12326. if ($cor) { $g['col2'] = array($cor['R'],$cor['G'],$cor['B']); }
  12327. else { $g['col2'] = array(255); }
  12328. $g['extend'] = array('true','true');
  12329. return $g;
  12330. }
  12331. return false;
  12332. }
  12333. /*-- END GRADIENTS --*/
  12334. function expand24($mp) {
  12335. $prop = preg_split('/\s+/',trim($mp));
  12336. if (count($prop) == 1 ) {
  12337. return array('T' => $prop[0], 'R' => $prop[0], 'B' => $prop[0], 'L'=> $prop[0]);
  12338. }
  12339. if (count($prop) == 2 ) {
  12340. return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[0], 'L'=> $prop[1]);
  12341. }
  12342. // mPDF 4.0
  12343. if (count($prop) == 3 ) {
  12344. return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[1]);
  12345. }
  12346. if (count($prop) == 4 ) {
  12347. return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[3]);
  12348. }
  12349. return array();
  12350. }
  12351. /*-- BORDER-RADIUS --*/
  12352. function border_radius_expand($val,$k) {
  12353. $b = array();
  12354. if ($k == 'BORDER-RADIUS') {
  12355. $hv = explode('/',trim($val));
  12356. $prop = preg_split('/\s+/',trim($hv[0]));
  12357. if (count($prop)==1) {
  12358. $b['TL-H'] = $b['TR-H'] = $b['BR-H'] = $b['BL-H'] = $prop[0];
  12359. }
  12360. else if (count($prop)==2) {
  12361. $b['TL-H'] = $b['BR-H'] = $prop[0];
  12362. $b['TR-H'] = $b['BL-H'] = $prop[1];
  12363. }
  12364. else if (count($prop)==3) {
  12365. $b['TL-H'] = $prop[0];
  12366. $b['TR-H'] = $b['BL-H'] = $prop[1];
  12367. $b['BR-H'] = $prop[2];
  12368. }
  12369. else if (count($prop)==4) {
  12370. $b['TL-H'] = $prop[0];
  12371. $b['TR-H'] = $prop[1];
  12372. $b['BR-H'] = $prop[2];
  12373. $b['BL-H'] = $prop[3];
  12374. }
  12375. if (count($hv)==2) {
  12376. $prop = preg_split('/\s+/',trim($hv[1]));
  12377. if (count($prop)==1) {
  12378. $b['TL-V'] = $b['TR-V'] = $b['BR-V'] = $b['BL-V'] = $prop[0];
  12379. }
  12380. else if (count($prop)==2) {
  12381. $b['TL-V'] = $b['BR-V'] = $prop[0];
  12382. $b['TR-V'] = $b['BL-V'] = $prop[1];
  12383. }
  12384. else if (count($prop)==3) {
  12385. $b['TL-V'] = $prop[0];
  12386. $b['TR-V'] = $b['BL-V'] = $prop[1];
  12387. $b['BR-V'] = $prop[2];
  12388. }
  12389. else if (count($prop)==4) {
  12390. $b['TL-V'] = $prop[0];
  12391. $b['TR-V'] = $prop[1];
  12392. $b['BR-V'] = $prop[2];
  12393. $b['BL-V'] = $prop[3];
  12394. }
  12395. }
  12396. else {
  12397. $b['TL-V'] = $b['TL-H'];
  12398. $b['TR-V'] = $b['TR-H'];
  12399. $b['BL-V'] = $b['BL-H'];
  12400. $b['BR-V'] = $b['BR-H'];
  12401. }
  12402. return $b;
  12403. }
  12404. // Parse 2
  12405. $h = 0;
  12406. $v = 0;
  12407. $prop = preg_split('/\s+/',trim($val));
  12408. if (count($prop)==1) { $h = $v = $val; }
  12409. else { $h = $prop[0]; $v = $prop[1]; }
  12410. if ($h==0 || $v==0) { $h = $v = 0; }
  12411. if ($k == 'BORDER-TOP-LEFT-RADIUS') {
  12412. $b['TL-H'] = $h;
  12413. $b['TL-V'] = $v;
  12414. }
  12415. else if ($k == 'BORDER-TOP-RIGHT-RADIUS') {
  12416. $b['TR-H'] = $h;
  12417. $b['TR-V'] = $v;
  12418. }
  12419. else if ($k == 'BORDER-BOTTOM-LEFT-RADIUS') {
  12420. $b['BL-H'] = $h;
  12421. $b['BL-V'] = $v;
  12422. }
  12423. else if ($k == 'BORDER-BOTTOM-RIGHT-RADIUS') {
  12424. $b['BR-H'] = $h;
  12425. $b['BR-V'] = $v;
  12426. }
  12427. return $b;
  12428. }
  12429. /*-- END BORDER-RADIUS --*/
  12430. // mPDF 4.2
  12431. // Return either a number (factor) - based on current set fontsize (if % or em) - or exact lineheight (with 'mm' after it)
  12432. function fixLineheight($v) {
  12433. $lh = false;
  12434. if (preg_match('/^[0-9\.,]*$/',$v) && $v >= 0) { return ($v + 0); }
  12435. else if (strtoupper($v) == 'NORMAL') {
  12436. return $this->normalLineheight;
  12437. }
  12438. else {
  12439. $tlh = $this->ConvertSize($v,$this->FontSize,$this->FontSize,true);
  12440. if ($tlh) { return ($tlh.'mm'); }
  12441. }
  12442. return $this->normalLineheight;
  12443. }
  12444. /*-- BORDER-RADIUS --*/
  12445. // mPDF 3.0
  12446. function _borderPadding($a, $b, &$px, &$py) {
  12447. // $px and py are padding long axis (x) and short axis (y)
  12448. $added = 0; // extra padding
  12449. $x = $a-$px;
  12450. $y = $b-$py;
  12451. // Check if Falls within ellipse of border radius
  12452. if ( ( (($x+$added)*($x+$added))/($a*$a) + (($y+$added)*($y+$added))/($b*$b) ) <=1 ) { return false; }
  12453. $t = atan2($y,$x);
  12454. $newx = $b / sqrt((($b*$b)/($a*$a)) + ( tan($t) * tan($t) ) );
  12455. $newy = $a / sqrt((($a*$a)/($b*$b)) + ( (1/tan($t)) * (1/tan($t)) ) );
  12456. $px = max($px, $a - $newx + $added);
  12457. $py = max($py, $b - $newy + $added);
  12458. }
  12459. /*-- END BORDER-RADIUS --*/
  12460. /*-- TABLES --*/
  12461. function setBorderDominance($prop, $val) {
  12462. if (isset($prop['BORDER-LEFT']) && $prop['BORDER-LEFT']) { $this->cell_border_dominance_L = $val; }
  12463. if (isset($prop['BORDER-RIGHT']) && $prop['BORDER-RIGHT']) { $this->cell_border_dominance_R = $val; }
  12464. if (isset($prop['BORDER-TOP']) && $prop['BORDER-TOP']) { $this->cell_border_dominance_T = $val; }
  12465. if (isset($prop['BORDER-BOTTOM']) && $prop['BORDER-BOTTOM']) { $this->cell_border_dominance_B = $val; }
  12466. }
  12467. /*-- END TABLES --*/
  12468. // mPDF 4.0
  12469. function _mergeCSS(&$p, &$t) {
  12470. // Save Cascading CSS e.g. "div.topic p" at this block level
  12471. if (isset($p) && $p) {
  12472. $carry = $p;
  12473. if ($t) {
  12474. $t = $this->array_merge_recursive_unique($t, $carry);
  12475. }
  12476. else { $t = $carry; }
  12477. }
  12478. }
  12479. // for CSS handling
  12480. function array_merge_recursive_unique($array1, $array2) {
  12481. $arrays = func_get_args();
  12482. $narrays = count($arrays);
  12483. $ret = $arrays[0];
  12484. for ($i = 1; $i < $narrays; $i ++) {
  12485. foreach ($arrays[$i] as $key => $value) {
  12486. if (((string) $key) === ((string) intval($key))) { // integer or string as integer key - append
  12487. $ret[] = $value;
  12488. }
  12489. else { // string key - merge
  12490. if (is_array($value) && isset($ret[$key])) {
  12491. $ret[$key] = $this->array_merge_recursive_unique($ret[$key], $value);
  12492. }
  12493. else {
  12494. $ret[$key] = $value;
  12495. }
  12496. }
  12497. }
  12498. }
  12499. return $ret;
  12500. }
  12501. // mPDF 4.0
  12502. function _mergeFullCSS(&$p, &$t, $tag, $classes, $id) {
  12503. $this->_mergeCSS($p[$tag], $t);
  12504. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  12505. foreach($classes AS $class) {
  12506. $this->_mergeCSS($p['CLASS>>'.$class], $t);
  12507. }
  12508. // STYLESHEET CLASS e.g. #smallone{} #redletter{}
  12509. if (isset($id)) {
  12510. $this->_mergeCSS($p['ID>>'.$id], $t);
  12511. }
  12512. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  12513. foreach($classes AS $class) {
  12514. $this->_mergeCSS($p[$tag.'>>CLASS>>'.$class], $t);
  12515. }
  12516. // STYLESHEET CLASS e.g. #smallone{} #redletter{}
  12517. if (isset($id)) {
  12518. $this->_mergeCSS($p[$tag.'>>ID>>'.$id], $t);
  12519. }
  12520. }
  12521. // mPDF 4.0
  12522. function _set_mergedCSS(&$m, &$p, $d=true, $bd=false) {
  12523. if (isset($m)) {
  12524. if ((isset($m['depth']) && $m['depth']>1) || $d==false) { // include check for 'depth'
  12525. if ($bd) { $this->setBorderDominance($m, $bd); } // *TABLES*
  12526. if (is_array($m)) {
  12527. $p = array_merge($p,$m);
  12528. $this->_mergeBorders($p,$m); // mPDF 4.0
  12529. }
  12530. }
  12531. }
  12532. }
  12533. // mPDF 4.0
  12534. function _mergeBorders(&$b, &$a) { // Merges $a['BORDER-TOP-STYLE'] to $b['BORDER-TOP'] etc.
  12535. foreach(array('TOP','RIGHT','BOTTOM','LEFT') AS $side) {
  12536. foreach(array('STYLE','WIDTH','COLOR') AS $el) {
  12537. if (isset($a['BORDER-'.$side.'-'.$el])) { // e.g. $b['BORDER-TOP-STYLE']
  12538. $s = trim($a['BORDER-'.$side.'-'.$el]);
  12539. if (isset($b['BORDER-'.$side])) { // e.g. $b['BORDER-TOP']
  12540. $p = trim($b['BORDER-'.$side]);
  12541. }
  12542. else { $p = ''; }
  12543. if ($el=='STYLE') {
  12544. if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 '.$s.' \\3', $p); }
  12545. else { $b['BORDER-'.$side] = '0px '.$s.' #000000'; }
  12546. }
  12547. else if ($el=='WIDTH') {
  12548. if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', $s.' \\2 \\3', $p); }
  12549. else { $b['BORDER-'.$side] = $s.' none #000000'; }
  12550. }
  12551. else if ($el=='COLOR') {
  12552. if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 \\2 '.$s, $p); }
  12553. else { $b['BORDER-'.$side] = '0px none '.$s; }
  12554. }
  12555. unset($a['BORDER-'.$side.'-'.$el]);
  12556. }
  12557. }
  12558. }
  12559. }
  12560. function MergeCSS($inherit,$tag,$attr) {
  12561. $p = array();
  12562. $zp = array();
  12563. $classes = array();
  12564. if (isset($attr['CLASS'])) {
  12565. $classes = preg_split('/\s+/',$attr['CLASS']);
  12566. }
  12567. //===============================================
  12568. /*-- TABLES --*/
  12569. // Set Inherited properties
  12570. if ($inherit == 'TOPTABLE') { // $tag = TABLE
  12571. //===============================================
  12572. // Save Cascading CSS e.g. "div.topic p" at this block level
  12573. if (isset($this->blk[$this->blklvl]['cascadeCSS'])) {
  12574. $this->tablecascadeCSS[0] = $this->blk[$this->blklvl]['cascadeCSS'];
  12575. }
  12576. else {
  12577. $this->tablecascadeCSS[0] = $this->cascadeCSS;
  12578. }
  12579. }
  12580. //===============================================
  12581. // Set Inherited properties
  12582. if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') {
  12583. //Cascade everything from last level that is not an actual property, or defined by current tag/attributes
  12584. if (isset($this->tablecascadeCSS[$this->tbCSSlvl-1]) && is_array($this->tablecascadeCSS[$this->tbCSSlvl-1])) {
  12585. foreach($this->tablecascadeCSS[$this->tbCSSlvl-1] AS $k=>$v) {
  12586. // if ($k != $tag && !preg_match('/^CLASS>>('.implode('|',$classes).')$/i',$k) && !preg_match('/^'.$tag.'>>CLASS>>('.implode('|',$classes).')$/i',$k) && $k != 'ID>>'.$attr['ID'] && $k != $tag.'>>ID>>'.$attr['ID'] && (preg_match('/(ID|CLASS)>>/',$k) || preg_match('/^('.$this->allowedCSStags.')(>>.*){0,1}$/',$k))) {
  12587. $this->tablecascadeCSS[$this->tbCSSlvl][$k] = $v;
  12588. // }
  12589. }
  12590. }
  12591. // mPDF 4.0
  12592. $this->_mergeFullCSS($this->cascadeCSS, $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID']);
  12593. //===============================================
  12594. // Cascading forward CSS e.g. "table.topic td" for this table in $this->tablecascadeCSS
  12595. //===============================================
  12596. // STYLESHEET TAG e.g. table
  12597. // mPDF 4.0
  12598. $this->_mergeFullCSS($this->tablecascadeCSS[$this->tbCSSlvl-1], $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID']);
  12599. //===============================================
  12600. }
  12601. /*-- END TABLES --*/
  12602. //===============================================
  12603. /*-- LISTS --*/
  12604. // Set Inherited properties
  12605. if ($inherit == 'TOPLIST') { // $tag = UL,OL
  12606. //===============================================
  12607. // Save Cascading CSS e.g. "div.topic p" at this block level
  12608. if (isset($this->blk[$this->blklvl]['cascadeCSS'])) {
  12609. $this->listcascadeCSS[0] = $this->blk[$this->blklvl]['cascadeCSS'];
  12610. }
  12611. else {
  12612. $this->listcascadeCSS[0] = $this->cascadeCSS;
  12613. }
  12614. }
  12615. //===============================================
  12616. // Set Inherited properties
  12617. if ($inherit == 'TOPLIST' || $inherit == 'LIST') {
  12618. //Cascade everything from last level that is not an actual property, or defined by current tag/attributes
  12619. if (isset($this->listcascadeCSS[$this->listCSSlvl-1]) && is_array($this->listcascadeCSS[$this->listCSSlvl-1])) {
  12620. foreach($this->listcascadeCSS[$this->listCSSlvl-1] AS $k=>$v) {
  12621. $this->listcascadeCSS[$this->listCSSlvl][$k] = $v;
  12622. }
  12623. }
  12624. // mPDF 4.0
  12625. $this->_mergeFullCSS($this->cascadeCSS, $this->listcascadeCSS[$this->listCSSlvl], $tag, $classes, $attr['ID']);
  12626. //===============================================
  12627. // Cascading forward CSS e.g. "table.topic td" for this list in $this->listcascadeCSS
  12628. //===============================================
  12629. // STYLESHEET TAG e.g. table
  12630. // mPDF 4.0
  12631. $this->_mergeFullCSS($this->listcascadeCSS[$this->listCSSlvl-1], $this->listcascadeCSS[$this->listCSSlvl], $tag, $classes, $attr['ID']);
  12632. //===============================================
  12633. }
  12634. /*-- END LISTS --*/
  12635. //===============================================
  12636. // Set Inherited properties
  12637. if ($inherit == 'BLOCK') {
  12638. if (isset($this->blk[$this->blklvl-1]['cascadeCSS']) && is_array($this->blk[$this->blklvl-1]['cascadeCSS'])) {
  12639. foreach($this->blk[$this->blklvl-1]['cascadeCSS'] AS $k=>$v) {
  12640. // if ($k != $tag && !preg_match('/^CLASS>>('.implode('|',$classes).')$/i',$k) && !preg_match('/^'.$tag.'>>CLASS>>('.implode('|',$classes).')$/i',$k) && $k != 'ID>>'.$attr['ID'] && $k != $tag.'>>ID>>'.$attr['ID'] && (preg_match('/(ID|CLASS)>>/',$k) || preg_match('/^('.$this->allowedCSStags.')(>>.*){0,1}$/',$k))) {
  12641. $this->blk[$this->blklvl]['cascadeCSS'][$k] = $v;
  12642. // }
  12643. }
  12644. }
  12645. //===============================================
  12646. // Save Cascading CSS e.g. "div.topic p" at this block level
  12647. // mPDF 4.0
  12648. if (!isset($attr['ID'])) {
  12649. $attr['ID'] = null;
  12650. }
  12651. $this->_mergeFullCSS($this->cascadeCSS, $this->blk[$this->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID']);
  12652. //===============================================
  12653. // Cascading forward CSS
  12654. //===============================================
  12655. // mPDF 4.0
  12656. $this->_mergeFullCSS($this->blk[$this->blklvl-1]['cascadeCSS'], $this->blk[$this->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID']);
  12657. //===============================================
  12658. // Block properties
  12659. 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
  12660. 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']; }
  12661. if (isset($this->blk[$this->blklvl-1]['align']) && $this->blk[$this->blklvl-1]['align']) {
  12662. if ($this->blk[$this->blklvl-1]['align'] == 'L') { $p['TEXT-ALIGN'] = 'left'; }
  12663. else if ($this->blk[$this->blklvl-1]['align'] == 'J') { $p['TEXT-ALIGN'] = 'justify'; }
  12664. else if ($this->blk[$this->blklvl-1]['align'] == 'R') { $p['TEXT-ALIGN'] = 'right'; }
  12665. else if ($this->blk[$this->blklvl-1]['align'] == 'C') { $p['TEXT-ALIGN'] = 'center'; }
  12666. }
  12667. // mPDF 3.0
  12668. if ($this->ColActive || $this->keep_block_together) {
  12669. if (isset($this->blk[$this->blklvl-1]['bgcolor']) && $this->blk[$this->blklvl-1]['bgcolor']) { // Doesn't officially inherit, but default value is transparent (?=inherited)
  12670. $cor = $this->blk[$this->blklvl-1]['bgcolorarray' ];
  12671. $p['BACKGROUND-COLOR'] = 'RGB('.$cor['R'].','.$cor['G'].','.$cor['B'].')';
  12672. }
  12673. }
  12674. // mPDF 4.0
  12675. 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']; }
  12676. // mPDF 4.0
  12677. $biilp = $this->blk[$this->blklvl-1]['InlineProperties'];
  12678. if (isset($biilp[ 'family' ]) && $biilp[ 'family' ]) { $p['FONT-FAMILY'] = $biilp[ 'family' ]; }
  12679. if (isset($biilp[ 'I' ]) && $biilp[ 'I' ]) { $p['FONT-STYLE'] = 'italic'; }
  12680. if (isset($biilp[ 'sizePt' ]) && $biilp[ 'sizePt' ]) { $p['FONT-SIZE'] = $biilp[ 'sizePt' ] . 'pt'; }
  12681. if (isset($biilp[ 'B' ]) && $biilp[ 'B' ]) { $p['FONT-WEIGHT'] = 'bold'; }
  12682. if (isset($biilp[ 'colorarray' ]) && $biilp[ 'colorarray' ]) {
  12683. $cor = $biilp[ 'colorarray' ];
  12684. $p['COLOR'] = 'RGB('.$cor['R'].','.$cor['G'].','.$cor['B'].')';
  12685. }
  12686. if (isset($biilp[ 'toupper' ]) && $biilp[ 'toupper' ]) { $p['TEXT-TRANSFORM'] = 'uppercase'; }
  12687. else if (isset($biilp[ 'tolower' ]) && $biilp[ 'tolower' ]) { $p['TEXT-TRANSFORM'] = 'lowercase'; }
  12688. // CSS says text-decoration is not inherited, but IE7 does??
  12689. if (isset($biilp[ 'underline' ]) && $biilp[ 'underline' ]) { $p['TEXT-DECORATION'] = 'underline'; }
  12690. }
  12691. //===============================================
  12692. //===============================================
  12693. /*-- LISTS --*/
  12694. // Set Inherited properties
  12695. // mPDF 4.2
  12696. if ($inherit == 'TOPLIST') {
  12697. if ($this->listCSSlvl == 1) {
  12698. $bilp = $this->blk[$this->blklvl]['InlineProperties'];
  12699. if (isset($bilp[ 'family' ]) && $bilp[ 'family' ]) { $p['FONT-FAMILY'] = $bilp[ 'family' ]; }
  12700. if (isset($bilp[ 'I' ]) && $bilp[ 'I' ]) { $p['FONT-STYLE'] = 'italic'; }
  12701. if (isset($bilp[ 'sizePt' ]) && $bilp[ 'sizePt' ]) { $p['FONT-SIZE'] = $bilp[ 'sizePt' ] . 'pt'; }
  12702. if (isset($bilp[ 'B' ]) && $bilp[ 'B' ]) { $p['FONT-WEIGHT'] = 'bold'; }
  12703. if (isset($bilp[ 'colorarray' ]) && $bilp[ 'colorarray' ]) {
  12704. $cor = $bilp[ 'colorarray' ];
  12705. $p['COLOR'] = 'RGB('.$cor['R'].','.$cor['G'].','.$cor['B'].')';
  12706. }
  12707. if (isset($bilp[ 'toupper' ]) && $bilp[ 'toupper' ]) { $p['TEXT-TRANSFORM'] = 'uppercase'; }
  12708. else if (isset($bilp[ 'tolower' ]) && $bilp[ 'tolower' ]) { $p['TEXT-TRANSFORM'] = 'lowercase'; }
  12709. // CSS says text-decoration is not inherited, but IE7 does??
  12710. if (isset($bilp[ 'underline' ]) && $bilp[ 'underline' ]) { $p['TEXT-DECORATION'] = 'underline'; }
  12711. if ($tag=='LI') {
  12712. $lilp = $this->InlineProperties['LIST'][$this->listlvl][$this->listoccur[$this->listlvl]];
  12713. if (isset($lilp[ 'family' ]) && $lilp[ 'family' ]) { $p['FONT-FAMILY'] = $lilp[ 'family' ]; }
  12714. if (isset($lilp[ 'I' ]) && $lilp[ 'I' ]) { $p['FONT-STYLE'] = 'italic'; }
  12715. if (isset($lilp[ 'sizePt' ]) && $lilp[ 'sizePt' ]) { $p['FONT-SIZE'] = $lilp[ 'sizePt' ] . 'pt'; }
  12716. if (isset($lilp[ 'B' ]) && $lilp[ 'B' ]) { $p['FONT-WEIGHT'] = 'bold'; }
  12717. if (isset($lilp[ 'colorarray' ]) && $lilp[ 'colorarray' ]) {
  12718. $cor = $lilp[ 'colorarray' ];
  12719. $p['COLOR'] = 'RGB('.$cor['R'].','.$cor['G'].','.$cor['B'].')';
  12720. }
  12721. if (isset($lilp[ 'toupper' ]) && $lilp[ 'toupper' ]) { $p['TEXT-TRANSFORM'] = 'uppercase'; }
  12722. else if (isset($lilp[ 'tolower' ]) && $lilp[ 'tolower' ]) { $p['TEXT-TRANSFORM'] = 'lowercase'; }
  12723. // CSS says text-decoration is not inherited, but IE7 does??
  12724. if (isset($lilp[ 'underline' ]) && $lilp[ 'underline' ]) { $p['TEXT-DECORATION'] = 'underline'; }
  12725. }
  12726. }
  12727. }
  12728. /*-- END LISTS --*/
  12729. //===============================================
  12730. //===============================================
  12731. // DEFAULT for this TAG set in DefaultCSS
  12732. if (isset($this->defaultCSS[$tag])) {
  12733. $zp = $this->fixCSS($this->defaultCSS[$tag]);
  12734. /*-- RTL --*/
  12735. // mPDF 4.0 $rtlCSS can be any value
  12736. if ($this->directionality == 'rtl') {
  12737. if (isset($zp['TEXT-ALIGN'])) { $this->reverse_align($zp['TEXT-ALIGN']); } // mPDF 4.0
  12738. $pl = $zp['PADDING-LEFT'];
  12739. $pr = $zp['PADDING-RIGHT'];
  12740. if ($pl || $pr) { $zp['PADDING-RIGHT'] = $pl; $zp['PADDING-LEFT'] = $pr; }
  12741. $ml = $zp['MARGIN-LEFT'];
  12742. $mr = $zp['MARGIN-RIGHT'];
  12743. if ($ml || $mr) { $zp['MARGIN-RIGHT'] = $ml; $zp['MARGIN-LEFT'] = $mr; }
  12744. $bl = $zp['BORDER-LEFT'];
  12745. $br = $zp['BORDER-RIGHT'];
  12746. if ($bl || $br) { $zp['BORDER-RIGHT'] = $bl; $zp['BORDER-LEFT'] = $br; }
  12747. }
  12748. /*-- END RTL --*/
  12749. if (is_array($zp)) { // Default overwrites Inherited
  12750. $p = array_merge($p,$zp); // !! Note other way round !!
  12751. $this->_mergeBorders($p,$zp); // mPDF 4.0
  12752. }
  12753. }
  12754. //===============================================
  12755. /*-- TABLES --*/
  12756. // mPDF 4.0 cellPadding overwrites TD/TH default but not specific CSS set on cell
  12757. if (($tag=='TD' || $tag=='TH') && ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'] || $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding']===0)) { // mPDF 4.4.014
  12758. $p['PADDING-LEFT'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  12759. $p['PADDING-RIGHT'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  12760. $p['PADDING-TOP'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  12761. $p['PADDING-BOTTOM'] = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cell_padding'];
  12762. }
  12763. /*-- END TABLES --*/
  12764. //===============================================
  12765. // STYLESHEET TAG e.g. h1 p div table
  12766. if (isset($this->CSS[$tag]) && $this->CSS[$tag]) {
  12767. $zp = $this->CSS[$tag];
  12768. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  12769. if (is_array($zp)) {
  12770. // mPDF 4.0
  12771. if (($this->directionality == 'rtl') && ($this->rtlCSS > 0) && isset($zp['TEXT-ALIGN'])) { $this->reverse_align($zp['TEXT-ALIGN']); } // *RTL*
  12772. $p = array_merge($p,$zp);
  12773. $this->_mergeBorders($p,$zp); // mPDF 4.0
  12774. }
  12775. }
  12776. //===============================================
  12777. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  12778. foreach($classes AS $class) {
  12779. $zp = array();
  12780. if (isset($this->CSS['CLASS>>'.$class]) && $this->CSS['CLASS>>'.$class]) { $zp = $this->CSS['CLASS>>'.$class]; }
  12781. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  12782. if (is_array($zp)) {
  12783. // mPDF 4.0
  12784. if (($this->directionality == 'rtl') && ($this->rtlCSS > 0) && isset($zp['TEXT-ALIGN'])) { $this->reverse_align($zp['TEXT-ALIGN']); } // *RTL*
  12785. $p = array_merge($p,$zp);
  12786. $this->_mergeBorders($p,$zp); // mPDF 4.0
  12787. }
  12788. }
  12789. //===============================================
  12790. // STYLESHEET ID e.g. #smallone{} #redletter{}
  12791. if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']]) && $this->CSS['ID>>'.$attr['ID']]) {
  12792. $zp = $this->CSS['ID>>'.$attr['ID']];
  12793. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  12794. if (is_array($zp)) {
  12795. // mPDF 4.0
  12796. if (($this->directionality == 'rtl') && ($this->rtlCSS > 0) && isset($zp['TEXT-ALIGN'])) { $this->reverse_align($zp['TEXT-ALIGN']); } // *RTL*
  12797. $p = array_merge($p,$zp);
  12798. $this->_mergeBorders($p,$zp); // mPDF 4.0
  12799. }
  12800. }
  12801. //===============================================
  12802. // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
  12803. foreach($classes AS $class) {
  12804. $zp = array();
  12805. if (isset($this->CSS[$tag.'>>CLASS>>'.$class]) && $this->CSS[$tag.'>>CLASS>>'.$class]) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; }
  12806. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  12807. if (is_array($zp)) {
  12808. // mPDF 4.0
  12809. if (($this->directionality == 'rtl') && ($this->rtlCSS > 0) && isset($zp['TEXT-ALIGN'])) { $this->reverse_align($zp['TEXT-ALIGN']); } // *RTL*
  12810. $p = array_merge($p,$zp);
  12811. $this->_mergeBorders($p,$zp); // mPDF 4.0
  12812. }
  12813. }
  12814. //===============================================
  12815. // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
  12816. if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']]) && $this->CSS[$tag.'>>ID>>'.$attr['ID']]) {
  12817. $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']];
  12818. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  12819. if (is_array($zp)) {
  12820. // mPDF 4.0
  12821. if (($this->directionality == 'rtl') && ($this->rtlCSS > 0) && isset($zp['TEXT-ALIGN'])) { $this->reverse_align($zp['TEXT-ALIGN']); } // *RTL*
  12822. $p = array_merge($p,$zp);
  12823. $this->_mergeBorders($p,$zp); // mPDF 4.0
  12824. }
  12825. }
  12826. //===============================================
  12827. // Cascaded e.g. div.class p only works for block level
  12828. if ($inherit == 'BLOCK') {
  12829. // mPDF 4.0
  12830. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS'][$tag], $p);
  12831. foreach($classes AS $class) {
  12832. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS']['CLASS>>'.$class], $p);
  12833. }
  12834. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS']['ID>>'.$attr['ID']], $p);
  12835. foreach($classes AS $class) {
  12836. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p);
  12837. }
  12838. $this->_set_mergedCSS($this->blk[$this->blklvl-1]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p);
  12839. }
  12840. // mPDF 4.0
  12841. else if ($inherit == 'INLINE') {
  12842. // mPDF 4.0
  12843. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS'][$tag], $p);
  12844. foreach($classes AS $class) {
  12845. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS']['CLASS>>'.$class], $p);
  12846. }
  12847. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS']['ID>>'.$attr['ID']], $p);
  12848. foreach($classes AS $class) {
  12849. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p);
  12850. }
  12851. $this->_set_mergedCSS($this->blk[$this->blklvl]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p);
  12852. }
  12853. /*-- TABLES --*/
  12854. else if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') { // NB looks at $this->tablecascadeCSS-1 for cascading CSS
  12855. // false, 9 = don't check for 'depth' and do set border dominance
  12856. // mPDF 4.0
  12857. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag], $p, false, 9);
  12858. foreach($classes AS $class) {
  12859. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['CLASS>>'.$class], $p, false, 9);
  12860. }
  12861. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['ID>>'.$attr['ID']], $p, false, 9);
  12862. foreach($classes AS $class) {
  12863. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>CLASS>>'.$class], $p, false, 9);
  12864. }
  12865. $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>ID>>'.$attr['ID']], $p, false, 9);
  12866. }
  12867. /*-- END TABLES --*/
  12868. //===============================================
  12869. /*-- LISTS --*/
  12870. else if ($inherit == 'TOPLIST' || $inherit == 'LIST') { // NB looks at $this->listcascadeCSS-1 for cascading CSS
  12871. // false = don't check for 'depth'
  12872. // mPDF 4.0
  12873. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1][$tag], $p, false);
  12874. foreach($classes AS $class) {
  12875. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1]['CLASS>>'.$class], $p, false);
  12876. }
  12877. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1]['ID>>'.$attr['ID']], $p, false);
  12878. foreach($classes AS $class) {
  12879. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1][$tag.'>>CLASS>>'.$class], $p, false);
  12880. }
  12881. $this->_set_mergedCSS($this->listcascadeCSS[$this->listCSSlvl-1][$tag.'>>ID>>'.$attr['ID']], $p, false);
  12882. }
  12883. /*-- END LISTS --*/
  12884. //===============================================
  12885. //===============================================
  12886. // INLINE STYLE e.g. style="CSS:property"
  12887. if (isset($attr['STYLE'])) {
  12888. $zp = $this->readInlineCSS($attr['STYLE']);
  12889. if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
  12890. if (is_array($zp)) {
  12891. // mPDF 4.0
  12892. if (($this->directionality == 'rtl') && ($this->rtlCSS > 1) && isset($zp['TEXT-ALIGN'])) { // *RTL*
  12893. $this->reverse_align($zp['TEXT-ALIGN']); // *RTL*
  12894. } // *RTL*
  12895. $p = array_merge($p,$zp);
  12896. $this->_mergeBorders($p,$zp); // mPDF 4.0
  12897. }
  12898. }
  12899. //===============================================
  12900. //===============================================
  12901. // INLINE ATTRIBUTES e.g. .. ALIGN="CENTER">
  12902. if (isset($attr['LANG']) and $attr['LANG']!='') {
  12903. $p['LANG'] = $attr['LANG'];
  12904. }
  12905. if (isset($attr['COLOR']) and $attr['COLOR']!='') {
  12906. $p['COLOR'] = $attr['COLOR'];
  12907. }
  12908. if ($tag != 'INPUT') {
  12909. if (isset($attr['WIDTH']) and $attr['WIDTH']!='') {
  12910. $p['WIDTH'] = $attr['WIDTH'];
  12911. }
  12912. if (isset($attr['HEIGHT']) and $attr['HEIGHT']!='') {
  12913. $p['HEIGHT'] = $attr['HEIGHT'];
  12914. }
  12915. }
  12916. if ($tag == 'FONT') {
  12917. if (isset($attr['FACE'])) {
  12918. $p['FONT-FAMILY'] = $attr['FACE'];
  12919. }
  12920. if (isset($attr['SIZE']) and $attr['SIZE']!='') {
  12921. $s = '';
  12922. if ($attr['SIZE'] === '+1') { $s = '120%'; }
  12923. else if ($attr['SIZE'] === '-1') { $s = '86%'; }
  12924. else if ($attr['SIZE'] === '1') { $s = 'XX-SMALL'; }
  12925. else if ($attr['SIZE'] == '2') { $s = 'X-SMALL'; }
  12926. else if ($attr['SIZE'] == '3') { $s = 'SMALL'; }
  12927. else if ($attr['SIZE'] == '4') { $s = 'MEDIUM'; }
  12928. else if ($attr['SIZE'] == '5') { $s = 'LARGE'; }
  12929. else if ($attr['SIZE'] == '6') { $s = 'X-LARGE'; }
  12930. else if ($attr['SIZE'] == '7') { $s = 'XX-LARGE'; }
  12931. if ($s) $p['FONT-SIZE'] = $s;
  12932. }
  12933. }
  12934. if (isset($attr['VALIGN']) and $attr['VALIGN']!='') {
  12935. $p['VERTICAL-ALIGN'] = $attr['VALIGN'];
  12936. }
  12937. if (isset($attr['VSPACE']) and $attr['VSPACE']!='') {
  12938. $p['MARGIN-TOP'] = $attr['VSPACE'];
  12939. $p['MARGIN-BOTTOM'] = $attr['VSPACE'];
  12940. }
  12941. if (isset($attr['HSPACE']) and $attr['HSPACE']!='') {
  12942. $p['MARGIN-LEFT'] = $attr['HSPACE'];
  12943. $p['MARGIN-RIGHT'] = $attr['HSPACE'];
  12944. }
  12945. //===============================================
  12946. return $p;
  12947. }
  12948. /*-- CSS-PAGE --*/
  12949. // mPDF 4.2
  12950. function SetPagedMediaCSS($name='', $first, $oddEven) {
  12951. if ($oddEven == 'E') {
  12952. if ($this->directionality=='rtl') { $side = 'R'; }
  12953. else { $side = 'L'; }
  12954. }
  12955. else {
  12956. if ($this->directionality=='rtl') { $side = 'L'; }
  12957. else { $side = 'R'; }
  12958. }
  12959. $name = strtoupper($name);
  12960. $p = array();
  12961. $p['SIZE'] = 'AUTO';
  12962. // Uses mPDF original margins as default
  12963. $p['MARGIN-RIGHT'] = strval($this->orig_rMargin).'mm';
  12964. $p['MARGIN-LEFT'] = strval($this->orig_lMargin).'mm';
  12965. $p['MARGIN-TOP'] = strval($this->orig_tMargin).'mm';
  12966. $p['MARGIN-BOTTOM'] = strval($this->orig_bMargin).'mm';
  12967. $p['MARGIN-HEADER'] = strval($this->orig_hMargin).'mm';
  12968. $p['MARGIN-FOOTER'] = strval($this->orig_fMargin).'mm';
  12969. // Basic page + selector
  12970. if (isset($this->CSS['@PAGE'])) { $zp = $this->CSS['@PAGE']; }
  12971. else { $zp = array(); }
  12972. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  12973. if (isset($p['EVEN-HEADER-NAME']) && $oddEven=='E') {
  12974. $p['HEADER'] = $p['EVEN-HEADER-NAME']; unset($p['EVEN-HEADER-NAME']);
  12975. }
  12976. if (isset($p['ODD-HEADER-NAME']) && $oddEven!='E') {
  12977. $p['HEADER'] = $p['ODD-HEADER-NAME']; unset($p['ODD-HEADER-NAME']);
  12978. }
  12979. if (isset($p['EVEN-FOOTER-NAME']) && $oddEven=='E') {
  12980. $p['FOOTER'] = $p['EVEN-FOOTER-NAME']; unset($p['EVEN-FOOTER-NAME']);
  12981. }
  12982. if (isset($p['ODD-FOOTER-NAME']) && $oddEven!='E') {
  12983. $p['FOOTER'] = $p['ODD-FOOTER-NAME']; unset($p['ODD-FOOTER-NAME']);
  12984. }
  12985. // If right/Odd page
  12986. if (isset($this->CSS['@PAGE>>PSEUDO>>RIGHT']) && $side=='R') {
  12987. $zp = $this->CSS['@PAGE>>PSEUDO>>RIGHT'];
  12988. }
  12989. else { $zp = array(); }
  12990. // mPDF 4.2.022 Disallow size or sheet-size on :LEFT or :RIGHT or :FIRST
  12991. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  12992. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); } // mPDF 4.2.024
  12993. // Disallow margin-left or -right on :LEFT or :RIGHT
  12994. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  12995. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  12996. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  12997. // If left/Even page
  12998. if (isset($this->CSS['@PAGE>>PSEUDO>>LEFT']) && $side=='L') { // mPDF 4.2 This had RIGHT in error
  12999. $zp = $this->CSS['@PAGE>>PSEUDO>>LEFT'];
  13000. }
  13001. else { $zp = array(); }
  13002. // mPDF 4.2.022 Disallow size or sheet-size on :LEFT or :RIGHT or :FIRST
  13003. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13004. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); } // mPDF 4.2.024
  13005. // Disallow margin-left or -right on :LEFT or :RIGHT
  13006. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  13007. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  13008. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13009. // If first page
  13010. if (isset($this->CSS['@PAGE>>PSEUDO>>FIRST']) && $first) { $zp = $this->CSS['@PAGE>>PSEUDO>>FIRST']; }
  13011. else { $zp = array(); }
  13012. // mPDF 4.2.022 Disallow size or sheet-size on :LEFT or :RIGHT or :FIRST
  13013. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13014. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); } // mPDF 4.2.024
  13015. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13016. // If named page
  13017. if ($name) {
  13018. if (isset($this->CSS['@PAGE>>NAMED>>'.$name])) { $zp = $this->CSS['@PAGE>>NAMED>>'.$name]; }
  13019. else { $zp = array(); }
  13020. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13021. if (isset($p['EVEN-HEADER-NAME']) && $oddEven=='E') {
  13022. $p['HEADER'] = $p['EVEN-HEADER-NAME']; unset($p['EVEN-HEADER-NAME']);
  13023. }
  13024. if (isset($p['ODD-HEADER-NAME']) && $oddEven!='E') {
  13025. $p['HEADER'] = $p['ODD-HEADER-NAME']; unset($p['ODD-HEADER-NAME']);
  13026. }
  13027. if (isset($p['EVEN-FOOTER-NAME']) && $oddEven=='E') {
  13028. $p['FOOTER'] = $p['EVEN-FOOTER-NAME']; unset($p['EVEN-FOOTER-NAME']);
  13029. }
  13030. if (isset($p['ODD-FOOTER-NAME']) && $oddEven!='E') {
  13031. $p['FOOTER'] = $p['ODD-FOOTER-NAME']; unset($p['ODD-FOOTER-NAME']);
  13032. }
  13033. // If named right/Odd page
  13034. if (isset($this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>RIGHT']) && $side=='R') { $zp = $this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>RIGHT']; }
  13035. else { $zp = array(); }
  13036. // mPDF 4.2.022 Disallow size or sheet-size on :LEFT or :RIGHT or :FIRST
  13037. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13038. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); } // mPDF 4.2.024
  13039. // Disallow margin-left or -right on :LEFT or :RIGHT
  13040. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  13041. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  13042. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13043. // If named left/Even page
  13044. if (isset($this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>LEFT']) && $side=='L') { $zp = $this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>LEFT']; }
  13045. else { $zp = array(); }
  13046. // mPDF 4.2.022 Disallow size or sheet-size on :LEFT or :RIGHT or :FIRST
  13047. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13048. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); } // mPDF 4.2.024
  13049. // Disallow margin-left or -right on :LEFT or :RIGHT
  13050. if (isset($zp['MARGIN-LEFT'])) { unset($zp['MARGIN-LEFT']); }
  13051. if (isset($zp['MARGIN-RIGHT'])) { unset($zp['MARGIN-RIGHT']); }
  13052. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13053. // If named first page
  13054. if (isset($this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>FIRST']) && $first) { $zp = $this->CSS['@PAGE>>NAMED>>'.$name.'>>PSEUDO>>FIRST']; }
  13055. else { $zp = array(); }
  13056. // mPDF 4.2.022 Disallow size or sheet-size on :LEFT or :RIGHT or :FIRST
  13057. if (isset($zp['SIZE'])) { unset($zp['SIZE']); }
  13058. if (isset($zp['SHEET-SIZE'])) { unset($zp['SHEET-SIZE']); } // mPDF 4.2.024
  13059. if (is_array($zp) && !empty($zp)) { $p = array_merge($p,$zp); }
  13060. }
  13061. // mPDF 4.2
  13062. $orientation = $mgl = $mgr = $mgt = $mgb = $mgh = $mgf = '';
  13063. $header = $footer = '';
  13064. $resetpagenum = $pagenumstyle = $suppress = '';
  13065. $marks = '';
  13066. $bg = array();
  13067. // mPDF 4.2.024
  13068. $newformat = '';
  13069. // mPDF 4.2.024
  13070. if (isset($p['SHEET-SIZE']) && is_array($p['SHEET-SIZE'])) {
  13071. $newformat = $p['SHEET-SIZE'];
  13072. if ($newformat[0] > $newformat[1]) { // landscape
  13073. $newformat = array_reverse($newformat);
  13074. $p['ORIENTATION'] = 'L';
  13075. }
  13076. else { $p['ORIENTATION'] = 'P'; }
  13077. $this->_setPageSize($newformat, $p['ORIENTATION']);
  13078. }
  13079. if (isset($p['SIZE']) && is_array($p['SIZE']) && !$newformat) { // mPDF 4.2.024
  13080. if ($p['SIZE']['W'] > $p['SIZE']['H']) { $p['ORIENTATION'] = 'L'; }
  13081. else { $p['ORIENTATION'] = 'P'; }
  13082. }
  13083. if (is_array($p['SIZE'])) {
  13084. if ($p['SIZE']['W'] > $this->fw) { $p['SIZE']['W'] = $this->fw; } // mPD 4.2 use fw not fPt
  13085. if ($p['SIZE']['H'] > $this->fh) { $p['SIZE']['H'] = $this->fh; }
  13086. if (($p['ORIENTATION']==$this->DefOrientation && !$newformat) || ($newformat && $p['ORIENTATION']=='P')) { // mPDF 4.2.024
  13087. $outer_width_LR = ($this->fw - $p['SIZE']['W'])/2;
  13088. $outer_width_TB = ($this->fh - $p['SIZE']['H'])/2;
  13089. }
  13090. else {
  13091. $outer_width_LR = ($this->fh - $p['SIZE']['W'])/2;
  13092. $outer_width_TB = ($this->fw - $p['SIZE']['H'])/2;
  13093. }
  13094. $pgw = $p['SIZE']['W'];
  13095. $pgh = $p['SIZE']['H'];
  13096. }
  13097. else { // AUTO LANDSCAPE PORTRAIT
  13098. $outer_width_LR = 0;
  13099. $outer_width_TB = 0;
  13100. // mPDF 4.2.024 If new sheet size not specified, set orientation based on page-box
  13101. if (!$newformat) {
  13102. if (strtoupper($p['SIZE']) == 'AUTO') { $p['ORIENTATION']=$this->DefOrientation; }
  13103. else if (strtoupper($p['SIZE']) == 'LANDSCAPE') { $p['ORIENTATION']='L'; }
  13104. else { $p['ORIENTATION']='P'; }
  13105. }
  13106. if (($p['ORIENTATION']==$this->DefOrientation && !$newformat) || ($newformat && $p['ORIENTATION']=='P')) { // mPDF 4.2.024
  13107. $pgw = $this->fw;
  13108. $pgh = $this->fh;
  13109. }
  13110. else {
  13111. $pgw = $this->fh;
  13112. $pgh = $this->fw;
  13113. }
  13114. }
  13115. if (isset($p['HEADER']) && $p['HEADER']) { $header = $p['HEADER']; }
  13116. if (isset($p['FOOTER']) && $p['FOOTER']) { $footer = $p['FOOTER']; }
  13117. if (isset($p['RESETPAGENUM']) && $p['RESETPAGENUM']) { $resetpagenum = $p['RESETPAGENUM']; }
  13118. if (isset($p['PAGENUMSTYLE']) && $p['PAGENUMSTYLE']) { $pagenumstyle = $p['PAGENUMSTYLE']; }
  13119. if (isset($p['SUPPRESS']) && $p['SUPPRESS']) { $suppress = $p['SUPPRESS']; }
  13120. if (strtoupper($p['MARKS']) == 'CROP') { $marks = 'CROP'; }
  13121. else if (strtoupper($p['MARKS']) == 'CROSS') { $marks = 'CROSS'; }
  13122. // mPDF 3.0
  13123. if (isset($p['BACKGROUND-COLOR']) && $p['BACKGROUND-COLOR']) { $bg['BACKGROUND-COLOR'] = $p['BACKGROUND-COLOR']; }
  13124. if (isset($p['BACKGROUND-GRADIENT']) && $p['BACKGROUND-GRADIENT']) { $bg['BACKGROUND-GRADIENT'] = $p['BACKGROUND-GRADIENT']; } // *GRADIENTS*
  13125. if (isset($p['BACKGROUND-IMAGE']) && $p['BACKGROUND-IMAGE']) { $bg['BACKGROUND-IMAGE'] = $p['BACKGROUND-IMAGE']; } // *BACKGROUND-IMAGES*
  13126. if (isset($p['BACKGROUND-REPEAT']) && $p['BACKGROUND-REPEAT']) { $bg['BACKGROUND-REPEAT'] = $p['BACKGROUND-REPEAT']; } // *BACKGROUND-IMAGES*
  13127. if (isset($p['BACKGROUND-POSITION']) && $p['BACKGROUND-POSITION']) { $bg['BACKGROUND-POSITION'] = $p['BACKGROUND-POSITION']; } // *BACKGROUND-IMAGES*
  13128. if (isset($p['MARGIN-LEFT'])) { $mgl = $this->ConvertSize($p['MARGIN-LEFT'],$pgw) + $outer_width_LR; }
  13129. if (isset($p['MARGIN-RIGHT'])) { $mgr = $this->ConvertSize($p['MARGIN-RIGHT'],$pgw) + $outer_width_LR; }
  13130. if (isset($p['MARGIN-BOTTOM'])) { $mgb = $this->ConvertSize($p['MARGIN-BOTTOM'],$pgh) + $outer_width_TB; }
  13131. if (isset($p['MARGIN-TOP'])) { $mgt = $this->ConvertSize($p['MARGIN-TOP'],$pgh) + $outer_width_TB; }
  13132. if (isset($p['MARGIN-HEADER'])) { $mgh = $this->ConvertSize($p['MARGIN-HEADER'],$pgh) + $outer_width_TB; }
  13133. if (isset($p['MARGIN-FOOTER'])) { $mgf = $this->ConvertSize($p['MARGIN-FOOTER'],$pgh) + $outer_width_TB; }
  13134. if (isset($p['ORIENTATION']) && $p['ORIENTATION']) { $orientation = $p['ORIENTATION']; }
  13135. $this->page_box['outer_width_LR'] = $outer_width_LR; // Used in MARKS:crop etc.
  13136. $this->page_box['outer_width_TB'] = $outer_width_TB;
  13137. // mPDF 4.2
  13138. // mPDF 4.2.024
  13139. return array($orientation,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$header,$footer,$bg,$resetpagenum,$pagenumstyle,$suppress,$marks,$newformat);
  13140. }
  13141. /*-- END CSS-PAGE --*/
  13142. function PreviewBlockCSS($tag,$attr) {
  13143. // Looks ahead from current block level to a new level
  13144. $p = array();
  13145. $zp = array();
  13146. $oldcascadeCSS = $this->blk[$this->blklvl]['cascadeCSS'];
  13147. $classes = array();
  13148. if (isset($attr['CLASS'])) { $classes = preg_split('/\s+/',$attr['CLASS']); }
  13149. //===============================================
  13150. // DEFAULT for this TAG set in DefaultCSS
  13151. if (isset($this->defaultCSS[$tag])) {
  13152. $zp = $this->fixCSS($this->defaultCSS[$tag]);
  13153. if (is_array($zp)) { $p = array_merge($zp,$p); } // Inherited overwrites default
  13154. }
  13155. // STYLESHEET TAG e.g. h1 p div table
  13156. if (isset($this->CSS[$tag])) {
  13157. $zp = $this->CSS[$tag];
  13158. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13159. }
  13160. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  13161. foreach($classes AS $class) {
  13162. $zp = array();
  13163. if (isset($this->CSS['CLASS>>'.$class])) { $zp = $this->CSS['CLASS>>'.$class]; }
  13164. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13165. }
  13166. // STYLESHEET ID e.g. #smallone{} #redletter{}
  13167. if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']])) {
  13168. $zp = $this->CSS['ID>>'.$attr['ID']];
  13169. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13170. }
  13171. // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
  13172. foreach($classes AS $class) {
  13173. $zp = array();
  13174. if (isset($this->CSS[$tag.'>>CLASS>>'.$class])) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; }
  13175. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13176. }
  13177. // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
  13178. if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']])) {
  13179. $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']];
  13180. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13181. }
  13182. //===============================================
  13183. // STYLESHEET TAG e.g. div h1 div p
  13184. // mPDF 4.0
  13185. $this->_set_mergedCSS($oldcascadeCSS[$tag], $p);
  13186. // STYLESHEET CLASS e.g. .smallone{} .redletter{}
  13187. foreach($classes AS $class) {
  13188. // mPDF 4.0
  13189. $this->_set_mergedCSS($oldcascadeCSS['CLASS>>'.$class], $p);
  13190. }
  13191. // STYLESHEET CLASS e.g. #smallone{} #redletter{}
  13192. if (isset($attr['ID'])) {
  13193. // mPDF 4.0
  13194. $this->_set_mergedCSS($oldcascadeCSS['ID>>'.$attr['ID']], $p);
  13195. }
  13196. // STYLESHEET CLASS e.g. div.smallone{} p.redletter{}
  13197. foreach($classes AS $class) {
  13198. // mPDF 4.0
  13199. $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>CLASS>>'.$class], $p);
  13200. }
  13201. // STYLESHEET CLASS e.g. div#smallone{} p#redletter{}
  13202. if (isset($attr['ID'])) {
  13203. // mPDF 4.0
  13204. $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>ID>>'.$attr['ID']], $p);
  13205. }
  13206. //===============================================
  13207. // INLINE STYLE e.g. style="CSS:property"
  13208. if (isset($attr['STYLE'])) {
  13209. $zp = $this->readInlineCSS($attr['STYLE']);
  13210. if (is_array($zp)) { $p = array_merge($p,$zp); }
  13211. }
  13212. //===============================================
  13213. return $p;
  13214. }
  13215. /*-- CSS-FLOAT --*/
  13216. // Added mPDF 3.0 Float DIV - CLEAR
  13217. function ClearFloats($clear, $blklvl=0) {
  13218. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($blklvl,true);
  13219. $end = $currpos = ($this->page*1000 + $this->y);
  13220. if ($clear == 'BOTH' && ($l_exists || $r_exists)) {
  13221. // mPDF 4.0 $this->Reset();
  13222. $this->pageoutput[$this->page] = array();
  13223. $end = max($l_max, $r_max, $currpos);
  13224. }
  13225. else if ($clear == 'RIGHT' && $r_exists) {
  13226. // mPDF 4.0 $this->Reset();
  13227. $this->pageoutput[$this->page] = array();
  13228. $end = max($r_max, $currpos);
  13229. }
  13230. else if ($clear == 'LEFT' && $l_exists ) {
  13231. // mPDF 4.0 $this->Reset();
  13232. $this->pageoutput[$this->page] = array();
  13233. $end = max($l_max, $currpos);
  13234. }
  13235. else { return; }
  13236. $old_page = $this->page;
  13237. $new_page = intval($end/1000);
  13238. if ($old_page != $new_page) {
  13239. $s = $this->PrintPageBackgrounds();
  13240. // Writes after the marker so not overwritten later by page background etc.
  13241. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  13242. $this->pageBackgrounds = array();
  13243. $this->page = $new_page;
  13244. }
  13245. $this->ResetMargins();
  13246. // mPDF 4.0 $this->Reset();
  13247. $this->pageoutput[$this->page] = array();
  13248. $this->y = (($end*1000) % 1000000)/1000; // mod changes operands to integers before processing
  13249. }
  13250. // Added mPDF 3.0 Float DIV
  13251. function GetFloatDivInfo($blklvl=0,$clear=false) {
  13252. // If blklvl specified, only returns floats at that level - for ClearFloats
  13253. $l_exists = false;
  13254. $r_exists = false;
  13255. $l_max = 0;
  13256. $r_max = 0;
  13257. $l_width = 0;
  13258. $r_width = 0;
  13259. if (count($this->floatDivs)) {
  13260. $currpos = ($this->page*1000 + $this->y);
  13261. foreach($this->floatDivs AS $f) {
  13262. 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'])) {
  13263. if ($f['side']=='L') {
  13264. $l_exists= true;
  13265. $l_max = max($l_max, $f['endpos']);
  13266. $l_width = max($l_width , $f['w']);
  13267. }
  13268. if ($f['side']=='R') {
  13269. $r_exists= true;
  13270. $r_max = max($r_max, $f['endpos']);
  13271. $r_width = max($r_width , $f['w']);
  13272. }
  13273. }
  13274. }
  13275. }
  13276. return array($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width);
  13277. }
  13278. /*-- END CSS-FLOAT --*/
  13279. function OpenTag($tag,$attr)
  13280. {
  13281. // What this gets: < $tag $attr['WIDTH']="90px" > does not get content here </closeTag here>
  13282. // Correct tags where HTML specifies optional end tags,
  13283. // and/or does not allow nesting e.g. P inside P, or
  13284. if ($this->allow_html_optional_endtags) {
  13285. 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 ); }
  13286. if ($tag == 'DD' && $this->lastoptionaltag == 'DD') { $this->CloseTag($this->lastoptionaltag ); }
  13287. if ($tag == 'DD' && $this->lastoptionaltag == 'DT') { $this->CloseTag($this->lastoptionaltag ); }
  13288. if ($tag == 'DT' && $this->lastoptionaltag == 'DD') { $this->CloseTag($this->lastoptionaltag ); }
  13289. if ($tag == 'DT' && $this->lastoptionaltag == 'DT') { $this->CloseTag($this->lastoptionaltag ); }
  13290. if ($tag == 'LI' && $this->lastoptionaltag == 'LI') { $this->CloseTag($this->lastoptionaltag ); }
  13291. if (($tag == 'TD' || $tag == 'TH') && $this->lastoptionaltag == 'TD') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES*
  13292. if (($tag == 'TD' || $tag == 'TH') && $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES*
  13293. if ($tag == 'TR' && $this->lastoptionaltag == 'TR') { $this->CloseTag($this->lastoptionaltag ); } // *TABLES*
  13294. if ($tag == 'TR' && $this->lastoptionaltag == 'TD') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); $this->CloseTag('THEAD'); } // *TABLES*
  13295. if ($tag == 'TR' && $this->lastoptionaltag == 'TH') { $this->CloseTag($this->lastoptionaltag ); $this->CloseTag('TR'); $this->CloseTag('THEAD'); } // *TABLES*
  13296. if ($tag == 'OPTION' && $this->lastoptionaltag == 'OPTION') { $this->CloseTag($this->lastoptionaltag ); }
  13297. }
  13298. // mPDF 4.2 Baseline = S
  13299. $align = array('left'=>'L','center'=>'C','right'=>'R','top'=>'T','text-top'=>'TT','middle'=>'M','baseline'=>'BS','bottom'=>'B','text-bottom'=>'TB','justify'=>'J');
  13300. $this->ignorefollowingspaces=false;
  13301. //Opening tag
  13302. switch($tag){
  13303. // mPDF 4.2.031
  13304. case 'DOTTAB':
  13305. $objattr = array();
  13306. $objattr['type'] = 'dottab';
  13307. $dots=str_repeat('.', 3)." "; // minimum number of dots
  13308. $objattr['width'] = $this->GetStringWidth($dots);
  13309. $objattr['margin_top'] = 0;
  13310. $objattr['margin_bottom'] = 0;
  13311. $objattr['margin_left'] = 0;
  13312. $objattr['margin_right'] = 0;
  13313. $objattr['height'] = 0;
  13314. $objattr['border_top']['w'] = 0;
  13315. $objattr['border_bottom']['w'] = 0;
  13316. $objattr['border_left']['w'] = 0;
  13317. $objattr['border_right']['w'] = 0;
  13318. $e = "\xbb\xa4\xactype=dottab,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13319. /*-- TABLES --*/
  13320. // Output it to buffers
  13321. if ($this->tableLevel) {
  13322. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  13323. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  13324. }
  13325. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  13326. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  13327. }
  13328. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  13329. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  13330. }
  13331. else {
  13332. /*-- END TABLES --*/
  13333. $this->textbuffer[] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  13334. } // *TABLES*
  13335. break;
  13336. case 'PAGEHEADER':
  13337. case 'PAGEFOOTER':
  13338. $this->ignorefollowingspaces = true;
  13339. if ($attr['NAME']) { $pname = $attr['NAME']; }
  13340. else { $pname = '_default'; }
  13341. if ($tag=='PAGEHEADER') { $p = &$this->pageheaders[$pname]; }
  13342. else { $p = &$this->pagefooters[$pname]; }
  13343. $p['L']=array();
  13344. $p['C']=array();
  13345. $p['R']=array();
  13346. $p['L']['font-style'] = '';
  13347. $p['C']['font-style'] = '';
  13348. $p['R']['font-style'] = '';
  13349. if (isset($attr['CONTENT-LEFT'])) {
  13350. $p['L']['content'] = $attr['CONTENT-LEFT'];
  13351. }
  13352. if (isset($attr['CONTENT-CENTER'])) {
  13353. $p['C']['content'] = $attr['CONTENT-CENTER'];
  13354. }
  13355. if (isset($attr['CONTENT-RIGHT'])) {
  13356. $p['R']['content'] = $attr['CONTENT-RIGHT'];
  13357. }
  13358. if (isset($attr['HEADER-STYLE']) || isset($attr['FOOTER-STYLE'])) { // font-family,size,weight,style,color
  13359. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE']); }
  13360. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE']); }
  13361. if (isset($properties['FONT-FAMILY'])) {
  13362. $p['L']['font-family'] = $properties['FONT-FAMILY'];
  13363. $p['C']['font-family'] = $properties['FONT-FAMILY'];
  13364. $p['R']['font-family'] = $properties['FONT-FAMILY'];
  13365. }
  13366. if (isset($properties['FONT-SIZE'])) {
  13367. $p['L']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * $this->k;
  13368. $p['C']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * $this->k;
  13369. $p['R']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * $this->k;
  13370. }
  13371. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='BOLD') {
  13372. $p['L']['font-style'] = 'B';
  13373. $p['C']['font-style'] = 'B';
  13374. $p['R']['font-style'] = 'B';
  13375. }
  13376. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='ITALIC') {
  13377. $p['L']['font-style'] .= 'I';
  13378. $p['C']['font-style'] .= 'I';
  13379. $p['R']['font-style'] .= 'I';
  13380. }
  13381. if (isset($properties['COLOR'])) {
  13382. $p['L']['color'] = $properties['COLOR'];
  13383. $p['C']['color'] = $properties['COLOR'];
  13384. $p['R']['color'] = $properties['COLOR'];
  13385. }
  13386. }
  13387. if (isset($attr['HEADER-STYLE-LEFT']) || isset($attr['FOOTER-STYLE-LEFT'])) {
  13388. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE-LEFT']); }
  13389. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE-LEFT']); }
  13390. if (isset($properties['FONT-FAMILY'])) { $p['L']['font-family'] = $properties['FONT-FAMILY']; }
  13391. if (isset($properties['FONT-SIZE'])) { $p['L']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * $this->k; }
  13392. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='BOLD') { $p['L']['font-style'] ='B'; }
  13393. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='ITALIC') { $p['L']['font-style'] .='I'; }
  13394. if (isset($properties['COLOR'])) { $p['L']['color'] = $properties['COLOR']; }
  13395. }
  13396. if (isset($attr['HEADER-STYLE-CENTER']) || isset($attr['FOOTER-STYLE-CENTER'])) {
  13397. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE-CENTER']); }
  13398. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE-CENTER']); }
  13399. if (isset($properties['FONT-FAMILY'])) { $p['C']['font-family'] = $properties['FONT-FAMILY']; }
  13400. if (isset($properties['FONT-SIZE'])) { $p['C']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * $this->k; }
  13401. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='BOLD') { $p['C']['font-style'] = 'B'; }
  13402. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='ITALIC') { $p['C']['font-style'] .= 'I'; }
  13403. if (isset($properties['COLOR'])) { $p['C']['color'] = $properties['COLOR']; }
  13404. }
  13405. if (isset($attr['HEADER-STYLE-RIGHT']) || isset($attr['FOOTER-STYLE-RIGHT'])) {
  13406. if ($tag=='PAGEHEADER') { $properties = $this->readInlineCSS($attr['HEADER-STYLE-RIGHT']); }
  13407. else { $properties = $this->readInlineCSS($attr['FOOTER-STYLE-RIGHT']); }
  13408. if (isset($properties['FONT-FAMILY'])) { $p['R']['font-family'] = $properties['FONT-FAMILY']; }
  13409. if (isset($properties['FONT-SIZE'])) { $p['R']['font-size'] = $this->ConvertSize($properties['FONT-SIZE']) * $this->k; }
  13410. if (isset($properties['FONT-WEIGHT']) && $properties['FONT-WEIGHT']=='BOLD') { $p['R']['font-style'] = 'B'; }
  13411. if (isset($properties['FONT-STYLE']) && $properties['FONT-STYLE']=='ITALIC') { $p['R']['font-style'] .= 'I'; }
  13412. if (isset($properties['COLOR'])) { $p['R']['color'] = $properties['COLOR']; }
  13413. }
  13414. if (isset($attr['LINE']) && $attr['LINE']) { // 0|1|on|off
  13415. if ($attr['LINE']=='1' || strtoupper($attr['LINE'])=='ON') { $lineset=1; }
  13416. else { $lineset=0; }
  13417. $p['line'] = $lineset;
  13418. }
  13419. break;
  13420. /*-- HTMLHEADERS-FOOTERS --*/
  13421. case 'SETHTMLPAGEHEADER':
  13422. case 'SETHTMLPAGEFOOTER':
  13423. $this->ignorefollowingspaces = true;
  13424. if (isset($attr['NAME']) && $attr['NAME']) { $pname = $attr['NAME']; }
  13425. else { $pname = '_default'; }
  13426. if (isset($attr['PAGE']) && $attr['PAGE']) { // O|odd|even|E|ALL|[blank]
  13427. if (strtoupper($attr['PAGE'])=='O' || strtoupper($attr['PAGE'])=='ODD') { $side='odd'; }
  13428. else if (strtoupper($attr['PAGE'])=='E' || strtoupper($attr['PAGE'])=='EVEN') { $side='even'; }
  13429. else if (strtoupper($attr['PAGE'])=='ALL') { $side='both'; }
  13430. else { $side='odd'; }
  13431. }
  13432. else { $side='odd'; }
  13433. if (isset($attr['VALUE']) && $attr['VALUE']) { // -1|1|on|off
  13434. if ($attr['VALUE']=='1' || strtoupper($attr['VALUE'])=='ON') { $set=1; }
  13435. else if ($attr['VALUE']=='-1' || strtoupper($attr['VALUE'])=='OFF') { $set=0; }
  13436. else { $set=1; }
  13437. }
  13438. else { $set=1; }
  13439. if (isset($attr['SHOW-THIS-PAGE']) && $attr['SHOW-THIS-PAGE'] && $tag=='SETHTMLPAGEHEADER') { $write = 1; }
  13440. else { $write = 0; }
  13441. if ($side=='odd' || $side=='both') {
  13442. if ($set && $tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader($this->pageHTMLheaders[$pname],'O',$write); }
  13443. else if ($set && $tag=='SETHTMLPAGEFOOTER') { $this->SetHTMLFooter($this->pageHTMLfooters[$pname],'O'); }
  13444. else if ($tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader('','O'); }
  13445. else { $this->SetHTMLFooter('','O'); }
  13446. }
  13447. if ($side=='even' || $side=='both') {
  13448. if ($set && $tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader($this->pageHTMLheaders[$pname],'E',$write); }
  13449. else if ($set && $tag=='SETHTMLPAGEFOOTER') { $this->SetHTMLFooter($this->pageHTMLfooters[$pname],'E'); }
  13450. else if ($tag=='SETHTMLPAGEHEADER') { $this->SetHTMLHeader('','E'); }
  13451. else { $this->SetHTMLFooter('','E'); }
  13452. }
  13453. break;
  13454. /*-- END HTMLHEADERS-FOOTERS --*/
  13455. case 'SETPAGEHEADER':
  13456. case 'SETPAGEFOOTER':
  13457. $this->ignorefollowingspaces = true;
  13458. if (isset($attr['NAME']) && $attr['NAME']) { $pname = $attr['NAME']; }
  13459. else { $pname = '_default'; }
  13460. if (isset($attr['PAGE']) && $attr['PAGE']) { // O|odd|even|E|ALL|[blank]
  13461. if (strtoupper($attr['PAGE'])=='O' || strtoupper($attr['PAGE'])=='ODD') { $side='odd'; }
  13462. else if (strtoupper($attr['PAGE'])=='E' || strtoupper($attr['PAGE'])=='EVEN') { $side='even'; }
  13463. else if (strtoupper($attr['PAGE'])=='ALL') { $side='both'; }
  13464. else { $side='odd'; }
  13465. }
  13466. else { $side='odd'; }
  13467. if (isset($attr['VALUE']) && $attr['VALUE']) { // -1|1|on|off
  13468. if ($attr['VALUE']=='1' || strtoupper($attr['VALUE'])=='ON') { $set=1; }
  13469. else if ($attr['VALUE']=='-1' || strtoupper($attr['VALUE'])=='OFF') { $set=0; }
  13470. else { $set=1; }
  13471. }
  13472. else { $set=1; }
  13473. if ($side=='odd' || $side=='both') {
  13474. if ($set && $tag=='SETPAGEHEADER') { $this->headerDetails['odd'] = $this->pageheaders[$pname]; }
  13475. else if ($set && $tag=='SETPAGEFOOTER') { $this->footerDetails['odd'] = $this->pagefooters[$pname]; }
  13476. else if ($tag=='SETPAGEHEADER') { $this->headerDetails['odd'] = array(); }
  13477. else { $this->footerDetails['odd'] = array(); }
  13478. // mPDF 4.0
  13479. if (!$this->mirrorMargins || ($this->page)%2!=0) { // ODD
  13480. if ($tag=='SETPAGEHEADER') { $this->_setAutoHeaderHeight($this->headerDetails['odd'],$this->HTMLHeader); }
  13481. if ($tag=='SETPAGEFOOTER') { $this->_setAutoFooterHeight($this->footerDetails['odd'],$this->HTMLFooter); }
  13482. }
  13483. }
  13484. if ($side=='even' || $side=='both') {
  13485. if ($set && $tag=='SETPAGEHEADER') { $this->headerDetails['even'] = $this->pageheaders[$pname]; }
  13486. else if ($set && $tag=='SETPAGEFOOTER') { $this->footerDetails['even'] = $this->pagefooters[$pname]; }
  13487. else if ($tag=='SETPAGEHEADER') { $this->headerDetails['even'] = array(); }
  13488. else { $this->footerDetails['even'] = array(); }
  13489. // mPDF 4.0
  13490. if ($this->mirrorMargins && ($this->page)%2==0) { // EVEN
  13491. if ($tag=='SETPAGEHEADER') { $this->_setAutoHeaderHeight($this->headerDetails['even'],$this->HTMLHeaderE); }
  13492. if ($tag=='SETPAGEFOOTER') { $this->_setAutoFooterHeight($this->footerDetails['even'],$this->HTMLFooterE); }
  13493. }
  13494. }
  13495. if (isset($attr['SHOW-THIS-PAGE']) && $attr['SHOW-THIS-PAGE'] && $tag=='SETPAGEHEADER') {
  13496. $this->Header();
  13497. }
  13498. break;
  13499. /*-- TOC --*/
  13500. case 'TOC': //added custom-tag - set Marker for insertion later of ToC
  13501. if (isset($attr['FONT-SIZE']) && $attr['FONT-SIZE']) { $tocfontsize = $attr['FONT-SIZE']; } else { $tocfontsize = ''; }
  13502. if (isset($attr['FONT']) && $attr['FONT']) { $tocfont = $attr['FONT']; } else { $tocfont = ''; }
  13503. if (isset($attr['INDENT']) && $attr['INDENT']) { $tocindent = $attr['INDENT']; } else { $tocindent = ''; }
  13504. if (isset($attr['RESETPAGENUM']) && $attr['RESETPAGENUM']) { $resetpagenum = $attr['RESETPAGENUM']; } else { $resetpagenum = ''; }
  13505. if (isset($attr['PAGENUMSTYLE']) && $attr['PAGENUMSTYLE']) { $pagenumstyle = $attr['PAGENUMSTYLE']; } else { $pagenumstyle= ''; }
  13506. if (isset($attr['SUPPRESS']) && $attr['SUPPRESS']) { $suppress = $attr['SUPPRESS']; } else { $suppress = ''; }
  13507. if (isset($attr['TOC-ORIENTATION']) && $attr['TOC-ORIENTATION']) { $toc_orientation = $attr['TOC-ORIENTATION']; } else { $toc_orientation = ''; }
  13508. if (isset($attr['PAGING']) && (strtoupper($attr['PAGING'])=='OFF' || $attr['PAGING']==='0')) { $paging = false; }
  13509. else { $paging = true; }
  13510. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS'])=='ON' || $attr['LINKS']==1)) { $links = true; }
  13511. else { $links = false; }
  13512. if (isset($attr['NAME']) && $attr['NAME']) { $toc_id = strtolower($attr['NAME']); } else { $toc_id = 0; }
  13513. $this->TOC($tocfont,$tocfontsize,$tocindent,$resetpagenum, $pagenumstyle, $suppress, $toc_orientation, $paging, $links, $toc_id);
  13514. break;
  13515. case 'TOCPAGEBREAK': // custom-tag - set Marker for insertion later of ToC AND adds PAGEBREAK
  13516. if (isset($attr['NAME']) && $attr['NAME']) { $toc_id = strtolower($attr['NAME']); } else { $toc_id = 0; }
  13517. if ($toc_id) {
  13518. if (isset($attr['FONT-SIZE'])) { $this->m_TOC[$toc_id]['TOCfontsize'] = $attr['FONT-SIZE']; } else { $this->m_TOC[$toc_id]['TOCfontsize'] = $this->default_font_size; }
  13519. if (isset($attr['FONT'])) { $this->m_TOC[$toc_id]['TOCfont'] = $attr['FONT']; } else { $this->m_TOC[$toc_id]['TOCfont'] = $this->default_font; }
  13520. if (isset($attr['INDENT']) && $attr['INDENT']) { $this->m_TOC[$toc_id]['TOCindent'] = $attr['INDENT']; } else { $this->m_TOC[$toc_id]['TOCindent'] = ''; }
  13521. if (isset($attr['TOC-ORIENTATION']) && $attr['TOC-ORIENTATION']) { $this->m_TOC[$toc_id]['TOCorientation'] = $attr['TOC-ORIENTATION']; } else { $this->m_TOC[$toc_id]['TOCorientation'] = ''; }
  13522. if (isset($attr['PAGING']) && (strtoupper($attr['PAGING'])=='OFF' || $attr['PAGING']==='0')) { $this->m_TOC[$toc_id]['TOCusePaging'] = false; }
  13523. else { $this->m_TOC[$toc_id]['TOCusePaging'] = true; }
  13524. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS'])=='ON' || $attr['LINKS']==1)) { $this->m_TOC[$toc_id]['TOCuseLinking'] = true; }
  13525. else { $this->m_TOC[$toc_id]['TOCuseLinking'] = false; }
  13526. $this->m_TOC[$toc_id]['TOC_margin_left'] = $this->m_TOC[$toc_id]['TOC_margin_right'] = $this->m_TOC[$toc_id]['TOC_margin_top'] = $this->m_TOC[$toc_id]['TOC_margin_bottom'] = $this->m_TOC[$toc_id]['TOC_margin_header'] = $this->m_TOC[$toc_id]['TOC_margin_footer'] = '';
  13527. if (isset($attr['TOC-MARGIN-RIGHT'])) { $this->m_TOC[$toc_id]['TOC_margin_right'] = $this->ConvertSize($attr['TOC-MARGIN-RIGHT'],$this->w,$this->FontSize,false); }
  13528. if (isset($attr['TOC-MARGIN-LEFT'])) { $this->m_TOC[$toc_id]['TOC_margin_left'] = $this->ConvertSize($attr['TOC-MARGIN-LEFT'],$this->w,$this->FontSize,false); }
  13529. if (isset($attr['TOC-MARGIN-TOP'])) { $this->m_TOC[$toc_id]['TOC_margin_top'] = $this->ConvertSize($attr['TOC-MARGIN-TOP'],$this->w,$this->FontSize,false); }
  13530. if (isset($attr['TOC-MARGIN-BOTTOM'])) { $this->m_TOC[$toc_id]['TOC_margin_bottom'] = $this->ConvertSize($attr['TOC-MARGIN-BOTTOM'],$this->w,$this->FontSize,false); }
  13531. if (isset($attr['TOC-MARGIN-HEADER'])) { $this->m_TOC[$toc_id]['TOC_margin_header'] = $this->ConvertSize($attr['TOC-MARGIN-HEADER'],$this->w,$this->FontSize,false); }
  13532. if (isset($attr['TOC-MARGIN-FOOTER'])) { $this->m_TOC[$toc_id]['TOC_margin_footer'] = $this->ConvertSize($attr['TOC-MARGIN-FOOTER'],$this->w,$this->FontSize,false); }
  13533. $this->m_TOC[$toc_id]['TOC_odd_header_name'] = $this->m_TOC[$toc_id]['TOC_even_header_name'] = $this->m_TOC[$toc_id]['TOC_odd_footer_name'] = $this->m_TOC[$toc_id]['TOC_even_footer_name'] = '';
  13534. if (isset($attr['TOC-ODD-HEADER-NAME']) && $attr['TOC-ODD-HEADER-NAME']) { $this->m_TOC[$toc_id]['TOC_odd_header_name'] = $attr['TOC-ODD-HEADER-NAME']; }
  13535. if (isset($attr['TOC-EVEN-HEADER-NAME']) && $attr['TOC-EVEN-HEADER-NAME']) { $this->m_TOC[$toc_id]['TOC_even_header_name'] = $attr['TOC-EVEN-HEADER-NAME']; }
  13536. if (isset($attr['TOC-ODD-FOOTER-NAME']) && $attr['TOC-ODD-FOOTER-NAME']) { $this->m_TOC[$toc_id]['TOC_odd_footer_name'] = $attr['TOC-ODD-FOOTER-NAME']; }
  13537. if (isset($attr['TOC-EVEN-FOOTER-NAME']) && $attr['TOC-EVEN-FOOTER-NAME']) { $this->m_TOC[$toc_id]['TOC_even_footer_name'] = $attr['TOC-EVEN-FOOTER-NAME']; }
  13538. $this->m_TOC[$toc_id]['TOC_odd_header_value'] = $this->m_TOC[$toc_id]['TOC_even_header_value'] = $this->m_TOC[$toc_id]['TOC_odd_footer_value'] = $this->m_TOC[$toc_id]['TOC_even_footer_value'] = 0;
  13539. if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE']=='1' || strtoupper($attr['TOC-ODD-HEADER-VALUE'])=='ON')) { $this->m_TOC[$toc_id]['TOC_odd_header_value'] = 1; }
  13540. else if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE']=='-1' || strtoupper($attr['TOC-ODD-HEADER-VALUE'])=='OFF')) { $this->m_TOC[$toc_id]['TOC_odd_header_value'] = -1; }
  13541. if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE']=='1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE'])=='ON')) { $this->m_TOC[$toc_id]['TOC_even_header_value'] = 1; }
  13542. else if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE']=='-1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE'])=='OFF')) { $this->m_TOC[$toc_id]['TOC_even_header_value'] = -1; }
  13543. if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE']=='1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE'])=='ON')) { $this->m_TOC[$toc_id]['TOC_odd_footer_value'] = 1; }
  13544. else if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE']=='-1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE'])=='OFF')) { $this->m_TOC[$toc_id]['TOC_odd_footer_value'] = -1; }
  13545. if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE']=='1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE'])=='ON')) { $this->m_TOC[$toc_id]['TOC_even_footer_value'] = 1; }
  13546. else if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE']=='-1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE'])=='OFF')) { $this->m_TOC[$toc_id]['TOC_even_footer_value'] = -1; }
  13547. // mPDF 4.2
  13548. if (isset($attr['TOC-PAGE-SELECTOR']) && $attr['TOC-PAGE-SELECTOR']) { $this->m_TOC[$toc_id]['TOC_page_selector'] = $attr['TOC-PAGE-SELECTOR']; }
  13549. else { $this->m_TOC[$toc_id]['TOC_page_selector'] = ''; }
  13550. // mPDF 4.2.04
  13551. if (isset($attr['TOC-SHEET-SIZE']) && $attr['TOC-SHEET-SIZE']) { $this->m_TOC[$toc_id]['TOCsheetsize'] = $attr['TOC-SHEET-SIZE']; } else { $this->m_TOC[$toc_id]['TOCsheetsize'] = ''; }
  13552. if (isset($attr['TOC-PREHTML']) && $attr['TOC-PREHTML']) { $this->m_TOC[$toc_id]['TOCpreHTML'] = htmlspecialchars_decode($attr['TOC-PREHTML'],ENT_QUOTES); }
  13553. if (isset($attr['TOC-POSTHTML']) && $attr['TOC-POSTHTML']) { $this->m_TOC[$toc_id]['TOCpostHTML'] = htmlspecialchars_decode($attr['TOC-POSTHTML'],ENT_QUOTES); }
  13554. // mPDF 3.0
  13555. if (isset($attr['TOC-BOOKMARKTEXT']) && $attr['TOC-BOOKMARKTEXT']) { $this->m_TOC[$toc_id]['TOCbookmarkText'] = htmlspecialchars_decode($attr['TOC-BOOKMARKTEXT'],ENT_QUOTES); } // *BOOKMARKS*
  13556. }
  13557. else {
  13558. if (isset($attr['FONT-SIZE'])) { $this->TOCfontsize = $attr['FONT-SIZE']; } else { $this->TOCfontsize = $this->default_font_size; }
  13559. if (isset($attr['FONT'])) { $this->TOCfont = $attr['FONT']; } else { $this->TOCfont = $this->default_font; }
  13560. if (isset($attr['INDENT']) && $attr['INDENT']) { $this->TOCindent = $attr['INDENT']; } else { $this->TOCindent = ''; }
  13561. if (isset($attr['TOC-ORIENTATION']) && $attr['TOC-ORIENTATION']) { $this->TOCorientation = $attr['TOC-ORIENTATION']; } else { $this->TOCorientation = ''; }
  13562. if (isset($attr['PAGING']) && (strtoupper($attr['PAGING'])=='OFF' || $attr['PAGING']==='0')) { $this->TOCusePaging = false; }
  13563. else { $this->TOCusePaging = true; }
  13564. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS'])=='ON' || $attr['LINKS']==1)) { $this->TOCuseLinking = true; }
  13565. else { $this->TOCuseLinking = false; }
  13566. $this->TOC_margin_left = $this->TOC_margin_right = $this->TOC_margin_top = $this->TOC_margin_bottom = $this->TOC_margin_header = $this->TOC_margin_footer = '';
  13567. if (isset($attr['TOC-MARGIN-RIGHT'])) { $this->TOC_margin_right = $this->ConvertSize($attr['TOC-MARGIN-RIGHT'],$this->w,$this->FontSize,false); }
  13568. if (isset($attr['TOC-MARGIN-LEFT'])) { $this->TOC_margin_left = $this->ConvertSize($attr['TOC-MARGIN-LEFT'],$this->w,$this->FontSize,false); }
  13569. if (isset($attr['TOC-MARGIN-TOP'])) { $this->TOC_margin_top = $this->ConvertSize($attr['TOC-MARGIN-TOP'],$this->w,$this->FontSize,false); }
  13570. if (isset($attr['TOC-MARGIN-BOTTOM'])) { $this->TOC_margin_bottom = $this->ConvertSize($attr['TOC-MARGIN-BOTTOM'],$this->w,$this->FontSize,false); }
  13571. if (isset($attr['TOC-MARGIN-HEADER'])) { $this->TOC_margin_header = $this->ConvertSize($attr['TOC-MARGIN-HEADER'],$this->w,$this->FontSize,false); }
  13572. if (isset($attr['TOC-MARGIN-FOOTER'])) { $this->TOC_margin_footer = $this->ConvertSize($attr['TOC-MARGIN-FOOTER'],$this->w,$this->FontSize,false); }
  13573. $this->TOC_odd_header_name = $this->TOC_even_header_name = $this->TOC_odd_footer_name = $this->TOC_even_footer_name = '';
  13574. if (isset($attr['TOC-ODD-HEADER-NAME']) && $attr['TOC-ODD-HEADER-NAME']) { $this->TOC_odd_header_name = $attr['TOC-ODD-HEADER-NAME']; }
  13575. if (isset($attr['TOC-EVEN-HEADER-NAME']) && $attr['TOC-EVEN-HEADER-NAME']) { $this->TOC_even_header_name = $attr['TOC-EVEN-HEADER-NAME']; }
  13576. if (isset($attr['TOC-ODD-FOOTER-NAME']) && $attr['TOC-ODD-FOOTER-NAME']) { $this->TOC_odd_footer_name = $attr['TOC-ODD-FOOTER-NAME']; }
  13577. if (isset($attr['TOC-EVEN-FOOTER-NAME']) && $attr['TOC-EVEN-FOOTER-NAME']) { $this->TOC_even_footer_name = $attr['TOC-EVEN-FOOTER-NAME']; }
  13578. $this->TOC_odd_header_value = $this->TOC_even_header_value = $this->TOC_odd_footer_value = $this->TOC_even_footer_value = 0;
  13579. if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE']=='1' || strtoupper($attr['TOC-ODD-HEADER-VALUE'])=='ON')) { $this->TOC_odd_header_value = 1; }
  13580. else if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE']=='-1' || strtoupper($attr['TOC-ODD-HEADER-VALUE'])=='OFF')) { $this->TOC_odd_header_value = -1; }
  13581. if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE']=='1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE'])=='ON')) { $this->TOC_even_header_value = 1; }
  13582. else if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE']=='-1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE'])=='OFF')) { $this->TOC_even_header_value = -1; }
  13583. if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE']=='1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE'])=='ON')) { $this->TOC_odd_footer_value = 1; }
  13584. else if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE']=='-1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE'])=='OFF')) { $this->TOC_odd_footer_value = -1; }
  13585. if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE']=='1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE'])=='ON')) { $this->TOC_even_footer_value = 1; }
  13586. else if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE']=='-1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE'])=='OFF')) { $this->TOC_even_footer_value = -1; }
  13587. // mPDF 4.2
  13588. if (isset($attr['TOC-PAGE-SELECTOR']) && $attr['TOC-PAGE-SELECTOR']) { $this->TOC_page_selector = $attr['TOC-PAGE-SELECTOR']; }
  13589. else { $this->TOC_page_selector = ''; }
  13590. // mPDF 4.2.04
  13591. if (isset($attr['TOC-SHEET-SIZE']) && $attr['TOC-SHEET-SIZE']) { $this->TOCsheetsize = $attr['TOC-SHEET-SIZE']; } else { $this->TOCsheetsize = ''; }
  13592. if (isset($attr['TOC-PREHTML']) && $attr['TOC-PREHTML']) { $this->TOCpreHTML = htmlspecialchars_decode($attr['TOC-PREHTML'],ENT_QUOTES); }
  13593. if (isset($attr['TOC-POSTHTML']) && $attr['TOC-POSTHTML']) { $this->TOCpostHTML = htmlspecialchars_decode($attr['TOC-POSTHTML'],ENT_QUOTES); }
  13594. if (isset($attr['TOC-BOOKMARKTEXT']) && $attr['TOC-BOOKMARKTEXT']) { $this->TOCbookmarkText = htmlspecialchars_decode($attr['TOC-BOOKMARKTEXT'],ENT_QUOTES); } // *BOOKMARKS*
  13595. }
  13596. // mPDF 3.0
  13597. if ($this->y == $this->tMargin && (!$this->mirrorMargins ||($this->mirrorMargins && $this->page % 2==1))) {
  13598. if ($toc_id) { $this->m_TOC[$toc_id]['TOCmark'] = $this->page; }
  13599. else { $this->TOCmark = $this->page; }
  13600. // Don't add a page
  13601. if ($this->page==1 && count($this->PageNumSubstitutions)==0) {
  13602. $resetpagenum = '';
  13603. $pagenumstyle = '';
  13604. $suppress = '';
  13605. if (isset($attr['RESETPAGENUM'])) { $resetpagenum = $attr['RESETPAGENUM']; }
  13606. if (isset($attr['PAGENUMSTYLE'])) { $pagenumstyle = $attr['PAGENUMSTYLE']; }
  13607. if (isset($attr['SUPPRESS'])) { $suppress = $attr['SUPPRESS']; }
  13608. if (!$suppress) { $suppress = 'off'; }
  13609. if (!$resetpagenum) { $resetpagenum= 1; }
  13610. $this->PageNumSubstitutions[] = array('from'=>1, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=> $suppress);
  13611. }
  13612. break;
  13613. }
  13614. // No break - continues as PAGEBREAK...
  13615. /*-- END TOC --*/
  13616. case 'PAGE_BREAK': //custom-tag
  13617. case 'PAGEBREAK': //custom-tag
  13618. case 'NEWPAGE': //custom-tag
  13619. case 'FORMFEED': //custom-tag
  13620. $save_blklvl = $this->blklvl;
  13621. $save_blk = $this->blk;
  13622. $save_silp = $this->saveInlineProperties();
  13623. $save_spanlvl = $this->spanlvl;
  13624. $save_ilp = $this->InlineProperties;
  13625. // Close any open block tags
  13626. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  13627. if(!empty($this->textbuffer)) { //Output previously buffered content
  13628. $this->printbuffer($this->textbuffer);
  13629. $this->textbuffer=array();
  13630. }
  13631. $this->ignorefollowingspaces = true;
  13632. $save_cols = false;
  13633. /*-- COLUMNS --*/
  13634. if ($this->ColActive) {
  13635. $save_cols = true;
  13636. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  13637. $this->SetColumns(0);
  13638. }
  13639. /*-- END COLUMNS --*/
  13640. // mPDF 4.2.024
  13641. if (isset($attr['SHEET-SIZE']) && $tag != 'FORMFEED' && !$this->restoreBlockPageBreaks) {
  13642. // Convert to same types as accepted in initial mPDF() A4, A4-L, or array(w,h)
  13643. $prop = preg_split('/\s+/',trim($attr['SHEET-SIZE']));
  13644. if (count($prop) == 2 ) {
  13645. $newformat = array($this->ConvertSize($prop[0]), $this->ConvertSize($prop[1]));
  13646. }
  13647. else { $newformat = $attr['SHEET-SIZE']; }
  13648. }
  13649. else { $newformat = ''; }
  13650. $mgr = $mgl = $mgt = $mgb = $mgh = $mgf = '';
  13651. if (isset($attr['MARGIN-RIGHT'])) { $mgr = $this->ConvertSize($attr['MARGIN-RIGHT'],$this->w,$this->FontSize,false); }
  13652. if (isset($attr['MARGIN-LEFT'])) { $mgl = $this->ConvertSize($attr['MARGIN-LEFT'],$this->w,$this->FontSize,false); }
  13653. if (isset($attr['MARGIN-TOP'])) { $mgt = $this->ConvertSize($attr['MARGIN-TOP'],$this->w,$this->FontSize,false); }
  13654. if (isset($attr['MARGIN-BOTTOM'])) { $mgb = $this->ConvertSize($attr['MARGIN-BOTTOM'],$this->w,$this->FontSize,false); }
  13655. if (isset($attr['MARGIN-HEADER'])) { $mgh = $this->ConvertSize($attr['MARGIN-HEADER'],$this->w,$this->FontSize,false); }
  13656. if (isset($attr['MARGIN-FOOTER'])) { $mgf = $this->ConvertSize($attr['MARGIN-FOOTER'],$this->w,$this->FontSize,false); }
  13657. $ohname = $ehname = $ofname = $efname = '';
  13658. if (isset($attr['ODD-HEADER-NAME'])) { $ohname = $attr['ODD-HEADER-NAME']; }
  13659. if (isset($attr['EVEN-HEADER-NAME'])) { $ehname = $attr['EVEN-HEADER-NAME']; }
  13660. if (isset($attr['ODD-FOOTER-NAME'])) { $ofname = $attr['ODD-FOOTER-NAME']; }
  13661. if (isset($attr['EVEN-FOOTER-NAME'])) { $efname = $attr['EVEN-FOOTER-NAME']; }
  13662. $ohvalue = $ehvalue = $ofvalue = $efvalue = 0;
  13663. if (isset($attr['ODD-HEADER-VALUE']) && ($attr['ODD-HEADER-VALUE']=='1' || strtoupper($attr['ODD-HEADER-VALUE'])=='ON')) { $ohvalue = 1; }
  13664. else if (isset($attr['ODD-HEADER-VALUE']) && ($attr['ODD-HEADER-VALUE']=='-1' || strtoupper($attr['ODD-HEADER-VALUE'])=='OFF')) { $ohvalue = -1; }
  13665. if (isset($attr['EVEN-HEADER-VALUE']) && ($attr['EVEN-HEADER-VALUE']=='1' || strtoupper($attr['EVEN-HEADER-VALUE'])=='ON')) { $ehvalue = 1; }
  13666. else if (isset($attr['EVEN-HEADER-VALUE']) && ($attr['EVEN-HEADER-VALUE']=='-1' || strtoupper($attr['EVEN-HEADER-VALUE'])=='OFF')) { $ehvalue = -1; }
  13667. if (isset($attr['ODD-FOOTER-VALUE']) && ($attr['ODD-FOOTER-VALUE']=='1' || strtoupper($attr['ODD-FOOTER-VALUE'])=='ON')) { $ofvalue = 1; }
  13668. else if (isset($attr['ODD-FOOTER-VALUE']) && ($attr['ODD-FOOTER-VALUE']=='-1' || strtoupper($attr['ODD-FOOTER-VALUE'])=='OFF')) { $ofvalue = -1; }
  13669. if (isset($attr['EVEN-FOOTER-VALUE']) && ($attr['EVEN-FOOTER-VALUE']=='1' || strtoupper($attr['EVEN-FOOTER-VALUE'])=='ON')) { $efvalue = 1; }
  13670. else if (isset($attr['EVEN-FOOTER-VALUE']) && ($attr['EVEN-FOOTER-VALUE']=='-1' || strtoupper($attr['EVEN-FOOTER-VALUE'])=='OFF')) { $efvalue = -1; }
  13671. if (isset($attr['ORIENTATION']) && (strtoupper($attr['ORIENTATION'])=='L' || strtoupper($attr['ORIENTATION'])=='LANDSCAPE')) { $orient = 'L'; }
  13672. else if (isset($attr['ORIENTATION']) && (strtoupper($attr['ORIENTATION'])=='P' || strtoupper($attr['ORIENTATION'])=='PORTRAIT')) { $orient = 'P'; }
  13673. else { $orient = $this->CurOrientation; }
  13674. // mPDF 4.2
  13675. if (isset($attr['PAGE-SELECTOR']) && $attr['PAGE-SELECTOR']) { $pagesel = $attr['PAGE-SELECTOR']; }
  13676. else { $pagesel = ''; }
  13677. $resetpagenum = '';
  13678. $pagenumstyle = '';
  13679. $suppress = '';
  13680. if (isset($attr['RESETPAGENUM'])) { $resetpagenum = $attr['RESETPAGENUM']; }
  13681. if (isset($attr['PAGENUMSTYLE'])) { $pagenumstyle = $attr['PAGENUMSTYLE']; }
  13682. if (isset($attr['SUPPRESS'])) { $suppress = $attr['SUPPRESS']; }
  13683. if ($tag == 'TOCPAGEBREAK') { $type = 'NEXT-ODD'; }
  13684. else if(isset($attr['TYPE'])) { $type = strtoupper($attr['TYPE']); }
  13685. else { $type = ''; }
  13686. // mPDF 4.2
  13687. 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); }
  13688. 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); }
  13689. 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); }
  13690. 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); }
  13691. else { $this->AddPage($orient,'', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$newformat); }
  13692. /*-- TOC --*/
  13693. if ($tag == 'TOCPAGEBREAK') {
  13694. if ($toc_id) { $this->m_TOC[$toc_id]['TOCmark'] = $this->page; }
  13695. else { $this->TOCmark = $this->page; }
  13696. }
  13697. /*-- END TOC --*/
  13698. /*-- COLUMNS --*/
  13699. if ($save_cols) {
  13700. // Restore columns
  13701. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  13702. }
  13703. /*-- END COLUMNS --*/
  13704. if (($tag == 'FORMFEED' || $this->restoreBlockPagebreaks) && !$this->tableLevel && !$this->listlvl) {
  13705. $this->blk = $save_blk;
  13706. // Re-open block tags
  13707. $t = $this->blk[0]['tag'];
  13708. $a = $this->blk[0]['attr'];
  13709. $this->blklvl = 0;
  13710. for ($b=0; $b<=$save_blklvl;$b++) {
  13711. $tc = $t;
  13712. $ac = $a;
  13713. $t = $this->blk[$b+1]['tag'];
  13714. $a = $this->blk[$b+1]['attr'];
  13715. unset($this->blk[$b+1]);
  13716. $this->OpenTag($tc,$ac);
  13717. }
  13718. $this->spanlvl = $save_spanlvl;
  13719. $this->InlineProperties = $save_ilp;
  13720. $this->restoreInlineProperties($save_silp);
  13721. }
  13722. break;
  13723. /*-- TOC --*/
  13724. case 'TOCENTRY':
  13725. if (isset($attr['CONTENT']) && $attr['CONTENT']) {
  13726. $objattr = array();
  13727. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  13728. $objattr['type'] = 'toc';
  13729. if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['toclevel'] = $attr['LEVEL']; } else { $objattr['toclevel'] = 0; }
  13730. if (isset($attr['NAME']) && $attr['NAME']) { $objattr['toc_id'] = $attr['NAME']; } else { $objattr['toc_id'] = 0; }
  13731. $e = "\xbb\xa4\xactype=toc,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13732. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  13733. else { // *TABLES*
  13734. $this->textbuffer[] = array($e);
  13735. } // *TABLES*
  13736. }
  13737. break;
  13738. /*-- END TOC --*/
  13739. /*-- INDEX --*/
  13740. case 'INDEXENTRY':
  13741. if (isset($attr['CONTENT']) && $attr['CONTENT']) {
  13742. // mPDF 3.0
  13743. if (isset($attr['XREF']) && $attr['XREF']) {
  13744. $this->IndexEntry(htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES),$attr['XREF']);
  13745. break;
  13746. }
  13747. $objattr = array();
  13748. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  13749. $objattr['type'] = 'indexentry';
  13750. $e = "\xbb\xa4\xactype=indexentry,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13751. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  13752. else { // *TABLES*
  13753. $this->textbuffer[] = array($e);
  13754. } // *TABLES*
  13755. }
  13756. break;
  13757. // mPDF 3.0
  13758. case 'INDEXINSERT':
  13759. if (isset($attr['FONT-SIZE'])) { $reffontsize = $attr['FONT-SIZE']; } else { $reffontsize = ''; }
  13760. if (isset($attr['LINE-SPACING']) && $attr['LINE-SPACING']) { $linespacing = $attr['LINE-SPACING']; } else { $linespacing = ''; }
  13761. if (isset($attr['DIV-FONT-SIZE']) && $attr['DIV-FONT-SIZE']) { $divlettfontsize = $attr['DIV-FONT-SIZE']; } else { $divlettfontsize = ''; }
  13762. if (isset($attr['FONT']) && $attr['FONT']) { $reffont = $attr['FONT']; } else { $reffont = ''; }
  13763. if (isset($attr['DIV-FONT']) && $attr['DIV-FONT']) { $divlettfont = $attr['DIV-FONT']; } else { $divlettfont = ''; }
  13764. if (isset($attr['COLS']) && $attr['COLS']) { $cols = $attr['COLS']; } else { $cols = 1; }
  13765. if (isset($attr['OFFSET']) && $attr['OFFSET']) { $offset = $attr['OFFSET']; } else { $offset = 3; }
  13766. if (isset($attr['GAP']) && $attr['GAP']) { $gap = $attr['GAP']; } else { $gap = 5; }
  13767. if (isset($attr['USEDIVLETTERS']) && (strtoupper($attr['USEDIVLETTERS'])=='OFF' || $attr['USEDIVLETTERS']==-1 || $attr['USEDIVLETTERS']==='0')) { $usedivletters = 0; }
  13768. else { $usedivletters = 1; }
  13769. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS'])=='ON' || $attr['LINKS']==1)) { $links = true; }
  13770. else { $links = false; }
  13771. $this->CreateIndex($cols, $reffontsize, $linespacing, $offset, $usedivletters, $divlettfontsize, $gap, $reffont,$divlettfont, $links);
  13772. break;
  13773. /*-- END INDEX --*/
  13774. /*-- WATERMARK --*/
  13775. // mPDF 3.0
  13776. case 'WATERMARKTEXT':
  13777. if (isset($attr['CONTENT']) && $attr['CONTENT']) { $txt = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES); } else { $txt = ''; }
  13778. if (isset($attr['ALPHA']) && $attr['ALPHA']>0) { $alpha = $attr['ALPHA']; } else { $alpha = -1; }
  13779. $this->SetWatermarkText($txt, $alpha);
  13780. break;
  13781. // mPDF 3.0
  13782. case 'WATERMARKIMAGE':
  13783. if (isset($attr['SRC'])) { $src = $attr['SRC']; } else { $src = ''; }
  13784. if (isset($attr['ALPHA']) && $attr['ALPHA']>0) { $alpha = $attr['ALPHA']; } else { $alpha = -1; }
  13785. if (isset($attr['SIZE']) && $attr['SIZE']) {
  13786. $size = $attr['SIZE'];
  13787. if (strpos($size,',')) { $size = explode(',',$size); }
  13788. }
  13789. else { $size = 'D'; }
  13790. if (isset($attr['POS']) && $attr['POS']) {
  13791. $pos = $attr['POS'];
  13792. if (strpos($pos,',')) { $pos = explode(',',$pos); }
  13793. }
  13794. else { $pos = 'P'; }
  13795. $this->SetWatermarkImage($src, $alpha, $size, $pos);
  13796. break;
  13797. /*-- END WATERMARK --*/
  13798. /*-- BOOKMARKS --*/
  13799. case 'BOOKMARK':
  13800. if (isset($attr['CONTENT'])) {
  13801. // mPDF 3.0
  13802. $objattr = array();
  13803. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  13804. $objattr['type'] = 'bookmark';
  13805. if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['bklevel'] = $attr['LEVEL']; } else { $objattr['bklevel'] = 0; }
  13806. $e = "\xbb\xa4\xactype=bookmark,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13807. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  13808. else { // *TABLES*
  13809. $this->textbuffer[] = array($e);
  13810. } // *TABLES*
  13811. }
  13812. break;
  13813. /*-- END BOOKMARKS --*/
  13814. /*-- ANNOTATIONS --*/
  13815. case 'ANNOTATION':
  13816. // mPDF 4.0
  13817. if (isset($attr['CONTENT']) && !$this->writingHTMLheader && !$this->writingHTMLfooter) { // Stops annotations in FixedPos
  13818. $objattr = array();
  13819. // mPDF 3.0
  13820. $objattr['margin_top'] = 0;
  13821. $objattr['margin_bottom'] = 0;
  13822. $objattr['margin_left'] = 0;
  13823. $objattr['margin_right'] = 0;
  13824. $objattr['width'] = 0;
  13825. $objattr['height'] = 0;
  13826. $objattr['border_top']['w'] = 0;
  13827. $objattr['border_bottom']['w'] = 0;
  13828. $objattr['border_left']['w'] = 0;
  13829. $objattr['border_right']['w'] = 0;
  13830. $objattr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'],ENT_QUOTES);
  13831. $objattr['type'] = 'annot';
  13832. $objattr['POPUP'] = ''; // mPDF 4.2.027
  13833. }
  13834. else { break; }
  13835. if (isset($attr['POS-X'])) { $objattr['POS-X'] = $attr['POS-X']; } else { $objattr['POS-X'] = 0; }
  13836. if (isset($attr['POS-Y'])) { $objattr['POS-Y'] = $attr['POS-Y']; } else { $objattr['POS-Y'] = 0; }
  13837. if (isset($attr['ICON'])) { $objattr['ICON'] = $attr['ICON']; } else { $objattr['ICON'] = 'Note'; }
  13838. if (isset($attr['AUTHOR'])) { $objattr['AUTHOR'] = $attr['AUTHOR']; } else { $objattr['AUTHOR'] = ''; }
  13839. if (isset($attr['SUBJECT'])) { $objattr['SUBJECT'] = $attr['SUBJECT']; } else { $objattr['SUBJECT'] = ''; }
  13840. if (isset($attr['OPACITY']) && $attr['OPACITY']>0 && $attr['OPACITY']<=1) { $objattr['OPACITY'] = $attr['OPACITY']; }
  13841. else if ($this->annotMargin) { $objattr['OPACITY'] = 1; }
  13842. else { $objattr['OPACITY'] = $this->annotOpacity; }
  13843. if (isset($attr['COLOR'])) {
  13844. $cor = $this->ConvertColor($attr['COLOR']);
  13845. if ($cor) { $objattr['COLOR'] = array($cor['R'],$cor['G'],$cor['B']); }
  13846. else { $objattr['COLOR'] = array(255,255,0); }
  13847. }
  13848. else { $objattr['COLOR'] = array(255,255,0); }
  13849. // mPDF 4.2.027
  13850. if (isset($attr['POPUP']) && !empty($attr['POPUP'])) {
  13851. $pop = preg_split('/\s+/',trim($attr['POPUP']));
  13852. if (count($pop)>1) { $objattr['POPUP'] = $pop; }
  13853. else { $objattr['POPUP'] = true; }
  13854. }
  13855. $e = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13856. if($this->tableLevel) { $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); } // *TABLES*
  13857. else { // *TABLES*
  13858. $this->textbuffer[] = array($e);
  13859. } // *TABLES*
  13860. break;
  13861. /*-- END ANNOTATIONS --*/
  13862. /*-- COLUMNS --*/
  13863. case 'COLUMNS': //added custom-tag
  13864. if (isset($attr['COLUMN-COUNT']) && ($attr['COLUMN-COUNT'] || $attr['COLUMN-COUNT']==='0')) {
  13865. // Close any open block tags
  13866. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  13867. if(!empty($this->textbuffer)) { //Output previously buffered content
  13868. $this->printbuffer($this->textbuffer);
  13869. $this->textbuffer=array();
  13870. }
  13871. if (isset($attr['VALIGN']) && $attr['VALIGN']) {
  13872. if ($attr['VALIGN'] == 'J') { $valign = 'J'; }
  13873. else { $valign = $align[$attr['VALIGN']]; }
  13874. }
  13875. else { $valign = ''; }
  13876. if (isset($attr['COLUMN-GAP']) && $attr['COLUMN-GAP']) { $this->SetColumns($attr['COLUMN-COUNT'],$valign,$attr['COLUMN-GAP']); }
  13877. else { $this->SetColumns($attr['COLUMN-COUNT'],$valign); }
  13878. }
  13879. $this->ignorefollowingspaces = true;
  13880. break;
  13881. case 'COLUMN_BREAK': //custom-tag
  13882. case 'COLUMNBREAK': //custom-tag
  13883. case 'NEWCOLUMN': //custom-tag
  13884. $this->ignorefollowingspaces = true;
  13885. $this->NewColumn();
  13886. $this->ColumnAdjust = false; // disables all column height adjustment for the page.
  13887. break;
  13888. /*-- END COLUMNS --*/
  13889. case 'BDO':
  13890. $this->biDirectional = true;
  13891. break;
  13892. case 'TTZ':
  13893. $this->ttz = true;
  13894. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  13895. $this->setCSS(array('FONT-FAMILY'=>'zapfdingbats','FONT-WEIGHT'=>'normal','FONT-STYLE'=>'normal'),'INLINE');
  13896. break;
  13897. case 'TTS':
  13898. $this->tts = true;
  13899. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  13900. $this->setCSS(array('FONT-FAMILY'=>'symbol','FONT-WEIGHT'=>'normal','FONT-STYLE'=>'normal'),'INLINE');
  13901. break;
  13902. case 'TTA':
  13903. $this->tta = true;
  13904. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  13905. // mPDF 4.0
  13906. if (in_array($this->FontFamily,$this->mono_fonts)) {
  13907. $this->setCSS(array('FONT-FAMILY'=>'courier-embedded'),'INLINE');
  13908. }
  13909. else if (in_array($this->FontFamily,$this->serif_fonts)) {
  13910. $this->setCSS(array('FONT-FAMILY'=>'times-embedded'),'INLINE');
  13911. }
  13912. else {
  13913. $this->setCSS(array('FONT-FAMILY'=>'helvetica-embedded'),'INLINE');
  13914. }
  13915. break;
  13916. // INLINE PHRASES OR STYLES
  13917. case 'SUB':
  13918. case 'SUP':
  13919. case 'ACRONYM':
  13920. case 'BIG':
  13921. case 'SMALL':
  13922. case 'INS':
  13923. case 'S':
  13924. case 'STRIKE':
  13925. case 'DEL':
  13926. case 'STRONG':
  13927. case 'CITE':
  13928. case 'Q':
  13929. case 'EM':
  13930. case 'B':
  13931. case 'I':
  13932. case 'U':
  13933. case 'SAMP':
  13934. case 'CODE':
  13935. case 'KBD':
  13936. case 'TT':
  13937. case 'VAR':
  13938. case 'FONT':
  13939. case 'SPAN':
  13940. /*-- ANNOTATIONS --*/
  13941. if ($this->title2annots && isset($attr['TITLE'])) {
  13942. $objattr = array();
  13943. // mPDF 3.0
  13944. $objattr['margin_top'] = 0;
  13945. $objattr['margin_bottom'] = 0;
  13946. $objattr['margin_left'] = 0;
  13947. $objattr['margin_right'] = 0;
  13948. $objattr['width'] = 0;
  13949. $objattr['height'] = 0;
  13950. $objattr['border_top']['w'] = 0;
  13951. $objattr['border_bottom']['w'] = 0;
  13952. $objattr['border_left']['w'] = 0;
  13953. $objattr['border_right']['w'] = 0;
  13954. $objattr['CONTENT'] = $attr['TITLE'];
  13955. $objattr['type'] = 'annot';
  13956. $objattr['POS-X'] = 0;
  13957. $objattr['POS-Y'] = 0;
  13958. $objattr['ICON'] = 'Comment';
  13959. $objattr['AUTHOR'] = '';
  13960. $objattr['SUBJECT'] = '';
  13961. $objattr['OPACITY'] = $this->annotOpacity;
  13962. $objattr['COLOR'] = array(255,255,0);
  13963. $annot = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13964. }
  13965. /*-- END ANNOTATIONS --*/
  13966. if ($tag == 'SPAN') {
  13967. $this->spanlvl++;
  13968. $this->InlineProperties['SPAN'][$this->spanlvl] = $this->saveInlineProperties();
  13969. if (isset($annot)) { $this->InlineAnnots[$tag][$this->spanlvl] = $annot; } // *ANNOTATIONS*
  13970. }
  13971. else {
  13972. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  13973. if (isset($annot)) { $this->InlineAnnots[$tag] = $annot; } // *ANNOTATIONS*
  13974. }
  13975. $properties = $this->MergeCSS('INLINE',$tag,$attr); // mPDF 4.0
  13976. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  13977. break;
  13978. case 'A':
  13979. if (isset($attr['NAME']) and $attr['NAME'] != '') {
  13980. // mPDF 3.0
  13981. $e = '';
  13982. /*-- BOOKMARKS --*/
  13983. if ($this->anchor2Bookmark) {
  13984. $objattr = array();
  13985. $objattr['CONTENT'] = htmlspecialchars_decode($attr['NAME'],ENT_QUOTES);
  13986. $objattr['type'] = 'bookmark';
  13987. if (isset($attr['LEVEL']) && $attr['LEVEL']) { $objattr['bklevel'] = $attr['LEVEL']; } else { $objattr['bklevel'] = 0; }
  13988. $e = "\xbb\xa4\xactype=bookmark,objattr=".serialize($objattr)."\xbb\xa4\xac";
  13989. }
  13990. /*-- END BOOKMARKS --*/
  13991. if($this->tableLevel) { // *TABLES*
  13992. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,'','',array(),'',false,false,$attr['NAME']); // *TABLES*
  13993. } // *TABLES*
  13994. else { // *TABLES*
  13995. $this->textbuffer[] = array($e,'','',array(),'',false,false,$attr['NAME']); //an internal link (adds a space for recognition)
  13996. } // *TABLES*
  13997. }
  13998. if (isset($attr['HREF'])) {
  13999. $this->InlineProperties['A'] = $this->saveInlineProperties();
  14000. $properties = $this->MergeCSS('',$tag,$attr);
  14001. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  14002. $this->HREF=$attr['HREF'];
  14003. }
  14004. break;
  14005. case 'BR':
  14006. // Added mPDF 3.0 Float DIV - CLEAR
  14007. if (isset($attr['STYLE'])) {
  14008. $properties = $this->readInlineCSS($attr['STYLE']);
  14009. if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']),$this->blklvl); } // *CSS-FLOAT*
  14010. }
  14011. /*-- TABLES --*/
  14012. if($this->tableLevel) {
  14013. // mPDF 3.0
  14014. if ($this->blockjustfinished || $this->listjustfinished) {
  14015. $this->cell[$this->row][$this->col]['textbuffer'][] = array("\n",$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  14016. $this->cell[$this->row][$this->col]['text'][] = "\n";
  14017. }
  14018. $this->cell[$this->row][$this->col]['textbuffer'][] = array("\n",$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  14019. $this->cell[$this->row][$this->col]['text'][] = "\n";
  14020. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  14021. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14022. }
  14023. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  14024. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14025. }
  14026. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  14027. }
  14028. else {
  14029. /*-- END TABLES --*/
  14030. $this->textbuffer[] = array("\n",$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  14031. } // *TABLES*
  14032. $this->ignorefollowingspaces = true;
  14033. $this->blockjustfinished=false;
  14034. $this->listjustfinished=false;
  14035. // mPDF 3.0
  14036. $this->linebreakjustfinished=true;
  14037. break;
  14038. // *********** BLOCKS ********************
  14039. //NB $outerblocktags = array('DIV','FORM','CENTER','DL');
  14040. //NB $innerblocktags = array('P','BLOCKQUOTE','ADDRESS','PRE',''H1','H2','H3','H4','H5','H6','DT','DD');
  14041. case 'PRE':
  14042. $this->ispre=true; // ADDED - Prevents left trim of textbuffer in printbuffer()
  14043. case 'DIV':
  14044. case 'FORM':
  14045. case 'CENTER':
  14046. case 'BLOCKQUOTE':
  14047. case 'ADDRESS':
  14048. case 'P':
  14049. case 'H1':
  14050. case 'H2':
  14051. case 'H3':
  14052. case 'H4':
  14053. case 'H5':
  14054. case 'H6':
  14055. case 'DL':
  14056. case 'DT':
  14057. case 'DD':
  14058. $p = $this->PreviewBlockCSS($tag,$attr);
  14059. if(isset($p['DISPLAY']) && strtolower($p['DISPLAY'])=='none') {
  14060. $this->blklvl++;
  14061. $this->blk[$this->blklvl]['hide'] = true;
  14062. return;
  14063. }
  14064. /*-- CSS-POSITION --*/
  14065. // mPDF 4.0
  14066. if ((isset($p['POSITION']) && (strtolower($p['POSITION'])=='fixed' || strtolower($p['POSITION'])=='absolute')) && $this->blklvl==0) {
  14067. if ($this->inFixedPosBlock) {
  14068. $this->Error("Cannot nest block with position:fixed or position:absolute");
  14069. }
  14070. $this->inFixedPosBlock = true;
  14071. return;
  14072. }
  14073. /*-- END CSS-POSITION --*/
  14074. // Start Block
  14075. $this->ignorefollowingspaces = true;
  14076. // mPDF 4.2
  14077. if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins) { $lastbottommargin = $this->lastblockbottommargin; }
  14078. else { $lastbottommargin = 0; }
  14079. $this->lastblockbottommargin = 0;
  14080. $this->blockjustfinished=false;
  14081. /*-- LISTS --*/
  14082. // mPDF 4.0
  14083. if ($this->listlvl>0) { return; }
  14084. /*-- END LISTS --*/
  14085. $this->InlineProperties = array();
  14086. $this->spanlvl = 0;
  14087. $this->listjustfinished=false;
  14088. $this->divbegin=true;
  14089. // mPDF 3.0
  14090. $this->linebreakjustfinished=false;
  14091. /*-- TABLES --*/
  14092. if ($this->tableLevel) {
  14093. // mPDF 3.0
  14094. // If already something on the line
  14095. if ($this->cell[$this->row][$this->col]['s'] > 0 && !$this->nestedtablejustfinished ) {
  14096. $this->cell[$this->row][$this->col]['textbuffer'][] = array("\n",$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  14097. $this->cell[$this->row][$this->col]['text'][] = "\n";
  14098. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  14099. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14100. }
  14101. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  14102. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14103. }
  14104. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  14105. }
  14106. // Cannot set block properties inside table - use Bold to indicate h1-h6
  14107. if ($tag == 'CENTER' && $this->tdbegin) { $this->cell[$this->row][$this->col]['a'] = $align['center']; }
  14108. $this->InlineProperties['BLOCKINTABLE'] = $this->saveInlineProperties();
  14109. $properties = $this->MergeCSS('',$tag,$attr);
  14110. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  14111. break;
  14112. }
  14113. /*-- END TABLES --*/
  14114. if ($tag == 'P' || $tag == 'DT' || $tag == 'DD') { $this->lastoptionaltag = $tag; } // Save current HTML specified optional endtag
  14115. else { $this->lastoptionaltag = ''; }
  14116. if ($this->lastblocklevelchange == 1) { $blockstate = 1; } // Top margins/padding only
  14117. else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding
  14118. $this->printbuffer($this->textbuffer,$blockstate);
  14119. $this->textbuffer=array();
  14120. $this->blklvl++;
  14121. // mPDF 4.0
  14122. $currblk =& $this->blk[$this->blklvl];
  14123. $this->initialiseBlock($currblk);
  14124. $prevblk =& $this->blk[$this->blklvl-1];
  14125. $currblk['tag'] = $tag;
  14126. $currblk['attr'] = $attr;
  14127. $this->Reset();
  14128. $properties = $this->MergeCSS('BLOCK',$tag,$attr);
  14129. $pagesel = '';
  14130. /*-- CSS-PAGE --*/
  14131. // mPDF 4.2
  14132. if (isset($properties['PAGE'])) { $pagesel = $properties['PAGE']; }
  14133. /*-- END CSS-PAGE --*/
  14134. // If page-box has changed AND/OR PAGE-BREAK-BEFORE
  14135. $save_cols = false;
  14136. if (($pagesel && $pagesel != $this->page_box['current']) || (isset($properties['PAGE-BREAK-BEFORE']) && $properties['PAGE-BREAK-BEFORE'])) {
  14137. if ($this->blklvl>1) {
  14138. // Close any open block tags
  14139. for ($b= $this->blklvl;$b>0;$b--) { $this->CloseTag($this->blk[$b]['tag']); }
  14140. // Output any text left in buffer
  14141. if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer); $this->textbuffer=array(); }
  14142. }
  14143. /*-- COLUMNS --*/
  14144. if ($this->ColActive) {
  14145. $save_cols = true;
  14146. $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off
  14147. $this->SetColumns(0);
  14148. }
  14149. /*-- END COLUMNS --*/
  14150. // Must Add new page if changed page properties
  14151. if (isset($properties['PAGE-BREAK-BEFORE'])) {
  14152. if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'RIGHT') { $this->AddPage($this->CurOrientation,'NEXT-ODD','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14153. else if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'LEFT') { $this->AddPage($this->CurOrientation,'NEXT-EVEN','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14154. else if (strtoupper($properties['PAGE-BREAK-BEFORE']) == 'ALWAYS') { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14155. else if ($this->page_box['current'] != $pagesel) { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); } // *CSS-PAGE*
  14156. }
  14157. /*-- CSS-PAGE --*/
  14158. else if ($pagesel != $this->page_box['current']) { $this->AddPage($this->CurOrientation,'','','','','','', '','', '','','','','','',0,0,0,0,$pagesel); }
  14159. /*-- END CSS-PAGE --*/
  14160. // if using htmlheaders, the headers need to be rewritten when new page
  14161. // done by calling WriteHTML() within resethtmlheaders
  14162. // so block is reset to 0 - now we need to resurrect it
  14163. // As in WriteHTML() initialising
  14164. $this->blklvl = 0;
  14165. $this->lastblocklevelchange = 0;
  14166. $this->blk = array();
  14167. // mPDF 4.0
  14168. $this->initialiseBlock($this->blk[0]);
  14169. $this->blk[0]['width'] =& $this->pgwidth;
  14170. $this->blk[0]['inner_width'] =& $this->pgwidth;
  14171. // mPDF 3.0
  14172. $this->blk[0]['blockContext'] = $this->blockContext;
  14173. $properties = $this->MergeCSS('BLOCK','BODY','');
  14174. $this->setCSS($properties,'','BODY');
  14175. $this->blklvl++;
  14176. // mPDF 4.0
  14177. $currblk =& $this->blk[$this->blklvl];
  14178. $prevblk =& $this->blk[$this->blklvl-1];
  14179. $this->initialiseBlock($currblk);
  14180. $currblk['tag'] = $tag;
  14181. $currblk['attr'] = $attr;
  14182. $this->Reset();
  14183. $properties = $this->MergeCSS('BLOCK',$tag,$attr);
  14184. /*-- COLUMNS --*/
  14185. if ($save_cols) {
  14186. // Restore columns
  14187. $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap);
  14188. }
  14189. /*-- END COLUMNS --*/
  14190. }
  14191. if (isset($properties['PAGE-BREAK-INSIDE']) && strtoupper($properties['PAGE-BREAK-INSIDE']) == 'AVOID' && !$this->ColActive && !$this->keep_block_together) {
  14192. $currblk['keep_block_together'] = 1;
  14193. $currblk['y00'] = $this->y;
  14194. $this->keep_block_together = 1;
  14195. $this->divbuffer = array();
  14196. $this->ktLinks = array();
  14197. $this->ktAnnots = array();
  14198. $this->ktBlock = array();
  14199. $this->ktReference = array();
  14200. $this->ktBMoutlines = array();
  14201. $this->_kttoc = array();
  14202. }
  14203. // mPDF 4.2 Collaspe vertical block margins
  14204. if ($lastbottommargin && $properties['MARGIN-TOP']) { $currblk['lastbottommargin'] = $lastbottommargin; }
  14205. $this->setCSS($properties,'BLOCK',$tag); //name(id/class/style) found in the CSS array!
  14206. $currblk['InlineProperties'] = $this->saveInlineProperties();
  14207. if(isset($attr['ALIGN']) && $attr['ALIGN']) { $currblk['block-align'] = $align[strtolower($attr['ALIGN'])]; }
  14208. // mPDF 4.0 height
  14209. if (isset($properties['HEIGHT'])) { $currblk['css_set_height'] = $this->ConvertSize($properties['HEIGHT'],($this->h - $this->tMargin - $this->bMargin),$this->FontSize,false); }
  14210. else { $currblk['css_set_height'] = false; }
  14211. // Added mPDF 3.0 Float DIV
  14212. if (isset($prevblk['blockContext'])) { $currblk['blockContext'] = $prevblk['blockContext'] ; } // *CSS-FLOAT*
  14213. if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']), $this->blklvl-1); } // *CSS-FLOAT*
  14214. $container_w = $prevblk['inner_width'];
  14215. $bdr = $currblk['border_right']['w'];
  14216. $bdl = $currblk['border_left']['w'];
  14217. $pdr = $currblk['padding_right'];
  14218. $pdl = $currblk['padding_left'];
  14219. if (isset($currblk['css_set_width'])) { $setwidth = $currblk['css_set_width']; }
  14220. else { $setwidth = 0; }
  14221. /*-- CSS-FLOAT --*/
  14222. if (isset($properties['FLOAT']) && strtoupper($properties['FLOAT']) == 'RIGHT' && !$this->ColActive) {
  14223. // Cancel Keep-Block-together
  14224. $currblk['keep_block_together'] = false;
  14225. $currblk['y00'] = '';
  14226. $this->keep_block_together = 0;
  14227. $this->blockContext++;
  14228. $currblk['blockContext'] = $this->blockContext;
  14229. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14230. // DIV is too narrow for text to fit!
  14231. $maxw = $container_w - $l_width - $r_width;
  14232. if (($setwidth + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr)) < $this->GetStringWidth('WW')) {
  14233. // Too narrow to fit - try to move down past L or R float
  14234. 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)) > $this->GetStringWidth('WW')) {
  14235. $this->ClearFloats('LEFT', $this->blklvl-1);
  14236. }
  14237. 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)) > $this->GetStringWidth('WW')) {
  14238. $this->ClearFloats('RIGHT', $this->blklvl-1);
  14239. }
  14240. else { $this->ClearFloats('BOTH', $this->blklvl-1); }
  14241. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14242. }
  14243. if ($r_exists) { $currblk['margin_right'] += $r_width; }
  14244. $currblk['float'] = 'R';
  14245. $currblk['float_start_y'] = $this->y;
  14246. if ($currblk['css_set_width']) {
  14247. $currblk['margin_left'] = $container_w - ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']);
  14248. $currblk['float_width'] = ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']);
  14249. }
  14250. else {
  14251. // *** If no width set - would need to buffer and keep track of max width, then Right-align if not full width
  14252. // and do borders and backgrounds - For now - just set to maximum width left
  14253. if ($l_exists) { $currblk['margin_left'] += $l_width; }
  14254. $currblk['css_set_width'] = $container_w - ($currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr);
  14255. $currblk['float_width'] = ($currblk['css_set_width'] + $bdl + $pdl + $bdr + $pdr + $currblk['margin_right']);
  14256. }
  14257. }
  14258. else if (isset($properties['FLOAT']) && strtoupper($properties['FLOAT']) == 'LEFT' && !$this->ColActive) {
  14259. // Cancel Keep-Block-together
  14260. $currblk['keep_block_together'] = false;
  14261. $currblk['y00'] = '';
  14262. $this->keep_block_together = 0;
  14263. $this->blockContext++;
  14264. $currblk['blockContext'] = $this->blockContext;
  14265. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14266. // DIV is too narrow for text to fit!
  14267. $maxw = $container_w - $l_width - $r_width;
  14268. if (($setwidth + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) < $this->GetStringWidth('WW')) {
  14269. // Too narrow to fit - try to move down past L or R float
  14270. 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)) > $this->GetStringWidth('WW')) {
  14271. $this->ClearFloats('LEFT', $this->blklvl-1);
  14272. }
  14273. 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)) > $this->GetStringWidth('WW')) {
  14274. $this->ClearFloats('RIGHT', $this->blklvl-1);
  14275. }
  14276. else { $this->ClearFloats('BOTH', $this->blklvl-1); }
  14277. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14278. }
  14279. if ($l_exists) { $currblk['margin_left'] += $l_width; }
  14280. $currblk['float'] = 'L';
  14281. $currblk['float_start_y'] = $this->y;
  14282. if ($setwidth) {
  14283. $currblk['margin_right'] = $container_w - ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']);
  14284. $currblk['float_width'] = ($setwidth + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']);
  14285. }
  14286. else {
  14287. // *** If no width set - would need to buffer and keep track of max width, then Right-align if not full width
  14288. // and do borders and backgrounds - For now - just set to maximum width left
  14289. if ($r_exists) { $currblk['margin_right'] += $r_width; }
  14290. $currblk['css_set_width'] = $container_w - ($currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr);
  14291. $currblk['float_width'] = ($currblk['css_set_width'] + $bdl + $pdl + $bdr + $pdr + $currblk['margin_left']);
  14292. }
  14293. }
  14294. else {
  14295. // Don't allow overlap - if floats present - adjust padding to avoid overlap with Floats
  14296. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14297. $maxw = $container_w - $l_width - $r_width;
  14298. if (($setwidth + $currblk['margin_left'] + $currblk['margin_right'] + $bdl + $pdl + $bdr + $pdr) > $maxw || ($maxw - ($currblk['margin_right'] + $currblk['margin_left'] + $bdl + $pdl + $bdr + $pdr)) < $this->GetStringWidth('WW')) {
  14299. // Too narrow to fit - try to move down past L or R float
  14300. 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)) > $this->GetStringWidth('WW')) {
  14301. $this->ClearFloats('LEFT', $this->blklvl-1);
  14302. }
  14303. 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)) > $this->GetStringWidth('WW')) {
  14304. $this->ClearFloats('RIGHT', $this->blklvl-1);
  14305. }
  14306. else { $this->ClearFloats('BOTH', $this->blklvl-1); }
  14307. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl-1);
  14308. }
  14309. if ($r_exists) { $currblk['padding_right'] = max(($r_width-$currblk['margin_right']-$bdr), $pdr); }
  14310. if ($l_exists) { $currblk['padding_left'] = max(($l_width-$currblk['margin_left']-$bdl), $pdl); }
  14311. }
  14312. /*-- END CSS-FLOAT --*/
  14313. /*-- BORDER-RADIUS --*/
  14314. // Automatically increase padding if required for border-radius
  14315. if ($this->autoPadding && !$this->ColActive && !$this->keep_block_together) {
  14316. if ($currblk['border_radius_TL_H']>$currblk['padding_left'] && $currblk['border_radius_TL_V']>$currblk['padding_top']) {
  14317. if ($currblk['border_radius_TL_H']>$currblk['border_radius_TL_V']) {
  14318. $this->_borderPadding($currblk['border_radius_TL_H'],$currblk['border_radius_TL_V'], $currblk['padding_left'], $currblk['padding_top']);
  14319. }
  14320. else {
  14321. $this->_borderPadding($currblk['border_radius_TL_V'],$currblk['border_radius_TL_H'], $currblk['padding_top'], $currblk['padding_left']);
  14322. }
  14323. }
  14324. if ($currblk['border_radius_TR_H']>$currblk['padding_right'] && $currblk['border_radius_TR_V']>$currblk['padding_top']) {
  14325. if ($currblk['border_radius_TR_H']>$currblk['border_radius_TR_V']) {
  14326. $this->_borderPadding($currblk['border_radius_TR_H'],$currblk['border_radius_TR_V'], $currblk['padding_right'], $currblk['padding_top']);
  14327. }
  14328. else {
  14329. $this->_borderPadding($currblk['border_radius_TR_V'],$currblk['border_radius_TR_H'], $currblk['padding_top'], $currblk['padding_right']);
  14330. }
  14331. }
  14332. if ($currblk['border_radius_BL_H']>$currblk['padding_left'] && $currblk['border_radius_BL_V']>$currblk['padding_bottom']) {
  14333. if ($currblk['border_radius_BL_H']>$currblk['border_radius_BL_V']) {
  14334. $this->_borderPadding($currblk['border_radius_BL_H'],$currblk['border_radius_BL_V'], $currblk['padding_left'], $currblk['padding_bottom']);
  14335. }
  14336. else {
  14337. $this->_borderPadding($currblk['border_radius_BL_V'],$currblk['border_radius_BL_H'], $currblk['padding_bottom'], $currblk['padding_left']);
  14338. }
  14339. }
  14340. if ($currblk['border_radius_BR_H']>$currblk['padding_right'] && $currblk['border_radius_BR_V']>$currblk['padding_bottom']) {
  14341. if ($currblk['border_radius_BR_H']>$currblk['border_radius_BR_V']) {
  14342. $this->_borderPadding($currblk['border_radius_BR_H'],$currblk['border_radius_BR_V'], $currblk['padding_right'], $currblk['padding_bottom']);
  14343. }
  14344. else {
  14345. $this->_borderPadding($currblk['border_radius_BR_V'],$currblk['border_radius_BR_H'], $currblk['padding_bottom'], $currblk['padding_right']);
  14346. }
  14347. }
  14348. }
  14349. /*-- END BORDER-RADIUS --*/
  14350. // Hanging indent - if negative indent: ensure padding is >= indent
  14351. // mPDF 4.0
  14352. $cbti = $this->ConvertSize($currblk['text_indent'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  14353. if ($cbti < 0) {
  14354. $hangind = -($cbti);
  14355. if ($this->directionality == 'rtl') { // *RTL*
  14356. $currblk['padding_right'] = max($currblk['padding_right'],$hangind); // *RTL*
  14357. } // *RTL*
  14358. else { // *RTL*
  14359. $currblk['padding_left'] = max($currblk['padding_left'],$hangind);
  14360. } // *RTL*
  14361. }
  14362. if (isset($currblk['css_set_width'])) {
  14363. if (isset($properties['MARGIN-LEFT']) && isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-LEFT'])=='auto' && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  14364. // Try to reduce margins to accomodate - if still too wide, set margin-right/left=0 (reduces width)
  14365. $anyextra = $prevblk['inner_width'] - ($currblk['css_set_width'] + $currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right']);
  14366. if ($anyextra>0) {
  14367. $currblk['margin_left'] = $currblk['margin_right'] = $anyextra /2;
  14368. }
  14369. else {
  14370. $currblk['margin_left'] = $currblk['margin_right'] = 0;
  14371. }
  14372. }
  14373. else if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  14374. // Try to reduce margin-left to accomodate - if still too wide, set margin-left=0 (reduces width)
  14375. $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']);
  14376. if ($currblk['margin_left'] < 0) {
  14377. $currblk['margin_left'] = 0;
  14378. }
  14379. }
  14380. else if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  14381. // Try to reduce margin-right to accomodate - if still too wide, set margin-right=0 (reduces width)
  14382. $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']);
  14383. if ($currblk['margin_right'] < 0) {
  14384. $currblk['margin_right'] = 0;
  14385. }
  14386. }
  14387. else {
  14388. if ($this->directionality == 'rtl') { // *RTL*
  14389. // Try to reduce margin-left to accomodate - if still too wide, set margin-left=0 (reduces width)
  14390. $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*
  14391. if ($currblk['margin_left'] < 0) { // *RTL*
  14392. $currblk['margin_left'] = 0; // *RTL*
  14393. } // *RTL*
  14394. } // *RTL*
  14395. else { // *RTL*
  14396. // Try to reduce margin-right to accomodate - if still too wide, set margin-right=0 (reduces width)
  14397. $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']);
  14398. if ($currblk['margin_right'] < 0) {
  14399. $currblk['margin_right'] = 0;
  14400. }
  14401. } // *RTL*
  14402. }
  14403. }
  14404. $currblk['outer_left_margin'] = $prevblk['outer_left_margin'] + $currblk['margin_left'] + $prevblk['border_left']['w'] + $prevblk['padding_left'];
  14405. $currblk['outer_right_margin'] = $prevblk['outer_right_margin'] + $currblk['margin_right'] + $prevblk['border_right']['w'] + $prevblk['padding_right'];
  14406. $currblk['width'] = $this->pgwidth - ($currblk['outer_right_margin'] + $currblk['outer_left_margin']);
  14407. $currblk['inner_width'] = $currblk['width'] - ($currblk['border_left']['w'] + $currblk['padding_left'] + $currblk['border_right']['w'] + $currblk['padding_right']);
  14408. // Check DIV is not now too narrow to fit text
  14409. $mw = $this->GetStringWidth('WW');
  14410. if ($currblk['inner_width'] < $mw) {
  14411. $currblk['padding_left'] = 0;
  14412. $currblk['padding_right'] = 0;
  14413. $currblk['border_left']['w'] = 0.2;
  14414. $currblk['border_right']['w'] = 0.2;
  14415. $currblk['margin_left'] = 0;
  14416. $currblk['margin_right'] = 0;
  14417. $currblk['outer_left_margin'] = $prevblk['outer_left_margin'] + $currblk['margin_left'] + $prevblk['border_left']['w'] + $prevblk['padding_left'];
  14418. $currblk['outer_right_margin'] = $prevblk['outer_right_margin'] + $currblk['margin_right'] + $prevblk['border_right']['w'] + $prevblk['padding_right'];
  14419. $currblk['width'] = $this->pgwidth - ($currblk['outer_right_margin'] + $currblk['outer_left_margin']);
  14420. $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']);
  14421. // if ($currblk['inner_width'] < $mw) { $this->Error("DIV is too narrow for text to fit!"); }
  14422. }
  14423. $this->x = $this->lMargin + $currblk['outer_left_margin'];
  14424. /*-- BACKGROUND-IMAGES --*/
  14425. // mPDF 4.3.011
  14426. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->kwt && !$this->ColActive && !$this->keep_block_together) {
  14427. $file = $properties['BACKGROUND-IMAGE'];
  14428. $sizesarray = $this->Image($file,0,0,0,0,'','',false, false, false, false, false); // mPDF 4.3.012D
  14429. if (isset($sizesarray['IMAGE_ID'])) {
  14430. $image_id = $sizesarray['IMAGE_ID'];
  14431. $orig_w = $sizesarray['WIDTH']*$this->k; // in user units i.e. mm
  14432. $orig_h = $sizesarray['HEIGHT']*$this->k; // (using $this->img_dpi)
  14433. $x_repeat = true;
  14434. $y_repeat = true;
  14435. if (isset($properties['BACKGROUND-REPEAT'])) {
  14436. if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-x') { $y_repeat = false; }
  14437. if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-y') { $x_repeat = false; }
  14438. }
  14439. $x_pos = 0;
  14440. $y_pos = 0;
  14441. if (isset($properties['BACKGROUND-POSITION'])) {
  14442. $ppos = preg_split('/\s+/',$properties['BACKGROUND-POSITION']);
  14443. $x_pos = $ppos[0];
  14444. $y_pos = $ppos[1];
  14445. if (!stristr($x_pos ,'%') ) { $x_pos = $this->ConvertSize($x_pos ,$currblk['inner_width'],$this->FontSize); }
  14446. if (!stristr($y_pos ,'%') ) { $y_pos = $this->ConvertSize($y_pos ,$currblk['inner_width'],$this->FontSize); }
  14447. }
  14448. // mPDF 4.3.015
  14449. if (isset($properties['BACKGROUND-IMAGE-RESIZE'])) { $resize = $properties['BACKGROUND-IMAGE-RESIZE']; }
  14450. else { $resize = 0; }
  14451. // mPDF 4.3.017
  14452. if (isset($properties['BACKGROUND-IMAGE-OPACITY'])) { $opacity = $properties['BACKGROUND-IMAGE-OPACITY']; }
  14453. else { $opacity = 1; }
  14454. $currblk['background-image'] = 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); // mPDF 4.3.015 4.3.017
  14455. }
  14456. }
  14457. /*-- END BACKGROUND-IMAGES --*/
  14458. /*-- TABLES --*/
  14459. if ($this->use_kwt && isset($attr['KEEP-WITH-TABLE']) && !$this->ColActive && !$this->keep_block_together) {
  14460. $this->kwt = true;
  14461. $this->kwt_y0 = $this->y;
  14462. $this->kwt_x0 = $this->x;
  14463. $this->kwt_height = 0;
  14464. $this->kwt_buffer = array();
  14465. $this->kwt_Links = array();
  14466. $this->kwt_Annots = array();
  14467. $this->kwt_moved = false;
  14468. $this->kwt_saved = false;
  14469. // mPDF 3.0
  14470. $this->kwt_Reference = array();
  14471. $this->kwt_BMoutlines = array();
  14472. $this->kwt_toc = array();
  14473. }
  14474. else {
  14475. /*-- END TABLES --*/
  14476. $this->kwt = false;
  14477. } // *TABLES*
  14478. //Save x,y coords in case we need to print borders...
  14479. $currblk['y0'] = $this->y;
  14480. $currblk['x0'] = $this->x;
  14481. $currblk['startpage'] = $this->page;
  14482. $this->oldy = $this->y;
  14483. $this->lastblocklevelchange = 1 ;
  14484. break;
  14485. case 'HR':
  14486. // Added mPDF 3.0 Float DIV - CLEAR
  14487. if (isset($attr['STYLE'])) {
  14488. $properties = $this->readInlineCSS($attr['STYLE']);
  14489. if (isset($properties['CLEAR'])) { $this->ClearFloats(strtoupper($properties['CLEAR']),$this->blklvl); } // *CSS-FLOAT*
  14490. }
  14491. $this->ignorefollowingspaces = true;
  14492. $objattr = array();
  14493. // mPDF 3.0
  14494. $objattr['margin_top'] = 0;
  14495. $objattr['margin_bottom'] = 0;
  14496. $objattr['margin_left'] = 0;
  14497. $objattr['margin_right'] = 0;
  14498. $objattr['width'] = 0;
  14499. $objattr['height'] = 0;
  14500. $objattr['border_top']['w'] = 0;
  14501. $objattr['border_bottom']['w'] = 0;
  14502. $objattr['border_left']['w'] = 0;
  14503. $objattr['border_right']['w'] = 0;
  14504. $properties = $this->MergeCSS('',$tag,$attr);
  14505. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top'] = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14506. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14507. if (isset($properties['WIDTH'])) { $objattr['width'] = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']); }
  14508. if (isset($properties['TEXT-ALIGN'])) { $objattr['align'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  14509. // mPDF 3.0
  14510. if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  14511. $objattr['align'] = 'R';
  14512. }
  14513. if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  14514. $objattr['align'] = 'L';
  14515. if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto' && isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  14516. $objattr['align'] = 'C';
  14517. }
  14518. }
  14519. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  14520. if (isset($properties['HEIGHT'])) { $objattr['linewidth'] = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14521. if(isset($attr['WIDTH']) && $attr['WIDTH'] != '') $objattr['width'] = $this->ConvertSize($attr['WIDTH'],$this->blk[$this->blklvl]['inner_width']);
  14522. if(isset($attr['ALIGN']) && $attr['ALIGN'] != '') $objattr['align'] = $align[strtolower($attr['ALIGN'])];
  14523. if(isset($attr['COLOR']) && $attr['COLOR'] != '') $objattr['color'] = $this->ConvertColor($attr['COLOR']);
  14524. /*-- TABLES --*/
  14525. if ($this->tableLevel) {
  14526. $objattr['W-PERCENT'] = 100;
  14527. if (isset($properties['WIDTH']) && stristr($properties['WIDTH'],'%')) {
  14528. $properties['WIDTH'] += 0; //make "90%" become simply "90"
  14529. $objattr['W-PERCENT'] = $properties['WIDTH'];
  14530. }
  14531. if (isset($attr['WIDTH']) && stristr($attr['WIDTH'],'%')) {
  14532. $attr['WIDTH'] += 0; //make "90%" become simply "90"
  14533. $objattr['W-PERCENT'] = $attr['WIDTH'];
  14534. }
  14535. }
  14536. /*-- END TABLES --*/
  14537. $objattr['type'] = 'hr';
  14538. $objattr['height'] = $objattr['linewidth'] + $objattr['margin_top'] + $objattr['margin_bottom'];
  14539. $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14540. // Clear properties - tidy up
  14541. $properties = array();
  14542. /*-- TABLES --*/
  14543. // Output it to buffers
  14544. if ($this->tableLevel) {
  14545. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  14546. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14547. }
  14548. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  14549. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  14550. }
  14551. $this->cell[$this->row][$this->col]['s'] = 0 ;// reset
  14552. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  14553. }
  14554. else {
  14555. /*-- END TABLES --*/
  14556. $this->textbuffer[] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  14557. } // *TABLES*
  14558. break;
  14559. /*-- BARCODES --*/
  14560. // mPDF 4.0
  14561. case 'BARCODE':
  14562. if(isset($attr['CODE']) && $attr['CODE']) {
  14563. $objattr = array();
  14564. $objattr['margin_top'] = 0;
  14565. $objattr['margin_bottom'] = 0;
  14566. $objattr['margin_left'] = 0;
  14567. $objattr['margin_right'] = 0;
  14568. $objattr['padding_top'] = 0;
  14569. $objattr['padding_bottom'] = 0;
  14570. $objattr['padding_left'] = 0;
  14571. $objattr['padding_right'] = 0;
  14572. $objattr['width'] = 0;
  14573. $objattr['height'] = 0;
  14574. $objattr['border_top']['w'] = 0;
  14575. $objattr['border_bottom']['w'] = 0;
  14576. $objattr['border_left']['w'] = 0;
  14577. $objattr['border_right']['w'] = 0;
  14578. $objattr['code'] = $attr['CODE'];
  14579. if(isset($attr['TYPE'])) {
  14580. $objattr['btype'] = trim(strtoupper($attr['TYPE']));
  14581. }
  14582. else { $objattr['btype'] = 'EAN13'; } // default
  14583. if (preg_match('/^(EAN13|ISBN|ISSN|EAN8|UPCA|UPCE)P([25])$/',$objattr['btype'],$m)) {
  14584. $objattr['btype'] = $m[1];
  14585. $objattr['bsupp'] = $m[2];
  14586. if (preg_match('/^(\S+)\s+(.*)$/',$objattr['code'],$mm)) {
  14587. $objattr['code'] = $mm[1];
  14588. $objattr['bsupp_code'] = $mm[2];
  14589. }
  14590. }
  14591. else { $objattr['bsupp'] = 0; }
  14592. if(isset($attr['TEXT']) && $attr['TEXT']==1) { $objattr['showtext'] = 1; }
  14593. else { $objattr['showtext'] = 0; }
  14594. if(isset($attr['SIZE']) && $attr['SIZE']>0) { $objattr['bsize'] = $attr['SIZE']; }
  14595. else { $objattr['bsize'] = 1; }
  14596. if(isset($attr['HEIGHT']) && $attr['HEIGHT']>0) { $objattr['bheight'] = $attr['HEIGHT']; }
  14597. else { $objattr['bheight'] = 1; }
  14598. if(isset($attr['PR']) && $attr['PR']>0) { $objattr['pr_ratio'] = $attr['PR']; }
  14599. else { $objattr['pr_ratio'] = ''; }
  14600. $properties = $this->MergeCSS('',$tag,$attr);
  14601. if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') {
  14602. return;
  14603. }
  14604. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14605. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14606. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14607. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14608. if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14609. if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14610. if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14611. if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14612. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  14613. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  14614. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  14615. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  14616. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  14617. if (isset($properties['COLOR']) && $properties['COLOR'] != '') { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  14618. else { $objattr['color'] = false; }
  14619. if (isset($properties['BACKGROUND-COLOR']) && $properties['BACKGROUND-COLOR'] != '') { $objattr['bgcolor'] = $this->ConvertColor($properties['BACKGROUND-COLOR']); }
  14620. else { $objattr['bgcolor'] = false; }
  14621. if (!class_exists('PDFBarcode')) {
  14622. include(_MPDF_PATH.'classes/barcode.php');
  14623. $this->barcode = new PDFBarcode();
  14624. }
  14625. if ($objattr['btype'] == 'EAN13' || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN' || $objattr['btype'] == 'UPCA' || $objattr['btype'] == 'UPCE' || $objattr['btype'] == 'EAN8') {
  14626. $code = preg_replace('/\-/','',$objattr['code']);
  14627. if ($objattr['btype'] == 'ISSN' || $objattr['btype'] == 'ISBN') {
  14628. $arrcode = $this->barcode->getBarcodeArray($code, 'EAN13');
  14629. }
  14630. else { $arrcode = $this->barcode->getBarcodeArray($code, $objattr['btype'] ); }
  14631. if ($arrcode === false) { $this->Error('Error in barcode string.'); }
  14632. if ($objattr['bsupp'] == 2 || $objattr['bsupp'] == 5) { // EAN-2 or -5 Supplement
  14633. $supparrcode = $this->barcode->getBarcodeArray($objattr['bsupp_code'], 'EAN'.$objattr['bsupp'] );
  14634. $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR'] + $supparrcode["maxw"] + $supparrcode['sepM']) * $arrcode['nom-X'] * $objattr['bsize'];
  14635. }
  14636. else {
  14637. $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR']) * $arrcode['nom-X'] * $objattr['bsize'];
  14638. }
  14639. $h = $arrcode['nom-H'] * $objattr['bsize'] * $objattr['bheight'];
  14640. // Add height for ISBN string + margin from top of bars
  14641. if (($objattr['showtext'] && $objattr['btype'] == 'EAN13') || $objattr['btype'] == 'ISBN' || $objattr['btype'] == 'ISSN') {
  14642. $tisbnm = 1.5 * $objattr['bsize']; // Top margin between TOP TEXT (isbn - if shown) & bars
  14643. $isbn_fontsize = 2.1 * $objattr['bsize'];
  14644. $h += $isbn_fontsize + $tisbnm ;
  14645. }
  14646. }
  14647. else if ($objattr['btype'] == 'IMB' || $objattr['btype'] == 'RM4SCC' || $objattr['btype'] == 'KIX' || $objattr['btype'] == 'POSTNET' || $objattr['btype'] == 'PLANET') {
  14648. $arrcode = $this->barcode->getBarcodeArray($objattr['code'], $objattr['btype'] );
  14649. if ($arrcode === false) { $this->Error('Error in barcode string.'); }
  14650. $w = ($arrcode["maxw"] * $arrcode['nom-X'] * $objattr['bsize']) + $arrcode['quietL'] + $arrcode['quietR'];
  14651. $h = ($arrcode['nom-H'] * $objattr['bsize']) + (2*$arrcode['quietTB']);
  14652. }
  14653. 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'))) {
  14654. $arrcode = $this->barcode->getBarcodeArray($objattr['code'], $objattr['btype'], $objattr['pr_ratio'] );
  14655. if ($arrcode === false) { $this->Error('Error in barcode string.'); }
  14656. $w = ($arrcode["maxw"] + $arrcode['lightmL'] + $arrcode['lightmR']) * $arrcode['nom-X'] * $objattr['bsize'];
  14657. $h = ((2*$arrcode['lightTB'] * $arrcode['nom-X']) + $arrcode['nom-H']) * $objattr['bsize'] * $objattr['bheight'];
  14658. }
  14659. else { break; }
  14660. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  14661. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  14662. $objattr['type'] = 'barcode';
  14663. $objattr['height'] = $h + $extraheight;
  14664. $objattr['width'] = $w + $extrawidth;
  14665. $objattr['barcode_height'] = $h;
  14666. $objattr['barcode_width'] = $w;
  14667. /*-- CSS-IMAGE-FLOAT --*/
  14668. if (!$this->ColActive && !$this->tableLevel && !$this->listlvl && !$this->kwt && !$this->keep_block_together) {
  14669. if (isset($properties['FLOAT']) && (strtoupper($properties['FLOAT']) == 'RIGHT' || strtoupper($properties['FLOAT']) == 'LEFT')) {
  14670. $objattr['float'] = substr(strtoupper($properties['FLOAT']),0,1);
  14671. }
  14672. }
  14673. /*-- END CSS-IMAGE-FLOAT --*/
  14674. $e = "\xbb\xa4\xactype=barcode,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14675. // Clear properties - tidy up
  14676. $properties = array();
  14677. /*-- TABLES --*/
  14678. // Output it to buffers
  14679. if ($this->tableLevel) {
  14680. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  14681. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  14682. }
  14683. else {
  14684. /*-- END TABLES --*/
  14685. $this->textbuffer[] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  14686. } // *TABLES*
  14687. }
  14688. break;
  14689. /*-- END BARCODES --*/
  14690. // *********** FORM ELEMENTS ********************
  14691. /*-- FORMS --*/
  14692. case 'SELECT':
  14693. $this->lastoptionaltag = ''; // Save current HTML specified optional endtag
  14694. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  14695. $properties = $this->MergeCSS('',$tag,$attr);
  14696. if (isset($properties['FONT-FAMILY'])) {
  14697. if (!$this->isCJK) {
  14698. $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false);
  14699. }
  14700. }
  14701. if (isset($properties['FONT-SIZE'])) {
  14702. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/$this->k);
  14703. $this->SetFontSize($mmsize*$this->k,false);
  14704. }
  14705. if (isset($properties['COLOR'])) { $this->selectoption['COLOR'] = $this->ConvertColor($properties['COLOR']); }
  14706. $this->specialcontent = "type=select";
  14707. if(isset($attr['DISABLED'])) { $this->selectoption['DISABLED'] = $attr['DISABLED']; }
  14708. if(isset($attr['TITLE'])) { $this->selectoption['TITLE'] = $attr['TITLE']; }
  14709. if(isset($attr['MULTIPLE'])) { $this->selectoption['MULTIPLE'] = $attr['MULTIPLE']; }
  14710. if(isset($attr['SIZE']) && $attr['SIZE']>1) { $this->selectoption['SIZE'] = $attr['SIZE']; }
  14711. $properties = array();
  14712. break;
  14713. case 'OPTION':
  14714. $this->lastoptionaltag = 'OPTION'; // Save current HTML specified optional endtag
  14715. $this->selectoption['ACTIVE'] = true;
  14716. $this->selectoption['currentSEL'] = false;
  14717. if (empty($this->selectoption)) {
  14718. $this->selectoption['MAXWIDTH'] = '';
  14719. $this->selectoption['SELECTED'] = '';
  14720. }
  14721. if (isset($attr['SELECTED'])) {
  14722. $this->selectoption['SELECTED'] = '';
  14723. $this->selectoption['currentSEL'] = true;
  14724. }
  14725. // mPDD 1.4 Active Forms
  14726. $this->selectoption['currentVAL'] = $attr['VALUE'];
  14727. break;
  14728. case 'TEXTAREA':
  14729. $objattr = array();
  14730. // mPDF 3.0
  14731. $objattr['margin_top'] = 0;
  14732. $objattr['margin_bottom'] = 0;
  14733. $objattr['margin_left'] = 0;
  14734. $objattr['margin_right'] = 0;
  14735. $objattr['width'] = 0;
  14736. $objattr['height'] = 0;
  14737. $objattr['border_top']['w'] = 0;
  14738. $objattr['border_bottom']['w'] = 0;
  14739. $objattr['border_left']['w'] = 0;
  14740. $objattr['border_right']['w'] = 0;
  14741. if(isset($attr['DISABLED'])) { $objattr['disabled'] = true; }
  14742. if(isset($attr['READONLY'])) { $objattr['readonly'] = true; }
  14743. if(isset($attr['TITLE'])) { $objattr['title'] = $attr['TITLE']; }
  14744. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  14745. $properties = $this->MergeCSS('',$tag,$attr);
  14746. if (isset($properties['FONT-FAMILY'])) {
  14747. if (!$this->isCJK) {
  14748. $this->SetFont($properties['FONT-FAMILY'],'',0,false);
  14749. }
  14750. }
  14751. if (isset($properties['FONT-SIZE'])) {
  14752. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/$this->k);
  14753. $this->SetFontSize($mmsize*$this->k,false);
  14754. }
  14755. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  14756. $objattr['fontfamily'] = $this->FontFamily;
  14757. $objattr['fontsize'] = $this->FontSizePt;
  14758. $this->SetLineHeight('',$this->textarea_lineheight);
  14759. $formLineHeight = $this->lineheight;
  14760. $w = 0;
  14761. $h = 0;
  14762. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  14763. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  14764. if ($properties['VERTICAL-ALIGN']) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  14765. $colsize = 20; //HTML default value
  14766. $rowsize = 2; //HTML default value
  14767. if (isset($attr['COLS'])) $colsize = intval($attr['COLS']);
  14768. if (isset($attr['ROWS'])) $rowsize = intval($attr['ROWS']);
  14769. $charsize = $this->GetStringWidth('w');
  14770. if ($w) { $colsize = round(($w-($this->form_element_spacing['textarea']['outer']['h']*2)-($this->form_element_spacing['textarea']['inner']['h']*2))/$charsize); }
  14771. if ($h) { $rowsize = round(($h-($this->form_element_spacing['textarea']['outer']['v']*2)-($this->form_element_spacing['textarea']['inner']['v']*2))/$formLineHeight); }
  14772. $objattr['type'] = 'textarea';
  14773. $objattr['width'] = ($colsize * $charsize) + ($this->form_element_spacing['textarea']['outer']['h']*2)+($this->form_element_spacing['textarea']['inner']['h']*2);
  14774. $objattr['height'] = ($rowsize * $formLineHeight) + ($this->form_element_spacing['textarea']['outer']['v']*2)+($this->form_element_spacing['textarea']['inner']['v']*2);
  14775. $objattr['rows'] = $rowsize;
  14776. $objattr['cols'] = $colsize;
  14777. $this->specialcontent = serialize($objattr);
  14778. if ($this->tableLevel) { // *TABLES*
  14779. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; // *TABLES*
  14780. } // *TABLES*
  14781. // Clear properties - tidy up
  14782. $properties = array();
  14783. break;
  14784. // *********** FORM - INPUT ********************
  14785. case 'INPUT':
  14786. if (!isset($attr['TYPE'])) $attr['TYPE'] == 'TEXT';
  14787. $objattr = array();
  14788. // mPDF 3.0
  14789. $objattr['margin_top'] = 0;
  14790. $objattr['margin_bottom'] = 0;
  14791. $objattr['margin_left'] = 0;
  14792. $objattr['margin_right'] = 0;
  14793. $objattr['width'] = 0;
  14794. $objattr['height'] = 0;
  14795. $objattr['border_top']['w'] = 0;
  14796. $objattr['border_bottom']['w'] = 0;
  14797. $objattr['border_left']['w'] = 0;
  14798. $objattr['border_right']['w'] = 0;
  14799. $objattr['type'] = 'input';
  14800. if(isset($attr['DISABLED'])) { $objattr['disabled'] = true; }
  14801. if(isset($attr['READONLY'])) { $objattr['readonly'] = true; }
  14802. if(isset($attr['TITLE'])) { $objattr['title'] = $attr['TITLE']; }
  14803. else if(isset($attr['ALT'])) { $objattr['title'] = $attr['ALT']; }
  14804. $this->InlineProperties[$tag] = $this->saveInlineProperties();
  14805. $properties = $this->MergeCSS('',$tag,$attr);
  14806. $objattr['vertical-align'] = '';
  14807. if (isset($properties['FONT-FAMILY'])) {
  14808. if (!$this->isCJK) {
  14809. $this->SetFont($properties['FONT-FAMILY'],$this->FontStyle,0,false);
  14810. }
  14811. }
  14812. if (isset($properties['FONT-SIZE'])) {
  14813. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],($this->default_font_size/$this->k));
  14814. $this->SetFontSize($mmsize*$this->k,false);
  14815. }
  14816. if (isset($properties['COLOR'])) { $objattr['color'] = $this->ConvertColor($properties['COLOR']); }
  14817. $objattr['fontfamily'] = $this->FontFamily;
  14818. $objattr['fontsize'] = $this->FontSizePt;
  14819. $type = '';
  14820. $texto='';
  14821. $height = $this->FontSize;
  14822. $width = 0;
  14823. $spacesize = $this->GetStringWidth(' ');
  14824. $w = 0;
  14825. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']);
  14826. if ($properties['VERTICAL-ALIGN']) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  14827. switch(strtoupper($attr['TYPE'])){
  14828. case 'HIDDEN':
  14829. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  14830. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  14831. unset($this->InlineProperties[$tag]);
  14832. break 2;
  14833. case 'CHECKBOX': //Draw Checkbox
  14834. $type = 'CHECKBOX';
  14835. if (isset($attr['VALUE'])) $objattr['value'] = $attr['VALUE'];
  14836. if (isset($attr['CHECKED'])) { $objattr['checked'] = true; }
  14837. else { $objattr['checked'] = false; }
  14838. $width = $this->FontSize;
  14839. $height = $this->FontSize;
  14840. break;
  14841. case 'RADIO': //Draw Radio button
  14842. $type = 'RADIO';
  14843. if (isset($attr['CHECKED'])) $objattr['checked'] = true;
  14844. $width = $this->FontSize;
  14845. $height = $this->FontSize;
  14846. break;
  14847. /*-- IMAGES-CORE --*/
  14848. case 'IMAGE': // Draw an Image button
  14849. if(isset($attr['SRC'])) {
  14850. $type = 'IMAGE';
  14851. $srcpath = $attr['SRC'];
  14852. $orig_srcpath = $attr['ORIG_SRC']; // mPDF 4.2.029
  14853. // VSPACE and HSPACE converted to margins in MergeCSS
  14854. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14855. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14856. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14857. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  14858. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  14859. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  14860. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  14861. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  14862. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  14863. $w = 0;
  14864. $h = 0;
  14865. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width']);
  14866. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width']);
  14867. $extraheight = $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  14868. $extrawidth = $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  14869. // Image file
  14870. // mPDF 4.2
  14871. $info=$this->_getImage($srcpath, true, false, $orig_srcpath); // mPDF 4.2.029
  14872. if(!$info) {
  14873. $info = $this->_getImage($this->noImageFile);
  14874. if ($info) {
  14875. $srcpath = $this->noImageFile;
  14876. $w = ($info['w'] * (25.4/$this->dpi)); // mPDF 4.4.003
  14877. $h = ($info['h'] * (25.4/$this->dpi)); // mPDF 4.4.003
  14878. }
  14879. }
  14880. if(!$info) break;
  14881. $objattr['file'] = $srcpath;
  14882. //Default width and height calculation if needed
  14883. if($w==0 and $h==0) {
  14884. //Put image at default dpi
  14885. $w=($info['w']/$this->k) * (72/$this->img_dpi);
  14886. $h=($info['h']/$this->k) * (72/$this->img_dpi);
  14887. }
  14888. // IF WIDTH OR HEIGHT SPECIFIED
  14889. if($w==0) $w=$h*$info['w']/$info['h'];
  14890. if($h==0) $h=$w*$info['h']/$info['w'];
  14891. // Resize to maximum dimensions of page
  14892. $maxWidth = $this->blk[$this->blklvl]['inner_width'];
  14893. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 10) ; // mPDF 4.1
  14894. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; } // mPDF 4.1
  14895. if ($w + $extrawidth > $maxWidth ) {
  14896. $w = $maxWidth - $extrawidth;
  14897. $h=$w*$info['h']/$info['w'];
  14898. }
  14899. if ($h + $extraheight > $maxHeight ) {
  14900. $h = $maxHeight - $extraheight;
  14901. $w=$h*$info['w']/$info['h'];
  14902. }
  14903. $height = $h + $extraheight;
  14904. $width = $w + $extrawidth;
  14905. $objattr['image_height'] = $h;
  14906. $objattr['image_width'] = $w;
  14907. $objattr['ID'] = $info['i'];
  14908. $texto = 'X';
  14909. break;
  14910. }
  14911. /*-- END IMAGES-CORE --*/
  14912. case 'BUTTON': // Draw a button
  14913. case 'SUBMIT':
  14914. case 'RESET':
  14915. $type = strtoupper($attr['TYPE']);
  14916. if ($type=='IMAGE') { $type = 'BUTTON'; } // src path not found
  14917. if (isset($attr['VALUE'])) {
  14918. $objattr['value'] = $attr['VALUE'];
  14919. }
  14920. else {
  14921. $objattr['value'] = ucfirst(strtolower($type));
  14922. }
  14923. $texto = " " . $objattr['value'] . " ";
  14924. $width = $this->GetStringWidth($texto) + ($this->form_element_spacing['button']['outer']['h']*2)+($this->form_element_spacing['button']['inner']['h']*2);
  14925. $height = $this->FontSize + ($this->form_element_spacing['button']['outer']['v']*2)+($this->form_element_spacing['button']['inner']['v']*2);
  14926. break;
  14927. case 'PASSWORD':
  14928. case 'TEXT':
  14929. default:
  14930. if ($type == '') { $type = 'TEXT'; }
  14931. if(strtoupper($attr['TYPE'])=='PASSWORD') { $type = 'PASSWORD'; }
  14932. if (isset($attr['VALUE'])) {
  14933. if ($type == 'PASSWORD') {
  14934. $num_stars = strlen($attr['VALUE']);
  14935. $texto = str_repeat('*',$num_stars);
  14936. }
  14937. else { $texto = $attr['VALUE']; }
  14938. }
  14939. $xw = ($this->form_element_spacing['input']['outer']['h']*2)+($this->form_element_spacing['input']['inner']['h']*2);
  14940. $xh = ($this->form_element_spacing['input']['outer']['v']*2)+($this->form_element_spacing['input']['inner']['v']*2);
  14941. if ($w) { $width = $w + $xw; }
  14942. else { $width = (20 * $spacesize) + $xw; } // Default width in chars
  14943. if (isset($attr['SIZE']) and ctype_digit($attr['SIZE']) ) $width = ($attr['SIZE'] * $spacesize) + $xw;
  14944. $height = $this->FontSize + $xh;
  14945. break;
  14946. }
  14947. $objattr['subtype'] = $type;
  14948. $objattr['text'] = $texto;
  14949. $objattr['width'] = $width;
  14950. $objattr['height'] = $height;
  14951. $e = "\xbb\xa4\xactype=input,objattr=".serialize($objattr)."\xbb\xa4\xac";
  14952. // Clear properties - tidy up
  14953. $properties = array();
  14954. /*-- TABLES --*/
  14955. // Output it to buffers
  14956. if ($this->tableLevel) {
  14957. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  14958. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  14959. }
  14960. else {
  14961. /*-- END TABLES --*/
  14962. $this->textbuffer[] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  14963. } // *TABLES*
  14964. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  14965. unset($this->InlineProperties[$tag]);
  14966. break; // END of INPUT
  14967. /*-- END FORMS --*/
  14968. // *********** GRAPH ********************
  14969. case 'JPGRAPH':
  14970. if (!$this->useGraphs) { break; }
  14971. if ($attr['TABLE']) { $gid = strtoupper($attr['TABLE']); }
  14972. else { $gid = '0'; }
  14973. if (!is_array($this->graphs[$gid]) || count($this->graphs[$gid])==0 ) { break; }
  14974. include_once(_MPDF_PATH.'graph.php');
  14975. $this->graphs[$gid]['attr'] = $attr;
  14976. // mPDF 4.0
  14977. if (isset($this->graphs[$gid]['attr']['WIDTH']) && $this->graphs[$gid]['attr']['WIDTH']) {
  14978. $this->graphs[$gid]['attr']['cWIDTH']=$this->ConvertSize($this->graphs[$gid]['attr']['WIDTH'],$pgwidth);
  14979. } // mm
  14980. if (isset($this->graphs[$gid]['attr']['HEIGHT']) && $this->graphs[$gid]['attr']['HEIGHT']) {
  14981. $this->graphs[$gid]['attr']['cHEIGHT']=$this->ConvertSize($this->graphs[$gid]['attr']['HEIGHT'],$pgwidth);
  14982. }
  14983. $graph_img = print_graph($this->graphs[$gid],$this->blk[$this->blklvl]['inner_width']);
  14984. if ($graph_img) {
  14985. // mPDF 4.3.016
  14986. if(isset($attr['ROTATE'])) {
  14987. if ($attr['ROTATE']==90 || $attr['ROTATE']==-90) {
  14988. $tmpw = $graph_img['w'];
  14989. $graph_img['w']= $graph_img['h'];
  14990. $graph_img['h']= $tmpw;
  14991. }
  14992. }
  14993. $attr['SRC'] = $graph_img['file'];
  14994. $attr['WIDTH'] = $graph_img['w'];
  14995. $attr['HEIGHT'] = $graph_img['h'];
  14996. }
  14997. else { break; }
  14998. // *********** IMAGE ********************
  14999. /*-- IMAGES-CORE --*/
  15000. case 'IMG':
  15001. if ($this->progressBar) { $this->UpdateProgressBar(1,'','IMG'); } // *PROGRESS-BAR*
  15002. $objattr = array();
  15003. $objattr['margin_top'] = 0;
  15004. $objattr['margin_bottom'] = 0;
  15005. $objattr['margin_left'] = 0;
  15006. $objattr['margin_right'] = 0;
  15007. // mPDF 4.0
  15008. $objattr['padding_top'] = 0;
  15009. $objattr['padding_bottom'] = 0;
  15010. $objattr['padding_left'] = 0;
  15011. $objattr['padding_right'] = 0;
  15012. $objattr['width'] = 0;
  15013. $objattr['height'] = 0;
  15014. $objattr['border_top']['w'] = 0;
  15015. $objattr['border_bottom']['w'] = 0;
  15016. $objattr['border_left']['w'] = 0;
  15017. $objattr['border_right']['w'] = 0;
  15018. if(isset($attr['SRC'])) {
  15019. $srcpath = $attr['SRC'];
  15020. $orig_srcpath = $attr['ORIG_SRC']; // mPDF 4.2.029
  15021. $properties = $this->MergeCSS('',$tag,$attr);
  15022. if(isset($properties ['DISPLAY']) && strtolower($properties ['DISPLAY'])=='none') {
  15023. return;
  15024. }
  15025. // VSPACE and HSPACE converted to margins in MergeCSS
  15026. if (isset($properties['MARGIN-TOP'])) { $objattr['margin_top']=$this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15027. if (isset($properties['MARGIN-BOTTOM'])) { $objattr['margin_bottom'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15028. if (isset($properties['MARGIN-LEFT'])) { $objattr['margin_left'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15029. if (isset($properties['MARGIN-RIGHT'])) { $objattr['margin_right'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15030. // mPDF 4.0
  15031. if (isset($properties['PADDING-TOP'])) { $objattr['padding_top']=$this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15032. if (isset($properties['PADDING-BOTTOM'])) { $objattr['padding_bottom'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15033. if (isset($properties['PADDING-LEFT'])) { $objattr['padding_left'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15034. if (isset($properties['PADDING-RIGHT'])) { $objattr['padding_right'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15035. if (isset($properties['BORDER-TOP'])) { $objattr['border_top'] = $this->border_details($properties['BORDER-TOP']); }
  15036. if (isset($properties['BORDER-BOTTOM'])) { $objattr['border_bottom'] = $this->border_details($properties['BORDER-BOTTOM']); }
  15037. if (isset($properties['BORDER-LEFT'])) { $objattr['border_left'] = $this->border_details($properties['BORDER-LEFT']); }
  15038. if (isset($properties['BORDER-RIGHT'])) { $objattr['border_right'] = $this->border_details($properties['BORDER-RIGHT']); }
  15039. if (isset($properties['VERTICAL-ALIGN'])) { $objattr['vertical-align'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15040. $w = 0;
  15041. $h = 0;
  15042. // mPDF 4.0
  15043. if(isset($properties['WIDTH'])) $w = $this->ConvertSize($properties['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15044. if(isset($properties['HEIGHT'])) $h = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15045. if(isset($attr['WIDTH'])) $w = $this->ConvertSize($attr['WIDTH'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15046. if(isset($attr['HEIGHT'])) $h = $this->ConvertSize($attr['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15047. if (isset($properties['OPACITY']) && $properties['OPACITY'] > 0 && $properties['OPACITY'] <= 1) { $objattr['opacity'] = $properties['OPACITY']; }
  15048. if ($this->HREF) { $objattr['link'] = $this->HREF; } // ? this isn't used
  15049. // mPDF 4.0
  15050. $extraheight = $objattr['padding_top'] + $objattr['padding_bottom'] + $objattr['margin_top'] + $objattr['margin_bottom'] + $objattr['border_top']['w'] + $objattr['border_bottom']['w'];
  15051. $extrawidth = $objattr['padding_left'] + $objattr['padding_right'] + $objattr['margin_left'] + $objattr['margin_right'] + $objattr['border_left']['w'] + $objattr['border_right']['w'];
  15052. // Image file
  15053. $info=$this->_getImage($srcpath, true, true, $orig_srcpath); // mPDF 4.2.029
  15054. if(!$info) {
  15055. $info = $this->_getImage($this->noImageFile);
  15056. if ($info) {
  15057. $srcpath = $this->noImageFile;
  15058. $w = ($info['w'] * (25.4/$this->dpi)); // mPDF 4.4.003
  15059. $h = ($info['h'] * (25.4/$this->dpi)); // mPDF 4.4.003
  15060. }
  15061. }
  15062. if(!$info) break;
  15063. // mPDF 4.3.016
  15064. if(isset($attr['ROTATE'])) {
  15065. if ($attr['ROTATE']==90 || $attr['ROTATE']==-90) {
  15066. $tmpw = $info['w'];
  15067. $info['w'] = $info['h'];
  15068. $info['h'] = $tmpw;
  15069. }
  15070. $objattr['ROTATE'] = $attr['ROTATE'];
  15071. }
  15072. $objattr['file'] = $srcpath;
  15073. //Default width and height calculation if needed
  15074. if($w==0 and $h==0) {
  15075. /*-- IMAGES-WMF --*/
  15076. if ($info['type']=='wmf') {
  15077. // WMF units are twips (1/20pt)
  15078. // divide by 20 to get points
  15079. // divide by k to get user units
  15080. $w = abs($info['w'])/(20*$this->k);
  15081. $h = abs($info['h']) / (20*$this->k);
  15082. }
  15083. else
  15084. /*-- END IMAGES-WMF --*/
  15085. // mPDF 4.3.013
  15086. if ($info['type']=='svg') {
  15087. // SVG units are pixels
  15088. $w = abs($info['w'])/$this->k;
  15089. $h = abs($info['h'])/$this->k;
  15090. }
  15091. else {
  15092. //Put image at default image dpi
  15093. $w=($info['w']/$this->k) * (72/$this->img_dpi);
  15094. $h=($info['h']/$this->k) * (72/$this->img_dpi);
  15095. }
  15096. }
  15097. // IF WIDTH OR HEIGHT SPECIFIED
  15098. if($w==0) $w=abs($h*$info['w']/$info['h']);
  15099. if($h==0) $h=abs($w*$info['h']/$info['w']);
  15100. // Resize to maximum dimensions of page
  15101. $maxWidth = $this->blk[$this->blklvl]['inner_width'];
  15102. $maxHeight = $this->h - ($this->tMargin + $this->bMargin + 10) ; // mPDF 4.1
  15103. if ($this->fullImageHeight) { $maxHeight = $this->fullImageHeight; } // mPDF 4.1
  15104. if ($w + $extrawidth > $maxWidth ) {
  15105. $w = $maxWidth - $extrawidth;
  15106. $h=abs($w*$info['h']/$info['w']);
  15107. }
  15108. if ($h + $extraheight > $maxHeight ) {
  15109. $h = $maxHeight - $extraheight;
  15110. $w=abs($h*$info['w']/$info['h']);
  15111. }
  15112. $objattr['type'] = 'image';
  15113. $objattr['itype'] = $info['type'];
  15114. $objattr['orig_h'] = $info['h'];
  15115. $objattr['orig_w'] = $info['w'];
  15116. /*-- IMAGES-WMF --*/
  15117. if ($info['type']=='wmf') {
  15118. $objattr['wmf_x'] = $info['x'];
  15119. $objattr['wmf_y'] = $info['y'];
  15120. }
  15121. else
  15122. /*-- END IMAGES-WMF --*/
  15123. // mPDF 4.3.013
  15124. if ($info['type']=='svg') {
  15125. $objattr['wmf_x'] = $info['x'];
  15126. $objattr['wmf_y'] = $info['y'];
  15127. }
  15128. $objattr['height'] = $h + $extraheight;
  15129. $objattr['width'] = $w + $extrawidth;
  15130. $objattr['image_height'] = $h;
  15131. $objattr['image_width'] = $w;
  15132. /*-- CSS-IMAGE-FLOAT --*/
  15133. if (!$this->ColActive && !$this->tableLevel && !$this->listlvl && !$this->kwt && !$this->keep_block_together) {
  15134. if (isset($properties['FLOAT']) && (strtoupper($properties['FLOAT']) == 'RIGHT' || strtoupper($properties['FLOAT']) == 'LEFT')) {
  15135. $objattr['float'] = substr(strtoupper($properties['FLOAT']),0,1);
  15136. }
  15137. }
  15138. /*-- END CSS-IMAGE-FLOAT --*/
  15139. $e = "\xbb\xa4\xactype=image,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15140. // Clear properties - tidy up
  15141. $properties = array();
  15142. /*-- TABLES --*/
  15143. // Output it to buffers
  15144. if ($this->tableLevel) {
  15145. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  15146. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ;
  15147. }
  15148. else {
  15149. /*-- END TABLES --*/
  15150. $this->textbuffer[] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  15151. } // *TABLES*
  15152. /*-- ANNOTATIONS --*/
  15153. if ($this->title2annots && isset($attr['TITLE'])) {
  15154. $objattr = array();
  15155. // mPDF 3.0
  15156. $objattr['margin_top'] = 0;
  15157. $objattr['margin_bottom'] = 0;
  15158. $objattr['margin_left'] = 0;
  15159. $objattr['margin_right'] = 0;
  15160. $objattr['width'] = 0;
  15161. $objattr['height'] = 0;
  15162. $objattr['border_top']['w'] = 0;
  15163. $objattr['border_bottom']['w'] = 0;
  15164. $objattr['border_left']['w'] = 0;
  15165. $objattr['border_right']['w'] = 0;
  15166. $objattr['CONTENT'] = $attr['TITLE'];
  15167. $objattr['type'] = 'annot';
  15168. $objattr['POS-X'] = 0;
  15169. $objattr['POS-Y'] = 0;
  15170. $objattr['ICON'] = 'Comment';
  15171. $objattr['AUTHOR'] = '';
  15172. $objattr['SUBJECT'] = '';
  15173. $objattr['OPACITY'] = $this->annotOpacity;
  15174. $objattr['COLOR'] = array(255,255,0);
  15175. $e = "\xbb\xa4\xactype=annot,objattr=".serialize($objattr)."\xbb\xa4\xac";
  15176. if($this->tableLevel) { // *TABLES*
  15177. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e); // *TABLES*
  15178. } // *TABLES*
  15179. else { // *TABLES*
  15180. $this->textbuffer[] = array($e);
  15181. } // *TABLES*
  15182. }
  15183. /*-- END ANNOTATIONS --*/
  15184. }
  15185. break;
  15186. /*-- END IMAGES-CORE --*/
  15187. /*-- TABLES --*/
  15188. case 'TABLE': // TABLE-BEGIN
  15189. $this->tdbegin = false;
  15190. $this->lastoptionaltag = '';
  15191. // Disable vertical justification in columns
  15192. if ($this->ColActive) { $this->colvAlign = ''; } // *COLUMNS*
  15193. if ($this->lastblocklevelchange == 1) { $blockstate = 1; } // Top margins/padding only
  15194. else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding
  15195. // called from block after new div e.g. <div> ... <table> ... Outputs block top margin/border and padding
  15196. if (count($this->textbuffer) == 0 && $this->lastblocklevelchange == 1 && !$this->tableLevel && !$this->kwt) {
  15197. $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,1,true); // true = newblock
  15198. $this->finishFlowingBlock(true); // true = END of flowing block
  15199. }
  15200. else if (!$this->tableLevel && count($this->textbuffer)) { $this->printbuffer($this->textbuffer,$blockstate); }
  15201. //else if (!$this->tableLevel) { $this->printbuffer($this->textbuffer,$blockstate); }
  15202. $this->textbuffer=array();
  15203. $this->lastblocklevelchange = -1;
  15204. if ($this->tableLevel) { // i.e. now a nested table coming...
  15205. // Save current level table
  15206. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['baseProperties']= $this->base_table_properties;
  15207. // $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['tablecascadeCSS'] = $this->tablecascadeCSS;
  15208. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = $this->cell;
  15209. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currrow'] = $this->row;
  15210. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currcol'] = $this->col;
  15211. }
  15212. $this->tableLevel++;
  15213. $this->tbCSSlvl++;
  15214. // mPDF 3.0
  15215. if (isset($this->tbctr[$this->tableLevel])) { $this->tbctr[$this->tableLevel]++; }
  15216. else { $this->tbctr[$this->tableLevel] = 1; }
  15217. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['level'] = $this->tableLevel;
  15218. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['levelid'] = $this->tbctr[$this->tableLevel];
  15219. if ($this->tableLevel > $this->innermostTableLevel) { $this->innermostTableLevel = $this->tableLevel; }
  15220. if ($this->tableLevel > 1) {
  15221. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nestedpos'] = array($this->row,$this->col,$this->tbctr[($this->tableLevel-1)]);
  15222. }
  15223. //++++++++++++++++++++++++++++
  15224. $this->cell = array();
  15225. $this->col=-1; //int
  15226. $this->row=-1; //int
  15227. $table = &$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]];
  15228. // mPDF 3.0
  15229. $table['bgcolor'] = false;
  15230. $table['va'] = false;
  15231. $table['txta'] = false;
  15232. $table['topntail'] = false;
  15233. $table['thead-underline'] = false;
  15234. $table['border'] = false;
  15235. $table['border_details']['R']['w'] = 0;
  15236. $table['border_details']['L']['w'] = 0;
  15237. $table['border_details']['T']['w'] = 0;
  15238. $table['border_details']['B']['w'] = 0;
  15239. $table['border_details']['R']['style'] = '';
  15240. $table['border_details']['L']['style'] = '';
  15241. $table['border_details']['T']['style'] = '';
  15242. $table['border_details']['B']['style'] = '';
  15243. $table['max_cell_border_width']['R'] = 0;
  15244. $table['max_cell_border_width']['L'] = 0;
  15245. $table['max_cell_border_width']['T'] = 0;
  15246. $table['max_cell_border_width']['B'] = 0;
  15247. $table['padding']['L'] = false;
  15248. $table['padding']['R'] = false;
  15249. $table['padding']['T'] = false;
  15250. $table['padding']['B'] = false;
  15251. $table['margin']['L'] = false;
  15252. $table['margin']['R'] = false;
  15253. $table['margin']['T'] = false;
  15254. $table['margin']['B'] = false;
  15255. $table['a'] = false;
  15256. $table['border_spacing_H'] = false;
  15257. $table['border_spacing_V'] = false;
  15258. $this->Reset();
  15259. $this->InlineProperties = array();
  15260. $this->spanlvl = 0;
  15261. $table['nc'] = $table['nr'] = 0;
  15262. $this->tablethead = 0;
  15263. $this->tabletfoot = 0;
  15264. $this->tabletheadjustfinished = false;
  15265. // mPDF 4.2
  15266. if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins && $this->tableLevel==1) { $lastbottommargin = $this->lastblockbottommargin; }
  15267. else { $lastbottommargin = 0; }
  15268. $this->lastblockbottommargin = 0;
  15269. $this->blockjustfinished=false;
  15270. if ($this->tableLevel==1) { $this->table_lineheight = $this->normalLineheight; } // mPDF 4.2
  15271. // mPDF 3.0
  15272. if ($this->tableLevel==1) { $this->tableheadernrows = 0; $this->tablefooternrows = 0; $this->usetableheader = false; } // mPDF 4.0
  15273. if ($this->tableLevel ==1) $this->base_table_properties = array();
  15274. // ADDED CSS FUNCIONS FOR TABLE
  15275. if ($this->tbCSSlvl==1) {
  15276. $properties = $this->MergeCSS('TOPTABLE',$tag,$attr);
  15277. }
  15278. else {
  15279. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  15280. }
  15281. $w = '';
  15282. if (isset($properties['WIDTH'])) { $w = $properties['WIDTH']; }
  15283. if (isset($properties['BACKGROUND-COLOR'])) { $table['bgcolor'][-1] = $properties['BACKGROUND-COLOR']; }
  15284. else if (isset($properties['BACKGROUND'])) { $table['bgcolor'][-1] = $properties['BACKGROUND']; }
  15285. if (isset($properties['VERTICAL-ALIGN'])) { $table['va'] = $align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15286. if (isset($properties['TEXT-ALIGN'])) { $table['txta'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  15287. if (isset($properties['AUTOSIZE']) && $properties['AUTOSIZE'] && $this->tableLevel ==1) {
  15288. $this->shrink_this_table_to_fit = $properties['AUTOSIZE'];
  15289. if ($this->shrink_this_table_to_fit < 1) { $this->shrink_this_table_to_fit = 0; }
  15290. }
  15291. if (isset($properties['ROTATE']) && $properties['ROTATE'] && $this->tableLevel ==1) {
  15292. $this->table_rotate = $properties['ROTATE'];
  15293. }
  15294. if (isset($properties['TOPNTAIL'])) { $table['topntail'] = $properties['TOPNTAIL']; }
  15295. if (isset($properties['THEAD-UNDERLINE'])) { $table['thead-underline'] = $properties['THEAD-UNDERLINE']; }
  15296. if (isset($properties['BORDER'])) {
  15297. $bord = $this->border_details($properties['BORDER']);
  15298. if ($bord['s']) {
  15299. $table['border'] = _BORDER_ALL;
  15300. $table['border_details']['R'] = $bord;
  15301. $table['border_details']['L'] = $bord;
  15302. $table['border_details']['T'] = $bord;
  15303. $table['border_details']['B'] = $bord;
  15304. }
  15305. }
  15306. if (isset($properties['BORDER-RIGHT'])) {
  15307. if ($this->directionality == 'rtl') { // *RTL*
  15308. $table['border_details']['R'] = $this->border_details($properties['BORDER-LEFT']); // *RTL*
  15309. } // *RTL*
  15310. else { // *RTL*
  15311. $table['border_details']['R'] = $this->border_details($properties['BORDER-RIGHT']);
  15312. } // *RTL*
  15313. $this->setBorder($table['border'], _BORDER_RIGHT, $table['border_details']['R']['s']);
  15314. }
  15315. if (isset($properties['BORDER-LEFT'])) {
  15316. if ($this->directionality == 'rtl') { // *RTL*
  15317. $table['border_details']['L'] = $this->border_details($properties['BORDER-RIGHT']); // *RTL*
  15318. } // *RTL*
  15319. else { // *RTL*
  15320. $table['border_details']['L'] = $this->border_details($properties['BORDER-LEFT']);
  15321. } // *RTL*
  15322. $this->setBorder($table['border'], _BORDER_LEFT, $table['border_details']['L']['s']);
  15323. }
  15324. if (isset($properties['BORDER-BOTTOM'])) {
  15325. $table['border_details']['B'] = $this->border_details($properties['BORDER-BOTTOM']);
  15326. $this->setBorder($table['border'], _BORDER_BOTTOM, $table['border_details']['B']['s']);
  15327. }
  15328. if (isset($properties['BORDER-TOP'])) {
  15329. $table['border_details']['T'] = $this->border_details($properties['BORDER-TOP']);
  15330. $this->setBorder($table['border'], _BORDER_TOP, $table['border_details']['T']['s']);
  15331. }
  15332. if ($table['border']){ // mPDF 4.3.007
  15333. $this->table_border_css_set = 1;
  15334. }
  15335. else {
  15336. $this->table_border_css_set = 0;
  15337. }
  15338. if (isset($properties['FONT-FAMILY'])) {
  15339. if (!$this->isCJK) {
  15340. $this->default_font = $properties['FONT-FAMILY'];
  15341. $this->SetFont($this->default_font,'',0,false);
  15342. $this->base_table_properties['FONT-FAMILY'] = $properties['FONT-FAMILY'];
  15343. }
  15344. }
  15345. if (isset($properties['FONT-SIZE'])) {
  15346. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/$this->k);
  15347. if ($mmsize) {
  15348. $this->default_font_size = $mmsize*($this->k);
  15349. $this->SetFontSize($this->default_font_size,false);
  15350. $this->base_table_properties['FONT-SIZE'] = $properties['FONT-SIZE'];
  15351. }
  15352. }
  15353. if (isset($properties['FONT-WEIGHT'])) {
  15354. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->base_table_properties['FONT-WEIGHT'] = 'BOLD'; }
  15355. }
  15356. if (isset($properties['FONT-STYLE'])) {
  15357. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->base_table_properties['FONT-STYLE'] = 'ITALIC'; }
  15358. }
  15359. if (isset($properties['COLOR'])) {
  15360. $this->base_table_properties['COLOR'] = $properties['COLOR'];
  15361. }
  15362. if (isset($properties['PADDING-LEFT'])) {
  15363. $table['padding']['L'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15364. }
  15365. if (isset($properties['PADDING-RIGHT'])) {
  15366. $table['padding']['R'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15367. }
  15368. if (isset($properties['PADDING-TOP'])) {
  15369. $table['padding']['T'] = $this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15370. }
  15371. if (isset($properties['PADDING-BOTTOM'])) {
  15372. $table['padding']['B'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15373. }
  15374. if (isset($properties['MARGIN-TOP'])) {
  15375. // mPDF 4.2 Collaspe vertical block margins
  15376. if ($lastbottommargin) {
  15377. $tmp = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15378. if ($tmp > $lastbottommargin) { $properties['MARGIN-TOP'] -= $lastbottommargin; }
  15379. else { $properties['MARGIN-TOP'] = 0; }
  15380. }
  15381. $table['margin']['T'] = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15382. }
  15383. if (isset($properties['MARGIN-BOTTOM'])) {
  15384. $table['margin']['B'] = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15385. }
  15386. if (isset($properties['MARGIN-LEFT'])) { // mPDF 4.2 Error corrected
  15387. $table['margin']['L'] = $this->ConvertSize($properties['MARGIN-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15388. }
  15389. if (isset($properties['MARGIN-RIGHT'])) { // mPDF 4.2 Error corrected
  15390. $table['margin']['R'] = $this->ConvertSize($properties['MARGIN-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15391. }
  15392. if (isset($properties['MARGIN-LEFT']) && isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-LEFT'])=='auto' && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  15393. $table['a'] = 'C';
  15394. }
  15395. else if (isset($properties['MARGIN-LEFT']) && strtolower($properties['MARGIN-LEFT'])=='auto') {
  15396. $table['a'] = 'R';
  15397. }
  15398. else if (isset($properties['MARGIN-RIGHT']) && strtolower($properties['MARGIN-RIGHT'])=='auto') {
  15399. $table['a'] = 'L';
  15400. }
  15401. // mPDF 4.2
  15402. if (isset($properties['LINE-HEIGHT']) && $this->tableLevel==1) {
  15403. $this->table_lineheight = $this->fixLineheight($properties['LINE-HEIGHT']);
  15404. if (!$this->table_lineheight) { $this->table_lineheight = $this->normalLineheight; }
  15405. }
  15406. if (isset($properties['BORDER-COLLAPSE']) && strtoupper($properties['BORDER-COLLAPSE'])=='SEPARATE') {
  15407. $table['borders_separate'] = true;
  15408. }
  15409. else {
  15410. $table['borders_separate'] = false;
  15411. }
  15412. if (isset($properties['BORDER-SPACING-H'])) {
  15413. $table['border_spacing_H'] = $this->ConvertSize($properties['BORDER-SPACING-H'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15414. }
  15415. if (isset($properties['BORDER-SPACING-V'])) {
  15416. $table['border_spacing_V'] = $this->ConvertSize($properties['BORDER-SPACING-V'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15417. }
  15418. if (isset($properties['EMPTY-CELLS'])) {
  15419. $table['empty_cells'] = strtolower($properties['EMPTY-CELLS']); // 'hide' or 'show'
  15420. }
  15421. else { $table['empty_cells'] = ''; }
  15422. if (isset($properties['PAGE-BREAK-INSIDE']) && strtoupper($properties['PAGE-BREAK-INSIDE'])=='AVOID' && $this->tableLevel==1) {
  15423. $this->table_keep_together = true;
  15424. }
  15425. else if ($this->tableLevel==1) {
  15426. $this->table_keep_together = false;
  15427. }
  15428. // mPDF 4.2
  15429. if (isset($properties['OVERFLOW'])) {
  15430. $table['overflow'] = strtolower($properties['OVERFLOW']); // 'hidden' 'wrap' or 'visible' or 'auto'
  15431. }
  15432. $properties = array();
  15433. if (!$table['borders_separate']) { $table['border_spacing_H'] = $table['border_spacing_V'] = 0; }
  15434. else if (isset($attr['CELLSPACING'])) {
  15435. $table['border_spacing_H'] = $table['border_spacing_V'] = $this->ConvertSize($attr['CELLSPACING'],$this->blk[$this->blklvl]['inner_width']);
  15436. }
  15437. if (isset($attr['CELLPADDING'])) {
  15438. $table['cell_padding'] = $attr['CELLPADDING'];
  15439. }
  15440. else {
  15441. $table['cell_padding'] = false;
  15442. }
  15443. if (isset($attr['BORDER'])) {
  15444. $this->table_border_attr_set = 1;
  15445. if ($attr['BORDER']=='1') {
  15446. $bord = $this->border_details('#000000 1px solid');
  15447. if ($bord['s']) {
  15448. $table['border'] = _BORDER_ALL;
  15449. $table['border_details']['R'] = $bord;
  15450. $table['border_details']['L'] = $bord;
  15451. $table['border_details']['T'] = $bord;
  15452. $table['border_details']['B'] = $bord;
  15453. }
  15454. }
  15455. }
  15456. else {
  15457. $this->table_border_attr_set = 0;
  15458. }
  15459. if (isset($attr['REPEAT_HEADER']) and $attr['REPEAT_HEADER'] == true) { $this->UseTableHeader(true); }
  15460. if (isset($attr['ALIGN'])) { $table['a'] = $align[strtolower($attr['ALIGN'])]; }
  15461. if (!$table['a']) { $table['a'] = $this->defaultTableAlign; } // mPDF 4.0
  15462. if (isset($attr['BGCOLOR'])) { $table['bgcolor'][-1] = $attr['BGCOLOR']; }
  15463. // mPDF 4.0 This does not work
  15464. // if (isset($attr['HEIGHT'])) { $table['h'] = $this->ConvertSize($attr['HEIGHT'],$this->blk[$this->blklvl]['inner_width']); }
  15465. if (isset($attr['WIDTH']) && $attr['WIDTH']) { $w = $attr['WIDTH']; }
  15466. if ($w) { // set here or earlier in $properties
  15467. $maxwidth = $this->blk[$this->blklvl]['inner_width'];
  15468. if ($table['borders_separate']) {
  15469. $tblblw = $table['margin']['L'] + $table['margin']['R'] + $table['border_details']['L']['w']/2 + $table['border_details']['R']['w']/2;
  15470. }
  15471. else {
  15472. $tblblw = $table['margin']['L'] + $table['margin']['R'] + $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2;
  15473. }
  15474. if (strpos($w,'%') && $this->tableLevel == 1 && !$this->ignore_table_percents ) {
  15475. // % needs to be of inner box without table margins etc.
  15476. $maxwidth -= $tblblw ;
  15477. $wmm = $this->ConvertSize($w,$maxwidth,$this->FontSize,false);
  15478. $table['w'] = $wmm + $tblblw ;
  15479. }
  15480. if (strpos($w,'%') && $this->tableLevel > 1 && !$this->ignore_table_percents && $this->keep_table_proportions) {
  15481. $table['wpercent'] = $w + 0; // makes 80% -> 80
  15482. }
  15483. if (!strpos($w,'%') && !$this->ignore_table_widths ) {
  15484. $wmm = $this->ConvertSize($w,$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15485. $table['w'] = $wmm + $tblblw ;
  15486. }
  15487. if (!$this->keep_table_proportions) {
  15488. if (isset($table['w']) && $table['w'] > $this->blk[$this->blklvl]['inner_width']) { $table['w'] = $this->blk[$this->blklvl]['inner_width']; }
  15489. }
  15490. }
  15491. if (isset($attr['AUTOSIZE']) && $this->tableLevel==1) {
  15492. $this->shrink_this_table_to_fit = $attr['AUTOSIZE'];
  15493. if ($this->shrink_this_table_to_fit < 1) { $this->shrink_this_table_to_fit = 1; }
  15494. }
  15495. if (isset($attr['ROTATE']) && $this->tableLevel==1) {
  15496. $this->table_rotate = $attr['ROTATE'];
  15497. }
  15498. //++++++++++++++++++++++++++++
  15499. // keeping block together on one page
  15500. // Autosize is now forced therefore keep block together disabled
  15501. if ($this->keep_block_together) {
  15502. $this->keep_block_together = 0;
  15503. $this->printdivbuffer();
  15504. $this->blk[$this->blklvl]['keep_block_together'] = 0;
  15505. }
  15506. if ($this->table_rotate) {
  15507. $this->tbrot_Links = array();
  15508. $this->tbrot_Annots = array();
  15509. // mPDF 3.0
  15510. $this->tbrot_Reference = array();
  15511. $this->tbrot_BMoutlines = array();
  15512. $this->tbrot_toc = array();
  15513. }
  15514. if ($this->kwt) {
  15515. if ($this->table_rotate) { $this->table_keep_together = true; }
  15516. $this->kwt = false;
  15517. $this->kwt_saved = true;
  15518. }
  15519. if ($this->tableLevel==1 && $this->useGraphs) {
  15520. if (isset($attr['ID']) && $attr['ID']) { $this->currentGraphId = strtoupper($attr['ID']); }
  15521. else { $this->currentGraphId = '0'; }
  15522. $this->graphs[$this->currentGraphId] = array();
  15523. }
  15524. //++++++++++++++++++++++++++++
  15525. $this->plainCell_properties = array();
  15526. break;
  15527. case 'THEAD':
  15528. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  15529. $this->tbCSSlvl++;
  15530. $this->tablethead = 1;
  15531. $this->UseTableHeader(true);
  15532. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  15533. if (isset($properties['FONT-WEIGHT'])) {
  15534. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->thead_font_weight = 'B'; }
  15535. else { $this->thead_font_weight = ''; }
  15536. }
  15537. if (isset($properties['FONT-STYLE'])) {
  15538. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->thead_font_style = 'I'; }
  15539. else { $this->thead_font_style = ''; }
  15540. }
  15541. if (isset($properties['VERTICAL-ALIGN'])) {
  15542. $this->thead_valign_default = $properties['VERTICAL-ALIGN'];
  15543. }
  15544. if (isset($properties['TEXT-ALIGN'])) {
  15545. $this->thead_textalign_default = $properties['TEXT-ALIGN'];
  15546. }
  15547. $properties = array();
  15548. break;
  15549. case 'TFOOT':
  15550. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  15551. $this->tbCSSlvl++;
  15552. // mPDF 4.0
  15553. $this->tabletfoot = 1;
  15554. // mPDF 3.0
  15555. $this->tablethead = 0;
  15556. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  15557. if (isset($properties['FONT-WEIGHT'])) {
  15558. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->tfoot_font_weight = 'B'; }
  15559. else { $this->tfoot_font_weight = ''; }
  15560. }
  15561. if (isset($properties['FONT-STYLE'])) {
  15562. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->tfoot_font_style = 'I'; }
  15563. else { $this->tfoot_font_style = ''; }
  15564. }
  15565. if (isset($properties['VERTICAL-ALIGN'])) {
  15566. $this->tfoot_valign_default = $properties['VERTICAL-ALIGN'];
  15567. }
  15568. if (isset($properties['TEXT-ALIGN'])) {
  15569. $this->tfoot_textalign_default = $properties['TEXT-ALIGN'];
  15570. }
  15571. $properties = array();
  15572. break;
  15573. case 'TBODY':
  15574. // mPDF 3.0
  15575. $this->tablethead = 0;
  15576. $this->tabletfoot = 0; // mPDF 4.0
  15577. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  15578. $this->tbCSSlvl++;
  15579. $this->MergeCSS('TABLE',$tag,$attr);
  15580. break;
  15581. case 'TR':
  15582. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  15583. $this->tbCSSlvl++;
  15584. $this->row++;
  15585. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr']++;
  15586. $this->col = -1;
  15587. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  15588. if (isset($properties['BACKGROUND-COLOR'])) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$this->row] = $properties['BACKGROUND-COLOR']; }
  15589. else if (isset($properties['BACKGROUND'])) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$this->row] = $properties['BACKGROUND']; }
  15590. if (isset($properties['TEXT-ROTATE'])) {
  15591. $this->trow_text_rotate = $properties['TEXT-ROTATE'];
  15592. }
  15593. if (isset($attr['TEXT-ROTATE'])) $this->trow_text_rotate = $attr['TEXT-ROTATE'];
  15594. if (isset($attr['BGCOLOR'])) $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['bgcolor'][$this->row] = $attr['BGCOLOR'];
  15595. if ($this->tablethead) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead'][$this->row] = true; }
  15596. // mPDF 4.0
  15597. if ($this->tabletfoot) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$this->row] = true; }
  15598. $properties = array();
  15599. break;
  15600. case 'TH':
  15601. case 'TD':
  15602. $this->ignorefollowingspaces = true;
  15603. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  15604. $this->tbCSSlvl++;
  15605. $this->InlineProperties = array();
  15606. $this->spanlvl = 0;
  15607. $this->tdbegin = true;
  15608. $this->col++;
  15609. while (isset($this->cell[$this->row][$this->col])) { $this->col++; }
  15610. //Update number column
  15611. 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; }
  15612. $this->cell[$this->row][$this->col] = array();
  15613. $this->cell[$this->row][$this->col]['text'] = array();
  15614. $this->cell[$this->row][$this->col]['s'] = 0 ;
  15615. $table = &$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]];
  15616. $cell = &$this->cell[$this->row][$this->col];
  15617. $cell['a'] = false;
  15618. $cell['R'] = false;
  15619. $cell['nowrap'] = false;
  15620. $cell['bgcolor'] = false; // mPDF 4.3.006
  15621. $cell['padding']['L'] = false;
  15622. $cell['padding']['R'] = false;
  15623. $cell['padding']['T'] = false;
  15624. $cell['padding']['B'] = false;
  15625. if ($this->simpleTables && $this->row==0 && $this->col==0){ // mPDF 4.2.017
  15626. $table['simple']['border'] = false;
  15627. $table['simple']['border_details']['R']['w'] = 0;
  15628. $table['simple']['border_details']['L']['w'] = 0;
  15629. $table['simple']['border_details']['T']['w'] = 0;
  15630. $table['simple']['border_details']['B']['w'] = 0;
  15631. $table['simple']['border_details']['R']['style'] = '';
  15632. $table['simple']['border_details']['L']['style'] = '';
  15633. $table['simple']['border_details']['T']['style'] = '';
  15634. $table['simple']['border_details']['B']['style'] = '';
  15635. }
  15636. else if (!$this->simpleTables) {
  15637. $cell['border'] = false;
  15638. $cell['border_details']['R']['w'] = 0;
  15639. $cell['border_details']['L']['w'] = 0;
  15640. $cell['border_details']['T']['w'] = 0;
  15641. $cell['border_details']['B']['w'] = 0;
  15642. $cell['border_details']['mbw']['BL'] = 0;
  15643. $cell['border_details']['mbw']['BR'] = 0;
  15644. $cell['border_details']['mbw']['RT'] = 0;
  15645. $cell['border_details']['mbw']['RB'] = 0;
  15646. $cell['border_details']['mbw']['TL'] = 0;
  15647. $cell['border_details']['mbw']['TR'] = 0;
  15648. $cell['border_details']['mbw']['LT'] = 0;
  15649. $cell['border_details']['mbw']['LB'] = 0;
  15650. $cell['border_details']['R']['style'] = '';
  15651. $cell['border_details']['L']['style'] = '';
  15652. $cell['border_details']['T']['style'] = '';
  15653. $cell['border_details']['B']['style'] = '';
  15654. $cell['border_details']['R']['s'] = 0;
  15655. $cell['border_details']['L']['s'] = 0;
  15656. $cell['border_details']['T']['s'] = 0;
  15657. $cell['border_details']['B']['s'] = 0;
  15658. $cell['border_details']['R']['c'] = array('R'=>0, 'G'=>0, 'B'=>0);
  15659. $cell['border_details']['L']['c'] = array('R'=>0, 'G'=>0, 'B'=>0);
  15660. $cell['border_details']['T']['c'] = array('R'=>0, 'G'=>0, 'B'=>0);
  15661. $cell['border_details']['B']['c'] = array('R'=>0, 'G'=>0, 'B'=>0);
  15662. $cell['border_details']['R']['dom'] = 0;
  15663. $cell['border_details']['L']['dom'] = 0;
  15664. $cell['border_details']['T']['dom'] = 0;
  15665. $cell['border_details']['B']['dom'] = 0;
  15666. }
  15667. // INHERITED TABLE PROPERTIES (or ROW for BGCOLOR)
  15668. // If cell bgcolor not set specifically, set to TR row bgcolor (if set)
  15669. // mPDF 4.3.006
  15670. if ((!$cell['bgcolor']) && isset($table['bgcolor'][$this->row])) {
  15671. $cell['bgcolor'] = $table['bgcolor'][$this->row];
  15672. }
  15673. else if (isset($table['bgcolor'][-1])) {
  15674. $cell['bgcolor'] = $table['bgcolor'][-1];
  15675. }
  15676. if ($table['va']) { $cell['va'] = $table['va']; }
  15677. if ($table['txta']) { $cell['a'] = $table['txta']; }
  15678. if ($this->table_border_attr_set) {
  15679. if ($table['border_details']) {
  15680. if (!$this->simpleTables){ // mPDF 4.2.017
  15681. $cell['border_details']['R'] = $table['border_details']['R'];
  15682. $cell['border_details']['L'] = $table['border_details']['L'];
  15683. $cell['border_details']['T'] = $table['border_details']['T'];
  15684. $cell['border_details']['B'] = $table['border_details']['B'];
  15685. $cell['border'] = $table['border'];
  15686. $cell['border_details']['L']['dom'] = 1;
  15687. $cell['border_details']['R']['dom'] = 1;
  15688. $cell['border_details']['T']['dom'] = 1;
  15689. $cell['border_details']['B']['dom'] = 1;
  15690. }
  15691. else if ($this->simpleTables && $this->row==0 && $this->col==0){
  15692. $table['simple']['border_details']['R'] = $table['border_details']['R'];
  15693. $table['simple']['border_details']['L'] = $table['border_details']['L'];
  15694. $table['simple']['border_details']['T'] = $table['border_details']['T'];
  15695. $table['simple']['border_details']['B'] = $table['border_details']['B'];
  15696. $table['simple']['border'] = $table['border'];
  15697. }
  15698. }
  15699. }
  15700. // INHERITED THEAD CSS Properties
  15701. if ($this->tablethead) {
  15702. if ($this->thead_valign_default) $cell['va'] = $align[strtolower($this->thead_valign_default)];
  15703. if ($this->thead_textalign_default) $cell['a'] = $align[strtolower($this->thead_textalign_default)];
  15704. if ($this->thead_font_weight == 'B') { $this->SetStyle('B',true); }
  15705. if ($this->thead_font_style == 'I') { $this->SetStyle('I',true); }
  15706. }
  15707. // INHERITED TFOOT CSS Properties
  15708. if ($this->tabletfoot) {
  15709. if ($this->tfoot_valign_default) $cell['va'] = $align[strtolower($this->tfoot_valign_default)];
  15710. if ($this->tfoot_textalign_default) $cell['a'] = $align[strtolower($this->tfoot_textalign_default)];
  15711. if ($this->tfoot_font_weight == 'B') { $this->SetStyle('B',true); }
  15712. if ($this->tfoot_font_style == 'I') { $this->SetStyle('I',true); }
  15713. }
  15714. if ($this->trow_text_rotate){ // mPDF 4.3.006
  15715. $cell['R'] = $this->trow_text_rotate;
  15716. }
  15717. $this->cell_border_dominance_L = 0;
  15718. $this->cell_border_dominance_R = 0;
  15719. $this->cell_border_dominance_T = 0;
  15720. $this->cell_border_dominance_B = 0;
  15721. $properties = $this->MergeCSS('TABLE',$tag,$attr);
  15722. $properties = $this->array_merge_recursive_unique($this->base_table_properties, $properties);
  15723. // mPDF 4.3.006
  15724. if (isset($properties['BACKGROUND-COLOR'])) { $cell['bgcolor'] = $properties['BACKGROUND-COLOR']; }
  15725. else if (isset($properties['BACKGROUND'])) { $cell['bgcolor'] = $properties['BACKGROUND']; }
  15726. /*-- GRADIENTS --*/
  15727. // mPDF 4.3.006
  15728. if (isset($properties['BACKGROUND-GRADIENT'])) { $cell['gradient'] = $properties['BACKGROUND-GRADIENT']; }
  15729. else { $cell['gradient'] = false; }
  15730. /*-- END GRADIENTS --*/
  15731. /*-- BACKGROUND-IMAGES --*/
  15732. // mPDF 4.3.006 / 4.3.011
  15733. if (isset($properties['BACKGROUND-IMAGE']) && $properties['BACKGROUND-IMAGE'] && !$this->ColActive && !$this->keep_block_together) {
  15734. $file = $properties['BACKGROUND-IMAGE'];
  15735. $sizesarray = $this->Image($file,0,0,0,0,'','',false, false, false, false, false); // mPDF 4.3.012D
  15736. if (isset($sizesarray['IMAGE_ID'])) {
  15737. $image_id = $sizesarray['IMAGE_ID'];
  15738. $orig_w = $sizesarray['WIDTH']*$this->k; // in user units i.e. mm
  15739. $orig_h = $sizesarray['HEIGHT']*$this->k; // (using $this->img_dpi)
  15740. $x_repeat = true;
  15741. $y_repeat = true;
  15742. if (isset($properties['BACKGROUND-REPEAT'])) {
  15743. if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-x') { $y_repeat = false; }
  15744. if ($properties['BACKGROUND-REPEAT']=='no-repeat' || $properties['BACKGROUND-REPEAT']=='repeat-y') { $x_repeat = false; }
  15745. }
  15746. $x_pos = 0;
  15747. $y_pos = 0;
  15748. if (isset($properties['BACKGROUND-POSITION'])) {
  15749. $ppos = preg_split('/\s+/',$properties['BACKGROUND-POSITION']);
  15750. $x_pos = $ppos[0];
  15751. $y_pos = $ppos[1];
  15752. if (!stristr($x_pos ,'%') ) { $x_pos = $this->ConvertSize($x_pos ,$this->blk[$this->blklvl]['inner_width'],$this->FontSize); }
  15753. if (!stristr($y_pos ,'%') ) { $y_pos = $this->ConvertSize($y_pos ,$this->blk[$this->blklvl]['inner_width'],$this->FontSize); }
  15754. }
  15755. // mPDF 4.3.015
  15756. if (isset($properties['BACKGROUND-IMAGE-RESIZE'])) { $resize = $properties['BACKGROUND-IMAGE-RESIZE']; }
  15757. else { $resize = 0; }
  15758. // mPDF 4.3.017
  15759. if (isset($properties['BACKGROUND-IMAGE-OPACITY'])) { $opacity = $properties['BACKGROUND-IMAGE-OPACITY']; }
  15760. else { $opacity = 0; }
  15761. $cell['background-image'] = 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); // mPDF 4.3.015 mPDF 4.3.017
  15762. }
  15763. }
  15764. /*-- END BACKGROUND-IMAGES --*/
  15765. if (isset($properties['VERTICAL-ALIGN'])) { $cell['va']=$align[strtolower($properties['VERTICAL-ALIGN'])]; }
  15766. if (isset($properties['TEXT-ALIGN'])) { $cell['a'] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  15767. if (isset($properties['TEXT-ROTATE']) && $properties['TEXT-ROTATE']){ // mPDF 4.3.006
  15768. $cell['R'] = $properties['TEXT-ROTATE'];
  15769. }
  15770. if (isset($properties['BORDER'])) {
  15771. $bord = $this->border_details($properties['BORDER']);
  15772. if ($bord['s']) {
  15773. if (!$this->simpleTables){ // mPDF 4.2.017
  15774. $cell['border'] = _BORDER_ALL;
  15775. $cell['border_details']['R'] = $bord;
  15776. $cell['border_details']['L'] = $bord;
  15777. $cell['border_details']['T'] = $bord;
  15778. $cell['border_details']['B'] = $bord;
  15779. $cell['border_details']['L']['dom'] = $this->cell_border_dominance_L;
  15780. $cell['border_details']['R']['dom'] = $this->cell_border_dominance_R;
  15781. $cell['border_details']['T']['dom'] = $this->cell_border_dominance_T;
  15782. $cell['border_details']['B']['dom'] = $this->cell_border_dominance_B;
  15783. }
  15784. else if ($this->simpleTables && $this->row==0 && $this->col==0){
  15785. $table['simple']['border'] = _BORDER_ALL;
  15786. $table['simple']['border_details']['R'] = $bord;
  15787. $table['simple']['border_details']['L'] = $bord;
  15788. $table['simple']['border_details']['T'] = $bord;
  15789. $table['simple']['border_details']['B'] = $bord;
  15790. }
  15791. }
  15792. }
  15793. if (!$this->simpleTables){ // mPDF 4.2.017
  15794. if (isset($properties['BORDER-RIGHT']) && $properties['BORDER-RIGHT']) {
  15795. $cell['border_details']['R'] = $this->border_details($properties['BORDER-RIGHT']);
  15796. $this->setBorder($cell['border'], _BORDER_RIGHT, $cell['border_details']['R']['s']);
  15797. $cell['border_details']['R']['dom'] = $this->cell_border_dominance_R;
  15798. }
  15799. if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) {
  15800. $cell['border_details']['L'] = $this->border_details($properties['BORDER-LEFT']);
  15801. $this->setBorder($cell['border'], _BORDER_LEFT, $cell['border_details']['L']['s']);
  15802. $cell['border_details']['L']['dom'] = $this->cell_border_dominance_L;
  15803. }
  15804. if (isset($properties['BORDER-BOTTOM']) && $properties['BORDER-BOTTOM']) {
  15805. $cell['border_details']['B'] = $this->border_details($properties['BORDER-BOTTOM']);
  15806. $this->setBorder($cell['border'], _BORDER_BOTTOM, $cell['border_details']['B']['s']);
  15807. $cell['border_details']['B']['dom'] = $this->cell_border_dominance_B;
  15808. }
  15809. if (isset($properties['BORDER-TOP']) && $properties['BORDER-TOP']) {
  15810. $cell['border_details']['T'] = $this->border_details($properties['BORDER-TOP']);
  15811. $this->setBorder($cell['border'], _BORDER_TOP, $cell['border_details']['T']['s']);
  15812. $cell['border_details']['T']['dom'] = $this->cell_border_dominance_T;
  15813. }
  15814. }
  15815. else if ($this->simpleTables && $this->row==0 && $this->col==0){
  15816. if (isset($properties['BORDER-LEFT']) && $properties['BORDER-LEFT']) {
  15817. $bord = $this->border_details($properties['BORDER-LEFT']);
  15818. if ($bord['s']) { $table['simple']['border'] = _BORDER_ALL; }
  15819. else { $table['simple']['border'] = 0; }
  15820. $table['simple']['border_details']['R'] = $bord;
  15821. $table['simple']['border_details']['L'] = $bord;
  15822. $table['simple']['border_details']['T'] = $bord;
  15823. $table['simple']['border_details']['B'] = $bord;
  15824. }
  15825. }
  15826. if ($this->simpleTables && $this->row==0 && $this->col==0 && !$table['borders_separate']){ // mPDF 4.2.017
  15827. $table['border_details'] = $table['simple']['border_details'];
  15828. $table['border'] = $table['simple']['border'];
  15829. }
  15830. // mPDF 4.3.009 Binary packed data
  15831. if ($this->packTableData && !$this->simpleTables) {
  15832. $cell['borderbin'] = $this->_packCellBorder($cell);
  15833. unset($cell['border']);
  15834. unset($cell['border_details']);
  15835. }
  15836. // mPDF 4.3.006
  15837. if (isset($properties['PADDING-LEFT'])) {
  15838. $cell['padding']['L'] = $this->ConvertSize($properties['PADDING-LEFT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15839. }
  15840. if (isset($properties['PADDING-RIGHT'])) {
  15841. $cell['padding']['R'] = $this->ConvertSize($properties['PADDING-RIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15842. }
  15843. if (isset($properties['PADDING-BOTTOM'])) {
  15844. $cell['padding']['B'] = $this->ConvertSize($properties['PADDING-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15845. }
  15846. if (isset($properties['PADDING-TOP'])) {
  15847. $cell['padding']['T'] = $this->ConvertSize($properties['PADDING-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15848. }
  15849. $w = '';
  15850. if (isset($properties['WIDTH'])) { $w = $properties['WIDTH']; }
  15851. if (isset($attr['WIDTH'])) { $w = $attr['WIDTH']; }
  15852. if ($w) {
  15853. if (strpos($w,'%') && !$this->ignore_table_percents ) { $cell['wpercent'] = $w + 0; } // makes 80% -> 80
  15854. else if (!strpos($w,'%') && !$this->ignore_table_widths ) { $cell['w'] = $this->ConvertSize($w,$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15855. }
  15856. // mPDF 4.0
  15857. if (isset($properties['HEIGHT'])) { $cell['h'] = $this->ConvertSize($properties['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false); }
  15858. if (isset($properties['COLOR'])) {
  15859. $cor = $this->ConvertColor($properties['COLOR']);
  15860. if ($cor) {
  15861. $this->colorarray = $cor;
  15862. $this->SetTextColor($cor['R'],$cor['G'],$cor['B']);
  15863. $this->issetcolor=true;
  15864. }
  15865. }
  15866. if (isset($properties['FONT-FAMILY'])) {
  15867. if (!$this->isCJK) {
  15868. $this->SetFont($properties['FONT-FAMILY'],'',0,false);
  15869. }
  15870. }
  15871. if (isset($properties['FONT-SIZE'])) {
  15872. $mmsize = $this->ConvertSize($properties['FONT-SIZE'],$this->default_font_size/$this->k);
  15873. if ($mmsize) {
  15874. $this->SetFontSize($mmsize*($this->k),false);
  15875. }
  15876. }
  15877. // mPDF 4.2
  15878. $cell['dfs'] = $this->FontSize; // Default Font size
  15879. if (isset($properties['FONT-WEIGHT'])) {
  15880. if (strtoupper($properties['FONT-WEIGHT']) == 'BOLD') { $this->SetStyle('B',true); }
  15881. }
  15882. if (isset($properties['FONT-STYLE'])) {
  15883. if (strtoupper($properties['FONT-STYLE']) == 'ITALIC') { $this->SetStyle('I',true); }
  15884. }
  15885. if (isset($properties['WHITE-SPACE'])) {
  15886. if (strtoupper($properties['WHITE-SPACE']) == 'NOWRAP') { $cell['nowrap']= 1; }
  15887. }
  15888. $properties = array();
  15889. if (isset($attr['HEIGHT'])) $cell['h'] = $this->ConvertSize($attr['HEIGHT'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  15890. if (isset($attr['ALIGN'])) $cell['a'] = $align[strtolower($attr['ALIGN'])];
  15891. if (isset($attr['VALIGN'])) $cell['va'] = $align[strtolower($attr['VALIGN'])];
  15892. // mPDF 4.3.006
  15893. if (isset($attr['BGCOLOR'])) $cell['bgcolor'] = $attr['BGCOLOR'];
  15894. $cs = $rs = 1;
  15895. if (isset($attr['COLSPAN']) && $attr['COLSPAN']>1) $cs = $cell['colspan'] = $attr['COLSPAN'];
  15896. if ($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] < $this->col+$cs) {
  15897. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nc'] = $this->col+$cs;
  15898. for($l=$this->col; $l < $this->col+$cs ;$l++) {
  15899. if ($l-$this->col) $this->cell[$this->row][$l] = 0;
  15900. }
  15901. }
  15902. if (isset($attr['ROWSPAN']) && $attr['ROWSPAN']>1) $rs = $cell['rowspan'] = $attr['ROWSPAN'];
  15903. for ($k=$this->row ; $k < $this->row+$rs ;$k++) {
  15904. for($l=$this->col; $l < $this->col+$cs ;$l++) {
  15905. if ($k-$this->row || $l-$this->col) $this->cell[$k][$l] = 0;
  15906. }
  15907. }
  15908. if (isset($attr['TEXT-ROTATE'])) { // mPDF 4.3.006
  15909. $cell['R'] = $attr['TEXT-ROTATE'];
  15910. }
  15911. if (isset($attr['NOWRAP']) && $attr['NOWRAP']) $cell['nowrap']= 1;
  15912. unset($cell );
  15913. break;
  15914. /*-- END TABLES --*/
  15915. /*-- LISTS --*/
  15916. // *********** LISTS ********************
  15917. case 'OL':
  15918. case 'UL':
  15919. $this->listjustfinished = false;
  15920. // mPDF 4.2
  15921. if ($this->blockjustfinished && !count($this->textbuffer) && $this->y != $this->tMargin && $this->collapseBlockMargins) { $lastbottommargin = $this->lastblockbottommargin; }
  15922. else { $lastbottommargin = 0; }
  15923. $this->lastblockbottommargin = 0;
  15924. $this->blockjustfinished=false;
  15925. // mPDF 3.0
  15926. $this->linebreakjustfinished=false;
  15927. $this->lastoptionaltag = ''; // Save current HTML specified optional endtag
  15928. $this->listCSSlvl++;
  15929. if((!$this->tableLevel) && ($this->listlvl == 0)) {
  15930. // mPDF 4.2
  15931. $blockstate = 0;
  15932. //if ($this->lastblocklevelchange == 1) { $blockstate = -1; } // Top margins/padding only
  15933. //else if ($this->lastblocklevelchange < 1) { $blockstate = 0; } // NO margins/padding
  15934. // called from block after new div e.g. <div> ... <ol> ... Outputs block top margin/border and padding
  15935. if (count($this->textbuffer) == 0 && $this->lastblocklevelchange == 1 && !$this->tableLevel && !$this->kwt) {
  15936. $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,1,true); // true = newblock
  15937. $this->finishFlowingBlock(true); // true = END of flowing block
  15938. }
  15939. else if (count($this->textbuffer)) { $this->printbuffer($this->textbuffer,$blockstate); }
  15940. $this->textbuffer=array();
  15941. $this->lastblocklevelchange = -1;
  15942. }
  15943. // ol and ul types are mixed here
  15944. if ($this->listlvl == 0) {
  15945. $this->list_indent = array();
  15946. $this->list_align = array();
  15947. $this->list_lineheight = array();
  15948. $this->InlineProperties['LIST'] = array();
  15949. $this->InlineProperties['LISTITEM'] = array();
  15950. }
  15951. /*-- TABLES --*/
  15952. // A simple list for inside a table
  15953. if($this->tableLevel) {
  15954. $this->list_indent[$this->listlvl] = 0; // mm default indent for each level
  15955. if ($tag == 'OL') $this->listtype = '1';
  15956. else if ($tag == 'UL') $this->listtype = 'disc';
  15957. if ($this->listlvl > 0) {
  15958. $this->listlist[$this->listlvl]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  15959. }
  15960. $this->listlvl++;
  15961. $this->listnum = 0; // reset
  15962. $this->listlist[$this->listlvl] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  15963. break;
  15964. }
  15965. /*-- END TABLES --*/
  15966. // mPDF 4.2.018
  15967. if ($this->PDFA && $tag == 'UL') {
  15968. if (!$this->PDFAauto) { $this->PDFAwarnings[] = "List bullets cannot use core font Zapfdingbats in PDFA1-b. (Substitute characters from current font used if available, otherwise substitutes hyphen '-')"; }
  15969. }
  15970. if ($this->listCSSlvl==1) {
  15971. $properties = $this->MergeCSS('TOPLIST',$tag,$attr);
  15972. }
  15973. else {
  15974. $properties = $this->MergeCSS('LIST',$tag,$attr);
  15975. }
  15976. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  15977. // List-type
  15978. // mPDF 4.0
  15979. $this->listtype = '';
  15980. if (isset($attr['TYPE']) && $attr['TYPE']) { $this->listtype = $attr['TYPE']; }
  15981. else if (isset($properties['LIST-STYLE-TYPE'])) {
  15982. // mPDF 4.0
  15983. $this->listtype = $this->_getListStyle($properties['LIST-STYLE-TYPE']);
  15984. }
  15985. else if (isset($properties['LIST-STYLE'])) {
  15986. // mPDF 4.0
  15987. $this->listtype = $this->_getListStyle($properties['LIST-STYLE']);
  15988. }
  15989. if (!$this->listtype) {
  15990. if ($tag == 'OL') $this->listtype = '1';
  15991. if ($tag == 'UL') {
  15992. // mPDF 4.0
  15993. if ($this->listlvl % 3 == 0) $this->listtype = 'disc';
  15994. elseif ($this->listlvl % 3 == 1) $this->listtype = 'circle';
  15995. else $this->listtype = 'square';
  15996. }
  15997. }
  15998. if ($this->listlvl == 0) {
  15999. $this->inherit_lineheight = 0;
  16000. $this->listlvl++; // first depth level
  16001. $this->listnum = 0; // reset
  16002. $occur = $this->listoccur[$this->listlvl] = 1;
  16003. $this->listlist[$this->listlvl][1] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  16004. }
  16005. else {
  16006. if (!empty($this->textbuffer))
  16007. {
  16008. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  16009. $this->listnum++;
  16010. }
  16011. // Save current lineheight to inherit
  16012. $this->textbuffer = array();
  16013. $occur = $this->listoccur[$this->listlvl];
  16014. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  16015. $this->listlvl++;
  16016. $this->listnum = 0; // reset
  16017. // mPDF 3.0
  16018. if (!isset($this->listoccur[$this->listlvl]) || $this->listoccur[$this->listlvl] == 0) $this->listoccur[$this->listlvl] = 1;
  16019. else $this->listoccur[$this->listlvl]++;
  16020. $occur = $this->listoccur[$this->listlvl];
  16021. $this->listlist[$this->listlvl][$occur] = array('TYPE'=>$this->listtype,'MAXNUM'=>$this->listnum);
  16022. }
  16023. // TOP LEVEL ONLY
  16024. if ($this->listlvl == 1) {
  16025. if (isset($properties['MARGIN-TOP'])) {
  16026. // mPDF 4.2 Collaspe vertical block margins
  16027. if ($lastbottommargin) {
  16028. $tmp = $this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16029. if ($tmp > $lastbottommargin) { $properties['MARGIN-TOP'] -= $lastbottommargin; }
  16030. else { $properties['MARGIN-TOP'] = 0; }
  16031. }
  16032. $this->DivLn($this->ConvertSize($properties['MARGIN-TOP'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false),$this->blklvl,true,1); // collapsible
  16033. }
  16034. if (isset($properties['MARGIN-BOTTOM'])) {
  16035. $this->list_margin_bottom = $this->ConvertSize($properties['MARGIN-BOTTOM'],$this->blk[$this->blklvl]['inner_width'],$this->FontSize,false);
  16036. }
  16037. // mPDF 4.0
  16038. if (isset($this->blk[$this->blklvl]['line_height'])) {
  16039. $this->list_lineheight[$this->listlvl][$occur] = $this->blk[$this->blklvl]['line_height'];
  16040. }
  16041. }
  16042. $this->list_indent[$this->listlvl][$occur] = 5; // mm default indent for each level
  16043. 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); }
  16044. if (isset($properties['TEXT-ALIGN'])) { $this->list_align[$this->listlvl][$occur] = $align[strtolower($properties['TEXT-ALIGN'])]; }
  16045. // mPDF 4.0
  16046. if (isset($properties['LINE-HEIGHT'])) {
  16047. $this->list_lineheight[$this->listlvl][$occur] = $this->fixLineheight($properties['LINE-HEIGHT']);
  16048. }
  16049. // mPDF 4.2 Inherit
  16050. else if ($this->listlvl>1 && isset($this->list_lineheight[($this->listlvl - 1)][1])) {
  16051. $this->list_lineheight[$this->listlvl][$occur] = end($this->list_lineheight[($this->listlvl - 1)]);
  16052. }
  16053. if (!isset($this->list_lineheight[$this->listlvl][$occur]) || !$this->list_lineheight[$this->listlvl][$occur]) {
  16054. $this->list_lineheight[$this->listlvl][$occur] = $this->normalLineheight; // mPDF 4.2
  16055. }
  16056. $this->InlineProperties['LIST'][$this->listlvl][$occur] = $this->saveInlineProperties();
  16057. $properties = array();
  16058. break;
  16059. case 'LI':
  16060. // Start Block
  16061. $this->lastoptionaltag = $tag; // Save current HTML specified optional endtag
  16062. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  16063. /*-- TABLES --*/
  16064. // A simple list for inside a table
  16065. if($this->tableLevel) {
  16066. $this->blockjustfinished=false;
  16067. // If already something in the Cell
  16068. 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 ) {
  16069. $this->cell[$this->row][$this->col]['textbuffer'][] = array("\n",$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  16070. $this->cell[$this->row][$this->col]['text'][] = "\n";
  16071. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  16072. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  16073. }
  16074. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  16075. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  16076. }
  16077. $this->cell[$this->row][$this->col]['s'] = 0 ;
  16078. }
  16079. if ($this->listlvl == 0) { //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...)
  16080. $this->listlvl++; // first depth level
  16081. $this->listnum = 0; // reset
  16082. $this->listlist[$this->listlvl] = array('TYPE'=>'disc','MAXNUM'=>$this->listnum);
  16083. }
  16084. $this->listnum++;
  16085. switch($this->listlist[$this->listlvl]['TYPE']) {
  16086. case 'A':
  16087. $blt = $this->dec2alpha($this->listnum,true).$this->list_number_suffix;
  16088. break;
  16089. case 'a':
  16090. $blt = $this->dec2alpha($this->listnum,false).$this->list_number_suffix;
  16091. break;
  16092. case 'I':
  16093. $blt = $this->dec2roman($this->listnum,true).$this->list_number_suffix;
  16094. break;
  16095. case 'i':
  16096. $blt = $this->dec2roman($this->listnum,false).$this->list_number_suffix;
  16097. break;
  16098. case '1':
  16099. $blt = $this->listnum.$this->list_number_suffix;
  16100. break;
  16101. default:
  16102. // mPDF 4.2
  16103. if ($this->listlvl % 3 == 1 && isset($this->CurrentFont['cw'][8226])) { $blt = "\xe2\x80\xa2"; } // &#8226;
  16104. else if ($this->listlvl % 3 == 2 && isset($this->CurrentFont['cw'][9900])) { $blt = "\xe2\x9a\xac"; } // &#9900;
  16105. else if ($this->listlvl % 3 == 0 && isset($this->CurrentFont['cw'][9642])) { $blt = "\xe2\x96\xaa"; } // &#9642;
  16106. else { $blt = '-'; }
  16107. break;
  16108. }
  16109. /*-- UNICODE-FONTS --*/
  16110. // mPDF 3.0 - change to &nbsp; spaces
  16111. if ($this->is_MB) {
  16112. $ls = str_repeat("\xc2\xa0\xc2\xa0",($this->listlvl-1)*2) . $blt . ' ';
  16113. }
  16114. else {
  16115. /*-- END UNICODE-FONTS --*/
  16116. $ls = str_repeat(chr(160).chr(160),($this->listlvl-1)*2) . $blt . ' ';
  16117. /*-- UNICODE-FONTS --*/
  16118. }
  16119. /*-- END UNICODE-FONTS --*/
  16120. $this->cell[$this->row][$this->col]['textbuffer'][] = array($ls,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  16121. $this->cell[$this->row][$this->col]['text'][] = $ls;
  16122. $this->cell[$this->row][$this->col]['s'] += $this->GetStringWidth($ls);
  16123. break;
  16124. }
  16125. /*-- END TABLES --*/
  16126. //Observation: </LI> is ignored
  16127. if ($this->listlvl == 0) { //in case of malformed HTML code. Example:(...)</p><li>Content</li><p>Paragraph1</p>(...)
  16128. //First of all, skip a line
  16129. $this->listlvl++; // first depth level
  16130. $this->listnum = 0; // reset
  16131. $this->listoccur[$this->listlvl] = 1;
  16132. $this->listlist[$this->listlvl][1] = array('TYPE'=>'disc','MAXNUM'=>$this->listnum);
  16133. }
  16134. if ($this->listnum == 0) {
  16135. $this->listnum++;
  16136. $this->textbuffer = array();
  16137. }
  16138. else {
  16139. if (!empty($this->textbuffer)) {
  16140. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  16141. $this->listnum++;
  16142. }
  16143. $this->textbuffer = array();
  16144. }
  16145. $this->listCSSlvl++;
  16146. $properties = $this->MergeCSS('LIST',$tag,$attr);
  16147. if (!empty($properties)) $this->setCSS($properties,'INLINE');
  16148. $this->InlineProperties['LISTITEM'][$this->listlvl][$this->listoccur[$this->listlvl]][$this->listnum] = $this->saveInlineProperties();
  16149. // List-type
  16150. if (isset($attr['TYPE']) && $attr['TYPE']) { $this->listitemtype = $attr['TYPE']; }
  16151. else if (isset($properties['LIST-STYLE-TYPE'])) {
  16152. // mPDF 4.0
  16153. $this->listitemtype = $this->_getListStyle($properties['LIST-STYLE-TYPE']);
  16154. }
  16155. else if (isset($properties['LIST-STYLE'])) {
  16156. // mPDF 4.0
  16157. $this->listitemtype = $this->_getListStyle($properties['LIST-STYLE']);
  16158. }
  16159. else $this->listitemtype = '';
  16160. break;
  16161. /*-- END LISTS --*/
  16162. }//end of switch
  16163. }
  16164. /*-- LISTS --*/
  16165. // mPDF 4.0
  16166. function _getListStyle($ls) {
  16167. if (stristr($ls,'disc')) { return 'disc'; }
  16168. else if (stristr($ls,'circle')) { return 'circle'; }
  16169. else if (stristr($ls,'square')) { return 'square'; }
  16170. else if (stristr($ls,'decimal')) { return '1'; }
  16171. else if (stristr($ls,'lower-roman')) { return 'i'; }
  16172. else if (stristr($ls,'upper-roman')) { return 'I'; }
  16173. else if (stristr($ls,'lower-latin')|| stristr($ls,'lower-alpha')) { return 'a'; }
  16174. else if (stristr($ls,'upper-latin') || stristr($ls,'upper-alpha')) { return 'A'; }
  16175. else if (stristr($ls,'none')) { return 'none'; }
  16176. else { return ''; }
  16177. }
  16178. /*-- END LISTS --*/
  16179. function CloseTag($tag)
  16180. {
  16181. $this->ignorefollowingspaces = false; //Eliminate exceeding left-side spaces
  16182. //Closing tag
  16183. if($tag=='OPTION') { $this->selectoption['ACTIVE'] = false; $this->lastoptionaltag = ''; }
  16184. if($tag=='TTS' or $tag=='TTA' or $tag=='TTZ') {
  16185. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16186. unset($this->InlineProperties[$tag]);
  16187. $ltag = strtolower($tag);
  16188. $this->$ltag = false;
  16189. }
  16190. if($tag=='FONT' || $tag=='SPAN' || $tag=='CODE' || $tag=='KBD' || $tag=='SAMP' || $tag=='TT' || $tag=='VAR'
  16191. || $tag=='INS' || $tag=='STRONG' || $tag=='CITE' || $tag=='SUB' || $tag=='SUP' || $tag=='S' || $tag=='STRIKE' || $tag=='DEL'
  16192. || $tag=='Q' || $tag=='EM' || $tag=='B' || $tag=='I' || $tag=='U' | $tag=='SMALL' || $tag=='BIG' || $tag=='ACRONYM') {
  16193. if ($tag == 'SPAN') {
  16194. if (isset($this->InlineProperties['SPAN'][$this->spanlvl]) && $this->InlineProperties['SPAN'][$this->spanlvl]) { $this->restoreInlineProperties($this->InlineProperties['SPAN'][$this->spanlvl]); }
  16195. unset($this->InlineProperties['SPAN'][$this->spanlvl]);
  16196. if (isset($this->InlineAnnots['SPAN'][$this->spanlvl]) && $this->InlineAnnots['SPAN'][$this->spanlvl]) { $annot = $this->InlineAnnots['SPAN'][$this->spanlvl]; } // *ANNOTATIONS*
  16197. unset($this->InlineAnnots['SPAN'][$this->spanlvl]); // *ANNOTATIONS*
  16198. $this->spanlvl--;
  16199. }
  16200. else {
  16201. if (isset($this->InlineProperties[$tag]) && $this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16202. unset($this->InlineProperties[$tag]);
  16203. if (isset($this->InlineAnnots[$tag]) && $this->InlineAnnots[$tag]) { $annot = $this->InlineAnnots[$tag]; } // *ANNOTATIONS*
  16204. unset($this->InlineAnnots[$tag]); // *ANNOTATIONS*
  16205. }
  16206. /*-- ANNOTATIONS --*/
  16207. if (isset($annot)) {
  16208. if($this->tableLevel) { // *TABLES*
  16209. $this->cell[$this->row][$this->col]['textbuffer'][] = array($annot); // *TABLES*
  16210. } // *TABLES*
  16211. else { // *TABLES*
  16212. $this->textbuffer[] = array($annot);
  16213. } // *TABLES*
  16214. }
  16215. /*-- END ANNOTATIONS --*/
  16216. }
  16217. if($tag=='A') {
  16218. $this->HREF='';
  16219. if (isset($this->InlineProperties['A'])) { $this->restoreInlineProperties($this->InlineProperties['A']); }
  16220. unset($this->InlineProperties['A']);
  16221. }
  16222. /*-- FORMS --*/
  16223. // *********** FORM ELEMENTS ********************
  16224. if($tag=='TEXTAREA') {
  16225. $this->specialcontent = '';
  16226. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16227. unset($this->InlineProperties[$tag]);
  16228. }
  16229. if($tag=='SELECT') {
  16230. $this->lastoptionaltag = '';
  16231. $texto = '';
  16232. if (isset($this->selectoption['SELECTED'])) { $texto = $this->selectoption['SELECTED']; }
  16233. $w = $this->GetStringWidth($texto);
  16234. if ($w == 0) { $w = 5; }
  16235. $objattr['type'] = 'select'; // need to add into objattr
  16236. $objattr['text'] = $texto;
  16237. // mPDD 1.4 Active Forms
  16238. if (isset($this->selectoption['NAME'])) { $objattr['name'] = $this->selectoption['NAME']; }
  16239. if (isset($this->selectoption['ITEMS'])) { $objattr['items'] = $this->selectoption['ITEMS']; }
  16240. if (isset($this->selectoption['MULTIPLE'])) { $objattr['multiple'] = $this->selectoption['MULTIPLE']; }
  16241. if (isset($this->selectoption['DISABLED'])) { $objattr['disabled'] = $this->selectoption['DISABLED']; }
  16242. if (isset($this->selectoption['TITLE'])) { $objattr['title'] = $this->selectoption['TITLE']; }
  16243. if (isset($this->selectoption['COLOR'])) { $objattr['color'] = $this->selectoption['COLOR']; }
  16244. if (isset($this->selectoption['SIZE'])) { $objattr['size'] = $this->selectoption['SIZE']; }
  16245. if (isset($objattr['size']) && $objattr['size']>1) { $rows=$objattr['size']; } else { $rows = 1; }
  16246. $objattr['fontfamily'] = $this->FontFamily;
  16247. $objattr['fontsize'] = $this->FontSizePt;
  16248. $objattr['width'] = $w + ($this->form_element_spacing['select']['outer']['h']*2)+($this->form_element_spacing['select']['inner']['h']*2) + ($this->FontSize*1.4);
  16249. $objattr['height'] = ($this->FontSize*$rows) + ($this->form_element_spacing['select']['outer']['v']*2)+($this->form_element_spacing['select']['inner']['v']*2);
  16250. $e = "\xbb\xa4\xactype=select,objattr=".serialize($objattr)."\xbb\xa4\xac";
  16251. // Clear properties - tidy up
  16252. $properties = array();
  16253. // Output it to buffers
  16254. if ($this->tableLevel) { // *TABLES*
  16255. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle); // *TABLES*
  16256. $this->cell[$this->row][$this->col]['s'] += $objattr['width'] ; // *TABLES*
  16257. } // *TABLES*
  16258. else { // *TABLES*
  16259. $this->textbuffer[] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  16260. } // *TABLES*
  16261. $this->selectoption = array();
  16262. $this->specialcontent = '';
  16263. if ($this->InlineProperties[$tag]) { $this->restoreInlineProperties($this->InlineProperties[$tag]); }
  16264. unset($this->InlineProperties[$tag]);
  16265. }
  16266. /*-- END FORMS --*/
  16267. // *********** BLOCKS ********************
  16268. if($tag=='P' || $tag=='DIV' || $tag=='H1' || $tag=='H2' || $tag=='H3' || $tag=='H4' || $tag=='H5' || $tag=='H6' || $tag=='PRE'
  16269. || $tag=='FORM' || $tag=='ADDRESS' || $tag=='BLOCKQUOTE' || $tag=='CENTER' || $tag=='DT' || $tag=='DD' || $tag=='DL' ) {
  16270. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  16271. $this->blockjustfinished=true;
  16272. // mPDF 4.2
  16273. $this->lastblockbottommargin = $this->blk[$this->blklvl]['margin_bottom'];
  16274. /*-- LISTS --*/
  16275. // mPDF 4.0
  16276. if ($this->listlvl>0) { return; }
  16277. /*-- END LISTS --*/
  16278. /*-- TABLES --*/
  16279. if($this->tableLevel) {
  16280. // mPDF 3.0
  16281. if ($this->linebreakjustfinished) { $this->blockjustfinished=false; }
  16282. // mPDF 4.0
  16283. if (isset($this->InlineProperties['BLOCKINTABLE'])) {
  16284. if ($this->InlineProperties['BLOCKINTABLE']) { $this->restoreInlineProperties($this->InlineProperties['BLOCKINTABLE']); }
  16285. unset($this->InlineProperties['BLOCKINTABLE']);
  16286. }
  16287. return;
  16288. }
  16289. /*-- END TABLES --*/
  16290. $this->lastoptionaltag = '';
  16291. $this->divbegin=false;
  16292. // mPDF 3.0
  16293. $this->linebreakjustfinished=false;
  16294. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  16295. /*-- CSS-FLOAT --*/
  16296. // If float contained in a float, need to extend bottom to allow for it
  16297. $currpos = $this->page*1000 + $this->y;
  16298. if (isset($this->blk[$this->blklvl]['float_endpos']) && $this->blk[$this->blklvl]['float_endpos'] > $currpos) {
  16299. $old_page = $this->page;
  16300. $new_page = intval($this->blk[$this->blklvl]['float_endpos'] /1000);
  16301. if ($old_page != $new_page) {
  16302. $s = $this->PrintPageBackgrounds();
  16303. // Writes after the marker so not overwritten later by page background etc.
  16304. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  16305. $this->pageBackgrounds = array();
  16306. $this->page = $new_page;
  16307. $this->ResetMargins();
  16308. $this->Reset();
  16309. $this->pageoutput[$this->page] = array();
  16310. }
  16311. $this->y = (($this->blk[$this->blklvl]['float_endpos'] *1000) % 1000000)/1000; // mod changes operands to integers before processing
  16312. }
  16313. /*-- END CSS-FLOAT --*/
  16314. //Print content
  16315. if ($this->lastblocklevelchange == 1) { $blockstate = 3; } // Top & bottom margins/padding
  16316. else if ($this->lastblocklevelchange == -1) { $blockstate = 2; } // Bottom margins/padding only
  16317. else { $blockstate = 0; } // mPDF 3.0
  16318. // called from after e.g. </table> </div> </div> ... Outputs block margin/border and padding
  16319. if (count($this->textbuffer) && $this->textbuffer[count($this->textbuffer)-1]) {
  16320. // mPDF 3.0 ...as long as not special content
  16321. if (substr($this->textbuffer[count($this->textbuffer)-1][0],0,3) != "\xbb\xa4\xac") { // not special content
  16322. if ($this->is_MB) { // *UNICODE-FONTS*
  16323. $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/[ ]+$/u', '', $this->textbuffer[count($this->textbuffer)-1][0]); // *UNICODE-FONTS*
  16324. } // *UNICODE-FONTS*
  16325. else { // *UNICODE-FONTS*
  16326. $this->textbuffer[count($this->textbuffer)-1][0] = preg_replace('/[ ]+$/', '', $this->textbuffer[count($this->textbuffer)-1][0]);
  16327. } // *UNICODE-FONTS*
  16328. }
  16329. }
  16330. if (count($this->textbuffer) == 0 && $this->lastblocklevelchange != 0) {
  16331. $this->newFlowingBlock( $this->blk[$this->blklvl]['width'],$this->lineheight,'',false,false,2,true); // true = newblock
  16332. $this->finishFlowingBlock(true); // true = END of flowing block
  16333. $this->PaintDivBB('',$blockstate);
  16334. }
  16335. else {
  16336. $this->printbuffer($this->textbuffer,$blockstate);
  16337. }
  16338. $this->textbuffer=array();
  16339. if ($this->blk[$this->blklvl]['keep_block_together']) {
  16340. $this->printdivbuffer();
  16341. }
  16342. if ($this->kwt) {
  16343. $this->kwt_height = $this->y - $this->kwt_y0;
  16344. }
  16345. /*-- CSS-IMAGE-FLOAT --*/
  16346. $this->printfloatbuffer();
  16347. /*-- END CSS-IMAGE-FLOAT --*/
  16348. if($tag=='PRE') { $this->ispre=false; }
  16349. /*-- CSS-FLOAT --*/
  16350. if ($this->blk[$this->blklvl]['float'] == 'R') {
  16351. // If width not set, here would need to adjust and output buffer
  16352. $s = $this->PrintPageBackgrounds();
  16353. // Writes after the marker so not overwritten later by page background etc.
  16354. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  16355. $this->pageBackgrounds = array();
  16356. $this->Reset();
  16357. $this->pageoutput[$this->page] = array();
  16358. for($i=($this->blklvl-1); $i >= 0; $i--) {
  16359. if (isset($this->blk[$i]['float_endpos'])) { $this->blk[$i]['float_endpos'] = max($this->blk[$i]['float_endpos'], ($this->page*1000 + $this->y)); }
  16360. else { $this->blk[$i]['float_endpos'] = $this->page*1000 + $this->y; }
  16361. }
  16362. $this->floatDivs[] = array(
  16363. 'side'=>'R',
  16364. 'startpage'=>$this->blk[$this->blklvl]['startpage'] ,
  16365. 'y0'=>$this->blk[$this->blklvl]['float_start_y'] ,
  16366. 'startpos'=> ($this->blk[$this->blklvl]['startpage']*1000 + $this->blk[$this->blklvl]['float_start_y']),
  16367. 'endpage'=>$this->page ,
  16368. 'y1'=>$this->y ,
  16369. 'endpos'=> ($this->page*1000 + $this->y),
  16370. 'w'=> $this->blk[$this->blklvl]['float_width'],
  16371. 'blklvl'=>$this->blklvl,
  16372. 'blockContext' => $this->blk[$this->blklvl-1]['blockContext']
  16373. );
  16374. $this->y = $this->blk[$this->blklvl]['float_start_y'] ;
  16375. $this->page = $this->blk[$this->blklvl]['startpage'] ;
  16376. $this->ResetMargins();
  16377. $this->pageoutput[$this->page] = array();
  16378. }
  16379. if ($this->blk[$this->blklvl]['float'] == 'L') {
  16380. // If width not set, here would need to adjust and output buffer
  16381. $s = $this->PrintPageBackgrounds();
  16382. // Writes after the marker so not overwritten later by page background etc.
  16383. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', '\\1'."\n".$s."\n", $this->pages[$this->page]);
  16384. $this->pageBackgrounds = array();
  16385. $this->Reset();
  16386. $this->pageoutput[$this->page] = array();
  16387. for($i=($this->blklvl-1); $i >= 0; $i--) {
  16388. if (isset($this->blk[$i]['float_endpos'])) { $this->blk[$i]['float_endpos'] = max($this->blk[$i]['float_endpos'], ($this->page*1000 + $this->y)); }
  16389. else { $this->blk[$i]['float_endpos'] = $this->page*1000 + $this->y; }
  16390. }
  16391. $this->floatDivs[] = array(
  16392. 'side'=>'L',
  16393. 'startpage'=>$this->blk[$this->blklvl]['startpage'] ,
  16394. 'y0'=>$this->blk[$this->blklvl]['float_start_y'] ,
  16395. 'startpos'=> ($this->blk[$this->blklvl]['startpage']*1000 + $this->blk[$this->blklvl]['float_start_y']),
  16396. 'endpage'=>$this->page ,
  16397. 'y1'=>$this->y ,
  16398. 'endpos'=> ($this->page*1000 + $this->y),
  16399. 'w'=> $this->blk[$this->blklvl]['float_width'],
  16400. 'blklvl'=>$this->blklvl,
  16401. 'blockContext' => $this->blk[$this->blklvl-1]['blockContext']
  16402. );
  16403. $this->y = $this->blk[$this->blklvl]['float_start_y'] ;
  16404. $this->page = $this->blk[$this->blklvl]['startpage'] ;
  16405. $this->ResetMargins();
  16406. $this->pageoutput[$this->page] = array();
  16407. }
  16408. /*-- END CSS-FLOAT --*/
  16409. //Reset values
  16410. $this->Reset();
  16411. if ($this->blklvl > 0) { // ==0 SHOULDN'T HAPPEN - NOT XHTML
  16412. if ($this->blk[$this->blklvl]['tag'] == $tag) {
  16413. unset($this->blk[$this->blklvl]);
  16414. $this->blklvl--;
  16415. }
  16416. //else { echo $tag; exit; } // debug - forces error if incorrectly nested html tags
  16417. }
  16418. $this->lastblocklevelchange = -1 ;
  16419. // Reset Inline-type properties
  16420. if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']); }
  16421. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  16422. }
  16423. /*-- TABLES --*/
  16424. if($tag=='TH') $this->SetStyle('B',false);
  16425. if(($tag=='TH' or $tag=='TD') && $this->tableLevel) {
  16426. $this->lastoptionaltag = 'TR';
  16427. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  16428. $this->tbCSSlvl--;
  16429. $this->tdbegin = false;
  16430. // Added for correct calculation of cell column width - otherwise misses the last line if not end </p> etc.
  16431. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  16432. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  16433. }
  16434. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  16435. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  16436. }
  16437. // Remove last <br> if at end of cell
  16438. if (isset($this->cell[$this->row][$this->col]['textbuffer'])) { $ntb = count($this->cell[$this->row][$this->col]['textbuffer']); }
  16439. else { $ntb = 0; }
  16440. // mPDF 3.0 ... but only the last one
  16441. if ($ntb>1 && $this->cell[$this->row][$this->col]['textbuffer'][$ntb-1][0] == "\n") {
  16442. unset($this->cell[$this->row][$this->col]['textbuffer'][$ntb-1]);
  16443. }
  16444. if ($this->tablethead) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_thead'][$this->row] = true; }
  16445. // mPDF 3.0
  16446. if ($this->usetableheader && ($this->row == 0 || $this->tablethead) && $this->tableLevel==1) {
  16447. $this->tableheadernrows = max($this->tableheadernrows, ($this->row+1));
  16448. }
  16449. // mPDF 4.0
  16450. if ($this->tabletfoot) { $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$this->row] = true; }
  16451. if ($this->tabletfoot && $this->tableLevel==1) {
  16452. $this->tablefooternrows = max($this->tablefooternrows, ($this->row+1 - $this->tableheadernrows));
  16453. }
  16454. $this->Reset();
  16455. }
  16456. if($tag=='TR' && $this->tableLevel) {
  16457. $this->lastoptionaltag = '';
  16458. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  16459. $this->tbCSSlvl--;
  16460. $this->trow_text_rotate = '';
  16461. $this->tabletheadjustfinished = false;
  16462. }
  16463. if($tag=='TBODY') {
  16464. $this->lastoptionaltag = '';
  16465. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  16466. $this->tbCSSlvl--;
  16467. }
  16468. if($tag=='THEAD') {
  16469. $this->lastoptionaltag = '';
  16470. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  16471. $this->tbCSSlvl--;
  16472. $this->tablethead = 0;
  16473. $this->tabletheadjustfinished = true;
  16474. $this->thead_font_weight = '';
  16475. $this->SetStyle('B',false);
  16476. $this->thead_font_style = '';
  16477. $this->SetStyle('I',false);
  16478. $this->thead_valign_default = '';
  16479. $this->thead_textalign_default = '';
  16480. }
  16481. if($tag=='TFOOT') {
  16482. $this->lastoptionaltag = '';
  16483. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  16484. $this->tbCSSlvl--;
  16485. $this->tabletfoot = 0; // mPDF 4.0
  16486. $this->tfoot_font_weight = '';
  16487. $this->SetStyle('B',false);
  16488. $this->tfoot_font_style = '';
  16489. $this->SetStyle('I',false);
  16490. $this->tfoot_valign_default = '';
  16491. $this->tfoot_textalign_default = '';
  16492. }
  16493. if($tag=='TABLE') { // TABLE-END (
  16494. $this->tctr++;
  16495. if ($this->progressBar) { $this->UpdateProgressBar(1,'','TABLE'); } // *PROGRESS-BAR*
  16496. if ($this->progressBar) { $this->UpdateProgressBar(7,0,''); } // *PROGRESS-BAR*
  16497. $this->lastoptionaltag = '';
  16498. unset($this->tablecascadeCSS[$this->tbCSSlvl]);
  16499. $this->tbCSSlvl--;
  16500. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  16501. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = $this->cell;
  16502. $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));
  16503. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['hr'] = array_pad(array(),$this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['nr'],0);
  16504. // mPDF 4.0 Move TABLE FOOTER TFOOT to end of table
  16505. if (isset($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot']) && count($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'])) {
  16506. $tfrows = array();
  16507. foreach($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'] AS $r=>$val) {
  16508. if ($val) { $tfrows[] = $r; }
  16509. }
  16510. $temp = array();
  16511. $temptf = array();
  16512. foreach($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] AS $k=>$row) {
  16513. if (in_array($k,$tfrows)) {
  16514. $temptf[] = $row;
  16515. }
  16516. else {
  16517. $temp[] = $row;
  16518. }
  16519. }
  16520. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'] = array();
  16521. for($i=count($temp) ; $i<(count($temp)+count($temptf)); $i++) {
  16522. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['is_tfoot'][$i] = true;
  16523. }
  16524. // Update nestedpos row references
  16525. if (count($this->table[($this->tableLevel+1)])) {
  16526. foreach($this->table[($this->tableLevel+1)] AS $nid=>$nested) {
  16527. $this->table[($this->tableLevel+1)][$nid]['nestedpos'][0] -= count($temptf);
  16528. }
  16529. }
  16530. $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'] = array_merge($temp, $temptf);
  16531. }
  16532. // Fix Borders *********************************************
  16533. $this->_fixTableBorders($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]);
  16534. if ($this->progressBar) { $this->UpdateProgressBar(7,10,' '); } // *PROGRESS-BAR*
  16535. if ($this->ColActive) { $this->table_rotate = 0; } // *COLUMNS*
  16536. if ($this->table_rotate <> 0) {
  16537. $this->tablebuffer = array();
  16538. // Max width for rotated table
  16539. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5);
  16540. $this->tbrot_maxh = $this->blk[$this->blklvl]['inner_width'] ; // Max width for rotated table
  16541. $this->tbrot_align = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['a'] ;
  16542. }
  16543. $this->shrin_k = 1;
  16544. // mPDF 4.2
  16545. if ($this->shrink_tables_to_fit < 1) { $this->shrink_tables_to_fit = 1; }
  16546. if (!$this->shrink_this_table_to_fit) { $this->shrink_this_table_to_fit = $this->shrink_tables_to_fit; }
  16547. if ($this->tableLevel>1) {
  16548. // deal with nested table
  16549. $this->_tableColumnWidth($this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]],true);
  16550. $tmiw = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['miw'];
  16551. $tmaw = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['maw'];
  16552. $tl = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['tl'];
  16553. // Go down to lower table level
  16554. $this->tableLevel--;
  16555. // Reset lower level table
  16556. $this->base_table_properties = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['baseProperties'];
  16557. $this->cell = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['cells'];
  16558. $this->row = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currrow'];
  16559. $this->col = $this->table[$this->tableLevel][$this->tbctr[$this->tableLevel]]['currcol'];
  16560. $objattr['type'] = 'nestedtable';
  16561. $objattr['nestedcontent'] = $this->tbctr[($this->tableLevel+1)];
  16562. $objattr['table'] = $this->tbctr[$this->tableLevel];
  16563. $objattr['row'] = $this->row;
  16564. $objattr['col'] = $this->col;
  16565. $objattr['level'] = $this->tableLevel;
  16566. $e = "\xbb\xa4\xactype=nestedtable,objattr=".serialize($objattr)."\xbb\xa4\xac";
  16567. $this->cell[$this->row][$this->col]['textbuffer'][] = array($e,$this->HREF,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  16568. $this->cell[$this->row][$this->col]['s'] += $tl ;
  16569. if (!isset($this->cell[$this->row][$this->col]['maxs'])) {
  16570. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  16571. }
  16572. elseif($this->cell[$this->row][$this->col]['maxs'] < $this->cell[$this->row][$this->col]['s']) {
  16573. $this->cell[$this->row][$this->col]['maxs'] = $this->cell[$this->row][$this->col]['s'];
  16574. }
  16575. $this->cell[$this->row][$this->col]['s'] = 0;// reset
  16576. 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 ; }
  16577. 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 ; }
  16578. $this->cell[$this->row][$this->col]['nestedcontent'][] = $this->tbctr[($this->tableLevel+1)];
  16579. $this->tdbegin = true;
  16580. $this->nestedtablejustfinished = true;
  16581. $this->ignorefollowingspaces = true;
  16582. return;
  16583. }
  16584. $this->cMarginL = 0;
  16585. $this->cMarginR = 0;
  16586. $this->cMarginT = 0;
  16587. $this->cMarginB = 0;
  16588. $this->cellPaddingL = 0;
  16589. $this->cellPaddingR = 0;
  16590. $this->cellPaddingT = 0;
  16591. $this->cellPaddingB = 0;
  16592. if (!$this->kwt_saved) { $this->kwt_height = 0; }
  16593. list($check,$tablemiw) = $this->_tableColumnWidth($this->table[1][1],true);
  16594. $save_table = $this->table;
  16595. $reset_to_minimum_width = false;
  16596. $added_page = false;
  16597. if ($check > 1) {
  16598. if ($check > $this->shrink_this_table_to_fit && $this->table_rotate) {
  16599. $this->AddPage($this->CurOrientation);
  16600. $added_page = true;
  16601. $this->kwt_moved = true;
  16602. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  16603. // mPDF 3.0
  16604. //$check = $tablemiw/$this->tbrot_maxw; // undo any shrink
  16605. $check = 1; // undo any shrink
  16606. }
  16607. $reset_to_minimum_width = true;
  16608. }
  16609. if ($reset_to_minimum_width) {
  16610. $this->shrin_k = $check;
  16611. $this->default_font_size /= $this->shrin_k;
  16612. $this->SetFontSize($this->default_font_size, false );
  16613. $this->shrinkTable($this->table[1][1],$this->shrin_k);
  16614. $this->_tableColumnWidth($this->table[1][1],false); // repeat
  16615. // Starting at $this->innermostTableLevel
  16616. // Shrink table values - and redo columnWidth
  16617. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  16618. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  16619. $this->shrinkTable($this->table[$lvl][$nid],$this->shrin_k);
  16620. $this->_tableColumnWidth($this->table[$lvl][$nid],false);
  16621. }
  16622. }
  16623. }
  16624. // Set table cell widths for top level table
  16625. // Use $shrin_k to resize but don't change again
  16626. $this->SetLineHeight('',$this->table_lineheight);
  16627. // Top level table
  16628. $this->_tableWidth($this->table[1][1]);
  16629. // Now work through any nested tables setting child table[w'] = parent cell['w']
  16630. // Now do nested tables _tableWidth
  16631. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  16632. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  16633. // HERE set child table width = cell width
  16634. list($parentrow, $parentcol, $parentnid) = $this->table[$lvl][$nid]['nestedpos'];
  16635. if (isset($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['colspan']) && $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['colspan']> 1) {
  16636. $parentwidth = 0;
  16637. for($cs=0;$cs<$this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['colspan'] ; $cs++) {
  16638. $parentwidth += $this->table[($lvl-1)][$parentnid]['wc'][$parentcol+$cs];
  16639. }
  16640. }
  16641. else { $parentwidth = $this->table[($lvl-1)][$parentnid]['wc'][$parentcol]; }
  16642. //$parentwidth -= ALLOW FOR PADDING ETC.in parent cell
  16643. // mPDF 4.3.006
  16644. if (!$this->simpleTables){ // mPDF 4.2.017
  16645. // mPDF 4.3.009
  16646. if ($this->packTableData) {
  16647. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['borderbin']);
  16648. }
  16649. else {
  16650. $br = $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['border_details']['R']['w'];
  16651. $bl = $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['border_details']['L']['w'];
  16652. }
  16653. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  16654. $parentwidth -= $br + $bl
  16655. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  16656. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R']
  16657. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  16658. }
  16659. else {
  16660. $parentwidth -= $br/2 + $bl/2
  16661. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  16662. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R'];
  16663. }
  16664. }
  16665. else if ($this->simpleTables){
  16666. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  16667. $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']
  16668. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']
  16669. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  16670. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R']
  16671. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  16672. }
  16673. else {
  16674. $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']/2
  16675. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']/2
  16676. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  16677. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R'];
  16678. }
  16679. }
  16680. if (isset($this->table[$lvl][$nid]['wpercent']) && $this->table[$lvl][$nid]['wpercent'] && $lvl>1) {
  16681. $this->table[$lvl][$nid]['w'] = $parentwidth;
  16682. }
  16683. else if ($parentwidth > $this->table[$lvl][$nid]['maw']) {
  16684. $this->table[$lvl][$nid]['w'] = $this->table[$lvl][$nid]['maw'];
  16685. }
  16686. else {
  16687. $this->table[$lvl][$nid]['w'] = $parentwidth;
  16688. }
  16689. $this->_tableWidth($this->table[$lvl][$nid]);
  16690. }
  16691. }
  16692. // Starting at $this->innermostTableLevel
  16693. // Cascade back up nested tables: setting heights back up the tree
  16694. for($lvl=$this->innermostTableLevel;$lvl>0;$lvl--) {
  16695. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  16696. list($tableheight,$maxrowheight,$fullpage,$remainingpage) = $this->_tableHeight($this->table[$lvl][$nid]);
  16697. }
  16698. }
  16699. if ($this->progressBar) { $this->UpdateProgressBar(7,20,' '); } // *PROGRESS-BAR*
  16700. $recalculate = 1;
  16701. $forcerecalc = false; // mPDF 4.2.005
  16702. // RESIZING ALGORITHM
  16703. if ($maxrowheight > $fullpage) {
  16704. $recalculate = $this->tbsqrt($maxrowheight / $fullpage, 1);
  16705. $forcerecalc = true; // mPDF 4.2.005
  16706. }
  16707. else if ($this->table_rotate) { // NB $remainingpage == $fullpage == the width of the page
  16708. if ($tableheight > $remainingpage) {
  16709. // If can fit on remainder of page whilst respecting autsize value..
  16710. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, 1)) <= $this->shrink_this_table_to_fit) {
  16711. $recalculate = $this->tbsqrt($tableheight / $remainingpage, 1);
  16712. }
  16713. else if (!$added_page) {
  16714. $this->AddPage($this->CurOrientation);
  16715. $added_page = true;
  16716. $this->kwt_moved = true;
  16717. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  16718. // mPDF 3.0 added 0.001 to force it to recalculate
  16719. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  16720. }
  16721. }
  16722. }
  16723. else if ($this->table_keep_together) {
  16724. if ($tableheight > $fullpage) {
  16725. if (($this->shrin_k * $this->tbsqrt($tableheight / $fullpage, 1)) <= $this->shrink_this_table_to_fit) {
  16726. $recalculate = $this->tbsqrt($tableheight / $fullpage, 1);
  16727. }
  16728. else if ($this->tableMinSizePriority) { // mPDF 4.5.006
  16729. $this->table_keep_together = false;
  16730. $recalculate = 1.001;
  16731. }
  16732. else {
  16733. $this->AddPage($this->CurOrientation);
  16734. $added_page = true;
  16735. $this->kwt_moved = true;
  16736. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  16737. $recalculate = $this->tbsqrt($tableheight / $fullpage, 1);
  16738. }
  16739. }
  16740. else if ($tableheight > $remainingpage) {
  16741. // If can fit on remainder of page whilst respecting autsize value..
  16742. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, 1)) <= $this->shrink_this_table_to_fit) {
  16743. $recalculate = $this->tbsqrt($tableheight / $remainingpage, 1);
  16744. }
  16745. else {
  16746. $this->AddPage($this->CurOrientation);
  16747. $added_page = true;
  16748. $this->kwt_moved = true;
  16749. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  16750. // mPDF 3.0 added 0.001 to force it to recalculate
  16751. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  16752. }
  16753. }
  16754. }
  16755. else { $recalculate = 1; }
  16756. if ($recalculate > $this->shrink_this_table_to_fit && !$forcerecalc) { $recalculate = $this->shrink_this_table_to_fit; } // mPDF 4.2.005
  16757. $iteration = 1; // mPDF 4.5.006
  16758. // RECALCULATE
  16759. while($recalculate <> 1) {
  16760. $this->shrin_k1 = $recalculate ;
  16761. $this->shrin_k *= $recalculate ;
  16762. $this->default_font_size /= ($this->shrin_k1) ;
  16763. $this->SetFontSize($this->default_font_size, false );
  16764. $this->SetLineHeight('',$this->table_lineheight);
  16765. $this->table = $save_table;
  16766. if ($this->shrin_k <> 1) { $this->shrinkTable($this->table[1][1],$this->shrin_k); }
  16767. $this->_tableColumnWidth($this->table[1][1],false); // repeat
  16768. // Starting at $this->innermostTableLevel
  16769. // Shrink table values - and redo columnWidth
  16770. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  16771. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  16772. if ($this->shrin_k <> 1) { $this->shrinkTable($this->table[$lvl][$nid],$this->shrin_k); }
  16773. $this->_tableColumnWidth($this->table[$lvl][$nid],false);
  16774. }
  16775. }
  16776. // Set table cell widths for top level table
  16777. // Top level table
  16778. $this->_tableWidth($this->table[1][1]);
  16779. // Now work through any nested tables setting child table[w'] = parent cell['w']
  16780. // Now do nested tables _tableWidth
  16781. for($lvl=2;$lvl<=$this->innermostTableLevel;$lvl++) {
  16782. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  16783. // HERE set child table width = cell width
  16784. list($parentrow, $parentcol, $parentnid) = $this->table[$lvl][$nid]['nestedpos'];
  16785. if (isset($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['colspan']) && $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['colspan']> 1) {
  16786. $parentwidth = 0;
  16787. for($cs=0;$cs<$this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['colspan'] ; $cs++) {
  16788. $parentwidth += $this->table[($lvl-1)][$parentnid]['wc'][$parentcol+$cs];
  16789. }
  16790. }
  16791. else { $parentwidth = $this->table[($lvl-1)][$parentnid]['wc'][$parentcol]; }
  16792. //$parentwidth -= ALLOW FOR PADDING ETC.in parent cell
  16793. // mPDF 4.3.006
  16794. if (!$this->simpleTables){ // mPDF 4.2.017
  16795. // mPDF 4.3.009
  16796. if ($this->packTableData) {
  16797. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['borderbin']);
  16798. }
  16799. else {
  16800. $br = $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['border_details']['R']['w'];
  16801. $bl = $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['border_details']['L']['w'];
  16802. }
  16803. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  16804. $parentwidth -= $br + $bl
  16805. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  16806. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R']
  16807. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  16808. }
  16809. else {
  16810. $parentwidth -= $br/2 + $bl/2
  16811. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  16812. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R'];
  16813. }
  16814. }
  16815. else if ($this->simpleTables){
  16816. if ($this->table[$lvl-1][$parentnid]['borders_separate']) {
  16817. $parentwidth -= $this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']
  16818. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']
  16819. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  16820. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R']
  16821. + $this->table[($lvl-1)][$parentnid]['border_spacing_H'];
  16822. }
  16823. else {
  16824. $parentwidth -= ($this->table[($lvl-1)][$parentnid]['simple']['border_details']['L']['w']
  16825. + $this->table[($lvl-1)][$parentnid]['simple']['border_details']['R']['w']) /2
  16826. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['L']
  16827. + $this->table[($lvl-1)][$parentnid]['cells'][$parentrow][$parentcol]['padding']['R'];
  16828. }
  16829. }
  16830. if (isset($this->table[$lvl][$nid]['wpercent']) && $this->table[$lvl][$nid]['wpercent'] && $lvl>1) {
  16831. $this->table[$lvl][$nid]['w'] = $parentwidth;
  16832. }
  16833. else if ($parentwidth > $this->table[$lvl][$nid]['maw']) {
  16834. $this->table[$lvl][$nid]['w'] = $this->table[$lvl][$nid]['maw'] ;
  16835. }
  16836. else {
  16837. $this->table[$lvl][$nid]['w'] = $parentwidth;
  16838. }
  16839. $this->_tableWidth($this->table[$lvl][$nid]);
  16840. }
  16841. }
  16842. // Starting at $this->innermostTableLevel
  16843. // Cascade back up nested tables: setting heights back up the tree
  16844. for($lvl=$this->innermostTableLevel;$lvl>0;$lvl--) {
  16845. for ($nid=1; $nid<=$this->tbctr[$lvl]; $nid++) {
  16846. list($tableheight,$maxrowheight,$fullpage,$remainingpage) = $this->_tableHeight($this->table[$lvl][$nid]);
  16847. }
  16848. }
  16849. // RESIZING ALGORITHM
  16850. if ($maxrowheight > $fullpage) { $recalculate = $this->tbsqrt($maxrowheight / $fullpage, $iteration); $iteration++; }
  16851. else if ($this->table_rotate && $tableheight > $remainingpage && !$added_page) {
  16852. // If can fit on remainder of page whilst respecting autosize value..
  16853. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, $iteration)) <= $this->shrink_this_table_to_fit) {
  16854. $recalculate = $this->tbsqrt($tableheight / $remainingpage, $iteration); $iteration++;
  16855. }
  16856. else {
  16857. if (!$added_page) {
  16858. $this->AddPage($this->CurOrientation);
  16859. $added_page = true;
  16860. $this->kwt_moved = true;
  16861. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  16862. }
  16863. // mPDF 3.0 added 0.001 to force it to recalculate
  16864. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  16865. }
  16866. }
  16867. else if ($this->table_keep_together) {
  16868. if ($tableheight > $fullpage) {
  16869. if (($this->shrin_k * $this->tbsqrt($tableheight / $fullpage, $iteration)) <= $this->shrink_this_table_to_fit) {
  16870. $recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++;
  16871. }
  16872. else if ($this->tableMinSizePriority) { // mPDF 4.5.006
  16873. $this->table_keep_together = false;
  16874. $recalculate = (1 / $this->shrin_k) + 0.001;
  16875. }
  16876. else {
  16877. if (!$added_page) {
  16878. $this->AddPage($this->CurOrientation);
  16879. $added_page = true;
  16880. $this->kwt_moved = true;
  16881. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  16882. }
  16883. $recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++;
  16884. }
  16885. }
  16886. else if ($tableheight > $remainingpage) {
  16887. // If can fit on remainder of page whilst respecting autosize value..
  16888. if (($this->shrin_k * $this->tbsqrt($tableheight / $remainingpage, $iteration)) <= $this->shrink_this_table_to_fit) {
  16889. $recalculate = $this->tbsqrt($tableheight / $remainingpage, $iteration); $iteration++;
  16890. }
  16891. else {
  16892. if (!$added_page) {
  16893. $this->AddPage($this->CurOrientation);
  16894. $added_page = true;
  16895. $this->kwt_moved = true;
  16896. $this->tbrot_maxw = $this->h - ($this->y + $this->bMargin + 5) - $this->kwt_height;
  16897. }
  16898. // mPDF 4.0
  16899. //$recalculate = $this->tbsqrt($tableheight / $fullpage, $iteration); $iteration++;
  16900. $recalculate = (1 / $this->shrin_k) + 0.001; // undo any shrink
  16901. }
  16902. }
  16903. else { $recalculate = 1; }
  16904. }
  16905. else { $recalculate = 1; }
  16906. }
  16907. // keep-with-table: if page has advanced, print out buffer now, else done in fn. _Tablewrite()
  16908. if ($this->kwt_saved && $this->kwt_moved) {
  16909. $this->printkwtbuffer();
  16910. $this->kwt_moved = false;
  16911. $this->kwt_saved = false;
  16912. }
  16913. if ($this->progressBar) { $this->UpdateProgressBar(7,30,' '); } // *PROGRESS-BAR*
  16914. // Recursively writes all tables starting at top level
  16915. $this->_tableWrite($this->table[1][1]);
  16916. if ($this->table_rotate && count($this->tablebuffer)) {
  16917. $this->PageBreakTrigger=$this->h-$this->bMargin;
  16918. $save_tr = $this->table_rotate;
  16919. $save_y = $this->y;
  16920. $this->table_rotate = 0;
  16921. $this->y = $this->tbrot_y0;
  16922. $h = $this->tbrot_w;
  16923. $this->DivLn($h,$this->blklvl,true);
  16924. $this->table_rotate = $save_tr;
  16925. $this->y = $save_y;
  16926. $this->printtablebuffer();
  16927. }
  16928. $this->table_rotate = 0; // flag used for table rotation
  16929. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  16930. // mPDF 4.2
  16931. $this->blockjustfinished=true;
  16932. $this->lastblockbottommargin = $this->table[1][1]['margin']['B'];
  16933. //Reset values
  16934. // Keep-with-table
  16935. $this->kwt = false;
  16936. $this->kwt_y0 = 0;
  16937. $this->kwt_x0 = 0;
  16938. $this->kwt_height = 0;
  16939. $this->kwt_buffer = array();
  16940. $this->kwt_Links = array();
  16941. $this->kwt_Annots = array();
  16942. $this->kwt_moved = false;
  16943. $this->kwt_saved = false;
  16944. // mPDF 3.0
  16945. $this->kwt_Reference = array();
  16946. $this->kwt_BMoutlines = array();
  16947. $this->kwt_toc = array();
  16948. $this->shrin_k = 1;
  16949. $this->shrink_this_table_to_fit = 0;
  16950. unset($this->table);
  16951. $this->table=array(); //array
  16952. $this->tableLevel=0;
  16953. $this->tbctr=array();
  16954. $this->innermostTableLevel=0;
  16955. $this->tbCSSlvl = 0;
  16956. $this->tablecascadeCSS = array();
  16957. unset($this->cell);
  16958. $this->cell=array(); //array
  16959. $this->col=-1; //int
  16960. $this->row=-1; //int
  16961. $this->Reset();
  16962. $this->cellPaddingL = 0;
  16963. $this->cellPaddingT = 0;
  16964. $this->cellPaddingR = 0;
  16965. $this->cellPaddingB = 0;
  16966. $this->cMarginL = 0;
  16967. $this->cMarginT = 0;
  16968. $this->cMarginR = 0;
  16969. $this->cMarginB = 0;
  16970. $this->default_font_size = $this->original_default_font_size;
  16971. $this->default_font = $this->original_default_font;
  16972. $this->SetFontSize($this->default_font_size, false);
  16973. $this->SetFont($this->default_font,'',0,false);
  16974. $this->SetLineHeight();
  16975. if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']);}
  16976. if ($this->progressBar) { $this->UpdateProgressBar(7,100,' '); } // *PROGRESS-BAR*
  16977. }
  16978. /*-- END TABLES --*/
  16979. /*-- LISTS --*/
  16980. // *********** LISTS ********************
  16981. if($tag=='LI') {
  16982. $this->lastoptionaltag = '';
  16983. unset($this->listcascadeCSS[$this->listCSSlvl]);
  16984. $this->listCSSlvl--;
  16985. 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]]); }
  16986. }
  16987. if(($tag=='UL') or ($tag=='OL')) {
  16988. $this->ignorefollowingspaces = true; //Eliminate exceeding left-side spaces
  16989. unset($this->listcascadeCSS[$this->listCSSlvl]);
  16990. $this->listCSSlvl--;
  16991. $this->lastoptionaltag = '';
  16992. /*-- TABLES --*/
  16993. // A simple list for inside a table
  16994. if($this->tableLevel) {
  16995. $this->listlist[$this->listlvl]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  16996. unset($this->listlist[$this->listlvl]);
  16997. $this->listlvl--;
  16998. if (isset($this->listlist[$this->listlvl]['MAXNUM'])) { $this->listnum = $this->listlist[$this->listlvl]['MAXNUM']; } // restore previous levels
  16999. if ($this->listlvl == 0) { $this->listjustfinished = true; }
  17000. return;
  17001. }
  17002. /*-- END TABLES --*/
  17003. if ($this->listlvl > 1) { // returning one level
  17004. $this->listjustfinished=true;
  17005. if (!empty($this->textbuffer)) {
  17006. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  17007. }
  17008. // mPDF 3.0
  17009. else {
  17010. $this->listnum--;
  17011. }
  17012. $this->textbuffer = array();
  17013. $occur = $this->listoccur[$this->listlvl];
  17014. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum; //save previous lvl's maxnum
  17015. $this->listlvl--;
  17016. $occur = $this->listoccur[$this->listlvl];
  17017. $this->listnum = $this->listlist[$this->listlvl][$occur]['MAXNUM']; // recover previous level's number
  17018. $this->listtype = $this->listlist[$this->listlvl][$occur]['TYPE']; // recover previous level's type
  17019. if ($this->InlineProperties['LIST'][$this->listlvl][$occur]) { $this->restoreInlineProperties($this->InlineProperties['LIST'][$this->listlvl][$occur]); }
  17020. }
  17021. else { // We are closing the last OL/UL tag
  17022. if (!empty($this->textbuffer)) {
  17023. $this->listitem[] = array($this->listlvl,$this->listnum,$this->textbuffer,$this->listoccur[$this->listlvl],$this->listitemtype);
  17024. }
  17025. // mPDF 3.0
  17026. else {
  17027. $this->listnum--;
  17028. }
  17029. $occur = $this->listoccur[$this->listlvl];
  17030. $this->listlist[$this->listlvl][$occur]['MAXNUM'] = $this->listnum;
  17031. $this->textbuffer = array();
  17032. $this->listlvl--;
  17033. $this->printlistbuffer();
  17034. unset($this->InlineProperties['LIST']);
  17035. // SPACING AFTER LIST (Top level only)
  17036. $this->Ln(0);
  17037. if ($this->list_margin_bottom) {
  17038. $this->DivLn($this->list_margin_bottom,$this->blklvl,true,1); // collapsible
  17039. }
  17040. if (isset($this->blk[$this->blklvl]['InlineProperties'])) { $this->restoreInlineProperties($this->blk[$this->blklvl]['InlineProperties']);}
  17041. $this->listjustfinished = true;
  17042. $this->listCSSlvl = 0;
  17043. $this->listcascadeCSS = array();
  17044. // mPDF 4.2
  17045. $this->blockjustfinished=true;
  17046. $this->lastblockbottommargin = $this->list_margin_bottom;
  17047. }
  17048. }
  17049. /*-- END LISTS --*/
  17050. }
  17051. /*-- TABLES --*/
  17052. // This function determines the shrink factor when resizing tables
  17053. // val is the table_height / page_height_available
  17054. // returns a scaling factor used as $shrin_k to resize the table
  17055. // Overcompensating will be quicker but may unnecessarily shrink table too much
  17056. // Undercompensating means it will reiterate more times (taking more processing time)
  17057. function tbsqrt($val, $iteration=3) {
  17058. $k = 4; // Alters number of iterations until it returns $val itself - Must be > 2
  17059. // Probably best guess and most accurate
  17060. if ($iteration==1) return sqrt($val);
  17061. // Faster than using sqrt (because it won't undercompensate), and gives reasonable results
  17062. //return 1+(($val-1)/2);
  17063. if (2-(($iteration-2)/($k-2)) == 0) { return $val+0.00001; } // mPDF 4.5.005
  17064. return 1+(($val-1)/(2-(($iteration-2)/($k-2))));
  17065. }
  17066. /*-- END TABLES --*/
  17067. /*-- LISTS --*/
  17068. function printlistbuffer() {
  17069. //Save x coordinate
  17070. $x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  17071. $this->cMarginL = 0;
  17072. $this->cMarginR = 0;
  17073. $currIndentLvl = -1;
  17074. $lastIndent = array();
  17075. $bak_page = $this->page;
  17076. $indent = 0; // mPDF 3.0
  17077. foreach($this->listitem as $item)
  17078. {
  17079. // COLS
  17080. $oldcolumn = $this->CurrCol;
  17081. $this->bulletarray = array();
  17082. //Get list's buffered data
  17083. $this->listlvl = $lvl = $item[0];
  17084. $num = $item[1];
  17085. $this->textbuffer = $item[2];
  17086. $occur = $item[3];
  17087. if ($item[4]) { $type = $item[4]; } // listitemtype
  17088. else { $type = $this->listlist[$lvl][$occur]['TYPE']; }
  17089. $maxnum = $this->listlist[$lvl][$occur]['MAXNUM'];
  17090. $this->restoreInlineProperties($this->InlineProperties['LIST'][$lvl][$occur]);
  17091. $this->SetFont($this->FontFamily,$this->FontStyle,$this->FontSizePt,true,true); // force to write
  17092. $clh = $this->FontSize;
  17093. // mPDF 4.2
  17094. $this->SetLineHeight($this->FontSizePt,$this->list_lineheight[$lvl][$occur]);
  17095. $this->listOcc = $occur;
  17096. $this->listnum = $num;
  17097. // Set the bullet fontsize
  17098. $bullfs = $this->InlineProperties['LISTITEM'][$lvl][$occur][$num]['size'];
  17099. $space_width = $this->GetStringWidth(' ') * 1.5;
  17100. //Set default width & height values
  17101. $this->divwidth = $this->blk[$this->blklvl]['inner_width'];
  17102. $this->divheight = $this->lineheight;
  17103. $typefont = $this->FontFamily;
  17104. switch($type) //Format type
  17105. {
  17106. case 'none':
  17107. $type = '';
  17108. $blt_width = 0;
  17109. break;
  17110. case 'A':
  17111. $anum = $this->dec2alpha($num,true);
  17112. $maxnum = $this->dec2alpha($maxnum,true);
  17113. if ($this->directionality == 'rtl') { $type = $this->list_number_suffix . $anum; }
  17114. else { $type = $anum . $this->list_number_suffix; }
  17115. $blt_width = $this->GetStringWidth(str_repeat('W',strlen($maxnum)).$this->list_number_suffix);
  17116. break;
  17117. case 'a':
  17118. $anum = $this->dec2alpha($num,false);
  17119. $maxnum = $this->dec2alpha($maxnum,false);
  17120. if ($this->directionality == 'rtl') { $type = $this->list_number_suffix . $anum; }
  17121. else { $type = $anum . $this->list_number_suffix; }
  17122. $blt_width = $this->GetStringWidth(str_repeat('m',strlen($maxnum)).$this->list_number_suffix);
  17123. break;
  17124. case 'I':
  17125. $anum = $this->dec2roman($num,true);
  17126. if ($this->directionality == 'rtl') { $type = $this->list_number_suffix . $anum; }
  17127. else { $type = $anum . $this->list_number_suffix; }
  17128. // mPDF 4.0
  17129. if ($maxnum>87) { $bbit = 87; }
  17130. else if ($maxnum>86) { $bbit = 86; }
  17131. else if ($maxnum>37) { $bbit = 38; }
  17132. else if ($maxnum>36) { $bbit = 37; }
  17133. else if ($maxnum>27) { $bbit = 28; }
  17134. else if ($maxnum>26) { $bbit = 27; }
  17135. else if ($maxnum>17) { $bbit = 18; }
  17136. else if ($maxnum>16) { $bbit = 17; }
  17137. else if ($maxnum>7) { $bbit = 8; }
  17138. else if ($maxnum>6) { $bbit = 7; }
  17139. else if ($maxnum>3) { $bbit = 4; }
  17140. else { $bbit = $maxnum; }
  17141. $maxlnum = $this->dec2roman($bbit,true);
  17142. $blt_width = $this->GetStringWidth($maxlnum.$this->list_number_suffix);
  17143. break;
  17144. case 'i':
  17145. $anum = $this->dec2roman($num,false);
  17146. if ($this->directionality == 'rtl') { $type = $this->list_number_suffix . $anum; }
  17147. else { $type = $anum . $this->list_number_suffix; }
  17148. // mPDF 4.0
  17149. if ($maxnum>87) { $bbit = 87; }
  17150. else if ($maxnum>86) { $bbit = 86; }
  17151. else if ($maxnum>37) { $bbit = 38; }
  17152. else if ($maxnum>36) { $bbit = 37; }
  17153. else if ($maxnum>27) { $bbit = 28; }
  17154. else if ($maxnum>26) { $bbit = 27; }
  17155. else if ($maxnum>17) { $bbit = 18; }
  17156. else if ($maxnum>16) { $bbit = 17; }
  17157. else if ($maxnum>7) { $bbit = 8; }
  17158. else if ($maxnum>6) { $bbit = 7; }
  17159. else if ($maxnum>3) { $bbit = 4; }
  17160. else { $bbit = $maxnum; }
  17161. $maxlnum = $this->dec2roman($bbit,false);
  17162. // mPDF 4.0
  17163. $blt_width = $this->GetStringWidth($maxlnum.$this->list_number_suffix);
  17164. break;
  17165. case 'disc':
  17166. // mPDF 4.2.018
  17167. if ($this->PDFA) {
  17168. if (isset($this->CurrentFont['cw'][8226])) { $type = "\xe2\x80\xa2"; } // &#8226;
  17169. else { $type = '-'; }
  17170. $blt_width = $this->GetStringWidth($type);
  17171. break;
  17172. }
  17173. $type = $this->chrs[108]; // bullet disc in Zapfdingbats 'l'
  17174. $typefont = 'zapfdingbats';
  17175. $blt_width = (0.791 * $this->FontSize/2.5);
  17176. break;
  17177. case 'circle':
  17178. // mPDF 4.2.018
  17179. if ($this->PDFA) {
  17180. if (isset($this->CurrentFont['cw'][9900])) { $type = "\xe2\x9a\xac"; } // &#9900;
  17181. else { $type = '-'; }
  17182. $blt_width = $this->GetStringWidth($type);
  17183. break;
  17184. }
  17185. $type = $this->chrs[109]; // circle in Zapfdingbats 'm'
  17186. $typefont = 'zapfdingbats';
  17187. $blt_width = (0.873 * $this->FontSize/2.5);
  17188. break;
  17189. case 'square':
  17190. // mPDF 4.2.018
  17191. if ($this->PDFA) {
  17192. if (isset($this->CurrentFont['cw'][9642])) { $type = "\xe2\x96\xaa"; } // &#9642;
  17193. else { $type = '-'; }
  17194. $blt_width = $this->GetStringWidth($type);
  17195. break;
  17196. }
  17197. $type = $this->chrs[110]; //black square in Zapfdingbats font 'n'
  17198. $typefont = 'zapfdingbats';
  17199. $blt_width = (0.761 * $this->FontSize/2.5);
  17200. break;
  17201. case '1':
  17202. default:
  17203. if ($this->directionality == 'rtl') { $type = $this->list_number_suffix . $num; }
  17204. else { $type = $num . $this->list_number_suffix; }
  17205. $blt_width = $this->GetStringWidth(str_repeat('5',strlen($maxnum)).$this->list_number_suffix);
  17206. break;
  17207. }
  17208. if ($currIndentLvl < $lvl) {
  17209. if ($lvl > 1 || $this->list_indent_first_level) {
  17210. $indent += $this->list_indent[$lvl][$occur];
  17211. $lastIndent[$lvl] = $this->list_indent[$lvl][$occur];
  17212. }
  17213. }
  17214. else if ($currIndentLvl > $lvl) {
  17215. while ($currIndentLvl > $lvl) {
  17216. $indent -= $lastIndent[$currIndentLvl];
  17217. $currIndentLvl--;
  17218. }
  17219. }
  17220. $currIndentLvl = $lvl;
  17221. // mPDF 3.0
  17222. if (isset($this->list_align[$this->listlvl][$occur])) { $this->divalign = $this->list_align[$this->listlvl][$occur]; }
  17223. else { $this->divalign = ''; }
  17224. /*-- RTL --*/
  17225. if ($this->directionality == 'rtl') {
  17226. // mPDF 4.0
  17227. if ($this->list_align_style == 'L') { $lalign = 'R'; }
  17228. else { $lalign = 'L'; }
  17229. $this->divwidth = $this->blk[$this->blklvl]['width'] - ($indent + $blt_width + $space_width) ;
  17230. $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)
  17231. //Output bullet
  17232. $this->bulletarray = array('w'=>$blt_width,'h'=>$clh,'txt'=>$type,'x'=>$xb,'align'=>$lalign,'font'=>$typefont,'level'=>$lvl, 'occur'=>$occur, 'num'=>$num, 'fontsize'=>$bullfs );
  17233. $this->x = $x;
  17234. }
  17235. else {
  17236. /*-- END RTL --*/
  17237. // mPDF 4.0
  17238. if ($this->list_align_style == 'L') { $lalign = 'L'; }
  17239. else { $lalign = 'R'; }
  17240. $this->divwidth = $this->blk[$this->blklvl]['width'] - ($indent + $blt_width + $space_width) ;
  17241. $xb = $this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'] - $blt_width - $space_width;
  17242. //Output bullet
  17243. $this->bulletarray = array('w'=>$blt_width,'h'=>$clh,'txt'=>$type,'x'=>$xb,'align'=>$lalign,'font'=>$typefont,'level'=>$lvl, 'occur'=>$occur, 'num'=>$num, 'fontsize'=>$bullfs );
  17244. $this->x = $x + $indent + $blt_width + $space_width;
  17245. } // *RTL*
  17246. //Print content
  17247. $this->printbuffer($this->textbuffer,'',false,true);
  17248. $this->textbuffer=array();
  17249. // Added to correct for OddEven Margins
  17250. if ($this->page != $bak_page) {
  17251. if (($this->page-$bak_page) % 2 == 1) { // mPDF 4.2.022
  17252. $x += $this->MarginCorrection;
  17253. }
  17254. $bak_page = $this->page;
  17255. }
  17256. /*-- COLUMNS --*/
  17257. // OR COLUMN CHANGE
  17258. if ($this->CurrCol != $oldcolumn) {
  17259. if ($this->directionality == 'rtl') { // *RTL*
  17260. $x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  17261. } // *RTL*
  17262. else { // *RTL*
  17263. $x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  17264. } // *RTL*
  17265. $oldcolumn = $this->CurrCol;
  17266. }
  17267. /*-- END COLUMNS --*/
  17268. }
  17269. //Reset all used values
  17270. $this->listoccur = array();
  17271. $this->listitem = array();
  17272. $this->listlist = array();
  17273. $this->listlvl = 0;
  17274. $this->listnum = 0;
  17275. $this->listtype = '';
  17276. $this->textbuffer = array();
  17277. $this->divwidth = 0;
  17278. $this->divheight = 0;
  17279. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'];
  17280. }
  17281. /*-- END LISTS --*/
  17282. function printbuffer($arrayaux,$blockstate=0,$is_table=false,$is_list=false)
  17283. {
  17284. // $blockstate = 0; // NO margins/padding
  17285. // $blockstate = 1; // Top margins/padding only
  17286. // $blockstate = 2; // Bottom margins/padding only
  17287. // $blockstate = 3; // Top & bottom margins/padding
  17288. $this->spanbgcolorarray = array();
  17289. $this->spanbgcolor = false;
  17290. $paint_ht_corr = 0;
  17291. /*-- CSS-FLOAT --*/
  17292. if (count($this->floatDivs)) {
  17293. list($l_exists, $r_exists, $l_max, $r_max, $l_width, $r_width) = $this->GetFloatDivInfo($this->blklvl);
  17294. if (($this->blk[$this->blklvl]['inner_width']-$l_width-$r_width) < $this->GetStringWidth('WW')) {
  17295. // Too narrow to fit - try to move down past L or R float
  17296. if ($l_max < $r_max && ($this->blk[$this->blklvl]['inner_width']-$r_width) > $this->GetStringWidth('WW')) {
  17297. $this->ClearFloats('LEFT', $this->blklvl);
  17298. }
  17299. else if ($r_max < $l_max && ($this->blk[$this->blklvl]['inner_width']-$l_width) > $this->GetStringWidth('WW')) {
  17300. $this->ClearFloats('RIGHT', $this->blklvl);
  17301. }
  17302. else { $this->ClearFloats('BOTH', $this->blklvl); }
  17303. }
  17304. }
  17305. /*-- END CSS-FLOAT --*/
  17306. $bak_y = $this->y;
  17307. $bak_x = $this->x;
  17308. $align = '';
  17309. if (!$is_table && !$is_list) {
  17310. if (isset($this->blk[$this->blklvl]['align']) && $this->blk[$this->blklvl]['align']) { $align = $this->blk[$this->blklvl]['align']; }
  17311. // Block-align is set by e.g. <.. align="center"> Takes priority for this block but not inherited
  17312. if (isset($this->blk[$this->blklvl]['block-align']) && $this->blk[$this->blklvl]['block-align']) { $align = $this->blk[$this->blklvl]['block-align']; }
  17313. $this->divwidth = $this->blk[$this->blklvl]['width'];
  17314. }
  17315. else {
  17316. $align = $this->divalign;
  17317. }
  17318. $oldpage = $this->page;
  17319. // ADDED for Out of Block now done as Flowing Block
  17320. if ($this->divwidth == 0) {
  17321. $this->divwidth = $this->pgwidth;
  17322. }
  17323. if (!$is_table && !$is_list) { $this->SetLineHeight($this->FontSizePt,$this->blk[$this->blklvl]['line_height']); }
  17324. $this->divheight = $this->lineheight;
  17325. $old_height = $this->divheight;
  17326. // As a failsafe - if font has been set but not output to page
  17327. $this->SetFont($this->default_font,'',$this->default_font_size,true,true); // force output to page
  17328. $array_size = count($arrayaux);
  17329. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,true); // true = newblock
  17330. // Added - Otherwise <div><div><p> did not output top margins/padding for 1st/2nd div
  17331. if ($array_size == 0) { $this->finishFlowingBlock(true); } // true = END of flowing block
  17332. for($i=0;$i < $array_size; $i++)
  17333. {
  17334. // COLS
  17335. $oldcolumn = $this->CurrCol;
  17336. $vetor = $arrayaux[$i];
  17337. if ($i == 0 and $vetor[0] != "\n" and !$this->ispre) {
  17338. $vetor[0] = ltrim($vetor[0]);
  17339. }
  17340. // FIXED TO ALLOW IT TO SHOW '0'
  17341. if (empty($vetor[0]) && !($vetor[0]==='0') && empty($vetor[7])) { //Ignore empty text and not carrying an internal link
  17342. //Check if it is the last element. If so then finish printing the block
  17343. if ($i == ($array_size-1)) { $this->finishFlowingBlock(true); } // true = END of flowing block
  17344. continue;
  17345. }
  17346. //Activating buffer properties
  17347. if(isset($vetor[11]) and $vetor[11] != '') { // Font Size
  17348. if ($is_table && $this->shrin_k) {
  17349. $this->SetFontSize($vetor[11]/$this->shrin_k,false);
  17350. }
  17351. else {
  17352. $this->SetFontSize($vetor[11],false);
  17353. }
  17354. }
  17355. if(isset($vetor[10]) and !empty($vetor[10])) //Background color
  17356. {
  17357. $this->spanbgcolorarray = $vetor[10];
  17358. $this->spanbgcolor = true;
  17359. }
  17360. if(isset($vetor[9]) and !empty($vetor[9])) // Outline parameters
  17361. {
  17362. $cor = $vetor[9]['COLOR'];
  17363. $outlinewidth = $vetor[9]['WIDTH'];
  17364. $this->SetTextOutline($outlinewidth,$cor['R'],$cor['G'],$cor['B']);
  17365. $this->outline_on = true;
  17366. }
  17367. if(isset($vetor[8]) and $vetor[8] === true) // strike-through the text
  17368. {
  17369. $this->strike = true;
  17370. }
  17371. if(isset($vetor[7]) and $vetor[7] != '') // internal link: <a name="anyvalue">
  17372. {
  17373. if ($this->ColActive) { $ily = $this->y0; } else { $ily = $this->y; } // use top of columns
  17374. $this->internallink[$vetor[7]] = array("Y"=>$ily,"PAGE"=>$this->page );
  17375. if (empty($vetor[0])) { //Ignore empty text
  17376. //Check if it is the last element. If so then finish printing the block
  17377. if ($i == ($array_size-1)) { $this->finishFlowingBlock(true); } // true = END of flowing block
  17378. continue;
  17379. }
  17380. }
  17381. if(isset($vetor[6]) and $vetor[6] === true) // Subscript
  17382. {
  17383. $this->SUB = true;
  17384. }
  17385. if(isset($vetor[5]) and $vetor[5] === true) // Superscript
  17386. {
  17387. $this->SUP = true;
  17388. }
  17389. if(isset($vetor[4]) and $vetor[4] != '') { // Font Family
  17390. $font = $this->SetFont($vetor[4],$this->FontStyle,0,false);
  17391. }
  17392. if (!empty($vetor[3])) //Font Color
  17393. {
  17394. $cor = $vetor[3];
  17395. $this->SetTextColor($cor['R'],$cor['G'],$cor['B']);
  17396. }
  17397. if(isset($vetor[2]) and $vetor[2] != '') //Bold,Italic,Underline styles
  17398. {
  17399. if (strpos($vetor[2],"B") !== false) $this->SetStyle('B',true);
  17400. if (strpos($vetor[2],"I") !== false) $this->SetStyle('I',true);
  17401. if (strpos($vetor[2],"U") !== false) $this->SetStyle('U',true);
  17402. }
  17403. // mPDF 4.2
  17404. if(isset($vetor[12]) and $vetor[12] != '') { //Requested Bold,Italic,Underline
  17405. $this->ReqFontStyle = $vetor[12];
  17406. }
  17407. if(isset($vetor[1]) and $vetor[1] != '') //LINK
  17408. {
  17409. // mPDF 3.0
  17410. 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.)
  17411. {
  17412. //Repeated reference to same anchor?
  17413. while(array_key_exists($vetor[1],$this->internallink)) $vetor[1]="#".$vetor[1];
  17414. $this->internallink[$vetor[1]] = $this->AddLink();
  17415. $vetor[1] = $this->internallink[$vetor[1]];
  17416. }
  17417. $this->HREF = $vetor[1]; // HREF link style set here ******
  17418. }
  17419. // SPECIAL CONTENT - IMAGES & FORM OBJECTS
  17420. //Print-out special content
  17421. // mPDF 3.0
  17422. if (substr($vetor[0],0,3) == "\xbb\xa4\xac") { //identifier has been identified!
  17423. // mPDF 4.0
  17424. $objattr = $this->_getObjAttr($vetor[0]);
  17425. /*-- TABLES --*/
  17426. if ($objattr['type'] == 'nestedtable') {
  17427. $level = $objattr['level'];
  17428. $table = &$this->table[$level][$objattr['table']];
  17429. $cell = &$table['cells'][$objattr['row']][$objattr['col']];
  17430. if ($objattr['nestedcontent']) {
  17431. $this->finishFlowingBlock(false,'nestedtable'); // mPDF 4.3.003
  17432. $save_dw = $this->divwidth ;
  17433. $save_buffer = $this->cellBorderBuffer;
  17434. $this->cellBorderBuffer = array();
  17435. $ncx = $this->x;
  17436. //$w = $cell['w']; // parent cell width // mPDF 3.0 ? not needed
  17437. list($dummyx,$w) = $this->_tableGetWidth($table, $objattr['row'], $objattr['col']);
  17438. $ntw = $this->table[($level+1)][$objattr['nestedcontent']]['w']; // nested table width
  17439. if (!$this->simpleTables){ // mPDF 4.2.017
  17440. if ($table['borders_separate']) {
  17441. $innerw = $w - $cell['border_details']['L']['w'] - $cell['border_details']['R']['w'] - $cell['padding']['L'] - $cell['padding']['R'] - $table['border_spacing_H'];
  17442. }
  17443. else {
  17444. $innerw = $w - $cell['border_details']['L']['w']/2 - $cell['border_details']['R']['w']/2 - $cell['padding']['L'] - $cell['padding']['R'];
  17445. }
  17446. }
  17447. else if ($this->simpleTables){
  17448. // mPDF 4.3.006
  17449. if ($table['borders_separate']) {
  17450. $innerw = $w - $table['simple']['border_details']['L']['w'] - $table['simple']['border_details']['R']['w'] - $cell['padding']['L'] - $cell['padding']['R'] - $table['border_spacing_H'];
  17451. }
  17452. else {
  17453. $innerw = $w - $table['simple']['border_details']['L']['w']/2 - $table['simple']['border_details']['R']['w']/2 - $cell['padding']['L'] - $cell['padding']['R'];
  17454. }
  17455. }
  17456. if ($cell['a']=='C' || $this->table[($level+1)][$objattr['nestedcontent']]['a']=='C') {
  17457. $ncx += ($innerw-$ntw)/2;
  17458. }
  17459. elseif ($cell['a']=='R' || $this->table[($level+1)][$objattr['nestedcontent']]['a']=='R') {
  17460. $ncx += $innerw- $ntw;
  17461. }
  17462. $this->x = $ncx ;
  17463. $this->_tableWrite($this->table[($level+1)][$objattr['nestedcontent']]);
  17464. $this->cellBorderBuffer = $save_buffer;
  17465. $this->x = $bak_x ;
  17466. $this->divwidth = $save_dw;
  17467. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false);
  17468. }
  17469. }
  17470. else {
  17471. /*-- END TABLES --*/
  17472. if ($is_table) { // *TABLES*
  17473. $maxWidth = $this->divwidth; // *TABLES*
  17474. } // *TABLES*
  17475. else { // *TABLES*
  17476. $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']);
  17477. } // *TABLES*
  17478. /*-- CSS-IMAGE-FLOAT --*/
  17479. // If float (already) exists at this level
  17480. if (isset($this->floatmargins['R']) && $this->y <= $this->floatmargins['R']['y1'] && $this->y >= $this->floatmargins['R']['y0']) { $maxWidth -= $this->floatmargins['R']['w']; }
  17481. if (isset($this->floatmargins['L']) && $this->y <= $this->floatmargins['L']['y1'] && $this->y >= $this->floatmargins['L']['y0']) { $maxWidth -= $this->floatmargins['L']['w']; }
  17482. /*-- END CSS-IMAGE-FLOAT --*/
  17483. list($skipln) = $this->inlineObject($objattr['type'], '', $this->y, $objattr,$this->lMargin, ($this->flowingBlockAttr['contentWidth']/$this->k), $maxWidth, $this->flowingBlockAttr['height'], false, $is_table);
  17484. // 1 -> New line needed because of width
  17485. // -1 -> Will fit width on line but NEW PAGE REQUIRED because of height
  17486. // -2 -> Will not fit on line therefore needs new line but thus NEW PAGE REQUIRED
  17487. $iby = $this->y;
  17488. $oldpage = $this->page;
  17489. $oldcol = $this->CurrCol; // mPDF 4.2
  17490. if (($skipln == 1 || $skipln == -2) && !isset($objattr['float'])) {
  17491. $this->finishFlowingBlock(false,$objattr['type']); // mPDF 4.3.003
  17492. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false); //false=newblock
  17493. }
  17494. $thispage = $this->page;
  17495. if ($this->CurrCol!=$oldcol) { $changedcol = true; } // mPDF 4.2
  17496. else { $changedcol=false; }
  17497. // mPDF 4.2 Don't if column already changed (in finishFlowingblock)
  17498. // the previous lines can already have triggered page break or column change
  17499. if (!$changedcol && $skipln <0 && $this->AcceptPageBreak() && $thispage==$oldpage) {
  17500. $this->AddPage($this->CurOrientation);
  17501. // Added to correct Images already set on line before page advanced
  17502. // i.e. if second inline image on line is higher than first and forces new page
  17503. if (count($this->objectbuffer)) {
  17504. $yadj = $iby - $this->y;
  17505. foreach($this->objectbuffer AS $ib=>$val) {
  17506. if ($this->objectbuffer[$ib]['OUTER-Y'] ) $this->objectbuffer[$ib]['OUTER-Y'] -= $yadj;
  17507. if ($this->objectbuffer[$ib]['BORDER-Y']) $this->objectbuffer[$ib]['BORDER-Y'] -= $yadj;
  17508. if ($this->objectbuffer[$ib]['INNER-Y']) $this->objectbuffer[$ib]['INNER-Y'] -= $yadj;
  17509. }
  17510. }
  17511. }
  17512. // Added to correct for OddEven Margins
  17513. if ($this->page != $oldpage) {
  17514. if (($this->page-$oldpage) % 2 == 1) { // mPDF 4.2.022
  17515. $bak_x += $this->MarginCorrection;
  17516. }
  17517. $oldpage = $this->page;
  17518. $y = $this->tMargin - $paint_ht_corr ;
  17519. $this->oldy = $this->tMargin - $paint_ht_corr ;
  17520. $old_height = 0;
  17521. }
  17522. $this->x = $bak_x;
  17523. /*-- COLUMNS --*/
  17524. // COLS
  17525. // OR COLUMN CHANGE
  17526. if ($this->CurrCol != $oldcolumn) {
  17527. if ($this->directionality == 'rtl') { // *RTL*
  17528. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  17529. } // *RTL*
  17530. else { // *RTL*
  17531. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  17532. } // *RTL*
  17533. $this->x = $bak_x;
  17534. $oldcolumn = $this->CurrCol;
  17535. $y = $this->y0 - $paint_ht_corr ;
  17536. $this->oldy = $this->y0 - $paint_ht_corr ;
  17537. $old_height = 0;
  17538. }
  17539. /*-- END COLUMNS --*/
  17540. /*-- CSS-IMAGE-FLOAT --*/
  17541. if ($objattr['type'] == 'image' && isset($objattr['float'])) {
  17542. $fy = $this->y;
  17543. // DIV TOP MARGIN/BORDER/PADDING
  17544. if ($this->flowingBlockAttr['newblock'] && ($this->flowingBlockAttr['blockstate']==1 || $this->flowingBlockAttr['blockstate']==3) && $this->flowingBlockAttr['lineCount']== 0) {
  17545. $fy += $this->blk[$this->blklvl]['margin_top'] + $this->blk[$this->blklvl]['padding_top'] + $this->blk[$this->blklvl]['border_top']['w'];
  17546. }
  17547. if ($objattr['float']=='R') {
  17548. $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']);
  17549. }
  17550. else if ($objattr['float']=='L') {
  17551. $fx = $this->lMargin + ($this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_left']);
  17552. }
  17553. $w = $objattr['width'];
  17554. $h = abs($objattr['height']);
  17555. $widthLeft = $maxWidth - ($this->flowingBlockAttr['contentWidth']/$this->k);
  17556. $maxHeight = $this->h - ($this->tMargin + $this->margin_header + $this->bMargin + 10) ;
  17557. // For Images
  17558. $extraWidth = ($objattr['border_left']['w'] + $objattr['border_right']['w'] + $objattr['margin_left']+ $objattr['margin_right']);
  17559. $extraHeight = ($objattr['border_top']['w'] + $objattr['border_bottom']['w'] + $objattr['margin_top']+ $objattr['margin_bottom']);
  17560. // mPDF 4.3.013 SVG files
  17561. if ($objattr['itype'] == 'wmf' || $objattr['itype'] == 'svg') {
  17562. $file = $objattr['file'];
  17563. $info=$this->formobjects[$file];
  17564. }
  17565. else {
  17566. $file = $objattr['file'];
  17567. $info=$this->images[$file];
  17568. }
  17569. // Automatically resize to width remaining - ********** If > maxWidth *******
  17570. // if ($w > $widthLeft) {
  17571. // $w = $widthLeft ;
  17572. // $h=abs($w*$info['h']/$info['w']);
  17573. // }
  17574. $img_w = $w - $extraWidth ;
  17575. $img_h = $h - $extraHeight ;
  17576. if ($objattr['border_left']['w']) {
  17577. $objattr['BORDER-WIDTH'] = $img_w + (($objattr['border_left']['w'] + $objattr['border_right']['w'])/2) ;
  17578. $objattr['BORDER-HEIGHT'] = $img_h + (($objattr['border_top']['w'] + $objattr['border_bottom']['w'])/2) ;
  17579. $objattr['BORDER-X'] = $fx + $objattr['margin_left'] + (($objattr['border_left']['w'])/2) ;
  17580. $objattr['BORDER-Y'] = $fy + $objattr['margin_top'] + (($objattr['border_top']['w'])/2) ;
  17581. }
  17582. $objattr['INNER-WIDTH'] = $img_w;
  17583. $objattr['INNER-HEIGHT'] = $img_h;
  17584. $objattr['INNER-X'] = $fx + $objattr['margin_left'] + ($objattr['border_left']['w']);
  17585. $objattr['INNER-Y'] = $fy + $objattr['margin_top'] + ($objattr['border_top']['w']) ;
  17586. $objattr['ID'] = $info['i'];
  17587. $objattr['OUTER-WIDTH'] = $w;
  17588. $objattr['OUTER-HEIGHT'] = $h;
  17589. $objattr['OUTER-X'] = $fx;
  17590. $objattr['OUTER-Y'] = $fy;
  17591. if ($objattr['float']=='R') {
  17592. // If R float already exists at this level
  17593. $this->floatmargins['R']['skipline'] = false; // mPDF 3.0
  17594. if (isset($this->floatmargins['R']['y1']) && $this->floatmargins['R']['y1'] > 0 && $fy < $this->floatmargins['R']['y1']) {
  17595. $this->WriteFlowingBlock($vetor[0]);
  17596. }
  17597. // If L float already exists at this level
  17598. else if (isset($this->floatmargins['L']['y1']) && $this->floatmargins['L']['y1'] > 0 && $fy < $this->floatmargins['L']['y1']) {
  17599. // Final check distance between floats is not now too narrow to fit text
  17600. $mw = $this->GetStringWidth('WW');
  17601. if (($this->blk[$this->blklvl]['inner_width'] - $w - $this->floatmargins['L']['w']) < $mw) {
  17602. $this->WriteFlowingBlock($vetor[0]);
  17603. }
  17604. else {
  17605. $this->floatmargins['R']['x'] = $fx;
  17606. $this->floatmargins['R']['w'] = $w;
  17607. $this->floatmargins['R']['y0'] = $fy;
  17608. $this->floatmargins['R']['y1'] = $fy + $h;
  17609. if ($skipln == 1) {
  17610. $this->floatmargins['R']['skipline'] = true;
  17611. $this->floatmargins['R']['id'] = count($this->floatbuffer)+0;
  17612. $objattr['skipline'] = true;
  17613. }
  17614. $this->floatbuffer[] = $objattr;
  17615. }
  17616. }
  17617. else {
  17618. $this->floatmargins['R']['x'] = $fx;
  17619. $this->floatmargins['R']['w'] = $w;
  17620. $this->floatmargins['R']['y0'] = $fy;
  17621. $this->floatmargins['R']['y1'] = $fy + $h;
  17622. if ($skipln == 1) {
  17623. $this->floatmargins['R']['skipline'] = true;
  17624. $this->floatmargins['R']['id'] = count($this->floatbuffer)+0;
  17625. $objattr['skipline'] = true;
  17626. }
  17627. $this->floatbuffer[] = $objattr;
  17628. }
  17629. }
  17630. else if ($objattr['float']=='L') {
  17631. // If L float already exists at this level
  17632. $this->floatmargins['L']['skipline'] = false; // mPDF 3.0
  17633. if (isset($this->floatmargins['L']['y1']) && $this->floatmargins['L']['y1'] > 0 && $fy < $this->floatmargins['L']['y1']) {
  17634. $this->floatmargins['L']['skipline'] = false; // mPDF 3.0
  17635. $this->WriteFlowingBlock($vetor[0]);
  17636. }
  17637. // If R float already exists at this level
  17638. else if (isset($this->floatmargins['R']['y1']) && $this->floatmargins['R']['y1'] > 0 && $fy < $this->floatmargins['R']['y1']) {
  17639. // Final check distance between floats is not now too narrow to fit text
  17640. $mw = $this->GetStringWidth('WW');
  17641. if (($this->blk[$this->blklvl]['inner_width'] - $w - $this->floatmargins['R']['w']) < $mw) {
  17642. $this->WriteFlowingBlock($vetor[0]);
  17643. }
  17644. else {
  17645. $this->floatmargins['L']['x'] = $fx + $w;
  17646. $this->floatmargins['L']['w'] = $w;
  17647. $this->floatmargins['L']['y0'] = $fy;
  17648. $this->floatmargins['L']['y1'] = $fy + $h;
  17649. if ($skipln == 1) {
  17650. $this->floatmargins['L']['skipline'] = true;
  17651. $this->floatmargins['L']['id'] = count($this->floatbuffer)+0;
  17652. $objattr['skipline'] = true;
  17653. }
  17654. $this->floatbuffer[] = $objattr;
  17655. }
  17656. }
  17657. else {
  17658. $this->floatmargins['L']['x'] = $fx + $w;
  17659. $this->floatmargins['L']['w'] = $w;
  17660. $this->floatmargins['L']['y0'] = $fy;
  17661. $this->floatmargins['L']['y1'] = $fy + $h;
  17662. if ($skipln == 1) {
  17663. $this->floatmargins['L']['skipline'] = true;
  17664. $this->floatmargins['L']['id'] = count($this->floatbuffer)+0;
  17665. $objattr['skipline'] = true;
  17666. }
  17667. $this->floatbuffer[] = $objattr;
  17668. }
  17669. }
  17670. }
  17671. else {
  17672. /*-- END CSS-IMAGE-FLOAT --*/
  17673. $this->WriteFlowingBlock($vetor[0]);
  17674. /*-- CSS-IMAGE-FLOAT --*/
  17675. }
  17676. /*-- END CSS-IMAGE-FLOAT --*/
  17677. } // *TABLES*
  17678. } // END If special content
  17679. else { //THE text
  17680. if ($this->tableLevel) { $paint_ht_corr = 0; } // To move the y up when new column/page started if div border needed
  17681. else { $paint_ht_corr = $this->blk[$this->blklvl]['border_top']['w']; }
  17682. if ($vetor[0] == "\n") { //We are reading a <BR> now turned into newline ("\n")
  17683. if ($this->flowingBlockAttr['content']) {
  17684. $this->finishFlowingBlock(false,'br'); // mPDF 4.3.003
  17685. }
  17686. else if ($is_table) {
  17687. $this->y+= $this->_computeLineheight($this->table_lineheight);
  17688. }
  17689. else if (!$is_table) {
  17690. $this->DivLn($this->lineheight);
  17691. if ($this->ColActive) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  17692. }
  17693. // Added to correct for OddEven Margins
  17694. if ($this->page != $oldpage) {
  17695. if (($this->page-$oldpage) % 2 == 1) { // mPDF 4.2.022
  17696. $bak_x += $this->MarginCorrection;
  17697. }
  17698. $oldpage = $this->page;
  17699. $y = $this->tMargin - $paint_ht_corr ;
  17700. $this->oldy = $this->tMargin - $paint_ht_corr ;
  17701. $old_height = 0;
  17702. }
  17703. $this->x = $bak_x;
  17704. /*-- COLUMNS --*/
  17705. // COLS
  17706. // OR COLUMN CHANGE
  17707. if ($this->CurrCol != $oldcolumn) {
  17708. if ($this->directionality == 'rtl') { // *RTL*
  17709. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  17710. } // *RTL*
  17711. else { // *RTL*
  17712. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  17713. } // *RTL*
  17714. $this->x = $bak_x;
  17715. $oldcolumn = $this->CurrCol;
  17716. $y = $this->y0 - $paint_ht_corr ;
  17717. $this->oldy = $this->y0 - $paint_ht_corr ;
  17718. $old_height = 0;
  17719. }
  17720. /*-- END COLUMNS --*/
  17721. $this->newFlowingBlock( $this->divwidth,$this->divheight,$align,$is_table,$is_list,$blockstate,false); // false = newblock
  17722. }
  17723. else {
  17724. $this->WriteFlowingBlock( $vetor[0]);
  17725. // Added to correct for OddEven Margins
  17726. if ($this->page != $oldpage) {
  17727. if (($this->page-$oldpage) % 2 == 1) { // mPDF 4.2.022
  17728. $bak_x += $this->MarginCorrection;
  17729. $this->x = $bak_x;
  17730. }
  17731. $oldpage = $this->page;
  17732. $y = $this->tMargin - $paint_ht_corr ;
  17733. $this->oldy = $this->tMargin - $paint_ht_corr ;
  17734. $old_height = 0;
  17735. }
  17736. /*-- COLUMNS --*/
  17737. // COLS
  17738. // OR COLUMN CHANGE
  17739. if ($this->CurrCol != $oldcolumn) {
  17740. if ($this->directionality == 'rtl') { // *RTL*
  17741. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  17742. } // *RTL*
  17743. else { // *RTL*
  17744. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  17745. } // *RTL*
  17746. $this->x = $bak_x;
  17747. $oldcolumn = $this->CurrCol;
  17748. $y = $this->y0 - $paint_ht_corr ;
  17749. $this->oldy = $this->y0 - $paint_ht_corr ;
  17750. $old_height = 0;
  17751. }
  17752. /*-- END COLUMNS --*/
  17753. }
  17754. }
  17755. //Check if it is the last element. If so then finish printing the block
  17756. if ($i == ($array_size-1)) {
  17757. $this->finishFlowingBlock(true); // true = END of flowing block
  17758. // Added to correct for OddEven Margins
  17759. if ($this->page != $oldpage) {
  17760. if (($this->page-$oldpage) % 2 == 1) { // mPDF 4.2.022
  17761. $bak_x += $this->MarginCorrection;
  17762. $this->x = $bak_x;
  17763. }
  17764. $oldpage = $this->page;
  17765. $y = $this->tMargin - $paint_ht_corr ;
  17766. $this->oldy = $this->tMargin - $paint_ht_corr ;
  17767. $old_height = 0;
  17768. }
  17769. /*-- COLUMNS --*/
  17770. // COLS
  17771. // OR COLUMN CHANGE
  17772. if ($this->CurrCol != $oldcolumn) {
  17773. if ($this->directionality == 'rtl') { // *RTL*
  17774. $bak_x -= ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap); // *RTL*
  17775. } // *RTL*
  17776. else { // *RTL*
  17777. $bak_x += ($this->CurrCol - $oldcolumn) * ($this->ColWidth+$this->ColGap);
  17778. } // *RTL*
  17779. $this->x = $bak_x;
  17780. $oldcolumn = $this->CurrCol;
  17781. $y = $this->y0 - $paint_ht_corr ;
  17782. $this->oldy = $this->y0 - $paint_ht_corr ;
  17783. $old_height = 0;
  17784. }
  17785. /*-- END COLUMNS --*/
  17786. }
  17787. // RESETTING VALUES
  17788. $this->SetTextColor(0);
  17789. $this->SetDrawColor(0);
  17790. $this->SetFillColor(255);
  17791. $this->colorarray = array();
  17792. $this->spanbgcolorarray = array();
  17793. $this->spanbgcolor = false;
  17794. $this->issetcolor = false;
  17795. $this->HREF = '';
  17796. $this->outlineparam = array();
  17797. $this->SetTextOutline(false);
  17798. $this->outline_on = false;
  17799. $this->SUP = false;
  17800. $this->SUB = false;
  17801. $this->strike = false;
  17802. $this->currentfontfamily = '';
  17803. $this->currentfontsize = '';
  17804. $this->currentfontstyle = '';
  17805. /*-- TABLES --*/
  17806. if ($this->tableLevel) {
  17807. $this->SetLineHeight('',$this->table_lineheight); // *TABLES*
  17808. }
  17809. else
  17810. /*-- END TABLES --*/
  17811. /*-- LISTS --*/
  17812. if ($is_list && $this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]) {
  17813. //$this->SetLineHeight('',$this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]); // sets default line height
  17814. // mPDF 4.2
  17815. $this->SetLineHeight('',$this->list_lineheight[$this->listlvl][$this->listOcc]); // sets default line height
  17816. }
  17817. else
  17818. /*-- END LISTS --*/
  17819. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  17820. $this->SetLineHeight('',$this->blk[$this->blklvl]['line_height']); // sets default line height
  17821. }
  17822. $this->SetStyle('B',false);
  17823. $this->SetStyle('I',false);
  17824. $this->SetStyle('U',false);
  17825. $this->toupper = false;
  17826. $this->tolower = false;
  17827. $this->SetDash(); //restore to no dash
  17828. $this->dash_on = false;
  17829. $this->dotted_on = false;
  17830. }//end of for(i=0;i<arraysize;i++)
  17831. // PAINT DIV BORDER // DISABLED IN COLUMNS AS DOESN'T WORK WHEN BROKEN ACROSS COLS??
  17832. // mPDF 3.0 Border OR background
  17833. if ((isset($this->blk[$this->blklvl]['border']) || isset($this->blk[$this->blklvl]['bgcolor'])) && $blockstate && ($this->y != $this->oldy)) {
  17834. $bottom_y = $this->y; // Does not include Bottom Margin
  17835. // mPDF 4.2 Added blockstate
  17836. if (isset($this->blk[$this->blklvl]['startpage']) && $this->blk[$this->blklvl]['startpage'] != $this->page && $blockstate != 1) {
  17837. $this->PaintDivBB('pagetop',$blockstate);
  17838. }
  17839. // mPDF 3.0
  17840. else if ($blockstate != 1) {
  17841. $this->PaintDivBB('',$blockstate);
  17842. }
  17843. $this->y = $bottom_y;
  17844. $this->x = $bak_x;
  17845. }
  17846. // Reset Font
  17847. $this->SetFontSize($this->default_font_size,false);
  17848. }
  17849. // mPDF 4.0
  17850. function _setDashBorder($style, $div, $cp, $side) {
  17851. if ($style == 'dashed' && (($side=='L' || $side=='R') || ($side=='T' && $div != 'pagetop' && !$cp) || ($side=='B' && $div!='pagebottom') )) {
  17852. $dashsize = 2; // final dash will be this + 1*linewidth
  17853. $dashsizek = 1.5; // ratio of Dash/Blank
  17854. $this->SetDash($dashsize,($dashsize/$dashsizek)+($this->LineWidth*2));
  17855. }
  17856. else if ($style == 'dotted' || ($side=='T' && ($div == 'pagetop' || $cp)) || ($side=='B' && $div == 'pagebottom')) {
  17857. //Round join and cap
  17858. $this->_out("\n".'1 J'."\n".'1 j'."\n");
  17859. $this->SetDash(0.001,($this->LineWidth*3));
  17860. }
  17861. }
  17862. // mPDF 4.0
  17863. function _setBorderLine($b, $k=1) {
  17864. $this->SetLineWidth($b['w']/$k);
  17865. $this->SetDrawColor($b['c']['R'],$b['c']['G'],$b['c']['B']);
  17866. }
  17867. // mPDF 3.0 Borders & Background
  17868. function PaintDivBB($divider='',$blockstate=0,$blvl=0) {
  17869. // Borders & backgrounds are done elsewhere for columns - messes up the repositioning in printcolumnbuffer
  17870. if ($this->ColActive) { return ; } // *COLUMNS*
  17871. $save_y = $this->y;
  17872. if (!$blvl) { $blvl = $this->blklvl; }
  17873. $x0 = $x1 = $y0 = $y1 = 0;
  17874. // Added mPDF 3.0 Float DIV
  17875. if (isset($this->blk[$blvl]['bb_painted'][$this->page]) && $this->blk[$blvl]['bb_painted'][$this->page]) { return; } // *CSS-FLOAT*
  17876. if (isset($this->blk[$blvl]['x0'])) { $x0 = $this->blk[$blvl]['x0']; } // left
  17877. if (isset($this->blk[$blvl]['y1'])) { $y1 = $this->blk[$blvl]['y1']; } // bottom
  17878. // Added mPDF 3.0 Float DIV - ensures backgrounds/borders are drawn to bottom of page
  17879. if ($y1==0) {
  17880. if ($divider=='pagebottom') { $y1 = $this->h-$this->bMargin; }
  17881. else { $y1 = $this->y; }
  17882. }
  17883. // mPDF 3.0
  17884. if (isset($this->blk[$blvl]['startpage']) && $this->blk[$blvl]['startpage'] != $this->page) { $continuingpage = true; } else { $continuingpage = false; }
  17885. if (isset($this->blk[$blvl]['y0'])) { $y0 = $this->blk[$blvl]['y0']; }
  17886. $h = $y1 - $y0;
  17887. $w = $this->blk[$blvl]['width'];
  17888. $x1 = $x0 + $w;
  17889. // Set border-widths as used here
  17890. $border_top = $this->blk[$blvl]['border_top']['w'];
  17891. $border_bottom = $this->blk[$blvl]['border_bottom']['w'];
  17892. $border_left = $this->blk[$blvl]['border_left']['w'];
  17893. $border_right = $this->blk[$blvl]['border_right']['w'];
  17894. if (!$this->blk[$blvl]['border_top'] || $divider == 'pagetop' || $continuingpage) {
  17895. $border_top = 0;
  17896. }
  17897. if (!$this->blk[$blvl]['border_bottom'] || $blockstate == 1 || $divider == 'pagebottom') {
  17898. $border_bottom = 0;
  17899. }
  17900. $brTL_H = 0;
  17901. $brTL_V = 0;
  17902. $brTR_H = 0;
  17903. $brTR_V = 0;
  17904. $brBL_H = 0;
  17905. $brBL_V = 0;
  17906. $brBR_H = 0;
  17907. $brBR_V = 0;
  17908. // mPDF 4.2
  17909. $brset = false;
  17910. /*-- BORDER-RADIUS --*/
  17911. if (isset($this->blk[$blvl]['border_radius_TL_H'])) { $brTL_H = $this->blk[$blvl]['border_radius_TL_H']; $brset = true; }
  17912. if (isset($this->blk[$blvl]['border_radius_TL_V'])) { $brTL_V = $this->blk[$blvl]['border_radius_TL_V']; $brset = true; }
  17913. if (isset($this->blk[$blvl]['border_radius_TR_H'])) { $brTR_H = $this->blk[$blvl]['border_radius_TR_H']; $brset = true; }
  17914. if (isset($this->blk[$blvl]['border_radius_TR_V'])) { $brTR_V = $this->blk[$blvl]['border_radius_TR_V']; $brset = true; }
  17915. if (isset($this->blk[$blvl]['border_radius_BR_H'])) { $brBR_H = $this->blk[$blvl]['border_radius_BR_H']; $brset = true; }
  17916. if (isset($this->blk[$blvl]['border_radius_BR_V'])) { $brBR_V = $this->blk[$blvl]['border_radius_BR_V']; $brset = true; }
  17917. if (isset($this->blk[$blvl]['border_radius_BL_H'])) { $brBL_H = $this->blk[$blvl]['border_radius_BL_H']; $brset = true; }
  17918. if (isset($this->blk[$blvl]['border_radius_BL_V'])) { $brBL_V = $this->blk[$blvl]['border_radius_BL_V']; $brset = true; }
  17919. if (!$this->blk[$blvl]['border_top'] || $divider == 'pagetop' || $continuingpage || $this->keep_block_together) {
  17920. $brTL_H = 0;
  17921. $brTL_V = 0;
  17922. $brTR_H = 0;
  17923. $brTR_V = 0;
  17924. }
  17925. if (!$this->blk[$blvl]['border_bottom'] || $blockstate == 1 || $divider == 'pagebottom' || $this->keep_block_together) {
  17926. $brBL_H = 0;
  17927. $brBL_V = 0;
  17928. $brBR_H = 0;
  17929. $brBR_V = 0;
  17930. }
  17931. // Disallow border-radius if it is smaller than the border width.
  17932. if ($brTL_H < min($border_left, $border_top)) { $brTL_H = $brTL_V = 0; }
  17933. if ($brTL_V < min($border_left, $border_top)) { $brTL_V = $brTL_H = 0; }
  17934. if ($brTR_H < min($border_right, $border_top)) { $brTR_H = $brTR_V = 0; }
  17935. if ($brTR_V < min($border_right, $border_top)) { $brTR_V = $brTR_H = 0; }
  17936. if ($brBL_H < min($border_left, $border_bottom)) { $brBL_H = $brBL_V = 0; }
  17937. if ($brBL_V < min($border_left, $border_bottom)) { $brBL_V = $brBL_H = 0; }
  17938. if ($brBR_H < min($border_right, $border_bottom)) { $brBR_H = $brBR_V = 0; }
  17939. if ($brBR_V < min($border_right, $border_bottom)) { $brBR_V = $brBR_H = 0; }
  17940. // CHECK FOR radii that sum to > width or height of div ********
  17941. $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));
  17942. if ($f < 1) {
  17943. $brTL_H *= $f;
  17944. $brTL_V *= $f;
  17945. $brTR_H *= $f;
  17946. $brTR_V *= $f;
  17947. $brBL_H *= $f;
  17948. $brBL_V *= $f;
  17949. $brBR_H *= $f;
  17950. $brBR_V *= $f;
  17951. }
  17952. /*-- END BORDER-RADIUS --*/
  17953. // BORDERS
  17954. if (isset($this->blk[$blvl]['y0']) && $this->blk[$blvl]['y0']) { $y0 = $this->blk[$blvl]['y0']; }
  17955. $h = $y1 - $y0;
  17956. $w = $this->blk[$blvl]['width'];
  17957. //if ($this->blk[$blvl]['border_top']) {
  17958. // Reinstate line above for dotted line divider when block border crosses a page
  17959. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  17960. $tbd = $this->blk[$blvl]['border_top'];
  17961. if (isset($tbd['s']) && $tbd['s']) {
  17962. // mPDF 4.0
  17963. $this->_setBorderLine($tbd);
  17964. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'T'); }
  17965. else if (($brTL_V && $brTL_H) || ($brTR_V && $brTR_H)) { $this->_out("\n".'0 J'."\n".'0 j'."\n"); } // *BORDER-RADIUS*
  17966. /*-- BORDER-RADIUS --*/
  17967. if ($brTR_H && $brTR_V) {
  17968. $this->_out($this->_EllipseArc($x0 + $w - $brTR_H, $y0 + $brTR_V, $brTR_H - $border_top/2 , $brTR_V - $border_top/2 , 1, 2, true));
  17969. }
  17970. else {
  17971. /*-- END BORDER-RADIUS --*/
  17972. $this->_out(sprintf('%.3f %.3f m ',($x0 + $w - ($border_top/2))*$this->k, ($this->h-($y0 + ($border_top/2)))*$this->k));
  17973. /*-- BORDER-RADIUS --*/
  17974. }
  17975. if ($brTL_H && $brTL_V ) {
  17976. $this->_out(sprintf('%.3f %.3f l ',($x0 + ($border_top/2) + $brTL_H )*$this->k, ($this->h-($y0 + ($border_top/2)))*$this->k));
  17977. $this->_out($this->_EllipseArc($x0 + $brTL_H, $y0 + $brTL_V, $brTL_H - $border_top/2 , $brTL_V - $border_top/2 , 2, 1));
  17978. }
  17979. else {
  17980. /*-- END BORDER-RADIUS --*/
  17981. $this->_out(sprintf('%.3f %.3f l ',($x0 + ($border_top/2))*$this->k, ($this->h-($y0 + ($border_top/2)))*$this->k));
  17982. /*-- BORDER-RADIUS --*/
  17983. }
  17984. /*-- END BORDER-RADIUS --*/
  17985. $this->_out('S');
  17986. // Reset Corners and Dash off
  17987. $this->_out("\n".'2 J'."\n".'2 j'."\n");
  17988. $this->SetDash();
  17989. }
  17990. }
  17991. //if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1) {
  17992. // Reinstate line above for dotted line divider when block border crosses a page
  17993. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  17994. $tbd = $this->blk[$blvl]['border_bottom'];
  17995. if (isset($tbd['s']) && $tbd['s']) {
  17996. // mPDF 4.0
  17997. $this->_setBorderLine($tbd);
  17998. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'B'); }
  17999. else if (($brBL_V && $brBL_H) || ($brBR_V && $brBR_H)) { $this->_out("\n".'0 J'."\n".'0 j'."\n"); } // *BORDER-RADIUS*
  18000. /*-- BORDER-RADIUS --*/
  18001. if ($brBL_H && $brBL_V) {
  18002. $this->_out($this->_EllipseArc($x0 + $brBL_H, $y0 + $h - $brBL_V, $brBL_H - $border_bottom/2 , $brBL_V - $border_bottom/2 , 3, 2, true));
  18003. }
  18004. else {
  18005. /*-- END BORDER-RADIUS --*/
  18006. $this->_out(sprintf('%.3f %.3f m ',($x0 + ($border_bottom/2))*$this->k, ($this->h-($y0 + $h - ($border_bottom/2)))*$this->k));
  18007. /*-- BORDER-RADIUS --*/
  18008. }
  18009. if ($brBR_H && $brBR_V ) {
  18010. $this->_out(sprintf('%.3f %.3f l ',($x0 + $w - ($border_bottom/2) - $brBR_H )*$this->k, ($this->h-($y0 + $h - ($border_bottom/2)))*$this->k));
  18011. $this->_out($this->_EllipseArc($x0 + $w - $brBR_H, $y0 + $h - $brBR_V, $brBR_H - $border_bottom/2 , $brBR_V - $border_bottom/2 , 4, 1));
  18012. }
  18013. else {
  18014. /*-- END BORDER-RADIUS --*/
  18015. $this->_out(sprintf('%.3f %.3f l ',($x0 + $w - ($border_bottom/2) )*$this->k, ($this->h-($y0 + $h - ($border_bottom/2)))*$this->k));
  18016. /*-- BORDER-RADIUS --*/
  18017. }
  18018. /*-- END BORDER-RADIUS --*/
  18019. $this->_out('S');
  18020. // Reset Corners and Dash off
  18021. $this->_out("\n".'2 J'."\n".'2 j'."\n");
  18022. $this->SetDash();
  18023. }
  18024. }
  18025. if ($this->blk[$blvl]['border_left']) {
  18026. $tbd = $this->blk[$blvl]['border_left'];
  18027. if (isset($tbd['s']) && $tbd['s']) {
  18028. // mPDF 4.0
  18029. $this->_setBorderLine($tbd);
  18030. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'L'); }
  18031. else if (($brTL_V && $brTL_H) || ($brBL_V && $brBL_H)) { $this->_out("\n".'0 J'."\n".'0 j'."\n"); } // *BORDER-RADIUS*
  18032. /*-- BORDER-RADIUS --*/
  18033. if ($brTL_V && $brTL_H) {
  18034. $this->_out($this->_EllipseArc($x0 + $brTL_H, $y0 + $brTL_V, $brTL_H - $border_left/2 , $brTL_V - $border_left/2, 2, 2, true));
  18035. }
  18036. else {
  18037. /*-- END BORDER-RADIUS --*/
  18038. $this->_out(sprintf('%.3f %.3f m ',($x0 + ($border_left/2))*$this->k, ($this->h-($y0 + ($border_left/2)))*$this->k));
  18039. /*-- BORDER-RADIUS --*/
  18040. }
  18041. if ($brBL_V && $brBL_H ) {
  18042. $this->_out(sprintf('%.3f %.3f l ',($x0 + ($border_left/2))*$this->k, ($this->h-($y0 + $h - ($border_left/2)- $brBL_V) )*$this->k));
  18043. $this->_out($this->_EllipseArc($x0 + $brBL_H, $y0 + $h - $brBL_V, $brBL_H - $border_left/2 , $brBL_V - $border_left/2, 3, 1));
  18044. }
  18045. else {
  18046. /*-- END BORDER-RADIUS --*/
  18047. $this->_out(sprintf('%.3f %.3f l ',($x0 + ($border_left/2))*$this->k, ($this->h-($y0 + $h - ($border_left/2)) )*$this->k));
  18048. /*-- BORDER-RADIUS --*/
  18049. }
  18050. /*-- END BORDER-RADIUS --*/
  18051. $this->_out('S');
  18052. // Reset Corners and Dash off
  18053. $this->_out("\n".'2 J'."\n".'2 j'."\n");
  18054. $this->SetDash();
  18055. }
  18056. }
  18057. if ($this->blk[$blvl]['border_right']) {
  18058. $tbd = $this->blk[$blvl]['border_right'];
  18059. if (isset($tbd['s']) && $tbd['s']) {
  18060. // mPDF 4.0
  18061. $this->_setBorderLine($tbd);
  18062. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],$divider,$continuingpage,'R'); }
  18063. else if (($brTR_V && $brTR_H) || ($brBR_V && $brBR_H)) { $this->_out("\n".'0 J'."\n".'0 j'."\n"); } // *BORDER-RADIUS*
  18064. /*-- BORDER-RADIUS --*/
  18065. if ($brBR_V && $brBR_H) {
  18066. $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));
  18067. }
  18068. else {
  18069. /*-- END BORDER-RADIUS --*/
  18070. $this->_out(sprintf('%.3f %.3f m ',($x0 + $w - ($border_right/2))*$this->k, ($this->h-($y0 + $h - ($border_right/2)))*$this->k));
  18071. /*-- BORDER-RADIUS --*/
  18072. }
  18073. if ($brTR_V && $brTR_H ) {
  18074. $this->_out(sprintf('%.3f %.3f l ',($x0 + $w - ($border_right/2))*$this->k, ($this->h-($y0 + ($border_right/2) + $brTR_V) )*$this->k));
  18075. $this->_out($this->_EllipseArc($x0 + $w - $brTR_H, $y0 + $brTR_V, $brTR_H - $border_right/2 , $brTR_V - $border_right/2, 1, 1));
  18076. }
  18077. else {
  18078. /*-- END BORDER-RADIUS --*/
  18079. $this->_out(sprintf('%.3f %.3f l ',($x0 + $w - ($border_right/2))*$this->k, ($this->h-($y0 + ($border_right/2)) )*$this->k));
  18080. /*-- BORDER-RADIUS --*/
  18081. }
  18082. /*-- END BORDER-RADIUS --*/
  18083. $this->_out('S');
  18084. // Reset Corners and Dash off
  18085. $this->_out("\n".'2 J'."\n".'2 j'."\n");
  18086. $this->SetDash();
  18087. }
  18088. }
  18089. // mPDF 4.2 DOUBLE Border
  18090. if (!$brset) { // not if border-radius used
  18091. $tbcol = array(255,255,255);
  18092. for($l=0; $l <= $blvl; $l++) {
  18093. if ($this->blk[$l]['bgcolor']) {
  18094. $tbcol = array($this->blk[$l]['bgcolorarray']['R'],$this->blk[$l]['bgcolorarray']['G'],$this->blk[$l]['bgcolorarray']['B']);
  18095. }
  18096. }
  18097. }
  18098. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  18099. $tbd = $this->blk[$blvl]['border_top'];
  18100. if (isset($tbd['s']) && $tbd['s']) {
  18101. if (!$brset && $tbd['style']=='double') {
  18102. $this->SetLineWidth($tbd['w']/3);
  18103. $this->SetDrawColor($tbcol[0],$tbcol[1],$tbcol[2]);
  18104. $this->_out(sprintf('%.3f %.3f m %.3f %.3f l S', ($x0 + $w - ($border_top/2))*$this->k, ($this->h-($y0 + ($border_top/2)))*$this->k, ($x0 + ($border_top/2))*$this->k, ($this->h-($y0 + ($border_top/2)))*$this->k ));
  18105. }
  18106. }
  18107. }
  18108. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  18109. $tbd = $this->blk[$blvl]['border_bottom'];
  18110. if (isset($tbd['s']) && $tbd['s']) {
  18111. if (!$brset && $tbd['style']=='double') {
  18112. $this->SetLineWidth($tbd['w']/3);
  18113. $this->SetDrawColor($tbcol[0],$tbcol[1],$tbcol[2]);
  18114. $this->_out(sprintf('%.3f %.3f m %.3f %.3f l S', ($x0 + ($border_bottom/2))*$this->k, ($this->h-($y0 + $h - ($border_bottom/2)))*$this->k, ($x0 + $w - ($border_bottom/2) )*$this->k, ($this->h-($y0 + $h - ($border_bottom/2)))*$this->k ));
  18115. }
  18116. }
  18117. }
  18118. if ($this->blk[$blvl]['border_left']) {
  18119. $tbd = $this->blk[$blvl]['border_left'];
  18120. if (isset($tbd['s']) && $tbd['s']) {
  18121. if (!$brset && $tbd['style']=='double') {
  18122. $this->SetLineWidth($tbd['w']/3);
  18123. $this->SetDrawColor($tbcol[0],$tbcol[1],$tbcol[2]);
  18124. $this->_out(sprintf('%.3f %.3f m %.3f %.3f l S', ($x0 + ($border_left/2))*$this->k, ($this->h-($y0 + ($border_left/2)))*$this->k, ($x0 + ($border_left/2))*$this->k, ($this->h-($y0 + $h - ($border_left/2)) )*$this->k));
  18125. }
  18126. }
  18127. }
  18128. if ($this->blk[$blvl]['border_right']) {
  18129. $tbd = $this->blk[$blvl]['border_right'];
  18130. if (isset($tbd['s']) && $tbd['s']) {
  18131. if (!$brset && $tbd['style']=='double') {
  18132. $this->SetLineWidth($tbd['w']/3);
  18133. $this->SetDrawColor($tbcol[0],$tbcol[1],$tbcol[2]);
  18134. $this->_out(sprintf('%.3f %.3f m %.3f %.3f l S', ($x0 + $w - ($border_right/2))*$this->k, ($this->h-($y0 + $h - ($border_right/2)))*$this->k, ($x0 + $w - ($border_right/2))*$this->k, ($this->h-($y0 + ($border_right/2)) )*$this->k));
  18135. }
  18136. }
  18137. }
  18138. $this->SetDash();
  18139. $this->y = $save_y;
  18140. // BACKGROUNDS are disabled in columns/kbt/headers - messes up the repositioning in printcolumnbuffer
  18141. // mPDF 4.0 Added kwt
  18142. if ($this->ColActive || $this->kwt || $this->keep_block_together) { return ; }
  18143. $bgx0 = $x0;
  18144. $bgx1 = $x1;
  18145. $bgy0 = $y0;
  18146. $bgy1 = $y1;
  18147. /*-- BORDER-RADIUS --*/
  18148. // Defined br values represent the radius of the outer curve - need to take border-width/2 from each radius for drawing the borders
  18149. if (isset($this->blk[$blvl]['background_clip']) && $this->blk[$blvl]['background_clip'] == 'padding-box') {
  18150. $brbgTL_H = max(0, $brTL_H - $this->blk[$blvl]['border_left']['w']);
  18151. $brbgTL_V = max(0, $brTL_V - $this->blk[$blvl]['border_top']['w']);
  18152. $brbgTR_H = max(0, $brTR_H - $this->blk[$blvl]['border_right']['w']);
  18153. $brbgTR_V = max(0, $brTR_V - $this->blk[$blvl]['border_top']['w']);
  18154. $brbgBL_H = max(0, $brBL_H - $this->blk[$blvl]['border_left']['w']);
  18155. $brbgBL_V = max(0, $brBL_V - $this->blk[$blvl]['border_bottom']['w']);
  18156. $brbgBR_H = max(0, $brBR_H - $this->blk[$blvl]['border_right']['w']);
  18157. $brbgBR_V = max(0, $brBR_V - $this->blk[$blvl]['border_bottom']['w']);
  18158. $bgx0 += $this->blk[$blvl]['border_left']['w'];
  18159. $bgx1 -= $this->blk[$blvl]['border_right']['w'];
  18160. if ($this->blk[$blvl]['border_top'] && $divider != 'pagetop' && !$continuingpage) {
  18161. $bgy0 += $this->blk[$blvl]['border_top']['w'];
  18162. }
  18163. if ($this->blk[$blvl]['border_bottom'] && $blockstate != 1 && $divider != 'pagebottom') {
  18164. $bgy1 -= $this->blk[$blvl]['border_bottom']['w'];
  18165. }
  18166. }
  18167. else {
  18168. /*-- END BORDER-RADIUS --*/
  18169. $brbgTL_H = $brTL_H;
  18170. $brbgTL_V = $brTL_V;
  18171. $brbgTR_H = $brTR_H;
  18172. $brbgTR_V = $brTR_V;
  18173. $brbgBL_H = $brBL_H;
  18174. $brbgBL_V = $brBL_V;
  18175. $brbgBR_H = $brBR_H;
  18176. $brbgBR_V = $brBR_V;
  18177. /*-- BORDER-RADIUS --*/
  18178. }
  18179. /*-- END BORDER-RADIUS --*/
  18180. // Set clipping path
  18181. $s = ' q 0 w '; // Line width=0
  18182. $s .= sprintf('%.3f %.3f m ', ($bgx0+$brbgTL_H )*$this->k, ($this->h-$bgy0)*$this->k); // start point TL before the arc
  18183. /*-- BORDER-RADIUS --*/
  18184. if ($brbgTL_H || $brbgTL_V) {
  18185. $s .= $this->_EllipseArc($bgx0+$brbgTL_H, $bgy0+$brbgTL_V, $brbgTL_H , $brbgTL_V , 2); // segment 2 TL
  18186. }
  18187. /*-- END BORDER-RADIUS --*/
  18188. $s .= sprintf('%.3f %.3f l ', ($bgx0)*$this->k, ($this->h-($bgy1-$brbgBL_V ))*$this->k); // line to BL
  18189. /*-- BORDER-RADIUS --*/
  18190. if ($brbgBL_H || $brbgBL_V) {
  18191. $s .= $this->_EllipseArc($bgx0+$brbgBL_H, $bgy1-$brbgBL_V, $brbgBL_H , $brbgBL_V , 3); // segment 3 BL
  18192. }
  18193. /*-- END BORDER-RADIUS --*/
  18194. $s .= sprintf('%.3f %.3f l ', ($bgx1-$brbgBR_H )*$this->k, ($this->h-($bgy1))*$this->k); // line to BR
  18195. /*-- BORDER-RADIUS --*/
  18196. if ($brbgBR_H || $brbgBR_V) {
  18197. $s .= $this->_EllipseArc($bgx1-$brbgBR_H, $bgy1-$brbgBR_V, $brbgBR_H , $brbgBR_V , 4); // segment 4 BR
  18198. }
  18199. /*-- END BORDER-RADIUS --*/
  18200. $s .= sprintf('%.3f %.3f l ', ($bgx1)*$this->k, ($this->h-($bgy0+$brbgTR_V))*$this->k); // line to TR
  18201. /*-- BORDER-RADIUS --*/
  18202. if ($brbgTR_H || $brbgTR_V) {
  18203. $s .= $this->_EllipseArc($bgx1-$brbgTR_H, $bgy0+$brbgTR_V, $brbgTR_H , $brbgTR_V , 1); // segment 1 TR
  18204. }
  18205. /*-- END BORDER-RADIUS --*/
  18206. $s .= sprintf('%.3f %.3f l ', ($bgx0+$brbgTL_H )*$this->k, ($this->h-$bgy0)*$this->k); // line to TL
  18207. $s .= ' W n '; // Ends path no-op & Sets the clipping path
  18208. if ($this->blk[$blvl]['bgcolor']) {
  18209. $this->pageBackgrounds[$blvl][] = array('x'=>$x0, 'y'=>$y0, 'w'=>$w, 'h'=>$h, 'col'=>$this->blk[$blvl]['bgcolorarray'], 'clippath'=>$s);
  18210. }
  18211. /*-- GRADIENTS --*/
  18212. if (isset($this->blk[$blvl]['gradient'])) {
  18213. $g = $this->parseBackgroundGradient($this->blk[$blvl]['gradient']);
  18214. if ($g) {
  18215. $gx = $x0;
  18216. $gy = $y0;
  18217. $this->pageBackgrounds[$blvl][] = array('gradient'=>true, 'x'=>$gx, 'y'=>$gy, 'w'=>$w, 'h'=>$h, 'gradtype'=>$g['type'], 'col'=>$g['col'], 'col2'=>$g['col2'], 'coords'=>$g['coords'], 'extend'=>$g['extend'], 'clippath'=>$s);
  18218. }
  18219. }
  18220. /*-- END GRADIENTS --*/
  18221. /*-- BACKGROUND-IMAGES --*/
  18222. if (isset($this->blk[$blvl]['background-image'])) {
  18223. $image_id = $this->blk[$blvl]['background-image']['image_id'];
  18224. $orig_w = $this->blk[$blvl]['background-image']['orig_w'];
  18225. $orig_h = $this->blk[$blvl]['background-image']['orig_h'];
  18226. $x_pos = $this->blk[$blvl]['background-image']['x_pos'];
  18227. $y_pos = $this->blk[$blvl]['background-image']['y_pos'];
  18228. $x_repeat = $this->blk[$blvl]['background-image']['x_repeat'];
  18229. $y_repeat = $this->blk[$blvl]['background-image']['y_repeat'];
  18230. $resize = $this->blk[$blvl]['background-image']['resize']; // mPDF 4.3.015
  18231. $opacity = $this->blk[$blvl]['background-image']['opacity']; // mPDF 4.3.017
  18232. $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); // mPDF 4.3.015 4.3.017
  18233. }
  18234. /*-- END BACKGROUND-IMAGES --*/
  18235. // Added mPDF 3.0 Float DIV
  18236. $this->blk[$blvl]['bb_painted'][$this->page] = true;
  18237. }
  18238. /*-- BORDER-RADIUS --*/
  18239. // mPDF 3.0
  18240. function _EllipseArc($x0, $y0, $rx, $ry, $seg = 1, $part=false, $start=false) { // Anticlockwise segment 1-4 TR-TL-BL-BR (part=1 or 2)
  18241. $s = '';
  18242. if ($rx<0) { $rx = 0; }
  18243. if ($ry<0) { $ry = 0; }
  18244. $rx *= $this->k;
  18245. $ry *= $this->k;
  18246. $astart = 0;
  18247. if ($seg == 1) { // Top Right
  18248. $afinish = 90;
  18249. $nSeg = 4;
  18250. }
  18251. else if ($seg == 2) { // Top Left
  18252. $afinish = 180;
  18253. $nSeg = 8;
  18254. }
  18255. else if ($seg == 3) { // Bottom Left
  18256. $afinish = 270;
  18257. $nSeg = 12;
  18258. }
  18259. else { // Bottom Right
  18260. $afinish = 360;
  18261. $nSeg = 16;
  18262. }
  18263. $astart = deg2rad((float) $astart);
  18264. $afinish = deg2rad((float) $afinish);
  18265. $totalAngle = $afinish - $astart;
  18266. $dt = $totalAngle / $nSeg; // segment angle
  18267. $dtm = $dt/3;
  18268. $x0 *= $this->k;
  18269. $y0 = ($this->h - $y0) * $this->k;
  18270. $t1 = $astart;
  18271. $a0 = $x0 + ($rx * cos($t1));
  18272. $b0 = $y0 + ($ry * sin($t1));
  18273. $c0 = -$rx * sin($t1);
  18274. $d0 = $ry * cos($t1);
  18275. $op = false;
  18276. for ($i = 1; $i <= $nSeg; $i++) {
  18277. // Draw this bit of the total curve
  18278. $t1 = ($i * $dt) + $astart;
  18279. $a1 = $x0 + ($rx * cos($t1));
  18280. $b1 = $y0 + ($ry * sin($t1));
  18281. $c1 = -$rx * sin($t1);
  18282. $d1 = $ry * cos($t1);
  18283. if ($i>($nSeg-4) && (!$part || ($part == 1 && $i<=$nSeg-2) || ($part == 2 && $i>$nSeg-2))) {
  18284. if ($start && !$op) {
  18285. $s .= sprintf('%.3f %.3f m ', $a0, $b0);
  18286. }
  18287. $s .= sprintf('%.3f %.3f %.3f %.3f %.3f %.3f c ', ($a0 + ($c0 * $dtm)), ($b0 + ($d0 * $dtm)), ($a1 - ($c1 * $dtm)) , ($b1 - ($d1 * $dtm)), $a1 , $b1 );
  18288. $op = true;
  18289. }
  18290. $a0 = $a1;
  18291. $b0 = $b1;
  18292. $c0 = $c1;
  18293. $d0 = $d1;
  18294. }
  18295. return $s;
  18296. }
  18297. /*-- END BORDER-RADIUS --*/
  18298. function PaintDivLnBorder($state=0,$blvl=0,$h) {
  18299. // $state = 0 normal; 1 top; 2 bottom; 3 top and bottom
  18300. $this->ColDetails[$this->CurrCol]['bottom_margin'] = $this->y + $h;
  18301. $save_y = $this->y;
  18302. $w = $this->blk[$blvl]['width'];
  18303. $x0 = $this->x; // left
  18304. $y0 = $this->y; // top
  18305. $x1 = $this->x + $w; // bottom
  18306. $y1 = $this->y + $h; // bottom
  18307. if ($this->blk[$blvl]['border_top'] && ($state==1 || $state==3)) {
  18308. $tbd = $this->blk[$blvl]['border_top'];
  18309. if (isset($tbd['s']) && $tbd['s']) {
  18310. // mPDF 4.0
  18311. $this->_setBorderLine($tbd);
  18312. $this->y = $y0 + ($tbd['w']/2);
  18313. // mPDF 4.0
  18314. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'T'); }
  18315. $this->Line($x0 + ($tbd['w']/2) , $this->y , $x0 + $w - ($tbd['w']/2), $this->y);
  18316. $this->y += $tbd['w'];
  18317. // Reset Corners and Dash off
  18318. $this->_out('2 J 2 j');
  18319. $this->SetDash();
  18320. }
  18321. }
  18322. if ($this->blk[$blvl]['border_left']) {
  18323. $tbd = $this->blk[$blvl]['border_left'];
  18324. if (isset($tbd['s']) && $tbd['s']) {
  18325. // mPDF 4.0
  18326. $this->_setBorderLine($tbd);
  18327. $this->y = $y0 + ($tbd['w']/2);
  18328. // mPDF 4.0
  18329. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'L'); }
  18330. $this->Line($x0 + ($tbd['w']/2), $this->y, $x0 + ($tbd['w']/2), $y0 + $h -($tbd['w']/2));
  18331. $this->y += $tbd['w'];
  18332. // Reset Corners and Dash off
  18333. $this->_out('2 J 2 j');
  18334. $this->SetDash();
  18335. }
  18336. }
  18337. if ($this->blk[$blvl]['border_right']) {
  18338. $tbd = $this->blk[$blvl]['border_right'];
  18339. if (isset($tbd['s']) && $tbd['s']) {
  18340. // mPDF 4.0
  18341. $this->_setBorderLine($tbd);
  18342. $this->y = $y0 + ($tbd['w']/2);
  18343. // mPDF 4.0
  18344. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'R'); }
  18345. $this->Line($x0 + $w - ($tbd['w']/2), $this->y, $x0 + $w - ($tbd['w']/2), $y0 + $h - ($tbd['w']/2));
  18346. $this->y += $tbd['w'];
  18347. // Reset Corners and Dash off
  18348. $this->_out('2 J 2 j');
  18349. $this->SetDash();
  18350. }
  18351. }
  18352. if ($this->blk[$blvl]['border_bottom'] && $state > 1) {
  18353. $tbd = $this->blk[$blvl]['border_bottom'];
  18354. if (isset($tbd['s']) && $tbd['s']) {
  18355. // mPDF 4.0
  18356. $this->_setBorderLine($tbd);
  18357. $this->y = $y0 + $h - ($tbd['w']/2);
  18358. // mPDF 4.0
  18359. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'',$continuingpage,'B'); }
  18360. $this->Line($x0 + ($tbd['w']/2) , $this->y, $x0 + $w - ($tbd['w']/2), $this->y);
  18361. $this->y += $tbd['w'];
  18362. // Reset Corners and Dash off
  18363. $this->_out('2 J 2 j');
  18364. $this->SetDash();
  18365. }
  18366. }
  18367. $this->SetDash();
  18368. $this->y = $save_y;
  18369. }
  18370. function PaintImgBorder($objattr,$is_table) {
  18371. // Borders are disabled in columns - messes up the repositioning in printcolumnbuffer
  18372. if ($this->ColActive) { return ; } // *COLUMNS*
  18373. if ($is_table) { $k = $this->shrin_k; } else { $k = 1; }
  18374. $h = $objattr['BORDER-HEIGHT'];
  18375. $w = $objattr['BORDER-WIDTH'];
  18376. $x0 = $objattr['BORDER-X'];
  18377. $y0 = $objattr['BORDER-Y'];
  18378. // BORDERS
  18379. if ($objattr['border_top']) {
  18380. $tbd = $objattr['border_top'];
  18381. if ($tbd['s']) {
  18382. // mPDF 4.0
  18383. $this->_setBorderLine($tbd,$k);
  18384. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','T'); }
  18385. $this->Line($x0, $y0, $x0 + $w, $y0);
  18386. // Reset Corners and Dash off
  18387. $this->_out('2 J 2 j');
  18388. $this->SetDash();
  18389. }
  18390. }
  18391. if ($objattr['border_left']) {
  18392. $tbd = $objattr['border_left'];
  18393. if ($tbd['s']) {
  18394. // mPDF 4.0
  18395. $this->_setBorderLine($tbd,$k);
  18396. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','L'); }
  18397. $this->Line($x0, $y0, $x0, $y0 + $h);
  18398. // Reset Corners and Dash off
  18399. $this->_out('2 J 2 j');
  18400. $this->SetDash();
  18401. }
  18402. }
  18403. if ($objattr['border_right']) {
  18404. $tbd = $objattr['border_right'];
  18405. if ($tbd['s']) {
  18406. // mPDF 4.0
  18407. $this->_setBorderLine($tbd,$k);
  18408. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','R'); }
  18409. $this->Line($x0 + $w, $y0, $x0 + $w, $y0 + $h);
  18410. // Reset Corners and Dash off
  18411. $this->_out('2 J 2 j');
  18412. $this->SetDash();
  18413. }
  18414. }
  18415. if ($objattr['border_bottom']) {
  18416. $tbd = $objattr['border_bottom'];
  18417. if ($tbd['s']) {
  18418. // mPDF 4.0
  18419. $this->_setBorderLine($tbd,$k);
  18420. if ($tbd['style']=='dotted' || $tbd['style']=='dashed') { $this->_setDashBorder($tbd['style'],'','','B'); }
  18421. $this->Line($x0, $y0 + $h, $x0 + $w, $y0 + $h);
  18422. // Reset Corners and Dash off
  18423. $this->_out('2 J 2 j');
  18424. $this->SetDash();
  18425. }
  18426. }
  18427. $this->SetDash();
  18428. }
  18429. function Reset()
  18430. {
  18431. $this->SetTextColor(0);
  18432. $this->colorarray = array();
  18433. $this->issetcolor = false;
  18434. $this->SetDrawColor(0);
  18435. $this->SetFillColor(255);
  18436. $this->spanbgcolorarray = array();
  18437. $this->spanbgcolor = false;
  18438. $this->SetStyle('B',false);
  18439. $this->SetStyle('I',false);
  18440. $this->SetStyle('U',false);
  18441. $this->HREF = '';
  18442. $this->outlineparam = array();
  18443. $this->outline_on = false;
  18444. $this->SetTextOutline(false);
  18445. $this->SUP = false;
  18446. $this->SUB = false;
  18447. $this->strike = false;
  18448. $this->SetFont($this->default_font,'',0,false);
  18449. $this->SetFontSize($this->default_font_size,false);
  18450. $this->currentfontfamily = '';
  18451. $this->currentfontsize = '';
  18452. /*-- TABLES --*/
  18453. if ($this->tableLevel) {
  18454. $this->SetLineHeight('',$this->table_lineheight); // *TABLES*
  18455. }
  18456. else
  18457. /*-- END TABLES --*/
  18458. /*-- LISTS --*/
  18459. // mPDF 4.2
  18460. if ($this->listlvl && $this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]) {
  18461. $this->SetLineHeight('',$this->list_lineheight[$this->listlvl][$this->bulletarray['occur']]); // sets default line height
  18462. }
  18463. else
  18464. /*-- END LISTS --*/
  18465. if (isset($this->blk[$this->blklvl]['line_height']) && $this->blk[$this->blklvl]['line_height']) {
  18466. $this->SetLineHeight('',$this->blk[$this->blklvl]['line_height']); // sets default line height
  18467. }
  18468. $this->toupper = false;
  18469. $this->tolower = false;
  18470. $this->SetDash(); //restore to no dash
  18471. $this->dash_on = false;
  18472. $this->dotted_on = false;
  18473. $this->divwidth = 0;
  18474. $this->divheight = 0;
  18475. $this->divalign = $this->defaultAlign;
  18476. $this->divrevert = false;
  18477. $this->oldy = -1;
  18478. $bodystyle = array();
  18479. if (isset($this->CSS['BODY']['FONT-STYLE'])) { $bodystyle['FONT-STYLE'] = $this->CSS['BODY']['FONT-STYLE']; }
  18480. if (isset($this->CSS['BODY']['FONT-WEIGHT'])) { $bodystyle['FONT-WEIGHT'] = $this->CSS['BODY']['FONT-WEIGHT']; }
  18481. if (isset($this->CSS['BODY']['COLOR'])) { $bodystyle['COLOR'] = $this->CSS['BODY']['COLOR']; }
  18482. if (isset($bodystyle)) { $this->setCSS($bodystyle,'BLOCK','BODY'); }
  18483. }
  18484. function ReadMetaTags($html)
  18485. {
  18486. // changes anykey=anyvalue to anykey="anyvalue" (only do this when this happens inside tags)
  18487. $regexp = '/ (\\w+?)=([^\\s>"]+)/si';
  18488. $html = preg_replace($regexp," \$1=\"\$2\"",$html);
  18489. if (preg_match('/<title>(.*?)<\/title>/si',$html,$m)) {
  18490. $this->SetTitle($m[1]);
  18491. }
  18492. preg_match_all('/<meta [^>]*?(name|content)="([^>]*?)" [^>]*?(name|content)="([^>]*?)".*?>/si',$html,$aux);
  18493. $firstattr = $aux[1];
  18494. $secondattr = $aux[3];
  18495. for( $i = 0 ; $i < count($aux[0]) ; $i++)
  18496. {
  18497. $name = ( strtoupper($firstattr[$i]) == "NAME" )? strtoupper($aux[2][$i]) : strtoupper($aux[4][$i]);
  18498. $content = ( strtoupper($firstattr[$i]) == "CONTENT" )? $aux[2][$i] : $aux[4][$i];
  18499. switch($name)
  18500. {
  18501. case "KEYWORDS": $this->SetKeywords($content); break;
  18502. case "AUTHOR": $this->SetAuthor($content); break;
  18503. case "DESCRIPTION": $this->SetSubject($content); break;
  18504. }
  18505. }
  18506. }
  18507. function ReadCharset($html)
  18508. {
  18509. // Charset conversion
  18510. if ($this->allow_charset_conversion) {
  18511. if (preg_match('/<head.*charset=([^\'\"\s]*).*<\/head>/si',$html,$m)) {
  18512. if (strtoupper($m[1]) != 'UTF-8') {
  18513. $this->charset_in = strtoupper($m[1]);
  18514. }
  18515. }
  18516. }
  18517. }
  18518. //////////////////
  18519. /// CSS parser ///
  18520. //////////////////
  18521. //////////////////
  18522. /// CSS parser ///
  18523. //////////////////
  18524. //////////////////
  18525. /// CSS parser ///
  18526. //////////////////
  18527. function ReadDefaultCSS($CSSstr) {
  18528. $CSS = array();
  18529. $CSSstr = preg_replace('|/\*.*?\*/|s',' ',$CSSstr);
  18530. $CSSstr = preg_replace('/[\s\n\r\t\f]/s',' ',$CSSstr);
  18531. $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s',' ',$CSSstr);
  18532. if ($CSSstr ) {
  18533. preg_match_all('/(.*?)\{(.*?)\}/',$CSSstr,$styles);
  18534. for($i=0; $i < count($styles[1]) ; $i++) {
  18535. $stylestr= trim($styles[2][$i]);
  18536. $stylearr = explode(';',$stylestr);
  18537. foreach($stylearr AS $sta) {
  18538. if (trim($sta)) {
  18539. // mPDF 3.0
  18540. // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')"
  18541. list($property,$value) = explode(':',$sta,2);
  18542. $property = trim($property);
  18543. $value = preg_replace('/\s*!important/i','',$value);
  18544. $value = trim($value);
  18545. if ($property && ($value || $value==='0')) {
  18546. $classproperties[strtoupper($property)] = $value;
  18547. }
  18548. }
  18549. }
  18550. $classproperties = $this->fixCSS($classproperties);
  18551. $tagstr = strtoupper(trim($styles[1][$i]));
  18552. $tagarr = explode(',',$tagstr);
  18553. foreach($tagarr AS $tg) {
  18554. $tags = preg_split('/\s+/',trim($tg));
  18555. $level = count($tags);
  18556. if ($level == 1) { // e.g. p or .class or #id or p.class or p#id
  18557. $t = trim($tags[0]);
  18558. if ($t) {
  18559. $tag = '';
  18560. if (preg_match('/^('.$this->allowedCSStags.')$/',$t)) { $tag= $t; }
  18561. if ($this->CSS[$tag] && $tag) { $CSS[$tag] = $this->array_merge_recursive_unique($CSS[$tag], $classproperties); }
  18562. else if ($tag) { $CSS[$tag] = $classproperties; }
  18563. }
  18564. }
  18565. }
  18566. $properties = array();
  18567. $values = array();
  18568. $classproperties = array();
  18569. }
  18570. } // end of if
  18571. return $CSS;
  18572. }
  18573. function ReadCSS($html) {
  18574. //
  18575. // This supports: .class {...} / #id { .... }
  18576. // p {...} h1[-h6] {...} a {...} table {...} thead {...} th {...} td {...} hr {...}
  18577. // body {...} sets default font and fontsize
  18578. // It supports some cascaded CSS e.g. div.topic table.type1 td
  18579. // Does not support non-block level e.g. a#hover { ... }
  18580. // mPDF 4.3.001
  18581. preg_match_all('/<style[^>]*media=["\']([^"\'>]*)["\'].*?<\/style>/is',$html,$m);
  18582. for($i=0; $i<count($m[0]); $i++) {
  18583. if ($this->CSSselectMedia && !preg_match('/('.trim($this->CSSselectMedia).'|all)/i',$m[1][$i])) {
  18584. $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html);
  18585. }
  18586. }
  18587. preg_match_all('/<link[^>]*media=["\']([^"\'>]*)["\'].*?>/is',$html,$m);
  18588. for($i=0; $i<count($m[0]); $i++) {
  18589. if ($this->CSSselectMedia && !preg_match('/('.trim($this->CSSselectMedia).'|all)/i',$m[1][$i])) {
  18590. $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html);
  18591. }
  18592. }
  18593. // mPDF 4.0
  18594. // Remove Comment tags <!-- --> inside CSS as <style> in HTML document
  18595. preg_match_all('/<style.*?>(.*?)<\/style>/si',$html,$m);
  18596. if (count($m[1])) {
  18597. for($i=0;$i<count($m[1]);$i++) {
  18598. // Remove comment tags
  18599. $sub = preg_replace('/(<\!\-\-|\-\->)/s',' ',$m[1][$i]);
  18600. $html = preg_replace('/'.preg_quote($m[1][$i], '/').'/si', $sub, $html);
  18601. }
  18602. }
  18603. // mPDF 4.0
  18604. $html = preg_replace('/<!--mpdf/i','',$html); // mPDF 3.0 changed from ereg_
  18605. $html = preg_replace('/mpdf-->/i','',$html); // mPDF 3.0 changed from ereg_
  18606. $html = preg_replace('/<\!\-\-.*?\-\->/s',' ',$html);
  18607. $match = 0; // no match for instance
  18608. $regexp = ''; // This helps debugging: showing what is the REAL string being processed
  18609. $CSSext = array();
  18610. //CSS inside external files
  18611. // mPDF 3.0 Allow single or double quotes
  18612. // mPDF 4.0 Allow >1 space or extra text after link
  18613. $regexp = '/<link[^>]*rel=["\']stylesheet["\'][^>]*href=["\']([^>"\']*)["\'].*?>/si'; // EDIT mPDF 4.0
  18614. $x = preg_match_all($regexp,$html,$cxt);
  18615. if ($x) {
  18616. $match += $x;
  18617. $CSSext = $cxt[1];
  18618. }
  18619. // mPDF 3.0 Allow single or double quotes
  18620. $regexp = '/<link[^>]*href=["\']([^>"\']*)["\'][^>]*?rel=["\']stylesheet["\'].*?>/si'; // EDIT mPDF 4.0
  18621. $x = preg_match_all($regexp,$html,$cxt);
  18622. if ($x) {
  18623. $match += $x;
  18624. $CSSext = array_merge($CSSext,$cxt[1]);
  18625. }
  18626. // look for @import stylesheets
  18627. $regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css)[\'\"]{0,1}\)/si'; // EDIT mPDF 4.0
  18628. $x = preg_match_all($regexp,$html,$cxt);
  18629. if ($x) {
  18630. $match += $x;
  18631. $CSSext = array_merge($CSSext,$cxt[1]);
  18632. }
  18633. // mPDF 4.0
  18634. // look for @import without the url()
  18635. $regexp = '/@import [\'\"]{0,1}([^;]*?\.css)[\'\"]{0,1}/si';
  18636. $x = preg_match_all($regexp,$html,$cxt);
  18637. if ($x) {
  18638. $match += $x;
  18639. $CSSext = array_merge($CSSext,$cxt[1]);
  18640. }
  18641. $ind = 0;
  18642. $CSSstr = '';
  18643. // Edited mPDF v1.4
  18644. if (!is_array($this->cascadeCSS)) $this->cascadeCSS = array();
  18645. while($match){
  18646. $path = $CSSext[$ind];
  18647. $this->GetFullPath($path); // mPDF 4.0
  18648. $CSSextblock = $this->_get_file($path);
  18649. if ($CSSextblock) {
  18650. // mPDF 4.0
  18651. // look for embedded @import stylesheets in other stylesheets
  18652. // and fix url paths (including background-images) relative to stylesheet
  18653. $regexpem = '/@import url\([\'\"]{0,1}(.*?\.css)[\'\"]{0,1}\)/si';
  18654. $xem = preg_match_all($regexpem,$CSSextblock,$cxtem);
  18655. $cssBasePath = preg_replace('/\/[^\/]*$/','',$path) . '/';
  18656. if ($xem) {
  18657. foreach($cxtem[1] AS $cxtembedded) {
  18658. // path is relative to original stlyesheet!!
  18659. $this->GetFullPath($cxtembedded, $cssBasePath );
  18660. $match++;
  18661. $CSSext[] = $cxtembedded;
  18662. }
  18663. }
  18664. $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
  18665. $xem = preg_match_all($regexpem,$CSSextblock,$cxtem);
  18666. if ($xem) {
  18667. for ($i=0;$i<count($cxtem[0]);$i++) {
  18668. // path is relative to original stlyesheet!!
  18669. $embedded = $cxtem[2][$i];
  18670. $this->GetFullPath($embedded, $cssBasePath );
  18671. $CSSextblock = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $CSSextblock);
  18672. }
  18673. }
  18674. $CSSstr .= ' '.$CSSextblock;
  18675. }
  18676. $match--;
  18677. $ind++;
  18678. } //end of match
  18679. $match = 0; // reset value, if needed
  18680. // CSS as <style> in HTML document
  18681. $regexp = '/<style.*?>(.*?)<\/style>/si';
  18682. $match = preg_match_all($regexp,$html,$CSSblock);
  18683. if ($match) {
  18684. // mPDF 4.0
  18685. $tmpCSSstr = implode(' ',$CSSblock[1]);
  18686. $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
  18687. $xem = preg_match_all($regexpem,$tmpCSSstr ,$cxtem);
  18688. if ($xem) {
  18689. for ($i=0;$i<count($cxtem[0]);$i++) {
  18690. $embedded = $cxtem[2][$i];
  18691. $this->GetFullPath($embedded);
  18692. $tmpCSSstr = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $tmpCSSstr );
  18693. }
  18694. }
  18695. $CSSstr .= ' '.$tmpCSSstr;
  18696. }
  18697. // Remove comments
  18698. $CSSstr = preg_replace('|/\*.*?\*/|s',' ',$CSSstr);
  18699. $CSSstr = preg_replace('/[\s\n\r\t\f]/s',' ',$CSSstr);
  18700. // mPDF 4.3.001
  18701. if (preg_match('/@media/',$CSSstr)) {
  18702. preg_match_all('/@media(.*?)\{(([^\{\}]*\{[^\{\}]*\})+)\s*\}/is',$CSSstr,$m);
  18703. for($i=0; $i<count($m[0]); $i++) {
  18704. if ($this->CSSselectMedia && !preg_match('/('.trim($this->CSSselectMedia).'|all)/i',$m[1][$i])) {
  18705. $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$CSSstr);
  18706. }
  18707. else {
  18708. $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/',' '.$m[2][$i].' ',$CSSstr);
  18709. }
  18710. }
  18711. }
  18712. $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s',' ',$CSSstr);
  18713. if ($CSSstr ) {
  18714. preg_match_all('/(.*?)\{(.*?)\}/',$CSSstr,$styles);
  18715. for($i=0; $i < count($styles[1]) ; $i++) {
  18716. // SET array e.g. $classproperties['COLOR'] = '#ffffff';
  18717. $stylestr= trim($styles[2][$i]);
  18718. $stylearr = explode(';',$stylestr);
  18719. foreach($stylearr AS $sta) {
  18720. if (trim($sta)) {
  18721. // mPDF 3.0
  18722. // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')"
  18723. list($property,$value) = explode(':',$sta,2);
  18724. $property = trim($property);
  18725. $value = preg_replace('/\s*!important/i','',$value);
  18726. $value = trim($value);
  18727. if ($property && ($value || $value==='0')) {
  18728. $classproperties[strtoupper($property)] = $value;
  18729. }
  18730. }
  18731. }
  18732. $classproperties = $this->fixCSS($classproperties);
  18733. $tagstr = strtoupper(trim($styles[1][$i]));
  18734. $tagarr = explode(',',$tagstr);
  18735. $pageselectors = false; // used to turn on $this->mirrorMargins
  18736. foreach($tagarr AS $tg) {
  18737. $tags = preg_split('/\s+/',trim($tg));
  18738. $level = count($tags);
  18739. $t = '';
  18740. $t2 = '';
  18741. $t3 = '';
  18742. if (trim($tags[0])=='@PAGE') {
  18743. if (isset($tags[0])) { $t = trim($tags[0]); }
  18744. if (isset($tags[1])) { $t2 = trim($tags[1]); }
  18745. if (isset($tags[2])) { $t3 = trim($tags[2]); }
  18746. $tag = '';
  18747. if ($level==1) { $tag = $t; }
  18748. else if ($level==2 && preg_match('/^[:](.*)$/',$t2,$m)) {
  18749. $tag = $t.'>>PSEUDO>>'.$m[1];
  18750. if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mirrorMargins
  18751. }
  18752. else if ($level==2) { $tag = $t.'>>NAMED>>'.$t2; }
  18753. else if ($level==3 && preg_match('/^[:](.*)$/',$t3,$m)) {
  18754. $tag = $t.'>>NAMED>>'.$t2.'>>PSEUDO>>'.$m[1];
  18755. if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mirrorMargins
  18756. }
  18757. if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); }
  18758. else if ($tag) { $this->CSS[$tag] = $classproperties; }
  18759. }
  18760. else if ($level == 1) { // e.g. p or .class or #id or p.class or p#id
  18761. if (isset($tags[0])) { $t = trim($tags[0]); }
  18762. if ($t) {
  18763. $tag = '';
  18764. if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; }
  18765. else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; }
  18766. else if (preg_match('/^('.$this->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; }
  18767. else if (preg_match('/^('.$this->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; }
  18768. else if (preg_match('/^('.$this->allowedCSStags.')$/',$t)) { $tag= $t; }
  18769. if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); }
  18770. else if ($tag) { $this->CSS[$tag] = $classproperties; }
  18771. }
  18772. }
  18773. else {
  18774. $tmp = array();
  18775. for($n=0;$n<$level;$n++) {
  18776. if (isset($tags[$n])) { $t = trim($tags[$n]); }
  18777. else { $t = ''; } // mPDF 4.0
  18778. if ($t) {
  18779. $tag = '';
  18780. if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; }
  18781. else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; }
  18782. else if (preg_match('/^('.$this->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; }
  18783. else if (preg_match('/^('.$this->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; }
  18784. else if (preg_match('/^('.$this->allowedCSStags.')$/',$t)) { $tag= $t; }
  18785. if ($tag) $tmp[] = $tag;
  18786. // mPDF 4.0
  18787. else { break; }
  18788. }
  18789. }
  18790. // mPDF 4.0
  18791. if ($tag) {
  18792. $x = &$this->cascadeCSS;
  18793. foreach($tmp AS $tp) { $x = &$x[$tp]; }
  18794. $x = $this->array_merge_recursive_unique($x, $classproperties);
  18795. $x['depth'] = $level;
  18796. }
  18797. }
  18798. }
  18799. if ($pageselectors) { $this->mirrorMargins = true; }
  18800. $properties = array();
  18801. $values = array();
  18802. $classproperties = array();
  18803. }
  18804. } // end of if
  18805. //Remove CSS (tags and content), if any
  18806. $regexp = '/<style.*?>(.*?)<\/style>/si'; // it can be <style> or <style type="txt/css">
  18807. $html = preg_replace($regexp,'',$html);
  18808. //print_r($this->CSS); exit;
  18809. //print_r($this->cascadeCSS); exit;
  18810. return $html;
  18811. }
  18812. function readInlineCSS($html)
  18813. {
  18814. //Fix incomplete CSS code
  18815. $size = strlen($html)-1;
  18816. if (substr($html,$size,1) != ';') $html .= ';';
  18817. //Make CSS[Name-of-the-class] = array(key => value)
  18818. $regexp = '|\\s*?(\\S+?):(.+?);|i';
  18819. preg_match_all( $regexp, $html, $styleinfo);
  18820. $properties = $styleinfo[1];
  18821. $values = $styleinfo[2];
  18822. //Array-properties and Array-values must have the SAME SIZE!
  18823. $classproperties = array();
  18824. for($i = 0; $i < count($properties) ; $i++) $classproperties[strtoupper($properties[$i])] = trim($values[$i]);
  18825. return $this->fixCSS($classproperties);
  18826. }
  18827. function setCSS($arrayaux,$type='',$tag='') // type= INLINE | BLOCK // tag= BODY
  18828. {
  18829. if (!is_array($arrayaux)) return; //Removes PHP Warning
  18830. // Set font size first so that e.g. MARGIN 0.83em works on font size for this element
  18831. if (isset($arrayaux['FONT-SIZE'])) {
  18832. $v = $arrayaux['FONT-SIZE'];
  18833. if(is_numeric($v{0})) {
  18834. $mmsize = $this->ConvertSize($v,$this->FontSize);
  18835. $this->SetFontSize( $mmsize*($this->k),false ); //Get size in points (pt)
  18836. }
  18837. else{
  18838. $v = strtoupper($v);
  18839. // mPDF 4.0
  18840. if (isset($this->fontsizes[$v])) {
  18841. $this->SetFontSize( $this->fontsizes[$v]* $this->default_font_size,false);
  18842. }
  18843. }
  18844. if ($tag == 'BODY') { $this->SetDefaultFontSize($this->FontSizePt); }
  18845. }
  18846. /*-- UNICODE-FONTS --*/
  18847. if (isset($arrayaux['LANG']) && $this->useLang && $arrayaux['LANG'] && $this->is_MB && $arrayaux['LANG'] != $this->default_lang && ((strlen($arrayaux['LANG']) == 5 && $arrayaux['LANG'] != 'UTF-8') || strlen($arrayaux['LANG']) == 2)) {
  18848. list ($codepage,$mpdf_pdf_unifonts,$mpdf_directionality,$mpdf_jSpacing) = GetCodepage($arrayaux['LANG']);
  18849. /*-- CJK --*/
  18850. if ($codepage == 'SHIFT_JIS') { $this->SetFont('sjis',$this->currentfontstyle,0,false); }
  18851. else if ($codepage == 'UHC') { $this->SetFont('uhc',$this->currentfontstyle,0,false); }
  18852. else if ($codepage == 'BIG5') { $this->SetFont('big5',$this->currentfontstyle,0,false); }
  18853. else if ($codepage == 'GBK') { $this->SetFont('gb',$this->currentfontstyle,0,false); }
  18854. else
  18855. /*-- END CJK --*/
  18856. if ($mpdf_pdf_unifonts) { $this->RestrictUnicodeFonts($mpdf_pdf_unifonts); }
  18857. else { $this->RestrictUnicodeFonts($this->default_available_fonts ); }
  18858. if ($mpdf_directionality == 'rtl') { $this->biDirectional = true; }
  18859. if ($tag == 'BODY') {
  18860. $this->jSpacing = $mpdf_jSpacing;
  18861. $this->SetDirectionality($mpdf_directionality);
  18862. $this->currentLang = $codepage;
  18863. $this->default_lang = $codepage;
  18864. $this->default_jSpacing = $mpdf_jSpacing;
  18865. if ($mpdf_pdf_unifonts) { $this->default_available_fonts = $mpdf_pdf_unifonts; }
  18866. $this->default_dir = $mpdf_directionality;
  18867. }
  18868. else if ($type == 'BLOCK') {
  18869. $this->jSpacing = $mpdf_jSpacing;
  18870. }
  18871. else { // INLINE
  18872. if ($this->disableMultilingualJustify && $mpdf_jSpacing != $this->jSpacing && $this->blk[$this->blklvl]['align']=="J") {
  18873. $this->blk[$this->blklvl]['align']="";
  18874. }
  18875. }
  18876. }
  18877. else if ($this->useLang && $this->is_MB ) {
  18878. $this->RestrictUnicodeFonts($this->default_available_fonts );
  18879. $this->jSpacing = $this->default_jSpacing;
  18880. }
  18881. /*-- END UNICODE-FONTS --*/
  18882. // FOR INLINE and BLOCK OR 'BODY'
  18883. if (isset($arrayaux['FONT-FAMILY'])) {
  18884. $v = $arrayaux['FONT-FAMILY'];
  18885. //If it is a font list, get all font types
  18886. $aux_fontlist = explode(",",$v);
  18887. $fonttype = $aux_fontlist[0];
  18888. $fonttype = strtolower(trim($fonttype));
  18889. if(($fonttype == 'helvetica') || ($fonttype == 'arial')) { $fonttype = 'sans-serif'; }
  18890. else if($fonttype == 'helvetica-embedded') { $fonttype = 'helvetica'; }
  18891. // mPDF 4.0
  18892. else if($fonttype == 'courier-embedded') { $fonttype = 'courier'; }
  18893. else if($fonttype == 'times-embedded') { $fonttype = 'times'; }
  18894. else if($fonttype == 'times') { $fonttype = 'serif'; }
  18895. else if($fonttype == 'courier') { $fonttype = 'monospace'; }
  18896. if ($tag == 'BODY') {
  18897. $this->SetDefaultFont($fonttype);
  18898. }
  18899. $this->SetFont($fonttype,$this->currentfontstyle,0,false);
  18900. }
  18901. else {
  18902. $this->SetFont($this->currentfontfamily,$this->currentfontstyle,0,false);
  18903. }
  18904. foreach($arrayaux as $k => $v) {
  18905. if ($type != 'INLINE' && $tag != 'BODY') {
  18906. switch($k){
  18907. // BORDERS
  18908. case 'BORDER-TOP':
  18909. $this->blk[$this->blklvl]['border_top'] = $this->border_details($v);
  18910. if ($this->blk[$this->blklvl]['border_top']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  18911. break;
  18912. case 'BORDER-BOTTOM':
  18913. $this->blk[$this->blklvl]['border_bottom'] = $this->border_details($v);
  18914. if ($this->blk[$this->blklvl]['border_bottom']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  18915. break;
  18916. case 'BORDER-LEFT':
  18917. $this->blk[$this->blklvl]['border_left'] = $this->border_details($v);
  18918. if ($this->blk[$this->blklvl]['border_left']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  18919. break;
  18920. case 'BORDER-RIGHT':
  18921. $this->blk[$this->blklvl]['border_right'] = $this->border_details($v);
  18922. if ($this->blk[$this->blklvl]['border_right']['s']) { $this->blk[$this->blklvl]['border'] = 1; }
  18923. break;
  18924. // PADDING
  18925. case 'PADDING-TOP':
  18926. $this->blk[$this->blklvl]['padding_top'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18927. break;
  18928. case 'PADDING-BOTTOM':
  18929. $this->blk[$this->blklvl]['padding_bottom'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18930. break;
  18931. case 'PADDING-LEFT':
  18932. $this->blk[$this->blklvl]['padding_left'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18933. break;
  18934. case 'PADDING-RIGHT':
  18935. $this->blk[$this->blklvl]['padding_right'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18936. break;
  18937. // MARGINS
  18938. case 'MARGIN-TOP':
  18939. // mPDF 4.2 Collaspe vertical block margins
  18940. $tmp = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18941. if (isset($this->blk[$this->blklvl]['lastbottommargin'])) {
  18942. if ($tmp > $this->blk[$this->blklvl]['lastbottommargin']) {
  18943. $tmp -= $this->blk[$this->blklvl]['lastbottommargin'];
  18944. }
  18945. else {
  18946. $tmp = 0;
  18947. }
  18948. }
  18949. $this->blk[$this->blklvl]['margin_top'] = $tmp;
  18950. break;
  18951. case 'MARGIN-BOTTOM':
  18952. $this->blk[$this->blklvl]['margin_bottom'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18953. break;
  18954. case 'MARGIN-LEFT':
  18955. $this->blk[$this->blklvl]['margin_left'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18956. break;
  18957. case 'MARGIN-RIGHT':
  18958. $this->blk[$this->blklvl]['margin_right'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18959. break;
  18960. /*-- BORDER-RADIUS --*/
  18961. case 'BORDER-TOP-LEFT-RADIUS-H':
  18962. $this->blk[$this->blklvl]['border_radius_TL_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18963. break;
  18964. case 'BORDER-TOP-LEFT-RADIUS-V':
  18965. $this->blk[$this->blklvl]['border_radius_TL_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18966. break;
  18967. case 'BORDER-TOP-RIGHT-RADIUS-H':
  18968. $this->blk[$this->blklvl]['border_radius_TR_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18969. break;
  18970. case 'BORDER-TOP-RIGHT-RADIUS-V':
  18971. $this->blk[$this->blklvl]['border_radius_TR_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18972. break;
  18973. case 'BORDER-BOTTOM-LEFT-RADIUS-H':
  18974. $this->blk[$this->blklvl]['border_radius_BL_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18975. break;
  18976. case 'BORDER-BOTTOM-LEFT-RADIUS-V':
  18977. $this->blk[$this->blklvl]['border_radius_BL_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18978. break;
  18979. case 'BORDER-BOTTOM-RIGHT-RADIUS-H':
  18980. $this->blk[$this->blklvl]['border_radius_BR_H'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18981. break;
  18982. case 'BORDER-BOTTOM-RIGHT-RADIUS-V':
  18983. $this->blk[$this->blklvl]['border_radius_BR_V'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18984. break;
  18985. /*-- END BORDER-RADIUS --*/
  18986. case 'BACKGROUND-CLIP':
  18987. if (strtoupper($v) == 'PADDING-BOX') { $this->blk[$this->blklvl]['background_clip'] = 'padding-box'; }
  18988. break;
  18989. case 'PAGE-BREAK-AFTER':
  18990. if (strtoupper($v) == 'AVOID') { $this->blk[$this->blklvl]['page_break_after_avoid'] = true; }
  18991. break;
  18992. case 'WIDTH':
  18993. // mPDF 4.0 Allow em support and avoid 'auto'
  18994. if (strtoupper($v) != 'AUTO') {
  18995. $this->blk[$this->blklvl]['css_set_width'] = $this->ConvertSize($v,$this->blk[$this->blklvl-1]['inner_width'],$this->FontSize,false);
  18996. }
  18997. break;
  18998. case 'TEXT-INDENT':
  18999. // mPDF 4.0 Left as raw value (may include 1% or 2em)
  19000. $this->blk[$this->blklvl]['text_indent'] = $v;
  19001. break;
  19002. }//end of switch($k)
  19003. }
  19004. if ($type != 'INLINE') { // includes BODY tag
  19005. switch($k){
  19006. case 'MARGIN-COLLAPSE': // Custom tag to collapse margins at top and bottom of page
  19007. if (strtoupper($v) == 'COLLAPSE') { $this->blk[$this->blklvl]['margin_collapse'] = true; }
  19008. break;
  19009. case 'LINE-HEIGHT':
  19010. // mPDF 4.2
  19011. $this->blk[$this->blklvl]['line_height'] = $this->fixLineheight($v);
  19012. if (!$this->blk[$this->blklvl]['line_height'] ) { $this->blk[$this->blklvl]['line_height'] = $this->normalLineheight; }
  19013. break;
  19014. case 'TEXT-ALIGN': //left right center justify
  19015. switch (strtoupper($v)) {
  19016. case 'LEFT':
  19017. $this->blk[$this->blklvl]['align']="L";
  19018. break;
  19019. case 'CENTER':
  19020. $this->blk[$this->blklvl]['align']="C";
  19021. break;
  19022. case 'RIGHT':
  19023. $this->blk[$this->blklvl]['align']="R";
  19024. break;
  19025. case 'JUSTIFY':
  19026. $this->blk[$this->blklvl]['align']="J";
  19027. break;
  19028. }
  19029. break;
  19030. }//end of switch($k)
  19031. }
  19032. // FOR INLINE and BLOCK
  19033. switch($k){
  19034. case 'TEXT-ALIGN': //left right center justify
  19035. if (strtoupper($v) == 'NOJUSTIFY' && $this->blk[$this->blklvl]['align']=="J") {
  19036. $this->blk[$this->blklvl]['align']="";
  19037. }
  19038. break;
  19039. // bgcolor only - to stay consistent with original html2fpdf
  19040. case 'BACKGROUND':
  19041. case 'BACKGROUND-COLOR':
  19042. $cor = $this->ConvertColor($v);
  19043. if ($cor) {
  19044. // mPDF 3.0
  19045. if ($tag == 'BODY') {
  19046. $this->bodyBackgroundColor = $cor;
  19047. }
  19048. else if ($type == 'INLINE') {
  19049. $this->spanbgcolorarray = $cor;
  19050. $this->spanbgcolor = true;
  19051. }
  19052. else {
  19053. $this->blk[$this->blklvl]['bgcolorarray'] = $cor;
  19054. $this->blk[$this->blklvl]['bgcolor'] = true;
  19055. }
  19056. }
  19057. else if ($type != 'INLINE') {
  19058. // mPDF 3.0
  19059. if ($this->ColActive || $this->keep_block_together) {
  19060. $this->blk[$this->blklvl]['bgcolorarray'] = $this->blk[$this->blklvl-1]['bgcolorarray'] ;
  19061. $this->blk[$this->blklvl]['bgcolor'] = $this->blk[$this->blklvl-1]['bgcolor'] ;
  19062. }
  19063. }
  19064. break;
  19065. /*-- GRADIENTS --*/
  19066. case 'BACKGROUND-GRADIENT':
  19067. if ($type == 'BLOCK') {
  19068. $this->blk[$this->blklvl]['gradient'] = $v;
  19069. }
  19070. break;
  19071. /*-- END GRADIENTS --*/
  19072. case 'FONT-STYLE': // italic normal oblique
  19073. switch (strtoupper($v)) {
  19074. case 'ITALIC':
  19075. case 'OBLIQUE':
  19076. $this->SetStyle('I',true);
  19077. break;
  19078. case 'NORMAL':
  19079. $this->SetStyle('I',false);
  19080. break;
  19081. }
  19082. break;
  19083. case 'FONT-WEIGHT': // normal bold //Does not support: bolder, lighter, 100..900(step value=100)
  19084. switch (strtoupper($v)) {
  19085. case 'BOLD':
  19086. $this->SetStyle('B',true);
  19087. break;
  19088. case 'NORMAL':
  19089. $this->SetStyle('B',false);
  19090. break;
  19091. }
  19092. break;
  19093. case 'VERTICAL-ALIGN': //super and sub only dealt with here e.g. <SUB> and <SUP>
  19094. switch (strtoupper($v)) {
  19095. case 'SUPER':
  19096. $this->SUP=true;
  19097. break;
  19098. case 'SUB':
  19099. $this->SUB=true;
  19100. break;
  19101. }
  19102. break;
  19103. case 'TEXT-DECORATION': // none underline line-through (strikeout) //Does not support: overline, blink
  19104. if (stristr($v,'LINE-THROUGH')) {
  19105. $this->strike = true;
  19106. }
  19107. if (stristr($v,'UNDERLINE')) {
  19108. $this->SetStyle('U',true);
  19109. }
  19110. break;
  19111. case 'TEXT-TRANSFORM': // none uppercase lowercase //Does not support: capitalize
  19112. switch (strtoupper($v)) { //Not working 100%
  19113. case 'UPPERCASE':
  19114. $this->toupper=true;
  19115. break;
  19116. case 'LOWERCASE':
  19117. $this->tolower=true;
  19118. break;
  19119. case 'NONE': break;
  19120. }
  19121. break;
  19122. case 'OUTLINE-WIDTH':
  19123. switch(strtoupper($v)) {
  19124. case 'THIN': $v = '0.03em'; break;
  19125. case 'MEDIUM': $v = '0.05em'; break;
  19126. case 'THICK': $v = '0.07em'; break;
  19127. }
  19128. $this->outlineparam['WIDTH'] = $this->ConvertSize($v,$this->blk[$this->blklvl]['inner_width'],$this->FontSize);
  19129. break;
  19130. case 'OUTLINE-COLOR':
  19131. if (strtoupper($v) == 'INVERT') {
  19132. if ($this->colorarray) {
  19133. $cor = $this->colorarray;
  19134. $this->outlineparam['COLOR'] = array('R'=> (255-$cor['R']), 'G'=> (255-$cor['G']), 'B'=> (255-$cor['B']));
  19135. }
  19136. else {
  19137. $this->outlineparam['COLOR'] = array('R'=> 255, 'G'=> 255, 'B'=> 255);
  19138. }
  19139. }
  19140. else {
  19141. $cor = $this->ConvertColor($v);
  19142. if ($cor) { $this->outlineparam['COLOR'] = $cor ; }
  19143. }
  19144. break;
  19145. case 'COLOR': // font color
  19146. $cor = $this->ConvertColor($v);
  19147. if ($cor) {
  19148. $this->colorarray = $cor;
  19149. $this->SetTextColor($cor['R'],$cor['G'],$cor['B']);
  19150. $this->issetcolor = true;
  19151. }
  19152. break;
  19153. case 'DIR':
  19154. $this->biDirectional = true;
  19155. break;
  19156. }//end of switch($k)
  19157. }//end of foreach
  19158. }
  19159. function SetStyle($tag,$enable)
  19160. {
  19161. //Modify style and select corresponding font
  19162. $this->$tag+=($enable ? 1 : -1);
  19163. $style='';
  19164. //Fix some SetStyle misuse
  19165. if ($this->$tag < 0) $this->$tag = 0;
  19166. if ($this->$tag > 1) $this->$tag = 1;
  19167. foreach(array('B','I','U') as $s) {
  19168. if($this->$s>0) {
  19169. $style.=$s;
  19170. }
  19171. }
  19172. $this->currentfontstyle=$style;
  19173. $this->SetFont('',$style,0,false);
  19174. }
  19175. function GetStyle()
  19176. {
  19177. $style='';
  19178. foreach(array('B','I','U') as $s) {
  19179. if($this->$s>0) {
  19180. $style.=$s;
  19181. }
  19182. }
  19183. return($style);
  19184. }
  19185. function DisableTags($str='')
  19186. {
  19187. if ($str == '') //enable all tags
  19188. {
  19189. //Insert new supported tags in the long string below.
  19190. ///////////////////////////////////////////////////////
  19191. // Added custom tags <indexentry>
  19192. $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>";
  19193. }
  19194. else
  19195. {
  19196. $str = explode(",",$str);
  19197. foreach($str as $v) $this->enabledtags = str_replace(trim($v),'',$this->enabledtags);
  19198. }
  19199. }
  19200. /*-- TABLES --*/
  19201. // mPDF 4.2.015
  19202. function finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight) {
  19203. $af = 0; // Above font
  19204. $bf = 0; // Below font
  19205. $mta = 0; // Maximum top-aligned
  19206. $mba = 0; // Maximum bottom-aligned
  19207. if ($lhxt['BS']) {
  19208. $af = max($af, ($lhxt['BS'] - ($maxfontsize * (0.5 + $this->baselineC))));
  19209. }
  19210. if ($lhxt['M']) {
  19211. $af = max($af, ($lhxt['M'] - $maxfontsize)/2);
  19212. $bf = max($bf, ($lhxt['M'] - $maxfontsize)/2);
  19213. }
  19214. if ($lhxt['TT']) {
  19215. $bf = max($bf, ($lhxt['TT'] - $maxfontsize));
  19216. }
  19217. if ($lhxt['TB']) {
  19218. $af = max($af, ($lhxt['TB'] - $maxfontsize));
  19219. }
  19220. if ($lhxt['T']) {
  19221. $mta = max($mta, $lhxt['T']);
  19222. }
  19223. if ($lhxt['B']) {
  19224. $mba = max($mba, $lhxt['B']);
  19225. }
  19226. if ((!$lhfixed || !$forceExactLineheight) && ($af > (($maxlineHeight - $maxfontsize)/2) || $bf > (($maxlineHeight - $maxfontsize)/2))) {
  19227. $maxlineHeight = $maxfontsize + $af + $bf;
  19228. }
  19229. else if (!$lhfixed) { $af = $bf = ($maxlineHeight - $maxfontsize)/2; }
  19230. if ($mta > $maxlineHeight) {
  19231. $bf += ($mta - $maxlineHeight);
  19232. $maxlineHeight = $mta;
  19233. }
  19234. if ($mba > $maxlineHeight) {
  19235. $af += ($mba - $maxlineHeight);
  19236. $maxlineHeight = $mba;
  19237. }
  19238. return $maxlineHeight;
  19239. }
  19240. // mPDF 4.2.015
  19241. function TableWordWrap($maxwidth, $forcewrap = 0, $textbuffer = '', $def_fontsize, $returnarray=false) { // NB ** returnarray used in flowchart
  19242. $biggestword=0;
  19243. $toonarrow=false;
  19244. // Modified by Ivan Tcholakov, 28-JAN-2010.
  19245. //$curlyquote = mb_convert_encoding("\xe2\x80\x9e",$this->mb_enc,'UTF-8');
  19246. //$curlylowquote = mb_convert_encoding("\xe2\x80\x9d",$this->mb_enc,'UTF-8');
  19247. $curlyquote = api_convert_encoding("\xe2\x80\x9e",$this->mb_enc,'UTF-8');
  19248. $curlylowquote = api_convert_encoding("\xe2\x80\x9d",$this->mb_enc,'UTF-8');
  19249. //
  19250. // mPDF 3.0 Don't use ltrim as this gets rid of \n - new line from <br>
  19251. //$textbuffer[0][0] = ltrim($textbuffer[0][0]);
  19252. $textbuffer[0][0] = preg_replace('/^[ ]*/','',$textbuffer[0][0]);
  19253. if ((count($textbuffer) == 0) or ((count($textbuffer) == 1) && ($textbuffer[0][0] == ''))) { return 0; }
  19254. $text = '';
  19255. $lhfixed = false;
  19256. if (preg_match('/([0-9.,]+)mm/',$this->table_lineheight)) { $lhfixed = true; }
  19257. if ($lhfixed) { $def_lineheight = $this->_computeLineheight($this->table_lineheight, $def_fontsize);}
  19258. else { $def_lineheight = 0; }
  19259. // START OF NEW LINE
  19260. // Initialise lineheight variables
  19261. $maxfontsize = 0;
  19262. $forceExactLineheight = true;
  19263. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  19264. $maxlineHeight = $def_lineheight ;
  19265. $ch = 0;
  19266. $width = 0;
  19267. $ln = 1; // Counts line number
  19268. $mxw = $this->GetStringWidth('W'); // Keep tabs on Maxwidth of actual text
  19269. foreach ($textbuffer as $cctr=>$chunk) {
  19270. $line = $chunk[0];
  19271. //IMAGE
  19272. if (substr($line,0,3) == "\xbb\xa4\xac") { //identifier has been identified!
  19273. // mPDF 4.0
  19274. $objattr = $this->_getObjAttr($line);
  19275. if ($objattr['type'] == 'nestedtable') {
  19276. // END OF LINE
  19277. // Finalise & add lineheight
  19278. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  19279. $level = $objattr['level'];
  19280. $ih = $this->table[($level+1)][$objattr['nestedcontent']]['h']; // nested table width
  19281. $ch += $ih;
  19282. // START OF NEW LINE
  19283. // Initialise lineheight variables
  19284. $ln++;
  19285. $maxfontsize = 0;
  19286. $forceExactLineheight = true;
  19287. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  19288. $maxlineHeight = $def_lineheight ;
  19289. $width = 0;
  19290. $text = "";
  19291. continue;
  19292. }
  19293. list($skipln,$iw,$ih) = $this->inlineObject($specialcontent['type'],0,0, $objattr, $this->lMargin,$width,$maxwidth,$maxlineHeight,false,true);
  19294. if ($objattr['type'] == 'hr') {
  19295. // END OF LINE
  19296. // Finalise & add lineheight
  19297. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  19298. // Add HR height
  19299. $ch += $ih;
  19300. // START OF NEW LINE
  19301. // Initialise lineheight variables
  19302. $ln++;
  19303. $maxfontsize = 0;
  19304. $forceExactLineheight = true;
  19305. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  19306. $maxlineHeight = $def_lineheight ;
  19307. $width = 0;
  19308. $text = "";
  19309. continue;
  19310. }
  19311. if ($skipln==1 || $skipln==-2) {
  19312. // Finish last line
  19313. // END OF LINE
  19314. // Finalise & add lineheight
  19315. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  19316. // START OF NEW LINE
  19317. // Initialise lineheight variables
  19318. $maxfontsize = 0;
  19319. $forceExactLineheight = true;
  19320. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  19321. $maxlineHeight = $def_lineheight ;
  19322. $ln++;
  19323. $width = 0;
  19324. $text = "";
  19325. }
  19326. $va = $objattr['vertical-align'];
  19327. if ($va) {
  19328. $lhxt[$va] = max($lhxt[$va], $ih);
  19329. }
  19330. if ($lhfixed && $ih > $def_fontsize) { $forceExactLineheight = false; }
  19331. $maxlineHeight = max($maxlineHeight ,$ih);
  19332. $width += $iw;
  19333. continue;
  19334. }
  19335. // SET FONT SIZE/STYLE from $chunk[n]
  19336. // FONTSIZE
  19337. if(isset($chunk[11]) and $chunk[11] != '') {
  19338. if ($this->shrin_k) {
  19339. $this->SetFontSize($chunk[11]/$this->shrin_k,false);
  19340. }
  19341. else {
  19342. $this->SetFontSize($chunk[11],false);
  19343. }
  19344. }
  19345. // mPDF 3.0 Moved to after set FontSize
  19346. if ($line == "\n") {
  19347. // END OF LINE
  19348. $maxfontsize = max($maxfontsize,$this->FontSize);
  19349. $fh = $this->_computeLineheight($this->table_lineheight);
  19350. if ($lhfixed && $this->FontSize > $def_fontsize) {
  19351. $fh = $this->FontSize;
  19352. $forceExactLineheight = false;
  19353. }
  19354. $maxlineHeight = max($maxlineHeight,$fh);
  19355. // Finalise & add lineheight
  19356. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  19357. // START OF NEW LINE
  19358. // Initialise lineheight variables
  19359. $maxfontsize = 0;
  19360. $forceExactLineheight = true;
  19361. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  19362. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  19363. $ln++;
  19364. $text = "";
  19365. $width = 0;
  19366. // mPDF 3.0 Reset FontSize
  19367. if(isset($chunk[11]) and $chunk[11] != '') {
  19368. $this->SetFontSize($this->default_font_size,false);
  19369. }
  19370. continue;
  19371. }
  19372. // FONTFAMILY
  19373. if(isset($chunk[4]) and $chunk[4] != '') { $font = $this->SetFont($chunk[4],$this->FontStyle,0,false); }
  19374. // FONT STYLE B I U
  19375. if(isset($chunk[2]) and $chunk[2] != '') {
  19376. if (strpos($chunk[2],"B") !== false) $this->SetStyle('B',true);
  19377. if (strpos($chunk[2],"I") !== false) $this->SetStyle('I',true);
  19378. }
  19379. $space = $this->GetStringWidth(' ');
  19380. // Modified by Ivan Tcholakov, 28-JAN-2010.
  19381. //if (mb_substr($line,0,1,$this->mb_enc ) == ' ') { // line (chunk) starts with a space
  19382. if (api_substr($line,0,1,$this->mb_enc ) == ' ') { // line (chunk) starts with a space
  19383. //
  19384. $width += $space;
  19385. $text .= ' ';
  19386. }
  19387. // Modified by Ivan Tcholakov, 28-JAN-2010.
  19388. //if (mb_substr($line,(mb_strlen($line,$this->mb_enc )-1),1,$this->mb_enc ) == ' ') { $lsend = true; } // line (chunk) ends with a space
  19389. if (api_substr($line,(api_strlen($line,$this->mb_enc )-1),1,$this->mb_enc ) == ' ') { $lsend = true; } // line (chunk) ends with a space
  19390. //
  19391. else { $lsend = false; }
  19392. $line= trim($line); // mPDF 4.4.012
  19393. if ($line == '') { continue; }
  19394. $words = explode(' ', $line); // mPDF 4.4.012
  19395. foreach ($words as $word) {
  19396. $word = trim($word); // mPDF 4.4.012
  19397. $wordwidth = $this->GetStringWidth($word);
  19398. //maxwidth is insufficient for one word
  19399. if ($wordwidth > $maxwidth + 0.0001) {
  19400. $firstchunk=true;
  19401. while($wordwidth > $maxwidth + 0.0001) {
  19402. $chw = 0; // check width
  19403. // Modified by Ivan Tcholakov, 28-JAN-2010.
  19404. //for ( $i = 0; $i < mb_strlen($word, $this->mb_enc ); $i++ ) {
  19405. // $chw = $this->GetStringWidth(mb_substr($word,0,$i+1,$this->mb_enc ));
  19406. for ( $i = 0; $i < api_strlen($word, $this->mb_enc ); $i++ ) {
  19407. $chw = $this->GetStringWidth(api_substr($word,0,$i+1,$this->mb_enc ));
  19408. //
  19409. if ($chw > $maxwidth) {
  19410. if ($text && $firstchunk) {
  19411. // END OF LINE
  19412. // Finalise & add lineheight
  19413. $maxfontsize = max($maxfontsize,$this->FontSize);
  19414. $fh = $this->_computeLineheight($this->table_lineheight);
  19415. if ($lhfixed && $this->FontSize > $def_fontsize) {
  19416. $fh = $this->FontSize;
  19417. $forceExactLineheight = false;
  19418. }
  19419. $maxlineHeight = max($maxlineHeight,$fh);
  19420. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  19421. // START OF NEW LINE
  19422. // Initialise lineheight variables
  19423. $maxfontsize = $this->FontSize;
  19424. $forceExactLineheight = true;
  19425. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  19426. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  19427. $ln++;
  19428. }
  19429. // END OF LINE
  19430. // Finalise & add lineheight
  19431. $maxfontsize = max($maxfontsize,$this->FontSize);
  19432. $fh = $this->_computeLineheight($this->table_lineheight);
  19433. if ($lhfixed && $this->FontSize > $def_fontsize) {
  19434. $fh = $this->FontSize;
  19435. $forceExactLineheight = false;
  19436. }
  19437. $maxlineHeight = max($maxlineHeight,$fh);
  19438. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  19439. // START OF NEW LINE
  19440. // Initialise lineheight variables
  19441. $maxfontsize = $this->FontSize;
  19442. $forceExactLineheight = true;
  19443. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  19444. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  19445. $ln++;
  19446. $mxw = $maxwidth;
  19447. // Modified by Ivan Tcholakov, 28-JAN-2010.
  19448. //$text = mb_substr($word,0,$i,$this->mb_enc );
  19449. //$word = mb_substr($word,$i,mb_strlen($word, $this->mb_enc )-$i,$this->mb_enc );
  19450. $text = api_substr($word,0,$i,$this->mb_enc );
  19451. $word = api_substr($word,$i,api_strlen($word, $this->mb_enc )-$i,$this->mb_enc );
  19452. //
  19453. $wordwidth = $this->GetStringWidth($word);
  19454. $width = 0;
  19455. $firstchunk=false;
  19456. break;
  19457. }
  19458. }
  19459. // mPDF 4.2.015 to catch errors - added $i==0
  19460. // Modified by Ivan Tcholakov, 28-JAN-2010.
  19461. //if (mb_strlen($word, $this->mb_enc )<2 || $i==0) {
  19462. if (api_strlen($word, $this->mb_enc )<2 || $i==0) {
  19463. //
  19464. $wordwidth = $maxwidth - 0.0001;
  19465. if ($this->debug) { $this->Error("Table cell width calculated less than that needed for single character!"); }
  19466. }
  19467. $firstchunk=false;
  19468. }
  19469. }
  19470. // Word fits on line...
  19471. if ($width + $wordwidth < $maxwidth + 0.0001) {
  19472. $mxw = max($mxw, ($width+$wordwidth));
  19473. $width += $wordwidth + $space;
  19474. $text .= $word.' ';
  19475. }
  19476. // Word does not fit on line...
  19477. else {
  19478. $alloworphans = false;
  19479. // In case of orphan punctuation or SUB/SUP
  19480. // Strip end punctuation
  19481. // mPDF 4.2 Only allow 1 orphan character {1}
  19482. $tmp = preg_replace('/[\.),;:!?"'.$curlyquote . $curlylowquote ."\xef\xbc\x8c\xe3\x80\x82".']{1}$/','',$word);
  19483. // mPDF 4.5.012 ONLY ONE!
  19484. if ($tmp !== $word && !preg_match('/[\.),;:!?"'.$curlyquote . $curlylowquote ."\xef\xbc\x8c\xe3\x80\x82".']$/',$tmp)) {
  19485. $tmpwidth = $this->GetStringWidth($tmp);
  19486. if ($width + $tmpwidth < $maxwidth + 0.0001) { $alloworphans = true; }
  19487. }
  19488. // If line = SUB/SUP to max of orphansallowed ( $this->SUP || $this->SUB ) // mPDF 3.0
  19489. if(( (isset($chunk[5]) and $chunk[5]) || (isset($chunk[6]) and $chunk[6])) && strlen($word) <= $this->orphansAllowed) {
  19490. $alloworphans = true;
  19491. }
  19492. // if [stripped] word fits
  19493. if ($alloworphans) {
  19494. $mxw = $maxwidth;
  19495. $width += $wordwidth + $space;
  19496. $text .= $word.' ';
  19497. }
  19498. else {
  19499. /*-- HYPHENATION --*/
  19500. // mPDF 3.0 Soft Hyphens chr(173)
  19501. if (($this->is_MB && preg_match("/\xc2\xad/",$word)) || (!$this->is_MB && preg_match("/".chr(173)."/",$word) && ($this->FontFamily!='symbol' && $this->FontFamily!='zapfdingbats')) ) {
  19502. list($success,$pre,$post,$prelength) = $this->softHyphenate($word, ($maxwidth - $width));
  19503. if ($success) {
  19504. $text .= $pre.'-';
  19505. $word = $post;
  19506. $wordwidth = $this->GetStringWidth($word);
  19507. }
  19508. }
  19509. else if ($this->hyphenate || ($this->hyphenateTables)) {
  19510. list($success,$pre,$post,$prelength) = $this->hyphenateWord($word, ($maxwidth - $width));
  19511. if ($success) {
  19512. $text .= $pre.'-';
  19513. $word = $post;
  19514. $wordwidth = $this->GetStringWidth($word);
  19515. }
  19516. }
  19517. /*-- END HYPHENATION --*/
  19518. // END OF LINE
  19519. // Finalise & add lineheight
  19520. $maxfontsize = max($maxfontsize,$this->FontSize);
  19521. $fh = $this->_computeLineheight($this->table_lineheight);
  19522. if ($lhfixed && $this->FontSize > $def_fontsize) {
  19523. $fh = $this->FontSize;
  19524. $forceExactLineheight = false;
  19525. }
  19526. $maxlineHeight = max($maxlineHeight,$fh);
  19527. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  19528. $mxw = $maxwidth;
  19529. // START OF NEW LINE
  19530. // Initialise lineheight variables
  19531. $maxfontsize = $this->FontSize;
  19532. $forceExactLineheight = true;
  19533. $lhxt = array('BS'=>0, 'M'=>0, 'TT'=>0, 'TB'=>0, 'T'=>0, 'B'=>0);
  19534. $maxlineHeight = $this->_computeLineheight($this->table_lineheight);
  19535. $ln++;
  19536. $width = $wordwidth + $space;
  19537. $text = $word.' ';
  19538. }
  19539. }
  19540. $maxfontsize = max($maxfontsize,$this->FontSize);
  19541. $fh = $this->_computeLineheight($this->table_lineheight);
  19542. if ($lhfixed && $this->FontSize > $def_fontsize) {
  19543. $fh = $this->FontSize;
  19544. $forceExactLineheight = false;
  19545. }
  19546. $maxlineHeight = max($maxlineHeight,$fh);
  19547. }
  19548. // End of textbuffer chunk
  19549. if (!$lsend) {
  19550. $width -= $space;
  19551. $text = rtrim($text); // mPDF 4.4.012
  19552. }
  19553. // RESET FONT SIZE/STYLE
  19554. // RESETTING VALUES
  19555. //Now we must deactivate what we have used
  19556. if(isset($chunk[2]) and $chunk[2] != '') {
  19557. $this->SetStyle('B',false);
  19558. $this->SetStyle('I',false);
  19559. }
  19560. if(isset($chunk[4]) and $chunk[4] != '') {
  19561. $this->SetFont($this->default_font,$this->FontStyle,0,false);
  19562. }
  19563. if(isset($chunk[11]) and $chunk[11] != '') {
  19564. $this->SetFontSize($this->default_font_size,false);
  19565. }
  19566. }
  19567. // Finalise lineheight if something output on line and add
  19568. if ($width) {
  19569. $ch += $this->finaliseCellLineHeight($lhxt, $maxfontsize, $maxlineHeight, $lhfixed, $forceExactLineheight);
  19570. }
  19571. if ($returnarray) { return array($ch,$ln,$mxw); }
  19572. else { return $ch; }
  19573. }
  19574. function TableCheckMinWidth(&$text, $maxwidth, $forcewrap = 0, $textbuffer = '')
  19575. {
  19576. $biggestword=0;
  19577. $toonarrow=false;
  19578. if ((count($textbuffer) == 0) or ((count($textbuffer) == 1) && ($textbuffer[0][0] == ''))) { return 0; }
  19579. foreach ($textbuffer as $chunk) {
  19580. $line = $chunk[0];
  19581. // IMAGES & FORM ELEMENTS
  19582. if (substr($line,0,3) == "\xbb\xa4\xac") { //inline object - FORM element or IMAGE!
  19583. // mPDF 4.0
  19584. $objattr = $this->_getObjAttr($line);
  19585. if ($objattr['type']!='hr' && isset($objattr['width']) && ($objattr['width']/$this->shrin_k) > ($maxwidth + 0.0001) ) {
  19586. if (($objattr['width']/$this->shrin_k) > $biggestword) { $biggestword = ($objattr['width']/$this->shrin_k); }
  19587. $toonarrow=true;
  19588. }
  19589. continue;
  19590. }
  19591. if ($line == "\n") {
  19592. continue;
  19593. }
  19594. $line = trim($line ); // mPDF 4.4.012
  19595. // SET FONT SIZE/STYLE from $chunk[n]
  19596. // FONTSIZE
  19597. if(isset($chunk[11]) and $chunk[11] != '') {
  19598. if ($this->shrin_k) {
  19599. $this->SetFontSize($chunk[11]/$this->shrin_k,false);
  19600. }
  19601. else {
  19602. $this->SetFontSize($chunk[11],false);
  19603. }
  19604. }
  19605. // FONTFAMILY
  19606. if(isset($chunk[4]) and $chunk[4] != '') { $font = $this->SetFont($chunk[4],$this->FontStyle,0,false); }
  19607. // B I U
  19608. if(isset($chunk[2]) and $chunk[2] != '') {
  19609. if (strpos($chunk[2],"B") !== false) $this->SetStyle('B',true);
  19610. if (strpos($chunk[2],"I") !== false) $this->SetStyle('I',true);
  19611. }
  19612. $words = explode(' ', $line); // mPDF 4.4.012
  19613. foreach ($words as $word) {
  19614. $word = trim($word); // mPDF 4.4.012
  19615. $wordwidth = $this->GetStringWidth($word);
  19616. //EDITEI
  19617. //Warn user that maxwidth is insufficient
  19618. if ($wordwidth > $maxwidth + 0.0001) {
  19619. if ($wordwidth > $biggestword) { $biggestword = $wordwidth; }
  19620. $toonarrow=true;
  19621. }
  19622. }
  19623. // RESET FONT SIZE/STYLE
  19624. // RESETTING VALUES
  19625. //Now we must deactivate what we have used
  19626. if(isset($chunk[2]) and $chunk[2] != '') {
  19627. $this->SetStyle('B',false);
  19628. $this->SetStyle('I',false);
  19629. }
  19630. if(isset($chunk[4]) and $chunk[4] != '') {
  19631. $this->SetFont($this->default_font,$this->FontStyle,0,false);
  19632. }
  19633. if(isset($chunk[11]) and $chunk[11] != '') {
  19634. $this->SetFontSize($this->default_font_size,false);
  19635. }
  19636. }
  19637. //Return -(wordsize) if word is bigger than maxwidth
  19638. // ADDED
  19639. if (($toonarrow) && ($this->table_error_report)) {
  19640. $this->Error("Word is too long to fit in table - ".$this->table_error_report_param);
  19641. }
  19642. if ($toonarrow) return -$biggestword;
  19643. else return 1;
  19644. }
  19645. function shrinkTable(&$table,$k) {
  19646. $table['border_spacing_H'] /= $k;
  19647. $table['border_spacing_V'] /= $k;
  19648. $table['padding']['T'] /= $k;
  19649. $table['padding']['R'] /= $k;
  19650. $table['padding']['B'] /= $k;
  19651. $table['padding']['L'] /= $k;
  19652. $table['margin']['T'] /= $k;
  19653. $table['margin']['R'] /= $k;
  19654. $table['margin']['B'] /= $k;
  19655. $table['margin']['L'] /= $k;
  19656. $table['border_details']['T']['w'] /= $k;
  19657. $table['border_details']['R']['w'] /= $k;
  19658. $table['border_details']['B']['w'] /= $k;
  19659. $table['border_details']['L']['w'] /= $k;
  19660. if (isset($table['max_cell_border_width']['T'])) $table['max_cell_border_width']['T'] /= $k;
  19661. if (isset($table['max_cell_border_width']['R'])) $table['max_cell_border_width']['R'] /= $k;
  19662. if (isset($table['max_cell_border_width']['B'])) $table['max_cell_border_width']['B'] /= $k;
  19663. if (isset($table['max_cell_border_width']['L'])) $table['max_cell_border_width']['L'] /= $k;
  19664. if ($this->simpleTables){ // mPDF 4.2.017
  19665. $table['simple']['border_details']['T']['w'] /= $k;
  19666. $table['simple']['border_details']['R']['w'] /= $k;
  19667. $table['simple']['border_details']['B']['w'] /= $k;
  19668. $table['simple']['border_details']['L']['w'] /= $k;
  19669. // mPDF 4.3.006 removed padding
  19670. }
  19671. $table['miw'] /= $k;
  19672. $table['maw'] /= $k;
  19673. // unset($table['miw']);
  19674. // unset($table['maw']);
  19675. // $table['wc'] = array_pad(array(),$table['nc'],array('miw'=>0,'maw'=>0));
  19676. for($j = 0 ; $j < $table['nc'] ; $j++ ) { //columns
  19677. $table['wc'][$j]['miw'] /= $k;
  19678. $table['wc'][$j]['maw'] /= $k;
  19679. if (isset($table['wc'][$j]['absmiw']) && $table['wc'][$j]['absmiw'] ) $table['wc'][$j]['absmiw'] /= $k;
  19680. for($i = 0 ; $i < $table['nr']; $i++ ) { //rows
  19681. $c = &$table['cells'][$i][$j];
  19682. if (isset($c) && $c) {
  19683. if (!$this->simpleTables){ // mPDF 4.2.017
  19684. if ($this->packTableData) {
  19685. // mPDF 4.3.009 Binary packed data
  19686. $cell = $this->_unpackCellBorder($c['borderbin'] );
  19687. $cell['border_details']['T']['w'] /= $k;
  19688. $cell['border_details']['R']['w'] /= $k;
  19689. $cell['border_details']['B']['w'] /= $k;
  19690. $cell['border_details']['L']['w'] /= $k;
  19691. $cell['border_details']['mbw']['TL'] /= $k;
  19692. $cell['border_details']['mbw']['TR'] /= $k;
  19693. $cell['border_details']['mbw']['BL'] /= $k;
  19694. $cell['border_details']['mbw']['BR'] /= $k;
  19695. $cell['border_details']['mbw']['LT'] /= $k;
  19696. $cell['border_details']['mbw']['LB'] /= $k;
  19697. $cell['border_details']['mbw']['RT'] /= $k;
  19698. $cell['border_details']['mbw']['RB'] /= $k;
  19699. // mPDF 4.3.009 Binary packed data
  19700. $c['borderbin'] = $this->_packCellBorder($cell);
  19701. }
  19702. else {
  19703. $c['border_details']['T']['w'] /= $k;
  19704. $c['border_details']['R']['w'] /= $k;
  19705. $c['border_details']['B']['w'] /= $k;
  19706. $c['border_details']['L']['w'] /= $k;
  19707. $c['border_details']['mbw']['TL'] /= $k;
  19708. $c['border_details']['mbw']['TR'] /= $k;
  19709. $c['border_details']['mbw']['BL'] /= $k;
  19710. $c['border_details']['mbw']['BR'] /= $k;
  19711. $c['border_details']['mbw']['LT'] /= $k;
  19712. $c['border_details']['mbw']['LB'] /= $k;
  19713. $c['border_details']['mbw']['RT'] /= $k;
  19714. $c['border_details']['mbw']['RB'] /= $k;
  19715. }
  19716. }
  19717. $c['padding']['T'] /= $k;
  19718. $c['padding']['R'] /= $k;
  19719. $c['padding']['B'] /= $k;
  19720. $c['padding']['L'] /= $k;
  19721. $c['maxs'] /= $k;
  19722. if (isset($c['w'])) { $c['w'] /= $k; }
  19723. $c['s'] /= $k;
  19724. $c['maw'] /= $k;
  19725. $c['miw'] /= $k;
  19726. if (isset($c['absmiw'])) $c['absmiw'] /= $k;
  19727. if (isset($c['nestedmaw'])) $c['nestedmaw'] /= $k;
  19728. if (isset($c['nestedmiw'])) $c['nestedmiw'] /= $k;
  19729. }
  19730. }//rows
  19731. }//columns
  19732. unset($c);
  19733. }
  19734. // mPDF 4.3.009 Binary packed data
  19735. function _packCellBorder($cell) {
  19736. if (!is_array($cell) || !isset($cell)) { return ''; }
  19737. if (!$this->packTableData) { return $cell; }
  19738. $bindata = pack("nndnnnA10nndnnnA10nndnnnA10nndnnnA10nd9",
  19739. $cell['border'],
  19740. $cell['border_details']['R']['s'],
  19741. $cell['border_details']['R']['w'],
  19742. $cell['border_details']['R']['c']['R'],
  19743. $cell['border_details']['R']['c']['G'],
  19744. $cell['border_details']['R']['c']['B'],
  19745. $cell['border_details']['R']['style'],
  19746. $cell['border_details']['R']['dom'],
  19747. $cell['border_details']['L']['s'],
  19748. $cell['border_details']['L']['w'],
  19749. $cell['border_details']['L']['c']['R'],
  19750. $cell['border_details']['L']['c']['G'],
  19751. $cell['border_details']['L']['c']['B'],
  19752. $cell['border_details']['L']['style'],
  19753. $cell['border_details']['L']['dom'],
  19754. $cell['border_details']['T']['s'],
  19755. $cell['border_details']['T']['w'],
  19756. $cell['border_details']['T']['c']['R'],
  19757. $cell['border_details']['T']['c']['G'],
  19758. $cell['border_details']['T']['c']['B'],
  19759. $cell['border_details']['T']['style'],
  19760. $cell['border_details']['T']['dom'],
  19761. $cell['border_details']['B']['s'],
  19762. $cell['border_details']['B']['w'],
  19763. $cell['border_details']['B']['c']['R'],
  19764. $cell['border_details']['B']['c']['G'],
  19765. $cell['border_details']['B']['c']['B'],
  19766. $cell['border_details']['B']['style'],
  19767. $cell['border_details']['B']['dom'],
  19768. $cell['border_details']['mbw']['BL'],
  19769. $cell['border_details']['mbw']['BR'],
  19770. $cell['border_details']['mbw']['RT'],
  19771. $cell['border_details']['mbw']['RB'],
  19772. $cell['border_details']['mbw']['TL'],
  19773. $cell['border_details']['mbw']['TR'],
  19774. $cell['border_details']['mbw']['LT'],
  19775. $cell['border_details']['mbw']['LB'],
  19776. $cell['border_details']['cellposdom']
  19777. );
  19778. return $bindata;
  19779. }
  19780. // mPDF 4.3.009 Binary packed data
  19781. function _getBorderWidths($bindata) {
  19782. if (!$bindata) { return array(0,0,0,0); }
  19783. 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']); }
  19784. $bd = unpack("nbord/nrs/drw/nrcr/nrcg/nrcb/A10rst/nrd/nls/dlw/nlcr/nlcg/nlcb/A10lst/nld/nts/dtw/ntcr/ntcg/ntcb/A10tst/ntd/nbs/dbw/nbcr/nbcg/nbcb/A10bst/nbd/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd", $bindata);
  19785. $cell['border_details']['R']['w'] = $bd['rw'];
  19786. $cell['border_details']['L']['w'] = $bd['lw'];
  19787. $cell['border_details']['T']['w'] = $bd['tw'];
  19788. $cell['border_details']['B']['w'] = $bd['bw'];
  19789. return array($bd['tw'], $bd['rw'], $bd['bw'], $bd['lw']);
  19790. }
  19791. // mPDF 4.3.009 Binary packed data
  19792. function _unpackCellBorder($bindata) {
  19793. if (!$bindata) { return array(); }
  19794. if (!$this->packTableData) { return $bindata; }
  19795. $bd = unpack("nbord/nrs/drw/nrcr/nrcg/nrcb/A10rst/nrd/nls/dlw/nlcr/nlcg/nlcb/A10lst/nld/nts/dtw/ntcr/ntcg/ntcb/A10tst/ntd/nbs/dbw/nbcr/nbcg/nbcb/A10bst/nbd/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd/", $bindata);
  19796. $cell['border'] = $bd['bord'];
  19797. $cell['border_details']['R']['s'] = $bd['rs'];
  19798. $cell['border_details']['R']['w'] = $bd['rw'];
  19799. $cell['border_details']['R']['c']['R'] = $bd['rcr'];
  19800. $cell['border_details']['R']['c']['G'] = $bd['rcg'];
  19801. $cell['border_details']['R']['c']['B'] = $bd['rcb'];
  19802. $cell['border_details']['R']['style'] = trim($bd['rst']);
  19803. $cell['border_details']['R']['dom'] = $bd['rd'];
  19804. $cell['border_details']['L']['s'] = $bd['ls'];
  19805. $cell['border_details']['L']['w'] = $bd['lw'];
  19806. $cell['border_details']['L']['c']['R'] = $bd['lcr'];
  19807. $cell['border_details']['L']['c']['G'] = $bd['lcg'];
  19808. $cell['border_details']['L']['c']['B'] = $bd['lcb'];
  19809. $cell['border_details']['L']['style'] = trim($bd['lst']);
  19810. $cell['border_details']['L']['dom'] = $bd['ld'];
  19811. $cell['border_details']['T']['s'] = $bd['ts'];
  19812. $cell['border_details']['T']['w'] = $bd['tw'];
  19813. $cell['border_details']['T']['c']['R'] = $bd['tcr'];
  19814. $cell['border_details']['T']['c']['G'] = $bd['tcg'];
  19815. $cell['border_details']['T']['c']['B'] = $bd['tcb'];
  19816. $cell['border_details']['T']['style'] = trim($bd['tst']);
  19817. $cell['border_details']['T']['dom'] = $bd['td'];
  19818. $cell['border_details']['B']['s'] = $bd['bs'];
  19819. $cell['border_details']['B']['w'] = $bd['bw'];
  19820. $cell['border_details']['B']['c']['R'] = $bd['bcr'];
  19821. $cell['border_details']['B']['c']['G'] = $bd['bcg'];
  19822. $cell['border_details']['B']['c']['B'] = $bd['bcb'];
  19823. $cell['border_details']['B']['style'] = trim($bd['bst']);
  19824. $cell['border_details']['B']['dom'] = $bd['bd'];
  19825. $cell['border_details']['mbw']['BL'] = $bd['mbl'];
  19826. $cell['border_details']['mbw']['BR'] = $bd['mbr'];
  19827. $cell['border_details']['mbw']['RT'] = $bd['mrt'];
  19828. $cell['border_details']['mbw']['RB'] = $bd['mrb'];
  19829. $cell['border_details']['mbw']['TL'] = $bd['mtl'];
  19830. $cell['border_details']['mbw']['TR'] = $bd['mtr'];
  19831. $cell['border_details']['mbw']['LT'] = $bd['mlt'];
  19832. $cell['border_details']['mbw']['LB'] = $bd['mlb'];
  19833. $cell['border_details']['cellposdom'] = $bd['cpd'];
  19834. return($cell);
  19835. }
  19836. ////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
  19837. ////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
  19838. ////////////////////////TABLE CODE (from PDFTable)/////////////////////////////////////
  19839. //table Array of (w, h, bc, nr, wc, hr, cells)
  19840. //w Width of table
  19841. //h Height of table
  19842. //nc Number column
  19843. //nr Number row
  19844. //hr List of height of each row
  19845. //wc List of width of each column
  19846. //cells List of cells of each rows, cells[i][j] is a cell in the table
  19847. function _tableColumnWidth(&$table,$firstpass=false){
  19848. $cs = &$table['cells'];
  19849. $nc = $table['nc'];
  19850. $nr = $table['nr'];
  19851. $listspan = array();
  19852. if ($table['borders_separate']) {
  19853. $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'];
  19854. }
  19855. else { $tblbw = $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2 + $table['margin']['L'] + $table['margin']['R']; }
  19856. // mPDF 4.2
  19857. $longCJK = false;
  19858. // ADDED table['l'][colno]
  19859. // = total length of text approx (using $c['s']) in that column - used to approximately distribute col widths in _tableWidth
  19860. //
  19861. for($j = 0 ; $j < $nc ; $j++ ) { //columns
  19862. $wc = &$table['wc'][$j];
  19863. for($i = 0 ; $i < $nr ; $i++ ) { //rows
  19864. if (isset($cs[$i][$j]) && $cs[$i][$j]) {
  19865. $c = &$cs[$i][$j];
  19866. // mPDF 4.3.006
  19867. if ($this->simpleTables){
  19868. if ($table['borders_separate']) { // NB twice border width
  19869. $extrcw = $table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'] + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
  19870. }
  19871. else {
  19872. $extrcw = $table['simple']['border_details']['L']['w']/2 + $table['simple']['border_details']['R']['w']/2 + $c['padding']['L'] + $c['padding']['R'];
  19873. }
  19874. }
  19875. else {
  19876. // mPDF 4.3.009
  19877. if ($this->packTableData) {
  19878. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  19879. }
  19880. else {
  19881. $br = $c['border_details']['R']['w'];
  19882. $bl = $c['border_details']['L']['w'];
  19883. }
  19884. if ($table['borders_separate']) { // NB twice border width
  19885. $extrcw = $bl + $br + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
  19886. }
  19887. else {
  19888. $extrcw = $bl/2 + $br/2 + $c['padding']['L'] + $c['padding']['R'];
  19889. }
  19890. }
  19891. // mPDF 3.0
  19892. //$mw = $this->GetStringWidth('W') + $extrcw ;
  19893. $mw = 0;
  19894. $c['absmiw'] = $mw;
  19895. if (isset($c['R']) && $c['R']) {
  19896. $c['maw'] = $c['miw'] = $this->FontSize + $extrcw ;
  19897. if (isset($c['w'])) { // If cell width is specified
  19898. if ($c['miw'] <$c['w']) { $c['miw'] = $c['w']; }
  19899. }
  19900. if (!isset($c['colspan'])) {
  19901. if ($wc['miw'] < $c['miw']) { $wc['miw'] = $c['miw']; }
  19902. if ($wc['maw'] < $c['maw']) { $wc['maw'] = $c['maw']; }
  19903. if ($firstpass) {
  19904. if (isset($table['l'][$j]) ) {
  19905. $table['l'][$j] += $c['miw'] ;
  19906. }
  19907. else {
  19908. $table['l'][$j] = $c['miw'] ;
  19909. }
  19910. }
  19911. }
  19912. if ($c['miw'] > $wc['miw']) { $wc['miw'] = $c['miw']; }
  19913. if ($wc['miw'] > $wc['maw']) { $wc['maw'] = $wc['miw']; }
  19914. continue;
  19915. }
  19916. if ($firstpass) {
  19917. if (isset($c['s'])) { $c['s'] += $extrcw; }
  19918. if (isset($c['maxs'])) { $c['maxs'] += $extrcw; }
  19919. if (isset($c['nestedmiw'])) { $c['nestedmiw'] += $extrcw; }
  19920. if (isset($c['nestedmaw'])) { $c['nestedmaw'] += $extrcw; }
  19921. }
  19922. // If minimum width has already been set by a nested table or inline object (image/form), use it
  19923. if (isset($c['nestedmiw'])) { $miw = $c['nestedmiw']; }
  19924. else { $miw = $mw; }
  19925. if (isset($c['maxs']) && $c['maxs'] != '') { $c['s'] = $c['maxs']; }
  19926. // If maximum width has already been set by a nested table, use it
  19927. if (isset($c['nestedmaw'])) { $c['maw'] = $c['nestedmaw']; }
  19928. else $c['maw'] = $c['s'];
  19929. if (isset($c['nowrap']) && $c['nowrap']) { $miw = $c['maw']; }
  19930. if (isset($c['wpercent']) && $firstpass) {
  19931. if (isset($c['colspan'])) { // Not perfect - but % set on colspan is shared equally on cols.
  19932. for($k=0;$k<$c['colspan'];$k++) {
  19933. $table['wc'][($j+$k)]['wpercent'] = $c['wpercent'] / $c['colspan'];
  19934. }
  19935. }
  19936. else {
  19937. if (isset($table['w']) && $table['w']) { $c['w'] = $c['wpercent']/100 * ($table['w'] - $tblbw ); }
  19938. $wc['wpercent'] = $c['wpercent'];
  19939. }
  19940. }
  19941. if (isset($c['w'])) { // If cell width is specified
  19942. if ($miw<$c['w']) { $c['miw'] = $c['w']; } // Cell min width = that specified
  19943. if ($miw>$c['w']) { $c['miw'] = $c['w'] = $miw; } // If width specified is less than minimum allowed (W) increase it
  19944. if (!isset($wc['w'])) { $wc['w'] = 1; } // If the Col width is not specified = set it to 1
  19945. }
  19946. else { $c['miw'] = $miw; } // If cell width not specified -> set Cell min width it to minimum allowed (W)
  19947. if ($c['maw'] < $c['miw']) { $c['maw'] = $c['miw']; } // If Cell max width < Minwidth - increase it to =
  19948. if (!isset($c['colspan'])) {
  19949. if ($wc['miw'] < $c['miw']) { $wc['miw'] = $c['miw']; } // Update Col Minimum and maximum widths
  19950. if ($wc['maw'] < $c['maw']) { $wc['maw'] = $c['maw']; }
  19951. if ((isset($wc['absmiw']) && $wc['absmiw'] < $c['absmiw']) || !isset($wc['absmiw'])) { $wc['absmiw'] = $c['absmiw']; } // Update Col Minimum and maximum widths
  19952. if (isset($table['l'][$j]) ) {
  19953. $table['l'][$j] += $c['s'];
  19954. }
  19955. else {
  19956. $table['l'][$j] = $c['s'];
  19957. }
  19958. }
  19959. else {
  19960. $listspan[] = array($i,$j);
  19961. }
  19962. //Check if minimum width of the whole column is big enough for largest word to fit
  19963. $auxtext = implode("",$c['text']);
  19964. if (isset($c['textbuffer'])) {
  19965. $minwidth = $this->TableCheckMinWidth($auxtext,$wc['miw']- $extrcw ,0,$c['textbuffer']);
  19966. }
  19967. else { $minwidth = 0; }
  19968. if ($minwidth < 0) {
  19969. // mPDF 4.2
  19970. if(preg_match("/[".$this->pregCJKchars."]{10,}/u",$auxtext)) { $longCJK = true; }
  19971. //increase minimum width
  19972. if (!isset($c['colspan'])) {
  19973. $wc['miw'] = max($wc['miw'],((-$minwidth) + $extrcw) );
  19974. }
  19975. }
  19976. if (!isset($c['colspan'])) {
  19977. if ($wc['miw'] > $wc['maw']) { $wc['maw'] = $wc['miw']; } //update maximum width, if needed
  19978. }
  19979. }
  19980. unset($c);
  19981. }//rows
  19982. }//columns
  19983. // COLUMN SPANS
  19984. $wc = &$table['wc'];
  19985. foreach ($listspan as $span) {
  19986. list($i,$j) = $span;
  19987. $c = &$cs[$i][$j];
  19988. $lc = $j + $c['colspan'];
  19989. if ($lc > $nc) { $lc = $nc; }
  19990. $wis = $wisa = 0;
  19991. $was = $wasa = 0;
  19992. $list = array();
  19993. for($k=$j;$k<$lc;$k++) {
  19994. if (isset($table['l'][$k]) ) {
  19995. if ($c['R']) { $table['l'][$k] += $c['miw']/$c['colspan'] ; }
  19996. else { $table['l'][$k] += $c['s']/$c['colspan']; }
  19997. }
  19998. else {
  19999. if ($c['R']) { $table['l'][$k] = $c['miw']/$c['colspan'] ; }
  20000. else { $table['l'][$k] = $c['s']/$c['colspan']; }
  20001. }
  20002. $wis += $wc[$k]['miw'];
  20003. $was += $wc[$k]['maw'];
  20004. if (!isset($c['w'])) {
  20005. $list[] = $k;
  20006. $wisa += $wc[$k]['miw'];
  20007. $wasa += $wc[$k]['maw'];
  20008. }
  20009. }
  20010. if ($c['miw'] > $wis) {
  20011. if (!$wis) {
  20012. for($k=$j;$k<$lc;$k++) { $wc[$k]['miw'] = $c['miw']/$c['colspan']; }
  20013. }
  20014. else if (!count($list)) {
  20015. $wi = $c['miw'] - $wis;
  20016. for($k=$j;$k<$lc;$k++) { $wc[$k]['miw'] += ($wc[$k]['miw']/$wis)*$wi; }
  20017. }
  20018. else {
  20019. $wi = $c['miw'] - $wis;
  20020. foreach ($list as $k) { $wc[$k]['miw'] += ($wc[$k]['miw']/$wisa)*$wi; }
  20021. }
  20022. }
  20023. if ($c['maw'] > $was) {
  20024. if (!$wis) {
  20025. for($k=$j;$k<$lc;$k++) { $wc[$k]['maw'] = $c['maw']/$c['colspan']; }
  20026. }
  20027. else if (!count($list)) {
  20028. $wi = $c['maw'] - $was;
  20029. for($k=$j;$k<$lc;$k++) { $wc[$k]['maw'] += ($wc[$k]['maw']/$was)*$wi; }
  20030. }
  20031. else {
  20032. $wi = $c['maw'] - $was;
  20033. foreach ($list as $k) { $wc[$k]['maw'] += ($wc[$k]['maw']/$wasa)*$wi; }
  20034. }
  20035. }
  20036. unset($c);
  20037. }
  20038. $checkminwidth = 0;
  20039. $checkmaxwidth = 0;
  20040. $totallength = 0;
  20041. for( $i = 0 ; $i < $nc ; $i++ ) {
  20042. $checkminwidth += $table['wc'][$i]['miw'];
  20043. $checkmaxwidth += $table['wc'][$i]['maw'];
  20044. $totallength += $table['l'][$i];
  20045. }
  20046. if (!isset($table['w']) && $firstpass) {
  20047. $sumpc = 0;
  20048. // mPDF 3.2
  20049. $notset = 0;
  20050. for( $i = 0 ; $i < $nc ; $i++ ) {
  20051. if (isset($table['wc'][$i]['wpercent']) && $table['wc'][$i]['wpercent']) {
  20052. $sumpc += $table['wc'][$i]['wpercent'];
  20053. }
  20054. // mPDF 3.2
  20055. else { $notset++; }
  20056. }
  20057. // mPDF 3.2 If sum of widths as % >= 100% and not all columns are set
  20058. // Set a nominal width of 1% for unset columns
  20059. if ($sumpc >= 100 && $notset) {
  20060. for( $i = 0 ; $i < $nc ; $i++ ) {
  20061. if ((!isset($table['wc'][$i]['wpercent']) || !$table['wc'][$i]['wpercent']) &&
  20062. (!isset($table['wc'][$i]['w']) || !$table['wc'][$i]['w'])) {
  20063. $table['wc'][$i]['wpercent'] = 1;
  20064. }
  20065. }
  20066. }
  20067. if ($sumpc) { // if any percents are set
  20068. // mPDF 4.0
  20069. $sumnonpc = (100 - $sumpc);
  20070. $sumpc = max($sumpc,100);
  20071. $miwleft = 0;
  20072. $miwleftcount = 0;
  20073. $miwsurplusnonpc = 0;
  20074. $maxcalcmiw = 0;
  20075. $mawleft = 0;
  20076. $mawleftcount = 0;
  20077. $mawsurplusnonpc = 0;
  20078. $maxcalcmaw = 0;
  20079. for( $i = 0 ; $i < $nc ; $i++ ) {
  20080. if (isset($table['wc'][$i]['wpercent'])) {
  20081. $maxcalcmiw = max($maxcalcmiw, ($table['wc'][$i]['miw'] * $sumpc /$table['wc'][$i]['wpercent']) );
  20082. $maxcalcmaw = max($maxcalcmaw, ($table['wc'][$i]['maw'] * $sumpc /$table['wc'][$i]['wpercent']) );
  20083. }
  20084. else {
  20085. $miwleft += $table['wc'][$i]['miw'];
  20086. $mawleft += $table['wc'][$i]['maw'];
  20087. if (!isset($table['wc'][$i]['w'])) { $miwleftcount++; $mawleftcount++; }
  20088. }
  20089. }
  20090. if ($miwleft && $sumnonpc > 0) { $miwnon = $miwleft * 100 / $sumnonpc; }
  20091. if ($mawleft && $sumnonpc > 0) { $mawnon = $mawleft * 100 / $sumnonpc; }
  20092. if (($miwnon > $checkminwidth || $maxcalcmiw > $checkminwidth) && $this->keep_table_proportions) {
  20093. if ($miwnon > $maxcalcmiw) {
  20094. $miwsurplusnonpc = round((($miwnon * $sumnonpc / 100) - $miwleft),3);
  20095. $checkminwidth = $miwnon;
  20096. }
  20097. else { $checkminwidth = $maxcalcmiw; }
  20098. for( $i = 0 ; $i < $nc ; $i++ ) {
  20099. if (isset($table['wc'][$i]['wpercent'])) {
  20100. $newmiw = $checkminwidth * $table['wc'][$i]['wpercent']/100;
  20101. if ($table['wc'][$i]['miw'] < $newmiw) {
  20102. $table['wc'][$i]['miw'] = $newmiw;
  20103. }
  20104. $table['wc'][$i]['w'] = 1;
  20105. }
  20106. else if ($miwsurplusnonpc && !$table['wc'][$i]['w']) {
  20107. $table['wc'][$i]['miw'] += $miwsurplusnonpc / $miwleftcount;
  20108. }
  20109. }
  20110. }
  20111. if (($mawnon > $checkmaxwidth || $maxcalcmaw > $checkmaxwidth )) {
  20112. if ($mawnon > $maxcalcmaw) {
  20113. $mawsurplusnonpc = round((($mawnon * $sumnonpc / 100) - $mawleft),3);
  20114. $checkmaxwidth = $mawnon;
  20115. }
  20116. else { $checkmaxwidth = $maxcalcmaw; }
  20117. for( $i = 0 ; $i < $nc ; $i++ ) {
  20118. if (isset($table['wc'][$i]['wpercent'])) {
  20119. $newmaw = $checkmaxwidth * $table['wc'][$i]['wpercent']/100;
  20120. if ($table['wc'][$i]['maw'] < $newmaw) {
  20121. $table['wc'][$i]['maw'] = $newmaw;
  20122. }
  20123. $table['wc'][$i]['w'] = 1;
  20124. }
  20125. else if ($mawsurplusnonpc && !$table['wc'][$i]['w']) {
  20126. $table['wc'][$i]['maw'] += $mawsurplusnonpc / $mawleftcount;
  20127. }
  20128. if ($table['wc'][$i]['maw'] < $table['wc'][$i]['miw']) { $table['wc'][$i]['maw'] = $table['wc'][$i]['miw']; }
  20129. }
  20130. }
  20131. if ($checkminwidth > $checkmaxwidth) { $checkmaxwidth = $checkminwidth; }
  20132. }
  20133. }
  20134. if (isset($table['wpercent']) && $table['wpercent']) {
  20135. $checkminwidth *= (100 / $table['wpercent']);
  20136. $checkmaxwidth *= (100 / $table['wpercent']);
  20137. }
  20138. $checkminwidth += $tblbw ;
  20139. $checkmaxwidth += $tblbw ;
  20140. // Table['miw'] set by percent in first pass may be larger than sum of column miw
  20141. if ((isset($table['miw']) && $checkminwidth > $table['miw']) || !isset($table['miw'])) { $table['miw'] = $checkminwidth; }
  20142. if ((isset($table['maw']) && $checkmaxwidth > $table['maw']) || !isset($table['maw'])) { $table['maw'] = $checkmaxwidth; }
  20143. $table['tl'] = $totallength ;
  20144. // mPDF 4.2
  20145. if (!$this->isCJK && !$longCJK) {
  20146. if ($this->table_rotate) {
  20147. $mxw = $this->tbrot_maxw;
  20148. }
  20149. else {
  20150. $mxw = $this->blk[$this->blklvl]['inner_width'];
  20151. }
  20152. if (($table['overflow']=='visible' || $table['overflow']=='hidden') && !$this->table_rotate && !$this->ColActive && $checkminwidth > $mxw) {
  20153. $table['w'] = $table['miw'];
  20154. return array(0,0);
  20155. }
  20156. else if ($table['overflow']=='wrap') { return array(0,0); }
  20157. if (isset($table['w']) && $table['w'] ) {
  20158. if ($table['w'] >= $checkminwidth && $table['w'] <= $mxw) { $table['maw'] = $mxw = $table['w']; } // mPDF 4.0
  20159. else if ($table['w'] >= $checkminwidth && $table['w'] > $mxw && $this->keep_table_proportions) { $checkminwidth = $table['w']; }
  20160. else {
  20161. unset($table['w']);
  20162. }
  20163. }
  20164. $ratio = $checkminwidth/$mxw;
  20165. if ($checkminwidth > $mxw) { return array(($ratio +0.001),$checkminwidth); } // 0.001 to allow for rounded numbers when resizing
  20166. }
  20167. return array(0,0);
  20168. }
  20169. function _tableWidth(&$table){
  20170. $widthcols = &$table['wc'];
  20171. $numcols = $table['nc'];
  20172. $tablewidth = 0;
  20173. // Added mPDF1.4 - table border width if separate
  20174. if ($table['borders_separate']) {
  20175. $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'];
  20176. }
  20177. else { $tblbw = $table['max_cell_border_width']['L']/2 + $table['max_cell_border_width']['R']/2 + $table['margin']['L'] + $table['margin']['R']; }
  20178. if ($table['level']>1 && isset($table['w'])) {
  20179. if (isset($table['wpercent']) && $table['wpercent']) {
  20180. $table['w'] = $temppgwidth = (($table['w']-$tblbw) * $table['wpercent'] / 100) + $tblbw ;
  20181. }
  20182. else {
  20183. $temppgwidth = $table['w'] ;
  20184. }
  20185. }
  20186. else if ($this->table_rotate) {
  20187. $temppgwidth = $this->tbrot_maxw;
  20188. // If it is less than 1/20th of the remaining page height to finish the DIV (i.e. DIV padding + table bottom margin)
  20189. // then allow for this
  20190. $enddiv = $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'];
  20191. if ($enddiv/$temppgwidth <0.05) { $temppgwidth -= $enddiv; }
  20192. }
  20193. else {
  20194. if (isset($table['w']) && $table['w']< $this->blk[$this->blklvl]['inner_width']) {
  20195. $notfullwidth = 1;
  20196. $temppgwidth = $table['w'] ;
  20197. }
  20198. else if (($table['overflow']=='visible' || $table['overflow']=='hidden') && !$this->ColActive && isset($table['w']) && $table['w'] > $this->blk[$this->blklvl]['inner_width'] && $table['w']==$table['miw']) {
  20199. $temppgwidth = $table['w'] ;
  20200. }
  20201. else { $temppgwidth = $this->blk[$this->blklvl]['inner_width']; }
  20202. }
  20203. $totaltextlength = 0; // Added - to sum $table['l'][colno]
  20204. $totalatextlength = 0; // Added - to sum $table['l'][colno] for those columns where width not set
  20205. $percentages_set = 0;
  20206. for ( $i = 0 ; $i < $numcols ; $i++ ) {
  20207. if (isset($widthcols[$i]['wpercent'])) { $tablewidth += $widthcols[$i]['maw']; $percentages_set = 1; }
  20208. else if (isset($widthcols[$i]['w'])) { $tablewidth += $widthcols[$i]['miw']; }
  20209. else { $tablewidth += $widthcols[$i]['maw']; }
  20210. $totaltextlength += $table['l'][$i];
  20211. }
  20212. if (!$totaltextlength) { $totaltextlength =1; }
  20213. $tablewidth += $tblbw; // Outer half of table borders
  20214. if ($tablewidth > $temppgwidth) {
  20215. $table['w'] = $temppgwidth;
  20216. }
  20217. // if any widths set as percentages and max width fits < page width
  20218. else if ($tablewidth < $temppgwidth && !isset($table['w']) && $percentages_set) {
  20219. $table['w'] = $table['maw'];
  20220. }
  20221. // if table width is set and is > allowed width
  20222. if (isset($table['w']) && $table['w'] > $temppgwidth) { $table['w'] = $temppgwidth; }
  20223. // IF the table width is now set - Need to distribute columns widths
  20224. if (isset($table['w'])) {
  20225. $wis = $wisa = 0;
  20226. $list = array();
  20227. $notsetlist = array();
  20228. for( $i = 0 ; $i < $numcols ; $i++ ) {
  20229. $wis += $widthcols[$i]['miw'];
  20230. if (!isset($widthcols[$i]['w']) || ($widthcols[$i]['w'] && $table['w'] > $temppgwidth && !$this->keep_table_proportions && !$notfullwidth )){
  20231. $list[] = $i;
  20232. $wisa += $widthcols[$i]['miw'];
  20233. $totalatextlength += $table['l'][$i];
  20234. }
  20235. }
  20236. if (!$totalatextlength) { $totalatextlength =1; }
  20237. // Allocate spare (more than col's minimum width) across the cols according to their approx total text length
  20238. // Do it by setting minimum width here
  20239. if ($table['w'] > $wis + $tblbw) {
  20240. // First set any cell widths set as percentages
  20241. if ($table['w'] < $temppgwidth || $this->keep_table_proportions) {
  20242. for($k=0;$k<$numcols;$k++) {
  20243. if (isset($widthcols[$k]['wpercent'])) {
  20244. $curr = $widthcols[$k]['miw'];
  20245. $widthcols[$k]['miw'] = ($table['w']-$tblbw) * $widthcols[$k]['wpercent']/100;
  20246. $wis += $widthcols[$k]['miw'] - $curr;
  20247. $wisa += $widthcols[$k]['miw'] - $curr;
  20248. }
  20249. }
  20250. }
  20251. // Now allocate surplus up to maximum width of each column
  20252. $surplus = 0; $ttl = 0; // number of surplus columns
  20253. if (!count($list)) {
  20254. $wi = ($table['w']-($wis + $tblbw)); // i.e. extra space to distribute
  20255. for($k=0;$k<$numcols;$k++) {
  20256. $spareratio = ($table['l'][$k] / $totaltextlength); // gives ratio to divide up free space
  20257. // Don't allocate more than Maximum required width - save rest in surplus
  20258. if ($widthcols[$k]['miw'] + ($wi * $spareratio) > $widthcols[$k]['maw']) {
  20259. $surplus += ($wi * $spareratio) - ($widthcols[$k]['maw']-$widthcols[$k]['miw']);
  20260. $widthcols[$k]['miw'] = $widthcols[$k]['maw'];
  20261. }
  20262. else {
  20263. $notsetlist[] = $k;
  20264. $ttl += $table['l'][$k];
  20265. $widthcols[$k]['miw'] += ($wi * $spareratio);
  20266. }
  20267. }
  20268. }
  20269. else {
  20270. $wi = ($table['w'] - ($wis + $tblbw)); // i.e. extra space to distribute
  20271. foreach ($list as $k) {
  20272. $spareratio = ($table['l'][$k] / $totalatextlength); // gives ratio to divide up free space
  20273. // Don't allocate more than Maximum required width - save rest in surplus
  20274. if ($widthcols[$k]['miw'] + ($wi * $spareratio) > $widthcols[$k]['maw']) {
  20275. $surplus += ($wi * $spareratio) - ($widthcols[$k]['maw']-$widthcols[$k]['miw']);
  20276. $widthcols[$k]['miw'] = $widthcols[$k]['maw'];
  20277. }
  20278. else {
  20279. $notsetlist[] = $k;
  20280. $ttl += $table['l'][$k];
  20281. $widthcols[$k]['miw'] += ($wi * $spareratio);
  20282. }
  20283. }
  20284. }
  20285. // If surplus still left over apportion it across columns
  20286. if ($surplus) {
  20287. // if some are set only add to remaining - otherwise add to all of them
  20288. if (count($notsetlist) && count($notsetlist) < $numcols) {
  20289. foreach ($notsetlist AS $i) {
  20290. if ($ttl) $widthcols[$i]['miw'] += $surplus * $table['l'][$i] / $ttl ;
  20291. }
  20292. }
  20293. // If some widths are defined, and others have been added up to their maxmum
  20294. else if (count($list) && count($list) < $numcols) {
  20295. foreach ($list AS $i) {
  20296. $widthcols[$i]['miw'] += $surplus / count($list) ;
  20297. }
  20298. }
  20299. else if ($numcols) { // If all columns
  20300. $ttl = array_sum($table['l']);
  20301. for ($i=0;$i<$numcols;$i++) {
  20302. $widthcols[$i]['miw'] += $surplus * $table['l'][$i] / $ttl;
  20303. }
  20304. }
  20305. }
  20306. }
  20307. // This sets the columns all to minimum width (which has been increased above if appropriate)
  20308. for ($i=0;$i<$numcols;$i++) {
  20309. $widthcols[$i] = $widthcols[$i]['miw'];
  20310. }
  20311. // TABLE NOT WIDE ENOUGH EVEN FOR MINIMUM CONTENT WIDTH
  20312. // If sum of column widths set are too wide for table
  20313. $checktablewidth = 0;
  20314. for ( $i = 0 ; $i < $numcols ; $i++ ) {
  20315. $checktablewidth += $widthcols[$i];
  20316. }
  20317. if ($checktablewidth > ($temppgwidth + 0.001 - $tblbw)) {
  20318. $usedup = 0; $numleft = 0;
  20319. for ($i=0;$i<$numcols;$i++) {
  20320. if ((isset($widthcols[$i]) && $widthcols[$i] > (($temppgwidth - $tblbw) / $numcols)) && (!isset($widthcols[$i]['w']))) {
  20321. $numleft++;
  20322. unset($widthcols[$i]);
  20323. }
  20324. else { $usedup += $widthcols[$i]; }
  20325. }
  20326. for ($i=0;$i<$numcols;$i++) {
  20327. if (!isset($widthcols[$i]) || !$widthcols[$i]) {
  20328. $widthcols[$i] = ((($temppgwidth - $tblbw) - $usedup)/ ($numleft));
  20329. }
  20330. }
  20331. }
  20332. }
  20333. else { //table has no width defined
  20334. $table['w'] = $tablewidth;
  20335. for ( $i = 0 ; $i < $numcols ; $i++) {
  20336. if (isset($widthcols[$i]['wpercent']) && $this->keep_table_proportions) { $colwidth = $widthcols[$i]['maw']; }
  20337. else if (isset($widthcols[$i]['w'])) { $colwidth = $widthcols[$i]['miw']; }
  20338. else { $colwidth = $widthcols[$i]['maw']; }
  20339. unset($widthcols[$i]);
  20340. $widthcols[$i] = $colwidth;
  20341. }
  20342. }
  20343. }
  20344. function _tableHeight(&$table){
  20345. $level = $table['level'];
  20346. $levelid = $table['levelid'];
  20347. $cells = &$table['cells'];
  20348. $numcols = $table['nc'];
  20349. $numrows = $table['nr'];
  20350. $listspan = array();
  20351. $checkmaxheight = 0;
  20352. $headerrowheight = 0;
  20353. $checkmaxheightplus = 0;
  20354. $headerrowheightplus = 0;
  20355. // mPDF 4.0
  20356. $footerrowheight = 0;
  20357. $footerrowheightplus = 0;
  20358. if ($this->table_rotate) {
  20359. $temppgheight = $this->tbrot_maxh;
  20360. $remainingpage = $this->tbrot_maxh;
  20361. }
  20362. else {
  20363. $temppgheight = ($this->h - $this->bMargin - $this->tMargin) - $this->kwt_height;
  20364. $remainingpage = ($this->h - $this->bMargin - $this->y) - $this->kwt_height;
  20365. // If it is less than 1/20th of the remaining page height to finish the DIV (i.e. DIV padding + table bottom margin)
  20366. // then allow for this
  20367. $enddiv = $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $table['margin']['B'];
  20368. // mPDF 4.0 bug fix: if remaining page == 0 get error
  20369. if ($remainingpage > $enddiv && $enddiv/$remainingpage <0.05) { $remainingpage -= $enddiv; }
  20370. else if ($remainingpage == 0) { $remainingpage = 0.001; }
  20371. if ($temppgheight > $enddiv && $enddiv/$temppgheight <0.05) { $temppgheight -= $enddiv; }
  20372. else if ($temppgheight == 0) { $temppgheight = 0.001; }
  20373. }
  20374. for( $i = 0 ; $i < $numrows ; $i++ ) { //rows
  20375. $heightrow = &$table['hr'][$i];
  20376. for( $j = 0 ; $j < $numcols ; $j++ ) { //columns
  20377. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  20378. $c = &$cells[$i][$j];
  20379. // mPDF 4.3.006
  20380. if ($this->simpleTables){ // mPDF 4.2.017
  20381. if ($table['borders_separate']) { // NB twice border width
  20382. $extraWLR = ($table['simple']['border_details']['L']['w']+$table['simple']['border_details']['R']['w']) + ($c['padding']['L']+$c['padding']['R'])+$table['border_spacing_H'];
  20383. $extrh = ($table['simple']['border_details']['T']['w']+$table['simple']['border_details']['B']['w']) + ($c['padding']['T']+$c['padding']['B'])+$table['border_spacing_V'];
  20384. }
  20385. else {
  20386. $extraWLR = ($table['simple']['border_details']['L']['w']+$table['simple']['border_details']['R']['w'])/2 + ($c['padding']['L']+$c['padding']['R']);
  20387. $extrh = ($table['simple']['border_details']['T']['w']+$table['simple']['border_details']['B']['w'])/2 + ($c['padding']['T']+$c['padding']['B']);
  20388. }
  20389. }
  20390. else {
  20391. // mPDF 4.3.009
  20392. if ($this->packTableData) {
  20393. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  20394. }
  20395. else {
  20396. // mPDF 4.3.012E
  20397. $bt = $c['border_details']['T']['w'];
  20398. $bb = $c['border_details']['B']['w'];
  20399. $br = $c['border_details']['R']['w'];
  20400. $bl = $c['border_details']['L']['w'];
  20401. }
  20402. if ($table['borders_separate']) { // NB twice border width
  20403. $extraWLR = $bl + $br + $c['padding']['L'] + $c['padding']['R'] + $table['border_spacing_H'];
  20404. $extrh = $bt + $bb + $c['padding']['T'] + $c['padding']['B'] + $table['border_spacing_V'];
  20405. }
  20406. else {
  20407. $extraWLR = $bl/2 + $br/2 + $c['padding']['L'] + $c['padding']['R'];
  20408. $extrh = $bt/2 + $bb/2 + $c['padding']['T']+$c['padding']['B'];
  20409. }
  20410. }
  20411. list($x,$cw) = $this->_tableGetWidth($table, $i,$j);
  20412. //Check whether width is enough for this cells' text
  20413. $auxtext = implode("",$c['text']);
  20414. $auxtext2 = $auxtext; //in case we have text with styles
  20415. $aux3 = $auxtext; //in case we have text with styles
  20416. // Get CELL HEIGHT
  20417. // ++ extra parameter forces wrap to break word
  20418. if ($c['R']) {
  20419. $aux4 = implode(" ",$c['text']);
  20420. $s_fs = $this->FontSizePt;
  20421. $s_f = $this->FontFamily; // mPDF 3.0
  20422. $s_st = $this->FontStyle; // mPDF 3.0
  20423. $this->SetFont($c['textbuffer'][0][4],$c['textbuffer'][0][2],$c['textbuffer'][0][11] / $this->shrin_k,true,true);
  20424. $aux4 = ltrim($aux4);
  20425. $aux4= rtrim($aux4); // mPDF 4.4.012
  20426. $tempch = $this->GetStringWidth($aux4);
  20427. if ($c['R'] >= 45 && $c['R'] < 90) {
  20428. $tempch = ((sin(deg2rad($c['R']))) * $tempch ) + ((sin(deg2rad($c['R']))) * (($c['textbuffer'][0][11]/$this->k) / $this->shrin_k));
  20429. }
  20430. $this->SetFont($s_f,$s_st,$s_fs,true,true);
  20431. $ch = ($tempch ) + $extrh ;
  20432. }
  20433. else {
  20434. if (isset($c['textbuffer'])) {
  20435. $tempch = $this->TableWordWrap(($cw-$extraWLR),1,$c['textbuffer'], $c['dfs']); // mPDF 4.2
  20436. }
  20437. else { $tempch = 0; }
  20438. // Added cellpadding top and bottom. (Lineheight already adjusted to table_lineheight)
  20439. $ch = $tempch + $extrh ;
  20440. }
  20441. //If height is defined and it is bigger than calculated $ch then update values
  20442. if (isset($c['h']) && $c['h'] > $ch) {
  20443. $c['mih'] = $ch; //in order to keep valign working
  20444. $ch = $c['h'];
  20445. }
  20446. else $c['mih'] = $ch;
  20447. if (isset($c['rowspan'])) $listspan[] = array($i,$j);
  20448. elseif ($heightrow < $ch) $heightrow = $ch;
  20449. // this is the extra used in _tableWrite to determine whether to trigger a page change
  20450. if ($table['borders_separate']) {
  20451. // mPDF 3.0 - bug fix
  20452. //if ($i == ($numrows-1) || ($i+$cell['rowspan']) == ($numrows) ) {
  20453. if ($i == ($numrows-1) || (isset($c['rowspan']) && ($i+$c['rowspan']) == ($numrows)) ) {
  20454. $extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  20455. }
  20456. else {
  20457. $extra = $table['border_spacing_V']/2;
  20458. }
  20459. }
  20460. else {
  20461. if (!$this->simpleTables){ // mPDF 4.2.017
  20462. // mPDF 4.3.009
  20463. $extra = $bb/2;
  20464. }
  20465. else if ($this->simpleTables){
  20466. $extra = $table['simple']['border_details']['B']['w'] /2;
  20467. }
  20468. }
  20469. // mPDF 3.0
  20470. if ($i <$this->tableheadernrows && $this->usetableheader) {
  20471. $headerrowheight = max($headerrowheight,$ch);
  20472. $headerrowheightplus = max($headerrowheightplus,$ch+$extra);
  20473. }
  20474. // mPDF 4.0
  20475. else if ($table['is_tfoot'][$i]) {
  20476. $footerrowheight = max($footerrowheight,$ch);
  20477. $footerrowheightplus = max($footerrowheightplus,$ch+$extra);
  20478. }
  20479. else {
  20480. $checkmaxheight = max($checkmaxheight,$ch);
  20481. $checkmaxheightplus = max($checkmaxheightplus,$ch+$extra);
  20482. }
  20483. unset($c);
  20484. }
  20485. }//end of columns
  20486. }//end of rows
  20487. $heightrow = &$table['hr'];
  20488. foreach ($listspan as $span) {
  20489. list($i,$j) = $span;
  20490. $c = &$cells[$i][$j];
  20491. $lr = $i + $c['rowspan'];
  20492. if ($lr > $numrows) $lr = $numrows;
  20493. $hs = $hsa = 0;
  20494. $list = array();
  20495. for($k=$i;$k<$lr;$k++) {
  20496. $hs += $heightrow[$k];
  20497. if (!isset($c['h'])) {
  20498. $list[] = $k;
  20499. $hsa += $heightrow[$k];
  20500. }
  20501. }
  20502. // mPDF 3.0
  20503. if ($table['borders_separate']) {
  20504. if ($i == ($numrows-1) || ($i+$c['rowspan']) == ($numrows) ) {
  20505. $extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  20506. }
  20507. else {
  20508. $extra = $table['border_spacing_V']/2;
  20509. }
  20510. }
  20511. else {
  20512. if (!$this->simpleTables){ // mPDF 4.2.017
  20513. // mPDF 4.3.009
  20514. if ($this->packTableData) {
  20515. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($c['borderbin']);
  20516. }
  20517. else {
  20518. // mPDF 4.3.012E
  20519. $bb = $c['border_details']['B']['w'];
  20520. }
  20521. $extra = $bb/2;
  20522. }
  20523. else if ($this->simpleTables){
  20524. $extra = $table['simple']['border_details']['B']['w'] /2;
  20525. }
  20526. }
  20527. if ($i <$this->tableheadernrows && $this->usetableheader) {
  20528. $headerrowheight = max($headerrowheight,$hs);
  20529. $headerrowheightplus = max($headerrowheightplus,$hs+$extra);
  20530. }
  20531. // mPDF 4.0
  20532. else if ($table['is_tfoot'][$i]) {
  20533. $footerrowheight = max($footerrowheight,$hs);
  20534. $footerrowheightplus = max($footerrowheightplus,$hs+$extra);
  20535. }
  20536. else {
  20537. $checkmaxheight = max($checkmaxheight,$hs);
  20538. $checkmaxheightplus = max($checkmaxheightplus,$hs+$extra);
  20539. }
  20540. if ($c['mih'] > $hs) {
  20541. if (!$hs) {
  20542. for($k=$i;$k<$lr;$k++) $heightrow[$k] = $c['mih']/$c['rowspan'];
  20543. }
  20544. elseif (!count($list)) {
  20545. $hi = $c['mih'] - $hs;
  20546. for($k=$i;$k<$lr;$k++) $heightrow[$k] += ($heightrow[$k]/$hs)*$hi;
  20547. }
  20548. else {
  20549. $hi = $c['mih'] - $hsa;
  20550. foreach ($list as $k) $heightrow[$k] += ($heightrow[$k]/$hsa)*$hi;
  20551. }
  20552. }
  20553. unset($c);
  20554. }
  20555. $table['h'] = array_sum($table['hr']);
  20556. if ($table['borders_separate']) {
  20557. $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'];
  20558. }
  20559. else {
  20560. $table['h'] += $table['margin']['T'] + $table['margin']['B'] + $table['max_cell_border_width']['T']/2 + $table['max_cell_border_width']['B']/2;
  20561. }
  20562. // mPDF 4.0
  20563. $maxrowheight = $checkmaxheightplus + $headerrowheightplus + $footerrowheightplus;
  20564. return array($table['h'],$maxrowheight,$temppgheight,$remainingpage);
  20565. }
  20566. function _tableGetWidth(&$table, $i,$j){
  20567. $cell = &$table['cells'][$i][$j];
  20568. if ($cell) {
  20569. if (isset($cell['x0'])) return array($cell['x0'], $cell['w0']);
  20570. $x = 0;
  20571. $widthcols = &$table['wc'];
  20572. for( $k = 0 ; $k < $j ; $k++ ) $x += $widthcols[$k];
  20573. $w = $widthcols[$j];
  20574. if (isset($cell['colspan'])) {
  20575. for ( $k = $j+$cell['colspan']-1 ; $k > $j ; $k-- ) $w += $widthcols[$k];
  20576. }
  20577. $cell['x0'] = $x;
  20578. $cell['w0'] = $w;
  20579. return array($x, $w);
  20580. }
  20581. return array(0,0);
  20582. }
  20583. function _tableGetHeight(&$table, $i,$j){
  20584. $cell = &$table['cells'][$i][$j];
  20585. if ($cell){
  20586. if (isset($cell['y0'])) return array($cell['y0'], $cell['h0']);
  20587. $y = 0;
  20588. $heightrow = &$table['hr'];
  20589. for ($k=0;$k<$i;$k++) $y += $heightrow[$k];
  20590. $h = $heightrow[$i];
  20591. if (isset($cell['rowspan'])){
  20592. for ($k=$i+$cell['rowspan']-1;$k>$i;$k--)
  20593. $h += $heightrow[$k];
  20594. }
  20595. $cell['y0'] = $y;
  20596. $cell['h0'] = $h;
  20597. return array($y, $h);
  20598. }
  20599. return array(0,0);
  20600. }
  20601. // CHANGED TO ALLOW TABLE BORDER TO BE SPECIFIED CORRECTLY - added border_details
  20602. // mPDF 3.0 Table borders need additional parameters - either corner (TLBR) and/or border-spacing-H or -V ($bsh/$bsv)
  20603. function _tableRect($x, $y, $w, $h, $bord=-1, $details=array(), $buffer=false, $bSeparate=false, $cort='cell', $tablecorner='', $bsv=0, $bsh=0) {
  20604. // mPDF 3.0 Disabled again - buffer is printed at end of each table row - in fn. _tablewrite()
  20605. // if ($this->ColActive) { $buffer = false; }
  20606. // mPDF 3.0
  20607. $cellBorderOverlay = array();
  20608. if ($bord==-1) { $this->Rect($x, $y, $w, $h); }
  20609. else if ($this->simpleTables && ($cort=='cell')) { // mPDF 4.2.017
  20610. $this->SetLineWidth($details['L']['w']);
  20611. if ($details['L']['c']) {
  20612. $this->SetDrawColor($details['L']['c']['R'],$details['L']['c']['G'],$details['L']['c']['B']);
  20613. }
  20614. else { $this->SetDrawColor(0); }
  20615. $this->_out('0 j');
  20616. $this->Rect($x, $y, $w, $h);
  20617. }
  20618. else if ($bord){
  20619. if (!$bSeparate && $buffer) {
  20620. $priority = 'LRTB';
  20621. for($p=0;$p<strlen($priority);$p++) {
  20622. $side = $priority[$p]; // mPDF 4.4.012
  20623. $details['p'] = $side ;
  20624. $dom = 0;
  20625. if (isset($details[$side]['w'])) { $dom += ($details[$side]['w'] * 100000); }
  20626. if (isset($details[$side]['style'])) { $dom += (array_search($details[$side]['style'],$this->borderstyles)*100) ; }
  20627. if (isset($details[$side]['dom'])) { $dom += ($details[$side]['dom']*10); }
  20628. // mPDF 3.0 Precedence to darker colours at joins
  20629. $coldom = 0;
  20630. if (isset($details[$side]['c']) && is_array($details[$side]['c'])) {
  20631. $coldom = 10-((($details[$side]['c']['R']*1.00)+($details[$side]['c']['G']*1.00)+($details[$side]['c']['B']*1.00))/76.5);
  20632. } // 10 black - 0 white
  20633. if ($coldom) { $dom += $coldom; }
  20634. // mPDF 3.0 Lastly precedence to RIGHT and BOTTOM cells at joins
  20635. if (isset($details['cellposdom'])) { $dom += $details['cellposdom']; }
  20636. $save = false;
  20637. // mPDF 3.0
  20638. if ($side == 'T' && $this->issetBorder($bord, _BORDER_TOP)) { $cbord = _BORDER_TOP; $save = true; }
  20639. else if ($side == 'L' && $this->issetBorder($bord, _BORDER_LEFT)) { $cbord = _BORDER_LEFT; $save = true; }
  20640. else if ($side == 'R' && $this->issetBorder($bord, _BORDER_RIGHT)) { $cbord = _BORDER_RIGHT; $save = true; }
  20641. else if ($side == 'B' && $this->issetBorder($bord, _BORDER_BOTTOM)) { $cbord = _BORDER_BOTTOM; $save = true; }
  20642. if ($save) {
  20643. // mPDF 4.3.008 4.3.014
  20644. $this->cellBorderBuffer[] = pack("A16nCndnnnA10d14",
  20645. str_pad(sprintf("%08.7f", $dom),16,"0",STR_PAD_LEFT),
  20646. $cbord,
  20647. ord($side),
  20648. $details[$side]['s'],
  20649. $details[$side]['w'],
  20650. $details[$side]['c']['R'],
  20651. $details[$side]['c']['G'],
  20652. $details[$side]['c']['B'],
  20653. $details[$side]['style'],
  20654. $x, $y, $w, $h,
  20655. $details['mbw']['BL'],
  20656. $details['mbw']['BR'],
  20657. $details['mbw']['RT'],
  20658. $details['mbw']['RB'],
  20659. $details['mbw']['TL'],
  20660. $details['mbw']['TR'],
  20661. $details['mbw']['LT'],
  20662. $details['mbw']['LB'],
  20663. $details['cellposdom'],
  20664. 0
  20665. );
  20666. if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'groove' || $details[$side]['style'] == 'inset' || $details[$side]['style'] == 'outset' || $details[$side]['style'] == 'double' ) {
  20667. $details[$side]['overlay'] = true;
  20668. // mPDF 4.3.008 4.3.014
  20669. $this->cellBorderBuffer[] = pack("A16nCndnnnA10d14",
  20670. str_pad(sprintf("%08.7f", ($dom+4)),16,"0",STR_PAD_LEFT), /* mPDF 4.3.019 */
  20671. $cbord,
  20672. ord($side),
  20673. $details[$side]['s'],
  20674. $details[$side]['w'],
  20675. $details[$side]['c']['R'],
  20676. $details[$side]['c']['G'],
  20677. $details[$side]['c']['B'],
  20678. $details[$side]['style'],
  20679. $x, $y, $w, $h,
  20680. $details['mbw']['BL'],
  20681. $details['mbw']['BR'],
  20682. $details['mbw']['RT'],
  20683. $details['mbw']['RB'],
  20684. $details['mbw']['TL'],
  20685. $details['mbw']['TR'],
  20686. $details['mbw']['LT'],
  20687. $details['mbw']['LB'],
  20688. $details['cellposdom'],
  20689. 1
  20690. );
  20691. }
  20692. }
  20693. }
  20694. return;
  20695. }
  20696. if (isset($details['p']) && strlen($details['p'])>1) { $priority = $details['p']; }
  20697. else { $priority='LTRB'; }
  20698. $Tw = 0;
  20699. $Rw = 0;
  20700. $Bw = 0;
  20701. $Lw = 0;
  20702. if (isset($details['T']['w'])) { $Tw = $details['T']['w']; }
  20703. if (isset($details['R']['w'])) { $Rw = $details['R']['w']; }
  20704. if (isset($details['B']['w'])) { $Bw = $details['B']['w']; }
  20705. if (isset($details['L']['w'])) { $Lw = $details['L']['w']; }
  20706. $x2 = $x + $w; $y2 = $y + $h;
  20707. $oldlinewidth = $this->LineWidth;
  20708. for($p=0;$p<strlen($priority);$p++) {
  20709. $side = $priority[$p]; // mPDF 4.4.012
  20710. $xadj = 0;
  20711. $xadj2 = 0;
  20712. $yadj = 0;
  20713. $yadj2 = 0;
  20714. $print = false;
  20715. if ($Tw && $side=='T' && $this->issetBorder($bord, _BORDER_TOP)) { // TOP
  20716. $ly1 = $y;
  20717. $ly2 = $y;
  20718. $lx1 = $x;
  20719. $lx2 = $x2;
  20720. $this->SetLineWidth($Tw);
  20721. // mPDF 3.0
  20722. if ($cort == 'cell' || strpos($tablecorner,'L')!==false) {
  20723. if ($Tw > $Lw) $xadj = ($Tw - $Lw)/2;
  20724. if ($Tw < $Lw) $xadj = ($Tw + $Lw)/2;
  20725. }
  20726. else { $xadj = $Tw/2 - $bsh/2; }
  20727. // mPDF 3.0
  20728. if ($cort == 'cell' || strpos($tablecorner,'R')!==false) {
  20729. if ($Tw > $Rw) $xadj2 = ($Tw - $Rw)/2;
  20730. if ($Tw < $Rw) $xadj2 = ($Tw + $Rw)/2;
  20731. }
  20732. else { $xadj2 = $Tw/2 - $bsh/2; }
  20733. if (!$bSeparate && $details['mbw']['TL']) {
  20734. $xadj = ($Tw - $details['mbw']['TL'])/2 ;
  20735. }
  20736. if (!$bSeparate && $details['mbw']['TR']) {
  20737. $xadj2 = ($Tw - $details['mbw']['TR'])/2;
  20738. }
  20739. $print = true;
  20740. }
  20741. if ($Lw && $side=='L' && $this->issetBorder($bord, _BORDER_LEFT)) { // LEFT
  20742. $ly1 = $y;
  20743. $ly2 = $y2;
  20744. $lx1 = $x;
  20745. $lx2 = $x;
  20746. $this->SetLineWidth($Lw);
  20747. // mPDF 3.0
  20748. if ($cort == 'cell' || strpos($tablecorner,'T')!==false) {
  20749. if ($Lw > $Tw) $yadj = ($Lw - $Tw)/2;
  20750. if ($Lw < $Tw) $yadj = ($Lw + $Tw)/2;
  20751. }
  20752. else { $yadj = $Lw/2 - $bsv/2; }
  20753. // mPDF 3.0
  20754. if ($cort == 'cell' || strpos($tablecorner,'B')!==false) {
  20755. if ($Lw > $Bw) $yadj2 = ($Lw - $Bw)/2;
  20756. if ($Lw < $Bw) $yadj2 = ($Lw + $Bw)/2;
  20757. }
  20758. else { $yadj2 = $Lw/2 - $bsv/2; }
  20759. if (!$bSeparate && $details['mbw']['LT']) {
  20760. $yadj = ($Lw - $details['mbw']['LT'])/2;
  20761. }
  20762. if (!$bSeparate && $details['mbw']['LB']) {
  20763. $yadj2 = ($Lw - $details['mbw']['LB'])/2;
  20764. }
  20765. $print = true;
  20766. }
  20767. if ($Rw && $side=='R' && $this->issetBorder($bord, _BORDER_RIGHT)) { // RIGHT
  20768. $ly1 = $y;
  20769. $ly2 = $y2;
  20770. $lx1 = $x2;
  20771. $lx2 = $x2;
  20772. $this->SetLineWidth($Rw);
  20773. // mPDF 3.0
  20774. if ($cort == 'cell' || strpos($tablecorner,'T')!==false) {
  20775. if ($Rw < $Tw) $yadj = ($Rw + $Tw)/2;
  20776. if ($Rw > $Tw) $yadj = ($Rw - $Tw)/2;
  20777. }
  20778. else { $yadj = $Rw/2 - $bsv/2; }
  20779. // mPDF 3.0
  20780. if ($cort == 'cell' || strpos($tablecorner,'B')!==false) {
  20781. if ($Rw > $Bw) $yadj2 = ($Rw - $Bw)/2;
  20782. if ($Rw < $Bw) $yadj2 = ($Rw + $Bw)/2;
  20783. }
  20784. else { $yadj2 = $Rw/2 - $bsv/2; }
  20785. if (!$bSeparate && $details['mbw']['RT']) {
  20786. $yadj = ($Rw - $details['mbw']['RT'])/2;
  20787. }
  20788. if (!$bSeparate && $details['mbw']['RB']) {
  20789. $yadj2 = ($Rw - $details['mbw']['RB'])/2;
  20790. }
  20791. $print = true;
  20792. }
  20793. if ($Bw && $side=='B' && $this->issetBorder($bord, _BORDER_BOTTOM)) { // BOTTOM
  20794. $ly1 = $y2;
  20795. $ly2 = $y2;
  20796. $lx1 = $x;
  20797. $lx2 = $x2;
  20798. $this->SetLineWidth($Bw);
  20799. // mPDF 3.0
  20800. if ($cort == 'cell' || strpos($tablecorner,'L')!==false) {
  20801. if ($Bw > $Lw) $xadj = ($Bw - $Lw)/2;
  20802. if ($Bw < $Lw) $xadj = ($Bw + $Lw)/2;
  20803. }
  20804. else { $xadj = $Bw/2 - $bsh/2; }
  20805. // mPDF 3.0
  20806. if ($cort == 'cell' || strpos($tablecorner,'R')!==false) {
  20807. if ($Bw > $Rw) $xadj2 = ($Bw - $Rw)/2;
  20808. if ($Bw < $Rw) $xadj2 = ($Bw + $Rw)/2;
  20809. }
  20810. else { $xadj2 = $Bw/2 - $bsh/2; }
  20811. if (!$bSeparate && $details['mbw']['BL']) {
  20812. $xadj = ($Bw - $details['mbw']['BL'])/2;
  20813. }
  20814. if (!$bSeparate && $details['mbw']['BR']) {
  20815. $xadj2 = ($Bw - $details['mbw']['BR'])/2;
  20816. }
  20817. $print = true;
  20818. }
  20819. // Now draw line
  20820. if ($print) {
  20821. /*-- TABLES-ADVANCED-BORDERS --*/
  20822. if ($details[$side]['style'] == 'double') {
  20823. if (!isset($details[$side]['overlay']) || !$details[$side]['overlay'] || $bSeparate) {
  20824. if ($details[$side]['c']) {
  20825. $this->SetDrawColor($details[$side]['c']['R'],$details[$side]['c']['G'],$details[$side]['c']['B']);
  20826. }
  20827. else { $this->SetDrawColor(0); }
  20828. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  20829. }
  20830. if ((isset($details[$side]['overlay']) && $details[$side]['overlay']) || $bSeparate) {
  20831. if ($bSeparate && $cort=='table') {
  20832. if ($side=='T') {
  20833. $xadj -= $this->LineWidth/2;
  20834. $xadj2 -= $this->LineWidth;
  20835. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  20836. $xadj += $this->LineWidth/2;
  20837. }
  20838. if ($this->issetBorder($bord, _BORDER_RIGHT)) {
  20839. $xadj2 += $this->LineWidth;
  20840. }
  20841. }
  20842. if ($side=='L') {
  20843. $yadj -= $this->LineWidth/2;
  20844. $yadj2 -= $this->LineWidth;
  20845. if ($this->issetBorder($bord, _BORDER_TOP)) {
  20846. $yadj += $this->LineWidth/2;
  20847. }
  20848. if ($this->issetBorder($bord, _BORDER_BOTTOM)) {
  20849. $yadj2 += $this->LineWidth;
  20850. }
  20851. }
  20852. if ($side=='B') {
  20853. $xadj -= $this->LineWidth/2;
  20854. $xadj2 -= $this->LineWidth;
  20855. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  20856. $xadj += $this->LineWidth/2;
  20857. }
  20858. if ($this->issetBorder($bord, _BORDER_RIGHT)) {
  20859. $xadj2 += $this->LineWidth;
  20860. }
  20861. }
  20862. if ($side=='R') {
  20863. $yadj -= $this->LineWidth/2;
  20864. $yadj2 -= $this->LineWidth;
  20865. if ($this->issetBorder($bord, _BORDER_TOP)) {
  20866. $yadj += $this->LineWidth/2;
  20867. }
  20868. if ($this->issetBorder($bord, _BORDER_BOTTOM)) {
  20869. $yadj2 += $this->LineWidth;
  20870. }
  20871. }
  20872. }
  20873. $this->SetLineWidth($this->LineWidth/3);
  20874. // mPDF 4.2
  20875. $tbcol = array(255,255,255);
  20876. for($l=0; $l <= $this->blklvl; $l++) {
  20877. if ($this->blk[$l]['bgcolor']) {
  20878. $tbcol = array($this->blk[$l]['bgcolorarray']['R'],$this->blk[$l]['bgcolorarray']['G'],$this->blk[$l]['bgcolorarray']['B']);
  20879. }
  20880. }
  20881. if ($bSeparate) {
  20882. $cellBorderOverlay[] = array(
  20883. 'x' => $lx1 + $xadj,
  20884. 'y' => $ly1 + $yadj,
  20885. 'x2' => $lx2 - $xadj2,
  20886. 'y2' => $ly2 - $yadj2,
  20887. 'col' => $tbcol, /* mPDF 4.2 */
  20888. 'lw' => $this->LineWidth,
  20889. );
  20890. }
  20891. else {
  20892. $this->SetDrawColor($tbcol[0],$tbcol[1],$tbcol[2]); // mPDF 4.2
  20893. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  20894. }
  20895. }
  20896. }
  20897. else if (isset($details[$side]['style']) && ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'groove' || $details[$side]['style'] == 'inset' || $details[$side]['style'] == 'outset')) {
  20898. if (!isset($details[$side]['overlay']) || !$details[$side]['overlay'] || $bSeparate) {
  20899. if ($details[$side]['c']) {
  20900. $this->SetDrawColor($details[$side]['c']['R'],$details[$side]['c']['G'],$details[$side]['c']['B']);
  20901. }
  20902. else { $this->SetDrawColor(0); }
  20903. if ($details[$side]['style'] == 'outset' || $details[$side]['style'] == 'groove') {
  20904. $nc = $this->_darkenColor($details[$side]['c']);
  20905. $this->SetDrawColor($nc[0],$nc[1],$nc[2]);
  20906. }
  20907. else if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'inset') {
  20908. $nc = $this->_lightenColor($details[$side]['c']);
  20909. $this->SetDrawColor($nc[0],$nc[1],$nc[2]);
  20910. }
  20911. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  20912. }
  20913. if ((isset($details[$side]['overlay']) && $details[$side]['overlay']) || $bSeparate) {
  20914. if ($details[$side]['c']) {
  20915. $this->SetDrawColor($details[$side]['c']['R'],$details[$side]['c']['G'],$details[$side]['c']['B']);
  20916. }
  20917. else { $this->SetDrawColor(0); }
  20918. $doubleadj = ($this->LineWidth)/3;
  20919. $this->SetLineWidth($this->LineWidth/2);
  20920. $xadj3 = $yadj3 = $wadj3 = $hadj3 = 0;
  20921. if ($details[$side]['style'] == 'ridge' || $details[$side]['style'] == 'inset') {
  20922. $nc = $this->_darkenColor($details[$side]['c']);
  20923. if ($bSeparate && $cort=='table') {
  20924. if ($side=='T') {
  20925. $yadj3 = $this->LineWidth/2;
  20926. $xadj3 = -$this->LineWidth/2;
  20927. $wadj3 = $this->LineWidth;
  20928. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  20929. $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth;
  20930. }
  20931. if ($this->issetBorder($bord, _BORDER_RIGHT)) {
  20932. $wadj3 -= $this->LineWidth*2;
  20933. }
  20934. }
  20935. if ($side=='L') {
  20936. $xadj3 = $this->LineWidth/2;
  20937. $yadj3 = -$this->LineWidth/2;
  20938. $hadj3 = $this->LineWidth;
  20939. if ($this->issetBorder($bord, _BORDER_TOP)) {
  20940. $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth;
  20941. }
  20942. if ($this->issetBorder($bord, _BORDER_BOTTOM)) {
  20943. $hadj3 -= $this->LineWidth*2;
  20944. }
  20945. }
  20946. if ($side=='B') {
  20947. $yadj3 = $this->LineWidth/2;
  20948. $xadj3 = -$this->LineWidth/2;
  20949. $wadj3 = $this->LineWidth;
  20950. }
  20951. if ($side=='R') {
  20952. $xadj3 = $this->LineWidth/2;
  20953. $yadj3 = -$this->LineWidth/2;
  20954. $hadj3 = $this->LineWidth;
  20955. }
  20956. }
  20957. else if ($side=='T') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; $wadj3 = -$this->LineWidth*2; }
  20958. else if ($side=='L') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; $hadj3 = -$this->LineWidth*2; }
  20959. else if ($side=='B' && $bSeparate) { $yadj3 = $this->LineWidth/2; $wadj3 = $this->LineWidth/2; }
  20960. else if ($side=='R' && $bSeparate) { $xadj3 = $this->LineWidth/2; $hadj3 = $this->LineWidth/2; }
  20961. else if ($side=='B') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; }
  20962. else if ($side=='R') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; }
  20963. }
  20964. else {
  20965. $nc = $this->_lightenColor($details[$side]['c']);
  20966. if ($bSeparate && $cort=='table') {
  20967. if ($side=='T') {
  20968. $yadj3 = $this->LineWidth/2;
  20969. $xadj3 = -$this->LineWidth/2;
  20970. $wadj3 = $this->LineWidth;
  20971. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  20972. $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth;
  20973. }
  20974. }
  20975. if ($side=='L') {
  20976. $xadj3 = $this->LineWidth/2;
  20977. $yadj3 = -$this->LineWidth/2;
  20978. $hadj3 = $this->LineWidth;
  20979. if ($this->issetBorder($bord, _BORDER_TOP)) {
  20980. $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth;
  20981. }
  20982. }
  20983. if ($side=='B') {
  20984. $yadj3 = $this->LineWidth/2;
  20985. $xadj3 = -$this->LineWidth/2;
  20986. $wadj3 = $this->LineWidth;
  20987. if ($this->issetBorder($bord, _BORDER_LEFT)) {
  20988. $xadj3 += $this->LineWidth; $wadj3 -= $this->LineWidth;
  20989. }
  20990. }
  20991. if ($side=='R') {
  20992. $xadj3 = $this->LineWidth/2;
  20993. $yadj3 = -$this->LineWidth/2;
  20994. $hadj3 = $this->LineWidth;
  20995. if ($this->issetBorder($bord, _BORDER_TOP)) {
  20996. $yadj3 += $this->LineWidth; $hadj3 -= $this->LineWidth;
  20997. }
  20998. }
  20999. }
  21000. else if ($side=='T') { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; }
  21001. else if ($side=='L') { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; }
  21002. else if ($side=='B' && $bSeparate) { $yadj3 = $this->LineWidth/2; $xadj3 = $this->LineWidth/2; }
  21003. else if ($side=='R' && $bSeparate) { $xadj3 = $this->LineWidth/2; $yadj3 = $this->LineWidth/2; }
  21004. else if ($side=='B') { $yadj3 = $this->LineWidth/2; $xadj3 = -$this->LineWidth/2; $wadj3 = $this->LineWidth; }
  21005. else if ($side=='R') { $xadj3 = $this->LineWidth/2; $yadj3 = -$this->LineWidth/2; $hadj3 = $this->LineWidth; }
  21006. }
  21007. if ($bSeparate) {
  21008. $cellBorderOverlay[] = array(
  21009. 'x' => $lx1 + $xadj + $xadj3,
  21010. 'y' => $ly1 + $yadj + $yadj3,
  21011. 'x2' => $lx2 - $xadj2 + $xadj3 + $wadj3,
  21012. 'y2' => $ly2 - $yadj2 + $yadj3 + $hadj3,
  21013. 'col' => array($nc[0],$nc[1],$nc[2]),
  21014. 'lw' => $this->LineWidth,
  21015. );
  21016. }
  21017. else {
  21018. $this->SetDrawColor($nc[0],$nc[1],$nc[2]);
  21019. $this->Line($lx1 + $xadj + $xadj3, $ly1 + $yadj + $yadj3, $lx2 - $xadj2 + $xadj3 + $wadj3, $ly2 - $yadj2 + $yadj3 + $hadj3);
  21020. }
  21021. }
  21022. }
  21023. else {
  21024. /*-- END TABLES-ADVANCED-BORDERS --*/
  21025. if ($details[$side]['style'] == 'dashed') {
  21026. $dashsize = 2; // final dash will be this + 1*linewidth
  21027. $dashsizek = 1.5; // ratio of Dash/Blank
  21028. $this->SetDash($dashsize,($dashsize/$dashsizek)+($this->LineWidth*2));
  21029. }
  21030. else if ($details[$side]['style'] == 'dotted') {
  21031. $this->_out("\n".'1 J'."\n".'1 j'."\n");
  21032. $this->SetDash(0.001,($this->LineWidth*2));
  21033. }
  21034. if ($details[$side]['c']) {
  21035. $this->SetDrawColor($details[$side]['c']['R'],$details[$side]['c']['G'],$details[$side]['c']['B']);
  21036. }
  21037. else { $this->SetDrawColor(0); }
  21038. $this->Line($lx1 + $xadj, $ly1 + $yadj, $lx2 - $xadj2, $ly2 - $yadj2);
  21039. /*-- TABLES-ADVANCED-BORDERS --*/
  21040. }
  21041. /*-- END TABLES-ADVANCED-BORDERS --*/
  21042. // Reset Corners
  21043. $this->SetDash();
  21044. //BUTT style line cap
  21045. $this->_out('2 J');
  21046. }
  21047. }
  21048. if ($bSeparate && count($cellBorderOverlay)) {
  21049. foreach($cellBorderOverlay AS $cbo) {
  21050. $this->SetLineWidth($cbo['lw']);
  21051. $this->SetDrawColor($cbo['col'][0],$cbo['col'][1],$cbo['col'][2]);
  21052. $this->Line($cbo['x'], $cbo['y'], $cbo['x2'], $cbo['y2']);
  21053. }
  21054. }
  21055. $this->SetLineWidth($oldlinewidth);
  21056. $this->SetDrawColor(0);
  21057. }
  21058. }
  21059. /*-- TABLES --*/
  21060. /*-- TABLES-ADVANCED-BORDERS --*/
  21061. function _lightenColor($c) {
  21062. $r = $c['R']; $g = $c['G']; $b = $c['B'];
  21063. $var_r = $r / 255;
  21064. $var_g = $g / 255;
  21065. $var_b = $b / 255;
  21066. list($h,$s,$l) = $this->rgb2hsl($var_r,$var_g,$var_b);
  21067. $l += ((1 - $l)*0.8);
  21068. list($r,$g,$b) = $this->hsl2rgb($h,$s,$l);
  21069. return array($r,$g,$b);
  21070. }
  21071. function _darkenColor($c) {
  21072. $r = $c['R']; $g = $c['G']; $b = $c['B'];
  21073. $var_r = $r / 255;
  21074. $var_g = $g / 255;
  21075. $var_b = $b / 255;
  21076. list($h,$s,$l) = $this->rgb2hsl($var_r,$var_g,$var_b);
  21077. $s *= 0.25;
  21078. $l *= 0.75;
  21079. list($r,$g,$b) = $this->hsl2rgb($h,$s,$l);
  21080. return array($r,$g,$b);
  21081. }
  21082. // mPDF 4.0 Originally in htmltoolkit.php
  21083. function rgb2hsl($var_r, $var_g, $var_b) {
  21084. $var_min = min($var_r,$var_g,$var_b);
  21085. $var_max = max($var_r,$var_g,$var_b);
  21086. $del_max = $var_max - $var_min;
  21087. $l = ($var_max + $var_min) / 2;
  21088. if ($del_max == 0) {
  21089. $h = 0;
  21090. $s = 0;
  21091. }
  21092. else {
  21093. if ($l < 0.5) { $s = $del_max / ($var_max + $var_min); }
  21094. else { $s = $del_max / (2 - $var_max - $var_min); }
  21095. $del_r = ((($var_max - $var_r) / 6) + ($del_max / 2)) / $del_max;
  21096. $del_g = ((($var_max - $var_g) / 6) + ($del_max / 2)) / $del_max;
  21097. $del_b = ((($var_max - $var_b) / 6) + ($del_max / 2)) / $del_max;
  21098. if ($var_r == $var_max) { $h = $del_b - $del_g; }
  21099. elseif ($var_g == $var_max) { $h = (1 / 3) + $del_r - $del_b; }
  21100. elseif ($var_b == $var_max) { $h = (2 / 3) + $del_g - $del_r; };
  21101. if ($h < 0) { $h += 1; }
  21102. if ($h > 1) { $h -= 1; }
  21103. }
  21104. return array($h,$s,$l);
  21105. }
  21106. // mPDF 4.0 Originally in htmltoolkit.php
  21107. function hsl2rgb($h2,$s2,$l2) {
  21108. // Input is HSL value of complementary colour, held in $h2, $s, $l as fractions of 1
  21109. // Output is RGB in normal 255 255 255 format, held in $r, $g, $b
  21110. // Hue is converted using function hue_2_rgb, shown at the end of this code
  21111. if ($s2 == 0)
  21112. {
  21113. $r = $l2 * 255;
  21114. $g = $l2 * 255;
  21115. $b = $l2 * 255;
  21116. }
  21117. else
  21118. {
  21119. if ($l2 < 0.5)
  21120. {
  21121. $var_2 = $l2 * (1 + $s2);
  21122. }
  21123. else
  21124. {
  21125. $var_2 = ($l2 + $s2) - ($s2 * $l2);
  21126. };
  21127. $var_1 = 2 * $l2 - $var_2;
  21128. $r = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2 + (1 / 3)));
  21129. $g = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2));
  21130. $b = round(255 * $this->hue_2_rgb($var_1,$var_2,$h2 - (1 / 3)));
  21131. };
  21132. return array($r,$g,$b);
  21133. }
  21134. // mPDF 4.0 Originally in htmltoolkit.php
  21135. function hue_2_rgb($v1,$v2,$vh) {
  21136. // Function to convert hue to RGB, called from above
  21137. if ($vh < 0) { $vh += 1; };
  21138. if ($vh > 1) { $vh -= 1; };
  21139. if ((6 * $vh) < 1) { return ($v1 + ($v2 - $v1) * 6 * $vh); };
  21140. if ((2 * $vh) < 1) { return ($v2); };
  21141. if ((3 * $vh) < 2) { return ($v1 + ($v2 - $v1) * ((2 / 3 - $vh) * 6)); };
  21142. return ($v1);
  21143. }
  21144. /*-- END TABLES-ADVANCED-BORDERS --*/
  21145. /*-- END TABLES --*/
  21146. function setBorder(&$var, $flag, $set = true) {
  21147. $flag = intval($flag);
  21148. if ($set) { $set = true; }
  21149. $var = intval($var);
  21150. $var = $set ? ($var | $flag) : ($var & ~$flag);
  21151. }
  21152. function issetBorder($var, $flag) {
  21153. $flag = intval($flag);
  21154. $var = intval($var);
  21155. return (($var & $flag) == $flag);
  21156. }
  21157. // mPDF 4.0
  21158. function _table2cellBorder(&$tableb, &$cbdb, &$cellb, $bval) {
  21159. if ($tableb && $tableb['w'] > $cbdb['w']) {
  21160. $cbdb = $tableb;
  21161. $this->setBorder($cellb, $bval);
  21162. }
  21163. else if ($tableb && $tableb['w'] == $cbdb['w']
  21164. && array_search($tableb['style'],$this->borderstyles) > array_search($cbdb['style'],$this->borderstyles)) {
  21165. $cbdb = $tableb;
  21166. $this->setBorder($cellb, $bval);
  21167. }
  21168. }
  21169. // FIX BORDERS ********************************************
  21170. function _fixTableBorders(&$table){
  21171. if (!$table['borders_separate'] && $table['border_details']['L']['w']) {
  21172. $table['max_cell_border_width']['L'] = $table['border_details']['L']['w'];
  21173. }
  21174. if (!$table['borders_separate'] && $table['border_details']['R']['w']) {
  21175. $table['max_cell_border_width']['R'] = $table['border_details']['R']['w'];
  21176. }
  21177. if (!$table['borders_separate'] && $table['border_details']['T']['w']) {
  21178. $table['max_cell_border_width']['T'] = $table['border_details']['T']['w'];
  21179. }
  21180. if (!$table['borders_separate'] && $table['border_details']['B']['w']) {
  21181. $table['max_cell_border_width']['B'] = $table['border_details']['B']['w'];
  21182. }
  21183. if ($this->simpleTables) { return; } // mPDF 4.2.017
  21184. $cells = &$table['cells'];
  21185. $numcols = $table['nc'];
  21186. $numrows = $table['nr'];
  21187. for( $i = 0 ; $i < $numrows ; $i++ ) { //Rows
  21188. for( $j = 0 ; $j < $numcols ; $j++ ) { //Columns
  21189. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  21190. $cell = &$cells[$i][$j];
  21191. // mPDF 4.3.009 Binary packed data
  21192. if ($this->packTableData) {
  21193. $cbord = $this->_unpackCellBorder($cell['borderbin']);
  21194. }
  21195. else {
  21196. $cbord = &$cells[$i][$j];
  21197. }
  21198. // mPDF 4.3.009 Binary packed data
  21199. if (!$cbord['border'] && isset($table['border']) && $table['border'] && $this->table_border_attr_set) {
  21200. $cbord['border'] = $table['border'];
  21201. $cbord['border_details'] = $table['border_details'];
  21202. }
  21203. if (isset($cell['colspan']) && $cell['colspan']>1) { $ccolsp = $cell['colspan']; }
  21204. else { $ccolsp = 1; }
  21205. if (isset($cell['rowspan']) && $cell['rowspan']>1) { $crowsp = $cell['rowspan']; }
  21206. else { $crowsp = 1; }
  21207. // mPDF 3.0
  21208. $cbord['border_details']['cellposdom'] = ((($i+1)/$numrows) / 10000 ) + ((($j+1)/$numcols) / 10 );
  21209. // Inherit Cell border from Table border
  21210. if ($this->table_border_css_set && !$table['borders_separate']) {
  21211. if ($i == 0) {
  21212. $this->_table2cellBorder($table['border_details']['T'], $cbord['border_details']['T'], $cbord['border'], _BORDER_TOP); // mPDF 4.3.009
  21213. }
  21214. if ($i == ($numrows-1) || ($i+$crowsp) == ($numrows) ) {
  21215. $this->_table2cellBorder($table['border_details']['B'], $cbord['border_details']['B'], $cbord['border'], _BORDER_BOTTOM); // mPDF 4.3.009
  21216. }
  21217. if ($j == 0) {
  21218. $this->_table2cellBorder($table['border_details']['L'], $cbord['border_details']['L'], $cbord['border'], _BORDER_LEFT); // mPDF 4.3.009
  21219. }
  21220. if ($j == ($numcols-1) || ($j+$ccolsp) == ($numcols) ) {
  21221. $this->_table2cellBorder($table['border_details']['R'], $cbord['border_details']['R'], $cbord['border'], _BORDER_RIGHT); // mPDF 4.3.009
  21222. }
  21223. }
  21224. /*-- TABLES-ADVANCED-BORDERS --*/
  21225. if (isset($table['topntail']) && $table['topntail']) {
  21226. if ($i == 0) {
  21227. $cbord['border_details']['T'] = $this->border_details($table['topntail']);
  21228. $this->setBorder($cbord['border'], _BORDER_TOP);
  21229. if ($table['borders_separate']) {
  21230. $cbord['border_details']['B'] = $this->border_details($table['topntail']);
  21231. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  21232. }
  21233. }
  21234. else if (($i == $this->tableheadernrows) && $this->usetableheader) {
  21235. if (!$table['borders_separate']) {
  21236. $cbord['border_details']['T'] = $this->border_details($table['topntail']);
  21237. $this->setBorder($cbord['border'], _BORDER_TOP);
  21238. }
  21239. }
  21240. // Added v1.4 for TFOOT
  21241. else if (($i == ($numrows-1) ) && $this->tabletfoot) {
  21242. $cbord['border_details']['T'] = $this->border_details($table['topntail']);
  21243. $this->setBorder($cbord['border'], _BORDER_TOP);
  21244. }
  21245. else if ($this->tabletheadjustfinished) { // $this->tabletheadjustfinished called from tableheader
  21246. if (!$table['borders_separate']) {
  21247. $cbord['border_details']['T'] = $this->border_details($table['topntail']);
  21248. $this->setBorder($cbord['border'], _BORDER_TOP);
  21249. }
  21250. }
  21251. if ($i == ($numrows-1) || ($i+$crowsp) == ($numrows) ) {
  21252. $cbord['border_details']['B'] = $this->border_details($table['topntail']);
  21253. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  21254. }
  21255. }
  21256. if (isset($table['thead-underline']) && $table['thead-underline']) {
  21257. if ($table['borders_separate']) {
  21258. if ($i == 0) {
  21259. $cbord['border_details']['B'] = $this->border_details($table['thead-underline']);
  21260. $this->setBorder($cbord['border'], _BORDER_BOTTOM);
  21261. }
  21262. }
  21263. else {
  21264. if (($i == $this->tableheadernrows) && $this->usetableheader) {
  21265. $cbord['border_details']['T'] = $this->border_details($table['thead-underline']);
  21266. $this->setBorder($cbord['border'], _BORDER_TOP);
  21267. }
  21268. else if ($this->tabletheadjustfinished) { // $this->tabletheadjustfinished called from tableheader
  21269. $cbord['border_details']['T'] = $this->border_details($table['thead-underline']);
  21270. $this->setBorder($cbord['border'], _BORDER_TOP);
  21271. }
  21272. }
  21273. }
  21274. // Collapse Border - Algorithm for conflicting borders
  21275. // Hidden >> Width >> double>solid>dashed>dotted... >> style set on cell>table >> top/left>bottom/right
  21276. // mPDF 3.0
  21277. // Do not turn off border which is overridden
  21278. // Needed for page break for TOP/BOTTOM both to be defined in Collapsed borders
  21279. // Means it is painted twice. (Left/Right can still disable overridden border)
  21280. if (!$table['borders_separate'] && (!$this->usetableheader || $i>($this->tableheadernrows-1)) ) {
  21281. if ($i < ($numrows-1) || ($i+$crowsp) < $numrows ) { // Bottom
  21282. for ($cspi = 0; $cspi<$ccolsp; $cspi++) {
  21283. // already defined Top for adjacent cell below
  21284. if (isset($cells[($i+$crowsp)][$j+$cspi])) {
  21285. if ($this->packTableData) {
  21286. $celladj = $this->_unpackCellBorder($cells[($i+$crowsp)][$j+$cspi]['borderbin']); // mPDF 4.3.009 Binary packed data
  21287. }
  21288. else { $celladj =& $cells[($i+$crowsp)][$j+$cspi]; }
  21289. }
  21290. else { $celladj = false; }
  21291. if ($celladj && $celladj['border_details']['T']['s'] == 1) {
  21292. $csadj = $celladj['border_details']['T']['w'];
  21293. $csthis = $cbord['border_details']['B']['w'];
  21294. // Hidden
  21295. if ($cbord['border_details']['B']['style']=='hidden') {
  21296. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  21297. $this->setBorder($celladj['border'] , _BORDER_TOP, false);
  21298. $this->setBorder($cbord['border'] , _BORDER_BOTTOM , false);
  21299. }
  21300. else if ($celladj['border_details']['T']['style']=='hidden') {
  21301. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  21302. $this->setBorder($cbord['border'] , _BORDER_BOTTOM , false);
  21303. $this->setBorder($celladj['border'] , _BORDER_TOP, false);
  21304. }
  21305. // Width
  21306. else if ($csthis > $csadj) {
  21307. 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
  21308. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  21309. $this->setBorder($cbord['border'] , _BORDER_BOTTOM);
  21310. }
  21311. }
  21312. else if ($csadj > $csthis) {
  21313. if ($ccolsp < 2) { // don't overwrite this cell if it spans
  21314. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  21315. $this->setBorder($celladj['border'] , _BORDER_TOP);
  21316. }
  21317. }
  21318. // double>solid>dashed>dotted...
  21319. else if (array_search($cbord['border_details']['B']['style'],$this->borderstyles) > array_search($celladj['border_details']['T']['style'],$this->borderstyles)) {
  21320. 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
  21321. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  21322. $this->setBorder($cbord['border'] , _BORDER_BOTTOM );
  21323. }
  21324. }
  21325. else if (array_search($celladj['border_details']['T']['style'],$this->borderstyles) > array_search($cbord['border_details']['B']['style'],$this->borderstyles)) {
  21326. if ($ccolsp < 2) { // don't overwrite this cell if it spans
  21327. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  21328. $this->setBorder($celladj['border'] , _BORDER_TOP);
  21329. }
  21330. }
  21331. // Style set on cell vs. table
  21332. else if ($celladj['border_details']['T']['dom'] > $cbord['border_details']['B']['dom']) {
  21333. if ($ccolsp < 2) { // don't overwrite this cell if it spans
  21334. $cbord['border_details']['B'] = $celladj['border_details']['T'];
  21335. $this->setBorder($celladj['border'] , _BORDER_TOP);
  21336. }
  21337. }
  21338. // Style set on cell vs. table - OR - LEFT/TOP (cell) in preference to BOTTOM/RIGHT
  21339. else {
  21340. 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
  21341. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  21342. $this->setBorder($cbord['border'] , _BORDER_BOTTOM );
  21343. }
  21344. }
  21345. }
  21346. else if ($celladj) {
  21347. 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
  21348. $celladj['border_details']['T'] = $cbord['border_details']['B'];
  21349. }
  21350. }
  21351. // mPDF 4.3.009
  21352. if ($celladj && $this->packTableData) { $cells[($i+$crowsp)][$j+$cspi]['borderbin'] = $this->_packCellBorder($celladj); }
  21353. unset($celladj);
  21354. }
  21355. }
  21356. if ($j < ($numcols-1) || ($j+$ccolsp) < $numcols ) { // Right
  21357. for ($cspi = 0; $cspi<$crowsp; $cspi++) {
  21358. // already defined Left for adjacent cell to R
  21359. if (isset($cells[$i+$cspi][$j+$ccolsp])) {
  21360. if ($this->packTableData) {
  21361. $celladj = $this->_unpackCellBorder($cells[$i+$cspi][$j+$ccolsp]['borderbin']); // mPDF 4.3.009 Binary packed data
  21362. }
  21363. else { $celladj =& $cells[$i+$cspi][$j+$ccolsp]; }
  21364. }
  21365. else { $celladj = false; }
  21366. if ($celladj && $celladj['border_details']['L']['s'] == 1) {
  21367. $csadj = $celladj['border_details']['L']['w'];
  21368. $csthis = $cbord['border_details']['R']['w'];
  21369. // Hidden
  21370. if ($cbord['border_details']['R']['style']=='hidden') {
  21371. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  21372. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  21373. $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  21374. }
  21375. else if ($celladj['border_details']['L']['style']=='hidden') {
  21376. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  21377. $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  21378. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  21379. }
  21380. // Width
  21381. else if ($csthis > $csadj) {
  21382. 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
  21383. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  21384. $this->setBorder($cbord['border'] , _BORDER_RIGHT);
  21385. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  21386. }
  21387. }
  21388. else if ($csadj > $csthis) {
  21389. if ($crowsp < 2) { // don't overwrite this cell if it spans
  21390. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  21391. $this->setBorder($cbord['border'] , _BORDER_RIGHT, false);
  21392. $this->setBorder($celladj['border'] , _BORDER_LEFT);
  21393. }
  21394. }
  21395. // double>solid>dashed>dotted...
  21396. else if (array_search($cbord['border_details']['R']['style'],$this->borderstyles) > array_search($celladj['border_details']['L']['style'],$this->borderstyles)) {
  21397. 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
  21398. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  21399. $this->setBorder($celladj['border'] , _BORDER_LEFT, false);
  21400. $this->setBorder($cbord['border'] , _BORDER_RIGHT);
  21401. }
  21402. }
  21403. else if (array_search($celladj['border_details']['L']['style'],$this->borderstyles) > array_search($cbord['border_details']['R']['style'],$this->borderstyles)) {
  21404. if ($crowsp < 2) { // don't overwrite this cell if it spans
  21405. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  21406. $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  21407. $this->setBorder($celladj['border'] , _BORDER_LEFT);
  21408. }
  21409. }
  21410. // Style set on cell vs. table
  21411. else if ($celladj['border_details']['L']['dom'] > $cbord['border_details']['R']['dom']) {
  21412. if ($crowsp < 2) { // don't overwrite this cell if it spans
  21413. $cbord['border_details']['R'] = $celladj['border_details']['L'];
  21414. // mPDF 3.0 $this->setBorder($cbord['border'] , _BORDER_RIGHT , false);
  21415. $this->setBorder($celladj['border'] , _BORDER_LEFT);
  21416. }
  21417. }
  21418. // Style set on cell vs. table - OR - LEFT/TOP (cell) in preference to BOTTOM/RIGHT
  21419. else {
  21420. 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
  21421. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  21422. // mPDF 3.0 $this->setBorder($celladj['border'] , _BORDER_LEFT , false);
  21423. $this->setBorder($cbord['border'] , _BORDER_RIGHT);
  21424. }
  21425. }
  21426. }
  21427. else if ($celladj) {
  21428. // if right-cell border is not set
  21429. 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
  21430. $celladj['border_details']['L'] = $cbord['border_details']['R'];
  21431. // mPDF 3.0 $this->setBorder($celladj['border'] , _BORDER_LEFT , false);
  21432. }
  21433. }
  21434. // mPDF 4.3.009
  21435. if ($celladj && $this->packTableData) { $cells[$i+$cspi][$j+$ccolsp]['borderbin'] = $this->_packCellBorder($celladj); }
  21436. unset($celladj);
  21437. }
  21438. }
  21439. }
  21440. // Set maximum cell border width meeting at LRTB edges of cell - used for extended cell border
  21441. // ['border_details']['mbw']['LT'] = meeting border width - Left border - Top end
  21442. if (!$table['borders_separate']) {
  21443. $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $cbord['border_details']['L']['w']);
  21444. $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $cbord['border_details']['R']['w']);
  21445. $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $cbord['border_details']['T']['w']);
  21446. $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $cbord['border_details']['B']['w']);
  21447. $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $cbord['border_details']['L']['w']);
  21448. $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $cbord['border_details']['R']['w']);
  21449. $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $cbord['border_details']['T']['w']);
  21450. $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $cbord['border_details']['B']['w']);
  21451. if (($i+$crowsp) < $numrows && isset($cells[$i+$crowsp][$j])) { // Has Bottom adjoining cell
  21452. if ($this->packTableData) {
  21453. $celladj = $this->_unpackCellBorder($cells[$i+$crowsp][$j]['borderbin']); // mPDF 4.3.009 Binary packed data
  21454. }
  21455. else { $celladj =& $cells[$i+$crowsp][$j]; }
  21456. $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $celladj['border_details']['L']['w'], $celladj['border_details']['mbw']['TL']);
  21457. $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $celladj['border_details']['R']['w'], $celladj['border_details']['mbw']['TR']);
  21458. $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $celladj['border_details']['mbw']['LT']);
  21459. $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $celladj['border_details']['mbw']['RT']);
  21460. unset($celladj);
  21461. }
  21462. if (($j+$ccolsp) < $numcols && isset($cells[$i][$j+$ccolsp])) { // Has Right adjoining cell
  21463. if ($this->packTableData) {
  21464. $celladj = $this->_unpackCellBorder($cells[$i][$j+$ccolsp]['borderbin']); // mPDF 4.3.009 Binary packed data
  21465. }
  21466. else { $celladj =& $cells[$i][$j+$ccolsp]; }
  21467. $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $celladj['border_details']['T']['w'], $celladj['border_details']['mbw']['LT']);
  21468. $cbord['border_details']['mbw']['RB'] = max($cbord['border_details']['mbw']['RB'], $celladj['border_details']['B']['w'], $celladj['border_details']['mbw']['LB']);
  21469. $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $celladj['border_details']['mbw']['TL']);
  21470. $cbord['border_details']['mbw']['BR'] = max($cbord['border_details']['mbw']['BR'], $celladj['border_details']['mbw']['BL']);
  21471. unset($celladj);
  21472. }
  21473. if ($i > 0 && isset($cells[$i-1][$j]) && (($this->packTableData && $cells[$i-1][$j]['borderbin']) || $cells[$i-1][$j]['border'])) { // Has Top adjoining cell
  21474. if ($this->packTableData) {
  21475. $celladj = $this->_unpackCellBorder($cells[$i-1][$j]['borderbin']); // mPDF 4.3.009 Binary packed data
  21476. }
  21477. else { $celladj =& $cells[$i-1][$j]; }
  21478. $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['L']['w'], $celladj['border_details']['mbw']['BL']);
  21479. $cbord['border_details']['mbw']['TR'] = max($cbord['border_details']['mbw']['TR'], $celladj['border_details']['R']['w'], $celladj['border_details']['mbw']['BR']);
  21480. $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $celladj['border_details']['mbw']['LB']);
  21481. $cbord['border_details']['mbw']['RT'] = max($cbord['border_details']['mbw']['RT'], $celladj['border_details']['mbw']['RB']);
  21482. if ($celladj['border_details']['mbw']['BL']) {
  21483. $celladj['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['mbw']['BL']);
  21484. }
  21485. if ($celladj['border_details']['mbw']['BR'] ) {
  21486. $celladj['border_details']['mbw']['BR'] = max($celladj['border_details']['mbw']['BR'], $cbord['border_details']['mbw']['TR']);
  21487. }
  21488. if ($this->packTableData) { $cells[$i-1][$j]['borderbin'] = $this->_packCellBorder($celladj); }
  21489. unset($celladj);
  21490. }
  21491. if ($j > 0 && isset($cells[$i][$j-1]) && (($this->packTableData && $cells[$i][$j-1]['borderbin']) || $cells[$i][$j-1]['border'])) { // Has Left adjoining cell
  21492. if ($this->packTableData) {
  21493. $celladj = $this->_unpackCellBorder($cells[$i][$j-1]['borderbin']); // mPDF 4.3.009 Binary packed data
  21494. }
  21495. else { $celladj =& $cells[$i][$j-1]; }
  21496. $cbord['border_details']['mbw']['LT'] = max($cbord['border_details']['mbw']['LT'], $celladj['border_details']['T']['w'], $celladj['border_details']['mbw']['RT']);
  21497. $cbord['border_details']['mbw']['LB'] = max($cbord['border_details']['mbw']['LB'], $celladj['border_details']['B']['w'], $celladj['border_details']['mbw']['RB']);
  21498. $cbord['border_details']['mbw']['BL'] = max($cbord['border_details']['mbw']['BL'], $celladj['border_details']['mbw']['BR']);
  21499. $cbord['border_details']['mbw']['TL'] = max($cbord['border_details']['mbw']['TL'], $celladj['border_details']['mbw']['TR']);
  21500. if ($celladj['border_details']['mbw']['RT']) {
  21501. $celladj['border_details']['mbw']['RT'] = max($celladj['border_details']['mbw']['RT'], $cbord['border_details']['mbw']['LT']);
  21502. }
  21503. if ($celladj['border_details']['mbw']['RB']) {
  21504. $celladj['border_details']['mbw']['RB'] = max($celladj['border_details']['mbw']['RB'], $cbord['border_details']['mbw']['LB']);
  21505. }
  21506. if ($this->packTableData) { $cells[$i][$j-1]['borderbin'] = $this->_packCellBorder($celladj); }
  21507. unset($celladj);
  21508. }
  21509. // Update maximum cell border width at LRTB edges of table - used for overall table width
  21510. if ($j == 0 && $cbord['border_details']['L']['w']) {
  21511. $table['max_cell_border_width']['L'] = max($table['max_cell_border_width']['L'],$cbord['border_details']['L']['w']);
  21512. }
  21513. if (($j == ($numcols-1) || ($j+$ccolsp) == $numcols ) && $cbord['border_details']['R']['w']) {
  21514. $table['max_cell_border_width']['R'] = max($table['max_cell_border_width']['R'],$cbord['border_details']['R']['w']);
  21515. }
  21516. if ($i == 0 && $cbord['border_details']['T']['w']) {
  21517. $table['max_cell_border_width']['T'] = max($table['max_cell_border_width']['T'],$cbord['border_details']['T']['w']);
  21518. }
  21519. if (($i == ($numrows-1) || ($i+$crowsp) == $numrows ) && $cbord['border_details']['B']['w']) {
  21520. $table['max_cell_border_width']['B'] = max($table['max_cell_border_width']['B'],$cbord['border_details']['B']['w']);
  21521. }
  21522. }
  21523. /*-- END TABLES-ADVANCED-BORDERS --*/
  21524. // mPDF 4.3.009 Binary packed data
  21525. if ($this->packTableData) { $cell['borderbin'] = $this->_packCellBorder($cbord); }
  21526. unset($cbord );
  21527. unset($cell );
  21528. }
  21529. }
  21530. }
  21531. unset($cell );
  21532. }
  21533. // END FIX BORDERS ************************************************************************************
  21534. function _tableWrite(&$table){
  21535. $level = $table['level'];
  21536. $levelid = $table['levelid'];
  21537. $cells = &$table['cells'];
  21538. $numcols = $table['nc'];
  21539. $numrows = $table['nr'];
  21540. if ($this->ColActive && $level==1) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  21541. // TABLE TOP MARGIN
  21542. if ($table['margin']['T']) {
  21543. if (!$this->table_rotate && $level==1) {
  21544. $this->DivLn($table['margin']['T'],$this->blklvl,true,1); // collapsible
  21545. }
  21546. else {
  21547. $this->y += ($table['margin']['T']);
  21548. }
  21549. }
  21550. // Advance down page by half width of top border
  21551. if ($table['borders_separate']) {
  21552. $adv = $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2;
  21553. }
  21554. else {
  21555. $adv = $table['max_cell_border_width']['T']/2;
  21556. }
  21557. if (!$this->table_rotate && $level==1) { $this->DivLn($adv); }
  21558. else { $this->y += $adv; }
  21559. if ($level==1) {
  21560. $this->x = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['padding_left'] + $this->blk[$this->blklvl]['border_left']['w'];
  21561. $x0 = $this->x;
  21562. $y0 = $this->y;
  21563. $right = $x0 + $this->blk[$this->blklvl]['inner_width'];
  21564. $outerfilled = $this->y; // Keep track of how far down the outer DIV bgcolor is painted (NB rowspans)
  21565. $this->outerfilled = $this->y;
  21566. }
  21567. else {
  21568. $x0 = $this->x;
  21569. $y0 = $this->y;
  21570. $right = $x0 + $table['w']; // ????
  21571. // $outerfilled = $this->y; // Keep track of how far down the outer DIV bgcolor is painted (NB rowspans)
  21572. }
  21573. if ($this->table_rotate) {
  21574. $temppgwidth = $this->tbrot_maxw;
  21575. $this->PageBreakTrigger = $pagetrigger = $y0 + ($this->blk[$this->blklvl]['inner_width']);
  21576. if ($level==1) {
  21577. $this->tbrot_y0 = $this->y - $adv - $table['margin']['T'] ;
  21578. $this->tbrot_x0 = $this->x;
  21579. $this->tbrot_w = $table['w'];
  21580. if ($table['borders_separate']) { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2; }
  21581. else { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['max_cell_border_width']['T']; }
  21582. }
  21583. }
  21584. else {
  21585. $this->PageBreakTrigger = $pagetrigger = ($this->h - $this->bMargin);
  21586. if ($level==1) {
  21587. $temppgwidth = $this->blk[$this->blklvl]['inner_width'];
  21588. if (isset($table['a']) and ($table['w'] < $this->blk[$this->blklvl]['inner_width'])) {
  21589. if ($table['a']=='C') { $x0 += ((($right-$x0) - $table['w'])/2); }
  21590. else if ($table['a']=='R') { $x0 = $right - $table['w']; }
  21591. }
  21592. }
  21593. else {
  21594. $temppgwidth = $table['w'];
  21595. }
  21596. }
  21597. // mPDF 4.2 Clipping Output
  21598. if ($table['overflow']=='hidden' && $level==1 && !$this->table_rotate && !$this->ColActive) {
  21599. //Bounding rectangle to clip
  21600. $this->tableClipPath = sprintf('q %.3f %.3f %.3f %.3f re W n',$x0*$this->k,$this->h*$this->k,$this->blk[$this->blklvl]['inner_width']*$this->k,-$this->h*$this->k);
  21601. $this->_out($this->tableClipPath);
  21602. }
  21603. else { $this->tableClipPath = ''; }
  21604. if ($table['borders_separate']) { $indent = $table['margin']['L'] + $table['border_details']['L']['w'] + $table['padding']['L'] + $table['border_spacing_H']/2; }
  21605. else { $indent = $table['margin']['L'] + $table['max_cell_border_width']['L']/2; }
  21606. $x0 += $indent;
  21607. $returny = 0;
  21608. $tableheader = array();
  21609. $tablefooter = array(); // mPDF 4.0
  21610. $tablefooterrowheight = 0;
  21611. $footery = 0;
  21612. // mPD 3.0 Set the Page & Column where table starts
  21613. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  21614. $tablestartpage = 'EVEN';
  21615. }
  21616. else if (($this->mirrorMargins) && (($this->page)%2==1)) { // ODD
  21617. $tablestartpage = 'ODD';
  21618. }
  21619. else { $tablestartpage = ''; }
  21620. if ($this->ColActive) { $tablestartcolumn = $this->CurrCol; }
  21621. else { $tablestartcolumn = ''; }
  21622. // mPDF 4.0 Initialise variable
  21623. $y = $h = 0;
  21624. // mPDF 4.0 Table Footer
  21625. for( $i = 0 ; $i < $numrows ; $i++ ) { //Rows
  21626. if ($this->progressBar) { $this->UpdateProgressBar(7,intval(30 + ($i*40/$numrows)),' '); } // *PROGRESS-BAR*
  21627. if (isset($table['is_tfoot'][$i]) && $table['is_tfoot'][$i] && $level==1) {
  21628. $tablefooterrowheight += $table['hr'][$i];
  21629. for( $j = 0 ; $j < $numcols ; $j++ ) { //Columns
  21630. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  21631. $cell = &$cells[$i][$j];
  21632. list($x,$w) = $this->_tableGetWidth($table, $i, $j);
  21633. list($y,$h) = $this->_tableGetHeight($table, $i, $j);
  21634. $x += $x0;
  21635. $y += $y0;
  21636. //Get info of tfoot ==>> table footer
  21637. $tablefooter[$i][$j]['x'] = $x;
  21638. $tablefooter[$i][$j]['y'] = $y;
  21639. $tablefooter[$i][$j]['h'] = $h;
  21640. $tablefooter[$i][$j]['w'] = $w;
  21641. $tablefooter[$i][$j]['text'] = $cell['text'];
  21642. if (isset($cell['textbuffer'])) { $tablefooter[$i][$j]['textbuffer'] = $cell['textbuffer']; }
  21643. else { $tablefooter[$i][$j]['textbuffer'] = ''; }
  21644. $tablefooter[$i][$j]['a'] = $cell['a'];
  21645. $tablefooter[$i][$j]['R'] = $cell['R'];
  21646. $tablefooter[$i][$j]['va'] = $cell['va'];
  21647. $tablefooter[$i][$j]['mih'] = $cell['mih'];
  21648. $tablefooter[$i][$j]['gradient'] = $cell['gradient']; // *GRADIENTS*
  21649. $tablefooter[$i][$j]['background-image'] = $cell['background-image']; // *BACKGROUND-IMAGES*
  21650. //CELL FILL BGCOLOR
  21651. if (!$this->simpleTables){ // mPDF 4.2.017
  21652. // mPDF 4.3.009
  21653. if ($this->packTableData) {
  21654. $c = $this->_unpackCellBorder($cell['borderbin']);
  21655. $tablefooter[$i][$j]['border'] = $c['border'];
  21656. $tablefooter[$i][$j]['border_details'] = $c['border_details'];
  21657. }
  21658. else {
  21659. $tablefooter[$i][$j]['border'] = $cell['border'];
  21660. $tablefooter[$i][$j]['border_details'] = $cell['border_details'];
  21661. }
  21662. }
  21663. else if ($this->simpleTables){
  21664. $tablefooter[$i][$j]['border'] = $table['simple']['border'];
  21665. $tablefooter[$i][$j]['border_details'] = $table['simple']['border_details'];
  21666. }
  21667. // mPDF 4.3.006
  21668. $fill = isset($cell['bgcolor']) ? $cell['bgcolor'] : 0;
  21669. $tablefooter[$i][$j]['bgcolor'] = $fill;
  21670. $tablefooter[$i][$j]['padding'] = $cell['padding'];
  21671. $tablefooter[$i][$j]['rowspan'] = $cell['rowspan'];
  21672. $tablefooter[$i][$j]['colspan'] = $cell['colspan'];
  21673. }
  21674. }
  21675. }
  21676. }
  21677. //Draw Table Contents and Borders
  21678. for( $i = 0 ; $i < $numrows ; $i++ ) { //Rows
  21679. // Get Maximum row/cell height in row - including rowspan>1 + 1 overlapping
  21680. $maxrowheight = 0;
  21681. for( $j = 0 ; $j < $numcols ; $j++ ) { //Columns
  21682. list($y,$h) = $this->_tableGetHeight($table, $i, $j);
  21683. $maxrowheight = max($maxrowheight,$h);
  21684. }
  21685. $skippage = false;
  21686. $newpagestarted = false;
  21687. for( $j = 0 ; $j < $numcols ; $j++ ) { //Columns
  21688. if (isset($cells[$i][$j]) && $cells[$i][$j]) {
  21689. $cell = &$cells[$i][$j];
  21690. list($x,$w) = $this->_tableGetWidth($table, $i, $j);
  21691. list($y,$h) = $this->_tableGetHeight($table, $i, $j);
  21692. $x += $x0;
  21693. $y += $y0;
  21694. $y -= $returny;
  21695. if ($table['borders_separate']) {
  21696. // mPDF 3.0
  21697. if (!empty($tablefooter) || $i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows) || (!isset($cell['rowspan']) && ($i+1) == $numrows) ) {
  21698. $extra = $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  21699. //$extra = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  21700. }
  21701. else {
  21702. $extra = $table['border_spacing_V']/2;
  21703. }
  21704. }
  21705. else { $extra = $table['max_cell_border_width']['B']/2; }
  21706. // mPDF 4.5.004
  21707. if ($j==0 && ((($y + $maxrowheight + $extra ) > ($pagetrigger+0.001)) || (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && ($y + $maxrowheight + $tablefooterrowheight + $extra) > $pagetrigger) && ($i < ($numrows - $this->tableheadernrows))) && ($y0 >0 || $x0 > 0) && !$this->InFooter) {
  21708. if (!$skippage) {
  21709. // mPDF 4.0
  21710. //if (!$this->ColActive && !empty($tablefooter) && $i > 0 ) {
  21711. // mPDF 4.4.015
  21712. if (($this->keepColumns || !$this->ColActive) && !empty($tablefooter) && $i > 0 ) {
  21713. $this->y = $y;
  21714. $ya = $this->y;
  21715. $this->TableHeaderFooter($tablefooter,$tablestartpage,$tablestartcolumn,'F');
  21716. if ($this->table_rotate) {
  21717. $this->tbrot_h += $this->y - $ya ;
  21718. }
  21719. }
  21720. $y -= $y0;
  21721. $returny += $y;
  21722. $oldcolumn = $this->CurrCol;
  21723. if ($this->AcceptPageBreak()) {
  21724. $newpagestarted = true;
  21725. $this->y = $y + $y0;
  21726. // mPDF 3.0 - Move down to account for border-spacing or
  21727. // extra half border width in case page breaks in middle
  21728. if($i>0 && !$this->table_rotate && $level==1 && !$this->ColActive) {
  21729. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2; }
  21730. else {
  21731. $maxbwbottom = 0;
  21732. for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) {
  21733. if (isset($cells[$i][$ctj]) && $cells[$i][$ctj]) {
  21734. if (!$this->simpleTables){ // mPDF 4.2.017
  21735. // mPDF 4.3.009
  21736. if ($this->packTableData) {
  21737. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$i][$ctj]['borderbin']);
  21738. }
  21739. else {
  21740. $bt = $cells[$i][$ctj]['border_details']['T']['w'];
  21741. }
  21742. $maxbwbottom = max($maxbwbottom , $bt);
  21743. }
  21744. else if ($this->simpleTables){
  21745. $maxbwbottom = max($maxbwbottom , $table['simple']['border_details']['T']['w']);
  21746. }
  21747. }
  21748. }
  21749. $adv = $maxbwbottom /2;
  21750. }
  21751. $this->y += $adv;
  21752. }
  21753. // mPDF 3.0 Rotated table split over pages - needs this->y for borders/backgrounds
  21754. if($i>0 && $this->table_rotate && $level==1) {
  21755. $this->y = $y0 + $this->tbrot_w;
  21756. }
  21757. // mPDF 4.2
  21758. if ($this->tableClipPath ) { $this->_out("Q"); }
  21759. $this->AddPage($this->CurOrientation);
  21760. // mPDF 4.2
  21761. if ($this->tableClipPath ) { $this->_out($this->tableClipPath); }
  21762. // Added to correct for OddEven Margins
  21763. $x=$x +$this->MarginCorrection;
  21764. $x0=$x0 +$this->MarginCorrection;
  21765. // mPDF 3.0 - Move down to account for half of top border-spacing or
  21766. // extra half border width in case page was broken in middle
  21767. if($i>0 && !$this->table_rotate && $level==1 && !$this->usetableheader) {
  21768. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2; }
  21769. else {
  21770. $maxbwtop = 0;
  21771. for( $ctj = 0 ; $ctj < $numcols ; $ctj++ ) {
  21772. if (isset($cells[$i][$ctj]) && $cells[$i][$ctj]) {
  21773. if (!$this->simpleTables){ // mPDF 4.2.017
  21774. // mPDF 4.3.009
  21775. if ($this->packTableData) {
  21776. list($bt,$br,$bb,$bl) = $this->_getBorderWidths($cells[$i][$ctj]['borderbin']);
  21777. }
  21778. else {
  21779. $bt = $cells[$i][$ctj]['border_details']['T']['w'];
  21780. }
  21781. $maxbwtop = max($maxbwtop, $bt);
  21782. }
  21783. else if ($this->simpleTables){
  21784. $maxbwtop = max($maxbwtop, $table['simple']['border_details']['T']['w']);
  21785. }
  21786. }
  21787. }
  21788. $adv = $maxbwtop /2;
  21789. }
  21790. $this->y += $adv;
  21791. }
  21792. if ($this->table_rotate) {
  21793. // mPDF 3.0 Rotated table
  21794. //$this->tbrot_x0 = $x0;
  21795. $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'];
  21796. if ($table['borders_separate']) { $this->tbrot_h = $table['margin']['T'] + $table['padding']['T'] + $table['border_details']['T']['w'] + $table['border_spacing_V']/2; }
  21797. else { $this->tbrot_h = $table['margin']['T'] + $table['max_cell_border_width']['T'] ; }
  21798. $this->tbrot_y0 = $this->y;
  21799. $pagetrigger = $y0 + ($this->blk[$this->blklvl]['inner_width']);
  21800. }
  21801. else {
  21802. $pagetrigger = $this->PageBreakTrigger;
  21803. }
  21804. if ($this->kwt_saved && $level==1) {
  21805. $this->kwt_moved = true;
  21806. }
  21807. // Disable Table header repeat if Keep Block together
  21808. if ($this->usetableheader && !$this->keep_block_together && !empty($tableheader)) {
  21809. $ya = $this->y;
  21810. $this->TableHeaderFooter($tableheader,$tablestartpage,$tablestartcolumn,'H'); // mPDF 4.0
  21811. if ($this->table_rotate) {
  21812. $this->tbrot_h = $this->y - $ya ;
  21813. }
  21814. }
  21815. // mPDF 3.0
  21816. else if ($i==0 && !$this->keep_block_together && !$this->table_rotate && $level==1 && !$this->ColActive) {
  21817. // Advance down page
  21818. if ($table['borders_separate']) { $adv = $table['border_spacing_V']/2 + $table['border_details']['T']['w'] + $table['padding']['T']; }
  21819. else { $adv = $table['max_cell_border_width']['T'] /2 ; }
  21820. if ($adv) {
  21821. if ($this->table_rotate) {
  21822. $this->y += ($adv);
  21823. }
  21824. else {
  21825. $this->DivLn($adv,$this->blklvl,true);
  21826. }
  21827. }
  21828. }
  21829. $outerfilled = 0;
  21830. $y0 = $this->y;
  21831. $y = $y0;
  21832. }
  21833. /*-- COLUMNS --*/
  21834. // COLS
  21835. // COLUMN CHANGE
  21836. if ($this->CurrCol != $oldcolumn) {
  21837. // Added to correct for Columns
  21838. $x += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  21839. $x0 += $this->ChangeColumn * ($this->ColWidth+$this->ColGap);
  21840. if ($this->CurrCol == 0) { // just added a page - possibly with tableheader
  21841. $y0 = $this->y; // this->y0 is global used by Columns - $y0 is internal to tablewrite
  21842. }
  21843. else {
  21844. $y0 = $this->y0; // this->y0 is global used by Columns - $y0 is internal to tablewrite
  21845. }
  21846. $y = $y0;
  21847. $outerfilled = 0;
  21848. // mPDF 4.4.015
  21849. if ($this->CurrCol != 0 && ($this->keepColumns && $this->ColActive) && !empty($tableheader) && $i > 0 ) {
  21850. $this->x = $x;
  21851. $this->y = $y;
  21852. $this->TableHeaderFooter($tableheader,$tablestartpage,$tablestartcolumn,'H');
  21853. $y0 = $y=$this->y;
  21854. }
  21855. }
  21856. /*-- END COLUMNS --*/
  21857. }
  21858. $skippage = true;
  21859. }
  21860. $this->x = $x;
  21861. $this->y = $y;
  21862. if ($this->kwt_saved && $level==1) {
  21863. $this->printkwtbuffer();
  21864. $x0 = $x = $this->x;
  21865. $y0 = $y = $this->y;
  21866. $this->kwt_moved = false;
  21867. $this->kwt_saved = false;
  21868. }
  21869. // Set the Page & Column where table starts
  21870. if ($i==0 && $j==0 && $level==1) {
  21871. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  21872. $tablestartpage = 'EVEN';
  21873. }
  21874. else if (($this->mirrorMargins) && (($this->page)%2==1)) { // ODD
  21875. $tablestartpage = 'ODD';
  21876. }
  21877. else { $tablestartpage = ''; }
  21878. if ($this->ColActive) { $tablestartcolumn = $this->CurrCol; } // *COLUMNS*
  21879. }
  21880. //ALIGN
  21881. $align = $cell['a'];
  21882. /*-- COLUMNS --*/
  21883. // mPDF 3.0 - If outside columns, this is done in PaintDivBB
  21884. if ($this->ColActive) {
  21885. //OUTER FILL BGCOLOR of DIVS
  21886. if ($this->blklvl > 0 && ($j==0) && !$this->table_rotate && $level==1) {
  21887. $firstblockfill = $this->GetFirstBlockFill();
  21888. if ($firstblockfill && $this->blklvl >= $firstblockfill) {
  21889. $divh = $maxrowheight;
  21890. // Last row
  21891. if (isset($cell['rowspan']) && (($i == $numrows-1 && $cell['rowspan']<2) || ($cell['rowspan']>1 && ($i + $cell['rowspan']-1) == $numrows-1))) {
  21892. if ($table['borders_separate']) {
  21893. $adv = $table['margin']['B'] + $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2;
  21894. }
  21895. else {
  21896. $adv = $table['margin']['B'] + $table['max_cell_border_width']['B']/2;
  21897. }
  21898. $divh += $adv; //last row: fill bottom half of bottom border (y advanced at end)
  21899. }
  21900. if (($this->y + $divh) > $outerfilled ) { // if not already painted by previous rowspan
  21901. $bak_x = $this->x;
  21902. $bak_y = $this->y;
  21903. if ($outerfilled > $this->y) {
  21904. $divh = ($this->y + $divh) - $outerfilled;
  21905. $this->y = $outerfilled;
  21906. }
  21907. $this->DivLn($divh,-3,false);
  21908. $outerfilled = $this->y + $divh;
  21909. // Reset current block fill
  21910. $bcor = $this->blk[$this->blklvl]['bgcolorarray'];
  21911. if ($bcor ) $this->SetFillColor($bcor['R'],$bcor['G'],$bcor['B']);
  21912. $this->x = $bak_x;
  21913. $this->y = $bak_y;
  21914. }
  21915. }
  21916. }
  21917. }
  21918. /*-- END COLUMNS --*/
  21919. //TABLE BACKGROUND FILL BGCOLOR - for cellSpacing
  21920. if ($table['borders_separate']) {
  21921. $fill = isset($table['bgcolor'][-1]) ? $table['bgcolor'][-1] : 0; // mPDF 4.3.005
  21922. if ($fill) {
  21923. $color = $this->ConvertColor($fill);
  21924. if ($color) $this->SetFillColor($color['R'],$color['G'],$color['B']);
  21925. $xadj = ($table['border_spacing_H']/2);
  21926. $yadj = ($table['border_spacing_V']/2);
  21927. $wadj = $table['border_spacing_H'];
  21928. $hadj = $table['border_spacing_V'];
  21929. if ($i == 0) { // Top
  21930. $yadj += $table['padding']['T'];
  21931. $hadj += $table['padding']['T'];
  21932. }
  21933. if ($j == 0) { // Left
  21934. $xadj += $table['padding']['L'];
  21935. $wadj += $table['padding']['L'];
  21936. }
  21937. if ($i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows) || (!isset($cell['rowspan']) && ($i+1) == $numrows)) { // Bottom
  21938. $hadj += $table['padding']['B'];
  21939. }
  21940. if ($j == ($numcols-1) || (isset($cell['colspan']) && ($j+$cell['colspan']) == $numcols) || (!isset($cell['colspan']) && ($j+1) == $numcols)) { // Right
  21941. $wadj += $table['padding']['R'];
  21942. }
  21943. $this->Rect($x - $xadj, $y - $yadj, $w + $wadj, $h + $hadj, 'F');
  21944. }
  21945. }
  21946. // TABLE BORDER - if separate
  21947. if ($table['borders_separate'] && $table['border']) {
  21948. $halfspaceL = $table['padding']['L'] + ($table['border_spacing_H']/2);
  21949. $halfspaceR = $table['padding']['R'] + ($table['border_spacing_H']/2);
  21950. $halfspaceT = $table['padding']['T'] + ($table['border_spacing_V']/2);
  21951. $halfspaceB = $table['padding']['B'] + ($table['border_spacing_V']/2);
  21952. $tbx = $x;
  21953. $tby = $y;
  21954. $tbw = $w;
  21955. $tbh = $h;
  21956. $tab_bord = 0;
  21957. // mPDF 3.0
  21958. $corner = '';
  21959. if ($i == 0) { // Top
  21960. $tby -= $halfspaceT + ($table['border_details']['T']['w']/2);
  21961. $tbh += $halfspaceT + ($table['border_details']['T']['w']/2);
  21962. $this->setBorder($tab_bord , _BORDER_TOP);
  21963. $corner .= 'T';
  21964. }
  21965. if ($i == ($numrows-1) || (isset($cell['rowspan']) && ($i+$cell['rowspan']) == $numrows) || (!isset($cell['rowspan']) && ($i+1) == $numrows) ) { // Bottom
  21966. $tbh += $halfspaceB + ($table['border_details']['B']['w']/2);
  21967. $this->setBorder($tab_bord , _BORDER_BOTTOM);
  21968. $corner .= 'B';
  21969. }
  21970. if ($j == 0) { // Left
  21971. $tbx -= $halfspaceL + ($table['border_details']['L']['w']/2);
  21972. $tbw += $halfspaceL + ($table['border_details']['L']['w']/2);
  21973. $this->setBorder($tab_bord , _BORDER_LEFT);
  21974. $corner .= 'L';
  21975. }
  21976. if ($j == ($numcols-1) || (isset($cell['colspan']) && ($j+$cell['colspan']) == $numcols) || (!isset($cell['colspan']) && ($j+1) == $numcols)) { // Right
  21977. $tbw += $halfspaceR + ($table['border_details']['R']['w']/2);
  21978. $this->setBorder($tab_bord , _BORDER_RIGHT);
  21979. $corner .= 'R';
  21980. }
  21981. $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'] );
  21982. }
  21983. if ($table['empty_cells']!='hide' || !empty($cell['textbuffer']) || (isset($cell['nestedcontent']) && $cell['nestedcontent']) || !$table['borders_separate'] ) { $paintcell = true; }
  21984. else { $paintcell = false; }
  21985. //Set Borders
  21986. $bord = 0;
  21987. $bord_det = array();
  21988. if (!$this->simpleTables){ // mPDF 4.2.017
  21989. // mPDF 4.3.009
  21990. if ($this->packTableData) {
  21991. if ($cell['borderbin']) {
  21992. $c = $this->_unpackCellBorder($cell['borderbin']);
  21993. $bord = $c['border'];
  21994. $bord_det = $c['border_details'];
  21995. }
  21996. }
  21997. else if ($cell['border']) {
  21998. $bord = $cell['border'];
  21999. $bord_det = $cell['border_details'];
  22000. }
  22001. }
  22002. else if ($this->simpleTables){
  22003. if ($table['simple']['border']) {
  22004. $bord = $table['simple']['border'];
  22005. $bord_det = $table['simple']['border_details'];
  22006. }
  22007. }
  22008. // mPDF 4.3.006
  22009. //CELL FILL BGCOLOR
  22010. $fill = isset($cell['bgcolor']) ? $cell['bgcolor'] : 0;
  22011. if ($fill && $paintcell) {
  22012. $color = $this->ConvertColor($fill);
  22013. if ($color) $this->SetFillColor($color['R'],$color['G'],$color['B']);
  22014. if ($table['borders_separate']) {
  22015. $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');
  22016. }
  22017. else {
  22018. $this->Rect($x, $y, $w, $h, 'F');
  22019. }
  22020. }
  22021. /*-- GRADIENTS --*/
  22022. if (isset($cell['gradient']) && $cell['gradient'] && $paintcell){ // mPDF 4.3.006
  22023. $g = $this->parseBackgroundGradient($cell['gradient']);
  22024. if ($g) {
  22025. if ($table['borders_separate']) {
  22026. $px = $x+ ($table['border_spacing_H']/2);
  22027. $py = $y+ ($table['border_spacing_V']/2);
  22028. $pw = $w- $table['border_spacing_H'];
  22029. $ph = $h- $table['border_spacing_V'];
  22030. }
  22031. else {
  22032. $px = $x;
  22033. $py = $y;
  22034. $pw = $w;
  22035. $ph = $h;
  22036. }
  22037. $this->Gradient($px, $py, $pw, $ph, $g['type'], $g['col'], $g['col2'], $g['coords'], $g['extend']);
  22038. }
  22039. }
  22040. /*-- END GRADIENTS --*/
  22041. /*-- BACKGROUND-IMAGES --*/
  22042. if (isset($cell['background-image']) && $paintcell) { // mPDF 4.3.006
  22043. if ($cell['background-image']['image_id']) { // Background pattern
  22044. $n = count($this->patterns)+1;
  22045. if ($table['borders_separate']) {
  22046. $px = $x+ ($table['border_spacing_H']/2);
  22047. $py = $y+ ($table['border_spacing_V']/2);
  22048. $pw = $w- $table['border_spacing_H'];
  22049. $ph = $h- $table['border_spacing_V'];
  22050. }
  22051. else {
  22052. $px = $x;
  22053. $py = $y;
  22054. $pw = $w;
  22055. $ph = $h;
  22056. }
  22057. // mPDF 4.3.015
  22058. 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']);
  22059. $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); // mPDF 4.3.015
  22060. // mPDF 4.3.017
  22061. if ($cell['background-image']['opacity']>0 && $cell['background-image']['opacity']<1) { $opac = $this->SetAlpha($cell['background-image']['opacity'],'Normal',true); }
  22062. else { $opac = ''; }
  22063. $this->_out(sprintf('q /Pattern cs /P%d scn %s %.3f %.3f %.3f %.3f re f Q', $n, $opac, $px*$this->k, ($this->h-$py)*$this->k, $pw*$this->k, -$ph*$this->k));
  22064. }
  22065. }
  22066. /*-- END BACKGROUND-IMAGES --*/
  22067. if (isset($cell['colspan']) && $cell['colspan']>1) { $ccolsp = $cell['colspan']; }
  22068. else { $ccolsp = 1; }
  22069. if (isset($cell['rowspan']) && $cell['rowspan']>1) { $crowsp = $cell['rowspan']; }
  22070. else { $crowsp = 1; }
  22071. // but still need to do this for repeated headers...
  22072. if (!$table['borders_separate'] && $this->tabletheadjustfinished && !$this->simpleTables){ // mPDF 4.2.017
  22073. if (isset($table['topntail']) && $table['topntail']) {
  22074. $bord_det['T'] = $this->border_details($table['topntail']);
  22075. $bord_det['T']['w'] /= $this->shrin_k;
  22076. $this->setBorder($bord, _BORDER_TOP);
  22077. }
  22078. if (isset($table['thead-underline']) && $table['thead-underline']) {
  22079. $bord_det['T'] = $this->border_details($table['thead-underline']);
  22080. $bord_det['T']['w'] /= $this->shrin_k;
  22081. $this->setBorder($bord, _BORDER_TOP);
  22082. }
  22083. }
  22084. //Get info of first row ==>> table header
  22085. //Use > 1 row if THEAD
  22086. if ($this->usetableheader && ($i == 0 || (isset($table['is_thead'][$i]) && $table['is_thead'][$i])) && $level==1) {
  22087. $tableheader[$i][$j]['x'] = $x;
  22088. $tableheader[$i][$j]['y'] = $y;
  22089. $tableheader[$i][$j]['h'] = $h;
  22090. $tableheader[$i][$j]['w'] = $w;
  22091. $tableheader[$i][$j]['text'] = $cell['text'];
  22092. if (isset($cell['textbuffer'])) { $tableheader[$i][$j]['textbuffer'] = $cell['textbuffer']; }
  22093. else { $tableheader[$i][$j]['textbuffer'] = ''; }
  22094. $tableheader[$i][$j]['a'] = $cell['a'];
  22095. $tableheader[$i][$j]['R'] = $cell['R'];
  22096. $tableheader[$i][$j]['va'] = $cell['va'];
  22097. $tableheader[$i][$j]['mih'] = $cell['mih'];
  22098. // mPDF 3.1
  22099. $tableheader[$i][$j]['gradient'] = $cell['gradient']; // *GRADIENTS*
  22100. $tableheader[$i][$j]['background-image'] = $cell['background-image']; // *BACKGROUND-IMAGES*
  22101. // mPDF 4.0
  22102. $tableheader[$i][$j]['rowspan'] = $cell['rowspan'];
  22103. $tableheader[$i][$j]['colspan'] = $cell['colspan'];
  22104. $tableheader[$i][$j]['bgcolor'] = $fill;
  22105. if (!$this->simpleTables){ // mPDF 4.2.017
  22106. // mPDF 4.3.009
  22107. $tableheader[$i][$j]['border'] = $bord;
  22108. $tableheader[$i][$j]['border_details'] = $bord_det;
  22109. }
  22110. else if ($this->simpleTables){
  22111. $tableheader[$i][$j]['border'] = $table['simple']['border'];
  22112. $tableheader[$i][$j]['border_details'] = $table['simple']['border_details'];
  22113. }
  22114. // mPDF 4.3.006
  22115. $tableheader[$i][$j]['padding'] = $cell['padding'];
  22116. // mPDF 3.0 moved as needed earlier
  22117. //$this->tableheadernrows = max($this->tableheadernrows, ($i+1));
  22118. }
  22119. // CELL BORDER
  22120. if ($bord || $bord_det) {
  22121. if ($table['borders_separate'] && $paintcell) {
  22122. $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']);
  22123. }
  22124. else if (!$table['borders_separate']) {
  22125. $this->_tableRect($x, $y, $w, $h, $bord, $bord_det, true, $table['borders_separate']); // true causes buffer
  22126. }
  22127. }
  22128. //VERTICAL ALIGN
  22129. if ($cell['R'] && INTVAL($cell['R']) > 0 && INTVAL($cell['R']) < 90 && isset($cell['va']) && $cell['va']!='B') { $cell['va']='B';}
  22130. if (!isset($cell['va']) || $cell['va']=='M') $this->y += ($h-$cell['mih'])/2;
  22131. elseif (isset($cell['va']) && $cell['va']=='B') $this->y += $h-$cell['mih'];
  22132. // NESTED CONTENT
  22133. // TEXT (and nested tables)
  22134. $this->divalign=$align;
  22135. $this->divwidth=$w;
  22136. if (!empty($cell['textbuffer'])) {
  22137. $opy = $this->y;
  22138. if ($cell['R']) {
  22139. $cellPtSize = $cell['textbuffer'][0][11] / $this->shrin_k;
  22140. if (!$cellPtSize) { $cellPtSize = $this->default_font_size; }
  22141. $cellFontHeight = ($cellPtSize/$this->k);
  22142. $opx = $this->x;
  22143. $angle = INTVAL($cell['R']);
  22144. // Only allow 45 to 89 degrees (when bottom-aligned) or exactly 90 or -90
  22145. if ($angle > 90) { $angle = 90; }
  22146. else if ($angle > 0 && $angle <45) { $angle = 45; }
  22147. else if ($angle < 0) { $angle = -90; }
  22148. $offset = ((sin(deg2rad($angle))) * 0.37 * $cellFontHeight);
  22149. if (isset($cell['a']) && $cell['a']=='R') {
  22150. $this->x += ($w) + ($offset) - ($cellFontHeight/3) - ($cell['padding']['R'] + ($table['border_spacing_H']/2));
  22151. }
  22152. else if (!isset($cell['a']) || $cell['a']=='C') {
  22153. $this->x += ($w/2) + ($offset);
  22154. }
  22155. else {
  22156. $this->x += ($offset) + ($cellFontHeight/3)+($cell['padding']['L'] +($table['border_spacing_H']/2));
  22157. }
  22158. $str = trim(implode(' ',$cell['text'])); // mPDF 4.4.012
  22159. if (!isset($cell['va']) || $cell['va']=='M') {
  22160. $this->y -= ($h-$cell['mih'])/2; //Undo what was added earlier VERTICAL ALIGN
  22161. if ($angle > 0) { $this->y += (($h-$cell['mih'])/2) + $cell['padding']['T'] + ($cell['mih']-($cell['padding']['T'] + $cell['padding']['B'])); }
  22162. else if ($angle < 0) { $this->y += (($h-$cell['mih'])/2)+ ($cell['padding']['T'] + ($table['border_spacing_V']/2)); }
  22163. }
  22164. elseif (isset($cell['va']) && $cell['va']=='B') {
  22165. $this->y -= $h-$cell['mih']; //Undo what was added earlier VERTICAL ALIGN
  22166. if ($angle > 0) { $this->y += $h-($cell['padding']['B'] + ($table['border_spacing_V']/2)); }
  22167. else if ($angle < 0) { $this->y += $h-$cell['mih'] + ($cell['padding']['T'] + ($table['border_spacing_V']/2)); }
  22168. }
  22169. elseif (isset($cell['va']) && $cell['va']=='T') {
  22170. if ($angle > 0) { $this->y += $cell['mih']-($cell['padding']['B'] + ($table['border_spacing_V']/2)); }
  22171. else if ($angle < 0) { $this->y += ($cell['padding']['T'] + ($table['border_spacing_V']/2)); }
  22172. }
  22173. $this->Rotate($angle,$this->x,$this->y);
  22174. $s_fs = $this->FontSizePt;
  22175. $s_f = $this->FontFamily; // mPDF 3.0
  22176. $s_st = $this->FontStyle; // mPDF 3.0
  22177. $this->SetFont($cell['textbuffer'][0][4],$cell['textbuffer'][0][2],$cellPtSize,true,true);
  22178. $this->Text($this->x,$this->y,$str);
  22179. $this->Rotate(0);
  22180. $this->SetFont($s_f,$s_st,$s_fs,true,true);
  22181. $this->x = $opx;
  22182. }
  22183. else {
  22184. if (!$this->simpleTables){ // mPDF 4.2.017
  22185. if ($table['borders_separate']) { // NB twice border width
  22186. // mPDF 4.3.009
  22187. $xadj = $bord_det['L']['w'] + $cell['padding']['L'] +($table['border_spacing_H']/2);
  22188. $wadj = $bord_det['L']['w'] + $bord_det['R']['w'] + $cell['padding']['L'] +$cell['padding']['R'] + $table['border_spacing_H'];
  22189. $yadj = $bord_det['T']['w'] + $cell['padding']['T'] + ($table['border_spacing_H']/2);
  22190. }
  22191. else {
  22192. $xadj = $bord_det['L']['w']/2 + $cell['padding']['L'];
  22193. $wadj = ($bord_det['L']['w'] + $bord_det['R']['w'])/2 + $cell['padding']['L'] + $cell['padding']['R'];
  22194. $yadj = $bord_det['T']['w']/2 + $cell['padding']['T'];
  22195. }
  22196. }
  22197. else if ($this->simpleTables){
  22198. // mPDF 4.3.006
  22199. if ($table['borders_separate']) { // NB twice border width
  22200. $xadj = $table['simple']['border_details']['L']['w'] + $cell['padding']['L'] +($table['border_spacing_H']/2);
  22201. $wadj = $table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'] + $cell['padding']['L'] +$cell['padding']['R'] + $table['border_spacing_H'];
  22202. $yadj = $table['simple']['border_details']['T']['w'] + $cell['padding']['T'] + ($table['border_spacing_H']/2);
  22203. }
  22204. else {
  22205. $xadj = $table['simple']['border_details']['L']['w']/2 + $cell['padding']['L'];
  22206. $wadj = ($table['simple']['border_details']['L']['w'] + $table['simple']['border_details']['R']['w'])/2 + $cell['padding']['L'] + $cell['padding']['R'];
  22207. $yadj = $table['simple']['border_details']['T']['w']/2 + $cell['padding']['T'];
  22208. }
  22209. }
  22210. $this->divwidth=$w-$wadj;
  22211. if ($this->divwidth == 0) { $this->divwidth = 0.0001; }
  22212. $this->x += $xadj;
  22213. $this->y += $yadj;
  22214. $this->printbuffer($cell['textbuffer'],'',true);
  22215. }
  22216. $this->y = $opy;
  22217. }
  22218. unset($cell );
  22219. //Reset values
  22220. $this->Reset();
  22221. }//end of (if isset(cells)...)
  22222. }// end of columns
  22223. $newpagestarted = false;
  22224. $this->tabletheadjustfinished = false;
  22225. if ($this->ColActive && $i < $numrows-1 && $level==1) { $this->breakpoints[$this->CurrCol][] = $y + $h; } // *COLUMNS*
  22226. /*-- COLUMNS --*/
  22227. // mPDF 3.0 - If columns, print out cell borders (in buffer) at end of each row)
  22228. if ($this->ColActive) {
  22229. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); }
  22230. }
  22231. /*-- END COLUMNS --*/
  22232. if ($i == $numrows-1) { $this->y = $y + $h; } //last row jump (update this->y position)
  22233. if ($this->table_rotate && $level==1) {
  22234. $this->tbrot_h += $h;
  22235. }
  22236. }// end of rows
  22237. if ($this->progressBar) { $this->UpdateProgressBar(7,70,' '); } // *PROGRESS-BAR*
  22238. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); }
  22239. // mPDF 4.2
  22240. if ($this->tableClipPath ) { $this->_out("Q"); }
  22241. $this->tableClipPath = '';
  22242. // Advance down page by half width of bottom border
  22243. if ($table['borders_separate']) { $this->y += $table['padding']['B'] + $table['border_details']['B']['w'] + $table['border_spacing_V']/2; }
  22244. else { $this->y += $table['max_cell_border_width']['B']/2; }
  22245. 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; }
  22246. else if ($level==1) { $this->tbrot_h += $table['margin']['B'] + $table['max_cell_border_width']['B']/2; }
  22247. // TABLE BOTTOM MARGIN
  22248. if ($table['margin']['B']) {
  22249. if (!$this->table_rotate && $level==1) {
  22250. $this->DivLn($table['margin']['B'],$this->blklvl,true); // collapsible
  22251. }
  22252. else {
  22253. $this->y += ($table['margin']['B']);
  22254. }
  22255. }
  22256. if ($this->ColActive && $level==1) { $this->breakpoints[$this->CurrCol][] = $this->y; } // *COLUMNS*
  22257. }//END OF FUNCTION _tableWrite()
  22258. /////////////////////////END OF TABLE CODE//////////////////////////////////
  22259. /*-- END TABLES --*/
  22260. function _putextgstates() {
  22261. for ($i = 1; $i <= count($this->extgstates); $i++) {
  22262. $this->_newobj();
  22263. $this->extgstates[$i]['n'] = $this->n;
  22264. $this->_out('<</Type /ExtGState');
  22265. foreach ($this->extgstates[$i]['parms'] as $k=>$v)
  22266. $this->_out('/'.$k.' '.$v);
  22267. $this->_out('>>');
  22268. $this->_out('endobj');
  22269. }
  22270. }
  22271. /*-- ENCRYPTION --*/
  22272. function SetProtection($permissions=array(),$user_pass='',$owner_pass=null) {
  22273. $this->encrypted=false;
  22274. // mPDF 4.0
  22275. if (is_string($permissions) && strlen($permissions)>0) { $permissions = array($permissions); }
  22276. else if (!is_array($permissions)) { return 0; }
  22277. // if (count($permissions)<1 && !$user_pass && !$owner_pass) { return 0; }
  22278. $this->last_rc4_key='';
  22279. $this->padding="\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08".
  22280. "\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  22281. $options = array('print' => 4, 'modify' => 8, 'copy' => 16, 'annot-forms' => 32 );
  22282. $protection = 192;
  22283. foreach($permissions as $permission){
  22284. if (!isset($options[$permission]))
  22285. $this->Error('Incorrect permission: '.$permission);
  22286. $protection += $options[$permission];
  22287. }
  22288. if ($owner_pass === null)
  22289. $owner_pass = uniqid(rand());
  22290. $this->encrypted = true;
  22291. $this->_generateencryptionkey($user_pass, $owner_pass, $protection);
  22292. }
  22293. // Compute key depending on object number where the encrypted data is stored
  22294. function _objectkey($n) {
  22295. return substr($this->_md5_16($this->encryption_key.pack('VXxx',$n)),0,10);
  22296. }
  22297. /*-- END ENCRYPTION --*/
  22298. /*-- IMPORTS --*/
  22299. // mPDF 4.2.006
  22300. // from mPDFI
  22301. function _putimportedobjects() {
  22302. if (is_array($this->parsers) && count($this->parsers) > 0) {
  22303. foreach($this->parsers AS $filename => $p) {
  22304. $this->current_parser =& $this->parsers[$filename];
  22305. if (is_array($this->_obj_stack[$filename])) {
  22306. while($n = key($this->_obj_stack[$filename])) {
  22307. $nObj = $this->current_parser->pdf_resolve_object($this->current_parser->c,$this->_obj_stack[$filename][$n][1]);
  22308. $this->_newobj($this->_obj_stack[$filename][$n][0]);
  22309. if ($nObj[0] == PDF_TYPE_STREAM) {
  22310. $this->pdf_write_value($nObj);
  22311. }
  22312. else {
  22313. $this->pdf_write_value($nObj[1]);
  22314. }
  22315. $this->_out('endobj');
  22316. $this->_obj_stack[$filename][$n] = null; // free memory
  22317. unset($this->_obj_stack[$filename][$n]);
  22318. reset($this->_obj_stack[$filename]);
  22319. }
  22320. }
  22321. }
  22322. }
  22323. }
  22324. function _putformxobjects() {
  22325. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  22326. reset($this->tpls);
  22327. foreach($this->tpls AS $tplidx => $tpl) {
  22328. $p=($this->compress) ? gzcompress($tpl['buffer']) : $tpl['buffer'];
  22329. $this->_newobj();
  22330. $this->tpls[$tplidx]['n'] = $this->n;
  22331. $this->_out('<<'.$filter.'/Type /XObject');
  22332. $this->_out('/Subtype /Form');
  22333. $this->_out('/FormType 1');
  22334. // Left/Bottom/Right/Top
  22335. $this->_out(sprintf('/BBox [%.2f %.2f %.2f %.2f]',
  22336. $tpl['box']['x']*$this->k,
  22337. $tpl['box']['y']*$this->k,
  22338. ($tpl['box']['x'] + $tpl['box']['w'])*$this->k,
  22339. ($tpl['box']['y'] + $tpl['box']['h'])*$this->k )
  22340. );
  22341. if (isset($tpl['box']))
  22342. $this->_out(sprintf('/Matrix [1 0 0 1 %.5f %.5f]',-$tpl['box']['x']*$this->k, -$tpl['box']['y']*$this->k));
  22343. $this->_out('/Resources ');
  22344. if (isset($tpl['resources'])) {
  22345. $this->current_parser =& $tpl['parser'];
  22346. $this->pdf_write_value($tpl['resources']);
  22347. } else {
  22348. $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  22349. if (isset($this->_res['tpl'][$tplidx]['fonts']) && count($this->_res['tpl'][$tplidx]['fonts'])) {
  22350. $this->_out('/Font <<');
  22351. foreach($this->_res['tpl'][$tplidx]['fonts'] as $font)
  22352. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  22353. $this->_out('>>');
  22354. }
  22355. if(isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images']) ||
  22356. isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls']))
  22357. {
  22358. $this->_out('/XObject <<');
  22359. if (isset($this->_res['tpl'][$tplidx]['images']) && count($this->_res['tpl'][$tplidx]['images'])) {
  22360. foreach($this->_res['tpl'][$tplidx]['images'] as $image)
  22361. $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
  22362. }
  22363. if (isset($this->_res['tpl'][$tplidx]['tpls']) && count($this->_res['tpl'][$tplidx]['tpls'])) {
  22364. foreach($this->_res['tpl'][$tplidx]['tpls'] as $i => $itpl) // mPDF 4.4.001
  22365. $this->_out($this->tplprefix.$i.' '.$itpl['n'].' 0 R');
  22366. }
  22367. $this->_out('>>');
  22368. }
  22369. $this->_out('>>');
  22370. }
  22371. $this->_out('/Length '.strlen($p).' >>');
  22372. $this->_putstream($p);
  22373. $this->_out('endobj');
  22374. }
  22375. }
  22376. /*-- END IMPORTS --*/
  22377. /*-- BACKGROUND-IMAGES --*/
  22378. function _putpatterns() {
  22379. for ($i = 1; $i <= count($this->patterns); $i++) {
  22380. $x = $this->patterns[$i]['x'];
  22381. $y = $this->patterns[$i]['y'];
  22382. $w = $this->patterns[$i]['w'];
  22383. $h = $this->patterns[$i]['h'];
  22384. // mPDF 4.0 Uses saved page height
  22385. $pgh = $this->patterns[$i]['pgh'];
  22386. $orig_w = $this->patterns[$i]['orig_w'];
  22387. $orig_h = $this->patterns[$i]['orig_h'];
  22388. $image_id = $this->patterns[$i]['image_id'];
  22389. if ($this->patterns[$i]['x_repeat']) { $x_repeat = true; }
  22390. else { $x_repeat = false; }
  22391. if ($this->patterns[$i]['y_repeat']) { $y_repeat = true; }
  22392. else { $y_repeat = false; }
  22393. $x_pos = $this->patterns[$i]['x_pos'];
  22394. if (stristr($x_pos ,'%') ) {
  22395. $x_pos += 0;
  22396. $x_pos /= 100;
  22397. $x_pos = ($w * $x_pos) - ($orig_w/$this->k * $x_pos);
  22398. }
  22399. $y_pos = $this->patterns[$i]['y_pos'];
  22400. if (stristr($y_pos ,'%') ) {
  22401. $y_pos += 0;
  22402. $y_pos /= 100;
  22403. $y_pos = ($h * $y_pos) - ($orig_h/$this->k * $y_pos);
  22404. }
  22405. $adj_x = ($x_pos + $x) *$this->k;
  22406. // mPDF 4.0 Uses saved page height
  22407. $adj_y = (($pgh - $y_pos - $y)*$this->k) - $orig_h ;
  22408. $img_obj = false;
  22409. foreach($this->images AS $img) {
  22410. if ($img['i'] == $image_id) { $img_obj = $img['n']; break; }
  22411. }
  22412. if (!$img_obj ) { echo "Problem: Image object not found for background pattern ".$img['i']; exit; }
  22413. $this->_newobj();
  22414. $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  22415. $this->_out('/XObject <</I'.$image_id.' '.$img_obj.' 0 R >>');
  22416. $this->_out('>>');
  22417. $this->_out('endobj');
  22418. $this->_newobj();
  22419. $this->patterns[$i]['n'] = $this->n;
  22420. $this->_out('<< /Type /Pattern /PatternType 1 /PaintType 1 /TilingType 2');
  22421. $this->_out('/Resources '. ($this->n-1) .' 0 R');
  22422. // mPDF 4.3.015 %.2f to %.3F precision, and increase step 99999 to disable
  22423. $this->_out(sprintf('/BBox [0 0 %.3f %.3f]',$orig_w,$orig_h));
  22424. if ($x_repeat) { $this->_out(sprintf('/XStep %.3f',$orig_w)); }
  22425. else { $this->_out(sprintf('/XStep %d',99999)); }
  22426. if ($y_repeat) { $this->_out(sprintf('/YStep %.3f',$orig_h)); }
  22427. else { $this->_out(sprintf('/YStep %d',99999)); }
  22428. $this->_out(sprintf('/Matrix [1 0 0 1 %.3f %.3f]',$adj_x,$adj_y));
  22429. $s = sprintf("q %.3f 0 0 %.3f 0 0 cm /I%d Do Q",$orig_w,$orig_h,$image_id);
  22430. if ($this->compress) {
  22431. $this->_out('/Filter /FlateDecode');
  22432. $s = gzcompress($s);
  22433. }
  22434. $this->_out('/Length '.strlen($s).'>>');
  22435. $this->_putstream($s);
  22436. $this->_out('endobj');
  22437. }
  22438. }
  22439. /*-- END BACKGROUND-IMAGES --*/
  22440. // *BACKGROUND-IMAGES*
  22441. /*-- GRADIENTS --*/
  22442. function _putshaders() {
  22443. foreach ($this->gradients as $id => $grad) {
  22444. if (($grad['type'] == 2) OR ($grad['type'] == 3)) {
  22445. $this->_newobj();
  22446. $this->_out('<<');
  22447. $this->_out('/FunctionType 2');
  22448. $this->_out('/Domain [0.0 1.0]');
  22449. $this->_out('/C0 ['.$grad['col1'].']');
  22450. $this->_out('/C1 ['.$grad['col2'].']');
  22451. $this->_out('/N 1');
  22452. $this->_out('>>');
  22453. $this->_out('endobj');
  22454. $f1 = $this->n;
  22455. }
  22456. $this->_newobj();
  22457. $this->_out('<<');
  22458. $this->_out('/ShadingType '.$grad['type']);
  22459. $this->_out('/ColorSpace /DeviceRGB');
  22460. if ($grad['type'] == 2) {
  22461. $this->_out(sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]));
  22462. $this->_out('/Function '.$f1.' 0 R');
  22463. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  22464. $this->_out('>>');
  22465. }
  22466. else if ($grad['type'] == 3) {
  22467. //x0, y0, r0, x1, y1, r1
  22468. //at this this time radius of inner circle is 0
  22469. // mPDF 4.4.007
  22470. $ir = 0;
  22471. if (isset($grad['coords'][5]) && $grad['coords'][5]) { $ir = $grad['coords'][5]; }
  22472. $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]));
  22473. $this->_out('/Function '.$f1.' 0 R');
  22474. $this->_out('/Extend ['.$grad['extend'][0].' '.$grad['extend'][1].'] ');
  22475. $this->_out('>>');
  22476. }
  22477. $this->_out('endobj');
  22478. $this->gradients[$id]['id'] = $this->n;
  22479. }
  22480. }
  22481. /*-- END GRADIENTS --*/
  22482. function _putresources() {
  22483. $this->_putextgstates();
  22484. if ($this->progressBar) { $this->UpdateProgressBar(2,'+10','Compiling Fonts'); } // *PROGRESS-BAR*
  22485. $this->_putfonts();
  22486. if ($this->progressBar) { $this->UpdateProgressBar(2,'+10','Compiling Images'); } // *PROGRESS-BAR*
  22487. $this->_putimages();
  22488. $this->_putformobjects(); // *IMAGES-CORE*
  22489. /*-- IMPORTS --*/
  22490. // mPDF 4.2.006
  22491. if ($this->enableImports) {
  22492. $this->_putformxobjects();
  22493. $this->_putimportedobjects();
  22494. }
  22495. /*-- END IMPORTS --*/
  22496. $this->_putpatterns(); // *BACKGROUND-IMAGES*
  22497. $this->_putshaders(); // *GRADIENTS*
  22498. //Resource dictionary
  22499. $this->offsets[2]=strlen($this->buffer);
  22500. $this->_out('2 0 obj');
  22501. $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  22502. $this->_out('/Font <<');
  22503. // mPDF 4.0
  22504. foreach($this->fonts as $font) {
  22505. // mPDF 4.5.014
  22506. if (!$font['used'] && ($font['type']=='TrueTypeUnicode' || $font['type']=='Type1subset')) { continue; }
  22507. if ($font['type']=='Type1subset') {
  22508. foreach($font['n'] AS $k => $fid) {
  22509. $this->_out('/F'.$font['subsetfontids'][$k].' '.$font['n'][$k].' 0 R');
  22510. }
  22511. }
  22512. else {
  22513. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  22514. }
  22515. }
  22516. $this->_out('>>');
  22517. if (count($this->extgstates)) {
  22518. $this->_out('/ExtGState <<');
  22519. foreach($this->extgstates as $k=>$extgstate)
  22520. $this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R');
  22521. $this->_out('>>');
  22522. }
  22523. /*-- GRADIENTS --*/
  22524. if (isset($this->gradients) AND (count($this->gradients) > 0)) {
  22525. $this->_out('/Shading <<');
  22526. foreach ($this->gradients as $id => $grad) {
  22527. $this->_out('/Sh'.$id.' '.$grad['id'].' 0 R');
  22528. }
  22529. $this->_out('>>');
  22530. }
  22531. /*-- END GRADIENTS --*/
  22532. if(count($this->images) || count($this->formobjects) || ($this->enableImports && count($this->tpls))) { // mPDF 4.2.006
  22533. $this->_out('/XObject <<');
  22534. foreach($this->images as $image)
  22535. $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
  22536. foreach($this->formobjects as $formobject)
  22537. $this->_out('/FO'.$formobject['i'].' '.$formobject['n'].' 0 R');
  22538. /*-- IMPORTS --*/
  22539. // mPDF 4.2.006
  22540. if ($this->enableImports && count($this->tpls)) {
  22541. foreach($this->tpls as $tplidx => $tpl) {
  22542. $this->_out($this->tplprefix.$tplidx.' '.$tpl['n'].' 0 R');
  22543. }
  22544. }
  22545. /*-- END IMPORTS --*/
  22546. $this->_out('>>');
  22547. }
  22548. /*-- BACKGROUND-IMAGES --*/
  22549. // mPDF 3.0 - Tiling Patterns
  22550. if (count($this->patterns)) {
  22551. $this->_out('/Pattern <<');
  22552. foreach($this->patterns as $k=>$patterns)
  22553. $this->_out('/P'.$k.' '.$patterns['n'].' 0 R');
  22554. $this->_out('>>');
  22555. }
  22556. /*-- END BACKGROUND-IMAGES --*/
  22557. $this->_out('>>');
  22558. $this->_out('endobj'); // end resource dictionary
  22559. $this->_putbookmarks(); // *BOOKMARKS*
  22560. /*-- ENCRYPTION --*/
  22561. if ($this->encrypted) {
  22562. $this->_newobj();
  22563. $this->enc_obj_id = $this->n;
  22564. $this->_out('<<');
  22565. $this->_putencryption();
  22566. $this->_out('>>');
  22567. $this->_out('endobj');
  22568. }
  22569. /*-- END ENCRYPTION --*/
  22570. }
  22571. /*-- ENCRYPTION --*/
  22572. function _putencryption()
  22573. {
  22574. $this->_out('/Filter /Standard');
  22575. $this->_out('/V 1');
  22576. $this->_out('/R 2');
  22577. $this->_out('/O ('.$this->_escape($this->Ovalue).')');
  22578. $this->_out('/U ('.$this->_escape($this->Uvalue).')');
  22579. $this->_out('/P '.$this->Pvalue);
  22580. }
  22581. /*-- END ENCRYPTION --*/
  22582. function _puttrailer()
  22583. {
  22584. $this->_out('/Size '.($this->n+1));
  22585. $this->_out('/Root '.$this->n.' 0 R');
  22586. $this->_out('/Info '.$this->InfoRoot.' 0 R'); // mPDF 4.2.018
  22587. /*-- ENCRYPTION --*/
  22588. if ($this->encrypted) {
  22589. $this->_out('/Encrypt '.$this->enc_obj_id.' 0 R');
  22590. $this->_out('/ID [()()]');
  22591. }
  22592. // mPDF 4.2.010
  22593. else {
  22594. /*-- END ENCRYPTION --*/
  22595. $uniqid = md5(time() . $this->buffer);
  22596. $this->_out('/ID [<'.$uniqid.'> <'.$uniqid.'>]');
  22597. /*-- ENCRYPTION --*/
  22598. }
  22599. /*-- END ENCRYPTION --*/
  22600. }
  22601. /*-- ENCRYPTION --*/
  22602. // RC4 is the standard encryption algorithm used in PDF format
  22603. function _RC4($key, $text)
  22604. {
  22605. if ($this->last_rc4_key != $key) {
  22606. $k = str_repeat($key, 256/strlen($key)+1);
  22607. $rc4 = range(0,255);
  22608. $j = 0;
  22609. for ($i=0; $i<256; $i++){
  22610. $t = $rc4[$i];
  22611. $j = ($j + $t + ord($k[$i])) % 256; // mPDF 4.4.012
  22612. $rc4[$i] = $rc4[$j];
  22613. $rc4[$j] = $t;
  22614. }
  22615. $this->last_rc4_key = $key;
  22616. $this->last_rc4_key_c = $rc4;
  22617. } else {
  22618. $rc4 = $this->last_rc4_key_c;
  22619. }
  22620. $len = strlen($text);
  22621. $a = 0;
  22622. $b = 0;
  22623. $out = '';
  22624. for ($i=0; $i<$len; $i++){
  22625. $a = ($a+1)%256;
  22626. $t= $rc4[$a];
  22627. $b = ($b+$t)%256;
  22628. $rc4[$a] = $rc4[$b];
  22629. $rc4[$b] = $t;
  22630. $k = $rc4[($rc4[$a]+$rc4[$b])%256];
  22631. $out.= $this->chrs[ord($text[$i]) ^ $k]; // mPDF 4.4.012
  22632. }
  22633. return $out;
  22634. }
  22635. // Get MD5 as binary string
  22636. function _md5_16($string)
  22637. {
  22638. return pack('H*',md5($string));
  22639. }
  22640. // Compute O value
  22641. function _Ovalue($user_pass, $owner_pass)
  22642. {
  22643. $tmp = $this->_md5_16($owner_pass);
  22644. $owner_RC4_key = substr($tmp,0,5);
  22645. return $this->_RC4($owner_RC4_key, $user_pass);
  22646. }
  22647. // Compute U value
  22648. function _Uvalue()
  22649. {
  22650. return $this->_RC4($this->encryption_key, $this->padding);
  22651. }
  22652. // Compute encryption key
  22653. function _generateencryptionkey($user_pass, $owner_pass, $protection)
  22654. {
  22655. // Pad passwords
  22656. $user_pass = substr($user_pass.$this->padding,0,32);
  22657. $owner_pass = substr($owner_pass.$this->padding,0,32);
  22658. // Compute O value
  22659. $this->Ovalue = $this->_Ovalue($user_pass,$owner_pass);
  22660. // Compute encyption key
  22661. $tmp = $this->_md5_16($user_pass.$this->Ovalue.$this->chrs[$protection]."\xFF\xFF\xFF");
  22662. $this->encryption_key = substr($tmp,0,5);
  22663. // Compute U value
  22664. $this->Uvalue = $this->_Uvalue();
  22665. // Compute P value
  22666. $this->Pvalue = -(($protection^255)+1);
  22667. }
  22668. /*-- END ENCRYPTION --*/
  22669. //=========================================
  22670. /*-- BOOKMARKS --*/
  22671. // FROM class PDF_Bookmark
  22672. function Bookmark($txt,$level=0,$y=0)
  22673. {
  22674. $txt = $this->purify_utf8_text($txt);
  22675. if ($this->text_input_as_HTML) {
  22676. $txt = $this->all_entities_to_utf8($txt);
  22677. }
  22678. if($y==-1) {
  22679. if (!$this->ColActive){ $y=$this->y; }
  22680. else { $y = $this->y0; } // If columns are on - mark top of columns
  22681. }
  22682. // else y is used as set, or =0 i.e. top of page
  22683. // DIRECTIONALITY RTL
  22684. // mPDF 3.0
  22685. // $this->magic_reverse_dir($txt); // *RTL*
  22686. if ($this->keep_block_together) {
  22687. $this->ktBMoutlines[]=array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->page);
  22688. }
  22689. /*-- TABLES --*/
  22690. else if ($this->table_rotate) {
  22691. $this->tbrot_BMoutlines[]=array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->page);
  22692. }
  22693. else if ($this->kwt) {
  22694. $this->kwt_BMoutlines[]=array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->page);
  22695. }
  22696. /*-- END TABLES --*/
  22697. else if ($this->ColActive) { // *COLUMNS*
  22698. $this->col_BMoutlines[]=array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->page); // *COLUMNS*
  22699. } // *COLUMNS*
  22700. else {
  22701. $this->BMoutlines[]=array('t'=>$txt,'l'=>$level,'y'=>$y,'p'=>$this->page);
  22702. }
  22703. }
  22704. function _putbookmarks()
  22705. {
  22706. $nb=count($this->BMoutlines);
  22707. if($nb==0)
  22708. return;
  22709. $lru=array();
  22710. $level=0;
  22711. foreach($this->BMoutlines as $i=>$o)
  22712. {
  22713. if($o['l']>0)
  22714. {
  22715. $parent=$lru[$o['l']-1];
  22716. //Set parent and last pointers
  22717. $this->BMoutlines[$i]['parent']=$parent;
  22718. $this->BMoutlines[$parent]['last']=$i;
  22719. if($o['l']>$level)
  22720. {
  22721. //Level increasing: set first pointer
  22722. $this->BMoutlines[$parent]['first']=$i;
  22723. }
  22724. }
  22725. else
  22726. $this->BMoutlines[$i]['parent']=$nb;
  22727. if($o['l']<=$level and $i>0)
  22728. {
  22729. //Set prev and next pointers
  22730. $prev=$lru[$o['l']];
  22731. $this->BMoutlines[$prev]['next']=$i;
  22732. $this->BMoutlines[$i]['prev']=$prev;
  22733. }
  22734. $lru[$o['l']]=$i;
  22735. $level=$o['l'];
  22736. }
  22737. //Outline items
  22738. $n=$this->n+1;
  22739. foreach($this->BMoutlines as $i=>$o)
  22740. {
  22741. $this->_newobj();
  22742. $this->_out('<</Title '.$this->_UTF16BEtextstring($o['t']));
  22743. $this->_out('/Parent '.($n+$o['parent']).' 0 R');
  22744. if(isset($o['prev']))
  22745. $this->_out('/Prev '.($n+$o['prev']).' 0 R');
  22746. if(isset($o['next']))
  22747. $this->_out('/Next '.($n+$o['next']).' 0 R');
  22748. if(isset($o['first']))
  22749. $this->_out('/First '.($n+$o['first']).' 0 R');
  22750. if(isset($o['last']))
  22751. $this->_out('/Last '.($n+$o['last']).' 0 R');
  22752. // mPDF 3.0 Page orientation
  22753. if (isset($this->pageDim[$o['p']]['h'])) { $h=$this->pageDim[$o['p']]['h']; }
  22754. else { $h = 0; }
  22755. $this->_out(sprintf('/Dest [%d 0 R /XYZ 0 %.3f null]',1+2*($o['p']),($h-$o['y'])*$this->k));
  22756. $this->_out('/Count 0>>');
  22757. $this->_out('endobj');
  22758. }
  22759. //Outline root
  22760. $this->_newobj();
  22761. $this->OutlineRoot=$this->n;
  22762. $this->_out('<</Type /BMoutlines /First '.$n.' 0 R');
  22763. $this->_out('/Last '.($n+$lru[0]).' 0 R>>');
  22764. $this->_out('endobj');
  22765. }
  22766. /*-- END BOOKMARKS --*/
  22767. // *BOOKMARKS*
  22768. //======================================================
  22769. // DEPRACATED but included for backwards compatability
  22770. function startPageNums() {
  22771. }
  22772. //======================================================
  22773. /*-- TOC --*/
  22774. // ToC TABLE OF CONTENTS
  22775. // Initiate, and Mark a place for the Table of Contents to be inserted
  22776. function TOC($tocfont='', $tocfontsize=8, $tocindent=5, $resetpagenum='', $pagenumstyle='', $suppress='', $toc_orientation='', $TOCusePaging=true, $TOCuseLinking=false, $toc_id=0) {
  22777. if (strtoupper($toc_id)=='ALL') { $toc_id = '_mpdf_all'; }
  22778. else if (!$toc_id) { $toc_id = 0; }
  22779. else { $toc_id = strtolower($toc_id); }
  22780. // To use odd and even pages
  22781. // Cannot start table of contents on an even page
  22782. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  22783. /*-- COLUMNS --*/
  22784. if ($this->ColActive) {
  22785. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  22786. }
  22787. /*-- END COLUMNS --*/
  22788. $this->AddPage($this->CurOrientation,'',$resetpagenum, $pagenumstyle, $suppress);
  22789. }
  22790. else {
  22791. $this->PageNumSubstitutions[] = array('from'=>$this->page, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=>$suppress);
  22792. }
  22793. if (!$tocfont) { $tocfont = $this->default_font; }
  22794. if (!$tocfontsize) { $tocfontsize = $this->default_font_size; }
  22795. if ($toc_id) {
  22796. $this->m_TOC[$toc_id]['TOCmark'] = $this->page;
  22797. $this->m_TOC[$toc_id]['TOCfont'] = $tocfont;
  22798. $this->m_TOC[$toc_id]['TOCfontsize'] = $tocfontsize;
  22799. $this->m_TOC[$toc_id]['TOCindent'] = $tocindent;
  22800. $this->m_TOC[$toc_id]['TOCorientation'] = $toc_orientation;
  22801. $this->m_TOC[$toc_id]['TOCuseLinking'] = $TOCuseLinking;
  22802. $this->m_TOC[$toc_id]['TOCusePaging'] = $TOCusePaging;
  22803. }
  22804. else {
  22805. $this->TOCmark = $this->page;
  22806. $this->TOCfont = $tocfont;
  22807. $this->TOCfontsize = $tocfontsize;
  22808. $this->TOCindent = $tocindent;
  22809. $this->TOCorientation = $toc_orientation;
  22810. $this->TOCuseLinking = $TOCuseLinking;
  22811. $this->TOCusePaging = $TOCusePaging;
  22812. }
  22813. }
  22814. // mPDF 4.2 Added $pagesel
  22815. // mPDF 4.2.024
  22816. 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='') {
  22817. if (strtoupper($toc_id)=='ALL') { $toc_id = '_mpdf_all'; }
  22818. else if (!$toc_id) { $toc_id = 0; }
  22819. else { $toc_id = strtolower($toc_id); }
  22820. // mPDF 3.0
  22821. //Start a new page
  22822. if($this->state==0) $this->AddPage();
  22823. if ($this->y == $this->tMargin && (!$this->mirrorMargins ||($this->mirrorMargins && $this->page % 2==1))) {
  22824. // Don't add a page
  22825. if ($this->page==1 && count($this->PageNumSubstitutions)==0) {
  22826. if (!$suppress) { $suppress = 'off'; }
  22827. if (!$resetpagenum) { $resetpagenum= 1; }
  22828. $this->PageNumSubstitutions[] = array('from'=>1, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=> $suppress);
  22829. }
  22830. }
  22831. else {
  22832. $this->AddPage($orientation,'NEXT-ODD', $resetpagenum, $pagenumstyle, $suppress,$mgl,$mgr,$mgt,$mgb,$mgh,$mgf,$ohname,$ehname,$ofname,$efname,$ohvalue,$ehvalue,$ofvalue,$efvalue,$pagesel,$sheetsize); // mPDF 4.2.024
  22833. }
  22834. if (!$tocfont) { $tocfont = $this->default_font; }
  22835. if (!$tocfontsize) { $tocfontsize = $this->default_font_size; }
  22836. if (!$tocindent && $tocindent !== 0) { $tocindent = 5; }
  22837. // mPDF 3.0
  22838. if ($TOCusePaging === false || strtolower($TOCusePaging) == "off" || $TOCusePaging === 0 || $TOCusePaging === "0" || $TOCusePaging === "") { $TOCusePaging = false; }
  22839. else { $TOCusePaging = true; }
  22840. if (!$TOCuseLinking) { $TOCuseLinking = false; }
  22841. if ($toc_id) {
  22842. $this->m_TOC[$toc_id]['TOCmark'] = $this->page;
  22843. $this->m_TOC[$toc_id]['TOCfont'] = $tocfont;
  22844. $this->m_TOC[$toc_id]['TOCfontsize'] = $tocfontsize;
  22845. $this->m_TOC[$toc_id]['TOCindent'] = $tocindent;
  22846. $this->m_TOC[$toc_id]['TOCorientation'] = $toc_orientation;
  22847. $this->m_TOC[$toc_id]['TOCuseLinking'] = $TOCuseLinking;
  22848. $this->m_TOC[$toc_id]['TOCusePaging'] = $TOCusePaging;
  22849. if ($toc_preHTML) { $this->m_TOC[$toc_id]['TOCpreHTML'] = $toc_preHTML; }
  22850. if ($toc_postHTML) { $this->m_TOC[$toc_id]['TOCpostHTML'] = $toc_postHTML; }
  22851. if ($toc_bookmarkText) { $this->m_TOC[$toc_id]['TOCbookmarkText'] = $toc_bookmarkText; } // *BOOKMARKS*
  22852. $this->m_TOC[$toc_id]['TOC_margin_left'] = $toc_mgl;
  22853. $this->m_TOC[$toc_id]['TOC_margin_right'] = $toc_mgr;
  22854. $this->m_TOC[$toc_id]['TOC_margin_top'] = $toc_mgt;
  22855. $this->m_TOC[$toc_id]['TOC_margin_bottom'] = $toc_mgb;
  22856. $this->m_TOC[$toc_id]['TOC_margin_header'] = $toc_mgh;
  22857. $this->m_TOC[$toc_id]['TOC_margin_footer'] = $toc_mgf;
  22858. $this->m_TOC[$toc_id]['TOC_odd_header_name'] = $toc_ohname;
  22859. $this->m_TOC[$toc_id]['TOC_even_header_name'] = $toc_ehname;
  22860. $this->m_TOC[$toc_id]['TOC_odd_footer_name'] = $toc_ofname;
  22861. $this->m_TOC[$toc_id]['TOC_even_footer_name'] = $toc_efname;
  22862. $this->m_TOC[$toc_id]['TOC_odd_header_value'] = $toc_ohvalue;
  22863. $this->m_TOC[$toc_id]['TOC_even_header_value'] = $toc_ehvalue;
  22864. $this->m_TOC[$toc_id]['TOC_odd_footer_value'] = $toc_ofvalue;
  22865. $this->m_TOC[$toc_id]['TOC_even_footer_value'] = $toc_efvalue;
  22866. // mPDF 4.2.024
  22867. $this->m_TOC[$toc_id]['TOC_page_selector'] = $toc_pagesel;
  22868. $this->m_TOC[$toc_id]['TOCsheetsize'] = $toc_sheetsize;
  22869. }
  22870. else {
  22871. $this->TOCmark = $this->page;
  22872. $this->TOCfont = $tocfont;
  22873. $this->TOCfontsize = $tocfontsize;
  22874. $this->TOCindent = $tocindent;
  22875. $this->TOCorientation = $toc_orientation;
  22876. $this->TOCuseLinking = $TOCuseLinking;
  22877. $this->TOCusePaging = $TOCusePaging;
  22878. if ($toc_preHTML) { $this->TOCpreHTML = $toc_preHTML; }
  22879. if ($toc_postHTML) { $this->TOCpostHTML = $toc_postHTML; }
  22880. if ($toc_bookmarkText) { $this->TOCbookmarkText = $toc_bookmarkText; } // *BOOKMARKS*
  22881. $this->TOC_margin_left = $toc_mgl;
  22882. $this->TOC_margin_right = $toc_mgr;
  22883. $this->TOC_margin_top = $toc_mgt;
  22884. $this->TOC_margin_bottom = $toc_mgb;
  22885. $this->TOC_margin_header = $toc_mgh;
  22886. $this->TOC_margin_footer = $toc_mgf;
  22887. $this->TOC_odd_header_name = $toc_ohname;
  22888. $this->TOC_even_header_name = $toc_ehname;
  22889. $this->TOC_odd_footer_name = $toc_ofname;
  22890. $this->TOC_even_footer_name = $toc_efname;
  22891. $this->TOC_odd_header_value = $toc_ohvalue;
  22892. $this->TOC_even_header_value = $toc_ehvalue;
  22893. $this->TOC_odd_footer_value = $toc_ofvalue;
  22894. $this->TOC_even_footer_value = $toc_efvalue;
  22895. // mPDF 4.2.024
  22896. $this->TOC_page_selector = $toc_pagesel;
  22897. $this->TOCsheetsize = $toc_sheetsize;
  22898. }
  22899. }
  22900. function TOC_Entry($txt, $level=0, $toc_id=0) {
  22901. $txt = $this->purify_utf8_text($txt);
  22902. if ($this->text_input_as_HTML) {
  22903. $txt = $this->all_entities_to_utf8($txt);
  22904. }
  22905. // Modified by Ivan Tcholakov, 28-JAN-2010.
  22906. //if (!$this->is_MB) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  22907. if (!$this->is_MB) { $txt = api_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  22908. //
  22909. if ($this->ColActive) { $ily = $this->y0; } else { $ily = $this->y; } // use top of columns
  22910. $linkn = $this->AddLink();
  22911. $this->SetLink($linkn,$ily,$this->page);
  22912. /*-- RTL --*/
  22913. if (($this->directionality == 'rtl') || (($this->directionality == 'ltr') && ($this->biDirectional))) {
  22914. // mPDF 4.0 Remove rtlAsArabicFarsi
  22915. $txt = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $txt );
  22916. }
  22917. /*-- END RTL --*/
  22918. if (strtoupper($toc_id)=='ALL') { $toc_id = '_mpdf_all'; }
  22919. else if (!$toc_id) { $toc_id = 0; }
  22920. else { $toc_id = strtolower($toc_id); }
  22921. if ($this->keep_block_together) {
  22922. $this->_kttoc[]=array('t'=>$txt,'l'=>$level,'p'=>$this->page, 'link'=>$linkn, 'toc_id'=>$toc_id);
  22923. }
  22924. /*-- TABLES --*/
  22925. else if ($this->table_rotate) {
  22926. $this->tbrot_toc[]=array('t'=>$txt,'l'=>$level,'p'=>$this->page, 'link'=>$linkn, 'toc_id'=>$toc_id);
  22927. }
  22928. else if ($this->kwt) {
  22929. $this->kwt_toc[]=array('t'=>$txt,'l'=>$level,'p'=>$this->page, 'link'=>$linkn, 'toc_id'=>$toc_id);
  22930. }
  22931. /*-- END TABLES --*/
  22932. else if ($this->ColActive) { // *COLUMNS*
  22933. $this->col_toc[]=array('t'=>$txt,'l'=>$level,'p'=>$this->page, 'link'=>$linkn, 'toc_id'=>$toc_id); // *COLUMNS*
  22934. } // *COLUMNS*
  22935. else {
  22936. $this->_toc[]=array('t'=>$txt,'l'=>$level,'p'=>$this->page, 'link'=>$linkn, 'toc_id'=>$toc_id);
  22937. }
  22938. }
  22939. function insertTOC() {
  22940. $notocs = 0;
  22941. if ($this->TOCmark) { $notocs = 1; }
  22942. $notocs += count($this->m_TOC);
  22943. if ($notocs==0) { return; }
  22944. if (count($this->m_TOC)) { reset($this->m_TOC); }
  22945. $added_toc_pages = 0;
  22946. if ($this->ColActive) { $this->SetColumns(0); } // *COLUMNS*
  22947. if (($this->mirrorMargins) && (($this->page)%2==1)) { // ODD
  22948. $this->AddPage($this->CurOrientation);
  22949. $extrapage = true;
  22950. }
  22951. else { $extrapage = false; }
  22952. for ($toci = 0; $toci<$notocs; $toci++) {
  22953. if ($toci==0 && $this->TOCmark) {
  22954. $toc_id = 0;
  22955. $toc_page = $this->TOCmark;
  22956. $tocfont = $this->TOCfont;
  22957. $tocfontsize = $this->TOCfontsize;
  22958. $tocindent = $this->TOCindent;
  22959. $toc_orientation = $this->TOCorientation;
  22960. $TOCuseLinking = $this->TOCuseLinking;
  22961. $TOCusePaging = $this->TOCusePaging;
  22962. $toc_preHTML = $this->TOCpreHTML;
  22963. $toc_postHTML = $this->TOCpostHTML;
  22964. $toc_bookmarkText = $this->TOCbookmarkText; // *BOOKMARKS*
  22965. $toc_mgl = $this->TOC_margin_left;
  22966. $toc_mgr = $this->TOC_margin_right;
  22967. $toc_mgt = $this->TOC_margin_top;
  22968. $toc_mgb = $this->TOC_margin_bottom;
  22969. $toc_mgh = $this->TOC_margin_header;
  22970. $toc_mgf = $this->TOC_margin_footer;
  22971. $toc_ohname = $this->TOC_odd_header_name;
  22972. $toc_ehname = $this->TOC_even_header_name;
  22973. $toc_ofname = $this->TOC_odd_footer_name;
  22974. $toc_efname = $this->TOC_even_footer_name;
  22975. $toc_ohvalue = $this->TOC_odd_header_value;
  22976. $toc_ehvalue = $this->TOC_even_header_value;
  22977. $toc_ofvalue = $this->TOC_odd_footer_value;
  22978. $toc_efvalue = $this->TOC_even_footer_value;
  22979. // mPDF 4.2
  22980. $toc_page_selector = $this->TOC_page_selector;
  22981. $toc_sheet_size = $this->TOCsheetsize; // mPDF 4.2.024
  22982. }
  22983. else {
  22984. $arr = current($this->m_TOC);
  22985. $toc_id = key($this->m_TOC);
  22986. $toc_page = $this->m_TOC[$toc_id]['TOCmark'];
  22987. $tocfont = $this->m_TOC[$toc_id]['TOCfont'];
  22988. $tocfontsize = $this->m_TOC[$toc_id]['TOCfontsize'];
  22989. $tocindent = $this->m_TOC[$toc_id]['TOCindent'];
  22990. $toc_orientation = $this->m_TOC[$toc_id]['TOCorientation'];
  22991. $TOCuseLinking = $this->m_TOC[$toc_id]['TOCuseLinking'];
  22992. $TOCusePaging = $this->m_TOC[$toc_id]['TOCusePaging'];
  22993. if (isset($this->m_TOC[$toc_id]['TOCpreHTML'])) { $toc_preHTML = $this->m_TOC[$toc_id]['TOCpreHTML']; }
  22994. else { $toc_preHTML = ''; }
  22995. if (isset($this->m_TOC[$toc_id]['TOCpostHTML'])) { $toc_postHTML = $this->m_TOC[$toc_id]['TOCpostHTML']; }
  22996. else { $toc_postHTML = ''; }
  22997. if (isset($this->m_TOC[$toc_id]['TOCbookmarkText'])) { $toc_bookmarkText = $this->m_TOC[$toc_id]['TOCbookmarkText']; } // *BOOKMARKS*
  22998. else { $toc_bookmarkText = ''; } // *BOOKMARKS*
  22999. $toc_mgl = $this->m_TOC[$toc_id]['TOC_margin_left'];
  23000. $toc_mgr = $this->m_TOC[$toc_id]['TOC_margin_right'];
  23001. $toc_mgt = $this->m_TOC[$toc_id]['TOC_margin_top'];
  23002. $toc_mgb = $this->m_TOC[$toc_id]['TOC_margin_bottom'];
  23003. $toc_mgh = $this->m_TOC[$toc_id]['TOC_margin_header'];
  23004. $toc_mgf = $this->m_TOC[$toc_id]['TOC_margin_footer'];
  23005. $toc_ohname = $this->m_TOC[$toc_id]['TOC_odd_header_name'];
  23006. $toc_ehname = $this->m_TOC[$toc_id]['TOC_even_header_name'];
  23007. $toc_ofname = $this->m_TOC[$toc_id]['TOC_odd_footer_name'];
  23008. $toc_efname = $this->m_TOC[$toc_id]['TOC_even_footer_name'];
  23009. $toc_ohvalue = $this->m_TOC[$toc_id]['TOC_odd_header_value'];
  23010. $toc_ehvalue = $this->m_TOC[$toc_id]['TOC_even_header_value'];
  23011. $toc_ofvalue = $this->m_TOC[$toc_id]['TOC_odd_footer_value'];
  23012. $toc_efvalue = $this->m_TOC[$toc_id]['TOC_even_footer_value'];
  23013. // mPDF 4.2
  23014. $toc_page_selector = $this->m_TOC[$toc_id]['TOC_page_selector'];
  23015. $toc_sheet_size = $this->m_TOC[$toc_id]['TOCsheetsize']; // mPDF 4.2.024
  23016. next($this->m_TOC);
  23017. }
  23018. if ($this->TOCheader) { $this->SetHeader($this->TOCheader); }
  23019. else if ($this->TOCheader !== false) { $this->SetHeader(); }
  23020. // mPDF 3.0
  23021. if (!$tocindent && $tocindent !== 0) { $tocindent = 5; }
  23022. if (!$toc_orientation) { $toc_orientation= $this->DefOrientation; }
  23023. // mPDF 3.0
  23024. // mPDF 4.2
  23025. $this->AddPage($toc_orientation, '', '', '', "on", $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_page_selector, $toc_sheet_size ); // mPDF 4.2.024
  23026. if ($this->TOCfooter) { $this->SetFooter($this->TOCfooter); }
  23027. else if ($this->TOCfooter !== false) { $this->SetFooter(); }
  23028. $tocstart=count($this->pages);
  23029. if ($toc_preHTML) { $this->WriteHTML($toc_preHTML); }
  23030. foreach($this->_toc as $t) {
  23031. if ($t['toc_id']==='_mpdf_all' || $t['toc_id']===$toc_id ) {
  23032. // mPDF 3.0
  23033. $tpgno = $this->docPageNum($t['p']);
  23034. $lineheightcorr = 2-$t['l'];
  23035. //Offset
  23036. $level=$t['l'];
  23037. if ($TOCuseLinking) { $tlink = $t['link']; }
  23038. else { $tlink = ''; }
  23039. /*-- RTL --*/
  23040. if ($this->directionality == 'rtl') {
  23041. $weight='';
  23042. if($level==0)
  23043. $weight='B';
  23044. $str=$t['t'];
  23045. // mPDF 4.0
  23046. $fullstr = $str;
  23047. $this->SetFont($tocfont,$weight,$tocfontsize,true,true);
  23048. $PageCellSize=$this->GetStringWidth($tpgno )+2;
  23049. $strsize=$this->GetStringWidth($str);
  23050. // mPDF 3.0 Cut to only one line
  23051. $cw = count(explode(' ',$str));
  23052. while (($strsize + $this->GetStringWidth(str_repeat('.',5))+4 + $PageCellSize) > $this->pgwidth && $cw>1) {
  23053. $str = implode(' ',explode(' ',$str,-1));
  23054. $strsize=$this->GetStringWidth($str);
  23055. $cw = count(explode(' ',$str));
  23056. }
  23057. $sl = strlen($str);
  23058. // mPDF 4.0
  23059. $rem = substr($fullstr, ($sl+1));
  23060. // mPDF 3.0
  23061. $this->magic_reverse_dir($str); // *RTL*
  23062. if ($TOCusePaging) {
  23063. //Page number
  23064. $this->SetFont($tocfont,'',$tocfontsize);
  23065. $this->Cell($PageCellSize,$this->FontSize+$lineheightcorr,$tpgno ,0,0,'L',0,$tlink);
  23066. //Filling dots
  23067. $w=$this->w-$this->lMargin-$this->rMargin-$PageCellSize-($level*$tocindent)-($strsize+2);
  23068. $nb=intval($w/$this->GetStringWidth('.'));
  23069. if ($nb>0) {
  23070. $dots=str_repeat('.',$nb);
  23071. $this->Cell($w+2,$this->FontSize+$lineheightcorr,$dots,0,0,'L');
  23072. }
  23073. // Text
  23074. $this->SetFont($tocfont,$weight,$tocfontsize);
  23075. $this->Cell($strsize-($level*$tocindent),$this->FontSize+$lineheightcorr,$str,0,1,'R',0,$tlink);
  23076. }
  23077. else {
  23078. // Text
  23079. $this->SetFont($tocfont,$weight,$tocfontsize);
  23080. $this->Cell($this->pgwidth -($level*$tocindent),$this->FontSize+$lineheightcorr,$str,0,1,'R',0,$tlink);
  23081. }
  23082. if ($rem) {
  23083. $this->x += 10;
  23084. // mPDF 4.0 Added true last parameter
  23085. $this->MultiCell($this->pgwidth -($level*$tocindent)-15,$this->FontSize+$lineheightcorr,$rem,0,R,0,$tlink,'rtl',true);
  23086. }
  23087. }
  23088. // LTR
  23089. else {
  23090. /*-- END RTL --*/
  23091. // Text
  23092. $weight='';
  23093. if($level==0)
  23094. $weight='B';
  23095. $str=$t['t'];
  23096. // mPDF 4.0
  23097. $fullstr = $str;
  23098. $this->SetFont($tocfont,$weight,$tocfontsize,true,true);
  23099. if($level>0 && $tocindent) { $this->Cell($level*$tocindent,$this->FontSize+$lineheightcorr); }
  23100. // mPDF 4.0 Font-specific ligature substitution for Indic fonts
  23101. $this->ConvertIndic($str); // *INDIC*
  23102. $PageCellSize=$this->GetStringWidth($tpgno )+2;
  23103. $strsize=$this->GetStringWidth($str);
  23104. // mPDF 3.0 Cut to only one line
  23105. $cw = count(explode(' ',$str));
  23106. while (($strsize + $this->GetStringWidth(str_repeat('.',5))+4+ $PageCellSize + ($level*$tocindent)) > $this->pgwidth && $cw>1) {
  23107. $str = implode(' ',explode(' ',$str,-1));
  23108. $strsize=$this->GetStringWidth($str);
  23109. $cw = count(explode(' ',$str));
  23110. }
  23111. $sl = strlen($str);
  23112. // mPDF 4.0
  23113. $rem = substr($fullstr, ($sl+1));
  23114. if ($TOCusePaging) {
  23115. // Text
  23116. $this->Cell($strsize+2,$this->FontSize+$lineheightcorr,$str,0,0,'',0,$tlink);
  23117. //Filling dots
  23118. $this->SetFont($tocfont,'',$tocfontsize);
  23119. $w=$this->w-$this->lMargin-$this->rMargin-$PageCellSize-($level*$tocindent)-($strsize+2);
  23120. $nb=intval($w/$this->GetStringWidth('.'));
  23121. if ($nb>0) { $dots=str_repeat('.',$nb); }
  23122. else { $this->y += $this->lineheight; $dots=str_repeat('.',5); } // ..... 5 dots?
  23123. $this->Cell($w,$this->FontSize+$lineheightcorr,$dots,0,0,'R');
  23124. //Page number
  23125. $this->Cell($PageCellSize,$this->FontSize+$lineheightcorr,$tpgno ,0,1,'R',0,$tlink);
  23126. }
  23127. else {
  23128. // Text only
  23129. $this->Cell($strsize+2,$this->FontSize+$lineheightcorr,$str,0,1,'',0,$tlink); // forces new line
  23130. }
  23131. // mPDF 3.0
  23132. if ($rem) {
  23133. $this->x += 5 + $PageCellSize + ($level*$tocindent);
  23134. // mPDF 4.0 Added true last parameter
  23135. $this->MultiCell($strsize+2,$this->FontSize+$lineheightcorr,$rem,0,L,0,$tlink,'ltr',true);
  23136. }
  23137. } // *RTL*
  23138. }
  23139. }
  23140. if ($toc_postHTML) { $this->WriteHTML($toc_postHTML); }
  23141. $this->AddPage($toc_orientation,'E');
  23142. $n_toc = $this->page - $tocstart + 1;
  23143. if ($toci==0 && $this->TOCmark) {
  23144. $this->TOC_start = $tocstart ;
  23145. $this->TOC_end = $this->page;
  23146. $this->TOC_npages = $n_toc;
  23147. }
  23148. else {
  23149. $this->m_TOC[$toc_id]['start'] = $tocstart ;
  23150. $this->m_TOC[$toc_id]['end'] = $this->page;
  23151. $this->m_TOC[$toc_id]['npages'] = $n_toc;
  23152. }
  23153. }
  23154. // mPDF 4.2.023
  23155. $s = '';
  23156. $bby = $this->h;
  23157. $bbw = $this->w;
  23158. $bbh = $this->h;
  23159. if ($this->bodyBackgroundColor) {
  23160. $s .= sprintf('%.3f %.3f %.3f rg',$this->bodyBackgroundColor['R']/255,$this->bodyBackgroundColor['G']/255,$this->bodyBackgroundColor['B']/255)."\n";
  23161. $s .= sprintf('%.3f %.3f %.3f %.3f re f',0,$bby*$this->k,$bbw*$this->k,-$bbh*$this->k)."\n";
  23162. }
  23163. /*-- GRADIENTS --*/
  23164. if ($this->bodyBackgroundGradient) {
  23165. $g = $this->parseBackgroundGradient($this->bodyBackgroundGradient);
  23166. if ($g) {
  23167. $s .= $this->Gradient(0, 0, $this->w, $this->h, $g['gradtype'], $g['col'], $g['col2'], $g['coords'], $g['extend'], true);
  23168. }
  23169. }
  23170. /*-- END GRADIENTS --*/
  23171. /*-- BACKGROUND-IMAGES --*/
  23172. if ($this->bodyBackgroundImage) {
  23173. if ($this->bodyBackgroundImage['image_id']) { // Background pattern
  23174. $n = count($this->patterns)+1;
  23175. // mPDF 4.3.015
  23176. list($orig_w, $orig_h, $x_repeat, $y_repeat) = $this->_resizeBackgroundImage($this->bodyBackgroundImage['orig_w'], $this->bodyBackgroundImage['orig_h'], $bbw, $bbh, $this->bodyBackgroundImage['resize'],$this->bodyBackgroundImage['x_repeat'],$this->bodyBackgroundImage['y_repeat']);
  23177. // mPDF 3.1 $bbx = 0, 'y'=>0
  23178. $this->patterns[$n] = array('x'=>0, 'y'=>0, 'w'=>$bbw, 'h'=>$bbh, '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); // mPDF 4.3.015
  23179. // mPDF 4.3.017
  23180. if ($this->bodyBackgroundImage['opacity']>0 && $this->bodyBackgroundImage['opacity']<1) { $opac = $this->SetAlpha($this->bodyBackgroundImage['opacity'],'Normal',true); }
  23181. else { $opac = ''; }
  23182. $s .= sprintf('q /Pattern cs /P%d scn %s %.3f %.3f %.3f %.3f re f Q', $n, $opac, 0,$bby*$this->k,$bbw*$this->k,-$bbh*$this->k) ."\n";
  23183. }
  23184. }
  23185. /*-- END BACKGROUND-IMAGES --*/
  23186. $s .= $this->PrintPageBackgrounds();
  23187. $this->pages[$this->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->pages[$this->page]);
  23188. $this->pageBackgrounds = array();
  23189. //Page footer
  23190. $this->InFooter=true;
  23191. $this->Footer();
  23192. $this->InFooter=false;
  23193. // 2nd time through to move pages etc.
  23194. $added_toc_pages = 0;
  23195. if (count($this->m_TOC)) { reset($this->m_TOC); }
  23196. for ($toci = 0; $toci<$notocs; $toci++) {
  23197. if ($toci==0 && $this->TOCmark) {
  23198. $toc_id = 0;
  23199. $toc_page = $this->TOCmark + $added_toc_pages;
  23200. $toc_orientation = $this->TOCorientation;
  23201. $TOCuseLinking = $this->TOCuseLinking;
  23202. $TOCusePaging = $this->TOCusePaging;
  23203. $toc_bookmarkText = $this->TOCbookmarkText; // *BOOKMARKS*
  23204. $tocstart = $this->TOC_start ;
  23205. $tocend = $n = $this->TOC_end;
  23206. $n_toc = $this->TOC_npages;
  23207. }
  23208. else {
  23209. $arr = current($this->m_TOC);
  23210. $toc_id = key($this->m_TOC);
  23211. $toc_page = $this->m_TOC[$toc_id]['TOCmark'] + $added_toc_pages;
  23212. $toc_orientation = $this->m_TOC[$toc_id]['TOCorientation'];
  23213. $TOCuseLinking = $this->m_TOC[$toc_id]['TOCuseLinking'];
  23214. $TOCusePaging = $this->m_TOC[$toc_id]['TOCusePaging'];
  23215. $toc_bookmarkText = $this->m_TOC[$toc_id]['TOCbookmarkText']; // *BOOKMARKS*
  23216. $tocstart = $this->m_TOC[$toc_id]['start'] ;
  23217. $tocend = $n = $this->m_TOC[$toc_id]['end'] ;
  23218. $n_toc = $this->m_TOC[$toc_id]['npages'] ;
  23219. next($this->m_TOC);
  23220. }
  23221. // Now pages moved
  23222. $added_toc_pages += $n_toc;
  23223. $this->MovePages($toc_page, $tocstart, $tocend) ;
  23224. // mPDF 4.2.020
  23225. $this->pgsIns[$toc_page] = $tocend - $tocstart + 1;
  23226. /*-- BOOKMARKS --*/
  23227. // Insert new Bookmark for Bookmark
  23228. if ($toc_bookmarkText) {
  23229. $insert = -1;
  23230. foreach($this->BMoutlines as $i=>$o) {
  23231. if($o['p']<$toc_page) { // i.e. before point of insertion
  23232. $insert = $i;
  23233. }
  23234. }
  23235. $txt = $this->purify_utf8_text($toc_bookmarkText);
  23236. if ($this->text_input_as_HTML) {
  23237. $txt = $this->all_entities_to_utf8($txt);
  23238. }
  23239. $newBookmark[0] = array('t'=>$txt,'l'=>0,'y'=>0,'p'=>$toc_page );
  23240. array_splice($this->BMoutlines,($insert+1),0,$newBookmark);
  23241. }
  23242. /*-- END BOOKMARKS --*/
  23243. }
  23244. // Delete empty page that was inserted earlier
  23245. if ($extrapage) {
  23246. unset($this->pages[count($this->pages)]);
  23247. $this->page--; // Reset page pointer
  23248. }
  23249. }
  23250. //======================================================
  23251. function MovePages($target_page, $start_page, $end_page=-1) {
  23252. // move a page/pages EARLIER in the document
  23253. if ($end_page<1) { $end_page = $start_page; }
  23254. $n_toc = $end_page - $start_page + 1;
  23255. // Set/Update PageNumSubstitutions changes before moving anything
  23256. if (count($this->PageNumSubstitutions)) {
  23257. $tp_present = false;
  23258. $sp_present = false;
  23259. $ep_present = false;
  23260. foreach($this->PageNumSubstitutions AS $k=>$v) {
  23261. if ($this->PageNumSubstitutions[$k]['from']==$target_page) {
  23262. $tp_present = true;
  23263. if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) {
  23264. $this->PageNumSubstitutions[$k]['suppress']='off';
  23265. }
  23266. }
  23267. if ($this->PageNumSubstitutions[$k]['from']==$start_page) {
  23268. $sp_present = true;
  23269. if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) {
  23270. $this->PageNumSubstitutions[$k]['suppress']='off';
  23271. }
  23272. }
  23273. if ($this->PageNumSubstitutions[$k]['from']==($end_page+1)) {
  23274. $ep_present = true;
  23275. if ($this->PageNumSubstitutions[$k]['suppress']!='on' && $this->PageNumSubstitutions[$k]['suppress']!=1) {
  23276. $this->PageNumSubstitutions[$k]['suppress']='off';
  23277. }
  23278. }
  23279. }
  23280. if (!$tp_present) {
  23281. list($tp_type, $tp_suppress, $tp_reset) = $this->docPageSettings($target_page);
  23282. }
  23283. if (!$sp_present) {
  23284. list($sp_type, $sp_suppress, $sp_reset) = $this->docPageSettings($start_page);
  23285. }
  23286. if (!$ep_present) {
  23287. list($ep_type, $ep_suppress, $ep_reset) = $this->docPageSettings($start_page-1);
  23288. }
  23289. }
  23290. $last = array();
  23291. //store pages
  23292. for($i = $start_page;$i <= $end_page ;$i++)
  23293. $last[]=$this->pages[$i];
  23294. //move pages
  23295. for($i=$start_page - 1;$i>=($target_page);$i--) { // mPDF 3.0
  23296. $this->pages[$i+$n_toc]=$this->pages[$i];
  23297. }
  23298. //Put toc pages at insert point
  23299. for($i = 0;$i < $n_toc;$i++) {
  23300. $this->pages[$target_page + $i]=$last[$i];
  23301. }
  23302. /*-- BOOKMARKS --*/
  23303. // Update Bookmarks
  23304. foreach($this->BMoutlines as $i=>$o) {
  23305. if($o['p']>=$target_page) {
  23306. $this->BMoutlines[$i]['p'] += $n_toc;
  23307. }
  23308. }
  23309. /*-- END BOOKMARKS --*/
  23310. // Update Page Links
  23311. if (count($this->PageLinks)) {
  23312. $newarr = array();
  23313. foreach($this->PageLinks as $i=>$o) {
  23314. // mPDF 3.0 - Change links to page numbers (@) used by Index
  23315. foreach($this->PageLinks[$i] as $key => $pl) {
  23316. if (strpos($pl[4],'@')===0) {
  23317. $p=substr($pl[4],1);
  23318. if($p>=$start_page && $p<=$end_page) {
  23319. $this->PageLinks[$i][$key][4] = '@'.($p + ($target_page - $start_page));
  23320. }
  23321. else if($p>=$target_page && $p<$start_page) {
  23322. $this->PageLinks[$i][$key][4] = '@'.($p+$n_toc);
  23323. }
  23324. }
  23325. }
  23326. if($i>=$start_page && $i<=$end_page) {
  23327. $newarr[($i + ($target_page - $start_page))] = $this->PageLinks[$i];
  23328. }
  23329. else if($i>=$target_page && $i<$start_page) {
  23330. $newarr[($i + $n_toc)] = $this->PageLinks[$i];
  23331. }
  23332. else {
  23333. $newarr[$i] = $this->PageLinks[$i];
  23334. }
  23335. }
  23336. $this->PageLinks = $newarr;
  23337. }
  23338. // OrientationChanges
  23339. if (count($this->OrientationChanges)) {
  23340. $newarr = array();
  23341. foreach($this->OrientationChanges AS $p=>$v) {
  23342. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->OrientationChanges[$p]; }
  23343. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->OrientationChanges[$p]; }
  23344. else { $newarr[$p] = $this->OrientationChanges[$p]; }
  23345. }
  23346. ksort($newarr);
  23347. $this->OrientationChanges = $newarr;
  23348. }
  23349. // Page Dimensions
  23350. if (count($this->pageDim)) {
  23351. $newarr = array();
  23352. foreach($this->pageDim AS $p=>$v) {
  23353. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->pageDim[$p]; }
  23354. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->pageDim[$p]; }
  23355. else { $newarr[$p] = $this->pageDim[$p]; }
  23356. }
  23357. ksort($newarr);
  23358. $this->pageDim = $newarr;
  23359. }
  23360. // mPDF 4.0
  23361. // HTML Headers & Footers
  23362. if (count($this->saveHTMLHeader)) {
  23363. $newarr = array();
  23364. foreach($this->saveHTMLHeader AS $p=>$v) {
  23365. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->saveHTMLHeader[$p]; }
  23366. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->saveHTMLHeader[$p]; }
  23367. else { $newarr[$p] = $this->saveHTMLHeader[$p]; }
  23368. }
  23369. ksort($newarr);
  23370. $this->saveHTMLHeader = $newarr;
  23371. }
  23372. if (count($this->saveHTMLFooter)) {
  23373. $newarr = array();
  23374. foreach($this->saveHTMLFooter AS $p=>$v) {
  23375. if($p>=$start_page && $p<=$end_page) { $newarr[($p + ($target_page - $start_page))] = $this->saveHTMLFooter[$p]; }
  23376. else if($p>=$target_page && $p<$start_page) { $newarr[$p+$n_toc] = $this->saveHTMLFooter[$p]; }
  23377. else { $newarr[$p] = $this->saveHTMLFooter[$p]; }
  23378. }
  23379. ksort($newarr);
  23380. $this->saveHTMLFooter = $newarr;
  23381. }
  23382. // Update Internal Links
  23383. if (count($this->internallink)) {
  23384. foreach($this->internallink as $key=>$o) {
  23385. if($o['PAGE']>=$start_page && $o['PAGE']<=$end_page) {
  23386. $this->internallink[$key]['PAGE'] += ($target_page - $start_page);
  23387. }
  23388. else if($o['PAGE']>=$target_page && $o['PAGE']<$start_page) {
  23389. $this->internallink[$key]['PAGE'] += $n_toc;
  23390. }
  23391. }
  23392. }
  23393. // Update Links
  23394. if (count($this->links)) {
  23395. foreach($this->links as $key=>$o) {
  23396. if($o[0]>=$start_page && $o[0]<=$end_page) {
  23397. $this->links[$key][0] += ($target_page - $start_page);
  23398. }
  23399. if($o[0]>=$target_page && $o[0]<$start_page) {
  23400. $this->links[$key][0] += $n_toc;
  23401. }
  23402. }
  23403. }
  23404. /*-- ANNOTATIONS --*/
  23405. // Update Annotations
  23406. if (count($this->PageAnnots)) {
  23407. $newarr = array();
  23408. foreach($this->PageAnnots as $p=>$anno) {
  23409. if($p>=$start_page && $p<=$end_page) {
  23410. $np = $p + ($target_page - $start_page);
  23411. foreach($anno as $o) {
  23412. $newarr[$np][] = $o;
  23413. }
  23414. }
  23415. else if($p>=$target_page && $p<$start_page) {
  23416. $np = $p + $n_toc;
  23417. foreach($anno as $o) {
  23418. $newarr[$np][] = $o;
  23419. }
  23420. }
  23421. else {
  23422. $newarr[$p] = $this->PageAnnots[$p];
  23423. }
  23424. }
  23425. $this->PageAnnots = $newarr;
  23426. unset($newarr);
  23427. }
  23428. /*-- END ANNOTATIONS --*/
  23429. // Update PageNumSubstitutions
  23430. if (count($this->PageNumSubstitutions)) {
  23431. $newarr = array();
  23432. foreach($this->PageNumSubstitutions AS $k=>$v) {
  23433. if($this->PageNumSubstitutions[$k]['from']>=$start_page && $this->PageNumSubstitutions[$k]['from']<=$end_page) {
  23434. $this->PageNumSubstitutions[$k]['from'] += ($target_page - $start_page);
  23435. $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k];
  23436. }
  23437. else if($this->PageNumSubstitutions[$k]['from']>=$target_page && $this->PageNumSubstitutions[$k]['from']<$start_page) {
  23438. $this->PageNumSubstitutions[$k]['from'] += $n_toc;
  23439. $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k];
  23440. }
  23441. else {
  23442. $newarr[$this->PageNumSubstitutions[$k]['from']] = $this->PageNumSubstitutions[$k];
  23443. }
  23444. }
  23445. if (!$sp_present) {
  23446. $newarr[$target_page] = array('from'=>$target_page, 'suppress'=>$sp_suppress, 'reset'=>$sp_reset, 'type'=>$sp_type);
  23447. }
  23448. if (!$tp_present) {
  23449. $newarr[($target_page + $n_toc)] = array('from'=>($target_page+$n_toc), 'suppress'=>$tp_suppress, 'reset'=>$tp_reset, 'type'=>$tp_type);
  23450. }
  23451. if (!$ep_present && $end_page>count($this->pages)) {
  23452. $newarr[($end_page+1)] = array('from'=>($end_page+1), 'suppress'=>$ep_suppress, 'reset'=>$ep_reset, 'type'=>$ep_type);
  23453. }
  23454. ksort($newarr);
  23455. $this->PageNumSubstitutions = array();
  23456. foreach($newarr as $v) {
  23457. $this->PageNumSubstitutions[] = $v;
  23458. }
  23459. }
  23460. }
  23461. /*-- END TOC --*/
  23462. //======================================================
  23463. /*-- INDEX --*/
  23464. // FROM class PDF_Ref == INDEX
  23465. function Reference($txt) {
  23466. $this->IndexEntry($txt);
  23467. }
  23468. // mPDF 3.0
  23469. function IndexEntry($txt, $xref='') {
  23470. if ($xref) {
  23471. $this->IndexEntrySee($txt,$xref);
  23472. return;
  23473. }
  23474. $txt = strip_tags($txt);
  23475. $txt = $this->purify_utf8_text($txt);
  23476. if ($this->text_input_as_HTML) {
  23477. $txt = $this->all_entities_to_utf8($txt);
  23478. }
  23479. // Modified by Ivan Tcholakov, 28-JAN-2010.
  23480. //if (!$this->is_MB) { $txt = mb_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  23481. if (!$this->is_MB) { $txt = api_convert_encoding($txt,$this->mb_enc,'UTF-8'); }
  23482. //
  23483. $Present=0;
  23484. $size=sizeof($this->Reference);
  23485. if ($this->directionality == 'rtl') { // *RTL*
  23486. $txt = str_replace(':',' - ',$txt); // *RTL*
  23487. } // *RTL*
  23488. else { // *RTL*
  23489. $txt = str_replace(':',', ',$txt);
  23490. } // *RTL*
  23491. //Search the reference (AND Ref/PageNo) in the array
  23492. for ($i=0;$i<$size;$i++){
  23493. if ($this->keep_block_together) {
  23494. if (isset($this->ktReference[$i]['t']) && $this->ktReference[$i]['t']==$txt){
  23495. $Present=1;
  23496. if (!in_array($this->page,$this->ktReference[$i]['p'])) {
  23497. $this->ktReference[$i]['op'] = $this->page;
  23498. }
  23499. }
  23500. }
  23501. /*-- TABLES --*/
  23502. else if ($this->table_rotate) {
  23503. if (isset($this->tbrot_Reference[$i]['t']) && $this->tbrot_Reference[$i]['t']==$txt){
  23504. $Present=1;
  23505. if (!in_array($this->page,$this->tbrot_Reference[$i]['p'])) {
  23506. $this->tbrot_Reference[$i]['op'] = $this->page;
  23507. }
  23508. }
  23509. }
  23510. // mPDF 3.0
  23511. else if ($this->kwt) {
  23512. if (isset($this->kwt_Reference[$i]['t']) && $this->kwt_Reference[$i]['t']==$txt){
  23513. $Present=1;
  23514. if (!in_array($this->page,$this->kwt_Reference[$i]['p'])) {
  23515. $this->kwt_Reference[$i]['op'] = $this->page;
  23516. }
  23517. }
  23518. }
  23519. /*-- END TABLES --*/
  23520. /*-- COLUMNS --*/
  23521. // mPDF 3.0
  23522. else if ($this->ColActive) {
  23523. if (isset($this->col_Reference[$i]['t']) && $this->col_Reference[$i]['t']==$txt){
  23524. $Present=1;
  23525. if (!in_array($this->page,$this->col_Reference[$i]['p'])) {
  23526. $this->col_Reference[$i]['op'] = $this->page;
  23527. }
  23528. }
  23529. }
  23530. /*-- END COLUMNS --*/
  23531. else {
  23532. if (isset($this->Reference[$i]['t']) && $this->Reference[$i]['t']==$txt){
  23533. $Present=1;
  23534. if (!in_array($this->page,$this->Reference[$i]['p'])) {
  23535. $this->Reference[$i]['p'][] = $this->page;
  23536. }
  23537. }
  23538. }
  23539. }
  23540. //If not found, add it
  23541. if ($Present==0) {
  23542. if ($this->keep_block_together) {
  23543. $this->ktReference[]=array('t'=>$txt, 'op'=>$this->page);
  23544. }
  23545. /*-- TABLES --*/
  23546. else if ($this->table_rotate) {
  23547. $this->tbrot_Reference[]=array('t'=>$txt, 'op'=>$this->page);
  23548. }
  23549. else if ($this->kwt) {
  23550. $this->kwt_Reference[]=array('t'=>$txt, 'op'=>$this->page);
  23551. }
  23552. /*-- END TABLES --*/
  23553. /*-- COLUMNS --*/
  23554. else if ($this->ColActive) {
  23555. $this->col_Reference[]=array('t'=>$txt, 'op'=>$this->page);
  23556. }
  23557. /*-- END COLUMNS --*/
  23558. else {
  23559. $this->Reference[]=array('t'=>$txt,'p'=>array($this->page));
  23560. }
  23561. }
  23562. }
  23563. // Added function to add a reference "Elephants. See Chickens"
  23564. function ReferenceSee($txta,$txtb) {
  23565. $this->IndexEntrySee($txta,$txtb);
  23566. }
  23567. function IndexEntrySee($txta,$txtb) {
  23568. $txta = strip_tags($txta);
  23569. $txtb = strip_tags($txtb);
  23570. $txta = $this->purify_utf8_text($txta);
  23571. $txtb = $this->purify_utf8_text($txtb);
  23572. if ($this->text_input_as_HTML) {
  23573. $txta = $this->all_entities_to_utf8($txta);
  23574. $txtb = $this->all_entities_to_utf8($txtb);
  23575. }
  23576. if (!$this->is_MB) {
  23577. // Modified by Ivan Tcholakov, 28-JAN-2010.
  23578. //$txta = mb_convert_encoding($txta,$this->mb_enc,'UTF-8');
  23579. //$txtb = mb_convert_encoding($txtb,$this->mb_enc,'UTF-8');
  23580. $txta = api_convert_encoding($txta,$this->mb_enc,'UTF-8');
  23581. $txtb = api_convert_encoding($txtb,$this->mb_enc,'UTF-8');
  23582. //
  23583. }
  23584. if ($this->directionality == 'rtl') { // *RTL*
  23585. $txta = str_replace(':',' - ',$txta); // *RTL*
  23586. $txtb = str_replace(':',' - ',$txtb); // *RTL*
  23587. } // *RTL*
  23588. else { // *RTL*
  23589. $txta = str_replace(':',', ',$txta);
  23590. $txtb = str_replace(':',', ',$txtb);
  23591. } // *RTL*
  23592. $this->Reference[]=array('t'=>$txta.' - see '.$txtb,'p'=>array()); // mPDF 3.0
  23593. }
  23594. function CreateReference($NbCol=1, $reffontsize='', $linespacing='', $offset=3, $usedivletters=1, $divlettfontsize='', $gap=5, $reffont='',$divlettfont='', $useLinking=false) {
  23595. $this->CreateIndex($NbCol, $reffontsize, $linespacing, $offset, $usedivletters, $divlettfontsize, $gap, $reffont, $divlettfont, $useLinking);
  23596. }
  23597. function CreateIndex($NbCol=1, $reffontsize='', $linespacing='', $offset=3, $usedivletters=1, $divlettfontsize='', $gap=5, $reffont='',$divlettfont='', $useLinking=false) {
  23598. if (!$reffontsize) { $reffontsize = $this->default_font_size; }
  23599. if (!$divlettfontsize) { $divlettfontsize = ($this->default_font_size * 1.8); }
  23600. if (!$reffont) { $reffont = $this->default_font; }
  23601. if (!$divlettfont) { $divlettfont = $reffont; }
  23602. if (!$linespacing) { $linespacing= $this->default_lineheight_correction; } // mPDF 3.0
  23603. if ($this->ColActive) { $this->SetColumns(0); } // *COLUMNS*
  23604. $size=sizeof($this->Reference);
  23605. if ($size == 0) { return false; }
  23606. if ($NbCol<2) {
  23607. $NbCol = 1;
  23608. $colWidth = $this->pgwidth;
  23609. }
  23610. else {
  23611. $this->SetColumns($NbCol,'',$gap);
  23612. $colWidth = $this->ColWidth;
  23613. }
  23614. if ($this->directionality == 'rtl') { $align = 'R'; }
  23615. else { $align = 'L'; }
  23616. $lett = '';
  23617. function cmp ($a, $b) {
  23618. return strnatcmp(strtolower($a['t']), strtolower($b['t']));
  23619. }
  23620. //Alphabetic sort of the references
  23621. usort($this->Reference, 'cmp');
  23622. $size=sizeof($this->Reference);
  23623. $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS*
  23624. // mPDF 3.0 - Prevent break after Dividing letter
  23625. $divlettjuststarted = false;
  23626. // mPDF 3.0
  23627. $this->OpenTag('DIV',array('STYLE'=>'line-height: '.$linespacing.'; font-family: '.$reffont.'; font-size: '.$reffontsize.'pt; '));
  23628. // mPDF 3.0
  23629. $last_lett = '';
  23630. for ($i=0;$i<$size;$i++){
  23631. if ($this->Reference[$i]['t']) {
  23632. if ($usedivletters) {
  23633. // mPDF 4.0
  23634. // Modified by Ivan Tcholakov, 28-JAN-2010.
  23635. //$lett = mb_strtoupper(mb_substr($this->Reference[$i]['t'],0,1,$this->mb_enc ),$this->mb_enc );
  23636. $lett = api_strtoupper(api_substr($this->Reference[$i]['t'],0,1,$this->mb_enc ),$this->mb_enc );
  23637. //
  23638. if ($lett != $last_lett) {
  23639. // mPDF 3.0 - Prevent break after Dividing letter
  23640. $save_bp = $this->breakpoints[$this->CurrCol]; // *COLUMNS*
  23641. $divlettjuststarted = true;
  23642. if ($i>0) {
  23643. $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; '));
  23644. }
  23645. else {
  23646. $this->OpenTag('DIV',array('STYLE'=>'line-height: '.$linespacing.'; font-family: '.$divlettfont.'; font-size: '.$divlettfontsize.'pt; font-weight: bold; page-break-after: avoid; '));
  23647. }
  23648. $this->textbuffer[] = array($lett,'',$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  23649. $this->CloseTag('DIV');
  23650. }
  23651. }
  23652. $this->OpenTag('DIV',array('STYLE'=>'text-indent: -'.$offset.'mm; line-height: '.$linespacing.'; font-family: '.$reffont.'; font-size: '.$reffontsize.'pt; '));
  23653. /*-- RTL --*/
  23654. // mPDF 3.0 // Change Arabic + Persian. to Presentation Forms
  23655. if (($this->directionality == 'rtl') || (($this->directionality == 'ltr') && ($this->biDirectional))) {
  23656. // mPDF 4.0 Remove rtlAsArabicFarsi
  23657. $this->Reference[$i]['t'] = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $this->Reference[$i]['t'] );
  23658. }
  23659. /*-- END RTL --*/
  23660. // mPDF 4.0 Font-specific ligature substitution for Indic fonts
  23661. $this->ConvertIndic($this->Reference[$i]['t']); // *INDIC*
  23662. $this->textbuffer[] = array($this->Reference[$i]['t'], '',$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  23663. $ppp = $this->Reference[$i]['p']; // = array of page numbers to point to
  23664. if (count($ppp)) {
  23665. sort($ppp);
  23666. $newarr = array();
  23667. $range_start = $ppp[0];
  23668. $range_end = 0;
  23669. if ($this->is_MB) { $spacer = "\xc2\xa0 "; }
  23670. else { $spacer = chr(160).' '; }
  23671. $this->textbuffer[] = array($spacer, '',$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  23672. if ($this->directionality == 'rtl') { $sep = '.'; $joiner = '-'; }
  23673. else { $sep = ', '; $joiner = '-'; }
  23674. for ($zi=1;$zi<count($ppp);$zi++) {
  23675. // RTL - Each number separately
  23676. if (($this->directionality == 'rtl') || (($this->directionality == 'ltr') && ($this->biDirectional))) {
  23677. /*-- RTL --*/
  23678. if ($zi<count($ppp)-1) {
  23679. $txt = $sep . $this->docPageNum($ppp[$zi]);
  23680. if ($useLinking) { $href = '@'.$ppp[$zi]; }
  23681. else { $href = ''; }
  23682. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  23683. }
  23684. /*-- END RTL --*/
  23685. }
  23686. else if ($ppp[$zi] == ($ppp[($zi-1)]+1)) {
  23687. $range_end = $ppp[$zi];
  23688. }
  23689. else {
  23690. if ($range_end) {
  23691. if ($range_end == $range_start+1) {
  23692. if ($useLinking) { $href = '@'.$range_start; }
  23693. else { $href = ''; }
  23694. $txt = $this->docPageNum($range_start) . $sep;
  23695. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  23696. if ($useLinking) { $href = '@'.$ppp[$zi-1]; }
  23697. else { $href = ''; }
  23698. $txt = $this->docPageNum($ppp[$zi-1]) . $sep;
  23699. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  23700. }
  23701. else {
  23702. if ($useLinking) { $href = '@'.$range_start; }
  23703. else { $href = ''; }
  23704. }
  23705. }
  23706. else {
  23707. if ($useLinking) { $href = '@'.$ppp[$zi-1]; }
  23708. else { $href = ''; }
  23709. $txt = $this->docPageNum($ppp[$zi-1]) . $sep;
  23710. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  23711. }
  23712. $range_start = $ppp[$zi];
  23713. $range_end = 0;
  23714. }
  23715. }
  23716. if ($range_end) {
  23717. if ($range_end == $range_start+1) {
  23718. if ($useLinking) { $href = '@'.$range_start; }
  23719. else { $href = ''; }
  23720. $txt = $this->docPageNum($range_start) . $sep;
  23721. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  23722. if ($useLinking) { $href = '@'.$range_end; }
  23723. else { $href = ''; }
  23724. $txt = $this->docPageNum($range_end);
  23725. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  23726. }
  23727. else {
  23728. if ($useLinking) { $href = '@'.$range_start; }
  23729. else { $href = ''; }
  23730. $txt = $this->docPageNum($range_start) . $joiner;
  23731. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  23732. if ($useLinking) { $href = '@'.$range_end; }
  23733. else { $href = ''; }
  23734. $txt = $this->docPageNum($range_end);
  23735. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  23736. }
  23737. }
  23738. else {
  23739. if ($useLinking) { $href = '@'.$ppp[(count($ppp)-1)]; }
  23740. else { $href = ''; }
  23741. $txt = $this->docPageNum($ppp[(count($ppp)-1)]);
  23742. $this->textbuffer[] = array($txt, $href,$this->currentfontstyle,$this->colorarray,$this->currentfontfamily,$this->SUP,$this->SUB,'',$this->strike,$this->outlineparam,$this->spanbgcolorarray,$this->currentfontsize,$this->ReqFontStyle);
  23743. }
  23744. }
  23745. }
  23746. $this->CloseTag('DIV');
  23747. if ($divlettjuststarted) { $this->breakpoints[$this->CurrCol] = $save_bp; } // *COLUMNS*
  23748. $divlettjuststarted = false;
  23749. $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS*
  23750. $last_lett = $lett;
  23751. }
  23752. $this->CloseTag('DIV');
  23753. $this->breakpoints[$this->CurrCol][] = $this->y; // *COLUMNS*
  23754. if ($this->ColActive) { $this->SetColumns(0); } // *COLUMNS*
  23755. }
  23756. /*-- END INDEX --*/
  23757. function AcceptPageBreak() {
  23758. if (count($this->cellBorderBuffer)) { $this->printcellbuffer(); } // *TABLES*
  23759. /*-- COLUMNS --*/
  23760. if ($this->ColActive==1) {
  23761. if($this->CurrCol<$this->NbCol-1) {
  23762. //Go to the next column
  23763. $this->CurrCol++;
  23764. $this->SetCol($this->CurrCol);
  23765. $this->y=$this->y0;
  23766. $this->ChangeColumn=1; // Number (and direction) of columns changed +1, +2, -2 etc.
  23767. // DIRECTIONALITY RTL
  23768. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  23769. //Stay on the page
  23770. return false;
  23771. }
  23772. else {
  23773. //Go back to the first column - NEW PAGE
  23774. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  23775. $this->SetCol(0);
  23776. $this->ChangePage=1;
  23777. $this->y0 = $this->tMargin;
  23778. $this->ChangeColumn= -($this->NbCol-1);
  23779. // DIRECTIONALITY RTL
  23780. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  23781. //Page break
  23782. return true;
  23783. }
  23784. }
  23785. /*-- END COLUMNS --*/
  23786. /*-- TABLES --*/
  23787. else if ($this->table_rotate) {
  23788. if (count($this->tablebuffer)) { $this->printtablebuffer(); }
  23789. return true;
  23790. }
  23791. /*-- END TABLES --*/
  23792. else { // *COLUMNS*
  23793. $this->ChangeColumn=0;
  23794. return $this->autoPageBreak; // mPDF 3.0
  23795. } // *COLUMNS*
  23796. return $this->autoPageBreak; // mPDF 3.0
  23797. }
  23798. //----------- COLUMNS ---------------------
  23799. /*-- COLUMNS --*/
  23800. function SetColumns($NbCol,$vAlign='',$gap=5) {
  23801. // NbCol = number of columns
  23802. // CurrCol = Number of the current column starting at 0
  23803. // Called externally to set columns on/off and number
  23804. // Integer 2 upwards sets columns on to that number
  23805. // Anything less than 2 turns columns off
  23806. if ($NbCol<2) { // SET COLUMNS OFF
  23807. if ($this->ColActive) {
  23808. $this->ColActive=0;
  23809. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  23810. $this->NbCol=1;
  23811. $this->ResetMargins();
  23812. $this->pgwidth = $this->w - $this->lMargin - $this->rMargin;
  23813. $this->divwidth = 0;
  23814. $this->Ln();
  23815. }
  23816. $this->ColActive=0;
  23817. $this->columnbuffer = array();
  23818. $this->ColDetails = array();
  23819. $this->columnLinks = array();
  23820. $this->columnAnnots = array();
  23821. // mPDF 3.0
  23822. $this->col_Reference = array();
  23823. $this->col_BMoutlines = array();
  23824. $this->col_toc = array();
  23825. $this->breakpoints = array();
  23826. }
  23827. else { // SET COLUMNS ON
  23828. if ($this->ColActive) {
  23829. $this->ColActive=0;
  23830. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  23831. $this->ResetMargins();
  23832. }
  23833. // mPDF 4.0
  23834. if (isset($this->y) && $this->y>$this->tMargin) $this->Ln();
  23835. $this->NbCol=$NbCol;
  23836. $this->ColGap = $gap;
  23837. $this->divwidth = 0;
  23838. $this->ColActive=1;
  23839. $this->ColumnAdjust = true; // enables column height adjustment for the page
  23840. $this->columnbuffer = array();
  23841. $this->ColDetails = array();
  23842. $this->columnLinks = array();
  23843. $this->columnAnnots = array();
  23844. // mPDF 3.0
  23845. $this->col_Reference = array();
  23846. $this->col_BMoutlines = array();
  23847. $this->col_toc = array();
  23848. $this->breakpoints = array();
  23849. if ((strtoupper($vAlign) == 'J') || (strtoupper($vAlign) == 'JUSTIFY')) { $vAlign = 'J'; }
  23850. else { $vAlign = ''; }
  23851. $this->colvAlign = $vAlign;
  23852. //Save the ordinate
  23853. $absL = $this->DeflMargin-($gap/2);
  23854. $absR = $this->DefrMargin-($gap/2);
  23855. $PageWidth = $this->w-$absL-$absR; // virtual pagewidth for calculation only
  23856. $ColWidth = (($PageWidth - ($gap * ($NbCol)))/$NbCol);
  23857. $this->ColWidth = $ColWidth;
  23858. /*-- RTL --*/
  23859. if ($this->directionality == 'rtl') {
  23860. for ($i=0;$i<$this->NbCol;$i++) {
  23861. $this->ColL[$i] = $absL + ($gap/2) + (($NbCol - ($i+1))*($PageWidth/$NbCol)) ;
  23862. $this->ColR[$i] = $this->ColL[$i] + $ColWidth; // NB This is not R margin -> R pos
  23863. }
  23864. }
  23865. else {
  23866. /*-- END RTL --*/
  23867. for ($i=0;$i<$this->NbCol;$i++) {
  23868. $this->ColL[$i] = $absL + ($gap/2) + ($i* ($PageWidth/$NbCol) );
  23869. $this->ColR[$i] = $this->ColL[$i] + $ColWidth; // NB This is not R margin -> R pos
  23870. }
  23871. } // *RTL*
  23872. $this->pgwidth = $ColWidth;
  23873. $this->SetCol(0);
  23874. $this->y0=$this->GetY();
  23875. }
  23876. $this->x = $this->lMargin;
  23877. }
  23878. function SetCol($CurrCol) {
  23879. // Used internally to set column by number 0 is 1st column
  23880. //Set position on a column
  23881. $this->CurrCol=$CurrCol;
  23882. $x = $this->ColL[$CurrCol];
  23883. $xR = $this->ColR[$CurrCol]; // NB This is not R margin -> R pos
  23884. if (($this->mirrorMargins) && (($this->page)%2==0)) { // EVEN
  23885. $x += $this->MarginCorrection ;
  23886. $xR += $this->MarginCorrection ;
  23887. }
  23888. $this->SetMargins($x,($this->w - $xR),$this->tMargin);
  23889. }
  23890. function AddColumn() {
  23891. $this->NewColumn();
  23892. $this->ColumnAdjust = false; // disables all column height adjustment for the page.
  23893. }
  23894. function NewColumn() {
  23895. if ($this->ColActive==1) {
  23896. if($this->CurrCol<$this->NbCol-1) {
  23897. //Go to the next column
  23898. $this->CurrCol++;
  23899. $this->SetCol($this->CurrCol);
  23900. $this->y = $this->y0;
  23901. $this->ChangeColumn=1;
  23902. // DIRECTIONALITY RTL
  23903. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  23904. //Stay on the page
  23905. }
  23906. else {
  23907. //Go back to the first column
  23908. //Page break
  23909. if (count($this->columnbuffer)) { $this->printcolumnbuffer(); }
  23910. $this->AddPage($this->CurOrientation);
  23911. $this->SetCol(0);
  23912. $this->ChangePage=1;
  23913. $this->y0 = $this->tMargin;
  23914. $this->ChangeColumn= -($this->NbCol-1);
  23915. // DIRECTIONALITY RTL
  23916. if ($this->directionality == 'rtl') { $this->ChangeColumn = -($this->ChangeColumn); } // *RTL*
  23917. }
  23918. $this->x = $this->lMargin;
  23919. }
  23920. else {
  23921. $this->AddPage($this->CurOrientation);
  23922. }
  23923. }
  23924. // mPDF 3.0 - Rewritten
  23925. function printcolumnbuffer() {
  23926. $k = $this->k;
  23927. // Columns ended (but page not ended) -> try to match all columns - unless disabled by using a custom column-break
  23928. if (!$this->ColActive && $this->ColumnAdjust && !$this->keepColumns) {
  23929. // Calculate adjustment to add to each column to calculate rel_y value
  23930. $this->ColDetails[0]['add_y'] = 0;
  23931. $last_col = 0;
  23932. // Recursively add previous column's height
  23933. for($i=1;$i<$this->NbCol;$i++) {
  23934. if (isset($this->ColDetails[$i]['bottom_margin']) && $this->ColDetails[$i]['bottom_margin']) { // If any entries in the column
  23935. $this->ColDetails[$i]['add_y'] = ($this->ColDetails[$i-1]['bottom_margin'] - $this->y0) + $this->ColDetails[$i-1]['add_y'];
  23936. $last_col = $i; // Last column actually printed
  23937. }
  23938. }
  23939. // Calculate value for each position sensitive entry as though for one column
  23940. foreach($this->columnbuffer AS $key=>$s) {
  23941. $t = $s['s'];
  23942. if (preg_match('/BT \d+\.\d\d+ (\d+\.\d\d+) Td/',$t)) {
  23943. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  23944. }
  23945. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ [\-]{0,1}\d+\.\d\d+ re/',$t)) {
  23946. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  23947. }
  23948. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) {
  23949. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  23950. }
  23951. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) {
  23952. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  23953. }
  23954. 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)) { // mPDF 4.5.007
  23955. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  23956. }
  23957. else if (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) {
  23958. $this->columnbuffer[$key]['rel_y'] = $s['y'] + $this->ColDetails[$s['col']]['add_y'] - $this->y0;
  23959. }
  23960. }
  23961. $breaks = array();
  23962. foreach($this->breakpoints AS $c => $bpa) {
  23963. foreach($bpa AS $rely) {
  23964. $breaks[] = $rely + $this->ColDetails[$c]['add_y'] - $this->y0;
  23965. }
  23966. }
  23967. if (isset($this->ColDetails[$last_col]['bottom_margin'])) { $lcbm = $this->ColDetails[$last_col]['bottom_margin']; }
  23968. else { $lcbm = 0; }
  23969. $sum_h = $this->ColDetails[$last_col]['add_y'] + $lcbm - $this->y0;
  23970. //$sum_h = max($this->ColDetails[$last_col]['add_y'] + $this->ColDetails[$last_col]['bottom_margin'] - $this->y0, end($breaks));
  23971. $target_h = ($sum_h / $this->NbCol);
  23972. $cbr = array();
  23973. for($i=1;$i<$this->NbCol;$i++) {
  23974. $th = ($sum_h * $i / $this->NbCol);
  23975. foreach($breaks AS $bk=>$val) {
  23976. if ($val > $th) {
  23977. if (($val-$th) < ($th-$breaks[$bk-1])) { $cbr[$i-1] = $val; }
  23978. else { $cbr[$i-1] = $breaks[$bk-1]; }
  23979. break;
  23980. }
  23981. }
  23982. }
  23983. $cbr[($this->NbCol-1)] = $sum_h;
  23984. // Now update the columns - divide into columns of approximately equal value
  23985. $last_new_col = 0;
  23986. $yadj = 0; // mm
  23987. $xadj = 0;
  23988. $last_col_bottom = 0;
  23989. $lowest_bottom_y = 0;
  23990. $block_bottom = 0;
  23991. $newcolumn = 0;
  23992. foreach($this->columnbuffer AS $key=>$s) {
  23993. if (isset($s['rel_y'])) { // only process position sensitive data
  23994. if ($s['rel_y'] >= $cbr[$newcolumn]) {
  23995. $newcolumn++;
  23996. }
  23997. else {
  23998. $newcolumn = $last_new_col ;
  23999. }
  24000. $block_bottom = max($block_bottom,($s['rel_y']+$s['h']));
  24001. if ($this->directionality == 'rtl') { // *RTL*
  24002. $xadj = -(($newcolumn - $s['col']) * ($this->ColWidth + $this->ColGap)); // *RTL*
  24003. } // *RTL*
  24004. else { // *RTL*
  24005. $xadj = ($newcolumn - $s['col']) * ($this->ColWidth + $this->ColGap);
  24006. } // *RTL*
  24007. if ($last_new_col != $newcolumn) { // Added new column
  24008. $last_col_bottom = $this->columnbuffer[$key]['rel_y'];
  24009. $block_bottom = 0;
  24010. }
  24011. $yadj = ($s['rel_y'] - $s['y']) - ($last_col_bottom)+$this->y0;
  24012. // callback function in htmltoolkit
  24013. $t = $s['s'];
  24014. $t = preg_replace('/BT (\d+\.\d\d+) (\d+\.\d\d+) Td/e',"\$this->columnAdjustAdd('Td',$k,$xadj,$yadj,'\\1','\\2')",$t);
  24015. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) ([\-]{0,1}\d+\.\d\d+) re/e',"\$this->columnAdjustAdd('re',$k,$xadj,$yadj,'\\1','\\2','\\3','\\4')",$t);
  24016. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) l/e',"\$this->columnAdjustAdd('l',$k,$xadj,$yadj,'\\1','\\2')",$t);
  24017. $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',$k,$xadj,$yadj,'\\1','\\2','\\3','\\4','\\5')",$t); // mPDF 4.5.007
  24018. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) m/e',"\$this->columnAdjustAdd('draw',$k,$xadj,$yadj,'\\1','\\2')",$t);
  24019. $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',$k,$xadj,$yadj,'\\1','\\2','\\3','\\4','\\5','\\6')",$t);
  24020. $this->columnbuffer[$key]['s'] = $t;
  24021. $this->columnbuffer[$key]['newcol'] = $newcolumn;
  24022. $this->columnbuffer[$key]['newy'] = $s['y'] + $yadj;
  24023. $last_new_col = $newcolumn;
  24024. $clb = $s['y'] + $yadj + $s['h'] ; // bottom_margin of current
  24025. 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; }
  24026. if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; }
  24027. // Adjust LINKS
  24028. if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  24029. $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  24030. $this->PageLinks[$this->page][$ref][0] += ($xadj*$k);
  24031. $this->PageLinks[$this->page][$ref][1] -= ($yadj*$k);
  24032. }
  24033. /*-- ANNOTATIONS --*/
  24034. if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  24035. $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  24036. if ($this->PageAnnots[$this->page][$ref]['x'] < 0) {
  24037. $this->PageAnnots[$this->page][$ref]['x'] -= ($xadj);
  24038. }
  24039. else {
  24040. $this->PageAnnots[$this->page][$ref]['x'] += ($xadj);
  24041. }
  24042. $this->PageAnnots[$this->page][$ref]['y'] += ($yadj); // unlike PageLinks, Page annots has y values from top in mm
  24043. }
  24044. /*-- END ANNOTATIONS --*/
  24045. }
  24046. }
  24047. /*-- BOOKMARKS --*/
  24048. // mPDF 3.0
  24049. // Adjust Bookmarks
  24050. foreach($this->col_BMoutlines AS $v) {
  24051. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$this->y0,'p'=>$v['p']);
  24052. }
  24053. /*-- END BOOKMARKS --*/
  24054. /*-- INDEX --*/
  24055. // mPDF 3.0
  24056. // Adjust Reference (index)
  24057. foreach($this->col_Reference AS $v) {
  24058. $Present=0;
  24059. //Search the reference (AND Ref/PageNo) in the array
  24060. for ($i=0;$i<count($this->Reference);$i++){
  24061. if ($this->Reference[$i]['t']==$v['t']){
  24062. $Present=1;
  24063. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  24064. $this->Reference[$i]['p'][] = $v['op'];
  24065. }
  24066. }
  24067. }
  24068. if ($Present==0) {
  24069. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  24070. }
  24071. }
  24072. /*-- END INDEX --*/
  24073. /*-- TOC --*/
  24074. // mPDF 3.0
  24075. // Adjust ToC
  24076. foreach($this->col_toc AS $v) {
  24077. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  24078. $this->links[$v['link']][1] = $this->y0;
  24079. }
  24080. /*-- END TOC --*/
  24081. // Adjust column length to be equal
  24082. if ($this->colvAlign == 'J') {
  24083. foreach($this->columnbuffer AS $key=>$s) {
  24084. if (isset($s['rel_y'])) { // only process position sensitive data
  24085. // Set ratio to expand y values or heights
  24086. if ($this->ColDetails[$s['newcol']]['max_bottom']) {
  24087. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['newcol']]['max_bottom'] - ($this->y0));
  24088. }
  24089. else { $ratio = 1; }
  24090. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  24091. $yadj = ($s['newy'] - $this->y0) * ($ratio - 1);
  24092. // Adjust LINKS
  24093. if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  24094. $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  24095. $this->PageLinks[$this->page][$ref][1] -= ($yadj*$k); // y value
  24096. $this->PageLinks[$this->page][$ref][3] *= $ratio; // height
  24097. }
  24098. /*-- ANNOTATIONS --*/
  24099. if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  24100. $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  24101. $this->PageAnnots[$this->page][$ref]['y'] += ($yadj);
  24102. }
  24103. /*-- END ANNOTATIONS --*/
  24104. }
  24105. }
  24106. }
  24107. $last_col = -1;
  24108. $trans_on = false;
  24109. foreach($this->columnbuffer AS $key=>$s) {
  24110. if (isset($s['rel_y'])) { // only process position sensitive data
  24111. // Set ratio to expand y values or heights
  24112. if (isset($this->ColDetails[$s['newcol']]['max_bottom']) && $this->ColDetails[$s['newcol']]['max_bottom']) {
  24113. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['newcol']]['max_bottom'] - ($this->y0));
  24114. }
  24115. else { $ratio = 1; }
  24116. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  24117. //Start Transformation
  24118. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  24119. $this->pages[$this->page] .= $this->transformScale(100, $ratio*100, $x='', $this->y0, true)."\n";
  24120. $trans_on = true;
  24121. }
  24122. }
  24123. // Now output the adjusted values
  24124. $this->pages[$this->page] .= $s['s']."\n";
  24125. if (isset($s['rel_y']) && ($ratio > 1) && ($ratio <= $this->max_colH_correction)) { // only process position sensitive data
  24126. //Stop Transformation
  24127. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  24128. }
  24129. }
  24130. }
  24131. else { // if NOT $this->colvAlign == 'J'
  24132. // Now output the adjusted values
  24133. foreach($this->columnbuffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; }
  24134. }
  24135. if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; }
  24136. }
  24137. // Columns not ended but new page -> align columns (can leave the columns alone - just tidy up the height)
  24138. else if ($this->colvAlign == 'J' && $this->ColumnAdjust && !$this->keepColumns) {
  24139. $k = $this->k;
  24140. // calculate the lowest bottom margin
  24141. $lowest_bottom_y = 0;
  24142. foreach($this->columnbuffer AS $key=>$s) {
  24143. // Only process output data
  24144. $t = $s['s'];
  24145. if ((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)) ||
  24146. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) ||
  24147. (preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+ (\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/',$t)) ||
  24148. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) ||
  24149. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) ) { // mPDF 4.5.007
  24150. $clb = $s['y'] + $s['h'];
  24151. 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; }
  24152. if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; }
  24153. $this->columnbuffer[$key]['rel_y'] = $s['y']; // Marks position sensitive data to process later
  24154. }
  24155. }
  24156. // Adjust column length equal
  24157. foreach($this->columnbuffer AS $key=>$s) {
  24158. // Set ratio to expand y values or heights
  24159. if (isset($this->ColDetails[$s['col']]['max_bottom']) && $this->ColDetails[$s['col']]['max_bottom']) {
  24160. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['col']]['max_bottom'] - ($this->y0));
  24161. }
  24162. else { $ratio = 1; }
  24163. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  24164. $yadj = ($s['y'] - $this->y0) * ($ratio - 1);
  24165. // Adjust LINKS
  24166. if (isset($s['rel_y'])) { // only process position sensitive data
  24167. // otherwise triggers for all entries in column buffer (.e.g. formatting) and makes below adjustments more than once
  24168. if (isset($this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  24169. $ref = $this->columnLinks[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  24170. $this->PageLinks[$this->page][$ref][1] -= ($yadj*$k); // y value
  24171. $this->PageLinks[$this->page][$ref][3] *= $ratio; // height
  24172. }
  24173. /*-- ANNOTATIONS --*/
  24174. if (isset($this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])])) {
  24175. $ref = $this->columnAnnots[$s['col']][INTVAL($s['x'])][INTVAL($s['y'])];
  24176. $this->PageAnnots[$this->page][$ref]['y'] += ($yadj);
  24177. }
  24178. /*-- END ANNOTATIONS --*/
  24179. }
  24180. }
  24181. }
  24182. /*-- BOOKMARKS --*/
  24183. // mPDF 3.0
  24184. // Adjust Bookmarks
  24185. foreach($this->col_BMoutlines AS $v) {
  24186. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$this->y0,'p'=>$v['p']);
  24187. }
  24188. /*-- END BOOKMARKS --*/
  24189. /*-- INDEX --*/
  24190. // mPDF 3.0
  24191. // Adjust Reference (index)
  24192. foreach($this->col_Reference AS $v) {
  24193. $Present=0;
  24194. //Search the reference (AND Ref/PageNo) in the array
  24195. for ($i=0;$i<count($this->Reference);$i++){
  24196. if ($this->Reference[$i]['t']==$v['t']){
  24197. $Present=1;
  24198. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  24199. $this->Reference[$i]['p'][] = $v['op'];
  24200. }
  24201. }
  24202. }
  24203. if ($Present==0) {
  24204. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  24205. }
  24206. }
  24207. /*-- END INDEX --*/
  24208. /*-- TOC --*/
  24209. // mPDF 3.0
  24210. // Adjust ToC
  24211. foreach($this->col_toc AS $v) {
  24212. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  24213. $this->links[$v['link']][1] = $this->y0;
  24214. }
  24215. /*-- END TOC --*/
  24216. foreach($this->columnbuffer AS $key=>$s) {
  24217. if (isset($s['rel_y'])) { // only process position sensitive data
  24218. // Set ratio to expand y values or heights
  24219. if ($this->ColDetails[$s['col']]['max_bottom']) {
  24220. $ratio = ($lowest_bottom_y - ($this->y0)) / ($this->ColDetails[$s['col']]['max_bottom'] - ($this->y0));
  24221. }
  24222. else { $ratio = 1; }
  24223. if (($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  24224. //Start Transformation
  24225. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  24226. $this->pages[$this->page] .= $this->transformScale(100, $ratio*100, $x='', $this->y0, true)."\n";
  24227. }
  24228. }
  24229. // Now output the adjusted values
  24230. $this->pages[$this->page] .= $s['s']."\n";
  24231. if (isset($s['rel_y']) && ($ratio > 1) && ($ratio <= $this->max_colH_correction)) {
  24232. //Stop Transformation
  24233. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  24234. }
  24235. }
  24236. if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; }
  24237. }
  24238. // Just reproduce the page as it was
  24239. else {
  24240. // If page has not ended but height adjustment was disabled by custom column-break - adjust y
  24241. $k = $this->k;
  24242. $lowest_bottom_y = 0;
  24243. // if ((!$this->ColumnAdjust && !$this->ColActive) || $this->keepColumns) {
  24244. if (!$this->ColActive && (!$this->ColumnAdjust || $this->keepColumns)) {
  24245. // calculate the lowest bottom margin
  24246. foreach($this->columnbuffer AS $key=>$s) {
  24247. // Only process output data
  24248. $t = $s['s'];
  24249. if ((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)) ||
  24250. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) l/',$t)) ||
  24251. (preg_match('/q \d+\.\d\d+ 0 0 \d+\.\d\d+ \d+\.\d\d+ (\d+\.\d\d+) cm \/(I|FO)\d+ Do Q/',$t)) ||
  24252. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) m/',$t)) ||
  24253. (preg_match('/\d+\.\d\d+ (\d+\.\d\d+) \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ \d+\.\d\d+ c/',$t)) ) { // mPDF 4.5.007
  24254. $clb = $s['y'] + $s['h'];
  24255. if ($clb > $this->ColDetails[$s['col']]['max_bottom']) { $this->ColDetails[$s['col']]['max_bottom'] = $clb; }
  24256. if ($clb > $lowest_bottom_y) { $lowest_bottom_y = $clb; }
  24257. }
  24258. }
  24259. }
  24260. foreach($this->columnbuffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; }
  24261. if ($lowest_bottom_y > 0) { $this->y = $lowest_bottom_y ; }
  24262. /*-- INDEX --*/
  24263. // mPDF 3.0
  24264. // Output Reference (index)
  24265. foreach($this->col_Reference AS $v) {
  24266. $Present=0;
  24267. for ($i=0;$i<count($this->Reference);$i++){
  24268. if ($this->Reference[$i]['t']==$v['t']){
  24269. $Present=1;
  24270. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  24271. $this->Reference[$i]['p'][] = $v['op'];
  24272. }
  24273. }
  24274. }
  24275. if ($Present==0) {
  24276. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  24277. }
  24278. }
  24279. /*-- END INDEX --*/
  24280. /*-- BOOKMARKS --*/
  24281. // Output Bookmarks
  24282. foreach($this->col_BMoutlines AS $v) {
  24283. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  24284. }
  24285. /*-- END BOOKMARKS --*/
  24286. /*-- TOC --*/
  24287. // Output ToC
  24288. foreach($this->col_toc AS $v) {
  24289. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  24290. }
  24291. /*-- END TOC --*/
  24292. }
  24293. $this->columnbuffer = array();
  24294. $this->ColDetails = array();
  24295. $this->columnLinks = array();
  24296. $this->columnAnnots = array();
  24297. // mPDF 3.0
  24298. $this->col_Reference = array();
  24299. $this->col_BMoutlines = array();
  24300. $this->col_toc = array();
  24301. $this->breakpoints = array();
  24302. }
  24303. /*-- END COLUMNS --*/
  24304. //==================================================================
  24305. /*-- TABLES --*/
  24306. function printcellbuffer() {
  24307. if (count($this->cellBorderBuffer )) {
  24308. // usort( $this->cellBorderBuffer , array($this, "_cmpdom"));
  24309. // mPDF 4.3.008 4.3.014
  24310. sort($this->cellBorderBuffer);
  24311. foreach($this->cellBorderBuffer AS $cbb) {
  24312. $cba = unpack("A16dom/nbord/A1side/ns/dbw/ncr/ncg/ncb/A10style/dx/dy/dw/dh/dmbl/dmbr/dmrt/dmrb/dmtl/dmtr/dmlt/dmlb/dcpd/dover/", $cbb);
  24313. $side = $cba['side'];
  24314. $details = array();
  24315. $details[$side]['dom'] = (float) $cba['dom'];
  24316. $details[$side]['s'] = $cba['s'];
  24317. $details[$side]['w'] = $cba['bw'];
  24318. $details[$side]['c']['R'] = $cba['cr'];
  24319. $details[$side]['c']['G'] = $cba['cg'];
  24320. $details[$side]['c']['B'] = $cba['cb'];
  24321. $details[$side]['style'] = trim($cba['style']);
  24322. $details['mbw']['BL'] = $cba['mbl'];
  24323. $details['mbw']['BR'] = $cba['mbr'];
  24324. $details['mbw']['RT'] = $cba['mrt'];
  24325. $details['mbw']['RB'] = $cba['mrb'];
  24326. $details['mbw']['TL'] = $cba['mtl'];
  24327. $details['mbw']['TR'] = $cba['mtr'];
  24328. $details['mbw']['LT'] = $cba['mlt'];
  24329. $details['mbw']['LB'] = $cba['mlb'];
  24330. $details['cellposdom'] = $cba['cpd'];
  24331. $details['p'] = $side;
  24332. if ($cba['over']==1) { $details[$side]['overlay'] = true; }
  24333. else { $details[$side]['overlay'] = false; }
  24334. $this->_tableRect($cba['x'],$cba['y'],$cba['w'],$cba['h'],$cba['bord'],$details, false, false);
  24335. }
  24336. $this->cellBorderBuffer = array();
  24337. }
  24338. }
  24339. //==================================================================
  24340. function printtablebuffer() {
  24341. if (!$this->table_rotate) {
  24342. foreach($this->tablebuffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; }
  24343. foreach($this->tbrot_Links AS $p => $l) {
  24344. foreach($l AS $v) {
  24345. $this->PageLinks[$p][] = $v;
  24346. }
  24347. }
  24348. $this->tbrot_Links = array();
  24349. /*-- ANNOTATIONS --*/
  24350. foreach($this->tbrot_Annots AS $p => $l) {
  24351. foreach($l AS $v) {
  24352. $this->PageAnnots[$p][] = $v;
  24353. }
  24354. }
  24355. $this->tbrot_Annots = array();
  24356. /*-- END ANNOTATIONS --*/
  24357. /*-- INDEX --*/
  24358. // mPDF 3.0
  24359. // Output Reference (index)
  24360. foreach($this->tbrot_Reference AS $v) {
  24361. $Present=0;
  24362. for ($i=0;$i<count($this->Reference);$i++){
  24363. if ($this->Reference[$i]['t']==$v['t']){
  24364. $Present=1;
  24365. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  24366. $this->Reference[$i]['p'][] = $v['op'];
  24367. }
  24368. }
  24369. }
  24370. if ($Present==0) {
  24371. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  24372. }
  24373. }
  24374. $this->tbrot_Reference = array();
  24375. /*-- END INDEX --*/
  24376. /*-- BOOKMARKS --*/
  24377. // Output Bookmarks
  24378. foreach($this->tbrot_BMoutlines AS $v) {
  24379. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  24380. }
  24381. $this->tbrot_BMoutlines = array();
  24382. /*-- END BOOKMARKS --*/
  24383. /*-- TOC --*/
  24384. // Output ToC
  24385. foreach($this->tbrot_toc AS $v) {
  24386. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  24387. }
  24388. $this->tbrot_toc = array();
  24389. /*-- END TOC --*/
  24390. return;
  24391. }
  24392. // else if rotated
  24393. $lm = $this->lMargin + $this->blk[$this->blklvl]['outer_left_margin'] + $this->blk[$this->blklvl]['border_left']['w'] + $this->blk[$this->blklvl]['padding_left'];
  24394. $pw = $this->blk[$this->blklvl]['inner_width'];
  24395. //Start Transformation
  24396. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  24397. if ($this->table_rotate > 1) { // clockwise
  24398. if ($this->tbrot_align == 'L') {
  24399. $xadj = $this->tbrot_h ; // align L (as is)
  24400. }
  24401. else if ($this->tbrot_align == 'R') {
  24402. $xadj = $lm-$this->tbrot_x0+($pw) ; // align R
  24403. }
  24404. else {
  24405. $xadj = $lm-$this->tbrot_x0+(($pw + $this->tbrot_h)/2) ; // align C
  24406. }
  24407. $yadj = 0;
  24408. }
  24409. else { // anti-clockwise
  24410. if ($this->tbrot_align == 'L') {
  24411. $xadj = 0 ; // align L (as is)
  24412. }
  24413. else if ($this->tbrot_align == 'R') {
  24414. $xadj = $lm-$this->tbrot_x0+($pw - $this->tbrot_h) ; // align R
  24415. }
  24416. else {
  24417. $xadj = $lm-$this->tbrot_x0+(($pw - $this->tbrot_h)/2) ; // align C
  24418. }
  24419. $yadj = $this->tbrot_w;
  24420. }
  24421. $this->pages[$this->page] .= $this->transformTranslate($xadj, $yadj , true)."\n";
  24422. $this->pages[$this->page] .= $this->transformRotate($this->table_rotate, $this->tbrot_x0 , $this->tbrot_y0 , true)."\n";
  24423. // Now output the adjusted values
  24424. foreach($this->tablebuffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; }
  24425. foreach($this->tbrot_Links AS $p => $l) {
  24426. foreach($l AS $v) {
  24427. $w = $v[2]/$this->k;
  24428. $h = $v[3]/$this->k;
  24429. $ax = ($v[0]/$this->k) - $this->tbrot_x0;
  24430. $ay = (($this->hPt-$v[1])/$this->k) - $this->tbrot_y0;
  24431. if ($this->table_rotate > 1) { // clockwise
  24432. $bx = $this->tbrot_x0+$xadj-$ay-$h;
  24433. $by = $this->tbrot_y0+$yadj+$ax;
  24434. }
  24435. else {
  24436. $bx = $this->tbrot_x0+$xadj+$ay;
  24437. $by = $this->tbrot_y0+$yadj-$ax-$w;
  24438. }
  24439. $v[0] = $bx*$this->k;
  24440. $v[1] = ($this->h-$by)*$this->k;
  24441. $v[2] = $h*$this->k; // swap width and height
  24442. $v[3] = $w*$this->k;
  24443. $this->PageLinks[$p][] = $v;
  24444. }
  24445. }
  24446. $this->tbrot_Links = array();
  24447. /*-- ANNOTATIONS --*/
  24448. foreach($this->tbrot_Annots AS $p => $l) {
  24449. foreach($l AS $v) {
  24450. $w = $this->annotSize;
  24451. $h = $this->annotSize;
  24452. $ax = abs($v['x']) - $this->tbrot_x0; // abs because -ve values are internally set and held for reference if annotMargin set
  24453. $ay = $v['y'] - $this->tbrot_y0;
  24454. if ($this->table_rotate > 1) { // clockwise
  24455. $bx = $this->tbrot_x0+$xadj-$ay-$h;
  24456. $by = $this->tbrot_y0+$yadj+$ax;
  24457. }
  24458. else {
  24459. $bx = $this->tbrot_x0+$xadj+$ay;
  24460. $by = $this->tbrot_y0+$yadj-$ax-$w;
  24461. }
  24462. if ($v['x'] < 0) {
  24463. $v['x'] = -$bx;
  24464. }
  24465. else {
  24466. $v['x'] = $bx;
  24467. }
  24468. $v['y'] = ($by);
  24469. $this->PageAnnots[$p][] = $v;
  24470. }
  24471. }
  24472. $this->tbrot_Annots = array();
  24473. /*-- END ANNOTATIONS --*/
  24474. /*-- BOOKMARKS --*/
  24475. // mPDF 3.0
  24476. // Adjust Bookmarks
  24477. foreach($this->tbrot_BMoutlines AS $v) {
  24478. $v['y'] = $this->tbrot_y0;
  24479. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$this->page);
  24480. }
  24481. /*-- END BOOKMARKS --*/
  24482. /*-- INDEX --*/
  24483. // mPDF 3.0
  24484. // Adjust Reference (index)
  24485. foreach($this->tbrot_Reference AS $v) {
  24486. $Present=0;
  24487. //Search the reference (AND Ref/PageNo) in the array
  24488. for ($i=0;$i<count($this->Reference);$i++){
  24489. if ($this->Reference[$i]['t']==$v['t']){
  24490. $Present=1;
  24491. if (!in_array($this->page,$this->Reference[$i]['p'])) {
  24492. $this->Reference[$i]['p'][] = $this->page;
  24493. }
  24494. }
  24495. }
  24496. if ($Present==0) {
  24497. $this->Reference[]=array('t'=>$v['t'],'p'=>array($this->page));
  24498. }
  24499. }
  24500. /*-- END INDEX --*/
  24501. /*-- TOC --*/
  24502. // mPDF 3.0
  24503. // Adjust ToC - uses document page number
  24504. foreach($this->tbrot_toc AS $v) {
  24505. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$this->page,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  24506. $this->links[$v['link']][1] = $this->tbrot_y0;
  24507. }
  24508. /*-- END TOC --*/
  24509. // mPDF 3.0
  24510. $this->tbrot_Reference = array();
  24511. $this->tbrot_BMoutlines = array();
  24512. $this->tbrot_toc = array();
  24513. //Stop Transformation
  24514. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  24515. $this->y = $this->tbrot_y0 + $this->tbrot_w;
  24516. $this->x = $this->lMargin;
  24517. $this->tablebuffer = array();
  24518. }
  24519. //==================================================================
  24520. // Keep-with-table This buffers contents of h1-6 to keep on page with table
  24521. function printkwtbuffer() {
  24522. if (!$this->kwt_moved) {
  24523. foreach($this->kwt_buffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; }
  24524. foreach($this->kwt_Links AS $p => $l) {
  24525. foreach($l AS $v) {
  24526. $this->PageLinks[$p][] = $v;
  24527. }
  24528. }
  24529. $this->kwt_Links = array();
  24530. /*-- ANNOTATIONS --*/
  24531. foreach($this->kwt_Annots AS $p => $l) {
  24532. foreach($l AS $v) {
  24533. $this->PageAnnots[$p][] = $v;
  24534. }
  24535. }
  24536. $this->kwt_Annots = array();
  24537. /*-- END ANNOTATIONS --*/
  24538. /*-- INDEX --*/
  24539. // mPDF 3.0
  24540. // Output Reference (index)
  24541. foreach($this->kwt_Reference AS $v) {
  24542. $Present=0;
  24543. for ($i=0;$i<count($this->Reference);$i++){
  24544. if ($this->Reference[$i]['t']==$v['t']){
  24545. $Present=1;
  24546. if (!in_array($v['op'],$this->Reference[$i]['p'])) {
  24547. $this->Reference[$i]['p'][] = $v['op'];
  24548. }
  24549. }
  24550. }
  24551. if ($Present==0) {
  24552. $this->Reference[]=array('t'=>$v['t'],'p'=>array($v['op']));
  24553. }
  24554. }
  24555. $this->kwt_Reference = array();
  24556. /*-- END INDEX --*/
  24557. /*-- BOOKMARKS --*/
  24558. // Output Bookmarks
  24559. foreach($this->kwt_BMoutlines AS $v) {
  24560. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  24561. }
  24562. $this->kwt_BMoutlines = array();
  24563. /*-- END BOOKMARKS --*/
  24564. /*-- TOC --*/
  24565. // Output ToC
  24566. foreach($this->kwt_toc AS $v) {
  24567. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  24568. }
  24569. $this->kwt_toc = array();
  24570. /*-- END TOC --*/
  24571. return;
  24572. }
  24573. //Start Transformation
  24574. $this->pages[$this->page] .= $this->StartTransform(true)."\n";
  24575. $xadj = $this->lMargin - $this->kwt_x0 ;
  24576. //$yadj = $this->y - $this->kwt_y0 ;
  24577. $yadj = $this->tMargin - $this->kwt_y0 ;
  24578. $this->pages[$this->page] .= $this->transformTranslate($xadj, $yadj , true)."\n";
  24579. // Now output the adjusted values
  24580. foreach($this->kwt_buffer AS $s) { $this->pages[$this->page] .= $s['s']."\n"; }
  24581. // Adjust hyperLinks
  24582. foreach($this->kwt_Links AS $p => $l) {
  24583. foreach($l AS $v) {
  24584. $bx = $this->kwt_x0+$xadj;
  24585. $by = $this->kwt_y0+$yadj;
  24586. $v[0] = $bx*$this->k;
  24587. $v[1] = ($this->h-$by)*$this->k;
  24588. $this->PageLinks[$p][] = $v;
  24589. }
  24590. }
  24591. /*-- ANNOTATIONS --*/
  24592. foreach($this->kwt_Annots AS $p => $l) {
  24593. foreach($l AS $v) {
  24594. $w = $this->annotSize;
  24595. $h = $this->annotSize;
  24596. $bx = $this->kwt_x0+$xadj;
  24597. $by = $this->kwt_y0+$yadj;
  24598. if ($v['x'] < 0) {
  24599. $v['x'] = -$bx;
  24600. }
  24601. else {
  24602. $v['x'] = $bx;
  24603. }
  24604. $v['y'] = $by;
  24605. $this->PageAnnots[$p][] = $v;
  24606. }
  24607. }
  24608. /*-- END ANNOTATIONS --*/
  24609. /*-- BOOKMARKS --*/
  24610. // mPDF 3.0
  24611. // Adjust Bookmarks
  24612. foreach($this->kwt_BMoutlines AS $v) {
  24613. if ($v['y'] != 0) { $v['y'] += $yadj; }
  24614. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$this->page);
  24615. }
  24616. /*-- END BOOKMARKS --*/
  24617. /*-- INDEX --*/
  24618. // mPDF 3.0
  24619. // Adjust Reference (index)
  24620. foreach($this->kwt_Reference AS $v) {
  24621. $Present=0;
  24622. //Search the reference (AND Ref/PageNo) in the array
  24623. for ($i=0;$i<count($this->Reference);$i++){
  24624. if ($this->Reference[$i]['t']==$v['t']){
  24625. $Present=1;
  24626. if (!in_array($this->page,$this->Reference[$i]['p'])) {
  24627. $this->Reference[$i]['p'][] = $this->page;
  24628. }
  24629. }
  24630. }
  24631. if ($Present==0) {
  24632. $this->Reference[]=array('t'=>$v['t'],'p'=>array($this->page));
  24633. }
  24634. }
  24635. /*-- END INDEX --*/
  24636. /*-- TOC --*/
  24637. // mPDF 3.0
  24638. // Adjust ToC
  24639. foreach($this->kwt_toc AS $v) {
  24640. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$this->page,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  24641. $this->links[$v['link']][0] = $this->page;
  24642. $this->links[$v['link']][1] += $yadj;
  24643. }
  24644. /*-- END TOC --*/
  24645. $this->kwt_Links = array();
  24646. $this->kwt_Annots = array();
  24647. // mPDF 3.0
  24648. $this->kwt_Reference = array();
  24649. $this->kwt_BMoutlines = array();
  24650. $this->kwt_toc = array();
  24651. //Stop Transformation
  24652. $this->pages[$this->page] .= $this->StopTransform(true)."\n";
  24653. $this->kwt_buffer = array();
  24654. $this->y += $this->kwt_height;
  24655. }
  24656. /*-- END TABLES --*/
  24657. //==================================================================
  24658. // mPDF 4.0
  24659. function printfloatbuffer() {
  24660. if (count($this->floatbuffer)) {
  24661. $this->objectbuffer = $this->floatbuffer;
  24662. $this->printobjectbuffer(false);
  24663. $this->objectbuffer = array();
  24664. $this->floatbuffer = array();
  24665. $this->floatmargins = array();
  24666. }
  24667. }
  24668. //==================================================================
  24669. function printdivbuffer() {
  24670. $k = $this->k;
  24671. $p1 = $this->blk[$this->blklvl]['startpage'];
  24672. $p2 = $this->page;
  24673. $bottom[$p1] = $this->ktBlock[$p1]['bottom_margin'];
  24674. $bottom[$p2] = $this->y; // $this->ktBlock[$p2]['bottom_margin'];
  24675. $top[$p1] = $this->blk[$this->blklvl]['y00'];
  24676. $top2 = $this->h;
  24677. foreach($this->divbuffer AS $key=>$s) {
  24678. if ($s['page'] == $p2) {
  24679. $top2 = MIN($s['y'], $top2);
  24680. }
  24681. }
  24682. $top[$p2] = $top2;
  24683. $height[$p1] = ($bottom[$p1] - $top[$p1]);
  24684. $height[$p2] = ($bottom[$p2] - $top[$p2]);
  24685. $xadj[$p1] = $this->MarginCorrection;
  24686. $yadj[$p1] = -($top[$p1] - $top[$p2]);
  24687. $xadj[$p2] = 0;
  24688. $yadj[$p2] = $height[$p1];
  24689. 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) {
  24690. foreach($this->divbuffer AS $s) { $this->pages[$s['page']] .= $s['s']."\n"; }
  24691. foreach($this->ktLinks AS $p => $l) {
  24692. foreach($l AS $v) {
  24693. $this->PageLinks[$p][] = $v;
  24694. }
  24695. }
  24696. /*-- ANNOTATIONS --*/
  24697. foreach($this->ktAnnots AS $p => $l) {
  24698. foreach($l AS $v) {
  24699. $this->PageAnnots[$p][] = $v;
  24700. }
  24701. }
  24702. /*-- END ANNOTATIONS --*/
  24703. /*-- INDEX --*/
  24704. // Adjust Reference (index)
  24705. foreach($this->ktReference AS $v) {
  24706. // mPDF 3.0
  24707. $Present=0;
  24708. //Search the reference (AND Ref/PageNo) in the array
  24709. for ($i=0;$i<count($this->Reference);$i++){
  24710. if ($this->Reference[$i]['t']==$v['t']){
  24711. $Present=1;
  24712. if (!in_array($p2,$this->Reference[$i]['p'])) {
  24713. $this->Reference[$i]['p'][] = $p2;
  24714. }
  24715. }
  24716. }
  24717. //If not found, add it
  24718. if ($Present==0) {
  24719. $this->Reference[]=array('t'=>$v['t'],'p'=>array($p2));
  24720. }
  24721. }
  24722. /*-- END INDEX --*/
  24723. /*-- BOOKMARKS --*/
  24724. // Adjust Bookmarks
  24725. foreach($this->ktBMoutlines AS $v) {
  24726. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
  24727. }
  24728. /*-- END BOOKMARKS --*/
  24729. /*-- TOC --*/
  24730. // Adjust ToC
  24731. foreach($this->_kttoc AS $v) {
  24732. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  24733. }
  24734. /*-- END TOC --*/
  24735. $this->divbuffer = array();
  24736. $this->ktLinks = array();
  24737. $this->ktAnnots = array();
  24738. $this->ktBlock = array();
  24739. $this->ktReference = array();
  24740. $this->ktBMoutlines = array();
  24741. $this->_kttoc = array();
  24742. $this->keep_block_together = 0;
  24743. return;
  24744. }
  24745. else {
  24746. foreach($this->divbuffer AS $key=>$s) {
  24747. // callback function in htmltoolkit
  24748. $t = $s['s'];
  24749. $p = $s['page'];
  24750. $t = preg_replace('/BT (\d+\.\d\d+) (\d+\.\d\d+) Td/e',"\$this->blockAdjust('Td',$k,$xadj[$p],$yadj[$p],'\\1','\\2')",$t);
  24751. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) (\d+\.\d\d+) ([\-]{0,1}\d+\.\d\d+) re/e',"\$this->blockAdjust('re',$k,$xadj[$p],$yadj[$p],'\\1','\\2','\\3','\\4')",$t);
  24752. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) l/e',"\$this->blockAdjust('l',$k,$xadj[$p],$yadj[$p],'\\1','\\2')",$t);
  24753. $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',$k,$xadj[$p],$yadj[$p],'\\1','\\2','\\3','\\4','\\5')",$t); // mPDF 4.5.007
  24754. $t = preg_replace('/(\d+\.\d\d+) (\d+\.\d\d+) m/e',"\$this->blockAdjust('draw',$k,$xadj[$p],$yadj[$p],'\\1','\\2')",$t);
  24755. $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',$k,$xadj[$p],$yadj[$p],'\\1','\\2','\\3','\\4','\\5','\\6')",$t);
  24756. $this->pages[$this->page] .= $t."\n";
  24757. }
  24758. // Adjust hyperLinks
  24759. foreach($this->ktLinks AS $p => $l) {
  24760. foreach($l AS $v) {
  24761. $v[0] += ($xadj[$p]*$k);
  24762. $v[1] -= ($yadj[$p]*$k);
  24763. $this->PageLinks[$p2][] = $v;
  24764. }
  24765. }
  24766. /*-- ANNOTATIONS --*/
  24767. foreach($this->ktAnnots AS $p => $l) {
  24768. foreach($l AS $v) {
  24769. if ($v['x']>0) { $v['x'] += $xadj[$p]; }
  24770. else if ($v['x']<0) { $v['x'] -= $xadj[$p]; }
  24771. // mPDF 3.0 -= -> +=
  24772. $v['y'] += $yadj[$p];
  24773. $this->PageAnnots[$p2][] = $v;
  24774. }
  24775. }
  24776. /*-- END ANNOTATIONS --*/
  24777. /*-- BOOKMARKS --*/
  24778. // Adjust Bookmarks
  24779. foreach($this->ktBMoutlines AS $v) {
  24780. if ($v['y'] != 0) { $v['y'] += ($yadj[$v['p']]); }
  24781. $this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$p2);
  24782. }
  24783. /*-- END BOOKMARKS --*/
  24784. /*-- INDEX --*/
  24785. // Adjust Reference (index)
  24786. foreach($this->ktReference AS $v) {
  24787. // mPDF 3.0
  24788. $Present=0;
  24789. //Search the reference (AND Ref/PageNo) in the array
  24790. for ($i=0;$i<count($this->Reference);$i++){
  24791. if ($this->Reference[$i]['t']==$v['t']){
  24792. $Present=1;
  24793. if (!in_array($p2,$this->Reference[$i]['p'])) {
  24794. $this->Reference[$i]['p'][] = $p2;
  24795. }
  24796. }
  24797. }
  24798. //If not found, add it
  24799. if ($Present==0) {
  24800. $this->Reference[]=array('t'=>$v['t'],'p'=>array($p2));
  24801. }
  24802. }
  24803. /*-- END INDEX --*/
  24804. /*-- TOC --*/
  24805. // Adjust ToC
  24806. foreach($this->_kttoc AS $v) {
  24807. $this->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$p2,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
  24808. // mPDF 3.0
  24809. $this->links[$v['link']][0] = $p2;
  24810. $this->links[$v['link']][1] += $yadj[$p];
  24811. }
  24812. /*-- END TOC --*/
  24813. $this->y = $top[$p2] + $height[$p1] + $height[$p2];
  24814. $this->x = $this->lMargin;
  24815. $this->divbuffer = array();
  24816. $this->ktLinks = array();
  24817. $this->ktAnnots = array();
  24818. $this->ktBlock = array();
  24819. $this->ktReference = array();
  24820. $this->ktBMoutlines = array();
  24821. $this->_kttoc = array();
  24822. $this->keep_block_together = 0;
  24823. }
  24824. }
  24825. //==================================================================
  24826. // Added ELLIPSES and CIRCLES
  24827. function Circle($x,$y,$r,$style='S') {
  24828. $this->Ellipse($x,$y,$r,$r,$style);
  24829. }
  24830. function Ellipse($x,$y,$rx,$ry,$style='S') {
  24831. if($style=='F') { $op='f'; }
  24832. elseif($style=='FD' or $style=='DF') { $op='B'; }
  24833. else { $op='S'; }
  24834. $lx=4/3*(M_SQRT2-1)*$rx;
  24835. $ly=4/3*(M_SQRT2-1)*$ry;
  24836. $k=$this->k;
  24837. $h=$this->h;
  24838. $this->_out(sprintf('%.3f %.3f m %.3f %.3f %.3f %.3f %.3f %.3f c', ($x+$rx)*$k,($h-$y)*$k, ($x+$rx)*$k,($h-($y-$ly))*$k, ($x+$lx)*$k,($h-($y-$ry))*$k, $x*$k,($h-($y-$ry))*$k));
  24839. $this->_out(sprintf('%.3f %.3f %.3f %.3f %.3f %.3f c', ($x-$lx)*$k,($h-($y-$ry))*$k, ($x-$rx)*$k,($h-($y-$ly))*$k, ($x-$rx)*$k,($h-$y)*$k));
  24840. $this->_out(sprintf('%.3f %.3f %.3f %.3f %.3f %.3f c', ($x-$rx)*$k,($h-($y+$ly))*$k, ($x-$lx)*$k,($h-($y+$ry))*$k, $x*$k,($h-($y+$ry))*$k));
  24841. $this->_out(sprintf('%.3f %.3f %.3f %.3f %.3f %.3f c %s', ($x+$lx)*$k,($h-($y+$ry))*$k, ($x+$rx)*$k,($h-($y+$ly))*$k, ($x+$rx)*$k,($h-$y)*$k, $op));
  24842. }
  24843. /*-- DIRECTW --*/
  24844. // Added adaptation of shaded_box = AUTOSIZE-TEXT
  24845. // Label and number of invoice/estimate
  24846. function AutosizeText($text,$w,$font,$style,$szfont=72) {
  24847. $text = $this->purify_utf8_text($text);
  24848. if ($this->text_input_as_HTML) {
  24849. $text = $this->all_entities_to_utf8($text);
  24850. }
  24851. // Modified by Ivan Tcholakov, 28-JAN-2010.
  24852. //if (!$this->is_MB) { $text = mb_convert_encoding($text,$this->mb_enc,'UTF-8'); }
  24853. if (!$this->is_MB) { $text = api_convert_encoding($text,$this->mb_enc,'UTF-8'); }
  24854. //
  24855. $text = ' '.$text.' ';
  24856. $width = $this->ConvertSize($w);
  24857. $loop = 0;
  24858. while ( $loop == 0 ) {
  24859. $this->SetFont($font,$style,$szfont);
  24860. $sz = $this->GetStringWidth( $text );
  24861. if ( $sz > $w ) { $szfont --; }
  24862. else { $loop ++; }
  24863. }
  24864. $this->SetFont($font,$style,$szfont);
  24865. $this->Cell($w, 0, $text, 0, 0, "C");
  24866. }
  24867. /*-- END DIRECTW --*/
  24868. // ====================================================
  24869. // ====================================================
  24870. /*-- RTL --*/
  24871. function reverse_letters($str) {
  24872. // mPDF 4.0
  24873. $str = strtr($str, '{}[]()', '}{][)(');
  24874. // Modified by Ivan Tcholakov, 28-JAN-2010.
  24875. //return $this->mb_strrev($str, $this->mb_enc);
  24876. return api_strrev($str, $this->mb_enc);
  24877. //
  24878. }
  24879. function magic_reverse_dir(&$chunk, $join=true) {
  24880. if (!$this->is_MB || $this->isCJK) { return 0; }
  24881. if (($this->directionality == 'rtl') || (($this->directionality == 'ltr') && ($this->biDirectional))) {
  24882. // Change Arabic + Persian. to Presentation Forms
  24883. if ($join) {
  24884. // mPDF 4.0 Remove rtlAsArabicFarsi
  24885. $chunk = preg_replace("/([".$this->pregRTLchars."]+)/ue", '$this->ArabJoin(stripslashes(\'\\1\'))', $chunk );
  24886. }
  24887. $contains_rtl = false;
  24888. $all_rtl = true;
  24889. if (preg_match("/[".$this->pregRTLchars."]/u",$chunk)) { // Chunk contains RTL characters
  24890. if (preg_match("/[^".$this->pregRTLchars."\x{A0}\"\'\(\)., :\-]/u",$chunk)) { // Chunk also contains LTR characters (added , mPDF 4.0)
  24891. $all_rtl = false;
  24892. $bits = explode(' ',$chunk); // mPDF 4.4.012
  24893. foreach($bits AS $bitkey=>$bit) {
  24894. if (preg_match("/[".$this->pregRTLchars."]/u",$bit)) { // Chunk also contains LTR characters
  24895. $bits[$bitkey] = $this->reverse_letters($bit);
  24896. }
  24897. else {
  24898. $bits[$bitkey] = $bit;
  24899. }
  24900. }
  24901. $bits = array_reverse($bits,false);
  24902. $chunk = implode(' ',$bits);
  24903. }
  24904. else {
  24905. $chunk = $this->reverse_letters($chunk);
  24906. }
  24907. $contains_rtl = true;
  24908. }
  24909. else { $all_rtl = false; }
  24910. if ($all_rtl) { return 2; }
  24911. else if ($contains_rtl) { return 1; }
  24912. else { return 0; }
  24913. }
  24914. return 0;
  24915. }
  24916. /*-- END RTL --*/
  24917. //
  24918. // ****************************
  24919. // ****************************
  24920. // mPDF 4.0
  24921. function SetSubstitutions($dummy=array()) { // parameter only for backward compatability
  24922. $subsarray = array();
  24923. @include(_MPDF_PATH.'includes/subs_'.strtolower($this->codepage).'.php');
  24924. $this->substitute = array();
  24925. foreach($subsarray AS $key => $val) {
  24926. $this->substitute[code2utf($key)] = $val;
  24927. }
  24928. }
  24929. function SubstituteChars($html) {
  24930. // mPDF 4.2.018
  24931. if ($this->PDFA && $this->useSubstitutions) {
  24932. if (!$this->PDFAauto) { $this->PDFAwarnings[] = "Core Adobe fonts [Helvetica, Times, Symbol etc] cannot be embedded with mPDF, which is required for PDFA1-b (Character substitution [useSubstitutions] disabled)"; }
  24933. $this->useSubstitutions = false;
  24934. }
  24935. // only substitute characters between tags
  24936. if ($this->useSubstitutions && count($this->substitute)) {
  24937. $a=preg_split('/(<.*?>)/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  24938. $html = '';
  24939. foreach($a as $i => $e) {
  24940. if($i%2==0) {
  24941. $e = strtr($e, $this->substitute);
  24942. }
  24943. $html .= $e;
  24944. }
  24945. }
  24946. return $html;
  24947. }
  24948. /*-- UNICODE-FONTS --*/
  24949. // mPDF 4.2
  24950. function SubstituteCharsMB(&$writehtml_a, &$writehtml_i, &$writehtml_e) {
  24951. // mPDF 4.2.018
  24952. if ($this->PDFA) {
  24953. if (!$this->PDFAauto) { $this->PDFAwarnings[] = "Core Adobe fonts [Helvetica, Times, Symbol etc] cannot be embedded with mPDF, which is required for PDFA1-b (Character substitution [useSubstitutionsMB] disabled)"; }
  24954. $this->useSubstitutionsMB = false;
  24955. return 0;
  24956. }
  24957. $cw = &$this->CurrentFont['cw'];
  24958. $unicode = $this->UTF8StringToArray($writehtml_e);
  24959. $start = -1;
  24960. $end = 0;
  24961. $flag = 0;
  24962. $ftype = '';
  24963. $u = array();
  24964. foreach($unicode AS $c => $char) {
  24965. if ($char != 173 && !isset($cw[$char]) && (!isset($this->chrs[$char]) || !isset($cw[$this->chrs[$char]])) &&
  24966. ($char<1423 || ($char>3583 && $char < 11263))) {
  24967. if ($flag==0) { $start=$c; }
  24968. $flag=1;
  24969. $u[] = $char;
  24970. }
  24971. else if ($flag==1) { $end=$c-1; break; }
  24972. }
  24973. if ($flag==1 && !$end) { $end=count($unicode)-1; }
  24974. if ($start==-1) { return 0; }
  24975. if (!$this->subArrMB) {
  24976. include(_MPDF_PATH.'includes/subs_core.php');
  24977. $this->subArrMB['a'] = $aarr;
  24978. $this->subArrMB['s'] = $sarr;
  24979. $this->subArrMB['z'] = $zarr;
  24980. }
  24981. // TRY CORE FONTS FIRST
  24982. if (isset($this->subArrMB['a'][$u[0]])) {
  24983. $font = 'tta'; $ftype = 'C';
  24984. foreach($u AS $char) {
  24985. if ($this->subArrMB['a'][$char]) { $repl[] = $this->subArrMB['a'][$char]; }
  24986. else { break; }
  24987. }
  24988. }
  24989. else if (isset($this->subArrMB['z'][$u[0]])) {
  24990. $font = 'ttz'; $ftype = 'C';
  24991. foreach($u AS $char) {
  24992. if ($this->subArrMB['z'][$char]) { $repl[] = $this->subArrMB['z'][$char]; }
  24993. else { break; }
  24994. }
  24995. }
  24996. else if (isset($this->subArrMB['s'][$u[0]])) {
  24997. $font = 'tts'; $ftype = 'C';
  24998. foreach($u AS $char) {
  24999. if ($this->subArrMB['s'][$char]) { $repl[] = $this->subArrMB['s'][$char]; }
  25000. else { break; }
  25001. }
  25002. }
  25003. if ($ftype=='C') {
  25004. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25005. //$patt = mb_substr($writehtml_e, $start, count($repl));
  25006. $patt = api_substr($writehtml_e, $start, count($repl));
  25007. //
  25008. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  25009. $writehtml_e = $m[1];
  25010. array_splice($writehtml_a, $writehtml_i+1, 0, array($font, implode('|', $repl), '/'.$font, $m[3])); // e.g. <tts>
  25011. $this->subPos = $writehtml_i+3;
  25012. return 4;
  25013. }
  25014. return 0;
  25015. }
  25016. // ELSE FIND IN DEFAULT FONT
  25017. if (strtolower($this->CurrentFont['name']) != $this->default_font) { $font = $this->default_font; }
  25018. else { unset($cw); return 0; }
  25019. if (isset($this->fonts[$font])) { $cw = &$this->fonts[$font]['cw']; }
  25020. else { @include(_MPDF_PATH.'unifont/'.$font.'.php'); }
  25021. if (!$cw) { return 0; }
  25022. $l = 0;
  25023. foreach($u AS $char) {
  25024. if ($char == 173 || isset($cw[$char]) || (isset($this->chrs[$char]) && isset($cw[$this->chrs[$char]])) ||
  25025. ($char>1422 && $char<3584) || $char > 11262) {
  25026. $l++;
  25027. }
  25028. else { break; }
  25029. }
  25030. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25031. //$patt = mb_substr($writehtml_e, $start, $l);
  25032. $patt = api_substr($writehtml_e, $start, $l);
  25033. //
  25034. if (preg_match("/(.*?)(".preg_quote($patt,'/').")(.*)/u", $writehtml_e, $m)) {
  25035. $writehtml_e = $m[1];
  25036. array_splice($writehtml_a, $writehtml_i+1, 0, array('span style="font-family: '.$font.'"', $m[2], '/span', $m[3]));
  25037. $this->subPos = $writehtml_i+3;
  25038. return 4;
  25039. }
  25040. return 0;
  25041. }
  25042. /*-- END UNICODE-FONTS --*/
  25043. function setHiEntitySubstitutions() {
  25044. $entarr = array (
  25045. 'nbsp' => '160', 'iexcl' => '161', 'cent' => '162', 'pound' => '163', 'curren' => '164', 'yen' => '165', 'brvbar' => '166', 'sect' => '167',
  25046. 'uml' => '168', 'copy' => '169', 'ordf' => '170', 'laquo' => '171', 'not' => '172', 'shy' => '173', 'reg' => '174', 'macr' => '175',
  25047. 'deg' => '176', 'plusmn' => '177', 'sup2' => '178', 'sup3' => '179', 'acute' => '180', 'micro' => '181', 'para' => '182', 'middot' => '183',
  25048. 'cedil' => '184', 'sup1' => '185', 'ordm' => '186', 'raquo' => '187', 'frac14' => '188', 'frac12' => '189', 'frac34' => '190',
  25049. 'iquest' => '191', 'Agrave' => '192', 'Aacute' => '193', 'Acirc' => '194', 'Atilde' => '195', 'Auml' => '196', 'Aring' => '197',
  25050. 'AElig' => '198', 'Ccedil' => '199', 'Egrave' => '200', 'Eacute' => '201', 'Ecirc' => '202', 'Euml' => '203', 'Igrave' => '204',
  25051. 'Iacute' => '205', 'Icirc' => '206', 'Iuml' => '207', 'ETH' => '208', 'Ntilde' => '209', 'Ograve' => '210', 'Oacute' => '211',
  25052. 'Ocirc' => '212', 'Otilde' => '213', 'Ouml' => '214', 'times' => '215', 'Oslash' => '216', 'Ugrave' => '217', 'Uacute' => '218',
  25053. 'Ucirc' => '219', 'Uuml' => '220', 'Yacute' => '221', 'THORN' => '222', 'szlig' => '223', 'agrave' => '224', 'aacute' => '225',
  25054. 'acirc' => '226', 'atilde' => '227', 'auml' => '228', 'aring' => '229', 'aelig' => '230', 'ccedil' => '231', 'egrave' => '232',
  25055. 'eacute' => '233', 'ecirc' => '234', 'euml' => '235', 'igrave' => '236', 'iacute' => '237', 'icirc' => '238', 'iuml' => '239',
  25056. 'eth' => '240', 'ntilde' => '241', 'ograve' => '242', 'oacute' => '243', 'ocirc' => '244', 'otilde' => '245', 'ouml' => '246',
  25057. 'divide' => '247', 'oslash' => '248', 'ugrave' => '249', 'uacute' => '250', 'ucirc' => '251', 'uuml' => '252', 'yacute' => '253',
  25058. 'thorn' => '254', 'yuml' => '255', 'OElig' => '338', 'oelig' => '339', 'Scaron' => '352', 'scaron' => '353', 'Yuml' => '376',
  25059. 'fnof' => '402', 'circ' => '710', 'tilde' => '732', 'Alpha' => '913', 'Beta' => '914', 'Gamma' => '915', 'Delta' => '916',
  25060. 'Epsilon' => '917', 'Zeta' => '918', 'Eta' => '919', 'Theta' => '920', 'Iota' => '921', 'Kappa' => '922', 'Lambda' => '923',
  25061. 'Mu' => '924', 'Nu' => '925', 'Xi' => '926', 'Omicron' => '927', 'Pi' => '928', 'Rho' => '929', 'Sigma' => '931', 'Tau' => '932',
  25062. 'Upsilon' => '933', 'Phi' => '934', 'Chi' => '935', 'Psi' => '936', 'Omega' => '937', 'alpha' => '945', 'beta' => '946', 'gamma' => '947',
  25063. 'delta' => '948', 'epsilon' => '949', 'zeta' => '950', 'eta' => '951', 'theta' => '952', 'iota' => '953', 'kappa' => '954',
  25064. 'lambda' => '955', 'mu' => '956', 'nu' => '957', 'xi' => '958', 'omicron' => '959', 'pi' => '960', 'rho' => '961', 'sigmaf' => '962',
  25065. 'sigma' => '963', 'tau' => '964', 'upsilon' => '965', 'phi' => '966', 'chi' => '967', 'psi' => '968', 'omega' => '969',
  25066. 'thetasym' => '977', 'upsih' => '978', 'piv' => '982', 'ensp' => '8194', 'emsp' => '8195', 'thinsp' => '8201', 'zwnj' => '8204',
  25067. 'zwj' => '8205', 'lrm' => '8206', 'rlm' => '8207', 'ndash' => '8211', 'mdash' => '8212', 'lsquo' => '8216', 'rsquo' => '8217',
  25068. 'sbquo' => '8218', 'ldquo' => '8220', 'rdquo' => '8221', 'bdquo' => '8222', 'dagger' => '8224', 'Dagger' => '8225', 'bull' => '8226',
  25069. 'hellip' => '8230', 'permil' => '8240', 'prime' => '8242', 'Prime' => '8243', 'lsaquo' => '8249', 'rsaquo' => '8250', 'oline' => '8254',
  25070. 'frasl' => '8260', 'euro' => '8364', 'image' => '8465', 'weierp' => '8472', 'real' => '8476', 'trade' => '8482', 'alefsym' => '8501',
  25071. 'larr' => '8592', 'uarr' => '8593', 'rarr' => '8594', 'darr' => '8595', 'harr' => '8596', 'crarr' => '8629', 'lArr' => '8656',
  25072. 'uArr' => '8657', 'rArr' => '8658', 'dArr' => '8659', 'hArr' => '8660', 'forall' => '8704', 'part' => '8706', 'exist' => '8707',
  25073. 'empty' => '8709', 'nabla' => '8711', 'isin' => '8712', 'notin' => '8713', 'ni' => '8715', 'prod' => '8719', 'sum' => '8721',
  25074. 'minus' => '8722', 'lowast' => '8727', 'radic' => '8730', 'prop' => '8733', 'infin' => '8734', 'ang' => '8736', 'and' => '8743',
  25075. 'or' => '8744', 'cap' => '8745', 'cup' => '8746', 'int' => '8747', 'there4' => '8756', 'sim' => '8764', 'cong' => '8773',
  25076. 'asymp' => '8776', 'ne' => '8800', 'equiv' => '8801', 'le' => '8804', 'ge' => '8805', 'sub' => '8834', 'sup' => '8835', 'nsub' => '8836',
  25077. 'sube' => '8838', 'supe' => '8839', 'oplus' => '8853', 'otimes' => '8855', 'perp' => '8869', 'sdot' => '8901', 'lceil' => '8968',
  25078. 'rceil' => '8969', 'lfloor' => '8970', 'rfloor' => '8971', 'lang' => '9001', 'rang' => '9002', 'loz' => '9674', 'spades' => '9824',
  25079. 'clubs' => '9827', 'hearts' => '9829', 'diams' => '9830',
  25080. );
  25081. foreach($entarr AS $key => $val) {
  25082. $this->entsearch[] = '&'.$key.';';
  25083. $this->entsubstitute[] = code2utf($val);
  25084. }
  25085. }
  25086. function SubstituteHiEntities($html) {
  25087. // converts html_entities > ASCII 127 to unicode (defined in includes/pdf/config.php
  25088. // Leaves in particular &lt; to distinguish from tag marker
  25089. if (count($this->entsearch)) {
  25090. $html = str_replace($this->entsearch,$this->entsubstitute,$html);
  25091. }
  25092. return $html;
  25093. }
  25094. // Edited v1.2 Pass by reference; option to continue if invalid UTF-8 chars
  25095. function is_utf8(&$string) {
  25096. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25097. //if ($string === mb_convert_encoding(mb_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32")) {
  25098. if ($string === api_convert_encoding(api_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32")) {
  25099. //
  25100. return true;
  25101. }
  25102. else {
  25103. if ($this->ignore_invalid_utf8) {
  25104. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25105. //$string = mb_convert_encoding(mb_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32") ;
  25106. $string = api_convert_encoding(api_convert_encoding($string, "UTF-32", "UTF-8"), "UTF-8", "UTF-32") ;
  25107. //
  25108. return true;
  25109. }
  25110. else {
  25111. return false;
  25112. }
  25113. }
  25114. }
  25115. function purify_utf8($html,$lo=true) {
  25116. // For HTML
  25117. // Checks string is valid UTF-8 encoded
  25118. // converts html_entities > ASCII 127 to UTF-8
  25119. // Only exception - leaves low ASCII entities e.g. &lt; &amp; etc.
  25120. // Leaves in particular &lt; to distinguish from tag marker
  25121. if (!$this->is_utf8($html)) { $this->Error("HTML contains invalid UTF-8 character(s)"); }
  25122. $html = preg_replace("/\r/", "", $html );
  25123. // converts html_entities > ASCII 127 to UTF-8
  25124. // Leaves in particular &lt; to distinguish from tag marker
  25125. $html = $this->SubstituteHiEntities($html);
  25126. // converts all &#nnn; or &#xHHH; to UTF-8 multibyte
  25127. // If $lo==true then includes ASCII < 128
  25128. $html = strcode2utf($html,$lo);
  25129. /*-- CJK --*/
  25130. // NON-BREAKING SPACE - convert to space as doesn't exist in CJK codepages (except japanese SJIS)
  25131. if ($this->isCJK) {
  25132. $html = preg_replace("/\xc2\xa0/"," ",$html); // non-breaking space
  25133. }
  25134. /*-- END CJK --*/
  25135. return ($html);
  25136. }
  25137. function purify_utf8_text($txt) {
  25138. // For TEXT
  25139. // Make sure UTF-8 string of characters
  25140. if (!$this->is_utf8($txt)) { $this->Error("Text contains invalid UTF-8 character(s)"); }
  25141. $txt = preg_replace("/\r/", "", $txt );
  25142. /*-- CJK --*/
  25143. // NON-BREAKING SPACE - convert to space as doesn't exist in CJK codepages
  25144. if ($this->isCJK) {
  25145. $txt = preg_replace("/\xc2\xa0/"," ",$txt); // non-breaking space
  25146. }
  25147. /*-- END CJK --*/
  25148. return ($txt);
  25149. }
  25150. function all_entities_to_utf8($txt) {
  25151. // converts txt_entities > ASCII 127 to UTF-8
  25152. // Leaves in particular &lt; to distinguish from tag marker
  25153. $txt = $this->SubstituteHiEntities($txt);
  25154. // converts all &#nnn; or &#xHHH; to UTF-8 multibyte
  25155. $txt = strcode2utf($txt);
  25156. $txt = $this->lesser_entity_decode($txt);
  25157. return ($txt);
  25158. }
  25159. // ====================================================
  25160. /*-- BARCODES --*/
  25161. // UPC/EAN barcode
  25162. // EAN13, EAN8, UPCA, UPCE, ISBN, ISSN
  25163. // Accepts 12 or 13 digits with or without - hyphens
  25164. 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) {
  25165. if (empty($code)) {
  25166. return;
  25167. }
  25168. $codestr = $code;
  25169. $code = preg_replace('/\-/','',$code);
  25170. if (!class_exists('PDFBarcode')) {
  25171. include(_MPDF_PATH.'classes/barcode.php');
  25172. $this->barcode = new PDFBarcode();
  25173. }
  25174. if ($btype == 'ISSN' || $btype == 'ISBN') {
  25175. $arrcode = $this->barcode->getBarcodeArray($code, 'EAN13');
  25176. }
  25177. else { $arrcode = $this->barcode->getBarcodeArray($code, $btype); }
  25178. if ($arrcode === false) { $this->Error('Error in barcode string: '.$codestr); }
  25179. if((($btype=='EAN13' || $btype=='ISBN' || $btype=='ISSN') && strlen($code) == 12) || ($btype=='UPCA' && strlen($code) == 11)
  25180. || ($btype=='UPCE' && strlen($code) == 11) || ($btype=='EAN8' && strlen($code) == 7)) {
  25181. $code .= $arrcode['checkdigit'];
  25182. if (stristr($codestr,'-')) { $codestr .= '-' . $arrcode['checkdigit']; }
  25183. else { $codestr .= $arrcode['checkdigit']; }
  25184. }
  25185. if ($btype == 'ISBN') { $codestr = 'ISBN '.$codestr; }
  25186. if ($btype == 'ISSN') { $codestr = 'ISSN '.$codestr; }
  25187. if (empty($x)) {
  25188. $x = $this->GetX();
  25189. }
  25190. if (empty($y)) {
  25191. $y = $this->GetY();
  25192. }
  25193. // set foreground color
  25194. $prevDrawColor = $this->DrawColor;
  25195. $prevTextColor = $this->TextColor;
  25196. $prevFillColor = $this->FillColor;
  25197. $lw = $this->LineWidth;
  25198. $this->SetLineWidth(0.01);
  25199. $size /= $k; // in case resized in a table
  25200. $xres = $arrcode['nom-X'] * $size;
  25201. $llm = $arrcode['lightmL'] * $arrcode['nom-X'] * $size; // Left Light margin
  25202. $rlm = $arrcode['lightmR'] * $arrcode['nom-X'] * $size; // Right Light margin
  25203. $bcw = ($arrcode["maxw"] * $xres); // Barcode width = Should always be 31.35mm * $size
  25204. $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
  25205. $ow = $fbw + $paddingL + $paddingR; // Full overall width incl. user-defined padding
  25206. $fbwi = $fbw - 2; // Full barcode width incl. light margins - 2mm - for isbn string
  25207. // cf. http://www.gs1uk.org/downloads/bar_code/Bar coding getting it right.pdf
  25208. $num_height = 3 * $size; // Height of numerals
  25209. $fbh = $arrcode['nom-H'] * $size * $height; // Full barcode height incl. numerals
  25210. $bch = $fbh - (1.5 * $size); // Barcode height of bars (3mm for numerals)
  25211. if (($btype=='EAN13' && $showtext) || $btype == 'ISSN' || $btype == 'ISBN') { // Add height for ISBN string + margin from top of bars
  25212. $tisbnm = 1.5 * $size; // Top margin between isbn (if shown) & bars
  25213. $codestr_fontsize = 2.1 * $size;
  25214. $paddingT += $codestr_fontsize + $tisbnm ;
  25215. }
  25216. $oh = $fbh + $paddingT + $paddingB; // Full overall height incl. user-defined padding
  25217. // PRINT border background color
  25218. $xpos = $x;
  25219. $ypos = $y;
  25220. if (is_array($col)) { // from <barcode />
  25221. $this->SetDrawColor($col['R'],$col['G'],$col['B']);
  25222. $this->SetTextColor($col['R'],$col['G'],$col['B']);
  25223. }
  25224. else {
  25225. $this->SetDrawColor(0);
  25226. $this->SetTextColor(0);
  25227. }
  25228. if (is_array($bgcol)) { // from <barcode />
  25229. $this->SetFillColor($bgcol['R'],$bgcol['G'],$bgcol['B']);
  25230. }
  25231. else { $this->SetFillColor(255); }
  25232. if (!$bgcol && !$col) { // fn. called directly - not via HTML
  25233. if ($border) { $fillb = 'DF'; } else { $fillb = 'F'; }
  25234. $this->Rect($xpos, $ypos, $ow, $oh, $fillb);
  25235. }
  25236. // PRINT BARS
  25237. $xpos = $x + $paddingL + $llm ;
  25238. $ypos = $y + $paddingT;
  25239. if (is_array($col)) { $this->SetFillColor($col['R'],$col['G'],$col['B']); }
  25240. else { $this->SetFillColor(0); }
  25241. if ($arrcode !== false) {
  25242. foreach ($arrcode["bcode"] AS $v) {
  25243. $bw = ($v["w"] * $xres);
  25244. if ($v["t"]) {
  25245. // draw a vertical bar
  25246. $this->Rect($xpos, $ypos, $bw, $bch, 'F');
  25247. }
  25248. $xpos += $bw;
  25249. }
  25250. }
  25251. // print text
  25252. $prevFontFamily = $this->FontFamily;
  25253. $prevFontStyle = $this->FontStyle;
  25254. $prevFontSizePt = $this->FontSizePt;
  25255. // ISBN string
  25256. if (($btype=='EAN13' && $showtext) || $btype=='ISBN' || $btype=='ISSN') {
  25257. // mPDF 4.2.018
  25258. if ($this->PDFA) {
  25259. if (!$this->PDFAauto) { $this->PDFAwarnings[] = "Core Adobe font Helvetica cannot be embedded in mPDF - used in barcode - which is required for PDFA1-b. (Embedded font will be substituted.)"; }
  25260. $this->SetFont('sans');
  25261. }
  25262. else {
  25263. $this->SetFont('helvetica');
  25264. }
  25265. // mPDF 4.0
  25266. if (is_array($bgcol)) { $this->SetFillColor($bgcol['R'],$bgcol['G'],$bgcol['B']); }
  25267. else { $this->SetFillColor(255); }
  25268. $this->x = $x + $paddingL + 1; // 1mm left margin (cf. $fbwi above)
  25269. // max width is $fbwi
  25270. $loop = 0;
  25271. while ( $loop == 0 ) {
  25272. $this->SetFontSize($codestr_fontsize*1.4*$this->k, false); // don't write
  25273. $sz = $this->GetStringWidth( $codestr );
  25274. if ($sz > $fbwi)
  25275. $codestr_fontsize -= 0.1;
  25276. else
  25277. $loop ++;
  25278. }
  25279. $this->SetFont('','',$codestr_fontsize*1.4*$this->k, true, true); // * 1.4 because font height is only 7/10 of given mm
  25280. // WORD SPACING
  25281. if ($fbwi > $sz) {
  25282. $xtra = $fbwi - $sz;
  25283. $charspacing = $xtra / (strlen($codestr)-1);
  25284. if ($charspacing) { $this->_out(sprintf('BT %.3f Tc ET',$charspacing*$this->k)); }
  25285. }
  25286. $this->y = $y + $paddingT - ($codestr_fontsize ) - $tisbnm ;
  25287. $this->Cell($fbw , $codestr_fontsize, $codestr);
  25288. if ($charspacing) { $this->_out('BT 0 Tc ET'); }
  25289. }
  25290. // Bottom NUMERALS
  25291. /*-- UNICODE-FONTS --*/
  25292. if ($this->is_MB) {
  25293. if (in_array('ocrb',$this->available_unifonts)) { $this->SetFont('ocrb'); }
  25294. else { $this->SetFont('mono'); }
  25295. }
  25296. else {
  25297. /*-- END UNICODE-FONTS --*/
  25298. if (in_array('ocrb',$this->available_fonts)) { $this->SetFont('ocrb'); }
  25299. else { $this->SetFont('mono'); }
  25300. } // *UNICODE-FONTS*
  25301. if (isset($this->CurrentFont['desc']['Ascent']) && $this->CurrentFont['desc']['Ascent']) { $fh = 1000/$this->CurrentFont['desc']['Ascent']; }
  25302. else { $fh = 1.4; }
  25303. $charRO = '';
  25304. if ($btype=='EAN13' || $btype=='ISBN' || $btype=='ISSN') {
  25305. $outerfontsize = 3; // Inner fontsize = 3
  25306. $outerp = $xres * 4;
  25307. $innerp = $xres * 2.5;
  25308. $textw = ($bcw*0.5) - $outerp - $innerp;
  25309. $chars = 6; // number of numerals in each half
  25310. $charLO = substr($code,0,1); // Left Outer
  25311. $charLI = substr($code,1,6); // Left Inner
  25312. $charRI = substr($code,7,6); // Right Inner
  25313. if (!$supplement) $charRO = '>'; // Right Outer
  25314. }
  25315. else if ($btype=='UPCA') {
  25316. $outerfontsize = 2.3; // Inner fontsize = 3
  25317. $outerp = $xres * 10;
  25318. $innerp = $xres * 2.5;
  25319. $textw = ($bcw*0.5) - $outerp - $innerp;
  25320. $chars = 5;
  25321. $charLO = substr($code,0,1); // Left Outer
  25322. $charLI = substr($code,1,5); // Left Inner
  25323. $charRI = substr($code,6,5); // Right Inner
  25324. $charRO = substr($code,11,1); // Right Outer
  25325. }
  25326. else if ($btype=='UPCE') {
  25327. $outerfontsize = 2.3; // Inner fontsize = 3
  25328. $outerp = $xres * 4;
  25329. $innerp = 0;
  25330. $textw = ($bcw*0.5) - $outerp - $innerp;
  25331. $chars = 3;
  25332. $upce_code = $arrcode['code'];
  25333. $charLO = substr($code,0,1); // Left Outer
  25334. $charLI = substr($upce_code,0,3); // Left Inner
  25335. $charRI = substr($upce_code,3,3); // Right Inner
  25336. $charRO = substr($code,11,1); // Right Outer
  25337. }
  25338. else if ($btype=='EAN8') {
  25339. $outerfontsize = 3; // Inner fontsize = 3
  25340. $outerp = $xres * 4;
  25341. $innerp = $xres * 2.5;
  25342. $textw = ($bcw*0.5) - $outerp - $innerp;
  25343. $chars = 4;
  25344. $charLO = '<'; // Left Outer
  25345. $charLI = substr($code,0,4); // Left Inner
  25346. $charRI = substr($code,4,4); // Right Inner
  25347. if (!$supplement) $charRO = '>'; // Right Outer
  25348. }
  25349. $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*$this->k); // 3mm numerals (FontSize is larger to account for space above/below characters)
  25350. if ($this->is_MB) { $cw = $this->CurrentFont['cw'][32]*3*$fh*$size/1000; } // character width at 3mm
  25351. else { $cw = $this->CurrentFont['cw']['0']*$this->FontSize/1000; } //
  25352. // Outer left character
  25353. $y_text = $y + $paddingT + $bch - ($num_height/2);
  25354. $y_text_outer = $y + $paddingT + $bch - ($num_height*($outerfontsize/3)/2);
  25355. $this->x = $x + $paddingL - ($cw*($outerfontsize/3)*0.1); // 0.1 is correction as char does not fill full width;
  25356. $this->y = $y_text_outer;
  25357. $this->Cell($cw, $num_height, $charLO );
  25358. // WORD SPACING for inner chars
  25359. $xtra = $textw - ($cw*$chars);
  25360. $charspacing = $xtra / ($chars-1);
  25361. if ($charspacing) { $this->_out(sprintf('BT %.3f Tc ET',$charspacing*$this->k)); }
  25362. if (is_array($bgcol)) { $this->SetFillColor($bgcol['R'],$bgcol['G'],$bgcol['B']); }
  25363. else { $this->SetFillColor(255); }
  25364. $this->SetFontSize(3*$fh*$size*$this->k); // 3mm numerals (FontSize is larger to account for space above/below characters)
  25365. // Inner left half characters
  25366. $this->x = $x + $paddingL + $llm + $outerp;
  25367. $this->y = $y_text;
  25368. $this->Cell($textw, $num_height, $charLI , 0, 0, '', 1);
  25369. // Inner right half characters
  25370. $this->x = $x + $paddingL + $llm + ($bcw*0.5) + $innerp;
  25371. $this->y = $y_text;
  25372. $this->Cell($textw, $num_height, $charRI , 0, 0, '', 1);
  25373. if ($charspacing) { $this->_out('BT 0 Tc ET'); }
  25374. // Outer Right character
  25375. $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*$this->k); // 3mm numerals (FontSize is larger to account for space above/below characters)
  25376. $this->x = $x + $paddingL + $llm + $bcw + $rlm - ($cw*($outerfontsize/3)*0.9); // 0.9 is correction as char does not fill full width
  25377. $this->y = $y_text_outer;
  25378. $this->Cell($cw*($outerfontsize/3), $num_height, $charRO , 0, 0, 'R');
  25379. if ($supplement) { // EAN-2 or -5 Supplement
  25380. // PRINT BARS
  25381. $supparrcode = $this->barcode->getBarcodeArray($supplement_code, 'EAN'.$supplement);
  25382. if ($supparrcode === false) { $this->Error('Error in barcode string (supplement): '.$codestr.' '.$supplement_code); }
  25383. if(strlen($supplement_code) != $supplement) {
  25384. $this->Error('Barcode supplement incorrect: '.$supplement_code);
  25385. }
  25386. $llm = $fbw - (($arrcode['lightmR'] - $supparrcode['sepM']) * $arrcode['nom-X'] * $size); // Left Light margin
  25387. $rlm = $arrcode['lightmR'] * $arrcode['nom-X'] * $size; // Right Light margin
  25388. $bcw = ($supparrcode["maxw"] * $xres); // Barcode width = Should always be 31.35mm * $size
  25389. $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
  25390. $ow = $fbw + $paddingL + $paddingR; // Full overall width incl. user-defined padding
  25391. $bch = $fbh - (1.5 * $size) - ($num_height + 0.5); // Barcode height of bars (3mm for numerals)
  25392. $xpos = $x + $paddingL + $llm ;
  25393. $ypos = $y + $paddingT + $num_height + 0.5;
  25394. if (is_array($col)) { $this->SetFillColor($col['R'],$col['G'],$col['B']); }
  25395. else { $this->SetFillColor(0); }
  25396. if ($supparrcode !== false) {
  25397. foreach ($supparrcode["bcode"] AS $v) {
  25398. $bw = ($v["w"] * $xres);
  25399. if ($v["t"]) {
  25400. // draw a vertical bar
  25401. $this->Rect($xpos, $ypos, $bw, $bch, 'F');
  25402. }
  25403. $xpos += $bw;
  25404. }
  25405. }
  25406. // Characters
  25407. if (is_array($bgcol)) { $this->SetFillColor($bgcol['R'],$bgcol['G'],$bgcol['B']); }
  25408. else { $this->SetFillColor(255); }
  25409. $this->SetFontSize(3*$fh*$size*$this->k); // 3mm numerals (FontSize is larger to account for space above/below characters)
  25410. $this->x = $x + $paddingL + $llm;
  25411. $this->y = $y + $paddingT;
  25412. $this->Cell($bcw, $num_height, $supplement_code, 0, 0, 'C');
  25413. // Outer Right character (light margin)
  25414. $this->SetFontSize(($outerfontsize/3)*3*$fh*$size*$this->k); // 3mm numerals (FontSize is larger to account for space above/below characters)
  25415. $this->x = $x + $paddingL + $llm + $bcw + $rlm - ($cw*0.9); // 0.9 is correction as char does not fill full width
  25416. $this->y = $y + $paddingT;
  25417. $this->Cell($cw*($outerfontsize/3), $num_height, '>', 0, 0, 'R');
  25418. }
  25419. // Restore **************
  25420. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt);
  25421. $this->DrawColor = $prevDrawColor;
  25422. $this->TextColor = $prevTextColor;
  25423. $this->FillColor = $prevFillColor;
  25424. $this->SetLineWidth($lw);
  25425. $this->SetY($y);
  25426. }
  25427. // ====================================================
  25428. // POSTAL and OTHER barcodes
  25429. function WriteBarcode2($code, $x='', $y='', $size=1, $height=1, $bgcol=false, $col=false, $btype='IMB', $print_ratio='', $k=1) {
  25430. if (empty($code)) { return; }
  25431. if (!class_exists('PDFBarcode')) {
  25432. include(_MPDF_PATH.'classes/barcode.php');
  25433. $this->barcode = new PDFBarcode();
  25434. }
  25435. $arrcode = $this->barcode->getBarcodeArray($code, $btype, $print_ratio);
  25436. if ($arrcode === false) { $this->Error('Error in barcode string: '.$code); }
  25437. if (empty($x)) { $x = $this->GetX(); }
  25438. if (empty($y)) { $y = $this->GetY(); }
  25439. $prevDrawColor = $this->DrawColor;
  25440. $prevTextColor = $this->TextColor;
  25441. $prevFillColor = $this->FillColor;
  25442. $lw = $this->LineWidth;
  25443. $this->SetLineWidth(0.01);
  25444. $size /= $k; // in case resized in a table
  25445. $xres = $arrcode['nom-X'] * $size;
  25446. if ($btype == 'IMB' || $btype == 'RM4SCC' || $btype == 'KIX' || $btype == 'POSTNET' || $btype == 'PLANET') {
  25447. $llm = $arrcode['quietL'] / $k; // Left Quiet margin
  25448. $rlm = $arrcode['quietR'] / $k; // Right Quiet margin
  25449. $tlm = $blm = $arrcode['quietTB'] / $k;
  25450. $height=1; // Overrides
  25451. }
  25452. 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'))) {
  25453. $llm = $arrcode['lightmL'] * $xres; // Left Quiet margin
  25454. $rlm = $arrcode['lightmR'] * $xres; // Right Quiet margin
  25455. $tlm = $blm = $arrcode['lightTB'] * $xres * $height;
  25456. }
  25457. $bcw = ($arrcode["maxw"] * $xres);
  25458. $fbw = $bcw + $llm + $rlm; // Full barcode width incl. light margins
  25459. $bch = ($arrcode["nom-H"] * $size * $height);
  25460. $fbh = $bch + $tlm + $blm; // Full barcode height
  25461. // PRINT border background color
  25462. $xpos = $x;
  25463. $ypos = $y;
  25464. if (is_array($col)) { // from <barcode />
  25465. $this->SetDrawColor($col['R'],$col['G'],$col['B']);
  25466. $this->SetTextColor($col['R'],$col['G'],$col['B']);
  25467. }
  25468. else {
  25469. $this->SetDrawColor(0);
  25470. $this->SetTextColor(0);
  25471. }
  25472. if (is_array($bgcol)) { // from <barcode />
  25473. $this->SetFillColor($bgcol['R'],$bgcol['G'],$bgcol['B']);
  25474. }
  25475. else { $this->SetFillColor(255); }
  25476. // PRINT BARS
  25477. if (is_array($col)) { $this->SetFillColor($col['R'],$col['G'],$col['B']); }
  25478. else { $this->SetFillColor(0); }
  25479. $xpos = $x + $llm ;
  25480. if ($arrcode !== false) {
  25481. foreach ($arrcode["bcode"] AS $v) {
  25482. $bw = ($v["w"] * $xres);
  25483. if ($v["t"]) {
  25484. $ypos = $y + $tlm + ($bch * $v['p'] / $arrcode['maxh']);
  25485. $this->Rect($xpos, $ypos, $bw, ($v['h'] * $bch / $arrcode['maxh']), 'F');
  25486. }
  25487. $xpos += $bw;
  25488. }
  25489. }
  25490. // PRINT BEARER BARS
  25491. if ($btype == 'I25B' || $btype == 'I25B+') {
  25492. $this->Rect($x, $y, $fbw, ($arrcode['lightTB'] * $xres * $height), 'F');
  25493. $this->Rect($x, $y+$tlm+$bch, $fbw, ($arrcode['lightTB'] * $xres * $height), 'F');
  25494. }
  25495. // Restore **************
  25496. $this->SetFont($prevFontFamily, $prevFontStyle, $prevFontSizePt);
  25497. $this->DrawColor = $prevDrawColor;
  25498. $this->TextColor = $prevTextColor;
  25499. $this->FillColor = $prevFillColor;
  25500. $this->SetLineWidth($lw);
  25501. $this->SetY($y);
  25502. }
  25503. /*-- END BARCODES --*/
  25504. // ====================================================
  25505. // ====================================================
  25506. // START TRANSFORMATIONS SECTION -----------------------
  25507. // authors: Moritz Wagner, Andreas Wurmser, Nicola Asuni
  25508. // From TCPDF
  25509. // Starts a 2D tranformation saving current graphic state.
  25510. function StartTransform($returnstring=false) {
  25511. if ($returnstring) { return('q'); }
  25512. else { $this->_out('q'); }
  25513. }
  25514. function StopTransform($returnstring=false) {
  25515. if ($returnstring) { return('Q'); }
  25516. else { $this->_out('Q'); }
  25517. }
  25518. // Vertical and horizontal non-proportional Scaling.
  25519. function transformScale($s_x, $s_y, $x='', $y='', $returnstring=false) {
  25520. if ($x === '') {
  25521. $x=$this->x;
  25522. }
  25523. if ($y === '') {
  25524. $y=$this->y;
  25525. }
  25526. if (($s_x == 0) OR ($s_y == 0)) {
  25527. $this->Error('Please do not use values equal to zero for scaling');
  25528. }
  25529. $y = ($this->h - $y) * $this->k;
  25530. $x *= $this->k;
  25531. //calculate elements of transformation matrix
  25532. $s_x /= 100;
  25533. $s_y /= 100;
  25534. $tm[0] = $s_x;
  25535. $tm[1] = 0;
  25536. $tm[2] = 0;
  25537. $tm[3] = $s_y;
  25538. $tm[4] = $x * (1 - $s_x);
  25539. $tm[5] = $y * (1 - $s_y);
  25540. //scale the coordinate system
  25541. if ($returnstring) { return($this->_transform($tm, true)); }
  25542. else { $this->_transform($tm); }
  25543. }
  25544. // Translate graphic object horizontally and vertically.
  25545. function transformTranslate($t_x, $t_y, $returnstring=false) {
  25546. //calculate elements of transformation matrix
  25547. $tm[0] = 1;
  25548. $tm[1] = 0;
  25549. $tm[2] = 0;
  25550. $tm[3] = 1;
  25551. $tm[4] = $t_x * $this->k;
  25552. $tm[5] = -$t_y * $this->k;
  25553. //translate the coordinate system
  25554. if ($returnstring) { return($this->_transform($tm, true)); }
  25555. else { $this->_transform($tm); }
  25556. }
  25557. // Rotate object.
  25558. function transformRotate($angle, $x='', $y='', $returnstring=false) {
  25559. if ($x === '') {
  25560. $x=$this->x;
  25561. }
  25562. if ($y === '') {
  25563. $y=$this->y;
  25564. }
  25565. $angle = -$angle;
  25566. $y = ($this->h - $y) * $this->k;
  25567. $x *= $this->k;
  25568. //calculate elements of transformation matrix
  25569. $tm[0] = cos(deg2rad($angle));
  25570. $tm[1] = sin(deg2rad($angle));
  25571. $tm[2] = -$tm[1];
  25572. $tm[3] = $tm[0];
  25573. $tm[4] = $x + $tm[1] * $y - $tm[0] * $x;
  25574. $tm[5] = $y - $tm[0] * $y - $tm[1] * $x;
  25575. //rotate the coordinate system around ($x,$y)
  25576. if ($returnstring) { return($this->_transform($tm, true)); }
  25577. else { $this->_transform($tm); }
  25578. }
  25579. function _transform($tm, $returnstring=false) {
  25580. if ($returnstring) { return(sprintf('%.3f %.3f %.3f %.3f %.3f %.3f cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); }
  25581. else { $this->_out(sprintf('%.3f %.3f %.3f %.3f %.3f %.3f cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); }
  25582. }
  25583. // END TRANSFORMATIONS SECTION -------------------------
  25584. /*-- INDIC --*/
  25585. // INDIC ============================
  25586. // mPDF 4.0 Font-specific ligature substitution for Indic fonts
  25587. // This conversion can only be done when font is set
  25588. function ConvertIndic(&$str) {
  25589. if (preg_match('/^ind_([a-z]{2})_/',strtolower($this->CurrentFont['name']), $m)) {
  25590. if (!class_exists('indic')) { include(_MPDF_PATH.'classes/indic.php'); }
  25591. if (empty($this->indic)) { $this->indic = new indic($this); }
  25592. $earr = $this->UTF8StringToArray($str);
  25593. $str = $this->indic->substituteIndic($earr, $m[1], strtolower($this->CurrentFont['name']), $this->useSubsets);
  25594. }
  25595. }
  25596. /*-- END INDIC --*/
  25597. // AUTOFONT =========================
  25598. function AutoFont($html) {
  25599. if ( !$this->is_MB ) { return $html; }
  25600. $this->useLang = true;
  25601. if ($this->autoFontGroupSize == 1) { $extra = $this->pregASCIIchars1; }
  25602. else if ($this->autoFontGroupSize == 3) { $extra = $this->pregASCIIchars3; }
  25603. else { $extra = $this->pregASCIIchars2; }
  25604. $n = '';
  25605. $a=preg_split('/<(.*?)>/ms',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
  25606. foreach($a as $i => $e) {
  25607. if($i%2==0) {
  25608. // mPDF 3.0
  25609. $e = strcode2utf($e);
  25610. $e = $this->lesser_entity_decode($e);
  25611. // mPDF 4.0 Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring
  25612. // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag##
  25613. /*-- CJK --*/
  25614. // CJK
  25615. if ($this->autoFontGroups & AUTOFONT_CJK) {
  25616. $e = preg_replace("/([".$this->pregCJKchars.$extra."]*[".$this->pregCJKchars."][".$this->pregCJKchars.$extra."]*)/ue", '$this->replaceCJK(stripslashes(\'\\1\'))', $e);
  25617. }
  25618. /*-- END CJK --*/
  25619. /*-- RTL --*/
  25620. if ($this->autoFontGroups & AUTOFONT_RTL) {
  25621. // HEBREW
  25622. $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);
  25623. // All Arabic
  25624. $e = preg_replace("/([".$this->pregARABICchars .$extra."]*[".$this->pregARABICchars ."][".$this->pregARABICchars .$extra."]*)/ue", '$this->replaceArabic(stripslashes(\'\\1\'))', $e);
  25625. }
  25626. /*-- END RTL --*/
  25627. /*-- INDIC --*/
  25628. // INDIC
  25629. if ($this->autoFontGroups & AUTOFONT_INDIC) {
  25630. // mPDF 4.0
  25631. // Bengali
  25632. $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);
  25633. // Devanagari (= script for Hindi, Nepali + Sindhi)
  25634. $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);
  25635. // Gujarati
  25636. $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);
  25637. // Malayalam
  25638. $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);
  25639. // Kannada
  25640. $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);
  25641. // Oriya
  25642. $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);
  25643. // Punjabi ?= Gurmuhki
  25644. $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);
  25645. // Tamil
  25646. $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);
  25647. // Telugu
  25648. $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);
  25649. }
  25650. /*-- END INDIC --*/
  25651. // mPDF 4.0 Moved so Vietnamese detection better
  25652. if ($this->autoFontGroups & AUTOFONT_THAIVIET) {
  25653. // THAI
  25654. $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);
  25655. // Vietnamese
  25656. $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);
  25657. }
  25658. // mPDF 3.0
  25659. $e = preg_replace('/[&]/','&amp;',$e); // mPDF 4.4.012
  25660. $e = preg_replace('/[<]/','&lt;',$e); // mPDF 4.4.012
  25661. $e = preg_replace('/[>]/','&gt;',$e); // mPDF 4.4.012
  25662. // mPDF 4.0
  25663. $e = preg_replace("/(\xef\xbf\xb0span lang=\"([a-z\-A-Z]{2,5})\"\xef\xbf\xb1)\s+/",' \\1',$e);
  25664. $e = preg_replace("/[ ]+(\xef\xbf\xb0\/span\xef\xbf\xb1)/",'\\1 ',$e); // mPDF 4.3.012C
  25665. $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);
  25666. $e = preg_replace("/\xef\xbf\xb0/",'<',$e);
  25667. $e = preg_replace("/\xef\xbf\xb1/",'>',$e);
  25668. $a[$i] = $e;
  25669. }
  25670. else {
  25671. $a[$i] = '<'.$e.'>';
  25672. }
  25673. }
  25674. $n = implode('',$a);
  25675. return $n;
  25676. }
  25677. /*-- CJK --*/
  25678. function replaceCJK($str) {
  25679. // mPDF 4.0 Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring
  25680. // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag##
  25681. if (preg_match("/[".$this->pregUHCchars."]/u", $str)) {
  25682. return "\xef\xbf\xb0span lang=\"ko\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  25683. }
  25684. else if (preg_match("/[".$this->pregSJISchars."]/u", $str)) {
  25685. return "\xef\xbf\xb0span lang=\"ja\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  25686. }
  25687. // mPDF 3.0 if in Unicode Plane 2, probably HKCS (incl in BIG5) if not Japanese
  25688. else if (preg_match("/[\x{20000}-\x{2AFFF}]/u", $str)) {
  25689. return "\xef\xbf\xb0span lang=\"zh-HK\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  25690. }
  25691. else{
  25692. return "\xef\xbf\xb0span lang=\"zh-CN\"\xef\xbf\xb1" . $str ."\xef\xbf\xb0/span\xef\xbf\xb1";
  25693. }
  25694. return $str;
  25695. }
  25696. /*-- END CJK --*/
  25697. /*-- RTL --*/
  25698. function replaceArabic($str) {
  25699. // mPDF 4.0 remove rtlAsArabicFarsi
  25700. // PASHTO, SINDHI, URDU, ARABIC, PERSIAN
  25701. $persian = "\x{067E}\x{0686}\x{0698}\x{06AF}";
  25702. $urdu = "\x{0679}\x{0688}\x{0691}\x{06BA}\x{06BE}\x{06C1}\x{06D2}";
  25703. $pashto = "\x{067C}\x{0681}\x{0685}\x{0689}\x{0693}\x{0696}\x{069A}\x{06BC}\x{06D0}";
  25704. $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}";
  25705. // mPDF 4.0 Use U=FFF0 and U+FFF1 to mark start and end of span tags to prevent nesting occurring
  25706. // "\xef\xbf\xb0" ##lthtmltag## "\xef\xbf\xb1" ##gthtmltag##
  25707. if (preg_match("/[".$this->pregNonARABICchars ."]/u", $str) ) {
  25708. if (preg_match("/[".$sindhi ."]/u", $str) ) {
  25709. return "\xef\xbf\xb0span lang=\"sd\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  25710. }
  25711. else if (preg_match("/[".$urdu ."]/u", $str) ) {
  25712. return "\xef\xbf\xb0span lang=\"ur\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  25713. }
  25714. else if (preg_match("/[".$pashto ."]/u", $str) ) {
  25715. return "\xef\xbf\xb0span lang=\"ps\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  25716. }
  25717. else if (preg_match("/[".$persian ."]/u", $str) ) {
  25718. return "\xef\xbf\xb0span lang=\"fa\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  25719. }
  25720. else {
  25721. return "\xef\xbf\xb0span lang=\"ar\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  25722. }
  25723. }
  25724. if (preg_match("/[".$persian ."]/u", $str) ) {
  25725. return "\xef\xbf\xb0span lang=\"fa\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  25726. }
  25727. else {
  25728. return "\xef\xbf\xb0span lang=\"ar\"\xef\xbf\xb1".$str."\xef\xbf\xb0/span\xef\xbf\xb1";
  25729. }
  25730. return $str;
  25731. }
  25732. // ARABIC ===========================
  25733. function InitArabic() {
  25734. // JOIN TO FOLLOWING LETTER IN LOGICAL ORDER
  25735. // 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;
  25736. // 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;
  25737. // U+06D0; U+0681; U+06C1;
  25738. $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";
  25739. // mPDF 4.0
  25740. // \xda\x98 (U+0698) removed from arabPrevLink
  25741. // \xd9\xb1 (U+0671) added to arabNextLink & final form added to Persian Glyphs (FB51)
  25742. // JOIN TO PREVIOUS LETTER IN LOGICAL ORDER
  25743. // 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;
  25744. // 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;
  25745. // U+0647; U+0648; U+0649; U+064a; U+06a9; U+06cc; U+0686; U+06af; U+0698; U+067e;
  25746. // U+0671; U+06D0; U+0696; U+0693; U+06D2; U+06C1;
  25747. $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";
  25748. // U+064b U+064c; U+064d; U+064e; U+064f; U+0650; U+0651; U+0652;
  25749. $this->arabVowels = "\xd9\x8b\xd9\x8c\xd9\x8d\xd9\x8e\xd9\x8f\xd9\x90\xd9\x91\xd9\x92";
  25750. // mPDF 4.0 Added chars that may not be vowels but should not interrupt joining
  25751. // U+0670; U+0653;
  25752. $this->arabVowels .= "\xd9\xb0\xd9\x93";
  25753. // ? should also add - U+615, 616, 617-61A, 653-65E, 6D6-6DC, 6DF-6E4, 6E7, 6E8, 6EA-6ED
  25754. // DON'T ADD ANY MORE TO ARABGLYPHS - cf. ArabJoin() counts 48 then does ligatures - use PersianGlyphs below
  25755. // ISOLATED FORM :: FINAL :: INITIAL :: MEDIAL
  25756. // U+064B; U+064C; U+064D; U+064E; U+064F; U+0650; U+0651; U+0652;
  25757. $this->arabGlyphs = "\xd9\x8b\xd9\x8c\xd9\x8d\xd9\x8e\xd9\x8f\xd9\x90\xd9\x91\xd9\x92";
  25758. $this->arabHex = '064B064B064B064B064C064C064C064C064D064D064D064D064E064E064E064E064F064F064F064F065006500650065006510651065106510652065206520652';
  25759. // U+0621; U+0622; U+0623; U+0624; U+0625; U+0626; U+0627; U+0628;
  25760. $this->arabGlyphs .= "\xd8\xa1\xd8\xa2\xd8\xa3\xd8\xa4\xd8\xa5\xd8\xa6\xd8\xa7\xd8\xa8";
  25761. $this->arabHex .= '06210621062106210622FE820622FE820623FE840623FE840624FE860624FE860625FE880625FE880626FE8AFE8BFE8C0627FE8E0627FE8E0628FE90FE91FE92';
  25762. // U+0629; U+062A; U+062B; U+062C; U+062D; U+062E; U+062F; U+0630;
  25763. $this->arabGlyphs .= "\xd8\xa9\xd8\xaa\xd8\xab\xd8\xac\xd8\xad\xd8\xae\xd8\xaf\xd8\xb0";
  25764. $this->arabHex .= '0629FE940629FE94062AFE96FE97FE98062BFE9AFE9BFE9C062CFE9EFE9FFEA0062DFEA2FEA3FEA4062EFEA6FEA7FEA8062FFEAA062FFEAA0630FEAC0630FEAC';
  25765. // U+0631; U+0632; U+0633; U+0634; U+0635; U+0636; U+0637; U+0638;
  25766. $this->arabGlyphs .= "\xd8\xb1\xd8\xb2\xd8\xb3\xd8\xb4\xd8\xb5\xd8\xb6\xd8\xb7\xd8\xb8";
  25767. $this->arabHex .= '0631FEAE0631FEAE0632FEB00632FEB00633FEB2FEB3FEB40634FEB6FEB7FEB80635FEBAFEBBFEBC0636FEBEFEBFFEC00637FEC2FEC3FEC40638FEC6FEC7FEC8';
  25768. // U+0639; U+063A; U+0641; U+0642; U+0643; U+0644; U+0645; U+0646;
  25769. $this->arabGlyphs .= "\xd8\xb9\xd8\xba\xd9\x81\xd9\x82\xd9\x83\xd9\x84\xd9\x85\xd9\x86";
  25770. $this->arabHex .= '0639FECAFECBFECC063AFECEFECFFED00641FED2FED3FED40642FED6FED7FED80643FEDAFEDBFEDC0644FEDEFEDFFEE00645FEE2FEE3FEE40646FEE6FEE7FEE8';
  25771. // U+0647; U+0648; U+0649; U+064A; U+0640; U+060C; U+061F; U+061B;
  25772. $this->arabGlyphs .= "\xd9\x87\xd9\x88\xd9\x89\xd9\x8a\xd9\x80\xd8\x8c\xd8\x9f\xd8\x9b";
  25773. // 0649 Initial or medial probably meant to be YEH (064A) so Initial and Medial forms of YEH given
  25774. $this->arabHex .= '0647FEEAFEEBFEEC0648FEEE0648FEEE0649FEF0FEF3FEF4064AFEF2FEF3FEF40640064006400640060C060C060C060C061F061F061F061F061B061B061B061B';
  25775. // 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
  25776. // $this->arabHex .= '0647FEEAFEEBFEEC0648FEEE0648FEEE0649FEF00649FEF0064AFEF2FEF3FEF40640064006400640060C060C060C060C061F061F061F061F061B061B061B061B';
  25777. // 0649 Alef Maksura Initial and Medial forms as given in Unicode FBE8 and FBE9 (not in most fonts) - dotless vesions of above
  25778. // $this->arabHex .= '0647FEEAFEEBFEEC0648FEEE0648FEEE0649FEF0FBE8FBE9064AFEF2FEF3FEF40640064006400640060C060C060C060C061F061F061F061F061B061B061B061B';
  25779. // LAM with ALEF ligatures
  25780. // U+0644; U+0622; U+0644; U+0623; U+0644; U+0625; U+0644; U+0627;
  25781. $this->arabGlyphs .= "\xd9\x84\xd8\xa2\xd9\x84\xd8\xa3\xd9\x84\xd8\xa5\xd9\x84\xd8\xa7";
  25782. $this->arabHex .= 'FEF5FEF6FEF5FEF6FEF7FEF8FEF7FEF8FEF9FEFAFEF9FEFAFEFBFEFCFEFBFEFC';
  25783. // Added Arabic Presentation Forms - A - for Persian and other langauges
  25784. // U+067B; U+067E; U+0680; U+067A; U+067F; U+0679; U+06A4; U+06A6;
  25785. $this->persianGlyphs = "\xd9\xbb\xd9\xbe\xda\x80\xd9\xba\xd9\xbf\xd9\xb9\xda\xa4\xda\xa6";
  25786. $this->persianHex = '067BFB53FB54FB55067EFB57FB58FB590680FB5BFB5CFB5D067AFB5FFB60FB61067FFB63FB64FB650679FB67FB68FB6906A4FB6BFB6CFB6D06A6FB6FFB70FB71';
  25787. // U+0684; U+0683; U+0686; U+0687; U+0698; U+0691; U+06A9; U+06Af;
  25788. $this->persianGlyphs .= "\xda\x84\xda\x83\xda\x86\xda\x87\xda\x98\xda\x91\xda\xa9\xda\xaf";
  25789. $this->persianHex .= '0684FB73FB74FB750683FB77FB78FB790686FB7BFB7CFB7D0687FB7FFB80FB810698FB8B0698FB8B0691FB8D0691FB8D06A9FB8FFB90FB9106AfFB93FB94FB95';
  25790. // U+06BA; U+06CC; U+06C1; U+0671; U+06D0; U+06D2;
  25791. // 06C1 final form is same as isolated so use 06C1
  25792. $this->persianGlyphs .= "\xda\xba\xdb\x8c\xdb\x81\xd9\xb1\xdb\x90\xdb\x92";
  25793. $this->persianHex .= '06BAFB9F06BAFB9F06CCFBFDFBFEFBFF06C106C1FBA8FBA90671FB510671FB5106D0FBE5FBE6FBE706D2FBAF06D2FBAF';
  25794. }
  25795. // ----------------------------------------------------------------------
  25796. // Derived from ArPHP
  25797. // by Khaled Al-Shamaa
  25798. // http://www.ar-php.org
  25799. // ----------------------------------------------------------------------
  25800. function ArabJoin($str) {
  25801. if (!$this->arabGlyphs) { $this->InitArabic(); }
  25802. $crntChar = null;
  25803. $prevChar = null;
  25804. $nextChar = null;
  25805. $output = array();
  25806. $chars = preg_split('//u', $str);
  25807. $max = count($chars);
  25808. for ($i = $max - 1; $i >= 0; $i--) {
  25809. $crntChar = $chars[$i];
  25810. if ($i > 0){ $prevChar = $chars[$i - 1]; }
  25811. else{ $prevChar = NULL; }
  25812. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25813. //if ($prevChar && mb_strpos($this->arabVowels, $prevChar, 0, 'utf-8') !== false) {
  25814. if ($prevChar && api_strpos($this->arabVowels, $prevChar, 0, 'utf-8') !== false) {
  25815. //
  25816. $prevChar = $chars[$i - 2];
  25817. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25818. //if ($prevChar && mb_strpos($this->arabVowels, $prevChar, 0, 'utf-8') !== false) {
  25819. if ($prevChar && api_strpos($this->arabVowels, $prevChar, 0, 'utf-8') !== false) {
  25820. //
  25821. $prevChar = $chars[$i - 3];
  25822. }
  25823. }
  25824. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25825. //if ($crntChar && mb_strpos($this->arabVowels, $crntChar, 0, 'utf-8') !== false) {
  25826. if ($crntChar && api_strpos($this->arabVowels, $crntChar, 0, 'utf-8') !== false) {
  25827. //
  25828. // If next_char = nextLink && prev_char = prevLink:
  25829. // mPDF 4.0 Added && $prevchar (defined) else error on mb_strpos()
  25830. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25831. //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)) {
  25832. if ($chars[$i + 1] && (api_strpos($this->arabNextLink, $chars[$i + 1], 0, 'utf-8') !== false) && $prevChar && (api_strpos($this->arabPrevLink, $prevChar, 0, 'utf-8') !== false)) {
  25833. //
  25834. $output[] = '&#x' . $this->get_arab_glyphs($crntChar, 1) . ';'; // <final> form
  25835. }
  25836. else {
  25837. $output[] = '&#x' . $this->get_arab_glyphs($crntChar, 0) . ';'; // <isolated> form
  25838. }
  25839. continue;
  25840. }
  25841. // NB = &#x622 &#x623; &#x625; &#x627; &#x644;
  25842. if (isset($chars[$i + 1]) && in_array($chars[$i + 1], array("\xd8\xa2","\xd8\xa3","\xd8\xa5","\xd8\xa7")) && $crntChar == "\xd9\x84"){
  25843. continue;
  25844. }
  25845. if (ord($crntChar) < 128) {
  25846. $output[] = $crntChar;
  25847. $nextChar = $crntChar;
  25848. continue;
  25849. }
  25850. $form = 0;
  25851. if (in_array($crntChar, array("\xd8\xa2", "\xd8\xa3", "\xd8\xa5", "\xd8\xa7")) && $prevChar == "\xd9\x84") {
  25852. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25853. //if ($chars[$i - 2] && mb_strpos($this->arabPrevLink, $chars[$i - 2], 0, 'utf-8') !== false) {
  25854. if ($chars[$i - 2] && api_strpos($this->arabPrevLink, $chars[$i - 2], 0, 'utf-8') !== false) {
  25855. //
  25856. $form++; // <final> form
  25857. }
  25858. $output[] = '&#x' . $this->get_arab_glyphs($prevChar . $crntChar, $form) . ';';
  25859. $nextChar = $prevChar;
  25860. continue;
  25861. }
  25862. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25863. //if ($prevChar && mb_strpos($this->arabPrevLink, $prevChar, 0, 'utf-8') !== false) {
  25864. if ($prevChar && api_strpos($this->arabPrevLink, $prevChar, 0, 'utf-8') !== false) {
  25865. //
  25866. $form++;
  25867. }
  25868. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25869. //if ($nextChar && mb_strpos($this->arabNextLink, $nextChar, 0, 'utf-8') !== false) {
  25870. if ($nextChar && api_strpos($this->arabNextLink, $nextChar, 0, 'utf-8') !== false) {
  25871. //
  25872. $form += 2;
  25873. }
  25874. $output[] = '&#x' . $this->get_arab_glyphs($crntChar, $form) . ';';
  25875. $nextChar = $crntChar;
  25876. }
  25877. $ra = array_reverse($output);
  25878. $s = implode($ra);
  25879. $s = strcode2utf($s);
  25880. return $s;
  25881. }
  25882. function get_arab_glyphs($char, $type) {
  25883. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25884. //$pos = mb_strpos($this->arabGlyphs, $char, 0, 'utf-8');
  25885. $pos = api_strpos($this->arabGlyphs, $char, 0, 'utf-8');
  25886. //
  25887. if ($pos === false) { // If character not covered here
  25888. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25889. //$pos = mb_strpos($this->persianGlyphs, $char, 0, 'utf-8'); // Try Persian additions
  25890. $pos = api_strpos($this->persianGlyphs, $char, 0, 'utf-8'); // Try Persian additions
  25891. //
  25892. if ($pos === false) { // return original character
  25893. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25894. //$x = mb_encode_numericentity ($char, array (0x0, 0xffff, 0, 0xffff), 'UTF-8');
  25895. if (function_exists('mb_encode_numericentity')) {
  25896. $x = mb_encode_numericentity ($char, array (0x0, 0xffff, 0, 0xffff), 'UTF-8');
  25897. } else {
  25898. $x = api_htmlentities($char, ENT_NOQUOTES, 'UTF-8');
  25899. }
  25900. //
  25901. preg_match('/&#(\d+);/', $x, $m);
  25902. return dechex($m[1]);
  25903. }
  25904. else { // if covered by Added Persian chars
  25905. $pos = $pos*16 + $type*4;
  25906. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25907. //return mb_substr($this->persianHex, $pos, 4, 'utf-8');
  25908. return api_substr($this->persianHex, $pos, 4, 'utf-8');
  25909. //
  25910. }
  25911. }
  25912. if ($pos > 48){
  25913. $pos = ($pos-48)/2 + 48;
  25914. }
  25915. $pos = $pos*16 + $type*4;
  25916. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25917. //return mb_substr($this->arabHex, $pos, 4, 'utf-8');
  25918. return api_substr($this->arabHex, $pos, 4, 'utf-8');
  25919. //
  25920. }
  25921. /*-- END RTL --*/
  25922. //===========================
  25923. // Functions originally in htmltoolkit - moved mPDF 4.0
  25924. // Call-back function Used for usort in fn _tableWrite
  25925. function _cmpdom($a, $b) {
  25926. return ($a["dom"] < $b["dom"]) ? -1 : 1;
  25927. }
  25928. function mb_strrev($str, $enc = 'utf-8'){
  25929. // Modified by Ivan Tcholakov, 28-JAN-2010.
  25930. //$ch = array();
  25931. //for($i=0;$i<mb_strlen($str,$enc);$i++) {
  25932. // $ch[] = mb_substr($str,$i,1,$enc);
  25933. //}
  25934. //$revch = array_reverse($ch);
  25935. //return implode('',$revch);
  25936. return api_strrev($str, $enc);
  25937. //
  25938. }
  25939. /*-- COLUMNS --*/
  25940. // Callback function from function printcolumnbuffer in mpdf
  25941. function columnAdjustAdd($type,$k,$xadj,$yadj,$a,$b,$c=0,$d=0,$e=0,$f=0) {
  25942. if ($type == 'Td') { // xpos,ypos
  25943. $a += ($xadj * $k);
  25944. $b -= ($yadj * $k);
  25945. return 'BT '.sprintf('%.3f %.3f',$a,$b).' Td';
  25946. }
  25947. else if ($type == 're') { // xpos,ypos,width,height
  25948. $a += ($xadj * $k);
  25949. $b -= ($yadj * $k);
  25950. return sprintf('%.3f %.3f %.3f %.3f',$a,$b,$c,$d).' re';
  25951. }
  25952. else if ($type == 'l') { // xpos,ypos,x2pos,y2pos
  25953. $a += ($xadj * $k);
  25954. $b -= ($yadj * $k);
  25955. return sprintf('%.3f %.3f l',$a,$b);
  25956. }
  25957. else if ($type == 'img') { // width,height,xpos,ypos
  25958. $c += ($xadj * $k);
  25959. $d -= ($yadj * $k);
  25960. return sprintf('q %.3f 0 0 %.3f %.3f %.3f',$a,$b,$c,$d).' cm /'.$e; // mPDF 4.5.007
  25961. }
  25962. else if ($type == 'draw') { // xpos,ypos
  25963. $a += ($xadj * $k);
  25964. $b -= ($yadj * $k);
  25965. return sprintf('%.3f %.3f m',$a,$b);
  25966. }
  25967. else if ($type == 'bezier') { // xpos,ypos,x2pos,y2pos,x3pos,y3pos
  25968. $a += ($xadj * $k);
  25969. $b -= ($yadj * $k);
  25970. $c += ($xadj * $k);
  25971. $d -= ($yadj * $k);
  25972. $e += ($xadj * $k);
  25973. $f -= ($yadj * $k);
  25974. return sprintf('%.3f %.3f %.3f %.3f %.3f %.3f',$a,$b,$c,$d,$e,$f).' c';
  25975. }
  25976. }
  25977. /*-- END COLUMNS --*/
  25978. // Callback function from function printdivbuffer in mpdf - keeping block together on one page
  25979. function blockAdjust($type,$k,$xadj,$yadj,$a,$b,$c=0,$d=0,$e=0,$f=0) {
  25980. if ($type == 'Td') { // xpos,ypos
  25981. $a += ($xadj * $k);
  25982. $b -= ($yadj * $k);
  25983. return 'BT '.sprintf('%.3f %.3f',$a,$b).' Td';
  25984. }
  25985. else if ($type == 're') { // xpos,ypos,width,height
  25986. $a += ($xadj * $k);
  25987. $b -= ($yadj * $k);
  25988. return sprintf('%.3f %.3f %.3f %.3f',$a,$b,$c,$d).' re';
  25989. }
  25990. else if ($type == 'l') { // xpos,ypos,x2pos,y2pos
  25991. $a += ($xadj * $k);
  25992. $b -= ($yadj * $k);
  25993. return sprintf('%.3f %.3f l',$a,$b);
  25994. }
  25995. else if ($type == 'img') { // width,height,xpos,ypos
  25996. $c += ($xadj * $k);
  25997. $d -= ($yadj * $k);
  25998. return sprintf('q %.3f 0 0 %.3f %.3f %.3f',$a,$b,$c,$d).' cm /'.$e; // mPDF 4.5.007
  25999. }
  26000. else if ($type == 'draw') { // xpos,ypos
  26001. $a += ($xadj * $k);
  26002. $b -= ($yadj * $k);
  26003. return sprintf('%.3f %.3f m',$a,$b);
  26004. }
  26005. else if ($type == 'bezier') { // xpos,ypos,x2pos,y2pos,x3pos,y3pos
  26006. $a += ($xadj * $k);
  26007. $b -= ($yadj * $k);
  26008. $c += ($xadj * $k);
  26009. $d -= ($yadj * $k);
  26010. $e += ($xadj * $k);
  26011. $f -= ($yadj * $k);
  26012. return sprintf('%.3f %.3f %.3f %.3f %.3f %.3f',$a,$b,$c,$d,$e,$f).' c';
  26013. }
  26014. }
  26015. function ConvertColor($color="#000000"){
  26016. //returns an associative array (keys: R,G,B) from html code (e.g. #3FE5AA)
  26017. //All color names array
  26018. static $common_colors = array('antiquewhite'=>'#FAEBD7','aqua'=>'#00FFFF','aquamarine'=>'#7FFFD4','beige'=>'#F5F5DC','black'=>'#000000',
  26019. 'blue'=>'#0000FF','brown'=>'#A52A2A','cadetblue'=>'#5F9EA0','chocolate'=>'#D2691E','cornflowerblue'=>'#6495ED','crimson'=>'#DC143C',
  26020. 'darkblue'=>'#00008B','darkgoldenrod'=>'#B8860B','darkgreen'=>'#006400','darkmagenta'=>'#8B008B','darkorange'=>'#FF8C00',
  26021. 'darkred'=>'#8B0000','darkseagreen'=>'#8FBC8F','darkslategray'=>'#2F4F4F','darkviolet'=>'#9400D3','deepskyblue'=>'#00BFFF',
  26022. 'dodgerblue'=>'#1E90FF','firebrick'=>'#B22222','forestgreen'=>'#228B22','fuchsia'=>'#FF00FF','gainsboro'=>'#DCDCDC','gold'=>'#FFD700',
  26023. 'gray'=>'#808080','green'=>'#008000','greenyellow'=>'#ADFF2F','hotpink'=>'#FF69B4','indigo'=>'#4B0082','khaki'=>'#F0E68C',
  26024. 'lavenderblush'=>'#FFF0F5','lemonchiffon'=>'#FFFACD','lightcoral'=>'#F08080','lightgoldenrodyellow'=>'#FAFAD2','lightgreen'=>'#90EE90',
  26025. 'lightsalmon'=>'#FFA07A','lightskyblue'=>'#87CEFA','lightslategray'=>'#778899','lightyellow'=>'#FFFFE0','lime'=>'#00FF00','limegreen'=>'#32CD32',
  26026. 'magenta'=>'#FF00FF','maroon'=>'#800000','mediumaquamarine'=>'#66CDAA','mediumorchid'=>'#BA55D3','mediumseagreen'=>'#3CB371',
  26027. 'mediumspringgreen'=>'#00FA9A','mediumvioletred'=>'#C71585','midnightblue'=>'#191970','mintcream'=>'#F5FFFA','moccasin'=>'#FFE4B5','navy'=>'#000080',
  26028. 'olive'=>'#808000','orange'=>'#FFA500','orchid'=>'#DA70D6','palegreen'=>'#98FB98',
  26029. 'palevioletred'=>'#D87093','peachpuff'=>'#FFDAB9','pink'=>'#FFC0CB','powderblue'=>'#B0E0E6','purple'=>'#800080',
  26030. 'red'=>'#FF0000','royalblue'=>'#4169E1','salmon'=>'#FA8072','seagreen'=>'#2E8B57','sienna'=>'#A0522D','silver'=>'#C0C0C0','skyblue'=>'#87CEEB',
  26031. 'slategray'=>'#708090','springgreen'=>'#00FF7F','steelblue'=>'#4682B4','tan'=>'#D2B48C','teal'=>'#008080','thistle'=>'#D8BFD8','turquoise'=>'#40E0D0',
  26032. 'violetred'=>'#D02090','white'=>'#FFFFFF','yellow'=>'#FFFF00',
  26033. 'aliceblue'=>'#f0f8ff', 'azure'=>'#f0ffff', 'bisque'=>'#ffe4c4', 'blanchedalmond'=>'#ffebcd', 'blueviolet'=>'#8a2be2', 'burlywood'=>'#deb887',
  26034. 'chartreuse'=>'#7fff00', 'coral'=>'#ff7f50', 'cornsilk'=>'#fff8dc', 'cyan'=>'#00ffff', 'darkcyan'=>'#008b8b', 'darkgray'=>'#a9a9a9',
  26035. 'darkgrey'=>'#a9a9a9', 'darkkhaki'=>'#bdb76b', 'darkolivegreen'=>'#556b2f', 'darkorchid'=>'#9932cc', 'darksalmon'=>'#e9967a',
  26036. 'darkslateblue'=>'#483d8b', 'darkslategrey'=>'#2f4f4f', 'darkturquoise'=>'#00ced1', 'deeppink'=>'#ff1493', 'dimgray'=>'#696969',
  26037. 'dimgrey'=>'#696969', 'floralwhite'=>'#fffaf0', 'ghostwhite'=>'#f8f8ff', 'goldenrod'=>'#daa520', 'grey'=>'#808080', 'honeydew'=>'#f0fff0',
  26038. 'indianred'=>'#cd5c5c', 'ivory'=>'#fffff0', 'lavender'=>'#e6e6fa', 'lawngreen'=>'#7cfc00', 'lightblue'=>'#add8e6', 'lightcyan'=>'#e0ffff',
  26039. 'lightgray'=>'#d3d3d3', 'lightgrey'=>'#d3d3d3', 'lightpink'=>'#ffb6c1', 'lightseagreen'=>'#20b2aa', 'lightslategrey'=>'#778899',
  26040. 'lightsteelblue'=>'#b0c4de', 'linen'=>'#faf0e6', 'mediumblue'=>'#0000cd', 'mediumpurple'=>'#9370db', 'mediumslateblue'=>'#7b68ee',
  26041. 'mediumturquoise'=>'#48d1cc', 'mistyrose'=>'#ffe4e1', 'navajowhite'=>'#ffdead', 'oldlace'=>'#fdf5e6', 'olivedrab'=>'#6b8e23', 'orangered'=>'#ff4500',
  26042. 'palegoldenrod'=>'#eee8aa', 'paleturquoise'=>'#afeeee', 'papayawhip'=>'#ffefd5', 'peru'=>'#cd853f', 'plum'=>'#dda0dd', 'rosybrown'=>'#bc8f8f',
  26043. 'saddlebrown'=>'#8b4513', 'sandybrown'=>'#f4a460', 'seashell'=>'#fff5ee', 'slateblue'=>'#6a5acd', 'slategrey'=>'#708090', 'snow'=>'#fffafa',
  26044. 'tomato'=>'#ff6347', 'violet'=>'#ee82ee', 'wheat'=>'#f5deb3', 'whitesmoke'=>'#f5f5f5', 'yellowgreen'=>'#9acd32');
  26045. //http://www.w3schools.com/css/css_colornames.asp
  26046. if (strtoupper($color)=='TRANSPARENT') { return false; }
  26047. if (strtoupper($color)=='INHERIT') { return false; }
  26048. if (isset($common_colors[strtolower($color)])) $color = $common_colors[strtolower($color)];
  26049. if ($color{0} == '#') //case of #nnnnnn or #nnn
  26050. {
  26051. $cor = strtoupper($color);
  26052. $cor = preg_replace('/\s+.*/','',$cor); // in case of Background: #CCC url() x-repeat etc.
  26053. if (strlen($cor) == 4) { // Turn #RGB into #RRGGBB
  26054. $cor = "#" . $cor{1} . $cor{1} . $cor{2} . $cor{2} . $cor{3} . $cor{3};
  26055. }
  26056. $R = substr($cor, 1, 2);
  26057. $vermelho = hexdec($R);
  26058. $V = substr($cor, 3, 2);
  26059. $verde = hexdec($V);
  26060. $B = substr($cor, 5, 2);
  26061. $azul = hexdec($B);
  26062. $color = array();
  26063. $color['R']=$vermelho;
  26064. $color['G']=$verde;
  26065. $color['B']=$azul;
  26066. }
  26067. else if (stristr($color,'cmyk(')) { //case of CMYK(c,m,y,k)
  26068. $color = str_replace("cmyk(",'',$color); //remove �cmyk(�
  26069. $color = str_replace("CMYK(",'',$color); //remove �CMYK(�
  26070. $color = str_replace(")",'',$color); //remove �)�
  26071. $cores = explode(",", $color);
  26072. $color = array();
  26073. $color['R']=$cores[0];
  26074. $color['G']=$cores[1];
  26075. $color['B']=$cores[2];
  26076. $color['K']=$cores[3];
  26077. }
  26078. else if (stristr($color,'rgb(')) //case of RGB(r,g,b)
  26079. {
  26080. $color = str_replace("rgb(",'',$color); //remove �rgb(�
  26081. $color = str_replace("RGB(",'',$color); //remove �RGB(� -- PHP < 5 does not have str_ireplace
  26082. $color = str_replace(")",'',$color); //remove �)�
  26083. $cores = explode(",", $color);
  26084. $color = array();
  26085. $color['R']=$cores[0];
  26086. $color['G']=$cores[1];
  26087. $color['B']=$cores[2];
  26088. }
  26089. else { return false; }
  26090. if (empty($color)) return false;
  26091. else return $color; // array['R']['G']['B']
  26092. }
  26093. function ConvertSize($size=5,$maxsize=0,$fontsize=false,$usefontsize=true){
  26094. // usefontsize - setfalse for e.g. margins - will ignore fontsize for % values
  26095. // Depends of maxsize value to make % work properly. Usually maxsize == pagewidth
  26096. // For text $maxsize = Fontsize
  26097. // Setting e.g. margin % will use maxsize (pagewidth) and em will use fontsize
  26098. //Identify size (remember: we are using 'mm' units here)
  26099. if ( strtolower($size) == 'thin' ) $size = 1*(25.4/$this->dpi); //1 pixel width for table borders // mPDF 4.4.003
  26100. elseif ( strtolower($size) == 'medium' ) $size = 3*(25.4/$this->dpi); //3 pixel width for table borders // mPDF 4.4.003
  26101. elseif ( strtolower($size) == 'thick' ) $size = 5*(25.4/$this->dpi); //5 pixel width for table borders // mPDF 4.4.003
  26102. elseif ( stristr($size,'px') ) $size *= (25.4/$this->dpi); //pixels // mPDF 4.4.003
  26103. elseif ( stristr($size,'cm') ) $size *= 10; //centimeters
  26104. elseif ( stristr($size,'mm') ) $size += 0; //millimeters
  26105. elseif ( stristr($size,'in') ) $size *= 25.4; //inches
  26106. elseif ( stristr($size,'pc') ) $size *= 38.1/9; //PostScript picas
  26107. elseif ( stristr($size,'pt') ) $size *= 25.4/72; //72 pts/inch
  26108. elseif ( stristr($size,'ex') ) { // mPDF 4.4.003 Approximates "ex" as half of font height
  26109. $size += 0; //make "3.5ex" become simply "3.5"
  26110. if ($fontsize) { $size *= $fontsize/2; }
  26111. else { $size *= $maxsize/2; }
  26112. }
  26113. elseif ( stristr($size,'em') ) {
  26114. $size += 0; //make "0.83em" become simply "0.83"
  26115. if ($fontsize) { $size *= $fontsize; }
  26116. else { $size *= $maxsize; }
  26117. }
  26118. elseif ( stristr($size,'%') ) {
  26119. $size += 0; //make "90%" become simply "90"
  26120. if ($fontsize && $usefontsize) { $size *= $fontsize/100; }
  26121. else { $size *= $maxsize/100; }
  26122. }
  26123. // mPDF 2.3
  26124. elseif (strtoupper($size) == 'XX-SMALL') {
  26125. if ($fontsize) { $size *= $fontsize*0.7; }
  26126. else { $size *= $maxsize*0.7; }
  26127. }
  26128. elseif (strtoupper($size) == 'X-SMALL') {
  26129. if ($fontsize) { $size *= $fontsize*0.77; }
  26130. else { $size *= $maxsize*0.77; }
  26131. }
  26132. elseif (strtoupper($size) == 'SMALL') {
  26133. if ($fontsize) { $size *= $fontsize*0.86; }
  26134. else { $size *= $maxsize*0.86; }
  26135. }
  26136. elseif (strtoupper($size) == 'MEDIUM') {
  26137. if ($fontsize) { $size *= $fontsize; }
  26138. else { $size *= $maxsize; }
  26139. }
  26140. elseif (strtoupper($size) == 'LARGE') {
  26141. if ($fontsize) { $size *= $fontsize*1.2; }
  26142. else { $size *= $maxsize*1.2; }
  26143. }
  26144. elseif (strtoupper($size) == 'X-LARGE') {
  26145. if ($fontsize) { $size *= $fontsize*1.5; }
  26146. else { $size *= $maxsize*1.5; }
  26147. }
  26148. elseif (strtoupper($size) == 'XX-LARGE') {
  26149. if ($fontsize) { $size *= $fontsize*2; }
  26150. else { $size *= $maxsize*2; }
  26151. }
  26152. else $size *= (25.4/$this->dpi); //nothing == px // mPDF 4.4.003
  26153. return $size;
  26154. }
  26155. function lesser_entity_decode($html) {
  26156. //supports the most used entity codes (only does ascii safe characters)
  26157. $html = str_replace("&nbsp;"," ",$html);
  26158. $html = str_replace("&lt;","<",$html);
  26159. $html = str_replace("&gt;",">",$html);
  26160. $html = str_replace("&apos;","'",$html);
  26161. $html = str_replace("&quot;",'"',$html);
  26162. $html = str_replace("&amp;","&",$html);
  26163. return $html;
  26164. }
  26165. function AdjustHTML($html,$directionality='ltr',$usepre=true, $tabSpaces=8) {
  26166. //Try to make the html text more manageable (turning it into XHTML)
  26167. /*-- ANNOTATIONS --*/
  26168. preg_match_all("/(<annotation.*?>)/si", $html, $m);
  26169. if (count($m[1])) {
  26170. for($i=0;$i<count($m[1]);$i++) {
  26171. $sub = preg_replace("/\n/si", "\xbb\xa4\xac", $m[1][$i]);
  26172. $html = preg_replace('/'.preg_quote($m[1][$i], '/').'/si', $sub, $html);
  26173. }
  26174. }
  26175. /*-- END ANNOTATIONS --*/
  26176. //Remove javascript code from HTML (should not appear in the PDF file)
  26177. $html = preg_replace('/<script.*?<\/script>/is','',$html); // mPDF 3.0 changed from ereg_
  26178. //Remove special comments
  26179. $html = preg_replace('/<!--mpdf/i','',$html); // mPDF 3.0 changed from ereg_
  26180. $html = preg_replace('/mpdf-->/i','',$html); // mPDF 3.0 changed from ereg_
  26181. //Remove comments from HTML (should not appear in the PDF file)
  26182. $html = preg_replace('/<!--.*?-->/s','',$html); // mPDF 3.0 changed from ereg_
  26183. $html = preg_replace('/\f/','',$html); //replace formfeed by nothing // mPDF 3.0 changed from ereg_
  26184. $html = preg_replace('/\r/','',$html); //replace carriage return by nothing // mPDF 3.0 changed from ereg_
  26185. // Well formed XHTML end tags
  26186. $html = preg_replace('/<(br|hr)\/>/i',"<\\1 />",$html);
  26187. /*-- TABLES --*/
  26188. // Get rid of empty <thead></thead>
  26189. $html = preg_replace('/<thead>\s*<\/thead>/i','',$html); // mPDF 3.0 changed from ereg_
  26190. $html = preg_replace('/<tfoot>\s*<\/tfoot>/i','',$html); // mPDF 3.2
  26191. $html = preg_replace('/<table[^>]*>\s*<\/table>/i','',$html); // mPDF 3.2
  26192. // Remove spaces at end of table cells
  26193. $html = preg_replace("/[ ]+<\/t(d|h)/",'</t\\1',$html);
  26194. // Transposes Table Cells When RTL direction
  26195. if ($directionality == 'rtl') {
  26196. preg_match_all('/<table(.*?)>(.*?)<\/table>/is',$html,$matches);
  26197. for($i=0;$i<count($matches[0]);$i++) {
  26198. $pre = '<table' . $matches[1][$i] . '>';
  26199. $post = '</table>';
  26200. // mPDF 3.2 Don't change if nested tables
  26201. if (!preg_match('/<table/is',$matches[2][$i]) && !preg_match('/<\/table/is',$matches[2][$i]) ) {
  26202. $table = $matches[0][$i];
  26203. if (preg_match('/(<thead[^>]*>)/is',$table,$m)) { $thead = $m[0]; } else { $thead = ''; }
  26204. preg_match_all('/<tr(.*?)>(.*?)<\/tr>/is',$table,$tmatches);
  26205. $newrows = array();
  26206. for($j=0;$j<count($tmatches[0]);$j++) {
  26207. $rpre = '<tr' . $tmatches[1][$j] . '>';
  26208. $rpost = '</tr>';
  26209. $row = $tmatches[0][$j];
  26210. preg_match_all('/<t[hd].*?>.*?<\/t[hd]>/is',$row,$rmatches);
  26211. $cells = array();
  26212. for($k=0;$k<count($rmatches[0]);$k++) { $cells[] = $rmatches[0][$k]; }
  26213. $cells = array_reverse($cells);
  26214. if (($thead) && ($j == 0)) { // First row
  26215. $newrows[] = $thead . $rpre . implode('',$cells) . $rpost . '</thead><tbody>';
  26216. }
  26217. else if (($thead) && ($j == (count($tmatches[0]) - 1))) { // last row adds </tbody>
  26218. $newrows[] = $rpre . implode('',$cells) . $rpost . '</tbody>';
  26219. }
  26220. else {
  26221. $newrows[] = $rpre . implode('',$cells) . $rpost;
  26222. }
  26223. }
  26224. $newtable = $pre . implode('',$newrows) . $post;
  26225. $html = str_replace($table,$newtable,$html);
  26226. }
  26227. }
  26228. }
  26229. /*-- END TABLES --*/
  26230. // mPDF 4.2.031 <dottab>
  26231. $html = preg_replace("/[ ]*<dottab\s*[\/]*>[ ]*/",'<dottab />',$html);
  26232. // Concatenates any Substitute characters from symbols/dingbats
  26233. $html = str_replace('</tts><tts>','|',$html);
  26234. $html = str_replace('</ttz><ttz>','|',$html);
  26235. $html = str_replace('</tta><tta>','|',$html);
  26236. // Modified by Ivan Tcholakov, 16-FEB-2010.
  26237. //$html = mb_eregi_replace('/<br \/>\s*/is',"<br />",$html); // mPDF 3.0 changed from ereg_
  26238. $html = preg_replace('/<br \/>\s*/is',"<br />",$html); // mPDF 3.0 changed from ereg_
  26239. //
  26240. if ($usepre) //used to keep \n on content inside <pre> and inside <textarea>
  26241. {
  26242. // Preserve '\n's in content between the tags <pre> and </pre>
  26243. $thereispre = preg_match_all('#<pre(.*?)>(.*?)</pre>#si',$html,$temp);
  26244. // Preserve '\n's in content between the tags <textarea> and </textarea>
  26245. $thereistextarea = preg_match_all('#<textarea(.*?)>(.*?)</textarea>#si',$html,$temp2);
  26246. $html = preg_replace('/[\n]/',' ',$html); //replace linefeed by spaces // mPDF 3.0 changed from ereg_
  26247. $html = preg_replace('/[\t]/',' ',$html); //replace tabs by spaces // mPDF 3.0 changed from ereg_
  26248. // mPDF 2.3 - moved
  26249. // Converts < to &lt; when not a tag
  26250. $html = preg_replace('/<([^!\/a-zA-Z])/i','&lt;\\1',$html);
  26251. // mPDF changed to prevent &nbsp; chars replaced
  26252. $html = preg_replace("/[ ]+/",' ',$html);
  26253. $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html); // mPDF 3.0 changed from ereg_
  26254. $html = preg_replace('/\/(u|o)l>\s+<\/li/i','/\\1l></li',$html); // mPDF 3.0 changed from ereg_
  26255. $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html); // mPDF 3.0 changed from ereg_
  26256. $html = preg_replace('/\/li>\s+<li/i','/li><li',$html); // mPDF 3.0 changed from ereg_
  26257. $html = preg_replace('/<(u|o)l([^>]*)>[ ]+/i','<\\1l\\2>',$html);
  26258. $html = preg_replace('/[ ]+<(u|o)l/i','<\\1l',$html); // mPDF 3.0 changed from ereg_
  26259. $iterator = 0;
  26260. while($thereispre) //Recover <pre attributes>content</pre>
  26261. {
  26262. // mPDF 2.4
  26263. $temp[2][$iterator] = str_replace("<||@mpdf@||pre", "<pre", $temp[2][$iterator] );
  26264. $temp[2][$iterator] = str_replace("<||@mpdf@||/pre", "</pre", $temp[2][$iterator] );
  26265. // mPDF 2.4 (moved) / mPDF 2.3
  26266. $temp[2][$iterator] = preg_replace("/^([^\n\t]*?)\t/me", "stripslashes('\\1') . str_repeat(' ', ( $tabSpaces - (mb_strlen(stripslashes('\\1')) % $tabSpaces)) )",$temp[2][$iterator]);
  26267. $temp[2][$iterator] = preg_replace('/&/',"&amp;",$temp[2][$iterator]); // mPDF 3.0 changed from ereg_
  26268. $temp[2][$iterator] = preg_replace('/</',"&lt;",$temp[2][$iterator]); // mPDF 3.0 changed from ereg_
  26269. $temp[2][$iterator] = preg_replace('/\t/',str_repeat(" ",$tabSpaces),$temp[2][$iterator]); // mPDF 3.0 changed from ereg_
  26270. $temp[2][$iterator] = preg_replace('/\n/',"<br />",$temp[2][$iterator]); // mPDF 3.0 changed from ereg_
  26271. // mPDF 1.3 Edited to fix bug with empty pre
  26272. // mPDF 2.4 Removed /u as not needed to be Unicode and causing bugs with annotations
  26273. $html = preg_replace('#<pre(.*?)>(.*?)</pre>#si','<erp'.$temp[1][$iterator].'>'.$temp[2][$iterator].'</erp>',$html,1);
  26274. $thereispre--;
  26275. $iterator++;
  26276. }
  26277. $iterator = 0;
  26278. while($thereistextarea) //Recover <textarea attributes>content</textarea>
  26279. {
  26280. $temp2[2][$iterator] = preg_replace('/&/',"&amp;",$temp2[2][$iterator]); // mPDF 3.0 changed from ereg_
  26281. $temp2[2][$iterator] = preg_replace('/</',"&lt;",$temp2[2][$iterator]); // mPDF 3.0 changed from ereg_
  26282. $temp2[2][$iterator] = preg_replace('/\t/',str_repeat(" ",$tabSpaces),$temp2[2][$iterator]); // mPDF 3.0 changed from ereg_
  26283. $temp2[2][$iterator] = preg_replace('/[ ]/',"&nbsp;",$temp2[2][$iterator]); // mPDF 3.0 changed from ereg_
  26284. // mPDF 4.1 /u modifier removed - not required and causing problems if annotation special chars
  26285. $html = preg_replace('#<textarea(.*?)>(.*?)</textarea>#si','<aeratxet'.$temp2[1][$iterator].'>'.trim($temp2[2][$iterator]) .'</aeratxet>',$html,1);
  26286. $thereistextarea--;
  26287. $iterator++;
  26288. }
  26289. //Restore original tag names
  26290. $html = str_replace("<erp","<pre",$html);
  26291. $html = str_replace("</erp>","</pre>",$html);
  26292. $html = str_replace("<aeratxet","<textarea",$html);
  26293. $html = str_replace("</aeratxet>","</textarea>",$html);
  26294. // (the code above might slowdown overall performance?)
  26295. } //end of if($usepre)
  26296. else
  26297. {
  26298. $html = preg_replace('/\n/',' ',$html); //replace linefeed by spaces // mPDF 3.0 changed from ereg_
  26299. $html = preg_replace('/\t/',' ',$html); //replace tabs by spaces // mPDF 3.0 changed from ereg_
  26300. // Converts < to &lt; when not a tag
  26301. $html = preg_replace('/<([^!\/a-zA-Z])/i','&lt;\\1',$html);
  26302. // mPDF changed to prevent &nbsp; chars replaced
  26303. $html = preg_replace("/[ ]+/",' ',$html); // mPDF 4.4.012
  26304. $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html); // mPDF 3.0 changed from ereg_
  26305. $html = preg_replace('/\/(u|o)l>\s+<\/li/i','/\\1l></li',$html); // mPDF 3.0 changed from ereg_
  26306. $html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html); // mPDF 3.0 changed from ereg_
  26307. $html = preg_replace('/\/li>\s+<li/i','/li><li',$html); // mPDF 3.0 changed from ereg_
  26308. $html = preg_replace('/<(u|o)l([^>]*)>[ ]+/i','<\\1l\\2>',$html);
  26309. $html = preg_replace('/[ ]+<(u|o)l/i','<\\1l',$html); // mPDF 3.0 changed from ereg_
  26310. }
  26311. $html = preg_replace('/<textarea([^>]*)><\/textarea>/si','<textarea\\1> </textarea>',$html);
  26312. // mPDF 4.5.015
  26313. // $html = preg_replace('/<(h[1-6])([^>]*)(>(?:(?!h[1-6]).)*<\/\\1>\s*<table)/si','<\\1\\2 keep-with-table="1"\\3',$html);
  26314. $html = preg_replace('/<(h[1-6])([^>]*)(>(?:(?!h[1-6]).)*?<\/\\1>\s*<table)/si','<\\1\\2 keep-with-table="1"\\3',$html); // *TABLES*
  26315. $html = preg_replace("/\xbb\xa4\xac/", "\n", $html);
  26316. return $html;
  26317. }
  26318. /*-- LISTS --*/
  26319. function dec2alpha($valor,$toupper="true"){
  26320. // returns a string from A-Z to AA-ZZ to AAA-ZZZ
  26321. // OBS: A = 65 ASCII TABLE VALUE
  26322. if (($valor < 1) || ($valor > 18278)) return "?"; //supports 'only' up to 18278
  26323. $c1 = $c2 = $c3 = '';
  26324. if ($valor > 702) // 3 letters (up to 18278)
  26325. {
  26326. $c1 = 65 + floor(($valor-703)/676);
  26327. $c2 = 65 + floor((($valor-703)%676)/26);
  26328. $c3 = 65 + floor((($valor-703)%676)%26);
  26329. }
  26330. elseif ($valor > 26) // 2 letters (up to 702)
  26331. {
  26332. $c1 = (64 + (int)(($valor-1) / 26));
  26333. $c2 = (64 + (int)($valor % 26));
  26334. if ($c2 == 64) $c2 += 26;
  26335. }
  26336. else // 1 letter (up to 26)
  26337. {
  26338. $c1 = (64 + $valor);
  26339. }
  26340. $alpha = chr($c1);
  26341. if ($c2 != '') $alpha .= chr($c2);
  26342. if ($c3 != '') $alpha .= chr($c3);
  26343. if (!$toupper) $alpha = strtolower($alpha);
  26344. return $alpha;
  26345. }
  26346. function dec2roman($valor,$toupper=true){
  26347. //returns a string as a roman numeral
  26348. $r1=$r2=$r3=$r4='';
  26349. if (($valor >= 5000) || ($valor < 1)) return "?"; //supports 'only' up to 4999
  26350. $aux = (int)($valor/1000);
  26351. if ($aux!==0)
  26352. {
  26353. $valor %= 1000;
  26354. while($aux!==0)
  26355. {
  26356. $r1 .= "M";
  26357. $aux--;
  26358. }
  26359. }
  26360. $aux = (int)($valor/100);
  26361. if ($aux!==0)
  26362. {
  26363. $valor %= 100;
  26364. switch($aux){
  26365. case 3: $r2="C";
  26366. case 2: $r2.="C";
  26367. case 1: $r2.="C"; break;
  26368. case 9: $r2="CM"; break;
  26369. case 8: $r2="C";
  26370. case 7: $r2.="C";
  26371. case 6: $r2.="C";
  26372. case 5: $r2="D".$r2; break;
  26373. case 4: $r2="CD"; break;
  26374. default: break;
  26375. }
  26376. }
  26377. $aux = (int)($valor/10);
  26378. if ($aux!==0)
  26379. {
  26380. $valor %= 10;
  26381. switch($aux){
  26382. case 3: $r3="X";
  26383. case 2: $r3.="X";
  26384. case 1: $r3.="X"; break;
  26385. case 9: $r3="XC"; break;
  26386. case 8: $r3="X";
  26387. case 7: $r3.="X";
  26388. case 6: $r3.="X";
  26389. case 5: $r3="L".$r3; break;
  26390. case 4: $r3="XL"; break;
  26391. default: break;
  26392. }
  26393. }
  26394. switch($valor){
  26395. case 3: $r4="I";
  26396. case 2: $r4.="I";
  26397. case 1: $r4.="I"; break;
  26398. case 9: $r4="IX"; break;
  26399. case 8: $r4="I";
  26400. case 7: $r4.="I";
  26401. case 6: $r4.="I";
  26402. case 5: $r4="V".$r4; break;
  26403. case 4: $r4="IV"; break;
  26404. default: break;
  26405. }
  26406. $roman = $r1.$r2.$r3.$r4;
  26407. if (!$toupper) $roman = strtolower($roman);
  26408. return $roman;
  26409. }
  26410. /*-- END LISTS --*/
  26411. //===========================
  26412. /*-- IMPORTS --*/
  26413. // mPDF 4.2.006
  26414. function SetImportUse() {
  26415. $this->enableImports = true;
  26416. ini_set('auto_detect_line_endings',1);
  26417. require_once(_MPDF_PATH."mpdfi/pdf_context.php");
  26418. require_once(_MPDF_PATH."mpdfi/pdf_parser.php");
  26419. require_once(_MPDF_PATH."mpdfi/fpdi_pdf_parser.php");
  26420. }
  26421. // from mPDFI
  26422. function hex2str($hex) {
  26423. return pack("H*", str_replace(array("\r","\n"," "),"", $hex));
  26424. }
  26425. function str2hex($str) {
  26426. return current(unpack("H*",$str));
  26427. }
  26428. function pdf_write_value(&$value) {
  26429. switch ($value[0]) {
  26430. case PDF_TYPE_NUMERIC :
  26431. case PDF_TYPE_TOKEN :
  26432. // A numeric value or a token.
  26433. // Simply output them
  26434. $this->_out($value[1]." ", false);
  26435. break;
  26436. case PDF_TYPE_ARRAY :
  26437. // An array. Output the proper
  26438. // structure and move on.
  26439. $this->_out("[",false);
  26440. for ($i = 0; $i < count($value[1]); $i++) {
  26441. $this->pdf_write_value($value[1][$i]);
  26442. }
  26443. $this->_out("]");
  26444. break;
  26445. case PDF_TYPE_DICTIONARY :
  26446. // A dictionary.
  26447. $this->_out("<<",false);
  26448. reset ($value[1]);
  26449. while (list($k, $v) = each($value[1])) {
  26450. $this->_out($k . " ",false);
  26451. $this->pdf_write_value($v);
  26452. }
  26453. $this->_out(">>");
  26454. break;
  26455. case PDF_TYPE_OBJREF :
  26456. // An indirect object reference
  26457. // Fill the object stack if needed
  26458. $cpfn =& $this->current_parser->filename;
  26459. if (!isset($this->_don_obj_stack[$cpfn][$value[1]])) {
  26460. $this->_newobj(false,true);
  26461. $this->_obj_stack[$cpfn][$value[1]] = array($this->n, $value);
  26462. $this->_don_obj_stack[$cpfn][$value[1]] = array($this->n, $value);
  26463. }
  26464. $objid = $this->_don_obj_stack[$cpfn][$value[1]][0];
  26465. $this->_out("{$objid} 0 R"); //{$value[2]}
  26466. break;
  26467. case PDF_TYPE_STRING :
  26468. if ($this->encrypted) {
  26469. $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
  26470. $value[1] = $this->_escape($value[1]);
  26471. }
  26472. // A string.
  26473. $this->_out('('.$value[1].')');
  26474. break;
  26475. case PDF_TYPE_STREAM :
  26476. // A stream. First, output the
  26477. // stream dictionary, then the
  26478. // stream data itself.
  26479. $this->pdf_write_value($value[1]);
  26480. if ($this->encrypted) {
  26481. $value[2][1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[2][1]);
  26482. }
  26483. $this->_out("stream");
  26484. $this->_out($value[2][1]);
  26485. $this->_out("endstream");
  26486. break;
  26487. case PDF_TYPE_HEX :
  26488. if ($this->encrypted) {
  26489. $value[1] = $this->hex2str($value[1]);
  26490. $value[1] = $this->_RC4($this->_objectkey($this->_current_obj_id), $value[1]);
  26491. // remake hexstring of encrypted string
  26492. $value[1] = $this->str2hex($value[1]);
  26493. }
  26494. $this->_out("<".$value[1].">");
  26495. break;
  26496. case PDF_TYPE_NULL :
  26497. // The null object.
  26498. $this->_out("null");
  26499. break;
  26500. }
  26501. }
  26502. // ========== OVERWRITE SEARCH STRING IN A PDF FILE ================
  26503. function OverWrite($file_in, $search, $replacement, $dest="D", $file_out="mpdf" ) {
  26504. $pdf = file_get_contents($file_in);
  26505. if (!is_array($search)) {
  26506. $x = $search;
  26507. $search = array($x);
  26508. }
  26509. if (!is_array($replacement)) {
  26510. $x = $replacement;
  26511. $search = array($x);
  26512. }
  26513. if ($this->isunicode && !$this->isCJK) {
  26514. foreach($search AS $k=>$val) {
  26515. $search[$k] = $this->UTF8ToUTF16BE($search[$k] , false);
  26516. $search[$k] = $this->_escape($search[$k]);
  26517. $replacement[$k] = $this->UTF8ToUTF16BE($replacement[$k], false);
  26518. $replacement[$k] = $this->_escape($replacement[$k]);
  26519. }
  26520. }
  26521. else {
  26522. foreach($replacement AS $k=>$val) {
  26523. $replacement[$k] = mb_convert_encoding($replacement[$k],$this->mb_encoding,'utf-8');
  26524. $replacement[$k] = $this->_escape($replacement[$k]);
  26525. }
  26526. }
  26527. // Get xref into array
  26528. $xref = array();
  26529. preg_match("/xref\n0 (\d+)\n(.*?)\ntrailer/s",$pdf,$m);
  26530. $xref_objid = $m[1];
  26531. preg_match_all('/(\d{10}) (\d{5}) (f|n)/',$m[2],$x);
  26532. for($i=0; $i<count($x[0]); $i++) {
  26533. $xref[] = array(intval($x[1][$i]), $x[2][$i], $x[3][$i]);
  26534. }
  26535. $changes = array();
  26536. preg_match("/<<\s*\/Type\s*\/Pages\s*\/Kids\s*\[(.*?)\]\s*\/Count/s",$pdf,$m); // mPDF 4.2.030
  26537. preg_match_all("/(\d+) 0 R /s",$m[1],$o);
  26538. $objlist = $o[1];
  26539. foreach($objlist AS $obj) {
  26540. if ($this->compress) {
  26541. preg_match("/".($obj+1)." 0 obj\n<<\s*\/Filter\s*\/FlateDecode\s*\/Length (\d+)>>\nstream\n(.*?)\nendstream\n/s",$pdf,$m); // mPDF 4.2.030
  26542. }
  26543. else {
  26544. preg_match("/".($obj+1)." 0 obj\n<<\s*\/Length (\d+)>>\nstream\n(.*?)\nendstream\n/s",$pdf,$m); // mPDF 4.2.030
  26545. }
  26546. $s = $m[2];
  26547. if (!$s) { continue; } // mPDF 4.2.030
  26548. $oldlen = $m[1];
  26549. if ($this->encrypted) {
  26550. $s = $this->_RC4($this->_objectkey($obj+1), $s);
  26551. }
  26552. if ($this->compress) {
  26553. $s = gzuncompress($s);
  26554. }
  26555. foreach($search AS $k=>$val) {
  26556. $s = str_replace($search[$k],$replacement[$k],$s);
  26557. }
  26558. if ($this->compress) {
  26559. $s = gzcompress($s);
  26560. }
  26561. if ($this->encrypted) {
  26562. $s = $this->_RC4($this->_objectkey($obj+1), $s);
  26563. }
  26564. $newlen = strlen($s);
  26565. $changes[($xref[$obj+1][0])] = ($newlen - $oldlen) + (strlen($newlen) - strlen($oldlen ));
  26566. if ($this->compress) {
  26567. $newstr = ($obj+1) . " 0 obj\n<</Filter /FlateDecode /Length ".$newlen.">>\nstream\n".$s."\nendstream\n";
  26568. }
  26569. else {
  26570. $newstr = ($obj+1) . " 0 obj\n<</Length ".$newlen.">>\nstream\n".$s."\nendstream\n";
  26571. }
  26572. $pdf = str_replace($m[0],$newstr,$pdf);
  26573. }
  26574. // Update xref in PDF
  26575. krsort($changes);
  26576. $newxref = "xref\n0 ".$xref_objid."\n";
  26577. foreach($xref AS $v) {
  26578. foreach($changes AS $ck => $cv) {
  26579. if ($v[0] > $ck) { $v[0] += $cv; }
  26580. }
  26581. $newxref .= sprintf('%010d',$v[0]) . ' ' . $v[1] . ' ' .$v[2] . " \n";
  26582. }
  26583. $newxref .= "trailer";
  26584. $pdf = preg_replace("/xref\n0 \d+\n.*?\ntrailer/s",$newxref,$pdf);
  26585. // Update startxref in PDF
  26586. preg_match("/startxref\n(\d+)\n%%EOF/s", $pdf, $m);
  26587. $startxref = $m[1];
  26588. $startxref += array_sum($changes);
  26589. $pdf = preg_replace("/startxref\n(\d+)\n%%EOF/s","startxref\n".$startxref."\n%%EOF",$pdf);
  26590. // OUTPUT
  26591. switch($dest) {
  26592. case 'I':
  26593. //Send to standard output
  26594. if(isset($_SERVER['SERVER_NAME']))
  26595. {
  26596. //We send to a browser
  26597. Header('Content-Type: application/pdf');
  26598. Header('Content-Length: '.strlen($pdf));
  26599. Header('Content-disposition: inline; filename='.$file_out);
  26600. }
  26601. echo $pdf;
  26602. break;
  26603. case 'F':
  26604. //Save to local file
  26605. if (!$file_out) { $file_out = 'mpdf.pdf'; }
  26606. $f=fopen($file_out,'wb');
  26607. if(!$f) die('Unable to create output file: '.$file_out);
  26608. fwrite($f,$pdf,strlen($pdf));
  26609. fclose($f);
  26610. break;
  26611. case 'S':
  26612. //Return as a string
  26613. return $pdf;
  26614. case 'D':
  26615. default:
  26616. //Download file
  26617. if(isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
  26618. Header('Content-Type: application/force-download');
  26619. else
  26620. Header('Content-Type: application/octet-stream');
  26621. Header('Content-Length: '.strlen($pdf));
  26622. Header('Content-disposition: attachment; filename='.$file_out);
  26623. echo $pdf;
  26624. break;
  26625. }
  26626. }
  26627. function GetTemplateSize($tplidx, $_w=0, $_h=0) {
  26628. if (!$this->tpls[$tplidx])
  26629. return false;
  26630. $w = $this->tpls[$tplidx]['box']['w'];
  26631. $h = $this->tpls[$tplidx]['box']['h'];
  26632. if ($_w == 0 and $_h == 0) {
  26633. $_w = $w;
  26634. $_h = $h;
  26635. }
  26636. if($_w==0)
  26637. $_w=$_h*$w/$h;
  26638. if($_h==0)
  26639. $_h=$_w*$h/$w;
  26640. return array("w" => $_w, "h" => $_h);
  26641. }
  26642. // Thumbnails
  26643. // mPDF 2.3 Templates
  26644. function Thumbnail($file, $npr=3, $spacing=10) { //$npr = number per row
  26645. $w = (($this->pgwidth + $spacing)/$npr) - $spacing;
  26646. $oldlinewidth = $this->LineWidth;
  26647. $this->SetLineWidth(0.02); $this->SetDrawColor(0);
  26648. $h = 0;
  26649. $maxh = 0;
  26650. $x = $_x = $this->lMargin;
  26651. $_y = $this->tMargin;
  26652. if ($this->y==0) { $y = $_y; } else { $y = $this->y; }
  26653. $pagecount = $this->SetSourceFile($file);
  26654. for ($n = 1; $n <= $pagecount; $n++) {
  26655. $tplidx = $this->ImportPage($n);
  26656. $size = $this->useTemplate($tplidx, $x, $y, $w);
  26657. $this->Rect($x, $y, $size['w'], $size['h']);
  26658. $h = max($h, $size['h']);
  26659. $maxh = max($h, $maxh);
  26660. if ($n % $npr == 0) {
  26661. if (($y + $h + $spacing + $maxh)>$this->PageBreakTrigger && $n != $pagecount) {
  26662. $this->AddPage();
  26663. $x = $_x;
  26664. $y = $_y;
  26665. }
  26666. else {
  26667. $y += $h+$spacing ;
  26668. $x = $_x;
  26669. $h = 0;
  26670. }
  26671. }
  26672. else {
  26673. $x += $w+$spacing ;
  26674. }
  26675. }
  26676. $this->SetLineWidth($oldlinewidth);
  26677. }
  26678. function SetSourceFile($filename) {
  26679. $this->current_filename = $filename;
  26680. $fn =& $this->current_filename;
  26681. if (!isset($this->parsers[$fn]))
  26682. // mPDF 4.3.007D
  26683. // $this->parsers[$fn] =& new fpdi_pdf_parser($fn,$this);
  26684. $this->parsers[$fn] = new fpdi_pdf_parser($fn,$this);
  26685. if (!$this->parsers[$fn]->success) {
  26686. $this->Error($this->parsers[$fn]->errormsg); // Delete this line to return false on fail
  26687. return false;
  26688. }
  26689. $this->current_parser =& $this->parsers[$fn];
  26690. return $this->parsers[$fn]->getPageCount();
  26691. }
  26692. function ImportPage($pageno=1, $crop_x=null, $crop_y=null, $crop_w=0, $crop_h=0, $boxName='/CropBox') {
  26693. $fn =& $this->current_filename;
  26694. $parser =& $this->parsers[$fn];
  26695. $parser->setPageno($pageno);
  26696. $this->tpl++;
  26697. $this->tpls[$this->tpl] = array();
  26698. $tpl =& $this->tpls[$this->tpl];
  26699. $tpl['parser'] =& $parser;
  26700. $tpl['resources'] = $parser->getPageResources();
  26701. $tpl['buffer'] = $parser->getContent();
  26702. if (!in_array($boxName, $parser->availableBoxes))
  26703. return $this->Error(sprintf("Unknown box: %s", $boxName));
  26704. $pageboxes = $parser->getPageBoxes($pageno);
  26705. /**
  26706. * MediaBox
  26707. * CropBox: Default -> MediaBox
  26708. * BleedBox: Default -> CropBox
  26709. * TrimBox: Default -> CropBox
  26710. * ArtBox: Default -> CropBox
  26711. */
  26712. if (!isset($pageboxes[$boxName]) && ($boxName == "/BleedBox" || $boxName == "/TrimBox" || $boxName == "/ArtBox"))
  26713. $boxName = "/CropBox";
  26714. if (!isset($pageboxes[$boxName]) && $boxName == "/CropBox")
  26715. $boxName = "/MediaBox";
  26716. if (!isset($pageboxes[$boxName]))
  26717. return false;
  26718. $box = $pageboxes[$boxName];
  26719. $tpl['box'] = $box;
  26720. // To build an array that can be used by useTemplate()
  26721. $this->tpls[$this->tpl] = array_merge($this->tpls[$this->tpl],$box);
  26722. // An imported page will start at 0,0 everytime. Translation will be set in _putformxobjects()
  26723. $tpl['x'] = 0;
  26724. $tpl['y'] = 0;
  26725. $tpl['w'] = $tpl['box']['w'] ;
  26726. $tpl['h'] = $tpl['box']['h'] ;
  26727. if ($crop_w) { $tpl['box']['w'] = $crop_w; }
  26728. if ($crop_h) { $tpl['box']['h'] = $crop_h; }
  26729. if (isset($crop_x)) { $tpl['box']['x'] = $crop_x; }
  26730. if (isset($crop_y)) {$tpl['box']['y'] = $tpl['h'] - $crop_y - $crop_h ; }
  26731. $page =& $parser->pages[$parser->pageno];
  26732. // fix for rotated pages
  26733. $rotation = $parser->getPageRotation($pageno);
  26734. if (isset($rotation[1]) && ($angle = $rotation[1] % 360) != 0 && $tpl['box']['w'] == $tpl['w']) {
  26735. $steps = $angle / 90;
  26736. $_w = $tpl['w'];
  26737. $_h = $tpl['h'];
  26738. $tpl['w'] = $steps % 2 == 0 ? $_w : $_h;
  26739. $tpl['h'] = $steps % 2 == 0 ? $_h : $_w;
  26740. if ($steps % 2 != 0) {
  26741. $x = $y = ($steps == 1 || $steps == -3) ? $tpl['h'] : $tpl['w'];
  26742. } else {
  26743. $x = $tpl['w'];
  26744. $y = $tpl['h'];
  26745. }
  26746. $cx=($x/2+$tpl['box']['x'])*$this->k;
  26747. $cy=($y/2+$tpl['box']['y'])*$this->k;
  26748. $angle*=-1;
  26749. $angle*=M_PI/180;
  26750. $c=cos($angle);
  26751. $s=sin($angle);
  26752. $tpl['box']['w'] = $tpl['w'] ;
  26753. $tpl['box']['h'] = $tpl['h'] ;
  26754. $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']);
  26755. }
  26756. return $this->tpl;
  26757. }
  26758. function UseTemplate($tplidx, $_x=null, $_y=null, $_w=0, $_h=0) {
  26759. if (!isset($this->tpls[$tplidx]))
  26760. $this->Error("Template does not exist!");
  26761. if($this->state==0) { $this->AddPage(); }
  26762. $out = 'q 0 J 1 w 0 j 0 G'."\n"; // reset standard values
  26763. $x = $this->tpls[$tplidx]['x'];
  26764. $y = $this->tpls[$tplidx]['y'];
  26765. $w = $this->tpls[$tplidx]['w'];
  26766. $h = $this->tpls[$tplidx]['h'];
  26767. if ($_x == null) { $_x = $x; }
  26768. if ($_y == null) { $_y = $y; }
  26769. if ($_x === -1) { $_x = $this->x; }
  26770. if ($_y === -1) { $_y = $this->y; }
  26771. $wh = $this->getTemplateSize($tplidx,$_w,$_h);
  26772. $_w = $wh['w'];
  26773. $_h = $wh['h'];
  26774. $out .= sprintf("q %.4f 0 0 %.4f %.2f %.2f cm", ($_w/$this->tpls[$tplidx]['box']['w']), ($_h/$this->tpls[$tplidx]['box']['h']), $_x*$this->k, ($this->h-($_y+$_h))*$this->k)."\n";
  26775. $out .= $this->tplprefix.$tplidx." Do Q\n";
  26776. $s = array("w" => $_w, "h" => $_h);
  26777. $out .= "Q\n";
  26778. $this->pages[$this->page] = $out . $this->pages[$this->page]; // mPDF 4.2.004
  26779. return $s;
  26780. }
  26781. function SetPageTemplate($tplidx='') {
  26782. if (!isset($this->tpls[$tplidx])) {
  26783. $this->pageTemplate = '';
  26784. return false;
  26785. }
  26786. $this->pageTemplate = $tplidx;
  26787. }
  26788. function SetDocTemplate($file='', $continue=0) {
  26789. $this->docTemplate = $file;
  26790. $this->docTemplateContinue = $continue;
  26791. }
  26792. /*-- END IMPORTS --*/
  26793. }//end of Class
  26794. ?>