Layout.c 149 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: Layout.c /main/31 1996/10/25 12:00:15 cde-hp $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: Layout.c
  28. **
  29. ** Project: CDE Info System
  30. **
  31. ** Description: Lays out the information on a canvas.
  32. **
  33. ** (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992 Hewlett-Packard Company
  34. **
  35. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  36. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  37. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  38. ** (c) Copyright 1993, 1994 Novell, Inc.
  39. **
  40. **
  41. ****************************************************************************
  42. ************************************<+>*************************************/
  43. /*
  44. * system includes
  45. */
  46. #include <stdlib.h>
  47. #include <stdio.h>
  48. #include <string.h>
  49. #include <limits.h>
  50. /*
  51. * Canvas Engine includes
  52. */
  53. #include "CanvasP.h"
  54. #include "CanvasSegP.h"
  55. /*
  56. * private includes
  57. */
  58. #include "bufioI.h"
  59. #include "CanvasI.h"
  60. #include "CvStringI.h"
  61. #include "LayoutUtilI.h"
  62. #include "SelectionI.h"
  63. #include "VirtFuncsI.h"
  64. /******************************************************************************
  65. *
  66. * Private Macros
  67. *
  68. *****************************************************************************/
  69. #define ObjHorizOrient(x) (_DtCvContainerOrientOfSeg(x))
  70. #define ObjVertOrient(x) (_DtCvContainerVOrientOfSeg(x))
  71. #define TxtHorizJustify(x) (_DtCvContainerJustifyOfSeg(x))
  72. #define TxtVertJustify(x) (_DtCvContainerVJustifyOfSeg(x))
  73. #define Border(x) (_DtCvContainerBorderOfSeg(x))
  74. #define BrdWidth(x) (_DtCvContainerLineWidthOfSeg(x))
  75. #define BrdData(x) (_DtCvContainerLineDataOfSeg(x))
  76. #define NotJoining(x) (False == (x)->info.join)
  77. #define JoinSet(x) (True == (x)->info.join)
  78. #define CheckAddToHyperList(a, b) \
  79. _DtCvCheckAddHyperToTravList(a, b, _DtCvTRUE, \
  80. &(layout->info.lst_vis), \
  81. &(layout->info.lst_hyper), &(layout->info.cur_len))
  82. /*****************************************************************************
  83. * Private Defines
  84. *****************************************************************************/
  85. /*
  86. * Defines for the dimension arrays
  87. */
  88. #define DIMS_LEFT 0
  89. #define DIMS_RIGHT 1
  90. #define DIMS_LM 0
  91. #define DIMS_CENTER 1
  92. #define DIMS_RM 2
  93. #define DIMS_TOP 0
  94. #define DIMS_BOTTOM 2
  95. #define DIMS_WIDTH 0
  96. #define DIMS_HEIGHT 1
  97. #define DIMS_YPOS 1
  98. #define DIMS_TC 0
  99. #define DIMS_BC 1
  100. /*
  101. */
  102. #define GROW_SIZE 10
  103. /******************************************************************************
  104. *
  105. * Private typedefs
  106. *
  107. *****************************************************************************/
  108. /*
  109. * top/bottom dimension array
  110. * -------------------------------------------
  111. * / DIMS_HEIGHT / DIMS_HEIGHT / DIMS_HEIGHT /|
  112. * / DIMS_YPOS / DIMS_YPOS / DIMS_YPOS / |
  113. * /-------------/-------------/-------------/ |
  114. * / DIMS_WIDTH / DIMS_WIDTH / DIMS_WIDTH /| /|
  115. * --------------|-------------|-------------| |/ |
  116. * DIMS_TOP | DIMS_LM | DIMS_CENTER | DIMS_RM | | /|
  117. * |-------------|-------------|-------------|/|/ |
  118. * unused | | | | | /
  119. * |-------------|-------------|-------------|/|/
  120. * DIMS_BOTTOM | DIMS_LM | DIMS_CENTER | DIMS_RM | /
  121. * ------------------------------------------|/
  122. */
  123. typedef _DtCvUnit TopDims[DIMS_BOTTOM+1][DIMS_RM+1][DIMS_HEIGHT+1];
  124. /*
  125. * left/right side dimension array - contains only the height or y_pos.
  126. * ----------------------------
  127. * DIMS_TOP | DIMS_LEFT | DIMS_RIGHT |
  128. * |------------|-------------|
  129. * DIMS_CENTER | DIMS_LEFT | DIMS_RIGHT |
  130. * |------------|-------------|
  131. * DIMS_BOTTOM | DIMS_LEFT | DIMS_RIGHT |
  132. * ----------------------------
  133. */
  134. typedef _DtCvUnit SideDims[DIMS_BOTTOM+1][DIMS_RIGHT+1];
  135. /*
  136. * corner dimension array - contains only the height or y_pos.
  137. * ----------------------------
  138. * DIMS_TC | DIMS_LEFT | DIMS_RIGHT |
  139. * |------------|-------------|
  140. * DIMS_BC | DIMS_LEFT | DIMS_RIGHT |
  141. * ----------------------------
  142. */
  143. typedef _DtCvUnit CornerDims[DIMS_BC+1][DIMS_RIGHT+1];
  144. /*
  145. * flow dimension array
  146. * -------------|--------------
  147. * DIMS_LEFT | DIMS_WIDTH | DIMS_HEIGHT |
  148. * | | DIMS_YPOS |
  149. * |------------|-------------|
  150. * DIMS_RIGHT | DIMS_WIDTH | DIMS_HEIGHT |
  151. * | | DIMS_YPOS |
  152. * ----------------------------
  153. */
  154. typedef _DtCvUnit FlowDims[DIMS_RIGHT+1][DIMS_HEIGHT+1];
  155. /*
  156. * margin data - important for determining flowing
  157. */
  158. typedef struct _dataPoint {
  159. _DtCvUnit left;
  160. _DtCvUnit right;
  161. _DtCvUnit y_pos;
  162. _DtCvUnit x_units;
  163. struct _dataPoint *next_pt;
  164. } DataPoint;
  165. /*
  166. * count information
  167. */
  168. typedef struct _cntInfo {
  169. int beg_txt;
  170. int end_txt;
  171. int beg_ln;
  172. int end_ln;
  173. int my_lines;
  174. int beg_brk;
  175. int end_brk;
  176. } CntInfo;
  177. /*
  178. * group information
  179. */
  180. typedef struct _grpInfo {
  181. _DtCvUnit min_x;
  182. _DtCvUnit max_x;
  183. _DtCvUnit top_y;
  184. _DtCvUnit bot_y;
  185. CntInfo cnt;
  186. struct _grpInfo *next_info;
  187. } GrpInfo;
  188. /*
  189. * layout information per container
  190. */
  191. typedef struct _layFrmtInfo {
  192. _DtCvUnit height;
  193. _DtCvUnit width;
  194. CntInfo cnt;
  195. struct _layFrmtInfo *next_info;
  196. } LayFrmtInfo;
  197. /*
  198. * the layout information carried around
  199. */
  200. typedef struct _layoutInfo {
  201. _DtCvUnit max_width; /* the current max width */
  202. _DtCvUnit id_Ypos; /* the y coordinate of the id found. */
  203. _DtCvUnit left; /* the current left margin for the
  204. current active container (incl br)*/
  205. _DtCvUnit right; /* the current right margin for the
  206. current active container (incl br)*/
  207. _DtCvUnit first; /* the current first indent */
  208. _DtCvUnit lmargin; /* the current absolute left margin */
  209. _DtCvUnit rmargin; /* the current absolute right margin */
  210. _DtCvUnit divisor; /* the current margin divisor */
  211. _DtCvUnit string_end;
  212. _DtCvUnit sub_end;
  213. _DtCvUnit super_end;
  214. _DtCvValue id_found; /* indicates if the id has been found*/
  215. _DtCvValue super_script;
  216. _DtCvValue sub_script;
  217. _DtCvValue stat_flag;
  218. _DtCvValue margin_non_zero;
  219. _DtCvValue brdr_flag; /* within container with a border */
  220. _DtCvValue table_flag; /* within table */
  221. _DtCvFrmtOption txt_justify;
  222. unsigned int cur_start; /* offset into the current segment
  223. to process */
  224. _DtCvSegmentI *lst_rendered; /* indicates the last string/region */
  225. char *target_id; /* if non-null, the id to search for */
  226. DataPoint *data_pts;
  227. GrpInfo *grp_lst; /* list of groups */
  228. _DtCvLayoutInfo info;
  229. } LayoutInfo;
  230. /*
  231. * information for laying out cells in a table.
  232. */
  233. typedef struct {
  234. int col_spn;
  235. int row_spn;
  236. _DtCvUnit pos_x;
  237. LayFrmtInfo info;
  238. _DtCvSegmentI *cell_seg;
  239. } CellInfo;
  240. /*
  241. * column description information for a table.
  242. */
  243. typedef struct _columnSpec {
  244. _DtCvUnit min;
  245. _DtCvUnit max;
  246. _DtCvUnit actual;
  247. _DtCvValue hanger;
  248. _DtCvFrmtOption justify;
  249. } ColumnSpec;
  250. /*
  251. * row description information
  252. */
  253. typedef struct _rowSpec {
  254. int column;
  255. _DtCvUnit y_adj;
  256. _DtCvUnit height;
  257. _DtCvUnit lst_height;
  258. char *next_id;
  259. } RowSpec;
  260. /*****************************************************************************
  261. * Private Variables/Data
  262. *****************************************************************************/
  263. static const LayFrmtInfo DefLayFrmtInfo = { 0, 0, {-1, -1, -1, -1, 0}, NULL };
  264. static const GrpInfo DefGrpInfo = { 0, 0, 0, 0, {-1, -1, -1, -1, 0}};
  265. static const LayoutInfo DefInfo = {
  266. 0, /* _DtCvUnit max_width; */
  267. 0, /* _DtCvUnit id_Ypos; */
  268. 0, /* _DtCvUnit left; */
  269. 0, /* _DtCvUnit right; */
  270. 0, /* _DtCvUnit first; */
  271. 0, /* _DtCvUnit lmargin; */
  272. 0, /* _DtCvUnit rmargin; */
  273. 1, /* _DtCvUnit divisor; */
  274. 0, /* _DtCvUnit string_end; */
  275. 0, /* _DtCvUnit sub_end; */
  276. 0, /* _DtCvUnit super_end; */
  277. False, /* _DtCvValue id_found; */
  278. False, /* _DtCvValue super_script; */
  279. False, /* _DtCvValue sub_script; */
  280. False, /* _DtCvValue stat_flag; */
  281. False, /* _DtCvValue margin_non_zero; */
  282. False, /* _DtCvValue brdr_flag; */
  283. False, /* _DtCvValue table_flag; */
  284. _DtCvJUSTIFY_LEFT, /* _DtCvFrmtOption txt_justify; */
  285. 0, /* unsigned int cur_start; */
  286. NULL, /* _DtCvSegmentI *lst_rendered; */
  287. NULL, /* char *target_id; */
  288. NULL, /* DataPoint *data_pts; */
  289. NULL, /* GrpInfo *data_pts; */
  290. };
  291. static const DataPoint DefDataPt = { 0, 0, _CEFORMAT_ALL, 0, NULL};
  292. static const double HeadDivisor = 10000.0;
  293. static const char *PeriodStr = ".";
  294. static const char *DefWidth[2] = { "", NULL };
  295. static const _DtCvSegmentI BlankTableCell =
  296. {
  297. _DtCvCONTAINER, /* type */
  298. -1, /* link_idx */
  299. { /* container info */
  300. NULL, /* id */
  301. NULL, /* justify_char */
  302. _DtCvDYNAMIC, /* type */
  303. _DtCvBORDER_NONE, /* border */
  304. _DtCvJUSTIFY_LEFT, /* justify */
  305. _DtCvJUSTIFY_TOP, /* vjustify */
  306. _DtCvJUSTIFY_LEFT, /* orient */
  307. _DtCvJUSTIFY_TOP, /* vorient */
  308. _DtCvWRAP_NONE, /* flow */
  309. 0, /* percent */
  310. 0, /* leading */
  311. 0, /* fmargin */
  312. 0, /* lmargin */
  313. 0, /* rmargin */
  314. 0, /* tmargin */
  315. 0, /* bmargin */
  316. _DtCvBORDER_NONE, /* bdr_info */
  317. NULL /* seg_list */
  318. },
  319. NULL, /* next_seg */
  320. NULL, /* next_disp */
  321. NULL, /* client_use */
  322. NULL /* internal_use */
  323. };
  324. /*****************************************************************************
  325. * Private Function Declarations
  326. *****************************************************************************/
  327. static void AdjustForBorders(
  328. _DtCanvasStruct *canvas,
  329. LayoutInfo *layout,
  330. _DtCvFrmtOption brdr,
  331. _DtCvUnit line_width,
  332. _DtCvUnit *ret_bot,
  333. _DtCvUnit *ret_right);
  334. static void AdjustHeadPosition(
  335. _DtCanvasStruct *canvas,
  336. LayoutInfo *layout,
  337. _DtCvSegmentI *p_seg,
  338. TopDims *top_bot,
  339. SideDims *side,
  340. CornerDims *corner,
  341. FlowDims *flow,
  342. LayFrmtInfo *info,
  343. _DtCvUnit base_y,
  344. _DtCvUnit base_left,
  345. _DtCvUnit block_width,
  346. _DtCvUnit left_margin,
  347. _DtCvUnit right_margin);
  348. static void AdjustObjectPosition(
  349. _DtCanvasStruct *canvas,
  350. LayoutInfo *layout,
  351. _DtCvFrmtOption justify,
  352. int start_txt,
  353. int start_ln,
  354. int start_brk,
  355. int end_txt,
  356. int end_ln,
  357. int end_brk,
  358. int brdr_cnt,
  359. _DtCvUnit height_adj,
  360. _DtCvUnit x_adj,
  361. _DtCvUnit y_adj,
  362. _DtCvUnit internal_y);
  363. static void CheckSaveInfo (
  364. _DtCanvasStruct *canvas,
  365. LayoutInfo *layout,
  366. _DtCvSegmentI *new_seg,
  367. int start);
  368. static void DetermineFlowConstraints(
  369. LayoutInfo *layout,
  370. FlowDims flow_dims,
  371. _DtCvUnit left_margin,
  372. _DtCvUnit right_margin,
  373. _DtCvUnit start_y,
  374. DataPoint *left_pt,
  375. DataPoint *right_pt);
  376. static void DetermineHeadPositioning(
  377. TopDims *top_bot,
  378. SideDims *side,
  379. CornerDims *corner,
  380. FlowDims *flow,
  381. _DtCvUnit start_y,
  382. _DtCvUnit max_top,
  383. _DtCvUnit block_size,
  384. _DtCvUnit *ret_side_size);
  385. static void DetermineMaxDims(
  386. TopDims *top_bot,
  387. CornerDims *corner,
  388. _DtCvUnit left_margin,
  389. _DtCvUnit right_margin,
  390. _DtCvUnit *top_height,
  391. _DtCvUnit *bot_height,
  392. _DtCvUnit *max_width);
  393. static int DrawBorders(
  394. _DtCanvasStruct *canvas,
  395. LayoutInfo *layout,
  396. _DtCvFrmtOption brdr,
  397. _DtCvPointer data,
  398. _DtCvUnit line_width,
  399. _DtCvUnit top_y,
  400. _DtCvUnit bot_y,
  401. _DtCvUnit left_x,
  402. _DtCvUnit right_x);
  403. static void FormatCell(
  404. _DtCanvasStruct *canvas,
  405. LayoutInfo *layout,
  406. _DtCvSegmentI *cell_seg,
  407. _DtCvUnit span_width,
  408. _DtCvUnit min_height,
  409. DataPoint base_pt,
  410. int *ret_ln,
  411. _DtCvUnit *ret_width,
  412. _DtCvUnit *ret_height,
  413. _DtCvValue *ret_tab_flag);
  414. static void InitDimArrays(
  415. TopDims *top_bot,
  416. SideDims *side,
  417. CornerDims *corner,
  418. FlowDims *flow);
  419. static _DtCvStatus LayoutCanvasInfo (
  420. _DtCanvasStruct *canvas,
  421. LayoutInfo *layout,
  422. _DtCvUnit divisor,
  423. char *target_id);
  424. static _DtCvValue LinesMayChange(
  425. _DtCanvasStruct *canvas,
  426. int start_ln,
  427. int end_ln,
  428. int brdr_cnt);
  429. static _DtCvUnit MoveGroup (
  430. _DtCanvasStruct *canvas,
  431. LayoutInfo *layout,
  432. GrpInfo *tst_grp,
  433. _DtCvUnit needed);
  434. static _DtCvUnit MoveLines (
  435. _DtCanvasStruct *canvas,
  436. LayoutInfo *layout,
  437. int idx,
  438. _DtCvUnit top_y,
  439. _DtCvUnit bot_y,
  440. _DtCvUnit needed);
  441. static _DtCvUnit MoveText (
  442. _DtCanvasStruct *canvas,
  443. LayoutInfo *layout,
  444. int idx,
  445. _DtCvUnit top_y,
  446. _DtCvUnit bot_y,
  447. _DtCvUnit needed);
  448. static void ProcessContainer(
  449. _DtCanvasStruct *canvas,
  450. LayoutInfo *layout,
  451. _DtCvSegmentI *con_seg,
  452. _DtCvUnit min_y,
  453. _DtCvUnit *ret_width,
  454. _DtCvUnit *ret_max_x,
  455. int *ret_cnt);
  456. static void ProcessSegmentList(
  457. _DtCanvasStruct *canvas,
  458. LayoutInfo *layout,
  459. _DtCvSegmentI *cur_seg,
  460. _DtCvUnit min_y,
  461. _DtCvUnit *ret_width,
  462. _DtCvUnit *ret_max_x,
  463. int **ret_vert);
  464. /******************************************************************************
  465. *
  466. * Private Functions
  467. *
  468. *****************************************************************************/
  469. /******************************************************************************
  470. * Function: AdjustTextPositions
  471. *
  472. * changes the baseline and text_x positioning of the text line by the
  473. * offsets indicated.
  474. *****************************************************************************/
  475. static void
  476. AdjustTextPositions(
  477. _DtCanvasStruct *canvas,
  478. int beg,
  479. int end,
  480. _DtCvUnit x_offset,
  481. _DtCvUnit y_offset)
  482. {
  483. if ( 0 != y_offset || 0 != x_offset)
  484. {
  485. while (beg < end)
  486. {
  487. canvas->txt_lst[beg].baseline += y_offset;
  488. canvas->txt_lst[beg].text_x += x_offset;
  489. beg++;
  490. }
  491. }
  492. }
  493. /******************************************************************************
  494. * Function: AdjustLinePositions
  495. *
  496. * changes the x & positions and the max x & y values by the offsets indicated.
  497. *****************************************************************************/
  498. static void
  499. AdjustLinePositions(
  500. _DtCanvasStruct *canvas,
  501. int beg,
  502. int end,
  503. _DtCvUnit x_offset,
  504. _DtCvUnit y_offset)
  505. {
  506. if ( 0 != y_offset || 0 != x_offset)
  507. {
  508. while (beg < end)
  509. {
  510. canvas->line_lst[beg].pos_y += y_offset;
  511. canvas->line_lst[beg].max_y += y_offset;
  512. canvas->line_lst[beg].pos_x += x_offset;
  513. canvas->line_lst[beg].max_x += x_offset;
  514. beg++;
  515. }
  516. }
  517. }
  518. /******************************************************************************
  519. * Function: AdjustPgBrk
  520. *
  521. * changes the y position of a page break.
  522. *****************************************************************************/
  523. static void
  524. AdjustPgBrk(
  525. _DtCanvasStruct *canvas,
  526. int beg,
  527. int end,
  528. _DtCvUnit y_offset)
  529. {
  530. if (0 != y_offset)
  531. {
  532. while (beg < end)
  533. canvas->pg_breaks[beg++] += y_offset;
  534. }
  535. }
  536. /******************************************************************************
  537. * Function: MaxXOfLine
  538. *
  539. * MaxXOfLine determines the max X of a line segment.
  540. *
  541. *****************************************************************************/
  542. /******************************************************************************
  543. * Function: MaxXOfLine
  544. *
  545. * MaxXOfLine determines the max X of a line segment.
  546. *
  547. *****************************************************************************/
  548. static _DtCvUnit
  549. MaxXOfLine(
  550. _DtCanvasStruct *canvas,
  551. _DtCvDspLine *line)
  552. {
  553. _DtCvValue lastLinkVisible = FALSE;
  554. int count = line->length;
  555. int start = line->byte_index;
  556. int len;
  557. int lnkInd = -1;
  558. _DtCvUnit xPos;
  559. _DtCvUnit tmpWidth;
  560. _DtCvSegmentI *pSeg;
  561. xPos = _DtCvGetStartXOfLine(line, &pSeg);
  562. while (pSeg != NULL && count > 0)
  563. {
  564. xPos = _DtCvAdvanceXOfLine(canvas, pSeg, xPos,
  565. &lnkInd, &lastLinkVisible);
  566. _DtCvGetWidthOfSegment(canvas, pSeg, start, count,
  567. &len, &tmpWidth, NULL);
  568. xPos += tmpWidth;
  569. count -= len;
  570. start = 0;
  571. pSeg = pSeg->next_disp;
  572. }
  573. return xPos;
  574. } /* End MaxXOfLine */
  575. /*****************************************************************************
  576. * Function: void GetLinkInfo ()
  577. *
  578. * Parameters:
  579. * canvas Specifies the handle for the canvas.
  580. *
  581. * Returns: A handle to the canvas or NULL if an error occurs.
  582. *
  583. * Purpose:
  584. *
  585. *****************************************************************************/
  586. static _DtCvValue
  587. GetLinkInfo (
  588. _DtCvHandle canvas_handle,
  589. int indx,
  590. _DtCvUnit *ret_x,
  591. _DtCvUnit *ret_y,
  592. _DtCvUnit *ret_width,
  593. _DtCvUnit *ret_height)
  594. {
  595. int len;
  596. int line;
  597. int count;
  598. int startChar;
  599. int lnkIndx = -1;
  600. _DtCvUnit startX;
  601. _DtCanvasStruct *canvas = (_DtCanvasStruct *) canvas_handle;
  602. _DtCvSegmentI *pSeg;
  603. _DtCvValue lstVisible = False;
  604. _DtCvValue found = False;
  605. _DtCvValue junk;
  606. _DtCvUnit endX = 0;
  607. void *pChar;
  608. /*
  609. * get the line index
  610. */
  611. line = canvas->trav_lst[indx].idx;
  612. /*
  613. * get some information from the line
  614. */
  615. pSeg = canvas->txt_lst[line].seg_ptr;
  616. count = canvas->txt_lst[line].length;
  617. startChar = canvas->txt_lst[line].byte_index;
  618. startX = canvas->txt_lst[line].text_x;
  619. *ret_y = canvas->txt_lst[line].baseline - canvas->txt_lst[line].ascent;
  620. *ret_height = canvas->txt_lst[line].ascent + canvas->txt_lst[line].descent;
  621. while (count > 0 && !found && pSeg != NULL)
  622. {
  623. if (startX < canvas->txt_lst[line].text_x)
  624. startX = canvas->txt_lst[line].text_x;
  625. /*
  626. * adjust the starting position by the link space
  627. */
  628. junk = _DtCvIsSegVisibleLink(pSeg);
  629. lstVisible = _DtCvModifyXpos (canvas->link_info, pSeg, junk,
  630. lstVisible, lnkIndx, &startX);
  631. /*
  632. * adjust the starting position by the traversal space
  633. */
  634. junk = _DtCvIsSegALink(pSeg);
  635. (void) _DtCvModifyXpos (canvas->traversal_info, pSeg, junk,
  636. ((_DtCvValue) True), lnkIndx, &startX);
  637. lnkIndx = pSeg->link_idx;
  638. /*
  639. * skip no-op
  640. */
  641. if (_DtCvIsSegNoop(pSeg))
  642. len = 0;
  643. /*
  644. * check region
  645. */
  646. else if (_DtCvIsSegRegion(pSeg))
  647. {
  648. len = 1;
  649. endX = startX + _DtCvWidthOfRegionSeg(pSeg);
  650. }
  651. else
  652. {
  653. /*
  654. * initialize the pointer to the string
  655. */
  656. pChar = _DtCvStrPtr(_DtCvStringOfStringSeg(pSeg),
  657. _DtCvIsSegWideChar(pSeg), startChar);
  658. /*
  659. * get the length of the current string.
  660. * If it is longer than the line count indicates,
  661. * it must be wrapped to the next line. We are
  662. * only interested in in the part of the line
  663. * that is on the line selected.
  664. */
  665. len = _DtCvStrLen (pChar, _DtCvIsSegWideChar(pSeg));
  666. if (len > count)
  667. len = count;
  668. /*
  669. * calculate the ending pixel postion for
  670. * this string segment.
  671. */
  672. endX = startX + _DtCvGetStringWidth(canvas,pSeg,pChar,len);
  673. }
  674. /*
  675. * test to see if the selected segment was this segment.
  676. */
  677. if (pSeg == canvas->trav_lst[indx].seg_ptr)
  678. {
  679. found = True;
  680. *ret_x = startX;
  681. *ret_width = endX - startX;
  682. }
  683. else
  684. {
  685. /*
  686. * go to the next segment.
  687. */
  688. pSeg = pSeg->next_disp;
  689. /*
  690. * adjust for the new begining.
  691. */
  692. startX = endX;
  693. count = count - len;
  694. startChar = 0;
  695. }
  696. }
  697. return found;
  698. }
  699. /******************************************************************************
  700. * Function: CheckId
  701. *
  702. * Check to see if the id matches the target id.
  703. * If so, set the 'found id' flag and indicate its y coordinate.
  704. *****************************************************************************/
  705. static void
  706. CheckId(
  707. LayoutInfo *layout,
  708. char *id)
  709. {
  710. if (layout->target_id != NULL && NULL != id &&
  711. _DtCvStrCaseCmpLatin1(id, layout->target_id) == 0)
  712. {
  713. layout->id_Ypos = layout->info.y_pos;
  714. layout->id_found = True;
  715. }
  716. }
  717. /******************************************************************************
  718. * Function: CheckSetLineStart
  719. *
  720. * Check to see if the line information is at the beginning.
  721. * If so, set the pointers to the current segment and offset.
  722. *****************************************************************************/
  723. static void
  724. CheckSetLineStart(
  725. LayoutInfo *layout,
  726. _DtCvSegmentI *cur_seg)
  727. {
  728. if (layout->info.line_bytes == 0)
  729. {
  730. layout->info.line_seg = cur_seg;
  731. layout->info.line_start = 0;
  732. }
  733. }
  734. /******************************************************************************
  735. * Function: CheckForPageBreak
  736. *
  737. * Check to see if there is a page break on this segment.
  738. * If so, remember its position.
  739. *****************************************************************************/
  740. static int
  741. CheckForPageBreak(
  742. _DtCanvasStruct *canvas,
  743. _DtCvSegmentI *cur_seg,
  744. _DtCvUnit position)
  745. {
  746. /*
  747. * does this segment cause a page break?
  748. */
  749. if (_DtCvIsSegPageBreak(cur_seg))
  750. {
  751. /*
  752. * check to see if there is room to save the page break.
  753. * if not, allocate more room.
  754. */
  755. if (canvas->brk_cnt >= canvas->brk_max)
  756. {
  757. canvas->brk_max += GROW_SIZE;
  758. if (NULL != canvas->pg_breaks)
  759. canvas->pg_breaks = (_DtCvUnit *) realloc (
  760. (void *) canvas->pg_breaks,
  761. (sizeof(_DtCvUnit) * canvas->brk_max));
  762. else
  763. canvas->pg_breaks = (_DtCvUnit *) malloc (
  764. (sizeof(_DtCvUnit) * canvas->brk_max));
  765. }
  766. /*
  767. * failed to allocate memory, abort.
  768. */
  769. if (NULL == canvas->pg_breaks)
  770. {
  771. canvas->brk_max = 0;
  772. canvas->brk_cnt = 0;
  773. return 1;
  774. }
  775. /*
  776. * save the y position of the page break for later.
  777. */
  778. canvas->pg_breaks[canvas->brk_cnt++] = position;
  779. }
  780. return 0;
  781. }
  782. /******************************************************************************
  783. * Function: SetBeginCounts
  784. *
  785. * Parameters:
  786. * canvas Specifies the canvas.
  787. * f_info Specifies the layout count info.
  788. *
  789. * Returns: Nothing
  790. *
  791. * Purpose: Initializes the layout count information for a container.
  792. *****************************************************************************/
  793. static void
  794. SetBeginCounts (
  795. _DtCanvasStruct *canvas,
  796. CntInfo *cnt_info)
  797. {
  798. /*
  799. * text counts
  800. */
  801. cnt_info->beg_txt = canvas->txt_cnt;
  802. cnt_info->end_txt = canvas->txt_cnt;
  803. /*
  804. * line counts
  805. */
  806. cnt_info->beg_ln = canvas->line_cnt;
  807. cnt_info->end_ln = canvas->line_cnt;
  808. /*
  809. * break counts
  810. */
  811. cnt_info->beg_brk = canvas->brk_cnt;
  812. cnt_info->end_brk = canvas->brk_cnt;
  813. }
  814. /******************************************************************************
  815. * Function: SetEndCounts
  816. *
  817. * Parameters:
  818. * canvas Specifies the canvas.
  819. * f_info Specifies the layout count info.
  820. *
  821. * Returns: Nothing
  822. *
  823. * Purpose: Sets the ending layout counts for a container.
  824. *****************************************************************************/
  825. static void
  826. SetEndCounts (
  827. _DtCanvasStruct *canvas,
  828. CntInfo *cnt_info,
  829. int end_ln)
  830. {
  831. /*
  832. * text counts
  833. */
  834. cnt_info->end_txt = canvas->txt_cnt;
  835. /*
  836. * line counts
  837. */
  838. cnt_info->end_ln = canvas->line_cnt;
  839. /*
  840. * break counts
  841. */
  842. cnt_info->end_brk = canvas->brk_cnt;
  843. /*
  844. * the number of lines for this container.
  845. * If negative, indicates the first line is for the
  846. * bottom of the container and goes the length.
  847. */
  848. cnt_info->my_lines = end_ln;
  849. }
  850. /******************************************************************************
  851. * Function: SkipToNumber
  852. *
  853. * Returns:
  854. *****************************************************************************/
  855. static void
  856. SkipToNumber (
  857. const char **string)
  858. {
  859. if (string != NULL)
  860. {
  861. const char *str = *string;
  862. while (*str == ' ' && *str != '\0')
  863. str++;
  864. *string = str;
  865. }
  866. }
  867. /******************************************************************************
  868. * Function: GetValueFromString
  869. *
  870. * Returns:
  871. *****************************************************************************/
  872. static int
  873. GetValueFromString (
  874. const char **string,
  875. int def_num)
  876. {
  877. int value = def_num;
  878. if (string != NULL && *string != NULL && **string != '\0')
  879. {
  880. const char *str = *string;
  881. if ('0' <= *str && *str <= '9')
  882. value = atoi(str);
  883. while ('0' <= *str && *str <= '9')
  884. str++;
  885. while (*str != ' ' && *str != '\0' && (*str < '0' || *str > '9'))
  886. str++;
  887. *string = str;
  888. }
  889. return value;
  890. }
  891. /******************************************************************************
  892. * Function: PushDataPoint
  893. *
  894. * Returns:
  895. *****************************************************************************/
  896. static void
  897. PushDataPoint (
  898. LayoutInfo *layout,
  899. DataPoint *data_pt)
  900. {
  901. data_pt->x_units = 0;
  902. data_pt->next_pt = layout->data_pts;
  903. layout->data_pts = data_pt;
  904. }
  905. /******************************************************************************
  906. * Function: InsertDataPoint
  907. *
  908. * Returns:
  909. *****************************************************************************/
  910. static void
  911. InsertDataPoint (
  912. LayoutInfo *layout,
  913. DataPoint *data_pt)
  914. {
  915. DataPoint *lastPt = NULL;
  916. DataPoint *nextPt = layout->data_pts;
  917. while (nextPt != NULL &&
  918. nextPt->y_pos != _CEFORMAT_ALL &&
  919. (data_pt->y_pos == _CEFORMAT_ALL || nextPt->y_pos < data_pt->y_pos))
  920. {
  921. lastPt = nextPt;
  922. nextPt = nextPt->next_pt;
  923. }
  924. data_pt->next_pt = nextPt;
  925. data_pt->x_units = 0;
  926. if (lastPt == NULL)
  927. layout->data_pts = data_pt;
  928. else
  929. lastPt->next_pt = data_pt;
  930. }
  931. /******************************************************************************
  932. * Function: RemoveDataPoint
  933. *
  934. * Returns:
  935. *****************************************************************************/
  936. static void
  937. RemoveDataPoint (
  938. LayoutInfo *layout,
  939. DataPoint *data_pt)
  940. {
  941. DataPoint *lastPt = NULL;
  942. DataPoint *curPt = layout->data_pts;
  943. while (curPt != NULL && curPt != data_pt)
  944. {
  945. lastPt = curPt;
  946. curPt = curPt->next_pt;
  947. }
  948. if (curPt != NULL)
  949. {
  950. data_pt->x_units = layout->info.cur_max_x - data_pt->left;
  951. if (lastPt == NULL)
  952. layout->data_pts = curPt->next_pt;
  953. else
  954. lastPt->next_pt = curPt->next_pt;
  955. }
  956. }
  957. /******************************************************************************
  958. * Function: GetCurrentDataPoint
  959. *
  960. * Returns:
  961. *****************************************************************************/
  962. static void
  963. GetCurrentDataPoint (
  964. LayoutInfo *layout,
  965. DataPoint *data_pt)
  966. {
  967. data_pt->left = 0;
  968. data_pt->right = 0;
  969. data_pt->y_pos = _CEFORMAT_ALL;
  970. if (layout->data_pts != NULL)
  971. *data_pt = *(layout->data_pts);
  972. }
  973. /******************************************************************************
  974. * Function: SetMargins
  975. *
  976. * Purpose: Sets the margins.
  977. *****************************************************************************/
  978. static void
  979. SetMargins (
  980. LayoutInfo *layout)
  981. {
  982. layout->lmargin = 0;
  983. layout->rmargin = 0;
  984. layout->info.format_y = _CEFORMAT_ALL;
  985. if (layout->data_pts != NULL)
  986. {
  987. /*
  988. * base
  989. */
  990. layout->lmargin = layout->data_pts->left;
  991. layout->rmargin = layout->data_pts->right;
  992. layout->info.format_y = layout->data_pts->y_pos;
  993. }
  994. layout->lmargin += layout->left;
  995. layout->rmargin += layout->right;
  996. }
  997. /******************************************************************************
  998. * Function: SetTextPosition
  999. *
  1000. * Purpose: Sets the text beginning position to the left margin.
  1001. * If 'first' is true, adds its value to the text beginning
  1002. * position value.
  1003. *****************************************************************************/
  1004. static void
  1005. SetTextPosition (
  1006. LayoutInfo *layout,
  1007. _DtCvValue first)
  1008. {
  1009. layout->info.text_x_pos = layout->lmargin;
  1010. if (first == True)
  1011. layout->info.text_x_pos += layout->first;
  1012. }
  1013. /******************************************************************************
  1014. * Function: CheckFormat
  1015. *
  1016. * Purpose: Checks to see if the flowing txt boundaries have been exceeded.
  1017. * If a boundary has been exceeded, then removes that boundary
  1018. * information from the stack until it finds a valid boundary point.
  1019. *
  1020. * Calls SetMargins to set the correct margin
  1021. * Calls SetTextPosition to set the text beginning position.
  1022. *****************************************************************************/
  1023. static void
  1024. CheckFormat (
  1025. LayoutInfo *layout,
  1026. _DtCvValue first)
  1027. {
  1028. while (layout->data_pts != NULL &&
  1029. layout->data_pts->y_pos != _CEFORMAT_ALL &&
  1030. layout->data_pts->y_pos < layout->info.y_pos)
  1031. RemoveDataPoint (layout, layout->data_pts);
  1032. SetMargins(layout);
  1033. SetTextPosition(layout, first);
  1034. }
  1035. /******************************************************************************
  1036. * Function: SaveLine
  1037. *
  1038. * Initializes a line table element to the segment it should display.
  1039. *****************************************************************************/
  1040. static void
  1041. SaveLine (
  1042. _DtCanvasStruct *canvas,
  1043. LayoutInfo *layout,
  1044. int direction,
  1045. _DtCvPointer data,
  1046. _DtCvUnit line_width,
  1047. _DtCvUnit x,
  1048. _DtCvUnit y,
  1049. _DtCvUnit length)
  1050. {
  1051. int i = canvas->line_cnt;
  1052. _DtCvUnit x2 = x;
  1053. _DtCvUnit y2 = y;
  1054. if (i >= canvas->line_max)
  1055. {
  1056. canvas->line_max += GROW_SIZE;
  1057. if (canvas->line_lst)
  1058. canvas->line_lst = (_DtCvLineSeg *) realloc (
  1059. (void *) canvas->line_lst,
  1060. (sizeof(_DtCvLineSeg) * canvas->line_max));
  1061. else
  1062. canvas->line_lst = (_DtCvLineSeg *) malloc (
  1063. (sizeof(_DtCvLineSeg) * canvas->line_max));
  1064. /*
  1065. * NOTE....should this routine return a value?
  1066. * If (re)alloc error occurs, this simply ignores the problem.
  1067. */
  1068. if (canvas->line_lst == NULL)
  1069. {
  1070. canvas->line_max = 0;
  1071. canvas->line_cnt = 0;
  1072. return;
  1073. }
  1074. }
  1075. /*
  1076. * does this line exceed the current maximum?
  1077. */
  1078. if (_DtCvLINE_HORZ == direction)
  1079. {
  1080. x2 += length;
  1081. y2 += line_width;
  1082. }
  1083. else
  1084. {
  1085. x2 += line_width;
  1086. y2 += length;
  1087. }
  1088. if (layout->info.max_x_pos < x2)
  1089. layout->info.max_x_pos = x2;
  1090. if (layout->info.cur_max_x < x2)
  1091. layout->info.cur_max_x = x2;
  1092. /*
  1093. * save the line information
  1094. */
  1095. canvas->line_lst[i].dir = direction;
  1096. canvas->line_lst[i].pos_x = x;
  1097. canvas->line_lst[i].max_x = x2;
  1098. canvas->line_lst[i].pos_y = y;
  1099. canvas->line_lst[i].max_y = y2;
  1100. canvas->line_lst[i].width = line_width;
  1101. canvas->line_lst[i].data = data;
  1102. canvas->line_cnt++;
  1103. }
  1104. /******************************************************************************
  1105. * Function: SaveInfo
  1106. *
  1107. * Purpose: Saves the current information into the txt line struct.
  1108. * Checks to see if this line exceeds the flowing text
  1109. * boundary and resets the internal global margins.
  1110. *****************************************************************************/
  1111. static void
  1112. SaveInfo (
  1113. _DtCanvasStruct *canvas,
  1114. LayoutInfo *layout,
  1115. _DtCvSegmentI *new_seg,
  1116. int start)
  1117. {
  1118. _DtCvSaveInfo (canvas, &(layout->info),
  1119. layout->max_width, layout->rmargin, layout->txt_justify);
  1120. while (layout->info.delayed_search_saves > 0) {
  1121. _DtCvSetSearchEntryInfo(canvas, canvas->txt_cnt - 1);
  1122. layout->info.delayed_search_saves--;
  1123. }
  1124. layout->super_end = 0;
  1125. layout->sub_end = 0;
  1126. layout->super_script = False;
  1127. layout->sub_script = False;
  1128. layout->info.line_seg = new_seg;
  1129. layout->info.line_start = start;
  1130. layout->info.cur_len = 0;
  1131. CheckFormat(layout, FALSE);
  1132. }
  1133. /******************************************************************************
  1134. * Function: CheckSaveInfo
  1135. *
  1136. * Purpose: Checks to see if there is any information to save and saves
  1137. * it if there is any.
  1138. *****************************************************************************/
  1139. static void
  1140. CheckSaveInfo (
  1141. _DtCanvasStruct *canvas,
  1142. LayoutInfo *layout,
  1143. _DtCvSegmentI *new_seg,
  1144. int start)
  1145. {
  1146. if (layout->info.line_bytes)
  1147. SaveInfo (canvas, layout, new_seg, start);
  1148. }
  1149. /******************************************************************************
  1150. * Function: ProcessStringSegment
  1151. *
  1152. * chops a string segment up until its completely used.
  1153. *
  1154. *****************************************************************************/
  1155. static void
  1156. ProcessStringSegment(
  1157. _DtCanvasStruct *canvas,
  1158. LayoutInfo *layout,
  1159. _DtCvSegmentI *cur_seg)
  1160. {
  1161. layout->cur_start = 0;
  1162. if (!(_DtCvIsSegSuperScript(cur_seg) || _DtCvIsSegSubScript(cur_seg))
  1163. && (layout->super_script == True || layout->sub_script == True))
  1164. {
  1165. layout->super_end = 0;
  1166. layout->sub_end = 0;
  1167. layout->super_script = False;
  1168. layout->sub_script = False;
  1169. }
  1170. while (_DtCvProcessStringSegment(canvas, &(layout->info),
  1171. layout->max_width, layout->lmargin, layout->rmargin,
  1172. cur_seg , &(layout->cur_start),
  1173. layout->txt_justify, layout->stat_flag) == 1)
  1174. CheckFormat(layout, False);
  1175. } /* End ProcessStringSegment */
  1176. /******************************************************************************
  1177. * Function: _DtCvUnit ResolveHeight(
  1178. *
  1179. * Parameters:
  1180. *
  1181. * Purpose: Determines the height of a row that is spanned.
  1182. *****************************************************************************/
  1183. static _DtCvUnit
  1184. ResolveHeight(
  1185. RowSpec *row_info,
  1186. CellInfo *cell_info,
  1187. int max_cols,
  1188. int row,
  1189. int span)
  1190. {
  1191. int i;
  1192. int col;
  1193. int cell;
  1194. int topRow;
  1195. int topCell;
  1196. int zeroed;
  1197. int total;
  1198. int rowHeight = 0;
  1199. for (col = 0, cell = row * max_cols; col < max_cols; col++, cell++)
  1200. {
  1201. /*
  1202. * if we have a row spanning cell in this column,
  1203. * but it isn't from a previous column, try to fill out
  1204. * the height using it.
  1205. */
  1206. if (cell_info[cell].row_spn == -1 && cell_info[cell].col_spn != -1)
  1207. {
  1208. /*
  1209. * back up to the cell information containing the row
  1210. * span value.
  1211. */
  1212. topRow = row;
  1213. topCell = cell;
  1214. do
  1215. {
  1216. topCell--;
  1217. topRow--;
  1218. } while (cell_info[topCell].row_spn == -1);
  1219. /*
  1220. * from here, start calculating the height of the row
  1221. * spanning cell, and find out how big the row must
  1222. * be to contain it.
  1223. */
  1224. i = cell_info[topCell].row_spn;
  1225. zeroed = span + 1;
  1226. total = 0;
  1227. while (i > 0 && zeroed > 0)
  1228. {
  1229. total += row_info[topRow].height;
  1230. if (row_info[topRow].height == 0)
  1231. zeroed--;
  1232. i--;
  1233. topRow++;
  1234. }
  1235. /*
  1236. * if zeroed is greater than zero, that means only the
  1237. * allowd number of row heights were zeroed out (the ones
  1238. * we are looking for).
  1239. * go ahead and calculate a new height. Otherwise,
  1240. * it may be tried later.
  1241. */
  1242. if (zeroed > 0)
  1243. {
  1244. /*
  1245. * make sure we get a positive value out of
  1246. * this for our height.
  1247. */
  1248. if (cell_info[topCell].info.height > total)
  1249. {
  1250. total = cell_info[topCell].info.height - total;
  1251. total = total / span + (total % span ? 1 : 0);
  1252. }
  1253. /*
  1254. * make sure we take the biggest value possible
  1255. * for this row. If it needs to be smaller for
  1256. * cells, we'll adjust the positioning within
  1257. * the cell.
  1258. */
  1259. if (rowHeight < total)
  1260. rowHeight = total;
  1261. }
  1262. }
  1263. }
  1264. row_info[row].height = rowHeight;
  1265. return rowHeight;
  1266. }
  1267. /******************************************************************************
  1268. * Function: void AdjustHeight(
  1269. *
  1270. * Parameters:
  1271. *
  1272. * Purpose: Determines the height of rows that are spanned but the
  1273. * the spanner needs more room than the calculated row height
  1274. * allow.
  1275. *****************************************************************************/
  1276. static void
  1277. AdjustHeight(
  1278. CellInfo *cell_info,
  1279. RowSpec *row_specs,
  1280. int max_cols,
  1281. int row,
  1282. int col)
  1283. {
  1284. int cell = row * max_cols + col;
  1285. int i, j;
  1286. _DtCvUnit total;
  1287. _DtCvUnit adjustValue;
  1288. _DtCvUnit value;
  1289. if (cell_info[cell].col_spn == -1 || cell_info[cell].row_spn == -1)
  1290. return;
  1291. for (j = row, i = 0, total = 0; i < cell_info[cell].row_spn; i++, j++)
  1292. total += row_specs[j].height;
  1293. /*
  1294. * adjust the row height to include all of the row spanning cell.
  1295. */
  1296. if (total < cell_info[cell].info.height)
  1297. {
  1298. _DtCvUnit totalUsed = 0;
  1299. /*
  1300. * first, try to grow the cells on a percentage basis.
  1301. * This way, a small cell will grow the same amount relative
  1302. * to the larger cells.
  1303. */
  1304. adjustValue = cell_info[cell].info.height - total;
  1305. /*
  1306. * now if total is zero, we'll get a divide by zero error.
  1307. * So check for this and set total to the number of rows spanned.
  1308. */
  1309. if (0 == total)
  1310. total = cell_info[cell].row_spn;
  1311. for (i = 0; i < cell_info[cell].row_spn; i++)
  1312. {
  1313. value = (((row_specs[row + i].height * 100) / total) * adjustValue)
  1314. / 100;
  1315. row_specs[row + i].height += value;
  1316. totalUsed += value;
  1317. }
  1318. /*
  1319. * if didn't use all the size up - apply it evenly.
  1320. */
  1321. if (totalUsed < adjustValue)
  1322. {
  1323. adjustValue = adjustValue - totalUsed;
  1324. for (i = 0, j = cell_info[cell].row_spn;
  1325. adjustValue > 0 && i < cell_info[cell].row_spn; i++, j--)
  1326. {
  1327. value = adjustValue / j + (adjustValue % j ? 1 : 0);
  1328. row_specs[row + i].height += value;
  1329. adjustValue -= value;
  1330. totalUsed += value;
  1331. }
  1332. }
  1333. total = totalUsed;
  1334. }
  1335. }
  1336. /******************************************************************************
  1337. * Function: void ReFormatCell(
  1338. *
  1339. * Parameters:
  1340. * canvas Specifies the specific information about the
  1341. * rendering area.
  1342. * layout Specifies the currently active information
  1343. * affecting the layout of information.
  1344. *
  1345. * Purpose: Based on a height and width, relay out the information in a cell.
  1346. *****************************************************************************/
  1347. static void
  1348. ReFormatCell(
  1349. _DtCanvasStruct *canvas,
  1350. LayoutInfo *layout,
  1351. CellInfo *this_cell,
  1352. ColumnSpec *col_specs,
  1353. int col,
  1354. _DtCvUnit new_height,
  1355. _DtCvUnit new_y)
  1356. {
  1357. int i;
  1358. int saveTxt = canvas->txt_cnt;
  1359. int saveLn = canvas->line_cnt;
  1360. _DtCvUnit saveYpos = layout->info.y_pos;
  1361. _DtCvUnit saveMaxX = layout->info.cur_max_x;
  1362. _DtCvUnit cellWidth = 0;
  1363. _DtCvUnit junk;
  1364. _DtCvValue junkValue;
  1365. DataPoint basePt;
  1366. /*
  1367. * reset the y_pos to the correct placement.
  1368. * reset the line counts to the original values.
  1369. * since we aren't changing the width, the number
  1370. * of lines used will not change.
  1371. */
  1372. layout->info.y_pos = new_y;
  1373. canvas->txt_cnt = this_cell->info.cnt.beg_txt;
  1374. canvas->line_cnt = this_cell->info.cnt.beg_ln;
  1375. /*
  1376. * determine the maximum width for the cell.
  1377. */
  1378. for (i = this_cell->col_spn; i > 0; i--)
  1379. cellWidth += col_specs[col++].actual;
  1380. /*
  1381. * get the current left and right margins.
  1382. */
  1383. GetCurrentDataPoint(layout, &basePt);
  1384. /*
  1385. * re-format the cell
  1386. */
  1387. FormatCell(canvas, layout, this_cell->cell_seg, cellWidth,
  1388. new_height,
  1389. basePt, &i, &cellWidth, &junk, &junkValue);
  1390. /*
  1391. * calculate the new height.
  1392. */
  1393. this_cell->info.height = layout->info.y_pos - new_y;
  1394. /*
  1395. * if the new cell does not use the same number of lines as the
  1396. * old formatting did, zero the length.
  1397. */
  1398. while (canvas->txt_cnt < this_cell->info.cnt.end_txt)
  1399. canvas->txt_lst[canvas->txt_cnt++].length = 0;
  1400. /*
  1401. * restore the saved counters
  1402. */
  1403. canvas->txt_cnt = saveTxt;
  1404. canvas->line_cnt = saveLn;
  1405. layout->info.y_pos = saveYpos;
  1406. layout->info.cur_max_x = saveMaxX;
  1407. }
  1408. /******************************************************************************
  1409. * Function: void FormatCell(
  1410. *
  1411. * Parameters:
  1412. * canvas Specifies the specific information about the
  1413. * rendering area.
  1414. * layout Specifies the currently active information
  1415. * affecting the layout of information.
  1416. * span_width Specifies the desired size constraining
  1417. * the layout of information.
  1418. * base_pt Specifies the base margins.
  1419. * this_cell Specifies the cell structure to fill out.
  1420. *
  1421. * Purpose: Determines the width and height of the cell. Also the begin/end
  1422. * counts on text, graphics and lines.
  1423. *****************************************************************************/
  1424. static void
  1425. FormatCell(
  1426. _DtCanvasStruct *canvas,
  1427. LayoutInfo *layout,
  1428. _DtCvSegmentI *cell_seg,
  1429. _DtCvUnit span_width,
  1430. _DtCvUnit min_height,
  1431. DataPoint base_pt,
  1432. int *ret_ln,
  1433. _DtCvUnit *ret_width,
  1434. _DtCvUnit *ret_height,
  1435. _DtCvValue *ret_tab_flag)
  1436. {
  1437. _DtCvStatus only1Col = True;
  1438. _DtCvUnit maxX;
  1439. _DtCvUnit minY = -1;
  1440. _DtCvUnit saveYpos = layout->info.y_pos;
  1441. _DtCvUnit saveRight = layout->right;
  1442. _DtCvUnit saveMaxX = layout->info.cur_max_x;
  1443. _DtCvSegmentI *nextSeg;
  1444. /*
  1445. * set the limits/margins
  1446. * assume the left_margin has been set by a previous call.
  1447. */
  1448. layout->right = layout->max_width - base_pt.left - base_pt.right
  1449. - layout->left - span_width;
  1450. /*
  1451. * set the minimum Y for the container.
  1452. */
  1453. if (0 < min_height)
  1454. minY = saveYpos + min_height;
  1455. /*
  1456. * If a segment was specified for this cell, format it.
  1457. */
  1458. if (cell_seg != NULL && &BlankTableCell != cell_seg)
  1459. {
  1460. ProcessContainer(canvas, layout, cell_seg, minY,
  1461. ret_width, &maxX, ret_ln);
  1462. /*
  1463. * check to see if the only thing in this container is a
  1464. * table.
  1465. */
  1466. nextSeg = _DtCvContainerListOfSeg(cell_seg);
  1467. *ret_tab_flag = True;
  1468. while (True == *ret_tab_flag && NULL != nextSeg)
  1469. {
  1470. /*
  1471. * check to see if there is any segments that aren't one
  1472. * column tables.
  1473. */
  1474. if (_DtCvIsSegTable(nextSeg) &&
  1475. 1 < _DtCvNumColsOfTableSeg(nextSeg))
  1476. only1Col = False;
  1477. else if (!(_DtCvIsSegTable(nextSeg) || _DtCvIsSegNoop(nextSeg)))
  1478. *ret_tab_flag = False;
  1479. nextSeg = _DtCvNextSeg(nextSeg);
  1480. }
  1481. if (True == *ret_tab_flag && True == only1Col)
  1482. *ret_tab_flag = False;
  1483. }
  1484. /*
  1485. * Calculate the height and return it.
  1486. */
  1487. *ret_height = layout->info.y_pos - saveYpos;
  1488. /*
  1489. * restore the right margin
  1490. */
  1491. layout->right = saveRight;
  1492. if (layout->info.cur_max_x < saveMaxX)
  1493. layout->info.cur_max_x = saveMaxX;
  1494. }
  1495. /******************************************************************************
  1496. * Function: AdjustFrmtTxtOption
  1497. *
  1498. *****************************************************************************/
  1499. static void
  1500. AdjustFrmtTxtOption(
  1501. _DtCvSegmentI *p_seg,
  1502. _DtCvFrmtOption option)
  1503. {
  1504. if (p_seg != NULL && _DtCvIsSegContainer(p_seg))
  1505. {
  1506. TxtHorizJustify(p_seg) = option;
  1507. p_seg = _DtCvContainerListOfSeg(p_seg);
  1508. while (p_seg != NULL)
  1509. {
  1510. AdjustFrmtTxtOption(p_seg, option);
  1511. p_seg = p_seg->next_seg;
  1512. }
  1513. }
  1514. }
  1515. /******************************************************************************
  1516. * Function: ResolveCell
  1517. *
  1518. *****************************************************************************/
  1519. static _DtCvValue
  1520. ResolveCell(
  1521. _DtCanvasStruct *canvas,
  1522. LayoutInfo *layout,
  1523. _DtCvSegmentI *table,
  1524. ColumnSpec *col_specs,
  1525. RowSpec *row_specs,
  1526. int col,
  1527. int row,
  1528. int max_cols,
  1529. int max_rows,
  1530. CellInfo *ret_info)
  1531. {
  1532. int i;
  1533. char *id = NULL;
  1534. char *idRefs;
  1535. char *ptr = NULL;
  1536. char c = 0;
  1537. int count;
  1538. int len;
  1539. int done;
  1540. int brdCnt;
  1541. int myCol = col;
  1542. int cell = row * max_cols + col;
  1543. _DtCvUnit cellWidth;
  1544. _DtCvUnit retWidth;
  1545. _DtCvUnit retHeight;
  1546. _DtCvUnit saveTop = 0;
  1547. CellInfo *thisCell = &ret_info[cell];
  1548. DataPoint basePt;
  1549. _DtCvValue reformat = False;
  1550. _DtCvValue retTabFlag = False;
  1551. _DtCvSegmentI **f_data = _DtCvCellsOfTableSeg(table);
  1552. /*
  1553. * if this column is spanned, skip
  1554. */
  1555. if (thisCell->col_spn == -1 || thisCell->row_spn == -1)
  1556. return False;
  1557. GetCurrentDataPoint(layout, &basePt);
  1558. if (thisCell->cell_seg == NULL)
  1559. {
  1560. idRefs = row_specs[row].next_id;
  1561. /*
  1562. * find the end of the id
  1563. */
  1564. done = False;
  1565. /*
  1566. * set the starting info
  1567. */
  1568. thisCell->col_spn = 1;
  1569. thisCell->pos_x = basePt.left + layout->left;
  1570. while (!done && col < max_cols)
  1571. {
  1572. ptr = idRefs;
  1573. id = idRefs;
  1574. /*
  1575. * move the ptr to the next id,
  1576. * counting the characters in this id at the same time.
  1577. */
  1578. len = 0;
  1579. while (NULL != ptr && *ptr != ' ' && *ptr != '\0')
  1580. {
  1581. ptr++;
  1582. len++;
  1583. }
  1584. /*
  1585. * set idRefs to the next id.
  1586. */
  1587. idRefs = ptr;
  1588. while (NULL != idRefs && *idRefs == ' ')
  1589. idRefs++;
  1590. /*
  1591. * Is this id and the next the same? If so,
  1592. * it spans the columns
  1593. */
  1594. if (0 != len && _DtCvStrNCaseCmpLatin1(id, idRefs, len) == 0 &&
  1595. (idRefs[len] == ' ' || idRefs[len] == '\0'))
  1596. {
  1597. col++;
  1598. thisCell->col_spn++;
  1599. ret_info[++cell].col_spn = -1;
  1600. }
  1601. else
  1602. done = True;
  1603. }
  1604. row_specs[row].next_id = idRefs;
  1605. /*
  1606. * find the segment
  1607. */
  1608. if (NULL != id && '\0' != *id)
  1609. {
  1610. c = *ptr;
  1611. *ptr = '\0';
  1612. while (f_data != NULL && NULL != *f_data &&
  1613. _DtCvStrCaseCmpLatin1(_DtCvContainerIdOfSeg(*f_data),id) != 0)
  1614. f_data++;
  1615. /*
  1616. * make sure to break the link to the next segment.
  1617. * Otherwise, the formatting routines will format too much
  1618. * for the cell.
  1619. */
  1620. if (NULL != f_data && NULL != *f_data)
  1621. {
  1622. _DtCvNextSeg(*f_data) = NULL;
  1623. /*
  1624. * assign the data to this cell.
  1625. */
  1626. thisCell->cell_seg = *f_data;
  1627. }
  1628. else /* there is no id for this cell, use a blank container */
  1629. thisCell->cell_seg = (struct _dtCvSegment*) &BlankTableCell;
  1630. }
  1631. else /* there is no id for this cell, use a blank container */
  1632. thisCell->cell_seg = (struct _dtCvSegment*) &BlankTableCell;
  1633. /*
  1634. * how many rows does this cell span?
  1635. */
  1636. len = 0;
  1637. if (NULL != id)
  1638. len = strlen(id);
  1639. for (done = False, count = 1, i = row + 1;
  1640. 0 < len && i < max_rows && False == done; i++)
  1641. {
  1642. done = True;
  1643. if (_DtCvStrNCaseCmpLatin1(id, row_specs[i].next_id, len) == 0 &&
  1644. (row_specs[i].next_id[len] == ' ' ||
  1645. row_specs[i].next_id[len] == '\0'))
  1646. {
  1647. int k;
  1648. done = False;
  1649. count++;
  1650. /*
  1651. * invalidate the columns spanned in this row
  1652. */
  1653. for (k = 0; k < thisCell->col_spn && k + myCol < max_cols; k++)
  1654. {
  1655. ret_info[i * max_cols + myCol + k].col_spn = -1;
  1656. ret_info[i * max_cols + myCol + k].row_spn = -1;
  1657. }
  1658. idRefs = row_specs[i].next_id;
  1659. do
  1660. {
  1661. /*
  1662. * skip the current id.
  1663. */
  1664. while (*idRefs != ' ' && *idRefs != '\0')
  1665. idRefs++;
  1666. /*
  1667. * skip the space to the next id.
  1668. */
  1669. while (*idRefs == ' ')
  1670. idRefs++;
  1671. /*
  1672. * now test to see if this is a match
  1673. * cycle if so. quit if the end of string
  1674. * or not a match.
  1675. */
  1676. } while (*idRefs != '\0' &&
  1677. _DtCvStrNCaseCmpLatin1(id, idRefs, len) == 0 &&
  1678. (idRefs[len] == ' ' || idRefs[len] == '\0'));
  1679. /*
  1680. * the next non-spanned column in this row will use this id.
  1681. */
  1682. row_specs[i].next_id = idRefs;
  1683. }
  1684. }
  1685. if (NULL != id && '\0' != *id)
  1686. *ptr = c;
  1687. thisCell->row_spn = count;
  1688. }
  1689. for (i = 0, cellWidth = 0; i < thisCell->col_spn; i++)
  1690. cellWidth += col_specs[myCol + i].actual;
  1691. /*
  1692. * set the start line and text information
  1693. */
  1694. SetBeginCounts(canvas, &(thisCell->info.cnt));
  1695. /*
  1696. * check to see if this cell is overhung by a previous cell.
  1697. * If so, zero the top margin. But remember and restore it
  1698. * because resizing may eliminate the need for the overhang!
  1699. */
  1700. if (&BlankTableCell != thisCell->cell_seg)
  1701. {
  1702. saveTop = _DtCvContainerTMarginOfSeg(thisCell->cell_seg);
  1703. if (_DtCvTRUE == col_specs[myCol].hanger
  1704. && 0 != row_specs[row].y_adj && myCol > row_specs[row].column)
  1705. _DtCvContainerTMarginOfSeg(thisCell->cell_seg) = 0;
  1706. }
  1707. /*
  1708. * Format the cell
  1709. */
  1710. FormatCell(canvas, layout, thisCell->cell_seg, cellWidth,
  1711. row_specs[row].height, basePt,
  1712. &brdCnt, &retWidth, &retHeight, &retTabFlag);
  1713. if (&BlankTableCell != thisCell->cell_seg)
  1714. _DtCvContainerTMarginOfSeg(thisCell->cell_seg) = saveTop;
  1715. /*
  1716. * set some ending information
  1717. */
  1718. thisCell->info.height = retHeight;
  1719. thisCell->info.width = retWidth;
  1720. SetEndCounts(canvas, &(thisCell->info.cnt), brdCnt);
  1721. /*
  1722. * check the height against previous heights
  1723. */
  1724. if (row_specs[row].height < retHeight && thisCell->row_spn == 1)
  1725. row_specs[row].height = retHeight;
  1726. /*
  1727. * check for run over of the desired widths
  1728. */
  1729. if (retWidth > cellWidth)
  1730. {
  1731. int j;
  1732. _DtCvUnit cellMax;
  1733. _DtCvUnit maxSlop;
  1734. _DtCvUnit value;
  1735. _DtCvUnit percent;
  1736. _DtCvUnit slopUsed = 0;
  1737. _DtCvUnit slop = retWidth - cellWidth; /* the amount of room
  1738. required of the neighbors */
  1739. /*
  1740. * set the reformat flag
  1741. */
  1742. if (False == retTabFlag)
  1743. reformat = True;
  1744. /*
  1745. * determine the maximum size the column can occupy
  1746. */
  1747. for (j = 0, cellMax = 0;
  1748. j < thisCell->col_spn && j + myCol < max_cols; j++)
  1749. cellMax += col_specs[myCol+j].max;
  1750. /*
  1751. * determine the maximum available space from the neighbors.
  1752. */
  1753. for (j = myCol + thisCell->col_spn, maxSlop = 0; j < max_cols; j++)
  1754. maxSlop = maxSlop + col_specs[j].actual - col_specs[j].min;
  1755. /*
  1756. * If the slop demanded is larger than available,
  1757. * simply reduced the other column specifications to their smallest
  1758. * values.
  1759. */
  1760. if (slop >= maxSlop)
  1761. {
  1762. for (j = myCol + thisCell->col_spn; j < max_cols; j++)
  1763. col_specs[j].actual = col_specs[j].min;
  1764. /*
  1765. * Is it allowed for this column to 'hang over' the others?
  1766. *
  1767. * And is it the first one? I.e. don't allow more than one
  1768. * cell per row to overhang it's neighbors.
  1769. *
  1770. * And only allow it if the vertical text justification places
  1771. * the text at the top of the cell.
  1772. */
  1773. if (_DtCvTRUE == col_specs[myCol].hanger
  1774. && 0 == row_specs[row].y_adj
  1775. && _DtCvJUSTIFY_TOP == TxtVertJustify(thisCell->cell_seg))
  1776. {
  1777. /*
  1778. * now set the other columns to start a little lower
  1779. * in their objects. Remove the bottom margin from the
  1780. * adjustment. One would hope that each of the containers
  1781. * for the columns in the row have the same bottom margin
  1782. * so that the overhung cell will push the next row down
  1783. * by the appropriate amount.
  1784. */
  1785. row_specs[row].y_adj = retHeight -
  1786. _DtCvContainerBMarginOfSeg(thisCell->cell_seg);
  1787. row_specs[row].column = myCol;
  1788. retWidth = cellMax;
  1789. /*
  1790. * clear the reformat flag
  1791. */
  1792. reformat = False;
  1793. }
  1794. }
  1795. else if (slop > 0)
  1796. {
  1797. /*
  1798. * the maximum slop available from the neighbors is
  1799. * enough. Now take space from my neighbors based
  1800. * on their orginal size. I.e. the larger they
  1801. * are, the more I take from them.
  1802. */
  1803. for (j = myCol + thisCell->col_spn; j < max_cols; j++)
  1804. {
  1805. percent = col_specs[j].actual - col_specs[j].min;
  1806. value = slop * percent / maxSlop;
  1807. slopUsed += value;
  1808. col_specs[j].actual -= value;
  1809. }
  1810. /*
  1811. * if any more slop is needed, grab it on a strictly
  1812. * straight basis.
  1813. */
  1814. do {
  1815. slop -= slopUsed;
  1816. for (j = myCol + thisCell->col_spn, slopUsed = 0;
  1817. slop > slopUsed && j < max_cols; j++)
  1818. {
  1819. if (col_specs[j].actual > col_specs[j].min)
  1820. {
  1821. col_specs[j].actual--;
  1822. slopUsed++;
  1823. }
  1824. }
  1825. } while (slopUsed > 0 && slop > slopUsed);
  1826. }
  1827. /*
  1828. * set the column width in the controlling column struct.
  1829. */
  1830. if (thisCell->col_spn == 1)
  1831. {
  1832. col_specs[myCol].actual = retWidth;
  1833. }
  1834. else
  1835. {
  1836. /*
  1837. * how much to spread among the columns?
  1838. */
  1839. slop = cellMax - retWidth;
  1840. /*
  1841. * if the aggragate max width is smaller than required,
  1842. * allocate the excess among the columns.
  1843. */
  1844. if (slop < 0)
  1845. {
  1846. /*
  1847. * set the desired to the max and calculate the leftover
  1848. * slop and the maximum desired size.
  1849. */
  1850. for (j = 0, slop = retWidth, maxSlop = 0;
  1851. myCol + j < max_cols && j < thisCell->col_spn; j++)
  1852. {
  1853. col_specs[j].actual = col_specs[myCol + j].max;
  1854. slop -= col_specs[myCol + j].max;
  1855. maxSlop += col_specs[myCol + j].max;
  1856. }
  1857. /*
  1858. * now allocate the leftover slop to each colum
  1859. * based on the maximum desired size.
  1860. */
  1861. for (j = 0, slopUsed = 0;
  1862. slop > slopUsed && myCol + j < max_cols
  1863. && j < thisCell->col_spn; j++)
  1864. {
  1865. value = slop * col_specs[myCol + j].max / maxSlop;
  1866. if (((slop*col_specs[myCol+j].max) % maxSlop) >= (maxSlop/2))
  1867. value++;
  1868. col_specs[myCol + j].actual += value;
  1869. slopUsed += value;
  1870. }
  1871. }
  1872. else if (slop > 0)
  1873. {
  1874. slopUsed = 0;
  1875. for (j = myCol;
  1876. j < max_cols && j < myCol + thisCell->col_spn; j++)
  1877. {
  1878. percent = col_specs[j].max - col_specs[j].actual;
  1879. value = slop * percent / maxSlop;
  1880. slopUsed += value;
  1881. col_specs[j].actual += value;
  1882. }
  1883. do {
  1884. slop -= slopUsed;
  1885. for (j = myCol, slopUsed = 0; slop > slopUsed &&
  1886. j < max_cols && j < myCol + thisCell->col_spn; j++)
  1887. {
  1888. if (col_specs[j].actual < col_specs[j].max)
  1889. {
  1890. col_specs[j].actual++;
  1891. slopUsed++;
  1892. }
  1893. }
  1894. } while (slopUsed > 0 && slop > slopUsed);
  1895. }
  1896. else /* if (slop == 0) */
  1897. {
  1898. for (j = 0; myCol + j < max_cols && j < thisCell->col_spn; j++)
  1899. col_specs[j].actual = col_specs[myCol + j].max;
  1900. }
  1901. }
  1902. }
  1903. return reformat;
  1904. }
  1905. /******************************************************************************
  1906. * Function: ProcessTable
  1907. *
  1908. *****************************************************************************/
  1909. static void
  1910. ProcessTable(
  1911. _DtCanvasStruct *canvas,
  1912. LayoutInfo *layout,
  1913. _DtCvSegmentI *table,
  1914. _DtCvUnit min_y)
  1915. {
  1916. int a;
  1917. int b;
  1918. int c;
  1919. int col;
  1920. int row;
  1921. int cell;
  1922. int divisor;
  1923. int maxCols;
  1924. int maxRows;
  1925. int maxRowSpn;
  1926. int saveLnStart = canvas->line_cnt;
  1927. int saveTxtStart = canvas->txt_cnt;
  1928. int saveTravCnt = canvas->trav_cnt;
  1929. _DtCvUnit workWidth;
  1930. _DtCvUnit newLeft;
  1931. _DtCvUnit saveLeft = layout->left;
  1932. _DtCvUnit saveYpos = layout->info.y_pos;
  1933. _DtCvUnit tableYpos;
  1934. _DtCvUnit newHeight;
  1935. _DtCvUnit newWidth;
  1936. _DtCvUnit oldAlignPos;
  1937. short anchorRow = -1;
  1938. const char **widthStr;
  1939. const char *saveAlignChar = layout->info.align_char;
  1940. char **rowIds;
  1941. char *alignCharacters = NULL;
  1942. char alignBuf[16];
  1943. _DtCvFrmtOption saveTxtJustify = layout->txt_justify;
  1944. _DtCvFrmtOption colJustify = _DtCvJUSTIFY_LEFT;
  1945. _DtCvFrmtOption *colJustSpec;
  1946. _DtCvValue oldFound = layout->id_found;
  1947. _DtCvValue haveBrds = False;
  1948. _DtCvValue saveState = layout->table_flag;
  1949. _DtCvValue saveAlignFlag = layout->info.align_flag;
  1950. _DtCvValue saveAlignPos = layout->info.align_pos;
  1951. _DtCvValue redo;
  1952. CellInfo defCell;
  1953. CellInfo *cellInfo = &defCell;
  1954. ColumnSpec defColumn;
  1955. ColumnSpec *colSpecs = &defColumn;
  1956. RowSpec defRow;
  1957. RowSpec *rowSpecs = &defRow;
  1958. DataPoint basePt;
  1959. GrpInfo grpInfo = DefGrpInfo;
  1960. /*
  1961. * get the base margins that the table will be working in.
  1962. */
  1963. GetCurrentDataPoint(layout, &basePt);
  1964. /*
  1965. * find out how many rows there are.
  1966. */
  1967. for (rowIds = _DtCvCellIdsOfTableSeg(table), maxRows = 0;
  1968. rowIds != NULL && rowIds[maxRows] != NULL; maxRows++);
  1969. if (maxRows == 0)
  1970. return;
  1971. /*
  1972. * get the number of columns and the column widths
  1973. */
  1974. maxCols = _DtCvNumColsOfTableSeg(table);
  1975. widthStr = (const char **)_DtCvColWOfTableSeg(table);
  1976. colJustSpec = _DtCvColJustifyOfTableSeg(table);
  1977. if (maxCols < 1)
  1978. maxCols = 1;
  1979. if (widthStr == NULL)
  1980. widthStr = DefWidth;
  1981. /*
  1982. * determine the width the table has to work with.
  1983. */
  1984. workWidth = layout->max_width - basePt.left - basePt.right -
  1985. layout->left - layout->right;
  1986. if (workWidth < 0)
  1987. workWidth = 0;
  1988. /*
  1989. * turn the string specifying column widths into units.
  1990. */
  1991. if (maxCols != 1)
  1992. {
  1993. colSpecs = (ColumnSpec *) malloc (sizeof(ColumnSpec) * maxCols);
  1994. if (colSpecs == NULL)
  1995. return;
  1996. }
  1997. if (maxRows != 1)
  1998. {
  1999. rowSpecs = (RowSpec *) malloc (sizeof(RowSpec) * maxRows);
  2000. if (rowSpecs == NULL)
  2001. {
  2002. if (maxCols > 1)
  2003. free(colSpecs);
  2004. return;
  2005. }
  2006. }
  2007. if (maxRows != 1 || maxCols != 1)
  2008. {
  2009. cellInfo = (CellInfo *) malloc (sizeof(CellInfo) * maxCols * maxRows);
  2010. if (cellInfo == NULL)
  2011. {
  2012. if (maxCols > 1)
  2013. free(colSpecs);
  2014. if (maxRows > 1)
  2015. free(rowSpecs);
  2016. return;
  2017. }
  2018. }
  2019. /*
  2020. * for each column, process the width specification.
  2021. * '+Optimal,Take,Give'
  2022. *
  2023. * + - means the cell can 'hang over' its neighbors.
  2024. * It will take everything it can get and then
  2025. * push the other below it. (Labeled lists).
  2026. * Optimal - The desired percentage of the available space to
  2027. * use for the column.
  2028. * Take - The percentage amount the column will take from
  2029. * other columns to make itself 'fit'.
  2030. * Give - The percentage amount the column is willing to give up
  2031. * to other columns for them to 'fit'.
  2032. */
  2033. for (col = 0, divisor = 0; col < maxCols; col++)
  2034. {
  2035. const char *nxtWidth = *widthStr;
  2036. /*
  2037. * move to the meat of the width specification string.
  2038. */
  2039. SkipToNumber(&nxtWidth);
  2040. /*
  2041. * set the correct 'allow hangers' flag.
  2042. */
  2043. colSpecs[col].hanger = _DtCvFALSE;
  2044. if ('+' == *nxtWidth)
  2045. {
  2046. colSpecs[col].hanger = _DtCvTRUE;
  2047. nxtWidth++;
  2048. }
  2049. /*
  2050. * now process the O,G,T specification.
  2051. */
  2052. a = GetValueFromString(&nxtWidth, 1); if (a < 1) a = 1;
  2053. b = GetValueFromString(&nxtWidth, 0); if (b < 0) b = 0;
  2054. c = GetValueFromString(&nxtWidth, b); if (c > a) c = a;
  2055. /*
  2056. * for now just get the base percentages.
  2057. */
  2058. colSpecs[col].min = a - c;
  2059. colSpecs[col].actual = a;
  2060. colSpecs[col].max = a + b;
  2061. /*
  2062. * get the column justification.
  2063. */
  2064. if (NULL != colJustSpec)
  2065. {
  2066. colJustify = *colJustSpec;
  2067. colJustSpec++;
  2068. }
  2069. colSpecs[col].justify = colJustify;
  2070. if (_DtCvINHERIT == colJustify)
  2071. colSpecs[col].justify = saveTxtJustify;
  2072. /*
  2073. * up the divisor value.
  2074. */
  2075. divisor += colSpecs[col].actual;
  2076. /*
  2077. * skip to the next set of width specifications
  2078. */
  2079. if (col + 1 < maxCols && NULL != widthStr[1])
  2080. widthStr++;
  2081. /*
  2082. * initialize the cell information for the rows in this column
  2083. */
  2084. for (row = 0; row < maxRows; row++)
  2085. {
  2086. cellInfo[row * maxCols + col].cell_seg = NULL;
  2087. cellInfo[row * maxCols + col].col_spn = 0;
  2088. cellInfo[row * maxCols + col].row_spn = 0;
  2089. cellInfo[row * maxCols + col].info = DefLayFrmtInfo;
  2090. }
  2091. }
  2092. /*
  2093. * initialize the row specs
  2094. */
  2095. newHeight = 0;
  2096. if (-1 != min_y && 1 == maxRows)
  2097. newHeight = min_y - saveYpos;
  2098. for (row = 0; row < maxRows; row++)
  2099. {
  2100. rowSpecs[row].column = -1;
  2101. rowSpecs[row].y_adj = 0;
  2102. rowSpecs[row].height = newHeight;
  2103. rowSpecs[row].height = newHeight;
  2104. rowSpecs[row].next_id = rowIds[row];
  2105. }
  2106. /*
  2107. * now figure the real values
  2108. */
  2109. if (divisor < 1)
  2110. divisor = 1;
  2111. for (col = 0; col < maxCols; col++)
  2112. {
  2113. colSpecs[col].min = workWidth * colSpecs[col].min / divisor;
  2114. colSpecs[col].actual = workWidth * colSpecs[col].actual / divisor;
  2115. colSpecs[col].max = workWidth * colSpecs[col].max / divisor;
  2116. if (colSpecs[col].min < 1)
  2117. colSpecs[col].min = 1;
  2118. if (colSpecs[col].actual < 1)
  2119. colSpecs[col].actual = 1;
  2120. if (colSpecs[col].max < 1)
  2121. colSpecs[col].max = 1;
  2122. }
  2123. /*
  2124. * now process the table.
  2125. */
  2126. tableYpos = layout->info.y_pos;
  2127. maxRowSpn = 1;
  2128. alignCharacters = _DtCvJustifyCharsOfTableSeg(table);
  2129. /*
  2130. * set up the state of table processing and
  2131. * the beginning line/text counts.
  2132. */
  2133. layout->table_flag = True;
  2134. SetBeginCounts(canvas, &(grpInfo.cnt));
  2135. /*
  2136. * now process each column, row by row.
  2137. * Doing it row by row allows the columns to shake out their
  2138. * sizing with less reformatting.
  2139. */
  2140. for (col = 0; col < maxCols; col++)
  2141. {
  2142. /*
  2143. * remember where this column starts.
  2144. */
  2145. saveTravCnt = canvas->trav_cnt;
  2146. saveLnStart = canvas->line_cnt;
  2147. saveTxtStart = canvas->txt_cnt;
  2148. newLeft = layout->left;
  2149. colJustify = layout->txt_justify;
  2150. layout->txt_justify = colSpecs[col].justify;
  2151. /*
  2152. * initialize the JUSTIFY_NUM or JUSTIFY_CHAR information
  2153. */
  2154. layout->info.align_pos = 0;
  2155. layout->info.align_char = PeriodStr;
  2156. if (_DtCvJUSTIFY_CHAR == layout->txt_justify)
  2157. {
  2158. /*
  2159. * are any alignment characters specified?
  2160. */
  2161. if (NULL != alignCharacters && '\0' != *alignCharacters)
  2162. {
  2163. int len = mblen(alignCharacters, MB_CUR_MAX);
  2164. /*
  2165. * copy the character into a buffer
  2166. */
  2167. strncpy(alignBuf, alignCharacters, len);
  2168. alignBuf[len] = '\0';
  2169. layout->info.align_char = alignBuf;
  2170. /*
  2171. * are there more characters? If so increment for the
  2172. * next column that may have JUSTIFY_CHAR. Otherwise,
  2173. * leave alone and re-use for other columns.
  2174. */
  2175. if ('\0' != alignCharacters[len])
  2176. alignCharacters += len;
  2177. }
  2178. /* no...then default */
  2179. else
  2180. layout->txt_justify = _DtCvJUSTIFY_LEFT;
  2181. }
  2182. do {
  2183. /*
  2184. * reset the counts to the start
  2185. */
  2186. canvas->trav_cnt = saveTravCnt;
  2187. canvas->line_cnt = saveLnStart;
  2188. canvas->txt_cnt = saveTxtStart;
  2189. layout->left = newLeft;
  2190. /*
  2191. * for each row, format the cell in this columns
  2192. */
  2193. for (row = 0, redo = False, cell = col;
  2194. row < maxRows && redo == False;
  2195. row++, cell += maxCols)
  2196. {
  2197. /*
  2198. * remember the old height
  2199. */
  2200. rowSpecs[row].lst_height = rowSpecs[row].height;
  2201. /*
  2202. * set the alignment flag for each column in the row.
  2203. */
  2204. layout->info.align_flag = False;
  2205. if (_DtCvJUSTIFY_CHAR == layout->txt_justify ||
  2206. _DtCvJUSTIFY_NUM == layout->txt_justify)
  2207. layout->info.align_flag = True;
  2208. /*
  2209. * remember the alignment position
  2210. */
  2211. oldAlignPos = layout->info.align_pos;
  2212. /*
  2213. * layout all the cells jammed to the top of the table.
  2214. * later, they get moved down to their position.
  2215. */
  2216. layout->info.y_pos = tableYpos;
  2217. redo = ResolveCell(canvas, layout, table,
  2218. colSpecs, rowSpecs, col, row,
  2219. maxCols, maxRows, cellInfo);
  2220. /*
  2221. * check for maximum row span
  2222. */
  2223. if (maxRowSpn < cellInfo[cell].row_spn)
  2224. maxRowSpn = cellInfo[cell].row_spn;
  2225. /*
  2226. * did the cell have borders?
  2227. */
  2228. if (0 != cellInfo[cell].info.cnt.my_lines)
  2229. haveBrds = True;
  2230. /*
  2231. * check to see if the specified anchor has been found in
  2232. * this row. If so, save some information for later use.
  2233. */
  2234. if (anchorRow == -1 && oldFound != layout->id_found)
  2235. anchorRow = row;
  2236. /*
  2237. * check to see if the alignment position has changed.
  2238. * for all but the first row!
  2239. */
  2240. if (0 != row && oldAlignPos != layout->info.align_pos)
  2241. redo = True;
  2242. }
  2243. if (True == redo)
  2244. {
  2245. for (a = 0; a < row; a++)
  2246. {
  2247. /*
  2248. * restore the old row heights for this column
  2249. */
  2250. rowSpecs[a].height = rowSpecs[a].lst_height;
  2251. /*
  2252. * reset the hanging cell information.
  2253. */
  2254. if (col == rowSpecs[a].column)
  2255. {
  2256. rowSpecs[a].column = -1;
  2257. rowSpecs[a].y_adj = 0;
  2258. }
  2259. }
  2260. }
  2261. } while (redo == True);
  2262. /*
  2263. * push the next column to the right by size of this column
  2264. */
  2265. layout->left += colSpecs[col].actual;
  2266. /*
  2267. * restore the horizontal text justification
  2268. */
  2269. layout->txt_justify = colJustify;
  2270. }
  2271. /*
  2272. * set the ending counts for the lines/text in the table.
  2273. * and save the information as long as we are not a table
  2274. * that is a descendant of some container with a border and
  2275. * our cells include borders and we're going to have to honor
  2276. * boundaries.
  2277. */
  2278. SetEndCounts(canvas, &(grpInfo.cnt), 0);
  2279. if (_DtCvUSE_BOUNDARY_MOVE == canvas->constraint &&
  2280. False == layout->brdr_flag && True == haveBrds)
  2281. {
  2282. GrpInfo *info = (GrpInfo *) malloc (sizeof(GrpInfo));
  2283. /*
  2284. * warning - nothing done if malloc error.
  2285. */
  2286. if (NULL != info)
  2287. {
  2288. /*
  2289. * initialize to the line counts for the table
  2290. */
  2291. *info = grpInfo;
  2292. /*
  2293. * set the linked list information
  2294. */
  2295. info->next_info = layout->grp_lst;
  2296. layout->grp_lst = info;
  2297. }
  2298. }
  2299. /*
  2300. * Now go back and search for zeroed row heights and fill them in
  2301. * based on spanned rows. This can only happen if maxRowSpn is
  2302. * greater than 1! Otherwise, a row height really did end up zero!
  2303. */
  2304. if (maxRowSpn > 1)
  2305. {
  2306. /*
  2307. * try to resolve the zero height rows
  2308. */
  2309. for (a = 1, redo = True; redo && a < maxRowSpn; a++)
  2310. {
  2311. redo = False;
  2312. for (row = 0; row < maxRows; row++)
  2313. {
  2314. if (rowSpecs[row].height == 0 &&
  2315. ResolveHeight(rowSpecs, cellInfo, maxCols, row, a) == 0)
  2316. redo = True;
  2317. }
  2318. }
  2319. /*
  2320. * if any of the rows comes up unresolved, force to an average
  2321. * line height.
  2322. *
  2323. * But only do this if the first cell *does not* span all the rows
  2324. * and columns.
  2325. */
  2326. if (redo &&
  2327. cellInfo[0].row_spn != maxRows && cellInfo[0].col_spn != maxCols)
  2328. {
  2329. for (row = 0; row < maxRows; row++)
  2330. {
  2331. if (rowSpecs[row].height == 0)
  2332. rowSpecs[row].height = canvas->metrics.line_height;
  2333. }
  2334. }
  2335. /*
  2336. * Now, double check that the row heights will accommodate
  2337. * all the cells.
  2338. */
  2339. for (row = 0; row < maxRows; row++)
  2340. for (col = 0; col < maxCols; col++)
  2341. AdjustHeight(cellInfo, rowSpecs, maxCols, row, col);
  2342. }
  2343. /*
  2344. * now check that the minimum heights used for the rows matches
  2345. * or exceeds the minimum y position required.
  2346. */
  2347. if (-1 != min_y)
  2348. {
  2349. _DtCvUnit pad;
  2350. for (newHeight = 0, row = 0; row < maxRows; row++)
  2351. newHeight += rowSpecs[row].height;
  2352. if (tableYpos + newHeight < min_y)
  2353. {
  2354. newHeight = tableYpos - min_y;
  2355. for (row = 0; 0 < newHeight && row < maxRows; row++)
  2356. {
  2357. pad = (newHeight/(maxRows-row));
  2358. rowSpecs[row].height += pad;
  2359. newHeight -= pad;
  2360. }
  2361. }
  2362. }
  2363. /*
  2364. * now reposition the cells based on the final row heights.
  2365. */
  2366. layout->info.y_pos = tableYpos;
  2367. for (tableYpos = 0, cell = 0, row = 0; row < maxRows;
  2368. tableYpos = tableYpos + rowSpecs[row].height + rowSpecs[row].y_adj,
  2369. row++)
  2370. {
  2371. /*
  2372. * check to see if the specified anchor has been found in this
  2373. * row. If so, adjust the found position.
  2374. */
  2375. if (anchorRow == row)
  2376. layout->id_Ypos += tableYpos;
  2377. for (col = 0, layout->left = saveLeft; col < maxCols;
  2378. layout->left += colSpecs[col++].actual, cell++)
  2379. {
  2380. if (cellInfo[cell].cell_seg != NULL)
  2381. {
  2382. /*
  2383. * calculate the new height
  2384. */
  2385. for (newHeight = 0, a = 0; a < cellInfo[cell].row_spn; a++)
  2386. {
  2387. newHeight += rowSpecs[row + a].height;
  2388. if (col != rowSpecs[row + a].column)
  2389. newHeight += rowSpecs[row + a].y_adj;
  2390. }
  2391. /*
  2392. * calculate the new width.
  2393. */
  2394. for (newWidth = 0, a = 0; a < cellInfo[cell].col_spn; a++)
  2395. newWidth += colSpecs[col + a].actual;
  2396. /*
  2397. * now get the overhang space for this cell
  2398. */
  2399. workWidth = 0;
  2400. if (col > rowSpecs[row].column)
  2401. workWidth = rowSpecs[row].y_adj;
  2402. /*
  2403. * if the heights (and/or width for spanning columns)
  2404. * are different, check to see if the
  2405. * cell contains lines that may be affected by the
  2406. * height adjustment.
  2407. *
  2408. * It is strongly assumed that if a table specifies that
  2409. * a cell can hang over it's neighbors that it will *NOT*
  2410. * have borders (whereby LinesMayChange is false) and
  2411. * newWidth will not be greater than the cell's width.
  2412. */
  2413. if ((newHeight > cellInfo[cell].info.height &&
  2414. True == LinesMayChange(canvas,
  2415. cellInfo[cell].info.cnt.beg_ln,
  2416. cellInfo[cell].info.cnt.end_ln,
  2417. cellInfo[cell].info.cnt.my_lines))
  2418. ||
  2419. (1 < cellInfo[cell].col_spn &&
  2420. newWidth > cellInfo[cell].info.width))
  2421. ReFormatCell(canvas, layout, &cellInfo[cell], colSpecs,
  2422. col, newHeight,
  2423. layout->info.y_pos + tableYpos);
  2424. else
  2425. /* adjust the cell rather than reformatting */
  2426. AdjustObjectPosition(canvas, layout,
  2427. TxtVertJustify(cellInfo[cell].cell_seg),
  2428. cellInfo[cell].info.cnt.beg_txt ,
  2429. cellInfo[cell].info.cnt.beg_ln ,
  2430. cellInfo[cell].info.cnt.beg_brk ,
  2431. cellInfo[cell].info.cnt.end_txt ,
  2432. cellInfo[cell].info.cnt.end_ln ,
  2433. cellInfo[cell].info.cnt.end_brk ,
  2434. cellInfo[cell].info.cnt.my_lines,
  2435. newHeight - cellInfo[cell].info.height,
  2436. 0,
  2437. tableYpos, workWidth);
  2438. }
  2439. }
  2440. }
  2441. /*
  2442. * increment the maximum y.
  2443. */
  2444. layout->info.y_pos += tableYpos;
  2445. layout->left = saveLeft;
  2446. if (maxCols > 1)
  2447. free(colSpecs);
  2448. if (maxRows > 1)
  2449. free(rowSpecs);
  2450. if (maxRows > 1 || maxCols > 1)
  2451. free(cellInfo);
  2452. layout->txt_justify = saveTxtJustify;
  2453. layout->table_flag = saveState;
  2454. /*
  2455. * restore the alignment information
  2456. */
  2457. layout->info.align_flag = saveAlignFlag;
  2458. layout->info.align_char = saveAlignChar;
  2459. layout->info.align_pos = saveAlignPos;
  2460. }
  2461. /******************************************************************************
  2462. * Function: UpdateDimensionArrays
  2463. *
  2464. * Purpose: Based on the object's orientation and justification,
  2465. * update the correct dimension array(s).
  2466. *
  2467. *****************************************************************************/
  2468. static void
  2469. UpdateDimensionArrays(
  2470. _DtCvSegmentI *p_seg,
  2471. _DtCvUnit width,
  2472. _DtCvUnit height,
  2473. TopDims *top_bot,
  2474. SideDims *side,
  2475. CornerDims *corner,
  2476. FlowDims *flow,
  2477. _DtCvUnit *max_left,
  2478. _DtCvUnit *max_right)
  2479. {
  2480. int i;
  2481. int j;
  2482. int *marginPtr;
  2483. _DtCvFrmtOption orient = ObjHorizOrient(p_seg);
  2484. _DtCvFrmtOption vOrient = ObjVertOrient(p_seg);
  2485. /*
  2486. * modify the width that headSize should be
  2487. */
  2488. j = DIMS_LM;
  2489. i = DIMS_TOP;
  2490. switch (orient)
  2491. {
  2492. case _DtCvJUSTIFY_RIGHT_MARGIN:
  2493. j++;
  2494. case _DtCvJUSTIFY_CENTER:
  2495. j++;
  2496. case _DtCvJUSTIFY_LEFT_MARGIN:
  2497. if (vOrient == _DtCvJUSTIFY_BOTTOM)
  2498. i = DIMS_BOTTOM;
  2499. if ((*top_bot)[i][j][DIMS_WIDTH] < width)
  2500. (*top_bot)[i][j][DIMS_WIDTH] = width;
  2501. if (_DtCvWRAP_JOIN != _DtCvContainerFlowOfSeg(p_seg))
  2502. (*top_bot)[i][j][DIMS_HEIGHT] += height;
  2503. break;
  2504. }
  2505. /*
  2506. * check left & right margins.
  2507. */
  2508. marginPtr = max_left;
  2509. j = DIMS_LEFT;
  2510. i = DIMS_TOP;
  2511. switch(orient)
  2512. {
  2513. case _DtCvJUSTIFY_RIGHT_CORNER:
  2514. case _DtCvJUSTIFY_RIGHT:
  2515. j = DIMS_RIGHT;
  2516. marginPtr = max_right;
  2517. case _DtCvJUSTIFY_LEFT_CORNER:
  2518. case _DtCvJUSTIFY_LEFT:
  2519. if (vOrient != _DtCvJUSTIFY_TOP)
  2520. i++;
  2521. if (vOrient == _DtCvJUSTIFY_BOTTOM)
  2522. i++;
  2523. /*
  2524. * push i to zero or 4
  2525. */
  2526. if (orient == _DtCvJUSTIFY_RIGHT_CORNER ||
  2527. orient == _DtCvJUSTIFY_LEFT_CORNER)
  2528. {
  2529. if (i) i = DIMS_BC;
  2530. (*corner)[i][j] += height;
  2531. if (*marginPtr < width)
  2532. *marginPtr = width;
  2533. }
  2534. else if (_DtCvContainerFlowOfSeg(p_seg) != _DtCvWRAP)
  2535. {
  2536. (*side)[i][j] += height;
  2537. if (*marginPtr < width)
  2538. *marginPtr = width;
  2539. }
  2540. else
  2541. {
  2542. (*flow)[j][DIMS_HEIGHT] += height;
  2543. if ((*flow)[j][DIMS_WIDTH] < width)
  2544. (*flow)[j][DIMS_WIDTH] = width;
  2545. }
  2546. break;
  2547. }
  2548. }
  2549. /******************************************************************************
  2550. * Function: DetermineMaxDims
  2551. *
  2552. *****************************************************************************/
  2553. static void
  2554. DetermineMaxDims(
  2555. TopDims *top_bot,
  2556. CornerDims *corner,
  2557. _DtCvUnit left_margin,
  2558. _DtCvUnit right_margin,
  2559. _DtCvUnit *top_height,
  2560. _DtCvUnit *bot_height,
  2561. _DtCvUnit *max_width)
  2562. {
  2563. int j;
  2564. _DtCvUnit topWidth;
  2565. _DtCvUnit botWidth;
  2566. /*
  2567. * now process all the information gathered about the (sub)headings
  2568. * to determine the bounding box for the (head) txt. Start by figuring
  2569. * out the maximums for the dimensions.
  2570. *
  2571. * figure the current top and bottom max widths.
  2572. */
  2573. topWidth = left_margin + right_margin;
  2574. botWidth = left_margin + right_margin;
  2575. *top_height = 0;
  2576. *bot_height = 0;
  2577. for (j = DIMS_LM; j <= DIMS_RM; j++)
  2578. {
  2579. topWidth = topWidth + (*top_bot)[DIMS_TOP] [j][DIMS_WIDTH];
  2580. botWidth = botWidth + (*top_bot)[DIMS_BOTTOM][j][DIMS_WIDTH];
  2581. if (*top_height < (*top_bot)[DIMS_TOP][j][DIMS_HEIGHT])
  2582. *top_height = (*top_bot)[DIMS_TOP][j][DIMS_HEIGHT];
  2583. if (*bot_height < (*top_bot)[DIMS_BOTTOM][j][DIMS_HEIGHT])
  2584. *bot_height = (*top_bot)[DIMS_BOTTOM][j][DIMS_HEIGHT];
  2585. }
  2586. /*
  2587. * for the maximum top and bottom heights, take into
  2588. * consideration the corner values
  2589. */
  2590. if (*top_height < (*corner)[DIMS_TC][DIMS_LEFT])
  2591. *top_height = (*corner)[DIMS_TC][DIMS_LEFT];
  2592. if (*top_height < (*corner)[DIMS_TC][DIMS_RIGHT])
  2593. *top_height = (*corner)[DIMS_TC][DIMS_RIGHT];
  2594. if (*bot_height < (*corner)[DIMS_BC][DIMS_LEFT])
  2595. *bot_height = (*corner)[DIMS_BC][DIMS_LEFT];
  2596. if (*bot_height < (*corner)[DIMS_BC][DIMS_RIGHT])
  2597. *bot_height = (*corner)[DIMS_BC][DIMS_RIGHT];
  2598. *max_width = topWidth;
  2599. if (*max_width < botWidth)
  2600. *max_width = botWidth;
  2601. }
  2602. /******************************************************************************
  2603. * Function: DetermineFlowConstraints
  2604. *
  2605. *****************************************************************************/
  2606. static void
  2607. DetermineFlowConstraints(
  2608. LayoutInfo *layout,
  2609. FlowDims flow_dims,
  2610. _DtCvUnit left_margin,
  2611. _DtCvUnit right_margin,
  2612. _DtCvUnit start_y,
  2613. DataPoint *left_pt,
  2614. DataPoint *right_pt)
  2615. {
  2616. _DtCvUnit leftSide = flow_dims[DIMS_LEFT][DIMS_HEIGHT];
  2617. _DtCvUnit rightSide = flow_dims[DIMS_RIGHT][DIMS_HEIGHT];
  2618. /*
  2619. * Now, if there is flowing text required, put points on the
  2620. * stack to indicate them.
  2621. */
  2622. left_margin += flow_dims[DIMS_LEFT][DIMS_WIDTH];
  2623. right_margin += flow_dims[DIMS_RIGHT][DIMS_WIDTH];
  2624. GetCurrentDataPoint(layout, left_pt);
  2625. GetCurrentDataPoint(layout, right_pt);
  2626. left_pt->left += left_margin;
  2627. left_pt->right += right_margin;
  2628. left_pt->y_pos = _CEFORMAT_ALL;
  2629. right_pt->left += left_margin;
  2630. right_pt->right += right_margin;
  2631. right_pt->y_pos = _CEFORMAT_ALL;
  2632. while (leftSide > 0 || rightSide > 0)
  2633. {
  2634. if (leftSide > 0)
  2635. {
  2636. if (rightSide == 0 || leftSide <= rightSide)
  2637. {
  2638. left_pt->right = right_margin;
  2639. left_pt->y_pos = start_y + leftSide;
  2640. if (leftSide != rightSide)
  2641. left_margin = 0;
  2642. leftSide = 0;
  2643. InsertDataPoint(layout, left_pt);
  2644. }
  2645. }
  2646. if (rightSide > 0)
  2647. {
  2648. if (leftSide == 0 || leftSide > rightSide)
  2649. {
  2650. right_pt->left = left_margin;
  2651. right_pt->y_pos = start_y + rightSide;
  2652. if (leftSide != rightSide)
  2653. right_margin = 0;
  2654. rightSide = 0;
  2655. InsertDataPoint(layout, right_pt);
  2656. }
  2657. }
  2658. }
  2659. }
  2660. /******************************************************************************
  2661. * Function: DetermineHeadPositioning
  2662. *
  2663. *****************************************************************************/
  2664. static void
  2665. DetermineHeadPositioning(
  2666. TopDims *top_bot,
  2667. SideDims *side,
  2668. CornerDims *corner,
  2669. FlowDims *flow,
  2670. _DtCvUnit start_y,
  2671. _DtCvUnit max_top,
  2672. _DtCvUnit block_size,
  2673. _DtCvUnit *ret_side_size)
  2674. {
  2675. int i;
  2676. _DtCvUnit leftSideHeight = 0;
  2677. _DtCvUnit rightSideHeight = 0;
  2678. _DtCvUnit sideHeight = 0;
  2679. /*
  2680. * determine the maximum side heights
  2681. */
  2682. for (i = DIMS_TOP; i <= DIMS_BOTTOM; i++)
  2683. {
  2684. leftSideHeight += (*side)[i][DIMS_LEFT];
  2685. rightSideHeight += (*side)[i][DIMS_RIGHT];
  2686. }
  2687. /*
  2688. * determine the maximum side height
  2689. */
  2690. sideHeight = block_size;
  2691. if (sideHeight < leftSideHeight)
  2692. sideHeight = leftSideHeight;
  2693. if (sideHeight < rightSideHeight)
  2694. sideHeight = rightSideHeight;
  2695. if (sideHeight < (*flow)[DIMS_LEFT][DIMS_HEIGHT])
  2696. sideHeight = (*flow)[DIMS_LEFT][DIMS_HEIGHT];
  2697. if (sideHeight < (*flow)[DIMS_RIGHT][DIMS_HEIGHT])
  2698. sideHeight = (*flow)[DIMS_RIGHT][DIMS_HEIGHT];
  2699. /*
  2700. * calculate the starting Y position for each of the positions
  2701. * reuse the arrays that were used to save the max dimension values.
  2702. */
  2703. for (i = DIMS_LM; i <= DIMS_RM; i++)
  2704. {
  2705. (*top_bot)[DIMS_TOP] [i][DIMS_YPOS] = start_y;
  2706. (*top_bot)[DIMS_BOTTOM][i][DIMS_YPOS] = start_y + max_top + sideHeight;
  2707. }
  2708. (*corner)[DIMS_TC][DIMS_LEFT] = start_y;
  2709. (*corner)[DIMS_TC][DIMS_RIGHT] = start_y;
  2710. (*corner)[DIMS_BC][DIMS_LEFT] = start_y + max_top + sideHeight;
  2711. (*corner)[DIMS_BC][DIMS_RIGHT] = start_y + max_top + sideHeight;
  2712. (*side)[DIMS_TOP][DIMS_LEFT] = start_y + max_top;
  2713. (*side)[DIMS_TOP][DIMS_RIGHT] = start_y + max_top;
  2714. (*flow)[DIMS_LEFT ][DIMS_YPOS] = start_y + max_top;
  2715. (*flow)[DIMS_RIGHT][DIMS_YPOS] = start_y + max_top;
  2716. (*side)[DIMS_CENTER][DIMS_LEFT] = start_y + max_top +
  2717. (sideHeight - (*side)[DIMS_CENTER][DIMS_LEFT]) / 2;
  2718. (*side)[DIMS_CENTER][DIMS_RIGHT] = start_y + max_top +
  2719. (sideHeight - (*side)[DIMS_CENTER][DIMS_RIGHT]) / 2;
  2720. (*side)[DIMS_BOTTOM][DIMS_LEFT] = start_y + max_top +
  2721. sideHeight - (*side)[DIMS_BOTTOM][DIMS_LEFT];
  2722. (*side)[DIMS_BOTTOM][DIMS_RIGHT] = start_y + max_top +
  2723. sideHeight - (*side)[DIMS_BOTTOM][DIMS_RIGHT];
  2724. if (ret_side_size != NULL)
  2725. *ret_side_size = sideHeight;
  2726. }
  2727. /******************************************************************************
  2728. * Function: AdjustHead
  2729. *
  2730. * Parameters:
  2731. * base_left Specifies the x position that the controller
  2732. * occupying 'left_margin' space would start
  2733. * at.
  2734. * block_width Specifies the body's width for which to
  2735. * center or align a controller with.
  2736. * left_margin Specifies the space used by a controller
  2737. * that is on the left side of the body.
  2738. * right_margin Specifies the space used by a controller
  2739. * on the right side of the body.
  2740. *
  2741. *****************************************************************************/
  2742. static void
  2743. AdjustHeadPosition(
  2744. _DtCanvasStruct *canvas,
  2745. LayoutInfo *layout,
  2746. _DtCvSegmentI *p_seg,
  2747. TopDims *top_bot,
  2748. SideDims *side,
  2749. CornerDims *corner,
  2750. FlowDims *flow,
  2751. LayFrmtInfo *info,
  2752. _DtCvUnit base_y,
  2753. _DtCvUnit base_left,
  2754. _DtCvUnit block_width,
  2755. _DtCvUnit left_margin,
  2756. _DtCvUnit right_margin)
  2757. {
  2758. int i = DIMS_TOP; /* also DIMS_TC */
  2759. int j = DIMS_LEFT; /* also DIMS_LM */
  2760. int divisor = 2;
  2761. _DtCvUnit adjustX = 0;
  2762. _DtCvUnit adjustY = 0;
  2763. _DtCvUnit newY = 0;
  2764. _DtCvUnit headWidth = info->width;
  2765. _DtCvFrmtOption orient = ObjHorizOrient(p_seg);
  2766. _DtCvFrmtOption vOrient = ObjVertOrient(p_seg);
  2767. if (_DtCvContainerPercentOfSeg(p_seg) == 10000
  2768. && orient == _DtCvJUSTIFY_CENTER
  2769. && TxtHorizJustify(p_seg) == _DtCvJUSTIFY_LEFT)
  2770. headWidth = block_width;
  2771. switch (orient)
  2772. {
  2773. case _DtCvJUSTIFY_RIGHT_MARGIN:
  2774. divisor = 1;
  2775. j++;
  2776. case _DtCvJUSTIFY_CENTER:
  2777. adjustX = (block_width - headWidth) / divisor;
  2778. j++;
  2779. case _DtCvJUSTIFY_LEFT_MARGIN:
  2780. adjustX += left_margin;
  2781. if (vOrient == _DtCvJUSTIFY_BOTTOM)
  2782. i = DIMS_BOTTOM;
  2783. newY = (*top_bot)[i][j][DIMS_YPOS];
  2784. (*top_bot)[i][j][DIMS_YPOS] += info->height;
  2785. break;
  2786. case _DtCvJUSTIFY_RIGHT_CORNER:
  2787. adjustX = block_width + left_margin;
  2788. j = DIMS_RIGHT;
  2789. case _DtCvJUSTIFY_LEFT_CORNER:
  2790. if (vOrient == _DtCvJUSTIFY_BOTTOM)
  2791. i = DIMS_BC;
  2792. newY = (*corner)[i][j];
  2793. (*corner)[i][j] += info->height;
  2794. break;
  2795. case _DtCvJUSTIFY_RIGHT:
  2796. adjustX = block_width + left_margin;
  2797. j = DIMS_RIGHT;
  2798. case _DtCvJUSTIFY_LEFT:
  2799. if (vOrient != _DtCvJUSTIFY_TOP)
  2800. i++;
  2801. if (vOrient == _DtCvJUSTIFY_BOTTOM)
  2802. i++;
  2803. if (_DtCvContainerFlowOfSeg(p_seg) == _DtCvWRAP)
  2804. {
  2805. if (orient == _DtCvJUSTIFY_LEFT)
  2806. adjustX += left_margin;
  2807. else
  2808. adjustX -= headWidth;
  2809. newY = (*flow)[j][DIMS_YPOS];
  2810. (*flow)[j][DIMS_YPOS] += info->height;
  2811. }
  2812. else
  2813. {
  2814. newY = (*side)[i][j];
  2815. (*side)[i][j] += info->height;
  2816. }
  2817. break;
  2818. }
  2819. adjustY = newY - base_y;
  2820. adjustX += base_left;
  2821. /*
  2822. * adjust the text positions
  2823. */
  2824. AdjustTextPositions(canvas, info->cnt.beg_txt, info->cnt.end_txt,
  2825. adjustX, adjustY);
  2826. /*
  2827. * adjust the lines positions
  2828. */
  2829. AdjustLinePositions(canvas, info->cnt.beg_ln, info->cnt.end_ln,
  2830. adjustX, adjustY);
  2831. /*
  2832. * adjust the page breaks, but only if necessary.
  2833. */
  2834. AdjustPgBrk(canvas, info->cnt.beg_brk, info->cnt.end_brk, adjustY);
  2835. }
  2836. /******************************************************************************
  2837. * Function: InitDimArrays
  2838. *
  2839. *****************************************************************************/
  2840. static void
  2841. InitDimArrays(
  2842. TopDims *top_bot,
  2843. SideDims *side,
  2844. CornerDims *corner,
  2845. FlowDims *flow)
  2846. {
  2847. int i;
  2848. int j;
  2849. for (i = DIMS_TOP; i <= DIMS_BOTTOM; i++)
  2850. {
  2851. for (j = DIMS_LM; j <= DIMS_RM; j++)
  2852. {
  2853. (*top_bot)[i][j][DIMS_WIDTH] = 0;
  2854. (*top_bot)[i][j][DIMS_HEIGHT] = 0;
  2855. }
  2856. for (j = DIMS_LEFT; j <= DIMS_RIGHT; j++)
  2857. (*side)[i][j] = 0;
  2858. }
  2859. for (i = DIMS_LEFT; i <= DIMS_RIGHT; i++)
  2860. {
  2861. for (j = DIMS_WIDTH; j <= DIMS_HEIGHT; j++)
  2862. {
  2863. (*corner)[i][j] = 0;
  2864. (*flow)[i][j] = 0;
  2865. }
  2866. }
  2867. }
  2868. /******************************************************************************
  2869. * Function: ProcessController
  2870. *****************************************************************************/
  2871. static LayFrmtInfo *
  2872. ProcessController(
  2873. _DtCanvasStruct *canvas,
  2874. LayoutInfo *layout,
  2875. _DtCvSegmentI *cur_seg)
  2876. {
  2877. int getLn;
  2878. int saveTravCnt = canvas->trav_cnt;
  2879. _DtCvUnit saveYPos = layout->info.y_pos;
  2880. _DtCvUnit saveMaxWidth = layout->max_width;
  2881. _DtCvUnit saveLeft = layout->left;
  2882. _DtCvUnit saveRight = layout->right;
  2883. _DtCvUnit maxWidth;
  2884. _DtCvUnit maxXPos;
  2885. _DtCvUnit myMaxWidth;
  2886. LayFrmtInfo *frmtInfo;
  2887. DataPoint basePt;
  2888. DataPoint zeroPt;
  2889. _DtCvValue redo;
  2890. /*
  2891. * Controllers always break the formatting sequence.
  2892. * So save any information in the buffer, reset the margins and
  2893. * add the appropriate lines, and check for going over boundaries.
  2894. */
  2895. CheckSaveInfo(canvas, layout, cur_seg, 0);
  2896. CheckFormat(layout, True);
  2897. /*
  2898. * Get the controller specific information.
  2899. * disallow some of the orientation & vOrient combinations
  2900. */
  2901. if ((ObjHorizOrient(cur_seg) == _DtCvJUSTIFY_CENTER
  2902. && ObjVertOrient(cur_seg) != _DtCvJUSTIFY_BOTTOM)
  2903. ||
  2904. (ObjVertOrient(cur_seg) == _DtCvJUSTIFY_CENTER
  2905. && ObjHorizOrient(cur_seg) != _DtCvJUSTIFY_LEFT
  2906. && ObjHorizOrient(cur_seg) != _DtCvJUSTIFY_RIGHT))
  2907. ObjVertOrient(cur_seg) = _DtCvJUSTIFY_TOP;
  2908. if (_DtCvContainerFlowOfSeg(cur_seg) == _DtCvWRAP
  2909. &&
  2910. (ObjVertOrient(cur_seg) != _DtCvJUSTIFY_TOP
  2911. ||
  2912. (ObjVertOrient(cur_seg) == _DtCvJUSTIFY_TOP
  2913. && ObjHorizOrient(cur_seg) != _DtCvJUSTIFY_LEFT
  2914. && ObjHorizOrient(cur_seg) != _DtCvJUSTIFY_RIGHT)))
  2915. _DtCvContainerFlowOfSeg(cur_seg) = _DtCvWRAP_NONE;
  2916. if (_DtCvContainerFlowOfSeg(cur_seg) == _DtCvWRAP_JOIN
  2917. &&
  2918. (ObjVertOrient(cur_seg) != _DtCvJUSTIFY_TOP
  2919. || ObjHorizOrient(cur_seg) != _DtCvJUSTIFY_LEFT_MARGIN))
  2920. {
  2921. ObjVertOrient(cur_seg) = _DtCvJUSTIFY_TOP;
  2922. ObjHorizOrient(cur_seg) = _DtCvJUSTIFY_LEFT_MARGIN;
  2923. }
  2924. /*
  2925. * malloc a formatting dimension structure and initialize it with
  2926. * default values. This will be returned to the caller.
  2927. */
  2928. frmtInfo = (LayFrmtInfo *) malloc (sizeof(LayFrmtInfo));
  2929. *frmtInfo = DefLayFrmtInfo;
  2930. /*
  2931. * the controller object begins here.
  2932. */
  2933. SetBeginCounts(canvas, &(frmtInfo->cnt));
  2934. /*
  2935. * set the parent's data point in the stack
  2936. */
  2937. GetCurrentDataPoint(layout, &basePt);
  2938. /*
  2939. * calculate the amount of space the controller can occupy.
  2940. * first calculate the amount of space to work with.
  2941. * then truncate to zero if necessary.
  2942. * then use the percentage of that remaining area as the space
  2943. * the controller's segments can occupy.
  2944. */
  2945. myMaxWidth = layout->max_width - basePt.left - basePt.right
  2946. - saveLeft - saveRight;
  2947. if (myMaxWidth < 0)
  2948. myMaxWidth = 0;
  2949. myMaxWidth = (_DtCvUnit) (((double) myMaxWidth)
  2950. * ((double) _DtCvContainerPercentOfSeg(cur_seg))
  2951. / HeadDivisor);
  2952. /*
  2953. * Format the controller at a 'zero'ed point.
  2954. * The lines it generates will be moved later to their correct position.
  2955. */
  2956. layout->left = 0;
  2957. layout->right = 0;
  2958. zeroPt = DefDataPt;
  2959. PushDataPoint(layout, &zeroPt);
  2960. /*
  2961. * now process as a regular container
  2962. */
  2963. do {
  2964. /*
  2965. * set some counts and flags (necessary for a redo).
  2966. */
  2967. redo = False;
  2968. canvas->trav_cnt = saveTravCnt;
  2969. canvas->line_cnt = frmtInfo->cnt.beg_ln;
  2970. canvas->txt_cnt = frmtInfo->cnt.beg_txt;
  2971. layout->max_width = myMaxWidth;
  2972. layout->info.y_pos = 0;
  2973. /*
  2974. * process the container
  2975. */
  2976. ProcessContainer(canvas,layout,cur_seg,-1,&maxWidth,&maxXPos,&getLn);
  2977. /*
  2978. * check to see if we need to reformat because the minimum size
  2979. * is larger than we asked for.
  2980. */
  2981. if (maxXPos + _DtCvContainerRMarginOfSeg(cur_seg) > myMaxWidth)
  2982. {
  2983. redo = True;
  2984. myMaxWidth = maxXPos + _DtCvContainerRMarginOfSeg(cur_seg);
  2985. }
  2986. } while (True == redo);
  2987. /*
  2988. * remove this element's data points from the stack.
  2989. */
  2990. RemoveDataPoint(layout, &zeroPt);
  2991. /*
  2992. * set the ending counts for the items in this container.
  2993. */
  2994. SetEndCounts(canvas, &(frmtInfo->cnt), getLn);
  2995. frmtInfo->width = myMaxWidth;
  2996. frmtInfo->height = layout->info.y_pos;
  2997. /*
  2998. * does this controller want to join with the lines in a non-controller?
  2999. */
  3000. if (_DtCvWRAP_JOIN == _DtCvContainerFlowOfSeg(cur_seg)
  3001. && frmtInfo->cnt.beg_txt != canvas->txt_cnt)
  3002. _DtCvSetJoinInfo(&(layout->info), True, canvas->txt_cnt - 1);
  3003. /*
  3004. * Restore the previous information
  3005. */
  3006. if (NULL != layout->lst_rendered)
  3007. layout->lst_rendered->next_disp = NULL;
  3008. layout->left = saveLeft;
  3009. layout->right = saveRight;
  3010. layout->max_width = saveMaxWidth;
  3011. layout->lst_rendered = NULL;
  3012. layout->info.y_pos = saveYPos;
  3013. return frmtInfo;
  3014. }
  3015. /******************************************************************************
  3016. * Function: AdjustForBorders
  3017. *
  3018. * Initializes the display line and graphic tables.
  3019. *****************************************************************************/
  3020. static void
  3021. AdjustForBorders(
  3022. _DtCanvasStruct *canvas,
  3023. LayoutInfo *layout,
  3024. _DtCvFrmtOption brdr,
  3025. _DtCvUnit line_width,
  3026. _DtCvUnit *ret_bot,
  3027. _DtCvUnit *ret_right)
  3028. {
  3029. /*
  3030. * if the line_width is zero, make it 1 so that is really takes
  3031. * up some space.
  3032. */
  3033. if (0 == line_width)
  3034. line_width = 1;
  3035. /*
  3036. * set the flag for processing a border
  3037. */
  3038. if (_DtCvBORDER_NONE != brdr)
  3039. layout->brdr_flag = True;
  3040. /*
  3041. * check to see if this element has a border. If so, adjust the
  3042. * boundaries.
  3043. */
  3044. if (brdr == _DtCvBORDER_FULL || brdr == _DtCvBORDER_HORZ
  3045. || brdr == _DtCvBORDER_TOP
  3046. || brdr == _DtCvBORDER_TOP_LEFT
  3047. || brdr == _DtCvBORDER_TOP_RIGHT)
  3048. layout->info.y_pos += line_width;
  3049. *ret_bot = 0;
  3050. if (brdr == _DtCvBORDER_FULL || brdr == _DtCvBORDER_HORZ
  3051. || brdr == _DtCvBORDER_BOTTOM
  3052. || brdr == _DtCvBORDER_BOTTOM_LEFT
  3053. || brdr == _DtCvBORDER_BOTTOM_RIGHT)
  3054. *ret_bot = line_width;
  3055. if (brdr == _DtCvBORDER_FULL || brdr == _DtCvBORDER_VERT
  3056. || brdr == _DtCvBORDER_LEFT
  3057. || brdr == _DtCvBORDER_TOP_LEFT
  3058. || brdr == _DtCvBORDER_BOTTOM_LEFT)
  3059. layout->left += line_width;
  3060. *ret_right = 0;
  3061. if (brdr == _DtCvBORDER_FULL || brdr == _DtCvBORDER_VERT
  3062. || brdr == _DtCvBORDER_RIGHT
  3063. || brdr == _DtCvBORDER_TOP_RIGHT
  3064. || brdr == _DtCvBORDER_BOTTOM_RIGHT)
  3065. {
  3066. layout->right += line_width;
  3067. *ret_right = line_width;
  3068. }
  3069. }
  3070. /******************************************************************************
  3071. * Function: DrawBorders
  3072. *
  3073. * Parameters:
  3074. * canvas Specifies the virtual canvas on which
  3075. * lines are drawn.
  3076. * layout Specifies the current layout information.
  3077. * brdr Specifies the type of border.
  3078. * top_y Specifes the top y of the bounding box for
  3079. * the object. Any border drawn should be
  3080. * completely below this y.
  3081. * bot_y Specifes the bottom y of the bounding box
  3082. * for the object. Any border drawn should be
  3083. * completely below this y.
  3084. * left_x Specifies the left x of the bounding box
  3085. * for the object. Any border drawn should be
  3086. * completely to the right of this x.
  3087. * right_x Specifies the right x of the bounding box
  3088. * for the object. Any border drawn should be
  3089. * completely to the left of this x.
  3090. *
  3091. * left_x right_x
  3092. * | |
  3093. * v v
  3094. * top_y ---> xxxxxxxxxxxxxxxxxxxxxx
  3095. * xxxxxxxxxxxxxxxxxxxxxx
  3096. * xx------------------xx
  3097. * xx| |xx (xx represents the line.)
  3098. * xx| |xx
  3099. * xx| |xx
  3100. * xx| |xx
  3101. * xx------------------xx
  3102. * bot_y ---> xxxxxxxxxxxxxxxxxxxxxx
  3103. * xxxxxxxxxxxxxxxxxxxxxx
  3104. *
  3105. *****************************************************************************/
  3106. static int
  3107. DrawBorders(
  3108. _DtCanvasStruct *canvas,
  3109. LayoutInfo *layout,
  3110. _DtCvFrmtOption brdr,
  3111. _DtCvPointer data,
  3112. _DtCvUnit line_width,
  3113. _DtCvUnit top_y,
  3114. _DtCvUnit bot_y,
  3115. _DtCvUnit left_x,
  3116. _DtCvUnit right_x)
  3117. {
  3118. int mod = 1;
  3119. int cnt = canvas->line_cnt;
  3120. _DtCvUnit width;
  3121. /*
  3122. * if line_width is zero, make it 1 so that it really takes
  3123. * up some space.
  3124. */
  3125. if (0 == line_width)
  3126. line_width = 1;
  3127. /*
  3128. * calculate the width of the element.
  3129. */
  3130. width = right_x - left_x;
  3131. /*
  3132. * If borders are specified, draw them
  3133. */
  3134. if (brdr != _DtCvBORDER_NONE)
  3135. {
  3136. /*
  3137. * now do the horizontal borders. the coordinates are the top,
  3138. * left most unit of the line.
  3139. */
  3140. switch(brdr)
  3141. {
  3142. case _DtCvBORDER_FULL:
  3143. case _DtCvBORDER_HORZ:
  3144. case _DtCvBORDER_BOTTOM:
  3145. case _DtCvBORDER_BOTTOM_LEFT:
  3146. case _DtCvBORDER_BOTTOM_RIGHT:
  3147. SaveLine(canvas, layout, _DtCvLINE_HORZ,
  3148. data, line_width,
  3149. left_x, bot_y, width);
  3150. mod = -1;
  3151. if (brdr == _DtCvBORDER_BOTTOM
  3152. || brdr == _DtCvBORDER_BOTTOM_LEFT
  3153. || brdr == _DtCvBORDER_BOTTOM_RIGHT)
  3154. break;
  3155. case _DtCvBORDER_TOP:
  3156. case _DtCvBORDER_TOP_LEFT:
  3157. case _DtCvBORDER_TOP_RIGHT:
  3158. SaveLine(canvas, layout, _DtCvLINE_HORZ,
  3159. data, line_width,
  3160. left_x, top_y, width);
  3161. }
  3162. /*
  3163. * for vertical lines, the coordinates are the top, right most
  3164. * unit of the line.
  3165. */
  3166. switch(brdr)
  3167. {
  3168. case _DtCvBORDER_FULL:
  3169. case _DtCvBORDER_BOTTOM_LEFT:
  3170. /*
  3171. * include the line width in length for a full
  3172. * border.
  3173. */
  3174. bot_y += line_width;
  3175. case _DtCvBORDER_VERT:
  3176. case _DtCvBORDER_LEFT:
  3177. case _DtCvBORDER_TOP_LEFT:
  3178. SaveLine(canvas, layout, _DtCvLINE_VERT,
  3179. data, line_width,
  3180. left_x, top_y, bot_y - top_y);
  3181. if (brdr == _DtCvBORDER_LEFT
  3182. || brdr == _DtCvBORDER_TOP_LEFT
  3183. || brdr == _DtCvBORDER_BOTTOM_LEFT)
  3184. break;
  3185. case _DtCvBORDER_BOTTOM_RIGHT:
  3186. /*
  3187. * if we didn't fall thru from above, we need to
  3188. * add the extension to the bottom to get the
  3189. * full length for the right vertical line.
  3190. */
  3191. if (brdr == _DtCvBORDER_BOTTOM_RIGHT)
  3192. bot_y += line_width;
  3193. case _DtCvBORDER_RIGHT:
  3194. case _DtCvBORDER_TOP_RIGHT:
  3195. SaveLine(canvas, layout, _DtCvLINE_VERT,
  3196. data, line_width,
  3197. right_x - line_width, top_y, bot_y - top_y);
  3198. }
  3199. }
  3200. return ((canvas->line_cnt - cnt) * mod);
  3201. }
  3202. /******************************************************************************
  3203. * Function: AdjustObjectPosition
  3204. *
  3205. * Parameters:
  3206. * canvas Specifies the virtual canvas on which
  3207. * lines are drawn.
  3208. * justify Specifies the vertical adjustment for the
  3209. * object.
  3210. * start_txt Specifies the start index of the text list.
  3211. * start_gr Specifies the start index of the graphics list.
  3212. * start_ln Specifies the start index of the line list.
  3213. * end_txt Specifies the end indext of the text list.
  3214. * end_gr Specifies the end indext of the graphics list.
  3215. * end_ln Specifies the end indext of the line list.
  3216. * height_adj Specifies the internal height adjust value.
  3217. * Depending on the justify type, this may
  3218. * add to y_adj for text and regions, bottom
  3219. * lines and the height of vertical lines.
  3220. * y_adj Specifies the y position adjustment.
  3221. * Lines, text and regions are moved this
  3222. * amount.
  3223. * internal_y Specifies the internal y position adjustment.
  3224. * height_adj includes this value. Text and
  3225. * regions are moved this amount.
  3226. *
  3227. * Return: nothing.
  3228. *
  3229. *****************************************************************************/
  3230. static void
  3231. AdjustObjectPosition(
  3232. _DtCanvasStruct *canvas,
  3233. LayoutInfo *layout,
  3234. _DtCvFrmtOption justify,
  3235. int start_txt,
  3236. int start_ln,
  3237. int start_brk,
  3238. int end_txt,
  3239. int end_ln,
  3240. int end_brk,
  3241. int brdr_cnt,
  3242. _DtCvUnit height_adj,
  3243. _DtCvUnit x_adj,
  3244. _DtCvUnit y_adj,
  3245. _DtCvUnit internal_y)
  3246. {
  3247. int mod = 1;
  3248. _DtCvUnit yOff = 0;
  3249. /*
  3250. * If border count is negative, indicates the first line in the
  3251. * list is bottom line. This requires special handling in adjusting
  3252. * its position. Set flags accordingly.
  3253. */
  3254. if (brdr_cnt < 0)
  3255. {
  3256. mod = -1;
  3257. brdr_cnt = -brdr_cnt;
  3258. }
  3259. /*
  3260. * calculate the offset value within the object for other objects
  3261. * contained in this object.
  3262. */
  3263. if (justify != _DtCvJUSTIFY_TOP)
  3264. {
  3265. yOff = height_adj - internal_y;
  3266. if (justify == _DtCvJUSTIFY_CENTER)
  3267. yOff /= 2;
  3268. }
  3269. yOff += y_adj;
  3270. yOff += internal_y;
  3271. /*
  3272. * don't modify the border lines around this object yet.
  3273. */
  3274. end_ln -= brdr_cnt;
  3275. /*
  3276. * modify the border lines of the objects contained within
  3277. * this object.
  3278. */
  3279. AdjustLinePositions(canvas, start_ln, end_ln, x_adj, yOff);
  3280. /*
  3281. * now adjust the border lines around this object.
  3282. */
  3283. start_ln = end_ln;
  3284. end_ln += brdr_cnt;
  3285. AdjustLinePositions(canvas, start_ln, end_ln, x_adj, y_adj);
  3286. /*
  3287. * now fix the lines if they've changed height and move
  3288. * the first line to its bottom position if necessary.
  3289. */
  3290. if (0 != height_adj)
  3291. {
  3292. while (start_ln < end_ln)
  3293. {
  3294. /*
  3295. * indicates the bottom line is the first line in the
  3296. * list. Move it down the height adjustment.
  3297. */
  3298. if (mod < 0)
  3299. {
  3300. canvas->line_lst[start_ln].pos_y += height_adj;
  3301. canvas->line_lst[start_ln].max_y += height_adj;
  3302. mod = 1;
  3303. }
  3304. /*
  3305. * stretch the vertical lines
  3306. */
  3307. else if (canvas->line_lst[start_ln].dir == _DtCvLINE_VERT)
  3308. canvas->line_lst[start_ln].max_y += height_adj;
  3309. start_ln++;
  3310. }
  3311. }
  3312. /*
  3313. * adjust the position of the text within this object.
  3314. */
  3315. AdjustTextPositions (canvas, start_txt, end_txt, x_adj, yOff);
  3316. /*
  3317. * adjust the position of the text within this object.
  3318. */
  3319. AdjustPgBrk (canvas, start_brk, end_brk, yOff);
  3320. }
  3321. /******************************************************************************
  3322. * Function: LinesMayChange
  3323. *
  3324. * Parameters:
  3325. * canvas Specifies the virtual canvas on which
  3326. * lines are drawn.
  3327. * start_ln Specifies the start index of the line list.
  3328. * end_ln Specifies the end indext of the line list.
  3329. *
  3330. * Return: True if there is a vertical line as a child of a container.
  3331. * False if there are no vertical lines in the child of a
  3332. * container/cell.
  3333. *
  3334. *****************************************************************************/
  3335. static _DtCvValue
  3336. LinesMayChange(
  3337. _DtCanvasStruct *canvas,
  3338. int start_ln,
  3339. int end_ln,
  3340. int brdr_cnt)
  3341. {
  3342. /*
  3343. * If border count is negative, indicates that one of the lines
  3344. * is for the bottom of the container/cell. Ignore for now.
  3345. * we want to check the lines in the container/cell.
  3346. */
  3347. if (brdr_cnt < 0)
  3348. brdr_cnt = -brdr_cnt;
  3349. /*
  3350. * get rid of the line count for this object,
  3351. * AdjustObjectPosition can take care of it.
  3352. */
  3353. end_ln -= brdr_cnt;
  3354. /*
  3355. * Now check for vertical lines that would
  3356. * be affected by a height change.
  3357. */
  3358. while (start_ln < end_ln)
  3359. {
  3360. if (_DtCvLINE_VERT == canvas->line_lst[start_ln].dir)
  3361. return True;
  3362. start_ln++;
  3363. }
  3364. return False;
  3365. }
  3366. /******************************************************************************
  3367. * Function: ProcessContainer
  3368. *
  3369. * Initializes the display line and graphic tables.
  3370. *****************************************************************************/
  3371. static void
  3372. ProcessContainer(
  3373. _DtCanvasStruct *canvas,
  3374. LayoutInfo *layout,
  3375. _DtCvSegmentI *con_seg,
  3376. _DtCvUnit min_y,
  3377. _DtCvUnit *ret_width,
  3378. _DtCvUnit *ret_max_x,
  3379. int *ret_cnt)
  3380. {
  3381. int getLn;
  3382. const char *saveJustifyChar = layout->info.align_char;
  3383. _DtCvUnit yPad = 0;
  3384. _DtCvUnit xPad = 0;
  3385. _DtCvUnit maxWidth = 0;
  3386. _DtCvUnit maxXPos = 0;
  3387. _DtCvUnit myMinY = -1;
  3388. _DtCvUnit saveLeft = layout->left;
  3389. _DtCvUnit saveRight = layout->right;
  3390. _DtCvUnit saveLead = layout->info.leading;
  3391. _DtCvUnit saveFirst = layout->first;
  3392. _DtCvUnit saveYpos = layout->info.y_pos;
  3393. _DtCvValue saveStatic = layout->stat_flag;
  3394. _DtCvValue saveBrdr = layout->brdr_flag;
  3395. _DtCvFrmtOption saveJustify = layout->txt_justify;
  3396. LayFrmtInfo frmtInfo;
  3397. DataPoint basePt;
  3398. DataPoint curPt;
  3399. /*
  3400. * check to see if this element breaks the formatting sequence.
  3401. * If so save any information in the buffer, reset the margins and
  3402. * add the appropriate lines, and check for going over boundaries.
  3403. */
  3404. if (NotJoining(layout))
  3405. {
  3406. CheckSaveInfo(canvas, layout, con_seg, 0);
  3407. CheckFormat(layout, True);
  3408. }
  3409. /*
  3410. * check to see if this segment is the segment we want as our first
  3411. * visible line.
  3412. */
  3413. CheckId(layout, _DtCvContainerIdOfSeg(con_seg));
  3414. /*
  3415. * Set beginning text and line counts
  3416. */
  3417. frmtInfo = DefLayFrmtInfo;
  3418. SetBeginCounts(canvas, &(frmtInfo.cnt));
  3419. /*
  3420. * Get the first indent and set the current container pointer to me.
  3421. */
  3422. layout->first = _DtCvContainerFMarginOfSeg(con_seg) / layout->divisor;
  3423. layout->left = _DtCvContainerLMarginOfSeg(con_seg) / layout->divisor;
  3424. layout->right = _DtCvContainerRMarginOfSeg(con_seg) / layout->divisor;
  3425. layout->info.leading = _DtCvContainerLeadingOfSeg(con_seg);
  3426. /*
  3427. * check to see if we violate the horiz_pad_hint on the left, right or
  3428. * first margins.
  3429. */
  3430. if (canvas->metrics.horiz_pad_hint > _DtCvContainerLMarginOfSeg(con_seg))
  3431. layout->left = _DtCvContainerLMarginOfSeg(con_seg);
  3432. else if (layout->left < canvas->metrics.horiz_pad_hint)
  3433. layout->left = canvas->metrics.horiz_pad_hint;
  3434. if (canvas->metrics.horiz_pad_hint > _DtCvContainerRMarginOfSeg(con_seg))
  3435. layout->right = _DtCvContainerRMarginOfSeg(con_seg);
  3436. else if (layout->right < canvas->metrics.horiz_pad_hint)
  3437. layout->right = canvas->metrics.horiz_pad_hint;
  3438. if (canvas->metrics.horiz_pad_hint > _DtCvContainerFMarginOfSeg(con_seg))
  3439. layout->first = _DtCvContainerFMarginOfSeg(con_seg);
  3440. else if (layout->first < canvas->metrics.horiz_pad_hint)
  3441. layout->first = canvas->metrics.horiz_pad_hint;
  3442. /*
  3443. * check to see if there is more squeeze room available.
  3444. */
  3445. if (layout->left > canvas->metrics.horiz_pad_hint
  3446. || layout->right > canvas->metrics.horiz_pad_hint
  3447. || layout->first > canvas->metrics.horiz_pad_hint)
  3448. layout->margin_non_zero = True;
  3449. /*
  3450. * set the formatting type for this container
  3451. */
  3452. layout->stat_flag = False;
  3453. if (_DtCvContainerTypeOfSeg(con_seg) == _DtCvLITERAL)
  3454. layout->stat_flag = True;
  3455. /*
  3456. * check to see if this element breaks the formatting sequence.
  3457. * If so, add lines, etc.
  3458. */
  3459. if (NotJoining(layout))
  3460. {
  3461. /*
  3462. * Adjust margins and y position for bordering
  3463. */
  3464. AdjustForBorders (canvas, layout, Border(con_seg), BrdWidth(con_seg),
  3465. &yPad, &xPad);
  3466. _DtCvAddSpace(_DtCvContainerTMarginOfSeg(con_seg),
  3467. &(layout->info.y_pos));
  3468. /*
  3469. * check for flow limits.
  3470. */
  3471. CheckFormat(layout, True);
  3472. /*
  3473. * get the parent's data point in the stack
  3474. * and add the current container's left and right to it.
  3475. */
  3476. GetCurrentDataPoint(layout, &basePt);
  3477. basePt.left += saveLeft;
  3478. basePt.right += saveRight;
  3479. /*
  3480. * if we don't inherit the the text justification
  3481. * set the new value.
  3482. */
  3483. if (_DtCvINHERIT != _DtCvContainerJustifyOfSeg(con_seg))
  3484. {
  3485. layout->txt_justify = _DtCvContainerJustifyOfSeg(con_seg);
  3486. if (_DtCvJUSTIFY_NUM == layout->txt_justify)
  3487. layout->info.align_char = PeriodStr;
  3488. else if (_DtCvJUSTIFY_CHAR == layout->txt_justify)
  3489. {
  3490. layout->info.align_char = _DtCvContainerJustifyCharOfSeg(con_seg);
  3491. /*
  3492. * check to see if the character is 'valid'.
  3493. * if not, default out of JUSTIFY_CHAR
  3494. */
  3495. if ( (NULL != layout->info.align_char) && ( '\0' != *layout->info.align_char))
  3496. layout->txt_justify = _DtCvJUSTIFY_LEFT;
  3497. }
  3498. }
  3499. /*
  3500. * terminate the previous rendering list
  3501. */
  3502. if (NULL != layout->lst_rendered)
  3503. layout->lst_rendered->next_disp = NULL;
  3504. layout->lst_rendered = NULL;
  3505. /*
  3506. * push the data point and reset margin/text info.
  3507. */
  3508. PushDataPoint(layout, &basePt);
  3509. SetMargins(layout);
  3510. SetTextPosition(layout, True);
  3511. }
  3512. /*
  3513. * determine the minimum Y that the child of this container should
  3514. * occupy. To do so, subtract off the bottom border pad and the
  3515. * bottom margin.
  3516. */
  3517. if (0 < min_y)
  3518. {
  3519. myMinY = min_y - yPad;
  3520. if (_DtCvWRAP_JOIN != _DtCvContainerFlowOfSeg(con_seg))
  3521. {
  3522. _DtCvUnit bPad = 0;
  3523. _DtCvAddSpace(_DtCvContainerBMarginOfSeg(con_seg), &bPad);
  3524. myMinY -= bPad;
  3525. }
  3526. }
  3527. /*
  3528. * format the segment
  3529. */
  3530. saveYpos = layout->info.y_pos;
  3531. GetCurrentDataPoint(layout, &curPt);
  3532. /*
  3533. * reset the max x variable
  3534. */
  3535. layout->info.cur_max_x = 0;
  3536. ProcessSegmentList(canvas, layout, _DtCvContainerListOfSeg(con_seg),
  3537. myMinY,
  3538. &maxWidth, &maxXPos, NULL);
  3539. /*
  3540. * if this container forces a wrap join of the next item,
  3541. * save the current line, but don't add space or null the
  3542. * last rendered item.
  3543. */
  3544. CheckSaveInfo(canvas, layout, con_seg, 0);
  3545. if (maxWidth < layout->info.cur_max_x - curPt.left + layout->right)
  3546. maxWidth = layout->info.cur_max_x - curPt.left + layout->right;
  3547. if (maxXPos < layout->info.cur_max_x)
  3548. maxXPos = layout->info.cur_max_x;
  3549. if (_DtCvWRAP_JOIN != _DtCvContainerFlowOfSeg(con_seg))
  3550. {
  3551. /*
  3552. * Save any information in the buffer,
  3553. * reset the margins and add the appropriate lines,
  3554. * and check for going over boundaries.
  3555. */
  3556. _DtCvAddSpace(_DtCvContainerBMarginOfSeg(con_seg),
  3557. &(layout->info.y_pos));
  3558. /*
  3559. * terminate the previous rendering list
  3560. */
  3561. if (NULL != layout->lst_rendered)
  3562. layout->lst_rendered->next_disp = NULL;
  3563. layout->lst_rendered = NULL;
  3564. }
  3565. /*
  3566. * remove this element's data points from the stack.
  3567. */
  3568. RemoveDataPoint(layout, &basePt);
  3569. /*
  3570. * include the bottom border (if needed) in the ending y position
  3571. */
  3572. layout->info.y_pos += yPad;
  3573. /*
  3574. * Set the ending counts for the lines and text in me.
  3575. * This sets the ending counts for the lines contained in me,
  3576. * NOT the lines in my border.
  3577. */
  3578. SetEndCounts(canvas, &(frmtInfo.cnt), 0);
  3579. /*
  3580. * does this object need to be adjust within its height?
  3581. */
  3582. if (0 < min_y && layout->info.y_pos < min_y)
  3583. {
  3584. AdjustObjectPosition(canvas, layout, TxtVertJustify(con_seg),
  3585. frmtInfo.cnt.beg_txt, frmtInfo.cnt.beg_ln,
  3586. frmtInfo.cnt.beg_brk,
  3587. frmtInfo.cnt.end_txt, frmtInfo.cnt.end_ln,
  3588. frmtInfo.cnt.end_brk,
  3589. 0, min_y - layout->info.y_pos - yPad, 0, 0, 0);
  3590. layout->info.y_pos = min_y;
  3591. }
  3592. /*
  3593. * Now draw the borders
  3594. * If borders are drawn, cur_max_x & max_x_pos may get changed
  3595. * if a right side border is drawn.
  3596. */
  3597. if (maxWidth < layout->max_width - curPt.left - curPt.right)
  3598. maxWidth = layout->max_width - curPt.left - curPt.right;
  3599. getLn = DrawBorders (canvas, layout, Border(con_seg),
  3600. BrdData(con_seg), BrdWidth(con_seg),
  3601. saveYpos, layout->info.y_pos - yPad,
  3602. curPt.left,
  3603. curPt.left + maxWidth);
  3604. /*
  3605. * check to see if we need to save the container counts away
  3606. * because we might need to move the entire container as one
  3607. * to honor the boundary. This will occur if the flag to honor
  3608. * a boundary is set to _DtCvUSE_BOUNDARY_MOVE, this container has
  3609. * border lines, the container's parent is not a table nor
  3610. * is the container within another container that has a border.
  3611. */
  3612. if (_DtCvUSE_BOUNDARY_MOVE == canvas->constraint
  3613. && True == layout->brdr_flag
  3614. && False == saveBrdr && False == layout->table_flag)
  3615. {
  3616. GrpInfo *info = (GrpInfo *) malloc (sizeof(GrpInfo));
  3617. /*
  3618. * warning - nothing done if malloc error.
  3619. */
  3620. if (NULL != info)
  3621. {
  3622. /*
  3623. * initialize to the end information of the container.
  3624. */
  3625. info->cnt = frmtInfo.cnt;
  3626. /*
  3627. * take into account the borders for this container
  3628. */
  3629. SetEndCounts(canvas, &(info->cnt), getLn);
  3630. /*
  3631. * set the linked list information
  3632. */
  3633. info->next_info = layout->grp_lst;
  3634. layout->grp_lst = info;
  3635. }
  3636. }
  3637. /*
  3638. * set the return values.
  3639. */
  3640. *ret_max_x = layout->info.cur_max_x;
  3641. *ret_width = maxWidth;
  3642. if (*ret_width < layout->max_width - curPt.left - curPt.right)
  3643. *ret_width = layout->max_width - curPt.left - curPt.right;
  3644. /*
  3645. * Restore the previous information
  3646. */
  3647. layout->left = saveLeft;
  3648. layout->right = saveRight;
  3649. layout->first = saveFirst;
  3650. layout->stat_flag = saveStatic;
  3651. layout->brdr_flag = saveBrdr;
  3652. layout->info.leading = saveLead;
  3653. /*
  3654. * Besides checking for flow constraints, also (re)sets margins and
  3655. * text information.
  3656. */
  3657. CheckFormat(layout, True);
  3658. layout->txt_justify = saveJustify;
  3659. layout->info.align_char = saveJustifyChar;
  3660. /*
  3661. * for tables and such, return how many lines were drawn around this
  3662. * container.
  3663. */
  3664. if (ret_cnt)
  3665. *ret_cnt = getLn;
  3666. return;
  3667. }
  3668. /******************************************************************************
  3669. * Function: ProcessSegmentList
  3670. *
  3671. * Process the segment list, laying it out according to left, right,
  3672. * and first margins specified. Returns the max_width of the all
  3673. * segments processed and the maximum x coordinate used.
  3674. *****************************************************************************/
  3675. static void
  3676. ProcessSegmentList(
  3677. _DtCanvasStruct *canvas,
  3678. LayoutInfo *layout,
  3679. _DtCvSegmentI *cur_seg,
  3680. _DtCvUnit min_y,
  3681. _DtCvUnit *ret_width,
  3682. _DtCvUnit *ret_max_x,
  3683. int **ret_vert)
  3684. {
  3685. int junk;
  3686. int saveTravCnt = canvas->trav_cnt;
  3687. int saveTxtCnt = canvas->txt_cnt;
  3688. int saveLineCnt = canvas->line_cnt;
  3689. int saveBrkCnt = canvas->brk_cnt;
  3690. _DtCvUnit tempX;
  3691. _DtCvUnit tempLen;
  3692. _DtCvUnit width;
  3693. _DtCvUnit nWidth = 0;
  3694. _DtCvUnit leftMargin = 0;
  3695. _DtCvUnit rightMargin = 0;
  3696. _DtCvUnit topHeight = 0;
  3697. _DtCvUnit botHeight = 0;
  3698. _DtCvUnit maxWidth = 0;
  3699. _DtCvUnit saveYpos = layout->info.y_pos;
  3700. _DtCvSegmentI *segStart = cur_seg;
  3701. LayFrmtInfo *headInfo = NULL;
  3702. LayFrmtInfo *lastHead = NULL;
  3703. LayFrmtInfo *nxtHead;
  3704. _DtCvLayoutInfo startInfo;
  3705. _DtCvValue redo = False;
  3706. _DtCvValue joinCleared = False;
  3707. _DtCvValue flag;
  3708. TopDims topBot;
  3709. SideDims sideDims;
  3710. CornerDims cornerDims;
  3711. FlowDims flowDims;
  3712. DataPoint basePt;
  3713. DataPoint leftPt;
  3714. DataPoint rightPt;
  3715. /*
  3716. * clear the controller arrays
  3717. */
  3718. InitDimArrays(&topBot, &sideDims, &cornerDims, &flowDims);
  3719. /*
  3720. * get the current left and right values or 'base'.
  3721. */
  3722. GetCurrentDataPoint(layout, &basePt);
  3723. /*
  3724. * ???
  3725. */
  3726. leftPt = basePt;
  3727. rightPt = basePt;
  3728. leftPt.y_pos = _CEFORMAT_ALL;
  3729. rightPt.y_pos = _CEFORMAT_ALL;
  3730. /*
  3731. * process all the controller type containers in the segment list
  3732. */
  3733. while (NULL != cur_seg)
  3734. {
  3735. if (_DtCvIsSegContainer(cur_seg) && _DtCvIsSegController(cur_seg))
  3736. {
  3737. /*
  3738. * want to clear this once and only once. Then any join
  3739. * directives will survive, though if two or more controllers
  3740. * have the directive set, the 'last' one will win out.
  3741. */
  3742. if (False == joinCleared)
  3743. {
  3744. _DtCvSetJoinInfo(&(layout->info), False, -1);
  3745. joinCleared = True;
  3746. }
  3747. /*
  3748. * process the 'controller'
  3749. */
  3750. nxtHead = ProcessController(canvas, layout, cur_seg);
  3751. /*
  3752. * update the dimension arrays so that the controller
  3753. * will get placed correctly.
  3754. */
  3755. UpdateDimensionArrays(cur_seg, nxtHead->width, nxtHead->height,
  3756. &topBot, &sideDims, &cornerDims, &flowDims,
  3757. &leftMargin, &rightMargin);
  3758. /*
  3759. * remember this controller.
  3760. */
  3761. if (NULL == headInfo)
  3762. headInfo = nxtHead;
  3763. else
  3764. lastHead->next_info = nxtHead;
  3765. lastHead = nxtHead;
  3766. }
  3767. /*
  3768. * go to the next segment
  3769. */
  3770. cur_seg = cur_seg->next_seg;
  3771. }
  3772. /*
  3773. * Now reset the margins based on the controllers found
  3774. */
  3775. if (NULL != headInfo)
  3776. {
  3777. DetermineMaxDims(&topBot, &cornerDims, leftMargin, rightMargin,
  3778. &topHeight, &botHeight, &maxWidth);
  3779. layout->info.y_pos += topHeight;
  3780. layout->left += leftMargin;
  3781. layout->right += rightMargin;
  3782. DetermineFlowConstraints(layout, flowDims,
  3783. basePt.left, basePt.right,
  3784. layout->info.y_pos, &leftPt, &rightPt);
  3785. /*
  3786. * get rid of the leftMargin and rightMargin values in maxWidth
  3787. * otherwise the use of layout->left & layout->right will double
  3788. * the value.
  3789. */
  3790. maxWidth = maxWidth - leftMargin - rightMargin;
  3791. if (layout->max_width < maxWidth + basePt.left + basePt.right +
  3792. layout->left + layout->right)
  3793. layout->max_width = maxWidth + basePt.left + basePt.right +
  3794. layout->left + layout->right;
  3795. SetMargins(layout);
  3796. SetTextPosition(layout, True);
  3797. if (JoinSet(layout))
  3798. {
  3799. int cnt;
  3800. int joinLine = layout->info.join_line;
  3801. int start = canvas->txt_lst[joinLine].byte_index;
  3802. int count = canvas->txt_lst[joinLine].length;
  3803. _DtCvSegmentI *pSeg = canvas->txt_lst[joinLine].seg_ptr;
  3804. _DtCvUnit tmpWidth;
  3805. /*
  3806. * change the starting location of the following text.
  3807. * take into account the left margin that *hasn't*
  3808. * been added to the controlling container.
  3809. */
  3810. layout->info.text_x_pos = canvas->txt_lst[joinLine].text_x
  3811. + layout->lmargin;
  3812. layout->info.cur_len = 0;
  3813. /*
  3814. * now calculate the width of this line.
  3815. */
  3816. while (pSeg != NULL && count > 0)
  3817. {
  3818. _DtCvGetWidthOfSegment(canvas,pSeg,start,count,
  3819. &cnt, &tmpWidth, NULL);
  3820. layout->info.text_x_pos += tmpWidth;
  3821. count -= cnt;
  3822. start = 0;
  3823. pSeg = pSeg->next_disp;
  3824. }
  3825. }
  3826. }
  3827. /*
  3828. * now format for non-controller containers and non-containers.
  3829. * re-start at the beginning.
  3830. */
  3831. cur_seg = segStart;
  3832. /*
  3833. * Save some information incase we have to redo the layout. I.e.
  3834. * we overflow the sizing.
  3835. */
  3836. startInfo = layout->info;
  3837. saveTravCnt = canvas->trav_cnt;
  3838. saveTxtCnt = canvas->txt_cnt;
  3839. saveLineCnt = canvas->line_cnt;
  3840. saveBrkCnt = canvas->brk_cnt;
  3841. while (NULL != cur_seg)
  3842. {
  3843. width = layout->max_width - layout->info.text_x_pos
  3844. - layout->rmargin - layout->info.cur_len;
  3845. /*
  3846. * check to see if this item should start a line.
  3847. */
  3848. CheckSetLineStart(layout, cur_seg);
  3849. /*
  3850. * check to see if this item will cause a page break.
  3851. */
  3852. CheckForPageBreak(canvas, cur_seg, layout->info.y_pos);
  3853. switch (_DtCvPrimaryTypeOfSeg(cur_seg))
  3854. {
  3855. case _DtCvCONTAINER:
  3856. if (!(_DtCvIsSegController(cur_seg)))
  3857. ProcessContainer(canvas, layout, cur_seg, min_y,
  3858. &junk, &junk, &junk);
  3859. break;
  3860. case _DtCvREGION:
  3861. /*
  3862. * flag that this segment needs a line number
  3863. */
  3864. cur_seg->internal_use = (void *) -1;
  3865. /*
  3866. * process the segment
  3867. */
  3868. if (_DtCvIsSegInLine(cur_seg))
  3869. {
  3870. /*
  3871. * if a hypertext link, this will add it to
  3872. * the internal list.
  3873. */
  3874. CheckAddToHyperList(canvas, cur_seg);
  3875. /*
  3876. * get the traversal width
  3877. */
  3878. nWidth = _DtCvGetTraversalWidth(canvas, cur_seg,
  3879. layout->info.lst_hyper);
  3880. /*
  3881. * check to see if this region can end a line
  3882. */
  3883. flag = _DtCvCheckLineSyntax(canvas,cur_seg,0,0,False);
  3884. /*
  3885. * if this can't end a line, get the length up to
  3886. * the next segment that can and base whether to
  3887. * save pased on that.
  3888. */
  3889. tempLen = 0;
  3890. if (False == flag)
  3891. {
  3892. tempLen = _DtCvGetNextWidth(canvas,
  3893. _DtCvSTRING,
  3894. layout->info.lst_hyper,
  3895. cur_seg->next_seg,
  3896. 0, cur_seg, NULL, NULL, NULL);
  3897. /*
  3898. * if the next width is zero, reset the flag.
  3899. */
  3900. if (tempLen <= 0)
  3901. flag = True;
  3902. }
  3903. tempLen += nWidth;
  3904. /*
  3905. * if not joining, but my length goes over the
  3906. * working width, save out the current buffered
  3907. * information
  3908. */
  3909. if (NotJoining(layout) &&
  3910. _DtCvWidthOfRegionSeg(cur_seg) + tempLen > width)
  3911. CheckSaveInfo (canvas, layout, cur_seg, 0);
  3912. /*
  3913. * up counts on the buffered information.
  3914. */
  3915. layout->info.line_bytes += 1;
  3916. layout->info.cur_len +=
  3917. (_DtCvWidthOfRegionSeg(cur_seg) + nWidth);
  3918. /*
  3919. * does the next segment need to join with
  3920. * this one? If so, set the information
  3921. */
  3922. _DtCvSetJoinInfo(&(layout->info), (flag ? 0 : 1), -1);
  3923. if (_DtCvIsSegNewLine(cur_seg))
  3924. SaveInfo(canvas, layout, cur_seg, 0);
  3925. }
  3926. else
  3927. {
  3928. /*
  3929. * clear out the join information
  3930. * standalone figures can't join with others.
  3931. */
  3932. _DtCvSetJoinInfo(&(layout->info), False, -1);
  3933. /*
  3934. * figures are standalone. Save any
  3935. * information in the buffer away.
  3936. */
  3937. CheckSaveInfo (canvas, layout, cur_seg, 0);
  3938. /*
  3939. * check to see if this segment is
  3940. * a hypertext. If so, add it to the
  3941. * list if it hasn't been added yet.
  3942. */
  3943. CheckAddToHyperList(canvas, cur_seg);
  3944. /*
  3945. * get the traversal width, if any.
  3946. */
  3947. nWidth = _DtCvGetTraversalWidth(canvas, cur_seg,
  3948. layout->info.lst_hyper);
  3949. /*
  3950. * now save the standalone figure
  3951. */
  3952. layout->info.line_bytes += 1;
  3953. layout->info.cur_len +=
  3954. _DtCvWidthOfRegionSeg(cur_seg) + nWidth;
  3955. SaveInfo(canvas, layout, cur_seg->next_seg, 0);
  3956. /*
  3957. * check for wrapping overflow
  3958. */
  3959. CheckFormat(layout, False);
  3960. }
  3961. /*
  3962. * indicate this segment as the last item rendered
  3963. */
  3964. if (NULL != layout->lst_rendered)
  3965. layout->lst_rendered->next_disp = cur_seg;
  3966. layout->lst_rendered = cur_seg;
  3967. break;
  3968. case _DtCvLINE:
  3969. /*
  3970. * lines are standalone. Save any
  3971. * information in the buffer away.
  3972. */
  3973. CheckSaveInfo (canvas, layout, cur_seg, 0);
  3974. /*
  3975. * if the line_width is zero, make it 1 so
  3976. * that it really does take some space.
  3977. */
  3978. nWidth = _DtCvWidthOfLineSeg(cur_seg);
  3979. if (0 == nWidth)
  3980. nWidth = 1;
  3981. /*
  3982. * start with it going all the way across the window.
  3983. */
  3984. width = layout->max_width;
  3985. tempX = 0;
  3986. /*
  3987. * or does it only extend across the container?
  3988. */
  3989. if (_DtCvIsSegBlockLine(cur_seg))
  3990. {
  3991. tempX = layout->lmargin;
  3992. width = layout->max_width - tempX - layout->rmargin;
  3993. }
  3994. SaveLine (canvas, layout, _DtCvLINE_HORZ,
  3995. _DtCvDataOfLineSeg(cur_seg), nWidth, tempX,
  3996. layout->info.y_pos, width);
  3997. layout->info.y_pos += nWidth;
  3998. break;
  3999. case _DtCvMARKER:
  4000. /*
  4001. * check to see if marker is the target id
  4002. */
  4003. CheckId(layout, _DtCvIdOfMarkerSeg(cur_seg));
  4004. break;
  4005. case _DtCvNOOP:
  4006. if (_DtCvIsSegNewLine(cur_seg))
  4007. SaveInfo(canvas, layout, cur_seg, 0);
  4008. break;
  4009. case _DtCvSTRING:
  4010. /*
  4011. * flag that this segment needs a line number
  4012. */
  4013. cur_seg->internal_use = (void *) -1;
  4014. /*
  4015. * process the string
  4016. */
  4017. ProcessStringSegment(canvas, layout, cur_seg);
  4018. /*
  4019. * check for wrapping overflow.
  4020. */
  4021. if (_DtCvIsSegNewLine(cur_seg))
  4022. CheckFormat(layout, False);
  4023. /*
  4024. * indicate this segment as the last item rendered
  4025. */
  4026. if (NULL != layout->lst_rendered)
  4027. layout->lst_rendered->next_disp = cur_seg;
  4028. layout->lst_rendered = cur_seg;
  4029. break;
  4030. case _DtCvTABLE:
  4031. ProcessTable(canvas, layout, cur_seg, min_y);
  4032. default:
  4033. break;
  4034. }
  4035. /*
  4036. * get the next segment
  4037. */
  4038. cur_seg = cur_seg->next_seg;
  4039. /*
  4040. * check the flowing text points
  4041. */
  4042. if (leftPt.y_pos > 0 &&
  4043. leftPt.x_units > layout->max_width - leftPt.left - leftPt.right)
  4044. {
  4045. layout->max_width = leftPt.x_units + leftPt.left + leftPt.right;
  4046. redo = True;
  4047. }
  4048. if (rightPt.y_pos > 0 &&
  4049. rightPt.x_units > layout->max_width-rightPt.left-rightPt.right)
  4050. {
  4051. layout->max_width = rightPt.x_units + rightPt.left + rightPt.right;
  4052. redo = True;
  4053. }
  4054. /*
  4055. * have we violated the available space?
  4056. * if so, we'll have to reformat.
  4057. */
  4058. if (redo == True)
  4059. {
  4060. redo = False;
  4061. cur_seg = segStart;
  4062. canvas->trav_cnt = saveTravCnt;
  4063. canvas->txt_cnt = saveTxtCnt;
  4064. canvas->line_cnt = saveLineCnt;
  4065. canvas->brk_cnt = saveBrkCnt;
  4066. layout->info = startInfo;
  4067. if (rightPt.y_pos > 0)
  4068. {
  4069. RemoveDataPoint(layout, &rightPt); /* make sure its gone */
  4070. InsertDataPoint(layout, &rightPt);
  4071. }
  4072. if (leftPt.y_pos > 0)
  4073. {
  4074. RemoveDataPoint(layout, &leftPt); /* make sure its gone */
  4075. InsertDataPoint(layout, &leftPt);
  4076. }
  4077. /*
  4078. * Now reset the margins based on the controllers found
  4079. */
  4080. if (NULL != headInfo)
  4081. {
  4082. layout->left += leftMargin;
  4083. layout->right += rightMargin;
  4084. SetMargins(layout);
  4085. SetTextPosition(layout, True);
  4086. if (JoinSet(layout))
  4087. {
  4088. int cnt;
  4089. int joinLine = layout->info.join_line;
  4090. int start = canvas->txt_lst[joinLine].byte_index;
  4091. int count = canvas->txt_lst[joinLine].length;
  4092. _DtCvSegmentI *pSeg = canvas->txt_lst[joinLine].seg_ptr;
  4093. _DtCvUnit tmpWidth;
  4094. /*
  4095. * change the starting location of the following text.
  4096. * take into account the left margin that *hasn't*
  4097. * been added to the controlling container.
  4098. */
  4099. layout->info.text_x_pos = canvas->txt_lst[joinLine].text_x
  4100. + layout->lmargin;
  4101. layout->info.cur_len = 0;
  4102. /*
  4103. * now calculate the width of this line.
  4104. */
  4105. while (pSeg != NULL && count > 0)
  4106. {
  4107. _DtCvGetWidthOfSegment(canvas,pSeg,start,count,
  4108. &cnt, &tmpWidth, NULL);
  4109. layout->info.text_x_pos += tmpWidth;
  4110. count -= cnt;
  4111. start = 0;
  4112. pSeg = pSeg->next_disp;
  4113. }
  4114. }
  4115. }
  4116. }
  4117. }
  4118. RemoveDataPoint(layout, &leftPt);
  4119. RemoveDataPoint(layout, &rightPt);
  4120. /*
  4121. * if there were heads, now place them correctly.
  4122. */
  4123. if (NULL != headInfo)
  4124. {
  4125. _DtCvUnit blockHeight;
  4126. _DtCvUnit blockWidth;
  4127. /*
  4128. * make sure all of the information in the body is saved out
  4129. */
  4130. CheckSaveInfo (canvas, layout, NULL, 0);
  4131. /*
  4132. * now calculate the non-controllers overall height.
  4133. */
  4134. blockHeight = layout->info.y_pos - saveYpos - topHeight;
  4135. /*
  4136. * now figure the head positions.
  4137. */
  4138. DetermineHeadPositioning(&topBot, &sideDims, &cornerDims, &flowDims,
  4139. saveYpos, topHeight,
  4140. blockHeight, &blockHeight);
  4141. /*
  4142. * if the maximum available space was exceeded by the text
  4143. * calculate a new max width
  4144. */
  4145. if (layout->max_width < layout->info.cur_max_x + layout->right)
  4146. layout->max_width = layout->info.cur_max_x + layout->right;
  4147. blockWidth = layout->max_width - basePt.left - basePt.right
  4148. - layout->left - layout->right;
  4149. nxtHead = headInfo;
  4150. cur_seg = segStart;
  4151. while (cur_seg != NULL)
  4152. {
  4153. if (_DtCvIsSegContainer(cur_seg) && _DtCvIsSegController(cur_seg))
  4154. {
  4155. AdjustHeadPosition(canvas, layout, cur_seg,
  4156. &topBot, &sideDims, &cornerDims, &flowDims, nxtHead,
  4157. 0, basePt.left + layout->left - leftMargin, blockWidth,
  4158. leftMargin, rightMargin);
  4159. /*
  4160. * go to the next head element
  4161. */
  4162. nxtHead = nxtHead->next_info;
  4163. /*
  4164. * free the information.
  4165. */
  4166. free(headInfo);
  4167. headInfo = nxtHead;
  4168. }
  4169. /*
  4170. * got to the next segment
  4171. */
  4172. cur_seg = cur_seg->next_seg;
  4173. }
  4174. if (layout->info.y_pos < saveYpos + topHeight + blockHeight)
  4175. layout->info.y_pos = saveYpos + topHeight + blockHeight;
  4176. layout->info.y_pos += botHeight;
  4177. }
  4178. /*
  4179. * set the return values
  4180. */
  4181. *ret_width = layout->info.cur_max_x - basePt.left + layout->right;
  4182. *ret_max_x = layout->info.cur_max_x;
  4183. return;
  4184. }
  4185. /*****************************************************************************
  4186. * Function: static _DtCvUnit MaxOfGroup (
  4187. *
  4188. * Purpose: Determine the maximum of a group.
  4189. *****************************************************************************/
  4190. static void
  4191. MaxOfGroup (
  4192. GrpInfo *group,
  4193. _DtCvDspLine *text,
  4194. _DtCvLineSeg *lines,
  4195. _DtCvUnit max_x,
  4196. _DtCvUnit max_y)
  4197. {
  4198. int i;
  4199. /*
  4200. * initialize
  4201. */
  4202. group->min_x = max_x;
  4203. group->max_x = 0;
  4204. group->top_y = max_y;
  4205. group->bot_y = 0;
  4206. /*
  4207. * find the maximum of the group
  4208. */
  4209. for (i = group->cnt.beg_txt; i < group->cnt.end_txt; i++)
  4210. {
  4211. /*
  4212. * check for min's and max's
  4213. */
  4214. if (group->min_x > text[i].text_x)
  4215. group->min_x = text[i].text_x;
  4216. if (group->max_x < text[i].max_x)
  4217. group->max_x = text[i].max_x;
  4218. if (group->top_y > text[i].baseline - text[i].ascent)
  4219. group->top_y = text[i].baseline - text[i].ascent;
  4220. if (group->bot_y < text[i].baseline + text[i].descent)
  4221. group->bot_y = text[i].baseline + text[i].descent;
  4222. /*
  4223. * indicate that this line has been processed already
  4224. */
  4225. _DtCvSetProcessed(text[i]);
  4226. }
  4227. for (i = group->cnt.beg_ln; i < group->cnt.end_ln; i++)
  4228. {
  4229. /*
  4230. * check for min's and max's
  4231. */
  4232. if (group->min_x > lines[i].pos_x)
  4233. group->min_x = lines[i].pos_x;
  4234. if (group->max_x < lines[i].max_x)
  4235. group->max_x = lines[i].max_x;
  4236. if (group->top_y > lines[i].pos_y)
  4237. group->top_y = lines[i].pos_y;
  4238. if (group->bot_y < lines[i].max_y)
  4239. group->bot_y = lines[i].max_y;
  4240. /*
  4241. * indicate that this line has been processed already
  4242. */
  4243. _DtCvSetProcessed(lines[i]);
  4244. }
  4245. }
  4246. /*****************************************************************************
  4247. * Function: static _DtCvUnit TestSpacing (
  4248. *
  4249. * Parameters:
  4250. *
  4251. * Returns: True if the object is before (x wise) the test object.
  4252. * False if the object is not before (x wise) the text object.
  4253. *
  4254. * Purpose:
  4255. *
  4256. *****************************************************************************/
  4257. static _DtCvStatus
  4258. TestSpacing (
  4259. _DtCvUnit tst_top,
  4260. _DtCvUnit tst_bot,
  4261. _DtCvUnit tst_min,
  4262. _DtCvUnit obj_top,
  4263. _DtCvUnit obj_bot,
  4264. _DtCvUnit obj_max,
  4265. _DtCvUnit needed,
  4266. _DtCvUnit min_space,
  4267. _DtCvUnit *ret_amount)
  4268. {
  4269. _DtCvStatus result = False;
  4270. /*
  4271. * check to see if the object is to the left of the test object
  4272. * to move and that it 'infringes' on the vertical
  4273. * space of the test object.
  4274. *
  4275. * I.e. ----obj_top------
  4276. * | | ----tst_top----
  4277. * ----obj_bot------ | |
  4278. * ----tst_bot----
  4279. *
  4280. * I.e. ----tst_top----
  4281. * ----obj_top------- | |
  4282. * | | ----tst_bot----
  4283. * ----obj_bot-------
  4284. *
  4285. * I.e. ----obj_top------
  4286. * | | ----tst_top----
  4287. * | | | |
  4288. * | | ----tst_bot----
  4289. * ----obj_bot------
  4290. *
  4291. * I.e. ----tst_top----
  4292. * ----obj_top------- | |
  4293. * | | | |
  4294. * ----obj_bot------- | |
  4295. * ----tst_bot----
  4296. */
  4297. if (obj_max < tst_min
  4298. && True == _DtCvCheckInfringement(tst_top, tst_bot, obj_top, obj_bot)
  4299. && needed > tst_min - obj_max)
  4300. {
  4301. /*
  4302. * okay, this infringes on the object's space.
  4303. * truncate the amount of room there is to move the object
  4304. */
  4305. result = True;
  4306. needed = tst_min - obj_max;
  4307. /*
  4308. * is the space between these two objects already squeezed
  4309. * below the minimum allowed?
  4310. */
  4311. if (needed < min_space)
  4312. needed = 0;
  4313. else /* leave the minimum space between the objects */
  4314. needed -= min_space;
  4315. }
  4316. *ret_amount = needed;
  4317. return result;
  4318. }
  4319. /*****************************************************************************
  4320. * Function: static void MoveLeft (
  4321. *
  4322. * Parameters:
  4323. *
  4324. * Returns:
  4325. *
  4326. * Purpose: Moves the object's rules/lines and text lines to the left.
  4327. *
  4328. *****************************************************************************/
  4329. static void
  4330. MoveLeft (
  4331. _DtCanvasStruct *canvas,
  4332. int beg_txt,
  4333. int end_txt,
  4334. int beg_ln,
  4335. int end_ln,
  4336. _DtCvUnit space)
  4337. {
  4338. int i;
  4339. /*
  4340. * bail now if nothing to do.
  4341. */
  4342. if (1 > space)
  4343. return;
  4344. /*
  4345. * move each text/region line.
  4346. */
  4347. for (i = beg_txt; i < end_txt; i++)
  4348. {
  4349. canvas->txt_lst[i].text_x -= space;
  4350. canvas->txt_lst[i].max_x -= space;
  4351. }
  4352. /*
  4353. * move each line/rule.
  4354. */
  4355. for (i = beg_ln; i < end_ln; i++)
  4356. {
  4357. canvas->line_lst[i].pos_x -= space;
  4358. canvas->line_lst[i].max_x -= space;
  4359. }
  4360. }
  4361. /*****************************************************************************
  4362. * Function: static _DtCvUnit CheckSpacing (
  4363. *
  4364. * Purpose: Check the spacing before an object and move any objects
  4365. * before it to the left to make room.
  4366. *
  4367. *****************************************************************************/
  4368. static _DtCvUnit
  4369. CheckSpacing (
  4370. _DtCanvasStruct *canvas,
  4371. LayoutInfo *layout,
  4372. GrpInfo *tst_grp,
  4373. int txt_idx,
  4374. int line_idx,
  4375. _DtCvUnit top_y,
  4376. _DtCvUnit bot_y,
  4377. _DtCvUnit min_x,
  4378. _DtCvUnit needed)
  4379. {
  4380. int i;
  4381. _DtCvUnit space;
  4382. _DtCvUnit maxSpace;
  4383. _DtCvUnit topY;
  4384. _DtCvUnit botY;
  4385. GrpInfo *nxtGrp = layout->grp_lst;
  4386. /*
  4387. * truncate if the amount needed is more than available.
  4388. */
  4389. if (min_x < needed)
  4390. needed = min_x;
  4391. maxSpace = needed;
  4392. /*
  4393. * see what group is before this group and how much space there is
  4394. */
  4395. while (NULL != nxtGrp)
  4396. {
  4397. /*
  4398. * as long as I'm not comparing against myself, try it.
  4399. */
  4400. if (nxtGrp != tst_grp)
  4401. {
  4402. /*
  4403. * is this group before(x wise) the test group, infringing
  4404. * upon the test group's top and bottom positioning (y)
  4405. * and is the amount of space (x wise) between them smaller
  4406. * than the current smallest space found?
  4407. */
  4408. if (True == TestSpacing (top_y, bot_y, min_x,
  4409. nxtGrp->top_y, nxtGrp->bot_y,
  4410. nxtGrp->max_x, needed,
  4411. canvas->metrics.horiz_pad_hint,
  4412. &space))
  4413. {
  4414. space += MoveGroup(canvas, layout, nxtGrp, needed - space);
  4415. if (maxSpace > space)
  4416. maxSpace = space;
  4417. }
  4418. }
  4419. /*
  4420. * check the next group
  4421. */
  4422. nxtGrp = nxtGrp->next_info;
  4423. }
  4424. /*
  4425. * look at each of the text lines;
  4426. */
  4427. for (i = 0; i < canvas->txt_cnt; i++)
  4428. {
  4429. /*
  4430. * Only look at those lines not already processed.
  4431. */
  4432. if (i != txt_idx && _DtCvIsNotProcessed(canvas->txt_lst[i]))
  4433. {
  4434. topY = canvas->txt_lst[i].baseline - canvas->txt_lst[i].ascent;
  4435. botY = canvas->txt_lst[i].baseline - canvas->txt_lst[i].descent;
  4436. if (True == TestSpacing(top_y, bot_y, min_x, topY, botY,
  4437. canvas->txt_lst[i].max_x, needed,
  4438. canvas->metrics.horiz_pad_hint, &space))
  4439. {
  4440. space += MoveText(canvas, layout, i, topY, botY, needed-space);
  4441. if (maxSpace > space)
  4442. maxSpace = space;
  4443. }
  4444. }
  4445. }
  4446. /*
  4447. * look at each of the rules/lines;
  4448. */
  4449. for (i = 0; i < canvas->line_cnt; i++)
  4450. {
  4451. /*
  4452. * Only look at those lines not already processed.
  4453. */
  4454. if (i != line_idx && _DtCvIsNotProcessed(canvas->line_lst[i]))
  4455. {
  4456. /*
  4457. * calculate the top and bottom of the line
  4458. */
  4459. topY = canvas->line_lst[i].pos_y;
  4460. botY = canvas->line_lst[i].max_y;
  4461. if (True == TestSpacing(top_y, bot_y, min_x, topY, botY,
  4462. canvas->line_lst[i].max_x, needed,
  4463. canvas->metrics.horiz_pad_hint, &space))
  4464. {
  4465. space += MoveLines(canvas, layout, i, topY, botY, needed-space);
  4466. if (maxSpace > space)
  4467. maxSpace = space;
  4468. }
  4469. }
  4470. }
  4471. return maxSpace;
  4472. }
  4473. /*****************************************************************************
  4474. * Function: static _DtCvUnit MoveGroup (_DtCanvasStruct canvas);
  4475. *
  4476. * Purpose: To move groupings (container, tables, etc.) as a group to
  4477. * honor boundaries.
  4478. *
  4479. *****************************************************************************/
  4480. static _DtCvUnit
  4481. MoveGroup (
  4482. _DtCanvasStruct *canvas,
  4483. LayoutInfo *layout,
  4484. GrpInfo *tst_grp,
  4485. _DtCvUnit needed)
  4486. {
  4487. _DtCvUnit space;
  4488. /*
  4489. * find out what's in front of it. And how much 'extra' room
  4490. * there is.
  4491. */
  4492. space = CheckSpacing(canvas, layout, tst_grp, -1, -1,
  4493. tst_grp->top_y, tst_grp->bot_y, tst_grp->min_x,
  4494. needed);
  4495. /*
  4496. * now move the group
  4497. */
  4498. MoveLeft(canvas, tst_grp->cnt.beg_txt, tst_grp->cnt.end_txt,
  4499. tst_grp->cnt.beg_ln, tst_grp->cnt.end_ln, space);
  4500. tst_grp->max_x -= space;
  4501. tst_grp->min_x -= space;
  4502. return space;
  4503. }
  4504. /*****************************************************************************
  4505. * Function: static _DtCvUnit MoveText (_DtCanvasStruct canvas);
  4506. *
  4507. * Purpose: To move text lines to honor boundaries.
  4508. *
  4509. *****************************************************************************/
  4510. static _DtCvUnit
  4511. MoveText (
  4512. _DtCanvasStruct *canvas,
  4513. LayoutInfo *layout,
  4514. int idx,
  4515. _DtCvUnit top_y,
  4516. _DtCvUnit bot_y,
  4517. _DtCvUnit needed)
  4518. {
  4519. _DtCvUnit space;
  4520. /*
  4521. * find out what's in front of it. And how much 'extra' room
  4522. * there is.
  4523. */
  4524. space = CheckSpacing(canvas, layout, NULL, idx, -1,
  4525. top_y, bot_y,
  4526. canvas->txt_lst[idx].text_x,
  4527. needed);
  4528. /*
  4529. * now move the group
  4530. */
  4531. MoveLeft(canvas, idx, idx, -1, -1, space);
  4532. return space;
  4533. }
  4534. /*****************************************************************************
  4535. * Function: static _DtCvUnit MoveLines (_DtCanvasStruct canvas);
  4536. *
  4537. * Purpose: To move groupings (container, tables, etc.) as a group to
  4538. * honor boundaries.
  4539. *
  4540. *****************************************************************************/
  4541. static _DtCvUnit
  4542. MoveLines (
  4543. _DtCanvasStruct *canvas,
  4544. LayoutInfo *layout,
  4545. int idx,
  4546. _DtCvUnit top_y,
  4547. _DtCvUnit bot_y,
  4548. _DtCvUnit needed)
  4549. {
  4550. _DtCvUnit space;
  4551. /*
  4552. * find out what's in front of it. And how much 'extra' room
  4553. * there is.
  4554. */
  4555. space = CheckSpacing(canvas, layout, NULL, -1, idx,
  4556. top_y, bot_y,
  4557. canvas->line_lst[idx].pos_x,
  4558. needed);
  4559. /*
  4560. * now move the group
  4561. */
  4562. MoveLeft(canvas, -1, -1, idx, idx, space);
  4563. return space;
  4564. }
  4565. /*****************************************************************************
  4566. * Function: static void CheckMoveInfo (_DtCanvasStruct canvas);
  4567. *
  4568. * Purpose: To move each of the groupings, rules and text lines to
  4569. * honor boundaries.
  4570. *
  4571. *****************************************************************************/
  4572. static void
  4573. CheckMoveInfo (
  4574. _DtCanvasStruct *canvas,
  4575. LayoutInfo *layout)
  4576. {
  4577. int i;
  4578. _DtCvUnit topY;
  4579. _DtCvUnit botY;
  4580. _DtCvUnit maxWidth = canvas->metrics.width;
  4581. GrpInfo *nxtGrp;
  4582. /*
  4583. * fill in the max x of each group
  4584. */
  4585. for (nxtGrp = layout->grp_lst; NULL != nxtGrp; nxtGrp = nxtGrp->next_info)
  4586. {
  4587. /*
  4588. * find the maximum of the group
  4589. */
  4590. MaxOfGroup(nxtGrp, canvas->txt_lst, canvas->line_lst,
  4591. layout->info.max_x_pos, layout->info.y_pos);
  4592. }
  4593. /*
  4594. * now check each group for exceeding the boundary.
  4595. */
  4596. for (nxtGrp = layout->grp_lst; NULL != nxtGrp; nxtGrp = nxtGrp->next_info)
  4597. {
  4598. /*
  4599. * does this group exceed the boundary?
  4600. */
  4601. if (maxWidth < nxtGrp->max_x)
  4602. (void) MoveGroup(canvas, layout, nxtGrp, nxtGrp->max_x - maxWidth);
  4603. }
  4604. /*
  4605. * look at each of the text lines;
  4606. */
  4607. for (i = 0; i < canvas->txt_cnt; i++)
  4608. {
  4609. /*
  4610. * Only look at those lines not already processed.
  4611. */
  4612. if (_DtCvIsNotProcessed(canvas->txt_lst[i]) &&
  4613. maxWidth < canvas->txt_lst[i].max_x)
  4614. {
  4615. topY = canvas->txt_lst[i].baseline - canvas->txt_lst[i].ascent;
  4616. botY = canvas->txt_lst[i].baseline - canvas->txt_lst[i].descent;
  4617. (void) MoveText(canvas, layout, i, topY, botY,
  4618. canvas->txt_lst[i].max_x - maxWidth);
  4619. }
  4620. }
  4621. /*
  4622. * look at each of the rules/lines;
  4623. */
  4624. for (i = 0; i < canvas->line_cnt; i++)
  4625. {
  4626. /*
  4627. * Only look at those lines not already processed.
  4628. */
  4629. if (_DtCvIsNotProcessed(canvas->line_lst[i]) &&
  4630. maxWidth < canvas->line_lst[i].max_x)
  4631. {
  4632. /*
  4633. * calculate the top and bottom of the line
  4634. */
  4635. topY = canvas->line_lst[i].pos_y;
  4636. botY = canvas->line_lst[i].max_y;
  4637. (void) MoveLines(canvas, layout, i, topY, botY,
  4638. canvas->line_lst[i].max_x - maxWidth);
  4639. }
  4640. }
  4641. }
  4642. /*****************************************************************************
  4643. * Function: static void CompareUnits ()
  4644. *
  4645. * Parameters:
  4646. *
  4647. * Returns:
  4648. *
  4649. * Purpose:
  4650. *
  4651. *****************************************************************************/
  4652. static int
  4653. CompareUnits (
  4654. const void *a,
  4655. const void *b)
  4656. {
  4657. _DtCvUnit *aPtr = (_DtCvUnit *) a;
  4658. _DtCvUnit *bPtr = (_DtCvUnit *) b;
  4659. if (*aPtr < *bPtr) return -1;
  4660. if (*aPtr == *bPtr) return 0;
  4661. return 1;
  4662. }
  4663. /*****************************************************************************
  4664. * Function: static void CompareSearchs ()
  4665. *
  4666. * Parameters:
  4667. *
  4668. * Returns:
  4669. *
  4670. * Purpose:
  4671. *
  4672. *****************************************************************************/
  4673. static int
  4674. CompareSearchs (
  4675. const void *a,
  4676. const void *b)
  4677. {
  4678. _DtCvSearchData *searchA = (_DtCvSearchData *) a;
  4679. _DtCvSearchData *searchB = (_DtCvSearchData *) b;
  4680. _DtCvDspLine *lineA = &(searchA->lst[searchA->idx]);
  4681. _DtCvDspLine *lineB = &(searchB->lst[searchB->idx]);
  4682. _DtCvUnit topA = lineA->baseline - lineA->ascent;
  4683. _DtCvUnit topB = lineB->baseline - lineB->ascent;
  4684. _DtCvUnit heightA = lineA->ascent + lineA->descent;
  4685. _DtCvUnit heightB = lineB->ascent + lineB->descent;
  4686. _DtCvUnit centA = topA + (heightA >> 1);
  4687. _DtCvUnit centB = topB + (heightB >> 1);
  4688. if (lineA->baseline + lineA->descent < centB && centA < topB)
  4689. return -1;
  4690. if (lineB->baseline + lineB->descent < centA && centB < topA)
  4691. return 1;
  4692. if (lineA->text_x != lineB->text_x)
  4693. return ((lineA->text_x < lineB->text_x) ? -1 : 1);
  4694. if (topA != topB)
  4695. return ((topA < topB) ? -1 : 1);
  4696. if (heightA != heightB)
  4697. return ((heightA < heightB) ? -1 : 1);
  4698. if (lineA->max_x != lineB->max_x)
  4699. return ((lineA->max_x < lineB->max_x) ? -1 : 1);
  4700. return 0;
  4701. }
  4702. /*****************************************************************************
  4703. * Function: static Status LayoutCanvasInfo (_DtCvHandle canvas);
  4704. *
  4705. * Parameters:
  4706. *
  4707. * Returns:
  4708. *
  4709. * Purpose:
  4710. *
  4711. *****************************************************************************/
  4712. static _DtCvStatus
  4713. LayoutCanvasInfo (
  4714. _DtCanvasStruct *canvas,
  4715. LayoutInfo *layout,
  4716. _DtCvUnit divisor,
  4717. char *target_id)
  4718. {
  4719. int i = 0;
  4720. DataPoint basePt;
  4721. _DtCvUnit maxWidth = 0;
  4722. _DtCvUnit maxXPos = 0;
  4723. _DtCvStatus result = _DtCvSTATUS_OK;
  4724. *layout = DefInfo;
  4725. layout->divisor = divisor;
  4726. layout->max_width = canvas->metrics.width;
  4727. layout->left = canvas->metrics.side_margin;
  4728. layout->right = canvas->metrics.side_margin;
  4729. layout->target_id = target_id;
  4730. _DtCvInitLayoutInfo(canvas, &(layout->info));
  4731. basePt = DefDataPt;
  4732. PushDataPoint(layout, &basePt);
  4733. SetMargins (layout);
  4734. SetTextPosition (layout, True);
  4735. ProcessSegmentList(canvas, layout, canvas->element_lst, -1,
  4736. &maxWidth, &maxXPos, NULL);
  4737. RemoveDataPoint(layout, &basePt);
  4738. /*
  4739. * fill in the max_x of each line of text/regions.
  4740. */
  4741. for (i = 0; i < canvas->txt_cnt; i++)
  4742. canvas->txt_lst[i].max_x = MaxXOfLine(canvas, &(canvas->txt_lst[i]));
  4743. /*
  4744. * calculate the actual right hand side boundary.
  4745. */
  4746. layout->info.max_x_pos += canvas->metrics.side_margin;
  4747. /*
  4748. * the max_x_pos so far has indicated where the *next* character,
  4749. * line or region will be *started*. Therefore back up one to
  4750. * indicate the true last position used.
  4751. */
  4752. layout->info.max_x_pos--;
  4753. return result;
  4754. } /* End LayoutCanvasInfo */
  4755. /*****************************************************************************
  4756. * Function: static Status LayoutCanvas (_DtCvHandle canvas);
  4757. *
  4758. * Parameters:
  4759. *
  4760. * Returns:
  4761. *
  4762. * Purpose:
  4763. *
  4764. *****************************************************************************/
  4765. static _DtCvStatus
  4766. LayoutCanvas (
  4767. _DtCanvasStruct *canvas,
  4768. LayoutInfo *layout,
  4769. char *target_id)
  4770. {
  4771. _DtCvUnit divisor = 1;
  4772. _DtCvValue redo;
  4773. _DtCvStatus result;
  4774. int i, search_cnt = canvas->search_cnt;
  4775. do {
  4776. redo = False;
  4777. result = LayoutCanvasInfo(canvas, layout, divisor, target_id);
  4778. /*
  4779. * Are we suppose to honor the boundary?
  4780. * If so, do any lines go over the boundary?
  4781. * Is there any margins that can be decremented?
  4782. */
  4783. if (_DtCvSTATUS_OK == result
  4784. && (_DtCvUSE_BOUNDARY == canvas->constraint ||
  4785. _DtCvUSE_BOUNDARY_MOVE == canvas->constraint)
  4786. && layout->info.max_x_pos >= canvas->metrics.width)
  4787. {
  4788. if (_DtCvUSE_BOUNDARY_MOVE == canvas->constraint)
  4789. {
  4790. int i;
  4791. /*
  4792. * clear the processed flag from all the text/region lines.
  4793. */
  4794. for (i = 0; i < canvas->txt_cnt; i++)
  4795. _DtCvClearProcessed(canvas->txt_lst[i]);
  4796. /*
  4797. * clear the processed flag from all the line/rules.
  4798. */
  4799. for (i = 0; i < canvas->line_cnt; i++)
  4800. _DtCvClearProcessed(canvas->line_lst[i]);
  4801. CheckMoveInfo(canvas, layout);
  4802. /*
  4803. * recalculate the new max x
  4804. */
  4805. layout->info.max_x_pos = 0;
  4806. for (i = 0; i < canvas->txt_cnt; i++)
  4807. if (layout->info.max_x_pos < canvas->txt_lst[i].max_x)
  4808. layout->info.max_x_pos = canvas->txt_lst[i].max_x;
  4809. for (i = 0; i < canvas->line_cnt; i++)
  4810. if (layout->info.max_x_pos < canvas->line_lst[i].max_x)
  4811. layout->info.max_x_pos = canvas->line_lst[i].max_x;
  4812. layout->info.max_x_pos--;
  4813. }
  4814. else if (True == layout->margin_non_zero)
  4815. {
  4816. redo = True;
  4817. divisor *= 2;
  4818. canvas->txt_cnt = 0;
  4819. canvas->line_cnt = 0;
  4820. canvas->trav_cnt = 0;
  4821. }
  4822. }
  4823. } while (True == redo);
  4824. /*
  4825. * clean up table information
  4826. */
  4827. if (NULL != layout->grp_lst)
  4828. free(layout->grp_lst);
  4829. /*
  4830. * subtract one from the y position to indicate the *last*
  4831. * pixel/column/etc that will be rendered.
  4832. */
  4833. canvas->max_y = layout->info.y_pos - 1;
  4834. canvas->max_x = layout->info.max_x_pos;
  4835. for (i = search_cnt; i < canvas->search_cnt; i++)
  4836. {
  4837. canvas->searchs[i - search_cnt] = canvas->searchs[i];
  4838. canvas->searchs[i - search_cnt].lst = canvas->txt_lst;
  4839. }
  4840. canvas->search_cnt -= search_cnt;
  4841. /*
  4842. * are there any search hits?
  4843. */
  4844. if (0 != canvas->search_cnt)
  4845. qsort (canvas->searchs, canvas->search_cnt, sizeof(_DtCvSearchData),
  4846. CompareSearchs);
  4847. /*
  4848. * sort the page break list.
  4849. */
  4850. if (0 != canvas->brk_cnt)
  4851. qsort (canvas->pg_breaks, canvas->brk_cnt, sizeof(_DtCvUnit),
  4852. CompareUnits);
  4853. return result;
  4854. } /* End LayoutCanvas */
  4855. /*****************************************************************************
  4856. * Function: static void SortTraversal (_DtCvHandle canvas);
  4857. *
  4858. * Parameters:
  4859. *
  4860. * Returns:
  4861. *
  4862. * Purpose:
  4863. *
  4864. *****************************************************************************/
  4865. static void
  4866. SortTraversal (_DtCanvasStruct *canvas)
  4867. {
  4868. int i;
  4869. /*
  4870. * sort the links correctly. First, establish the x,y,width,height
  4871. * of each link.
  4872. */
  4873. for (i = 0; i < canvas->trav_cnt; i++)
  4874. {
  4875. if (_DtCvTraversalLink == canvas->trav_lst[i].type)
  4876. GetLinkInfo(canvas, i, &(canvas->trav_lst[i].x_pos),
  4877. &(canvas->trav_lst[i].y_pos),
  4878. &(canvas->trav_lst[i].width),
  4879. &(canvas->trav_lst[i].height));
  4880. else
  4881. _DtCvCalcMarkPos(canvas, canvas->trav_lst[i].idx,
  4882. &(canvas->trav_lst[i].x_pos),
  4883. &(canvas->trav_lst[i].y_pos),
  4884. &(canvas->trav_lst[i].width),
  4885. &(canvas->trav_lst[i].height));
  4886. }
  4887. _DtCvSortTraversalList(canvas, _DtCvFALSE);
  4888. }
  4889. /*****************************************************************************
  4890. * Function: static void ProcessMarks (_DtCanvasStruct *canvas);
  4891. *
  4892. * Parameters:
  4893. *
  4894. * Returns:
  4895. *
  4896. * Purpose:
  4897. *
  4898. *****************************************************************************/
  4899. static _DtCvStatus
  4900. ProcessMarks (
  4901. _DtCanvasStruct *canvas,
  4902. _DtCvPointInfo **mark_lst)
  4903. {
  4904. int markIdx;
  4905. int result = _DtCvSTATUS_OK;
  4906. _DtCvSelectData beg;
  4907. _DtCvSelectData end;
  4908. _DtCvSegmentI *firstSeg;
  4909. while (NULL != mark_lst && NULL != *mark_lst)
  4910. {
  4911. /*
  4912. * convert the segments to begin and end points
  4913. */
  4914. if (_DtCvSTATUS_BAD == _DtCvCvtSegsToPts(canvas, (*mark_lst)->segs,
  4915. &beg, &end, NULL, NULL, &firstSeg))
  4916. /*
  4917. * just set a return value since this indicates bad data
  4918. * and not system failure.
  4919. */
  4920. result = _DtCvSTATUS_BAD;
  4921. /*
  4922. * now add it to the mark list
  4923. */
  4924. else
  4925. {
  4926. markIdx = _DtCvAddToMarkList(canvas, (*mark_lst)->client_data,
  4927. _DtCvFALSE, &beg, &end);
  4928. /*
  4929. * now put the mark in the traversal list, but don't sort
  4930. * or fill out position and dimension information.
  4931. * SortTraversal() will do that.
  4932. *
  4933. * bail here if system failure indicated.
  4934. */
  4935. if (-1 == markIdx || 0 != _DtCvSetTravEntryInfo(canvas,
  4936. _DtCvGetNextTravEntry(canvas),
  4937. _DtCvTraversalMark, firstSeg,
  4938. markIdx, _DtCvTRUE))
  4939. return _DtCvSTATUS_BAD;
  4940. }
  4941. mark_lst++;
  4942. }
  4943. return result;
  4944. }
  4945. /*****************************************************************************
  4946. * Public Functions
  4947. *****************************************************************************/
  4948. /*****************************************************************************
  4949. * Function: void _DtCanvasResize (_DtCvHandle canvas);
  4950. *
  4951. * Parameters:
  4952. *
  4953. * Returns:
  4954. *
  4955. * Purpose:
  4956. *
  4957. *****************************************************************************/
  4958. _DtCvStatus
  4959. _DtCanvasResize (
  4960. _DtCvHandle canvas_handle,
  4961. _DtCvValue force,
  4962. _DtCvUnit *ret_width,
  4963. _DtCvUnit *ret_height )
  4964. {
  4965. int i;
  4966. _DtCvStatus selectStatus;
  4967. _DtCvStatus retStatus = _DtCvSTATUS_NONE;
  4968. _DtCanvasStruct *canvas = (_DtCanvasStruct *) canvas_handle;
  4969. _DtCvUnit oldWidth = canvas->metrics.width;
  4970. LayoutInfo layOut;
  4971. _DtCvPointInfo selPt;
  4972. _DtCvPointInfo **markInfo;
  4973. selPt.client_data = NULL;
  4974. selPt.segs = NULL;
  4975. /*
  4976. * check to see if the width has changed - if not,
  4977. * don't do anything (but re-initialize the metrics
  4978. * to get the new height).
  4979. */
  4980. (*(canvas->virt_functions.get_metrics))(canvas->client_data,
  4981. _DtCvCANVAS_TYPE, &(canvas->metrics));
  4982. if (canvas->metrics.width != oldWidth || _DtCvTRUE == force)
  4983. {
  4984. /*
  4985. * remember the current selection.
  4986. */
  4987. selectStatus = _DtCanvasGetSelectionPoints(canvas, &(selPt.segs),
  4988. NULL, NULL);
  4989. /*
  4990. * remember the marks
  4991. */
  4992. if (_DtCvSTATUS_BAD == _DtCvGetMarkSegs(canvas, &markInfo))
  4993. return _DtCvSTATUS_BAD;
  4994. /*
  4995. * Re-Layout the information.
  4996. * First step - invalidate some counters.
  4997. */
  4998. canvas->trav_cnt = 0; /* zero this only because we re-process */
  4999. /* do not zero cur_hyper or we'll loose */
  5000. /* where we are in the TOC */
  5001. canvas->txt_cnt = 0;
  5002. canvas->line_cnt = 0;
  5003. canvas->mark_cnt = 0;
  5004. canvas->brk_cnt = 0;
  5005. /*
  5006. * Layout the information if there is anything to do
  5007. */
  5008. if (_DtCvSTATUS_BAD == LayoutCanvas (canvas, &layOut, NULL))
  5009. return _DtCvSTATUS_BAD;
  5010. /*
  5011. * restore the current selection.
  5012. */
  5013. if (_DtCvSTATUS_OK == selectStatus)
  5014. {
  5015. _DtCanvasActivatePts(canvas,_DtCvACTIVATE_SELECTION, &selPt,
  5016. NULL,NULL);
  5017. _DtCvFreeArray((void **) selPt.segs);
  5018. }
  5019. /*
  5020. * now place the marks in the mark and traversal lists
  5021. */
  5022. ProcessMarks(canvas, markInfo);
  5023. if (NULL != markInfo)
  5024. {
  5025. for (i = 0; NULL != markInfo[i]; i++)
  5026. _DtCvFreeArray((void **) (markInfo[i]->segs));
  5027. _DtCvFreeArray((void **) markInfo);
  5028. }
  5029. /*
  5030. * sort the traversal list.
  5031. */
  5032. SortTraversal(canvas);
  5033. retStatus = _DtCvSTATUS_OK;
  5034. }
  5035. /*
  5036. * return the maximum height and width used
  5037. */
  5038. if (ret_width != NULL)
  5039. *ret_width = canvas->max_x;
  5040. if (ret_height != NULL)
  5041. *ret_height = canvas->max_y;
  5042. return retStatus;
  5043. } /* End _DtCanvasResize */
  5044. /*****************************************************************************
  5045. * Function: void _DtCanvasSetTopic (_DtCvHandle canvas);
  5046. *
  5047. * Parameters:
  5048. *
  5049. * Returns:
  5050. *
  5051. * Purpose:
  5052. *
  5053. *****************************************************************************/
  5054. _DtCvStatus
  5055. _DtCanvasSetTopic (
  5056. _DtCvHandle canvas_handle,
  5057. _DtCvTopicPtr topic,
  5058. _DtCvValue honor_size,
  5059. _DtCvUnit *ret_width,
  5060. _DtCvUnit *ret_height,
  5061. _DtCvUnit *ret_y )
  5062. {
  5063. _DtCvStatus result = _DtCvSTATUS_OK;
  5064. _DtCanvasStruct *canvas = (_DtCanvasStruct *) canvas_handle;
  5065. LayoutInfo layOut;
  5066. /*
  5067. * clean the canvas
  5068. */
  5069. _DtCanvasClean (canvas_handle);
  5070. /*
  5071. * attach to the canvas
  5072. */
  5073. canvas->element_lst = topic->seg_list;
  5074. /*
  5075. * Attach the link information
  5076. */
  5077. canvas->link_data = topic->link_data;
  5078. /*
  5079. * init the internal use pointer in all containers to NULL
  5080. */
  5081. _DtCvClearInternalUse(canvas->element_lst, _DtCvFALSE);
  5082. /*
  5083. * Layout the information if there is anything to do
  5084. */
  5085. canvas->constraint = honor_size;
  5086. if (_DtCvSTATUS_BAD == LayoutCanvas (canvas, &layOut, topic->id_str))
  5087. return _DtCvSTATUS_BAD;
  5088. /*
  5089. * add the marks to the mark and traversal lists
  5090. */
  5091. ProcessMarks(canvas, topic->mark_list);
  5092. /*
  5093. * sort the traversal list.
  5094. */
  5095. SortTraversal(canvas);
  5096. /*
  5097. * return the maximum height and width used
  5098. * And the location of the id.
  5099. */
  5100. if (ret_width != NULL)
  5101. *ret_width = canvas->max_x;
  5102. if (ret_height != NULL)
  5103. *ret_height = canvas->max_y;
  5104. if (ret_y != NULL)
  5105. {
  5106. if (NULL != layOut.target_id && True != layOut.id_found)
  5107. result = _DtCvSTATUS_ID_BAD;
  5108. *ret_y = layOut.id_Ypos;
  5109. }
  5110. return result;
  5111. } /* End _DtCanvasSetTopic */