Develop.htm 145 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Information for Ghostscript developers</title>
  5. <link rel="stylesheet" type="text/css" href="gs.css" title="Ghostscript Style">
  6. <!-- $Id: Develop.htm,v 1.47.2.3 2002/02/01 05:31:24 raph Exp $ -->
  7. </head>
  8. <body>
  9. <!-- [1.0 begin visible header] ============================================ -->
  10. <!-- [1.1 begin headline] ================================================== -->
  11. <h1>Information for Ghostscript developers</h1>
  12. <!-- [1.1 end headline] ==================================================== -->
  13. <!-- [1.2 begin table of contents] ========================================= -->
  14. <h2>Table of contents</h2>
  15. <blockquote><ul>
  16. <li><a href="#Introduction">Introduction</a>
  17. <li><a href="#Architecture">Architecture</a>
  18. <ul>
  19. <li><a href="#Design_goals">Design goals</a>
  20. <li><a href="#Design_principles">Design principles</a>
  21. <li><a href="#Large_scale_structure">Large-scale structure</a>
  22. <li><a href="#Object_oriented_constructs">Object-oriented constructs</a>
  23. </ul>
  24. <li><a href="#File_roadmap">File roadmap</a>
  25. <ul>
  26. <li><a href="#Substrate">Substrate</a>
  27. <li><a href="#Graphics_library">Graphics library</a>
  28. <ul>
  29. <li><a href="#Library_support">Support</a>,
  30. <a href="#Paths">Paths</a>,
  31. <a href="#Text">Text</a>,
  32. <a href="#Images">Images</a>,
  33. <a href="#Paint">Paint</a>,
  34. <a href="#Clipping">Clipping</a>,
  35. <a href="#Other_graphics">Other graphics</a>,
  36. <a href="#Driver_support">Driver support</a>
  37. </ul>
  38. <li><a href="#Device_drivers">Device drivers</a>
  39. <ul>
  40. <li><a href="#Internal_devices">Internal devices</a>,
  41. <a href="#PS_and_PDF_writers">PostScript and PDF writers</a>,
  42. <a href="#High_level_devices">Other high-level devices</a>,
  43. <a href="#Other_maintained_drivers">Other maintained drivers</a>,
  44. <a href="#Contributed_drivers">Contributed drivers</a>
  45. </ul>
  46. <li><a href="#PostScript_interpreter">PostScript interpreter</a>
  47. <ul>
  48. <li><a href="#Main_program">Main program</a>,
  49. <a href="#Data_structures">Data structures</a>,
  50. <a href="#Interpreter_loop">Interpreter loop</a>,
  51. <a href="#Scanning_parsing">Scanning/parsing</a>,
  52. <a href="#Standard_operators">Standard operators</a>,
  53. <a href="#Non_standard_operators">Non-standard operators</a>,
  54. <a href="#Interpreter_support">Interpreter support</a>,
  55. <a href="#PostScript_code">PostScript code</a>
  56. </ul>
  57. <li><a href="#PDF_interpreter">PDF interpreter</a>
  58. <li><a href="#Build_process">Build process</a>
  59. <ul>
  60. <li><a href="#Makefile_structure">Makefile structure</a>,
  61. <a href="#dev_files">.dev files</a>,
  62. <a href="#Generators">Generators</a>,
  63. <a href="#Build_support">Support</a>
  64. </ul>
  65. <li><a href="#Utilities">Utilities</a>
  66. <ul>
  67. <li><a href="#Utilities_in_PostScript">Utilities in PostScript</a>
  68. <li><a href="#Utility_scripts">Utility scripts</a>
  69. </ul>
  70. </ul>
  71. <li><a href="#Memory_management">Memory management</a>
  72. <ul>
  73. <li><a href="#Memory_manager_architecture">Memory manager architecture</a>
  74. <ul>
  75. <li><a href="#Objects_vs_strings">Objects vs strings</a>,
  76. <a href="#Structure_descriptors">Structure descriptors</a>,
  77. <a href="#Garbage_collection">Garbage collection</a>,
  78. <a href="#Movability">Movability</a>,
  79. <a href="#Parent_hierarchy">Parent hierarchy</a>,
  80. <a href="#Allocator_API">Allocator API</a>
  81. </ul>
  82. <li><a href="#Freeing_storage">Freeing storage</a>
  83. <ul>
  84. <li><a href="#Explicit_freeing">Explicit freeing</a>,
  85. <a href="#Reference_counting">Reference counting</a>,
  86. <a href="#Real_garbage_collection">(Real) garbage collection</a>
  87. </ul>
  88. <li><a href="#Special_implementations">Special implementations</a>
  89. <ul>
  90. <li><a href="#malloc">malloc</a>,
  91. <a href="#Locking">Locking</a>,
  92. <a href="#Retrying">Retrying</a>
  93. </ul>
  94. <li><a href="#Standard_implementation">Standard implementation</a>
  95. <li><a href="#PostScript_interpreter_extensions">PostScript interpreter extensions</a>
  96. <ul>
  97. <li><a href="#Refs">Refs (PostScript "objects")</a>,
  98. <a href="#save_forgetsave_restore">save/.forgetsave/restore</a>,
  99. <a href="#Stable_allocators">Stable allocators</a>,
  100. <a href="#Interpreter_GC">Garbage collection</a>
  101. </ul>
  102. </ul>
  103. <li><a href="#Portability">Portability</a>
  104. <ul>
  105. <li><a href="#Structural">Structural</a>
  106. <ul>
  107. <li><a href="#CPU_and_compiler">CPU and compiler</a>,
  108. <a href="#Library_headers">Library headers</a>,
  109. <a href="#Cross_platform_APIs">Cross-platform APIs</a>,
  110. <a href="#Makefiles">Makefiles</a>
  111. </ul>
  112. <li><a href="#Coding">Coding</a>
  113. <ul>
  114. <li><a href="#Explicit_dependencies">Explicit dependencies</a>,
  115. <a href="#Implicit_dependencies">Implicit dependencies</a>
  116. </ul>
  117. <li><a href="#Platform_specific_code">Platform-specific code</a>
  118. </ul>
  119. <li><a href="#Adding_features_and_options">Adding features and options</a>
  120. <li><a href="#Troubleshooting">Troubleshooting</a>
  121. </ul></blockquote>
  122. <!-- [1.2 end table of contents] =========================================== -->
  123. <!-- [1.3 begin hint] ====================================================== -->
  124. <p>For other information, see the <a href="Readme.htm">Ghostscript
  125. overview</a> and the documentation related to <a
  126. href="Maintain.htm">maintaining Ghostscript</a>.
  127. <!-- [1.3 end hint] ======================================================== -->
  128. <hr>
  129. <!-- [1.0 end visible header] ============================================== -->
  130. <!-- [2.0 begin contents] ================================================== -->
  131. <h2><a name="Introduction"></a>Introduction</h2>
  132. <p>
  133. This document provides a wealth of information about Ghostscript's
  134. internals, primarily for developers actively working on Ghostscript. It is
  135. primarily <strong>descriptive</strong>, documenting the way things are; the
  136. companion <a href="C-style.htm">C style guide</a> is primarily
  137. <strong>prescriptive</strong>, documenting what developers should do when
  138. writing new code.
  139. <p>
  140. THIS FILE IS A WORK IN PROGRESS. MANY SECTIONS ARE PLACE-HOLDERS.
  141. <h2><a name="Architecture"></a>Architecture</h2>
  142. <h3><a name="Design_goals"></a>Design goals</h3>
  143. <p>
  144. Ghostscript has the following high-level design goals (not listed in order
  145. of importance):
  146. <ul>
  147. <li>Functionality
  148. <ul>
  149. <li>Ability to interpret the current PostScript and PDF languages, as
  150. defined (and occasionally, in the case of conflict, as implemented) by
  151. Adobe.
  152. <li>Ability to convert PostScript to and from PDF, comparable to
  153. Adobe products.
  154. <li>Ability to produce output for a wide range of resolutions (from
  155. TV-resolution displays to imagesetters) and color models (black and white,
  156. multilevel gray, bilevel or multi-level RGB and CMYK, 6- or 8-color
  157. inkjet printers, spot color).
  158. </ul>
  159. <li>Performance
  160. <ul>
  161. <li>Ability to render PostScript and PDF with commercial-quality performance
  162. (memory usage, speed, and output quality) on all platforms.
  163. <li>Specifically, ability to render PostScript effectively in embedded
  164. environments with constrained RAM, including the ability to put the code and
  165. supporting data in ROM.
  166. </ul>
  167. <li>Licensing
  168. <ul>
  169. <li>Licensing that supports both the Open Source / Free software communities
  170. and a commercial licensing business.
  171. <li>Freedom from licensing restrictions or fees imposed by third parties.
  172. </ul>
  173. <li>Other
  174. <ul>
  175. <li>Easy source portability to any platform (CPU, operating system, and
  176. development tools) that has an ANSI or K&amp;R C compiler.
  177. <li>Support for writing new interpreters and new drivers with no change to
  178. any existing code; specifically, ability to support PCL 5e, PCL 5c, and PCL
  179. XL interpreters, and the ever-changing roster of inkjet printers.
  180. </ul>
  181. </ul>
  182. <p>
  183. These goals often conflict: part of Ghostscript's claim to quality is that
  184. the conflicts have been resolved well.
  185. <h3><a name="Design_principles"></a>Design principles</h3>
  186. <p>
  187. Part of what has kept Ghostscript healthy through many years of major code
  188. revisions and functional expansion is consistent and conscientious adherence
  189. to a set of design principles. We hope the following list captures the most
  190. important ones.
  191. <h4>Non-preemption</h4>
  192. <p>
  193. Ghostscript is designed to be used as a component. As such, it must share
  194. its environment with other components. Therefore, it must not require
  195. ownership of, or make decisions about, inherently shared resources.
  196. Specifically, it must not assume that it can "own" either the locus of
  197. control or the management of the address space.
  198. <p>
  199. Not owning control means that whenever Ghostscript passes control to its
  200. caller, it must do so in a way that doesn't constrain what the caller can do
  201. next. The caller must be able to call any other piece of software, wait for
  202. an external event, execute another task, etc., without having to worry about
  203. Ghostscript being in an unknown state. While this is easy to arrange in a
  204. multi-threaded environment (by running Ghostscript in a separate thread),
  205. multi-threading APIs are not well standardized at this time (December 2000),
  206. and may not be implemented efficiently, or at all, on some platforms.
  207. Therefore, Ghostscript must choose between only two options for interacting
  208. with its caller: to <em>return</em>, preserving its own state in data
  209. structures, or to <em>call back</em> through a caller-supplied procedure.
  210. Calling back constrains the client program unacceptably: the callback
  211. procedure only has the options of either returning, or aborting Ghostscript.
  212. In particular, if it wants (for whatever reason) to multi-task Ghostscript
  213. with another program, it cannot do so in general, especially if the other
  214. program also uses callback rather than suspension. Therefore, Ghostscript
  215. tries extremely hard to return, rather than calling back, for all caller
  216. interaction. In particular:
  217. <ul>
  218. <li>For callers that want to pass input to Ghostscript piece by piece,
  219. Ghostscript returns with an <b><tt>e_NeedInput</tt></b> code rather than
  220. using a callback. This allows the caller complete flexibility in its
  221. control structure for managing the source of input. (It might, for example,
  222. be generating the input dynamically.)
  223. <li>In the future, the same arrangement should be used for input from
  224. <b><tt>stdin</tt></b> and output to <b><tt>stdout</tt></b> and
  225. <b><tt>stderr</tt></b>.
  226. <li>Likewise, scheduling of Ghostscript's own threads (contexts), currently
  227. done with a callback, should be done with suspension. The Display
  228. Ghostscript project (GNU DGS) is working on this.
  229. </ul>
  230. <p>
  231. The one area where suspension is not feasible with Ghostscript's current
  232. architecture is device output. Device drivers are called from deep within
  233. the graphics library. (If Ghostscript were being redesigned from scratch,
  234. we might try to do this with suspension as well, or at least optional
  235. suspension.)
  236. <p>
  237. Not owning management of the address space means that even though
  238. Ghostscript supports garbage collection for its own data, it must not do any
  239. of the things that garbage collection schemes for C often require: it must
  240. not replace 'malloc' and 'free', must not require its clients to use its own
  241. allocator, must not rely on manipulating the read/write status of memory
  242. pages, must not require special compiler or run-time support (e.g., APIs for
  243. scanning the C stack), must not depend on the availability of
  244. multi-threading, and must not take possession of one of a limited number of
  245. timer interrupts. However, in order not to constrain its own code unduly,
  246. it must also not require using special macros or calls to enter or leave
  247. procedures or assign pointers, and must not constrain the variety of C data
  248. structures any more than absolutely necessary. It achieves all of these
  249. goals, at the expense of some complexity, some performance cost (mostly for
  250. garbage collection), and some extra manual work required for each structure
  251. type allocated by its allocator. The details appear in the <a
  252. href="#Memory_management">Memory management</a> section below.
  253. <h4>Multi-instantiability</h4>
  254. <p>
  255. From many years of experience with the benefits of object-oriented design,
  256. we have learned that when the word "the" appears in a software design --
  257. "the" process scheduler, "the" memory manager, "the" output device, "the"
  258. interpreter, "the" stack -- it often flags an area in which the software
  259. will have difficulty adapting to future needs. For this reason, Ghostscript
  260. attempts to make every internal structure capable of existing in multiple
  261. instances. For example, Ghostscript's memory manager is not a one-of-a-kind
  262. entity with global state and procedures: it is (or rather they are, since
  263. Ghostscript has multiple memory managers, some of which have multiple
  264. instances) objects with their own state and (virtual) procedures.
  265. Ghostscript's PostScript interpreter has no writable non-local data
  266. (necessary, but not sufficient, to allow multiple instances), and in the
  267. future will be extended to be completely reentrant and instantiable. The
  268. device driver API is designed to make this easy for drivers as well. The
  269. graphics library is currently not completely reentrant or instantiable: we
  270. hope this will occur in the future.
  271. <h4>Late configuration binding</h4>
  272. <p>
  273. Ghostscript is designed to make configuration choices as late as possible,
  274. subject to simplicity and performance considerations. The major binding
  275. times for such choices are compilation, linking, startup, and dynamic.
  276. <ul>
  277. <li>Compilation binds only CPU and compiler characteristics (including data
  278. type size, presence of floating point hardware, and data alignment), and
  279. whether the code will be used for production, debugging, or profiling.
  280. <li>Linking binds the choice of what features and device drivers will be
  281. included in the executable. (Work is underway to make the choice of drivers
  282. dynamic.)
  283. <li>Startup binds essentially nothing. Almost every option and parameter
  284. that can appear on the command line can also be changed dynamically.
  285. <li>The selection of output device, all parameters associated with the
  286. device, the selection of debugging printout and self-checking (in debugging
  287. configurations), the macro-allocation of memory, and almost all other
  288. operational parameters are dynamic.
  289. </ul>
  290. <p>
  291. In addition, a number of major implementation decisions are made dynamically
  292. depending on the availability of resources. For example, Ghostscript
  293. chooses between banded and non-banded rendering depending on memory
  294. availability.
  295. <h3><a name="Large_scale_structure"></a>Large-scale structure</h3>
  296. <p>
  297. At the largest design scale, Ghostscript consists of 4 layers. Layer N
  298. is allowed to use the facilities of all layers M &lt;= N.
  299. <ol>
  300. <li>The bottom layer is called the <a href="#Substrate">substrate</a>. It
  301. includes facilities like memory management, streams, fixed-point arithmetic,
  302. and low-level interfaces to the operating system. The substrate is written
  303. in C, with a little C++ and/or assembler code for some platforms.
  304. <li>The layer above the substrate is the graphics layer. It consists of two
  305. separate sub-parts. The graphics layer is written in C.
  306. <ul>
  307. <li>The <a href="#Graphics_library">graphics library</a> manages graphics
  308. state information for, and decomposes and renders 2-D images described
  309. using, a graphics model that is approximately the union of those of
  310. PostScript, PDF, and PCL 5e/5c/XL.
  311. <li>The <a href="#Device_drivers">device drivers</a> are called by the
  312. graphics library to produce actual output. The graphics library, and all
  313. higher layers, call device driver procedures only through virtual functions.
  314. </ul>
  315. <li>The principal clients of the graphics layer are language interpreters.
  316. Ghostscript as distributed includes the <a
  317. href="#PostScript_interpreter">PostScript interpreter</a>; there are also
  318. interpreters for PCL 5e, PCL 5c, and PCL XL, which are not currently freely
  319. redistributable and are not included in the standard Ghostscript package.
  320. The PostScript interpreter is written partly in C and partly in PostScript.
  321. <li>The <a href="#PDF_interpreter">PDF interpreter</a> is actually a client
  322. of the PostScript interpreter: it is written entirely in PostScript.
  323. </ol>
  324. <p>
  325. The most important interface in Ghostscript is the API between the graphics
  326. library and the device drivers: new printers (and, to a lesser extent,
  327. window systems, displays, plotters, film recorders, and graphics file
  328. formats) come on the scene frequently, and it must be possible to produce
  329. output for them with a minimum of effort and distruption. This API is the
  330. only one that is extensively documented (see <a
  331. href="Drivers.htm">Drivers.htm</a>) and kept stringently backward-compatible
  332. through successive releases.
  333. <h3><a name="Object_oriented_constructs"></a>Object-oriented constructs</h3>
  334. <p>
  335. Ghostscript makes heavy use of object-oriented constructs, including
  336. analogues of classes, instances, subclassing, and class-associated
  337. procedures. Since Ghostscript is written in C, not C++, implementing these
  338. constructs requires following coding conventions. The <a
  339. href="C-style.htm#Objects">"Objects"</a> section of the C style guide
  340. explains these.
  341. <p>
  342. The memory manager API provides run-time type information about each class,
  343. but this information does not include anything about subclassing. See under
  344. <a href="#Structure_descriptors">Structure descriptors</a> below.
  345. <hr>
  346. <h2><a name="File_roadmap"></a>File roadmap</h2>
  347. <p>
  348. This section of the document provides a roadmap to all of the Ghostscript
  349. source files.
  350. <h3><a name="Substrate"></a>Substrate</h3>
  351. <h4>Memory manager</h4>
  352. <p>
  353. See <a href="#Memory_management">below</a>.
  354. <h4>Streams</h4>
  355. <dl>
  356. <dt>
  357. Framework, file and string streams:
  358. <dd>
  359. <a href="../src/gsdsrc.c">src/gsdsrc.c</a>,
  360. <a href="../src/gsdsrc.h">src/gsdsrc.h</a>,
  361. <a href="../src/scommon.h">src/scommon.h</a>,
  362. <a href="../src/sfxboth.c">src/sfxboth.c</a>,
  363. <a href="../src/sfxfd.c">src/sfxfd.c</a>,
  364. <a href="../src/sfxstdio.c">src/sfxstdio.c</a>,
  365. <a href="../src/stream.h">src/stream.h</a>,
  366. <a href="../src/stream.c">src/stream.c</a>,
  367. <a href="../src/strimpl.h">src/strimpl.h</a>.
  368. <dt>
  369. Standard filters:
  370. <dd>
  371. <dl>
  372. <dt>
  373. CCITTFax:
  374. <dd>
  375. <a href="../src/scf.h">src/scf.h</a>,
  376. <a href="../src/scfd.c">src/scfd.c</a>,
  377. <a href="../src/scfdgen.c">src/scfdgen.c</a>,
  378. <a href="../src/scfdtab.c">src/scfdtab.c</a>,
  379. <a href="../src/scfe.c">src/scfe.c</a>,
  380. <a href="../src/scfetab.c">src/scfetab.c</a>,
  381. <a href="../src/scfparam.c">src/scfparam.c</a>,
  382. <a href="../src/scfx.h">src/scfx.h</a>.
  383. <dt>
  384. DCT (JPEG):
  385. <dd>
  386. <a href="../src/gsjconf.h">src/gsjconf.h</a>,
  387. <a href="../src/gsjmorec.h">src/gsjmorec.h</a>,
  388. <a href="../src/sdcparam.c">src/sdcparam.c</a>,
  389. <a href="../src/sdcparam.h">src/sdcparam.h</a>,
  390. <a href="../src/sdct.h">src/sdct.h</a>,
  391. <a href="../src/sdctc.c">src/sdctc.c</a>,
  392. <a href="../src/sdctd.c">src/sdctd.c</a>,
  393. <a href="../src/sdcte.c">src/sdcte.c</a>,
  394. <a href="../src/sddparam.c">src/sddparam.c</a>,
  395. <a href="../src/sdeparam.c">src/sdeparam.c</a>,
  396. <a href="../src/sjpeg.h">src/sjpeg.h</a>,
  397. <a href="../src/sjpegc.c">src/sjpegc.c</a>,
  398. <a href="../src/sjpegd.c">src/sjpegd.c</a>,
  399. <a href="../src/sjpege.c">src/sjpege.c</a>.
  400. <dt>
  401. Other compression/decompression:
  402. <dd>
  403. <a href="../src/slzwc.c">src/slzwc.c</a>,
  404. <a href="../src/slzwce.c">src/slzwce.c</a>,
  405. <a href="../src/slzwd.c">src/slzwd.c</a>,
  406. <a href="../src/slzwx.h">src/slzwx.h</a>,
  407. <a href="../src/srld.c">src/srld.c</a>,
  408. <a href="../src/srle.c">src/srle.c</a>,
  409. <a href="../src/srlx.h">src/srlx.h</a>.
  410. <dt>
  411. Other:
  412. <dd>
  413. <a href="../src/sa85d.c">src/sa85d.c</a>,
  414. <a href="../src/sa85d.h">src/sa85d.h</a>,
  415. <a href="../src/sa85x.h">src/sa85x.h</a>,
  416. <a href="../src/sfilter1.c">src/sfilter1.c</a>,
  417. <a href="../src/sfilter2.c">src/sfilter2.c</a>,
  418. <a href="../src/sstring.c">src/sstring.c</a>,
  419. <a href="../src/sstring.h">src/sstring.h</a>.
  420. </dl>
  421. <dt>
  422. Non-standard filters used to implement standard filters:
  423. <dd>
  424. <a href="../src/seexec.c">src/seexec.c</a>,
  425. <a href="../src/sfilter.h">src/sfilter.h</a>,
  426. <a href="../src/shc.c">src/shc.c</a>,
  427. <a href="../src/shc.h">src/shc.h</a>,
  428. <a href="../src/shcgen.c">src/shcgen.c</a>,
  429. <a href="../src/shcgen.h">src/shcgen.h</a>,
  430. <a href="../src/spdiff.c">src/spdiff.c</a>,
  431. <a href="../src/spdiffx.h">src/spdiffx.h</a>,
  432. <a href="../src/spngp.c">src/spngp.c</a>,
  433. <a href="../src/spngpx.h">src/spngpx.h</a>,
  434. <a href="../src/szlibc.c">src/szlibc.c</a>,
  435. <a href="../src/szlibd.c">src/szlibd.c</a>,
  436. <a href="../src/szlibe.c">src/szlibe.c</a>,
  437. <a href="../src/szlibx.h">src/szlibx.h</a>,
  438. <a href="../src/szlibxx.h">src/szlibxx.h</a>.
  439. <dt>
  440. Non-standard filters:
  441. <dd>
  442. <a href="../src/sbcp.c">src/sbcp.c</a>,
  443. <a href="../src/sbcp.h">src/sbcp.h</a>,
  444. <a href="../src/sbhc.c">src/sbhc.c</a>,
  445. <a href="../src/sbhc.h">src/sbhc.h</a>,
  446. <a href="../src/sbtx.h">src/sbtx.h</a>,
  447. <a href="../src/sbwbs.c">src/sbwbs.c</a>,
  448. <a href="../src/sbwbs.h">src/sbwbs.h</a>,
  449. <a href="../src/smd5.c">src/smd5.c</a>,
  450. <a href="../src/smd5.h">src/smd5.h</a>,
  451. <a href="../src/sarc4.c">src/sarc4.c</a>,
  452. <a href="../src/sarc4.h">src/sarc4.h</a>,
  453. <a href="../src/smtf.c">src/smtf.c</a>,
  454. <a href="../src/smtf.h">src/smtf.h</a>.
  455. <dt>
  456. Internal filters:
  457. <dd>
  458. a<a href="../src/siinterp.c">src/siinterp.c</a>,
  459. <a href="../src/siinterp.h">src/siinterp.h</a>,
  460. <a href="../src/siscale.c">src/siscale.c</a>,
  461. <a href="../src/siscale.h">src/siscale.h</a>,
  462. <a href="../src/sisparam.h">src/sisparam.h</a>.
  463. <dt>
  464. Higher-level stream support:
  465. <dd>
  466. <a href="../src/spprint.c">src/spprint.c</a>,
  467. <a href="../src/spprint.h">src/spprint.h</a>,
  468. <a href="../src/spsdf.c">src/spsdf.c</a>,
  469. <a href="../src/spsdf.h">src/spsdf.h</a>,
  470. <a href="../src/srdline.h">src/srdline.h</a>.
  471. </dl>
  472. <h4>Platform-specific code</h4>
  473. See <a href="#Cross_platform_APIs">below</a>.
  474. <h4>Miscellaneous</h4>
  475. <dl>
  476. <dt>
  477. Library top level:
  478. <dd>
  479. <a href="../src/gsinit.c">src/gsinit.c</a>,
  480. <a href="../src/gslib.h">src/gslib.h</a>.
  481. <dt>
  482. Configuration-related:
  483. <dd>
  484. <a href="../src/gconf.c">src/gconf.c</a>,
  485. <a href="../src/gconf.h">src/gconf.h</a>,
  486. <a href="../src/gscdef.c">src/gscdef.c</a>,
  487. <a href="../src/gscdefs.h">src/gscdefs.h</a>.
  488. <dt>
  489. Arithmetic:
  490. <dd>
  491. <a href="../src/gsfemu.c">src/gsfemu.c</a>,
  492. <a href="../src/gxarith.h">src/gxarith.h</a>,
  493. <a href="../src/gxdda.h">src/gxdda.h</a>,
  494. <a href="../src/gxfarith.h">src/gxfarith.h</a>,
  495. <a href="../src/gxfixed.h">src/gxfixed.h</a>,
  496. <a href="../src/gxfrac.h">src/gxfrac.h</a>.
  497. <dt>
  498. Operating system interface:
  499. <dd>
  500. <a href="../src/gserror.h">src/gserror.h</a>,
  501. <a href="../src/gsexit.h">src/gsexit.h</a>,
  502. <a href="../src/gxstdio.h">src/gxstdio.h</a>,
  503. <a href="../src/gxsync.c">src/gxsync.c</a>,
  504. <a href="../src/gxsync.h">src/gxsync.h</a>.
  505. <dt>
  506. Other:
  507. <dd>
  508. <a href="../src/gsargs.c">src/gsargs.c</a>,
  509. <a href="../src/gsargs.h">src/gsargs.h</a>,
  510. <a href="../src/gserrors.h">src/gserrors.h</a>,
  511. <a href="../src/gsnotify.c">src/gsnotify.c</a>,
  512. <a href="../src/gsnotify.h">src/gsnotify.h</a>,
  513. <a href="../src/gsrect.h">src/gsrect.h</a>,
  514. <a href="../src/gstypes.h">src/gstypes.h</a>,
  515. <a href="../src/gsuid.h">src/gsuid.h</a>,
  516. <a href="../src/gsutil.h">src/gsutil.h</a>,
  517. <a href="../src/gsutil.c">src/gsutil.c</a>,
  518. <a href="../src/gx.h">src/gx.h</a>,
  519. <a href="../src/md5.c">src/md5.c</a>,
  520. <a href="../src/md5.h">src/md5.h</a>.
  521. </dl>
  522. <h3><a name="Graphics_library"></a>Graphics library</h3>
  523. <h4><a name="Library_support"></a>Support</h4>
  524. <dl>
  525. <dt>
  526. Bitmap processing:
  527. <dd>
  528. <a href="../src/gsbitcom.c">src/gsbitcom.c</a>,
  529. <a href="../src/gsbitmap.h">src/gsbitmap.h</a>,
  530. <a href="../src/gsbitops.c">src/gsbitops.c</a>,
  531. <a href="../src/gsbitops.h">src/gsbitops.h</a>,
  532. <a href="../src/gsbittab.c">src/gsbittab.c</a>,
  533. <a href="../src/gsbittab.h">src/gsbittab.h</a>,
  534. <a href="../src/gsflip.c">src/gsflip.c</a>,
  535. <a href="../src/gsflip.h">src/gsflip.h</a>,
  536. <a href="../src/gxbitmap.h">src/gxbitmap.h</a>,
  537. <a href="../src/gxbitops.h">src/gxbitops.h</a>,
  538. <a href="../src/gxsample.c">src/gxsample.c</a>,
  539. <a href="../src/gxsample.h">src/gxsample.h</a>.
  540. <dt>
  541. Functions:
  542. <dd>
  543. <a href="../src/gsfunc.c">src/gsfunc.c</a>,
  544. <a href="../src/gsfunc.h">src/gsfunc.h</a>,
  545. <a href="../src/gsfunc0.c">src/gsfunc0.c</a>,
  546. <a href="../src/gsfunc0.h">src/gsfunc0.h</a>,
  547. <a href="../src/gsfunc3.c">src/gsfunc3.c</a>,
  548. <a href="../src/gsfunc3.h">src/gsfunc3.h</a>,
  549. <a href="../src/gsfunc4.c">src/gsfunc4.c</a>,
  550. <a href="../src/gsfunc4.h">src/gsfunc4.h</a>,
  551. <a href="../src/gsfuncv.c">src/gsfuncv.c</a>,
  552. <a href="../src/gsfuncv.h">src/gsfuncv.h</a>,
  553. <a href="../src/gxfunc.h">src/gxfunc.h</a>.
  554. <dt>
  555. Parameter lists:
  556. <dd>
  557. <a href="../src/gscparam.c">src/gscparam.c</a>,
  558. <a href="../src/gsparam.c">src/gsparam.c</a>,
  559. <a href="../src/gsparam.h">src/gsparam.h</a>,
  560. <a href="../src/gsparam2.c">src/gsparam2.c</a> (not used),
  561. <a href="../src/gsparams.c">src/gsparams.c</a>,
  562. <a href="../src/gsparams.h">src/gsparams.h</a>,
  563. <a href="../src/gsparamx.c">src/gsparamx.c</a>,
  564. <a href="../src/gsparamx.h">src/gsparamx.h</a>.
  565. <dt>
  566. I/O-related:
  567. <dd>
  568. <a href="../src/gdevpipe.c">src/gdevpipe.c</a>,
  569. <a href="../src/gsfname.c">src/gsfname.c</a>,
  570. <a href="../src/gsfname.h">src/gsfname.h</a>,
  571. <a href="../src/gsio.h">src/gsio.h</a>,
  572. <a href="../src/gsiodev.c">src/gsiodev.c</a>,
  573. <a href="../src/gsiodevs.c">src/gsiodevs.c</a>,
  574. <a href="../src/gxiodev.h">src/gxiodev.h</a>.
  575. </dl>
  576. <h4><a name="Paths"></a>Paths</h4>
  577. <dl>
  578. <dt>
  579. Coordinate transformation:
  580. <dd>
  581. <a href="../src/gscoord.c">src/gscoord.c</a>,
  582. <a href="../src/gscoord.h">src/gscoord.h</a>,
  583. <a href="../src/gsmatrix.c">src/gsmatrix.c</a>,
  584. <a href="../src/gsmatrix.h">src/gsmatrix.h</a>,
  585. <a href="../src/gxcoord.h">src/gxcoord.h</a>,
  586. <a href="../src/gxmatrix.h">src/gxmatrix.h</a>.
  587. <dt>
  588. Path building:
  589. <dd>
  590. <a href="../src/gsdps1.c">src/gsdps1.c</a>,
  591. <a href="../src/gspath.c">src/gspath.c</a>,
  592. <a href="../src/gspath.h">src/gspath.h</a>,
  593. <a href="../src/gspath1.c">src/gspath1.c</a>,
  594. <a href="../src/gspath2.h">src/gspath2.h</a>,
  595. <a href="../src/gxpath.c">src/gxpath.c</a>,
  596. <a href="../src/gxpath.h">src/gxpath.h</a>,
  597. <a href="../src/gxpath2.c">src/gxpath2.c</a>,
  598. <a href="../src/gxpcopy.c">src/gxpcopy.c</a>,
  599. <a href="../src/gxpdash.c">src/gxpdash.c</a>,
  600. <a href="../src/gxpflat.c">src/gxpflat.c</a>,
  601. <a href="../src/gzpath.h">src/gzpath.h</a>.
  602. <dt>
  603. Path rendering:
  604. <dd>
  605. <a href="../src/gdevddrw.c">src/gdevddrw.c</a>,
  606. <a href="../src/gsdps1.c">src/gsdps1.c</a>,
  607. <a href="../src/gspaint.c">src/gspaint.c</a>,
  608. <a href="../src/gspaint.h">src/gspaint.h</a>,
  609. <a href="../src/gspenum.h">src/gspenum.h</a>,
  610. <a href="../src/gxfill.c">src/gxfill.c</a>,
  611. <a href="../src/gxpaint.c">src/gxpaint.c</a>,
  612. <a href="../src/gxpaint.h">src/gxpaint.h</a>,
  613. <a href="../src/gxstroke.c">src/gxstroke.c</a>.
  614. <dt>
  615. Clipping:
  616. <dd>
  617. See under <a href="#Clipping">Clipping</a> below.
  618. </dl>
  619. <h4><a name="Text"></a>Text</h4>
  620. <dl>
  621. <dt>
  622. Fonts, generic:
  623. <dd>
  624. <a href="../src/gsfont.c">src/gsfont.c</a>,
  625. <a href="../src/gsfont.h">src/gsfont.h</a>,
  626. <a href="../src/gxfont.h">src/gxfont.h</a>.
  627. <dt>
  628. Fonts, specific FontTypes:
  629. <dd>
  630. <a href="../src/gsfcid.c">src/gsfcid.c</a>,
  631. <a href="../src/gsfcmap.c">src/gsfcmap.c</a>,
  632. <a href="../src/gsfcmap.h">src/gsfcmap.h</a>,
  633. <a href="../src/gsfont0.c">src/gsfont0.c</a>,
  634. <a href="../src/gxcid.h">src/gxcid.h</a>,
  635. <a href="../src/gxfcid.h">src/gxfcid.h</a>,
  636. <a href="../src/gxfcmap.h">src/gxfcmap.h</a>,
  637. <a href="../src/gxfont0.h">src/gxfont0.h</a>,
  638. <a href="../src/gxfont1.h">src/gxfont1.h</a>,
  639. <a href="../src/gxfont42.h">src/gxfont42.h</a>,
  640. <a href="../src/gxftype.h">src/gxftype.h</a>,
  641. <a href="../src/gxttf.h">src/gxttf.h</a>.
  642. <dt>
  643. Character rendering + font cache, generic:
  644. <dd>
  645. <a href="../src/gsccode.h">src/gsccode.h</a>,
  646. <a href="../src/gschar.c">src/gschar.c</a>,
  647. <a href="../src/gschar.h">src/gschar.h</a>,
  648. <a href="../src/gscpm.h">src/gscpm.h</a>,
  649. <a href="../src/gstext.c">src/gstext.c</a>,
  650. <a href="../src/gstext.h">src/gstext.h</a>,
  651. <a href="../src/gxbcache.c">src/gxbcache.c</a>,
  652. <a href="../src/gxbcache.h">src/gxbcache.h</a>,
  653. <a href="../src/gxccache.c">src/gxccache.c</a>,
  654. <a href="../src/gxccman.c">src/gxccman.c</a>,
  655. <a href="../src/gxchar.c">src/gxchar.c</a>,
  656. <a href="../src/gxchar.h">src/gxchar.h</a>,
  657. <a href="../src/gxfcache.h">src/gxfcache.h</a>,
  658. <a href="../src/gxtext.h">src/gxtext.h</a>.
  659. <dt>
  660. Character rendering, specific FontTypes:
  661. <dd>
  662. <a href="../src/gschar0.c">src/gschar0.c</a>,
  663. <a href="../src/gscrypt1.c">src/gscrypt1.c</a>,
  664. <a href="../src/gscrypt1.h">src/gscrypt1.h</a>,
  665. <a href="../src/gstype1.c">src/gstype1.c</a>,
  666. <a href="../src/gstype1.h">src/gstype1.h</a>,
  667. <a href="../src/gstype2.c">src/gstype2.c</a>,
  668. <a href="../src/gstype42.c">src/gstype42.c</a>,
  669. <a href="../src/gxchrout.c">src/gxchrout.c</a>,
  670. <a href="../src/gxchrout.h">src/gxchrout.h</a>,
  671. <a href="../src/gxhint1.c">src/gxhint1.c</a>,
  672. <a href="../src/gxhint2.c">src/gxhint2.c</a>,
  673. <a href="../src/gxhint3.c">src/gxhint3.c</a>,
  674. <a href="../src/gxop1.h">src/gxop1.h</a>,
  675. <a href="../src/gxtype1.c">src/gxtype1.c</a>,
  676. <a href="../src/gxtype1.h">src/gxtype1.h</a>.
  677. </dl>
  678. <h4><a name="Images"></a>Images</h4>
  679. <dl>
  680. <dt>
  681. Buffered API (mostly for PostScript interpreter):
  682. <dd>
  683. <a href="../src/gsimage.c">src/gsimage.c</a>,
  684. <a href="../src/gsimage.h">src/gsimage.h</a>.
  685. <dt>
  686. Generic support:
  687. <dd>
  688. <a href="../src/gsiparam.h">src/gsiparam.h</a>,
  689. <a href="../src/gxiclass.h">src/gxiclass.h</a>,
  690. <a href="../src/gximage.c">src/gximage.c</a>,
  691. <a href="../src/gximage.h">src/gximage.h</a>,
  692. <a href="../src/gxiparam.h">src/gxiparam.h</a>.
  693. <dt>
  694. Type 1 and 4 images:
  695. <dd>
  696. <dl>
  697. <dt>
  698. Setup:
  699. <dd>
  700. <a href="../src/gsiparm4.h">src/gsiparm4.h</a>,
  701. <a href="../src/gximage1.c">src/gximage1.c</a>,
  702. <a href="../src/gximage4.c">src/gximage4.c</a>.
  703. <dt>
  704. Rendering:
  705. <dd>
  706. <a href="../src/gxi12bit.c">src/gxi12bit.c</a>,
  707. <a href="../src/gxicolor.c">src/gxicolor.c</a>,
  708. <a href="../src/gxidata.c">src/gxidata.c</a>,
  709. <a href="../src/gxifast.c">src/gxifast.c</a>,
  710. <a href="../src/gximono.c">src/gximono.c</a>,
  711. <a href="../src/gxino12b.c">src/gxino12b.c</a>,
  712. <a href="../src/gxipixel.c">src/gxipixel.c</a>,
  713. <a href="../src/gxiscale.c">src/gxiscale.c</a>.
  714. </dl>
  715. <dt>
  716. Type 2 images (Display PostScript):
  717. <dd>
  718. <a href="../src/gsiparm2.h">src/gsiparm2.h</a>,
  719. <a href="../src/gximage2.c">src/gximage2.c</a>.
  720. <dt>
  721. Type 3 images:
  722. <dd>
  723. <a href="../src/gsipar3x.h">src/gsipar3x.h</a>,
  724. <a href="../src/gsiparm3.h">src/gsiparm3.h</a>,
  725. <a href="../src/gximag3x.c">src/gximag3x.c</a>,
  726. <a href="../src/gximag3x.h">src/gximag3x.h</a>,
  727. <a href="../src/gximage3.c">src/gximage3.c</a>,
  728. <a href="../src/gximage3.h">src/gximage3.h</a>.
  729. <dt>
  730. Other:
  731. <dd>
  732. <a href="../src/gsimpath.c">src/gsimpath.c</a>.
  733. </dl>
  734. <h4><a name="Paint"></a>Paint</h4>
  735. <p>
  736. Ghostscript uses 4 internal representations of color. We list them here in
  737. the order in which they occur in the rendering pipeline.
  738. <ol>
  739. <li>Clients of the graphics library normally specify colors using the
  740. <em>client color</em> structure (<b><tt>gs_client_color</tt></b>, defined in
  741. <a href="../src/gsccolor.h">src/gsccolor.h</a>), consisting of one or more
  742. numeric values and/or a pointer to a Pattern instance. This corresponds
  743. directly to the values that would be passed to the PostScript
  744. <b><tt>setcolor</tt></b> operator: one or more (floating-point) numeric
  745. components and/or a Pattern. Client colors are interpreted relative to a
  746. color space (<b><tt>gs_color_space</tt></b>, defined in <a
  747. href="../src/gscspace.h">src/gscspace.h</a> and <a
  748. href="../src/gxcspace.h">src/gxcspace.h</a>, with specific color spaces
  749. defined in other files). Client colors do not explicitly reference the
  750. color space in which they are are interpreted: <b><tt>setcolor</tt></b> uses
  751. the color space in the graphics state, while images and shadings explicitly
  752. specify the color space to be used.
  753. <li>For ordinary non-Pattern colors, the first step in color rendering
  754. reduces a client color to a <em>concrete</em> color -- a set of values in a
  755. color space that corresponds to the device's color model (except for
  756. possible conversions between DeviceGray, DeviceRGB, and DeviceCMYK),
  757. together with an identification of the associated color space. (The
  758. confusion here between color spaces and color models will have to be cleaned
  759. up when we implement native Separation/DeviceN colors.) Concrete colors are
  760. like the numeric values in a client color, except that they are represented
  761. by arrays of <b><tt>frac</tt></b> values (defined in <a
  762. href="../src/gxfrac.h">src/gxfrac.h</a>) rather than floats. The procedure
  763. for this step is the virtual <b><tt>concretize_color</tt></b> and
  764. <b><tt>concrete_space</tt></b> procedures in the (original) color space.
  765. This step reduces Indexed colors, CIEBased colors, and Separation and
  766. DeviceN colors that use the alternate space.
  767. <li>The final step requires mapping a concrete color to the device's color
  768. model, done by procedures in <a href="../src/gxcmap.c">src/gxcmap.c</a>.
  769. These procedures combine the following three conceptual sub-steps:
  770. <ul>
  771. <li>A possible mapping between Device color spaces, possibly involving black
  772. generation and undercolor removal. The non-trivial cases are implemented in
  773. <a href="../src/gxdcconv.c">src/gxdcconv.c</a>.
  774. <li>Application of the transfer function(s) (done in-line).
  775. <li>Halftoning if necessary: see below.
  776. </ul>
  777. The result is called (inappropriately) a <em>device color</em>
  778. (<b><tt>gx_device_color</tt></b>, defined in <a
  779. href="../src/gsdcolor.h">src/gsdcolor.h</a> and <a
  780. href="../src/gxdcolor.h">src/gxdcolor.h</a>). For ordinary non-Pattern
  781. colors, a device color is either a pure color, or a halftone. The device
  782. and color model associated with a device color are implicit. The procedure
  783. for this step is the virtual <b><tt>remap_concrete_color</tt></b> procedure
  784. in the color space.
  785. <li>The pure colors that underlie a device color are opaque <em>pixel
  786. values</em> defined by the device (misnamed <b><tt>gx_color_index</tt></b>,
  787. defined in <a href="../src/gscindex.h">src/gscindex.h</a>). The device with
  788. which they are associated is implicit. Although the format and
  789. interpretation of a pixel value are known only to the device, the device's
  790. color model and color representation capabilities are public, defined by a
  791. <b><tt>gx_color_info</tt></b> structure stored in the device (defined in <a
  792. href="../src/gxdevcli.h">src/gxdevcli.h</a>). Virtual procedures of the
  793. device driver map between pixel values and RGB or CMYK. (This area is
  794. untidy and will need to be cleaned up when we implement native
  795. Separation/DeviceN colors.)
  796. </ol>
  797. <p>
  798. Steps 2 and 3 are normally combined into a single step for efficiency, as
  799. the <b><tt>remap_color</tt></b> virtual procedure in a color space.
  800. <p>
  801. Using a device color to actually paint pixels requires a further step called
  802. <em>color loading</em>, implemented by the <b><tt>load</tt></b> virtual
  803. procedure in the device color. This does nothing for pure colors, but loads
  804. the caches for halftones and Patterns.
  805. <p>
  806. All of the above steps -- concretizing, mapping to a device color, and color
  807. loading -- are done as late as possible, normally not until the color is
  808. actually needed for painting.
  809. <p>
  810. All painting operations (fill, stroke, imagemask/show) eventually call a
  811. virtual procedure in the device color, either <b><tt>fill_rectangle</tt></b>
  812. or <b><tt>fill_mask</tt></b> to actually paint pixels. For rectangle fills,
  813. pure colors call the device's <b><tt>fill_rectangle</tt></b> procedure;
  814. halftones and tiled Patterns call the device's
  815. <b><tt>tile_rectangle</tt></b>; shaded Patterns, and painting operations
  816. that involve a RasterOp, do something more complicated.
  817. <dl>
  818. <dt>
  819. Color specification:
  820. <dd>
  821. <a href="../src/gsccolor.h">src/gsccolor.h</a>,
  822. <a href="../src/gscolor.c">src/gscolor.c</a>,
  823. <a href="../src/gscolor.h">src/gscolor.h</a>,
  824. <a href="../src/gscolor1.c">src/gscolor1.c</a>,
  825. <a href="../src/gscolor1.h">src/gscolor1.h</a>,
  826. <a href="../src/gscolor2.c">src/gscolor2.c</a>,
  827. <a href="../src/gscolor2.h">src/gscolor2.h</a>,
  828. <a href="../src/gscolor3.c">src/gscolor3.c</a>,
  829. <a href="../src/gscolor3.h">src/gscolor3.h</a>,
  830. <a href="../src/gshsb.c">src/gshsb.c</a>,
  831. <a href="../src/gshsb.h">src/gshsb.h</a>,
  832. <a href="../src/gxcolor2.h">src/gxcolor2.h</a>,
  833. <a href="../src/gxcvalue.h">src/gxcvalue.h</a>.
  834. <dt>
  835. Color spaces:
  836. <dd>
  837. <a href="../src/gscdevn.c">src/gscdevn.c</a>,
  838. <a href="../src/gscdevn.h">src/gscdevn.h</a>,
  839. <a href="../src/gscie.c">src/gscie.c</a>,
  840. <a href="../src/gscie.h">src/gscie.h</a>,
  841. <a href="../src/gscpixel.c">src/gscpixel.c</a>,
  842. <a href="../src/gscpixel.h">src/gscpixel.h</a>,
  843. <a href="../src/gscscie.c">src/gscscie.c</a>,
  844. <a href="../src/gscsepnm.h">src/gscsepnm.h</a>,
  845. <a href="../src/gscsepr.c">src/gscsepr.c</a>,
  846. <a href="../src/gscsepr.h">src/gscsepr.h</a>,
  847. <a href="../src/gscspace.c">src/gscspace.c</a>,
  848. <a href="../src/gscspace.h">src/gscspace.h</a>,
  849. <a href="../src/gscssub.c">src/gscssub.c</a>,
  850. <a href="../src/gscssub.h">src/gscssub.h</a>,
  851. <a href="../src/gxcdevn.h">src/gxcdevn.h</a>,
  852. <a href="../src/gxcie.h">src/gxcie.h</a>,
  853. <a href="../src/gxcspace.h">src/gxcspace.h</a>.
  854. <dt>
  855. Color mapping:
  856. <dd>
  857. <a href="../src/gsciemap.c">src/gsciemap.c</a>,
  858. <a href="../src/gscindex.h">src/gscindex.h</a>,
  859. <a href="../src/gscrd.c">src/gscrd.c</a>,
  860. <a href="../src/gscrd.h">src/gscrd.h</a>,
  861. <a href="../src/gscrdp.c">src/gscrdp.c</a>,
  862. <a href="../src/gscrdp.h">src/gscrdp.h</a>,
  863. <a href="../src/gscsel.h">src/gscsel.h</a>,
  864. <a href="../src/gsdcolor.h">src/gsdcolor.h</a>,
  865. <a href="../src/gxcindex.h">src/gxcindex.h</a>,
  866. <a href="../src/gxcmap.c">src/gxcmap.c</a>,
  867. <a href="../src/gxcmap.h">src/gxcmap.h</a>,
  868. <a href="../src/gxctable.c">src/gxctable.c</a>,
  869. <a href="../src/gxctable.h">src/gxctable.h</a>,
  870. <a href="../src/gxdcconv.c">src/gxdcconv.c</a>,
  871. <a href="../src/gxdcconv.h">src/gxdcconv.h</a>,
  872. <a href="../src/gxdcolor.c">src/gxdcolor.c</a>,
  873. <a href="../src/gxdcolor.h">src/gxdcolor.h</a>,
  874. <a href="../src/gxdither.c">src/gxdither.c</a>,
  875. <a href="../src/gxdither.h">src/gxdither.h</a>,
  876. <a href="../src/gxfmap.h">src/gxfmap.h</a>,
  877. <a href="../src/gxlum.h">src/gxlum.h</a>,
  878. <a href="../src/gxtmap.h">src/gxtmap.h</a>.
  879. <p>
  880. ICC profiles are in some ways a special case of color mapping, but are
  881. not standard in PostScript.
  882. <dt>
  883. Color mapping:
  884. <dd>
  885. <a href="../src/gsicc.c">src/gsicc.c</a>,
  886. <a href="../src/gsicc.h">src/gsicc.h</a>,
  887. </dl>
  888. <p>
  889. Ghostscript represents halftones internally by "whitening orders" --
  890. essentially, arrays of arrays of bit coordinates within a halftone cell,
  891. specifying which bits are inverted to get from halftone level K to level
  892. K+1. The code does support all of the PostScript halftone types, but they
  893. are all ultimately reduced to whitening orders.
  894. <p>
  895. Threshold arrays, the more conventional representation of halftones, can be
  896. mapped to whitening orders straightforwardly; however, whitening orders can
  897. represent non-monotonic halftones (halftones where the bits turned on for
  898. level K+1 don't necessarily include all the bits turned on for level K),
  899. while threshold arrays cannot. On the other hand, threshold arrays allow
  900. rapid conversion of images (using a threshold comparison for each pixel)
  901. with no additional space, while whitening orders do not: they require
  902. storing the rendered halftone cell for each possible level as a bitmap.
  903. <p>
  904. Ghostscript uses two distinct types of rendered halftones -- that is, the
  905. bitmap(s) that represent a particular level.
  906. <ul>
  907. <li>Binary halftones. The rendered halftone is a single bit plane; each bit
  908. selects one of two pure colors. These are fast but limited: they are used
  909. for monochrome output devices, or for color devices in those cases where
  910. only two distinct colors are involved in a halftone (e.g., a pure cyan shade
  911. on a CMYK device). The device color for a binary halftone stores a pointer
  912. to the halftone bitmap, and the two pure colors.
  913. <li>Multi-plane halftones. Internally, each plane is rendered individually.
  914. Since there isn't enough room to store all 2^N pure colors, multi-plane
  915. halftones only store the scaled values for the individual components; the
  916. halftone renderer maps these to the pure colors on the fly, then combines
  917. the planes to assemble an N-bit index into the list of colors for each
  918. pixel, and stores the color into the fully rendered halftone.
  919. </ul>
  920. <p>
  921. The halftone level for rendering a color is computed in <a
  922. href="../src/gxdither.c">src/gxdither.c</a>; the actual halftone mask or
  923. tile is computed either in <a href="../src/gxcht.c">src/gxcht.c</a> (for
  924. multi-plane halftones), or in <a href="../src/gxht.c">src/gxht.c</a> and <a
  925. href="../src/gxhtbit.c">src/gxhtbit.c</a> (for binary halftones).
  926. <dl>
  927. <dt>
  928. Halftoning:
  929. <dd>
  930. <a href="../src/gsht.c">src/gsht.c</a>,
  931. <a href="../src/gsht.h">src/gsht.h</a>,
  932. <a href="../src/gsht1.c">src/gsht1.c</a>,
  933. <a href="../src/gsht1.h">src/gsht1.h</a>,
  934. <a href="../src/gshtscr.c">src/gshtscr.c</a>,
  935. <a href="../src/gshtx.c">src/gshtx.c</a>,
  936. <a href="../src/gshtx.h">src/gshtx.h</a>,
  937. <a href="../src/gxcht.c">src/gxcht.c</a>,
  938. <a href="../src/gxdht.h">src/gxdht.h</a>,
  939. <a href="../src/gxdhtres.h">src/gxdhtres.h</a>,
  940. <a href="../src/gxht.c">src/gxht.c</a>,
  941. <a href="../src/gxht.h">src/gxht.h</a>,
  942. <a href="../src/gxhtbit.c">src/gxhtbit.c</a>,
  943. <a href="../src/gxhttile.h">src/gxhttile.h</a>,
  944. <a href="../src/gxhttype.h">src/gxhttype.h</a>,
  945. <a href="../src/gzht.h">src/gzht.h</a>.
  946. </dl>
  947. <p>
  948. Pattern colors (tiled patterns and shadings) each use a slightly different
  949. approach from solid colors.
  950. <p>
  951. The device color for a tiled (PatternType 1) pattern contains a pointer to a
  952. pattern instance, plus (for uncolored patterns) the device color to be
  953. masked. The pattern instance includes a procedure that actually paints the
  954. pattern if the pattern is not in the cache. For the PostScript interpreter,
  955. this procedure returns an <b><tt>e_RemapColor</tt></b> exception code: this
  956. eventually causes the interpreter to run the pattern's PaintProc, loading
  957. the rendering into the cache, and then re-execute the original drawing
  958. operator.
  959. <dl>
  960. <dt>
  961. Patterns:
  962. <dd>
  963. <a href="../src/gspcolor.c">src/gspcolor.c</a>,
  964. <a href="../src/gspcolor.h">src/gspcolor.h</a>,
  965. <a href="../src/gsptype1.c">src/gsptype1.c</a>,
  966. <a href="../src/gsptype1.h">src/gsptype1.h</a>,
  967. <a href="../src/gxp1fill.c">src/gxp1fill.c</a>,
  968. <a href="../src/gxp1impl.h">src/gxp1impl.h</a>,
  969. <a href="../src/gxpcache.h">src/gxpcache.h</a>,
  970. <a href="../src/gxpcmap.c">src/gxpcmap.c</a>,
  971. <a href="../src/gxpcolor.h">src/gxpcolor.h</a>.
  972. </dl>
  973. <p>
  974. The device color for a shading (PatternType 2) pattern also contains a
  975. pointer to a pattern instance. Shadings are not cached: painting with a
  976. shading runs the shading algorithm every time.
  977. <dl>
  978. <dt>
  979. Shading:
  980. <dd>
  981. <a href="../src/gsptype2.c">src/gsptype2.c</a>,
  982. <a href="../src/gsptype2.h">src/gsptype2.h</a>,
  983. <a href="../src/gsshade.c">src/gsshade.c</a>,
  984. <a href="../src/gsshade.h">src/gsshade.h</a>,
  985. <a href="../src/gxshade.c">src/gxshade.c</a>,
  986. <a href="../src/gxshade.h">src/gxshade.h</a>,
  987. <a href="../src/gxshade1.c">src/gxshade1.c</a>,
  988. <a href="../src/gxshade4.c">src/gxshade4.c</a>,
  989. <a href="../src/gxshade4.h">src/gxshade4.h</a>,
  990. <a href="../src/gxshade6.c">src/gxshade6.c</a>.
  991. </dl>
  992. <p>
  993. In addition to the PostScript graphics model, Ghostscript supports RasterOp,
  994. a weak form of alpha channel, and eventually the full PDF 1.4 transparency
  995. model. The implemention of these facilities is quite slipshod and
  996. scattered: only RasterOp is really implemented fully. There is a general
  997. compositing architecture, but it is hardly used at all, and in particular is
  998. not used for RasterOp. ****** TO BE COMPLETED ******
  999. <dl>
  1000. <dt>
  1001. Compositing architecture:
  1002. <dd>
  1003. <a href="../src/gscompt.h">src/gscompt.h</a>,
  1004. <a href="../src/gxcomp.h">src/gxcomp.h</a>.
  1005. <dt>
  1006. RasterOp:
  1007. <dd>
  1008. <a href="../src/gdevdrop.c">src/gdevdrop.c</a>,
  1009. <a href="../src/gdevrops.c">src/gdevrops.c</a>,
  1010. <a href="../src/gsnorop.c">src/gsnorop.c</a>,
  1011. <a href="../src/gsrop.c">src/gsrop.c</a>,
  1012. <a href="../src/gsrop.h">src/gsrop.h</a>,
  1013. <a href="../src/gsropc.c">src/gsropc.c</a>,
  1014. <a href="../src/gsropc.h">src/gsropc.h</a>,
  1015. <a href="../src/gsropt.h">src/gsropt.h</a>,
  1016. <a href="../src/gsroptab.c">src/gsroptab.c</a>,
  1017. <a href="../src/gxdevrop.h">src/gxdevrop.h</a>,
  1018. <a href="../src/gxropc.h">src/gxropc.h</a>.
  1019. <dt>
  1020. Alpha channel and compositing:
  1021. <dd>
  1022. <a href="../src/gsalpha.c">src/gsalpha.c</a>,
  1023. <a href="../src/gsalpha.h">src/gsalpha.h</a>,
  1024. <a href="../src/gsalphac.c">src/gsalphac.c</a>,
  1025. <a href="../src/gsalphac.h">src/gsalphac.h</a>,
  1026. <a href="../src/gsdpnext.h">src/gsdpnext.h</a>,
  1027. <a href="../src/gxalpha.h">src/gxalpha.h</a>.
  1028. <dt>
  1029. Advanced transparency:
  1030. <dd>
  1031. <a href="../src/gstparam.h">src/gstparam.h</a>,
  1032. <a href="../src/gstrans.c">src/gstrans.c</a>,
  1033. <a href="../src/gstrans.h">src/gstrans.h</a>,
  1034. <a href="../src/gxblend.c">src/gxblend.c</a>,
  1035. <a href="../src/gxblend.h">src/gxblend.h</a>,
  1036. <a href="../src/gdevp14.c">src/gdevp14.c</a>.
  1037. <a href="../src/gdevp14.h">src/gdevp14.h</a>.
  1038. <a href="../src/gdevpnga.c">src/gdevpnga.c</a>.
  1039. </dl>
  1040. <h4><a name="Clipping"></a>Clipping</h4>
  1041. <p>
  1042. The Ghostscript graphics library implements clipping by inserting a clipping
  1043. device in the device pipeline. The clipping device modifies all drawing
  1044. operations to confine them to the clipping region.
  1045. <p>
  1046. The library supports three different kinds of clipping:
  1047. <dl>
  1048. <dt>
  1049. Region/path clipping
  1050. <dd>
  1051. This corresponds to the PostScript concept of a clipping path. The clipping
  1052. region is specified either by a list of rectangles (subject to the
  1053. constraints documented in <a href="../src/gxcpath.h">src/gxcpath.h</a>), or
  1054. by a path that is converted to such a list of rectangles.
  1055. <dt>
  1056. Stationary mask clipping
  1057. <dd>
  1058. This corresponds to the mask operand of a PostScript ImageType 3 image. The
  1059. clipping region is specified by a bitmap and an (X,Y) offset in the
  1060. coordinate space.
  1061. <dt>
  1062. Tiled mask clipping
  1063. <dd>
  1064. This corresponds to the region painted by a PostScript Pattern, for the case
  1065. where the Pattern does not completely cover its bounding box but the
  1066. combined transformation matrix has no skew or non-orthogonal rotation (i.e.,
  1067. XStep and YStep map respectively to (X,0) and (0,Y) or vice versa). The
  1068. clipping region is specified by a bitmap and an (X,Y) offset in the
  1069. coordinate space, and is replicated indefinitely in both X and Y.
  1070. </dl>
  1071. <p>
  1072. Note that simply scan-converting a clipping path in the usual way does not
  1073. produce a succession of rectangles that can simply be stored as the list for
  1074. region-based clipping: in general, the rectangles do not satisfy the
  1075. constraint for rectangle lists specified in <a
  1076. href="../src/gxcpath.h">src/gxcpath.h</a>, since they may overlap in X, Y,
  1077. or both. A non-trivial "clipping list accumulator" device is needed to
  1078. produce a rectangle list that does satisfy the constraint.
  1079. <dl>
  1080. <dt>
  1081. Clipping support:
  1082. <dd>
  1083. <a href="../src/gxclip.c">src/gxclip.c</a>,
  1084. <a href="../src/gxclip.h">src/gxclip.h</a>.
  1085. <dt>
  1086. Region/path clipping:
  1087. <dd>
  1088. <a href="../src/gxcpath.c">src/gxcpath.c</a>,
  1089. <a href="../src/gxcpath.h">src/gxcpath.h</a>,
  1090. <a href="../src/gzcpath.h">src/gzcpath.h</a>.
  1091. <dt>
  1092. Clipping list accumulator:
  1093. <dd>
  1094. <a href="../src/gxacpath.c">src/gxacpath.c</a>,
  1095. <a href="../src/gzacpath.h">src/gzacpath.h</a>.
  1096. <dt>
  1097. Mask clipping support:
  1098. <dd>
  1099. <a href="../src/gxmclip.c">src/gxmclip.c</a>,
  1100. <a href="../src/gxmclip.h">src/gxmclip.h</a>.
  1101. <dt>
  1102. Stationary mask clipping:
  1103. <dd>
  1104. <a href="../src/gxclipm.c">src/gxclipm.c</a>,
  1105. <a href="../src/gxclipm.h">src/gxclipm.h</a>.
  1106. <dt>
  1107. Tiled mask clipping:
  1108. <dd>
  1109. <a href="../src/gxclip2.c">src/gxclip2.c</a>,
  1110. <a href="../src/gxclip2.h">src/gxclip2.h</a>.
  1111. </dl>
  1112. <h4><a name="Other_graphics"></a>Other graphics</h4>
  1113. <dl>
  1114. <dt>
  1115. Miscellaneous graphics state:
  1116. <dd>
  1117. <a href="../src/gsclipsr.c">src/gsclipsr.c</a>,
  1118. <a href="../src/gsclipsr.h">src/gsclipsr.h</a>,
  1119. <a href="../src/gsdps.c">src/gsdps.c</a>,
  1120. <a href="../src/gsdps.h">src/gsdps.h</a>,
  1121. <a href="../src/gsdps1.c">src/gsdps1.c</a>,
  1122. <a href="../src/gsistate.c">src/gsistate.c</a>,
  1123. <a href="../src/gsline.c">src/gsline.c</a>,
  1124. <a href="../src/gsline.h">src/gsline.h</a>,
  1125. <a href="../src/gslparam.h">src/gslparam.h</a>,
  1126. <a href="../src/gsstate.c">src/gsstate.c</a>,
  1127. <a href="../src/gsstate.h">src/gsstate.h</a>,
  1128. <a href="../src/gstrap.c">src/gstrap.c</a>,
  1129. <a href="../src/gstrap.h">src/gstrap.h</a>,
  1130. <a href="../src/gxclipsr.h">src/gxclipsr.h</a>,
  1131. <a href="../src/gxistate.h">src/gxistate.h</a>,
  1132. <a href="../src/gxline.h">src/gxline.h</a>,
  1133. <a href="../src/gxstate.h">src/gxstate.h</a>,
  1134. <a href="../src/gzline.h">src/gzline.h</a>,
  1135. <a href="../src/gzstate.h">src/gzstate.h</a>.
  1136. </dl>
  1137. <h4><a name="Driver_support"></a>Driver support</h4>
  1138. <dl>
  1139. <dt>
  1140. Generic driver support:
  1141. <dd>
  1142. <a href="../src/gdevdcrd.c">src/gdevdcrd.c</a>,
  1143. <a href="../src/gdevdcrd.h">src/gdevdcrd.h</a>,
  1144. <a href="../src/gdevemap.c">src/gdevemap.c</a>,
  1145. <a href="../src/gsdevice.c">src/gsdevice.c</a>,
  1146. <a href="../src/gsdevice.h">src/gsdevice.h</a>,
  1147. <a href="../src/gsdparam.c">src/gsdparam.c</a>,
  1148. <a href="../src/gsxfont.h">src/gsxfont.h</a>,
  1149. <a href="../src/gxdevbuf.h">src/gxdevbuf.h</a>,
  1150. <a href="../src/gxdevcli.h">src/gxdevcli.h</a>,
  1151. <a href="../src/gxdevice.h">src/gxdevice.h</a>,
  1152. <a href="../src/gxrplane.h">src/gxrplane.h</a>,
  1153. <a href="../src/gxxfont.h">src/gxxfont.h</a>.
  1154. <dt>
  1155. Accessing rendered bits:
  1156. <dd>
  1157. <a href="../src/gdevdbit.c">src/gdevdbit.c</a>,
  1158. <a href="../src/gdevdgbr.c">src/gdevdgbr.c</a>,
  1159. <a href="../src/gxbitfmt.h">src/gxbitfmt.h</a>,
  1160. <a href="../src/gxgetbit.h">src/gxgetbit.h</a>.
  1161. <dt>
  1162. "Printer" driver support:
  1163. <dd>
  1164. <a href="../src/gdevmeds.c">src/gdevmeds.c</a>,
  1165. <a href="../src/gdevmeds.h">src/gdevmeds.h</a>,
  1166. <a href="../src/gdevppla.c">src/gdevppla.c</a>,
  1167. <a href="../src/gdevppla.h">src/gdevppla.h</a>,
  1168. <a href="../src/gdevprn.c">src/gdevprn.c</a>,
  1169. <a href="../src/gdevprn.h">src/gdevprn.h</a>,
  1170. <a href="../src/gdevprna.c">src/gdevprna.c</a>,
  1171. <a href="../src/gdevprna.h">src/gdevprna.h</a>,
  1172. <a href="../src/gxband.h">src/gxband.h</a>,
  1173. <a href="../src/gxpageq.c">src/gxpageq.c</a>,
  1174. <a href="../src/gxpageq.h">src/gxpageq.h</a>.
  1175. <dt>
  1176. High-level device support:
  1177. <dd>
  1178. <a href="../src/gdevvec.c">src/gdevvec.c</a>,
  1179. <a href="../src/gdevvec.h">src/gdevvec.h</a>.
  1180. <dt>
  1181. Banding:
  1182. <dd>
  1183. <a href="../src/gxclbits.c">src/gxclbits.c</a>,
  1184. <a href="../src/gxcldev.h">src/gxcldev.h</a>,
  1185. <a href="../src/gxclfile.c">src/gxclfile.c</a>,
  1186. <a href="../src/gxclimag.c">src/gxclimag.c</a>,
  1187. <a href="../src/gxclio.h">src/gxclio.h</a>,
  1188. <a href="../src/gxclist.c">src/gxclist.c</a>,
  1189. <a href="../src/gxclist.h">src/gxclist.h</a>,
  1190. <a href="../src/gxcllzw.c">src/gxcllzw.c</a>,
  1191. <a href="../src/gxclmem.c">src/gxclmem.c</a>,
  1192. <a href="../src/gxclmem.h">src/gxclmem.h</a>,
  1193. <a href="../src/gxclpage.c">src/gxclpage.c</a>,
  1194. <a href="../src/gxclpage.h">src/gxclpage.h</a>,
  1195. <a href="../src/gxclpath.c">src/gxclpath.c</a>,
  1196. <a href="../src/gxclpath.h">src/gxclpath.h</a>,
  1197. <a href="../src/gxclrast.c">src/gxclrast.c</a>,
  1198. <a href="../src/gxclread.c">src/gxclread.c</a>,
  1199. <a href="../src/gxclrect.c">src/gxclrect.c</a>,
  1200. <a href="../src/gxclutil.c">src/gxclutil.c</a>,
  1201. <a href="../src/gxclzlib.c">src/gxclzlib.c</a>.
  1202. </dl>
  1203. <h3><a name="Device_drivers"></a>Device drivers</h3>
  1204. <p>
  1205. See <a href="Drivers.htm">doc/Drivers.htm</a> for extensive documentation on
  1206. the interface between the core code and drivers.
  1207. <p>
  1208. The driver API includes high-level (path / image / text), mid-level
  1209. (polygon), and low-level (rectangle / raster) operations. Most devices
  1210. implement only the low-level operations, and let generic code break down the
  1211. high-level operations. However, some devices produce high-level output, and
  1212. therefore must implement the high-level operations.
  1213. <h4><a name="Internal_devices"></a>Internal devices</h4>
  1214. <p>
  1215. There are a number of "devices" that serve internal purposes. Some of these
  1216. are meant to be real rendering targets; others are intended for use in
  1217. device pipelines. The rendering targets are:
  1218. <dl>
  1219. <dt>
  1220. Memory devices, depth-independent:
  1221. <dd>
  1222. <a href="../src/gdevmem.c">src/gdevmem.c</a>,
  1223. <a href="../src/gdevmem.h">src/gdevmem.h</a>,
  1224. <a href="../src/gdevmpla.c">src/gdevmpla.c</a>,
  1225. <a href="../src/gdevmpla.h">src/gdevmpla.h</a>,
  1226. <a href="../src/gdevmrop.h">src/gdevmrop.h</a>,
  1227. <a href="../src/gsdevmem.c">src/gsdevmem.c</a>,
  1228. <a href="../src/gxdevmem.h">src/gxdevmem.h</a>.
  1229. <dt>
  1230. Memory devices, specific depths:
  1231. <dd>
  1232. <a href="../src/gdevm1.c">src/gdevm1.c</a>,
  1233. <a href="../src/gdevm2.c">src/gdevm2.c</a>,
  1234. <a href="../src/gdevm4.c">src/gdevm4.c</a>,
  1235. <a href="../src/gdevm8.c">src/gdevm8.c</a>,
  1236. <a href="../src/gdevm16.c">src/gdevm16.c</a>,
  1237. <a href="../src/gdevm24.c">src/gdevm24.c</a>,
  1238. <a href="../src/gdevm32.c">src/gdevm32.c</a>,
  1239. <a href="../src/gdevmr1.c">src/gdevmr1.c</a>,
  1240. <a href="../src/gdevmr2n.c">src/gdevmr2n.c</a>,
  1241. <a href="../src/gdevmr8n.c">src/gdevmr8n.c</a>.
  1242. <dt>
  1243. Alpha-related devices:
  1244. <dd>
  1245. <a href="../src/gdevabuf.c">src/gdevabuf.c</a>,
  1246. <a href="../src/gdevalph.c">src/gdevalph.c</a>.
  1247. <dt>
  1248. Other devices:
  1249. <dd>
  1250. <a href="../src/gdevdflt.c">src/gdevdflt.c</a>,
  1251. <a href="../src/gdevhit.c">src/gdevhit.c</a>,
  1252. <a href="../src/gdevht.c">src/gdevht.c</a>,
  1253. <a href="../src/gdevht.h">src/gdevht.h</a>,
  1254. <a href="../src/gdevmrun.c">src/gdevmrun.c</a>,
  1255. <a href="../src/gdevmrun.h">src/gdevmrun.h</a>,
  1256. <a href="../src/gdevplnx.c">src/gdevplnx.c</a>,
  1257. <a href="../src/gdevplnx.h">src/gdevplnx.h</a>,
  1258. </dl>
  1259. <p>
  1260. The forwarding devices meant for use in pipelines are:
  1261. <dl>
  1262. <dt>
  1263. The bounding box device:
  1264. <dd>
  1265. <a href="../src/gdevbbox.h">src/gdevbbox.h</a>,
  1266. <a href="../src/gdevbbox.c">src/gdevbbox.c</a>.
  1267. <dt>
  1268. Clipping devices:
  1269. <dd>
  1270. See under <a href="#Clipping">Clipping</a> above.
  1271. <dt>
  1272. Device filter stack:
  1273. <dd>
  1274. <a href="../src/gsdfilt.c">src/gsdfilt.c</a>,
  1275. <a href="../src/gsdfilt.h">src/gsdfilt.h</a>,
  1276. <dt>
  1277. Other devices:
  1278. <dd>
  1279. <a href="../src/gdevcmap.c">src/gdevcmap.c</a>,
  1280. <a href="../src/gdevcmap.h">src/gdevcmap.h</a>,
  1281. <a href="../src/gdevnfwd.c">src/gdevnfwd.c</a>.
  1282. </dl>
  1283. <h4><a name="PS_and_PDF_writers"></a>PostScript and PDF writers</h4>
  1284. <p>
  1285. Because PostScript and PDF have the same graphics model, lexical syntax, and
  1286. stack-based execution model, the drivers that produce PostScript and PDF
  1287. output share a significant amount of support code. In the future, the
  1288. PostScript output driver should be replaced with a slightly modified version
  1289. of the PDF driver, since the latter is far more sophisticated (in
  1290. particular, it has extensive facilities for image compression and for
  1291. handling text and fonts).
  1292. <dl>
  1293. <dt>
  1294. Shared support:
  1295. <dd>
  1296. <dl>
  1297. Writing fonts:
  1298. <dd>
  1299. <a href="../src/gdevpsf.h">src/gdevpsf.h</a>,
  1300. <a href="../src/gdevpsf1.c">src/gdevpsf1.c</a>,
  1301. <a href="../src/gdevpsf2.c">src/gdevpsf2.c</a>,
  1302. <a href="../src/gdevpsfm.c">src/gdevpsfm.c</a>,
  1303. <a href="../src/gdevpsft.c">src/gdevpsft.c</a>,
  1304. <a href="../src/gdevpsfu.c">src/gdevpsfu.c</a>,
  1305. <a href="../src/gdevpsfx.c">src/gdevpsfx.c</a>.
  1306. <dt>
  1307. Other:
  1308. <dd>
  1309. <a href="../src/gdevpsdf.h">src/gdevpsdf.h</a>,
  1310. <a href="../src/gdevpsdi.c">src/gdevpsdi.c</a>,
  1311. <a href="../src/gdevpsdp.c">src/gdevpsdp.c</a>,
  1312. <a href="../src/gdevpsds.c">src/gdevpsds.c</a>,
  1313. <a href="../src/gdevpsds.h">src/gdevpsds.h</a>,
  1314. <a href="../src/gdevpsdu.c">src/gdevpsdu.c</a>.
  1315. </dl>
  1316. <dt>
  1317. PostScript output driver ([e]pswrite):
  1318. <dd>
  1319. <a href="../src/gdevps.c">src/gdevps.c</a>,
  1320. <a href="../src/gdevpsu.c">src/gdevpsu.c</a>,
  1321. <a href="../src/gdevpsu.h">src/gdevpsu.h</a>.
  1322. <dt>
  1323. PDF output driver (pdfwrite):
  1324. <dd>
  1325. <dl>
  1326. <dt>
  1327. Substrate:
  1328. <dd>
  1329. <a href="../src/gdevpdfo.c">src/gdevpdfo.c</a>,
  1330. <a href="../src/gdevpdfo.h">src/gdevpdfo.h</a>,
  1331. <a href="../src/gdevpdfr.c">src/gdevpdfr.c</a>,
  1332. <a href="../src/gdevpdfu.c">src/gdevpdfu.c</a>.
  1333. <dt>
  1334. Text and fonts:
  1335. <dd>
  1336. <a href="../src/gdevpdfe.c">src/gdevpdfe.c</a>,
  1337. <a href="../src/gdevpdff.c">src/gdevpdff.c</a>,
  1338. <a href="../src/gdevpdff.h">src/gdevpdff.h</a>,
  1339. <a href="../src/gdevpdfs.c">src/gdevpdfs.c</a>,
  1340. <a href="../src/gdevpdft.c">src/gdevpdft.c</a>,
  1341. <a href="../src/gdevpdfw.c">src/gdevpdfw.c</a>.
  1342. <dt>
  1343. Graphics:
  1344. <dd>
  1345. <a href="../src/gdevpdfc.c">src/gdevpdfc.c</a>,
  1346. <a href="../src/gdevpdfd.c">src/gdevpdfd.c</a>,
  1347. <a href="../src/gdevpdfg.c">src/gdevpdfg.c</a>,
  1348. <a href="../src/gdevpdfg.h">src/gdevpdfg.h</a>,
  1349. <a href="../src/gdevpdfv.c">src/gdevpdfv.c</a>.
  1350. <dt>
  1351. Images:
  1352. <dd>
  1353. <a href="../src/gdevpdfb.c">src/gdevpdfb.c</a>,
  1354. <a href="../src/gdevpdfi.c">src/gdevpdfi.c</a>,
  1355. <a href="../src/gdevpdfj.c">src/gdevpdfj.c</a>.
  1356. <dt>
  1357. Other:
  1358. <dd>
  1359. <a href="../src/gdevpdf.c">src/gdevpdf.c</a>,
  1360. <a href="../src/gdevpdfm.c">src/gdevpdfm.c</a>,
  1361. <a href="../src/gdevpdfp.c">src/gdevpdfp.c</a>,
  1362. <a href="../src/gdevpdfx.h">src/gdevpdfx.h</a>.
  1363. </dl>
  1364. </dl>
  1365. <h4><a name="High_level_devices"></a>Other high-level devices</h4>
  1366. <p>
  1367. Currently, the CGM driver is raster-only. If anyone cares seriously about
  1368. CGM in the future, this driver should be upgraded to a higher level.
  1369. <dl>
  1370. <dt>
  1371. PCL XL output device (pxlmono, pxlcolor):
  1372. <dd>
  1373. <a href="../src/gdevpx.c">src/gdevpx.c</a>,
  1374. <a href="../src/gdevpxat.h">src/gdevpxat.h</a>,
  1375. <a href="../src/gdevpxen.h">src/gdevpxen.h</a>,
  1376. <a href="../src/gdevpxop.h">src/gdevpxop.h</a>,
  1377. <a href="../src/gdevpxut.c">src/gdevpxut.c</a>,
  1378. <a href="../src/gdevpxut.h">src/gdevpxut.h</a>.
  1379. <dt>
  1380. Other high-level devices:
  1381. <dd>
  1382. <a href="../src/gdevtrac.c">src/gdevtrac.c</a>.
  1383. </dl>
  1384. <h4><a name="Other_maintained_drivers"></a>Other maintained drivers</h4>
  1385. <p>
  1386. The standard Ghostscript distribution includes a collection of drivers,
  1387. mostly written by Aladdin Enterprises, that are "maintained" in the same
  1388. sense as the Ghostscript core code.
  1389. <dl>
  1390. <dt>
  1391. Display drivers:
  1392. <dd>
  1393. <a href="../src/gdev8bcm.c">src/gdev8bcm.c</a>,
  1394. <a href="../src/gdev8bcm.h">src/gdev8bcm.h</a>,
  1395. <a href="../src/gdevegaa.asm">src/gdevegaa.asm</a>,
  1396. <a href="../src/gdevevga.c">src/gdevevga.c</a>,
  1397. <a href="../src/gdevl256.c">src/gdevl256.c</a>,
  1398. <a href="../src/gdevpccm.c">src/gdevpccm.c</a>,
  1399. <a href="../src/gdevpccm.h">src/gdevpccm.h</a>,
  1400. <a href="../src/gdevpcfb.c">src/gdevpcfb.c</a>,
  1401. <a href="../src/gdevpcfb.h">src/gdevpcfb.h</a>,
  1402. <a href="../src/gdevs3ga.c">src/gdevs3ga.c</a>,
  1403. <a href="../src/gdevsco.c">src/gdevsco.c</a>,
  1404. <a href="../src/gdevsvga.c">src/gdevsvga.c</a>,
  1405. <a href="../src/gdevsvga.h">src/gdevsvga.h</a>,
  1406. <a href="../src/gdevvglb.c">src/gdevvglb.c</a>.
  1407. <dt>
  1408. Window system drivers:
  1409. <dd>
  1410. <dl>
  1411. <dt>
  1412. X Windows:
  1413. <dd>
  1414. <a href="../src/gdevx.c">src/gdevx.c</a>,
  1415. <a href="../src/gdevx.h">src/gdevx.h</a>,
  1416. <a href="../src/gdevxalt.c">src/gdevxalt.c</a>,
  1417. <a href="../src/gdevxcmp.c">src/gdevxcmp.c</a>,
  1418. <a href="../src/gdevxcmp.h">src/gdevxcmp.h</a>,
  1419. <a href="../src/gdevxini.c">src/gdevxini.c</a>,
  1420. <a href="../src/gdevxres.c">src/gdevxres.c</a>,
  1421. <a href="../src/gdevxxf.c">src/gdevxxf.c</a>.
  1422. <dt>
  1423. Microsoft Windows:
  1424. <dd>
  1425. <a href="../src/gdevmswn.c">src/gdevmswn.c</a>,
  1426. <a href="../src/gdevmswn.h">src/gdevmswn.h</a>,
  1427. <a href="../src/gdevmsxf.c">src/gdevmsxf.c</a>,
  1428. <a href="../src/gdevwddb.c">src/gdevwddb.c</a>,
  1429. <a href="../src/gdevwdib.c">src/gdevwdib.c</a>.
  1430. <dt>
  1431. OS/2 Presentation Manager:
  1432. <dd>
  1433. <a href="../src/gdevpm.c">src/gdevpm.c</a>,
  1434. <a href="../src/gdevpm.h">src/gdevpm.h</a>,
  1435. <a href="../src/gspmdrv.c">src/gspmdrv.c</a>,
  1436. <a href="../src/gspmdrv.h">src/gspmdrv.h</a>.
  1437. </dl>
  1438. <dt>
  1439. Raster file output drivers:
  1440. <dd>
  1441. <dl>
  1442. <dt>
  1443. Fax and TIFF:
  1444. <dd>
  1445. <a href="../src/gdevfax.c">src/gdevfax.c</a>,
  1446. <a href="../src/gdevfax.h">src/gdevfax.h</a>,
  1447. <a href="../src/gdevtfax.c">src/gdevtfax.c</a>,
  1448. <a href="../src/gdevtfax.h">src/gdevtfax.h</a>,
  1449. <a href="../src/gdevtifs.c">src/gdevtifs.c</a>,
  1450. <a href="../src/gdevtifs.h">src/gdevtifs.h</a>,
  1451. <a href="../src/gdevtfnx.c">src/gdevtfnx.c</a>.
  1452. <dt>
  1453. (Low-level) CGM:
  1454. <dd>
  1455. <a href="../src/gdevcgm.c">src/gdevcgm.c</a>,
  1456. <a href="../src/gdevcgml.c">src/gdevcgml.c</a>,
  1457. <a href="../src/gdevcgml.h">src/gdevcgml.h</a>,
  1458. <a href="../src/gdevcgmx.h">src/gdevcgmx.h</a>.
  1459. <dt>
  1460. Other raster file formats:
  1461. <dd>
  1462. <a href="../src/gdevbit.c">src/gdevbit.c</a>,
  1463. <a href="../src/gdevbmp.c">src/gdevbmp.c</a>,
  1464. <a href="../src/gdevbmp.h">src/gdevbmp.h</a>,
  1465. <a href="../src/gdevbmpa.c">src/gdevbmpa.c</a>,
  1466. <a href="../src/gdevbmpc.c">src/gdevbmpc.c</a>,
  1467. <a href="../src/gdevjpeg.c">src/gdevjpeg.c</a>,
  1468. <a href="../src/gdevmiff.c">src/gdevmiff.c</a>,
  1469. <a href="../src/gdevp2up.c">src/gdevp2up.c</a>,
  1470. <a href="../src/gdevpcx.c">src/gdevpcx.c</a>,
  1471. <a href="../src/gdevpbm.c">src/gdevpbm.c</a>,
  1472. <a href="../src/gdevpng.c">src/gdevpng.c</a>,
  1473. <a href="../src/gdevpsim.c">src/gdevpsim.c</a>.
  1474. </dl>
  1475. <dt>
  1476. Printer drivers:
  1477. <dd>
  1478. <dl>
  1479. <dt>
  1480. Operating system printer services:
  1481. <dd>
  1482. <a href="../src/gdevos2p.c">src/gdevos2p.c</a>,
  1483. <a href="../src/gdevwpr2.c">src/gdevwpr2.c</a>,
  1484. <a href="../src/gdevwprn.c">src/gdevwprn.c</a>.
  1485. <dt>
  1486. H-P monochrome printers:
  1487. <dd>
  1488. <a href="../src/gdevdljm.c">src/gdevdljm.c</a>,
  1489. <a href="../src/gdevdljm.h">src/gdevdljm.h</a>,
  1490. <a href="../src/gdevdjet.c">src/gdevdjet.c</a>,
  1491. <a href="../src/gdevlj56.c">src/gdevlj56.c</a>.
  1492. <dt>
  1493. Other printers:
  1494. <dd>
  1495. <a href="../src/gdevatx.c">src/gdevatx.c</a>.
  1496. </dl>
  1497. </dl>
  1498. <h4><a name="Contributed_drivers"></a>Contributed drivers</h4>
  1499. <p>
  1500. This list is likely to be incomplete and inaccurate: see <a
  1501. href="../src/contrib.mak">src/contrib.mak</a> for the real one.
  1502. <dl>
  1503. <dt>
  1504. Display and window system drivers:
  1505. <dd>
  1506. <a href="../src/gdev3b1.c">src/gdev3b1.c</a>,
  1507. <a href="../src/gdevherc.c">src/gdevherc.c</a>,
  1508. <a href="../src/gdevpe.c">src/gdevpe.c</a>,
  1509. <a href="../src/gdevsnfb.c">src/gdevsnfb.c</a>,
  1510. <a href="../src/gdevsun.c">src/gdevsun.c</a>.
  1511. <dt>
  1512. Raster file output drivers:
  1513. <dd>
  1514. <a href="../src/gdevcfax.c">src/gdevcfax.c</a>,
  1515. <a href="../src/gdevcif.c">src/gdevcif.c</a>,
  1516. <a href="../src/gdevdfax.c">src/gdevdfax.c</a>,
  1517. <a href="../src/gdevifno.c">src/gdevifno.c</a>,
  1518. <a href="../src/gdevmgr.c">src/gdevmgr.c</a>,
  1519. <a href="../src/gdevmgr.h">src/gdevmgr.h</a>,
  1520. <a href="../src/gdevsgi.c">src/gdevsgi.c</a>,
  1521. <a href="../src/gdevsgi.h">src/gdevsgi.h</a>,
  1522. <a href="../src/gdevsunr.c">src/gdevsunr.c</a>.
  1523. <dt>
  1524. Printer drivers:
  1525. <dd>
  1526. <a href="../lib/bj8.rpd">lib/bj8.rpd</a>,
  1527. <a href="../lib/cbjc600.ppd">lib/cbjc600.ppd</a>,
  1528. <a href="../lib/cbjc800.ppd">lib/cbjc800.ppd</a>,
  1529. <a href="../src/gdev3852.c">src/gdev3852.c</a>,
  1530. <a href="../src/gdev4081.c">src/gdev4081.c</a>,
  1531. <a href="../src/gdev4693.c">src/gdev4693.c</a>,
  1532. <a href="../src/gdev8510.c">src/gdev8510.c</a>,
  1533. <a href="../src/gdevadmp.c">src/gdevadmp.c</a>,
  1534. <a href="../src/gdevbj10.c">src/gdevbj10.c</a>,
  1535. <a href="../src/gdevbjc.h">src/gdevbjc.h</a>,
  1536. <a href="../src/gdevbjcl.c">src/gdevbjcl.c</a>,
  1537. <a href="../src/gdevbjcl.h">src/gdevbjcl.h</a>,
  1538. <a href="../src/gdevccr.c">src/gdevccr.c</a>,
  1539. <a href="../src/gdevcdj.c">src/gdevcdj.c</a>,
  1540. <a href="../src/gdevclj.c">src/gdevclj.c</a>,
  1541. <a href="../src/gdevcljc.c">src/gdevcljc.c</a>,
  1542. <a href="../src/gdevcp50.c">src/gdevcp50.c</a>,
  1543. <a href="../src/gdevcslw.c">src/gdevcslw.c</a>,
  1544. <a href="../src/gdevdjtc.c">src/gdevdjtc.c</a>,
  1545. <a href="../src/gdevdm24.c">src/gdevdm24.c</a>,
  1546. <a href="../src/gdevepsc.c">src/gdevepsc.c</a>,
  1547. <a href="../src/gdevepsn.c">src/gdevepsn.c</a>,
  1548. <a href="../src/gdevescp.c">src/gdevescp.c</a>,
  1549. <a href="../src/gdevhl7x.c">src/gdevhl7x.c</a>,
  1550. <a href="../src/gdevhpij.c">src/gdevhpij.c</a>,
  1551. <a href="../src/gdevhpij.h">src/gdevhpij.h</a>,
  1552. <a href="../src/gdevijs.c">src/gdevijs.c</a>,
  1553. <a href="../src/gdevimgn.c">src/gdevimgn.c</a>,
  1554. <a href="../src/gdevl31s.c">src/gdevl31s.c</a>,
  1555. <a href="../src/gdevlbp8.c">src/gdevlbp8.c</a>,
  1556. <a href="../src/gdevlp8k.c">src/gdevlp8k.c</a>,
  1557. <a href="../src/gdevlxm.c">src/gdevlxm.c</a>,
  1558. <a href="../src/gdevn533.c">src/gdevn533.c</a>,
  1559. <a href="../src/gdevo182.c">src/gdevo182.c</a>,
  1560. <a href="../src/gdevokii.c">src/gdevokii.c</a>,
  1561. <a href="../src/gdevpcl.c">src/gdevpcl.c</a>,
  1562. <a href="../src/gdevpcl.h">src/gdevpcl.h</a>,
  1563. <a href="../src/gdevphex.c">src/gdevphex.c</a>,
  1564. <a href="../src/gdevpjet.c">src/gdevpjet.c</a>,
  1565. <a href="../src/gdevsj48.c">src/gdevsj48.c</a>,
  1566. <a href="../src/gdevsppr.c">src/gdevsppr.c</a>,
  1567. <a href="../src/gdevstc.c">src/gdevstc.c</a>,
  1568. <a href="../src/gdevstc.h">src/gdevstc.h</a>,
  1569. <a href="../src/gdevstc1.c">src/gdevstc1.c</a>,
  1570. <a href="../src/gdevstc2.c">src/gdevstc2.c</a>,
  1571. <a href="../src/gdevstc3.c">src/gdevstc3.c</a>,
  1572. <a href="../src/gdevstc4.c">src/gdevstc4.c</a>,
  1573. <a href="../src/gdevtknk.c">src/gdevtknk.c</a>,
  1574. <a href="../src/gdevupd.c">src/gdevupd.c</a>.
  1575. </dl>
  1576. <h3><a name="PostScript_interpreter"></a>PostScript interpreter</h3>
  1577. <p>
  1578. The PostScript interpreter is conceptually simple: in fact, an interpreter
  1579. that could execute "3 4 add =" and print "7" was running 3 weeks after the
  1580. first line of Ghostscript code was written. However, a number of
  1581. considerations make the code large and complex.
  1582. <p>
  1583. The interpreter is designed to run in environments with very limited memory.
  1584. The main consequence of this is that it cannot allocate its stacks
  1585. (dictionary, execution, operand) as ordinary arrays, since the
  1586. user-specified stack size limit may be very large. Instead, it allocates
  1587. them as a linked list of blocks. See below for more details.
  1588. <p>
  1589. The interpreter must never cause a C runtime error that it cannot trap.
  1590. Unfortunately, C implementations almost never provide the ability to trap
  1591. stack overflow. In order to put a fixed bound on the C stack size, the
  1592. interpreter never implements PostScript recursion by C recursion. This
  1593. means that any C code that logically needs to call the interpreter must
  1594. instead push a continuation (including all necessary state information) on
  1595. the PostScript execution stack, followed by the PostScript object to be
  1596. executed, and then <em>return</em> to the interpreter. Unfortunately, since
  1597. PostScript Level 2 introduces streams whose data source can be a PostScript
  1598. procedure, any code that reads or writes stream data must be prepared to
  1599. suspend itself, storing all necessary state in a continuation. There are
  1600. some places where this is extremely awkward, such as the scanner/parser.
  1601. <p>
  1602. The use of continuations affects many places in the interpreter, and even
  1603. some places in the graphics library. For example, when processing an image,
  1604. one may need to call a PostScript procedure as part of mapping a CIE color
  1605. to a device color. Ghostscript uses a variety of dodges to handle this: for
  1606. example, in the case of CIE color mapping, all of the PostScript procedures
  1607. are pre-sampled and the results cached. The Adobe implementation limits
  1608. this kind of recursion to a fixed number of levels (5?): this would be
  1609. another acceptable approach, but at this point it would require far more
  1610. code restructuring than it would be worth.
  1611. <p>
  1612. A significant amount of the PostScript language implementation is in fact
  1613. written in PostScript. Writing in PostScript leverages the C code for
  1614. multi-threading, garbage collection, error handling, continuations for
  1615. streams, etc., etc.; also, we have found PostScript in general more concise
  1616. and easier to debug than C, mostly because of memory management issues. So
  1617. given the choice, we tended to implement a feature in PostScript if it
  1618. worked primarily with PostScript data structures, wasn't heavily used
  1619. (example: font loading), or if it interacted with the stream or other
  1620. callback machinery (examples: ReusableFileDecode streams, resourceforall).
  1621. Often we would add non-standard PostScript operators for functions that had
  1622. to run faster or that did more C-like things, such as the media matching
  1623. algorithm for setpagedevice.
  1624. </ul>
  1625. <h4><a name="Main_program"></a>Main program</h4>
  1626. <p>
  1627. The main program of the interpreter is normally invoked from the command
  1628. line, but it has an API as well. In fact, it has two APIs: one that
  1629. recognizes the existence of multiple "interpreter instances" (although it
  1630. currently provides a default instance, which almost all clients use), and a
  1631. completely different one designed for Windows DLLs. These should be unified
  1632. as soon as possible, since there are two steadily growing incompatible
  1633. bodies of client code.
  1634. <dl>
  1635. <dt>
  1636. Files:
  1637. <dd>
  1638. <a href="../src/gs.c">src/gs.c</a>,
  1639. <a href="../src/gserver.c">src/gserver.c</a>,
  1640. <a href="../src/iccinit0.c">src/iccinit0.c</a>,
  1641. <a href="../src/iinit.c">src/iinit.c</a>,
  1642. <a href="../src/iinit.h">src/iinit.h</a>,
  1643. <a href="../src/imain.c">src/imain.c</a>,
  1644. <a href="../src/imain.h">src/imain.h</a>,
  1645. <a href="../src/imainarg.c">src/imainarg.c</a>,
  1646. <a href="../src/imainarg.h">src/imainarg.h</a>,
  1647. <a href="../src/iminst.h">src/iminst.h</a>,
  1648. <a href="../src/main.h">src/main.h</a>.
  1649. </dl>
  1650. <h4><a name="Data_structures"></a>Data structures</h4>
  1651. <p>
  1652. The main data structures visible to the PostScript programmers are arrays,
  1653. contexts, dictionaries, names, and stacks.
  1654. <p>
  1655. Arrays have no unusual properties. See under <a href="#Refs">Refs</a> below
  1656. for more information about how array elements are stored.
  1657. <p>
  1658. Contexts are used to hold the interpreter state even in configurations that
  1659. don't include the Display PostScript multiple context extension. Context
  1660. switching is implemented by a complex cooperation of C and PostScript code.
  1661. <p>
  1662. Dictionaries have two special properties worth noting:
  1663. <ul>
  1664. <li>They use an optimized storage representation if all the keys are names,
  1665. which is almost always the case.
  1666. <li>They interact with a caching scheme used to accelerate name lookup in
  1667. the interpreter.
  1668. </ul>
  1669. <p>
  1670. Names are allocated in blocks. The characters and hash chains are stored
  1671. separately from the lookup cache information, so that in the future, most of
  1672. the former can be compiled into the executable and shared or put in ROM.
  1673. (This is not actually done yet.)
  1674. <p>
  1675. As mentioned above, each stack is allocated as a linked list of blocks.
  1676. However, for reasonable performance, operators must normally be able to
  1677. access their operands and produce their results using indexing rather than
  1678. an access procedure. This is implemented by ensuring that all the operands
  1679. of an operator are in the topmost block of the stack, using guard entries
  1680. that cause an internal error if the condition isn't met. See <a
  1681. href="../src/iostack.h">src/iostack.h</a> for more details.
  1682. <dl>
  1683. <dt>
  1684. General data structures:
  1685. <dd>
  1686. <dl>
  1687. <dt>
  1688. Contexts:
  1689. <dd>
  1690. <a href="../src/icontext.c">src/icontext.c</a>,
  1691. <a href="../src/icontext.h">src/icontext.h</a>,
  1692. <a href="../src/icstate.h">src/icstate.h</a>.
  1693. <dt>
  1694. Dictionaries:
  1695. <dd>
  1696. <a href="../src/iddict.h">src/iddict.h</a>,
  1697. <a href="../src/idict.h">src/idict.h</a>,
  1698. <a href="../src/idict.c">src/idict.c</a>,
  1699. <a href="../src/idictdef.h">src/idictdef.h</a>.
  1700. <dt>
  1701. Names:
  1702. <dd>
  1703. <a href="../src/iname.c">src/iname.c</a>,
  1704. <a href="../src/iname.h">src/iname.h</a>,
  1705. <a href="../src/inamedef.h">src/inamedef.h</a>,
  1706. <a href="../src/inameidx.h">src/inameidx.h</a>,
  1707. <a href="../src/inames.h">src/inames.h</a>,
  1708. <a href="../src/inamestr.h">src/inamestr.h</a>.
  1709. <dt>
  1710. Stacks:
  1711. <dd>
  1712. <a href="../src/isdata.h">src/isdata.h</a>,
  1713. <a href="../src/istack.c">src/istack.c</a>,
  1714. <a href="../src/istack.h">src/istack.h</a>,
  1715. <a href="../src/istkparm.h">src/istkparm.h</a>.
  1716. </dl>
  1717. <dt>
  1718. Specific stacks:
  1719. <dd>
  1720. <dl>
  1721. <dt>
  1722. Dictionary stack:
  1723. <dd>
  1724. <a href="../src/dstack.h">src/dstack.h</a>,
  1725. <a href="../src/estack.h">src/estack.h</a>,
  1726. <a href="../src/iddstack.h">src/iddstack.h</a>,
  1727. <a href="../src/idsdata.h">src/idsdata.h</a>,
  1728. <a href="../src/idstack.c">src/idstack.c</a>,
  1729. <a href="../src/idstack.h">src/idstack.h</a>.
  1730. <dt>
  1731. Execution stack:
  1732. <dd>
  1733. <a href="../src/iesdata.h">src/iesdata.h</a>,
  1734. <a href="../src/iestack.h">src/iestack.h</a>.
  1735. <dt>
  1736. Operand stack:
  1737. <dd>
  1738. <a href="../src/iosdata.h">src/iosdata.h</a>,
  1739. <a href="../src/iostack.h">src/iostack.h</a>,
  1740. <a href="../src/ostack.h">src/ostack.h</a>.
  1741. </dl>
  1742. </dl>
  1743. <h4><a name="Interpreter_loop"></a>Interpreter loop</h4>
  1744. <dl>
  1745. <dt>
  1746. Files:
  1747. <dd>
  1748. <a href="../src/interp.c">src/interp.c</a>,
  1749. <a href="../src/interp.h">src/interp.h</a>.
  1750. </dl>
  1751. <h4><a name="Scanning_parsing"></a>Scanning/parsing</h4>
  1752. <p>
  1753. PostScript parsing consists essentially of token scanning, and is simple in
  1754. principle. The scanner is complex because it must be able to suspend its
  1755. operation at any time (i.e., between any two input characters) to allow an
  1756. interpreter callout, if its input is coming from a procedure-based stream
  1757. and the procedure must be called to provide more input data.
  1758. <dl>
  1759. <dt>
  1760. Main scanner:
  1761. <dd>
  1762. <a href="../src/iscan.c">src/iscan.c</a>,
  1763. <a href="../src/iscan.h">src/iscan.h</a>,
  1764. <a href="../src/iscannum.c">src/iscannum.c</a>,
  1765. <a href="../src/iscannum.h">src/iscannum.h</a>,
  1766. <a href="../src/scanchar.h">src/scanchar.h</a>,
  1767. <a href="../src/scantab.c">src/scantab.c</a>.
  1768. <dt>
  1769. Binary tokens:
  1770. <dd>
  1771. <a href="../src/btoken.h">src/btoken.h</a>,
  1772. <a href="../src/ibnum.c">src/ibnum.c</a>,
  1773. <a href="../src/ibnum.h">src/ibnum.h</a>,
  1774. <a href="../src/inobtokn.c">src/inobtokn.c</a>,
  1775. <a href="../src/iscanbin.c">src/iscanbin.c</a>,
  1776. <a href="../src/iscanbin.h">src/iscanbin.h</a>.
  1777. <dt>
  1778. DSC parsing:
  1779. <dd>
  1780. <a href="../src/dscparse.c">src/dscparse.c</a>,
  1781. <a href="../src/dscparse.h">src/dscparse.h</a>.
  1782. </dl>
  1783. <h4><a name="Standard_operators"></a>Standard operators</h4>
  1784. <dl>
  1785. <dt>
  1786. Non-output-related:
  1787. <dd>
  1788. <dl>
  1789. <dt>
  1790. Filters:
  1791. <dd>
  1792. <a href="../src/ifilter.h">src/ifilter.h</a>,
  1793. <a href="../src/ifilter2.h">src/ifilter2.h</a>,
  1794. <a href="../src/ifrpred.h">src/ifrpred.h</a>,
  1795. <a href="../src/ifwpred.h">src/ifwpred.h</a>,
  1796. <a href="../src/istream.h">src/istream.h</a>,
  1797. <a href="../src/zfbcp.c">src/zfbcp.c</a>,
  1798. <a href="../src/zfdctd.c">src/zfdctd.c</a>,
  1799. <a href="../src/zfdcte.c">src/zfdcte.c</a>,
  1800. <a href="../src/zfdecode.c">src/zfdecode.c</a>,
  1801. <a href="../src/zfilter.c">src/zfilter.c</a>,
  1802. <a href="../src/zfilter2.c">src/zfilter2.c</a>,
  1803. <a href="../src/zfilterx.c">src/zfilterx.c</a>,
  1804. <a href="../src/zfmd5.c">src/zfmd5.c</a>,
  1805. <a href="../src/zfarc4.c">src/zfarc4.c</a>,
  1806. <a href="../src/zfproc.c">src/zfproc.c</a>,
  1807. <a href="../src/zfrsd.c">src/zfrsd.c</a>,
  1808. <a href="../src/zfzlib.c">src/zfzlib.c</a>.
  1809. <dt>
  1810. File and stream I/O:
  1811. <dd>
  1812. <a href="../src/files.h">src/files.h</a>,
  1813. <a href="../src/itoken.h">src/itoken.h</a>,
  1814. <a href="../src/zbseq.c">src/zbseq.c</a>,
  1815. <a href="../src/zdscpars.c">src/zdscpars.c</a>,
  1816. <a href="../src/zfile.c">src/zfile.c</a>,
  1817. <a href="../src/zfileio.c">src/zfileio.c</a>,
  1818. <a href="../src/ztoken.c">src/ztoken.c</a>.
  1819. <dt>
  1820. Data structures:
  1821. <dd>
  1822. <a href="../src/zarray.c">src/zarray.c</a>,
  1823. <a href="../src/zdict.c">src/zdict.c</a>,
  1824. <a href="../src/zgeneric.c">src/zgeneric.c</a>,
  1825. <a href="../src/zpacked.c">src/zpacked.c</a>,
  1826. <a href="../src/zstring.c">src/zstring.c</a>.
  1827. <dt>
  1828. Functions:
  1829. <dd>
  1830. <a href="../src/ifunc.h">src/ifunc.h</a>,
  1831. <a href="../src/zfunc.c">src/zfunc.c</a>,
  1832. <a href="../src/zfunc0.c">src/zfunc0.c</a>,
  1833. <a href="../src/zfunc3.c">src/zfunc3.c</a>,
  1834. <a href="../src/zfunc4.c">src/zfunc4.c</a>,
  1835. <dt>
  1836. Other:
  1837. <dd>
  1838. <a href="../src/ivmem2.h">src/ivmem2.h</a>,
  1839. <a href="../src/zarith.c">src/zarith.c</a>,
  1840. <a href="../src/zcontext.c">src/zcontext.c</a>,
  1841. <a href="../src/zcontrol.c">src/zcontrol.c</a>,
  1842. <a href="../src/zmath.c">src/zmath.c</a>,
  1843. <a href="../src/zmatrix.c">src/zmatrix.c</a>,
  1844. <a href="../src/zmisc.c">src/zmisc.c</a>,
  1845. <a href="../src/zmisc1.c">src/zmisc1.c</a>,
  1846. <a href="../src/zmisc2.c">src/zmisc2.c</a>,
  1847. <a href="../src/zmisc3.c">src/zmisc3.c</a>,
  1848. <a href="../src/zrelbit.c">src/zrelbit.c</a>,
  1849. <a href="../src/zstack.c">src/zstack.c</a>,
  1850. <a href="../src/ztype.c">src/ztype.c</a>,
  1851. <a href="../src/zusparam.c">src/zusparam.c</a>,
  1852. <a href="../src/zvmem.c">src/zvmem.c</a>,
  1853. <a href="../src/zvmem2.c">src/zvmem2.c</a>.
  1854. </dl>
  1855. <dt>
  1856. Output-related:
  1857. <dd>
  1858. <dl>
  1859. <dt>
  1860. Device management:
  1861. <dd>
  1862. <a href="../src/zdevcal.c">src/zdevcal.c</a>,
  1863. <a href="../src/zdevice.c">src/zdevice.c</a>,
  1864. <a href="../src/zdevice2.c">src/zdevice2.c</a>,
  1865. <a href="../src/ziodev.c">src/ziodev.c</a>,
  1866. <a href="../src/ziodev2.c">src/ziodev2.c</a>,
  1867. <a href="../src/ziodevs.c">src/ziodevs.c</a>,
  1868. <a href="../src/ziodevsc.c">src/ziodevsc.c</a>,
  1869. <a href="../src/zmedia2.c">src/zmedia2.c</a>,
  1870. <a href="../src/zdfilter.c">src/zdfilter.c</a>.
  1871. <dt>
  1872. Fonts and text:
  1873. <dd>
  1874. <a href="../src/bfont.h">src/bfont.h</a>,
  1875. <a href="../src/ccfont.h">src/ccfont.h</a>,
  1876. <a href="../src/iccfont.c">src/iccfont.c</a>,
  1877. <a href="../src/icfontab.c">src/icfontab.c</a>,
  1878. <a href="../src/ichar.h">src/ichar.h</a>,
  1879. <a href="../src/ichar1.h">src/ichar1.h</a>,
  1880. <a href="../src/icharout.h">src/icharout.h</a>,
  1881. <a href="../src/icid.h">src/icid.h</a>,
  1882. <a href="../src/ifcid.h">src/ifcid.h</a>,
  1883. <a href="../src/ifont.h">src/ifont.h</a>,
  1884. <a href="../src/ifont1.h">src/ifont1.h</a>,
  1885. <a href="../src/ifont2.h">src/ifont2.h</a>,
  1886. <a href="../src/ifont42.h">src/ifont42.h</a>,
  1887. <a href="../src/zbfont.c">src/zbfont.c</a>,
  1888. <a href="../src/zcfont.c">src/zcfont.c</a>,
  1889. <a href="../src/zchar.c">src/zchar.c</a>,
  1890. <a href="../src/zchar1.c">src/zchar1.c</a>,
  1891. <a href="../src/zchar2.c">src/zchar2.c</a>,
  1892. <a href="../src/zchar32.c">src/zchar32.c</a>,
  1893. <a href="../src/zchar42.c">src/zchar42.c</a>,
  1894. <a href="../src/zcharout.c">src/zcharout.c</a>,
  1895. <a href="../src/zcharx.c">src/zcharx.c</a>,
  1896. <a href="../src/zcid.c">src/zcid.c</a>,
  1897. <a href="../src/zfcid.c">src/zfcid.c</a>,
  1898. <a href="../src/zfcid0.c">src/zfcid0.c</a>,
  1899. <a href="../src/zfcid1.c">src/zfcid1.c</a>,
  1900. <a href="../src/zfcmap.c">src/zfcmap.c</a>,
  1901. <a href="../src/zfont.c">src/zfont.c</a>,
  1902. <a href="../src/zfont0.c">src/zfont0.c</a>,
  1903. <a href="../src/zfont1.c">src/zfont1.c</a>,
  1904. <a href="../src/zfont2.c">src/zfont2.c</a>,
  1905. <a href="../src/zfont32.c">src/zfont32.c</a>,
  1906. <a href="../src/zfont42.c">src/zfont42.c</a>.
  1907. <dt>
  1908. Color, pattern, and halftone:
  1909. <dd>
  1910. <a href="../src/icie.h">src/icie.h</a>,
  1911. <a href="../src/icolor.h">src/icolor.h</a>,
  1912. <a href="../src/icremap.h">src/icremap.h</a>,
  1913. <a href="../src/icsmap.h">src/icsmap.h</a>,
  1914. <a href="../src/iht.h">src/iht.h</a>,
  1915. <a href="../src/ipcolor.h">src/ipcolor.h</a>,
  1916. <a href="../src/zcie.c">src/zcie.c</a>,
  1917. <a href="../src/zcolor.c">src/zcolor.c</a>,
  1918. <a href="../src/zcolor1.c">src/zcolor1.c</a>,
  1919. <a href="../src/zcolor2.c">src/zcolor2.c</a>,
  1920. <a href="../src/zcrd.c">src/zcrd.c</a>,
  1921. <a href="../src/zcsdevn.c">src/zcsdevn.c</a>,
  1922. <a href="../src/zcsindex.c">src/zcsindex.c</a>,
  1923. <a href="../src/zcspixel.c">src/zcspixel.c</a>,
  1924. <a href="../src/zcssepr.c">src/zcssepr.c</a>,
  1925. <a href="../src/zicc.c">src/zicc.c</a>,
  1926. <a href="../src/zhsb.c">src/zhsb.c</a>,
  1927. <a href="../src/zht.c">src/zht.c</a>,
  1928. <a href="../src/zht1.c">src/zht1.c</a>,
  1929. <a href="../src/zht2.c">src/zht2.c</a>,
  1930. <a href="../src/zpcolor.c">src/zpcolor.c</a>,
  1931. <a href="../src/zshade.c">src/zshade.c</a>,
  1932. <a href="../src/ztrans.c">src/ztrans.c</a>.
  1933. <dt>
  1934. Images:
  1935. <dd>
  1936. <a href="../src/iimage.h">src/iimage.h</a>,
  1937. <a href="../src/iimage2.h">src/iimage2.h</a>,
  1938. <a href="../src/zimage.c">src/zimage.c</a>,
  1939. <a href="../src/zimage2.c">src/zimage2.c</a>,
  1940. <a href="../src/zimage3.c">src/zimage3.c</a>.
  1941. <dt>
  1942. Other graphics:
  1943. <dd>
  1944. <a href="../src/igstate.h">src/igstate.h</a>,
  1945. <a href="../src/zdpnext.c">src/zdpnext.c</a>,
  1946. <a href="../src/zdps.c">src/zdps.c</a>,
  1947. <a href="../src/zdps1.c">src/zdps1.c</a>,
  1948. <a href="../src/zgstate.c">src/zgstate.c</a>,
  1949. <a href="../src/zpaint.c">src/zpaint.c</a>,
  1950. <a href="../src/zpath.c">src/zpath.c</a>,
  1951. <a href="../src/zpath1.c">src/zpath1.c</a>,
  1952. <a href="../src/zrop.c">src/zrop.c</a>,
  1953. <a href="../src/ztrap.c">src/ztrap.c</a>,
  1954. <a href="../src/zupath.c">src/zupath.c</a>.
  1955. </dl>
  1956. <dt>
  1957. Operator support:
  1958. <dd>
  1959. <a href="../src/oparc.h">src/oparc.h</a>,
  1960. <a href="../src/opcheck.h">src/opcheck.h</a>,
  1961. <a href="../src/opdef.h">src/opdef.h</a>,
  1962. <a href="../src/oper.h">src/oper.h</a>,
  1963. <a href="../src/opextern.h">src/opextern.h</a>.
  1964. </dl>
  1965. <h4><a name="Non_standard_operators"></a>Non-standard operators</h4>
  1966. <p>
  1967. The interpreter includes many non-standard operators. Most of these provide
  1968. some part of the function of a standard operator, so that the standard
  1969. operator itself can be implemented in PostScript: these are not of interest
  1970. to users, and their function is usually obvious from the way they are used.
  1971. However, some non-standard operators provide access to additional,
  1972. non-standard facilities that users might want to know about, such as
  1973. transparency, RasterOp, and in-memory rendering. These are documented at <a
  1974. href="Language.htm#Additional_operators">Language.htm#Additional_operators</a>.
  1975. <p>
  1976. We don't document the complete set of non-standard operators here, because
  1977. the set changes frequently. However, all non-standard operators are
  1978. supposed to have names that begin with '.', so you can find them all by
  1979. executing the following (Unix) command:
  1980. <blockquote><pre>
  1981. grep '{".[.]' src/[zi]*.c
  1982. </pre></blockquote>
  1983. <p>
  1984. In addition to individual non-standard operators implemented in the same
  1985. files as standard ones, there are several independent optional packages of
  1986. non-standard operators. As with other non-standard operators, the names of
  1987. all the operators in these packages begin with '.'. We list those packages
  1988. here.
  1989. <dl>
  1990. <dt>
  1991. <a href="../src/zdosio.c">src/zdosio.c</a>
  1992. <dd>
  1993. Provides access to PC hardware I/O through MS-DOS system calls. Probably no
  1994. longer useful.
  1995. <dt>
  1996. <a href="../src/zdouble.c">src/zdouble.c</a>
  1997. <dd>
  1998. Provides "double" floating point arithmetic, using 8-byte strings to hold
  1999. values. Developed under a contract; probably used only by the group that
  2000. funded the development.
  2001. <dt>
  2002. <a href="../src/zsysvm.c">src/zsysvm.c</a>
  2003. <dd>
  2004. Provides operators for allocating objects in specific VM spaces,
  2005. disregarding the current VM mode.
  2006. <dt>
  2007. <a href="../src/zccube.c">src/zccube.c</a>
  2008. <dd>
  2009. Provides an operator for building a color cube from an arbitrary tint
  2010. transform, so that tint transforms can be applied from inside the
  2011. graphics library without calling back to the PostScript interpreter.
  2012. </dl>
  2013. <h4><a name="Interpreter_support"></a>Interpreter support</h4>
  2014. <p>
  2015. Memory management (refs, GC, save/restore) -- see <a
  2016. href="#PostScript_interpreter_extensions">below</a>.
  2017. <dl>
  2018. <dt>
  2019. Miscellaneous support:
  2020. <dd>
  2021. <a href="../src/errors.h">src/errors.h</a>,
  2022. <a href="../src/ghost.h">src/ghost.h</a>,
  2023. <a href="../src/iconf.c">src/iconf.c</a>,
  2024. <a href="../src/iconf.h">src/iconf.h</a>,
  2025. <a href="../src/idparam.c">src/idparam.c</a>,
  2026. <a href="../src/idparam.h">src/idparam.h</a>,
  2027. <a href="../src/ilevel.h">src/ilevel.h</a>,
  2028. <a href="../src/inouparm.c">src/inouparm.c</a>,
  2029. <a href="../src/iparam.c">src/iparam.c</a>,
  2030. <a href="../src/iparam.h">src/iparam.h</a>,
  2031. <a href="../src/iparray.h">src/iparray.h</a>,
  2032. <a href="../src/iutil.c">src/iutil.c</a>,
  2033. <a href="../src/iutil.h">src/iutil.h</a>,
  2034. <a href="../src/iutil2.c">src/iutil2.c</a>,
  2035. <a href="../src/iutil2.h">src/iutil2.h</a>,
  2036. <a href="../src/iutilasm.asm">src/iutilasm.asm</a>.
  2037. </dl>
  2038. <h4><a name="PostScript_code"></a>PostScript code</h4>
  2039. <dl>
  2040. <dt>
  2041. Initialization and language support:
  2042. <dd>
  2043. <dl>
  2044. <dt>
  2045. All configurations:
  2046. <dd>
  2047. <a href="../lib/gs_init.ps">lib/gs_init.ps</a>,
  2048. <a href="../lib/gs_statd.ps">lib/gs_statd.ps</a>.
  2049. <dt>
  2050. Level 2:
  2051. <dd>
  2052. <a href="../lib/gs_btokn.ps">lib/gs_btokn.ps</a>,
  2053. <a href="../lib/gs_dps1.ps">lib/gs_dps1.ps</a>,
  2054. <a href="../lib/gs_dps2.ps">lib/gs_dps2.ps</a>,
  2055. <a href="../lib/gs_lev2.ps">lib/gs_lev2.ps</a>,
  2056. <a href="../lib/gs_res.ps">lib/gs_res.ps</a>,
  2057. <a href="../lib/gs_setpd.ps">lib/gs_setpd.ps</a>.
  2058. <dt>
  2059. LanguageLevel 3:
  2060. <dd>
  2061. <a href="../lib/gs_frsd.ps">lib/gs_frsd.ps</a>,
  2062. <a href="../lib/gs_ll3.ps">lib/gs_ll3.ps</a>,
  2063. <a href="../lib/gs_trap.ps">lib/gs_trap.ps</a>.
  2064. <dt>
  2065. Display PostScript:
  2066. <dd>
  2067. <a href="../lib/gs_dpnxt.ps">lib/gs_dpnxt.ps</a>,
  2068. <a href="../lib/gs_dps.ps">lib/gs_dps.ps</a>.
  2069. <dt>
  2070. ICC color profiles:
  2071. <dd>
  2072. <a href="../lib/gs_icc.ps">lib/gs_icc.ps</a>.
  2073. </dl>
  2074. <dt>
  2075. Font loading and support:
  2076. <dd>
  2077. <dl>
  2078. <dt>
  2079. Font name mapping:
  2080. <dd>
  2081. <a href="../lib/Fontmap">lib/Fontmap</a>,
  2082. <a href="../lib/Fontmap.ATB">lib/Fontmap.ATB</a>,
  2083. <a href="../lib/Fontmap.ATM">lib/Fontmap.ATM</a>,
  2084. <a href="../lib/Fontmap.GS">lib/Fontmap.GS</a>,
  2085. <a href="../lib/Fontmap.OS2">lib/Fontmap.OS2</a>,
  2086. <a href="../lib/Fontmap.OSF">lib/Fontmap.OSF</a>,
  2087. <a href="../lib/Fontmap.SGI">lib/Fontmap.SGI</a>,
  2088. <a href="../lib/Fontmap.Sol">lib/Fontmap.Sol</a>,
  2089. <a href="../lib/Fontmap.Ult">lib/Fontmap.Ult</a>,
  2090. <a href="../lib/Fontmap.VMS">lib/Fontmap.VMS</a>.
  2091. <dt>
  2092. Generic:
  2093. <dd>
  2094. <a href="../lib/gs_ccfnt.ps">lib/gs_ccfnt.ps</a>,
  2095. <a href="../lib/gs_fonts.ps">lib/gs_fonts.ps</a>.
  2096. <dt>
  2097. Type 1 and CFF:
  2098. <dd>
  2099. <a href="../lib/gs_cff.ps">lib/gs_cff.ps</a>,
  2100. <a href="../lib/gs_diskf.ps">lib/gs_diskf.ps</a>,
  2101. <a href="../lib/gs_type1.ps">lib/gs_type1.ps</a>.
  2102. <dt>
  2103. TrueType:
  2104. <dd>
  2105. <a href="../lib/gs_ttf.ps">lib/gs_ttf.ps</a>,
  2106. <a href="../lib/gs_typ42.ps">lib/gs_typ42.ps</a>.
  2107. <dt>
  2108. CID-keyed:
  2109. <dd>
  2110. <a href="../lib/gs_cidcm.ps">lib/gs_cidcm.ps</a>,
  2111. <a href="../lib/gs_cidfn.ps">lib/gs_cidfn.ps</a>,
  2112. <a href="../lib/gs_cmap.ps">lib/gs_cmap.ps</a>.
  2113. <dt>
  2114. Other:
  2115. <dd>
  2116. <a href="../lib/gs_kanji.ps">lib/gs_kanji.ps</a>,
  2117. <a href="../lib/gs_pfile.ps">lib/gs_pfile.ps</a>,
  2118. <a href="../lib/gs_typ32.ps">lib/gs_typ32.ps</a>.
  2119. </dl>
  2120. <dt>
  2121. Encodings:
  2122. <dd>
  2123. <dl>
  2124. <dt>
  2125. Adobe-specified:
  2126. <dd>
  2127. <a href="../lib/gs_ce_e.ps">lib/gs_ce_e.ps</a>,
  2128. <a href="../lib/gs_dbt_e.ps">lib/gs_dbt_e.ps</a>,
  2129. <a href="../lib/gs_il1_e.ps">lib/gs_il1_e.ps</a>,
  2130. <a href="../lib/gs_mex_e.ps">lib/gs_mex_e.ps</a>,
  2131. <a href="../lib/gs_mro_e.ps">lib/gs_mro_e.ps</a>,
  2132. <a href="../lib/gs_pdf_e.ps">lib/gs_pdf_e.ps</a>,
  2133. <a href="../lib/gs_std_e.ps">lib/gs_std_e.ps</a>,
  2134. <a href="../lib/gs_sym_e.ps">lib/gs_sym_e.ps</a>,
  2135. <a href="../lib/gs_wan_e.ps">lib/gs_wan_e.ps</a>.
  2136. <dt>
  2137. Additional:
  2138. <dd>
  2139. <a href="../lib/gs_il2_e.ps">lib/gs_il2_e.ps</a>,
  2140. <a href="../lib/gs_ksb_e.ps">lib/gs_ksb_e.ps</a>,
  2141. <a href="../lib/gs_wl1_e.ps">lib/gs_wl1_e.ps</a>,
  2142. <a href="../lib/gs_wl2_e.ps">lib/gs_wl2_e.ps</a>,
  2143. <a href="../lib/gs_wl5_e.ps">lib/gs_wl5_e.ps</a>.
  2144. <dt>
  2145. Pseudo-encodings for internal use:
  2146. <dd>
  2147. <a href="../lib/gs_css_e.ps">lib/gs_css_e.ps</a>,
  2148. <a href="../lib/gs_lgo_e.ps">lib/gs_lgo_e.ps</a>,
  2149. <a href="../lib/gs_lgx_e.ps">lib/gs_lgx_e.ps</a>,
  2150. <a href="../lib/gs_mgl_e.ps">lib/gs_mgl_e.ps</a>.
  2151. </dl>
  2152. <dt>
  2153. Miscellaneous:
  2154. <dd>
  2155. <dl>
  2156. <dt>
  2157. Other support:
  2158. <dd>
  2159. <a href="../lib/gs_agl.ps">lib/gs_agl.ps</a>,
  2160. <a href="../lib/gs_dscp.ps">lib/gs_dscp.ps</a>,
  2161. <a href="../lib/gs_epsf.ps">lib/gs_epsf.ps</a>,
  2162. <a href="../lib/gs_pdfwr.ps">lib/gs_pdfwr.ps</a>,
  2163. <a href="../lib/gs_rdlin.ps">lib/gs_rdlin.ps</a>.
  2164. <dt>
  2165. X Windows icon bitmaps:
  2166. <dd>
  2167. <a href="../lib/gs_l.xbm">lib/gs_l.xbm</a>,
  2168. <a href="../lib/gs_l.xpm">lib/gs_l.xpm</a>,
  2169. <a href="../lib/gs_l_m.xbm">lib/gs_l_m.xbm</a>,
  2170. <a href="../lib/gs_m.xbm">lib/gs_m.xbm</a>,
  2171. <a href="../lib/gs_m.xpm">lib/gs_m.xpm</a>,
  2172. <a href="../lib/gs_m_m.xbm">lib/gs_m_m.xbm</a>,
  2173. <a href="../lib/gs_s.xbm">lib/gs_s.xbm</a>,
  2174. <a href="../lib/gs_s.xpm">lib/gs_s.xpm</a>,
  2175. <a href="../lib/gs_s_m.xbm">lib/gs_s_m.xbm</a>,
  2176. <a href="../lib/gs_t.xbm">lib/gs_t.xbm</a>,
  2177. <a href="../lib/gs_t.xpm">lib/gs_t.xpm</a>,
  2178. <a href="../lib/gs_t_m.xbm">lib/gs_t_m.xbm</a>.
  2179. <dt>
  2180. Not currently used:
  2181. <dd>
  2182. <a href="../lib/gs_cmdl.ps">lib/gs_cmdl.ps</a>,
  2183. <a href="../lib/gs_fform.ps">lib/gs_fform.ps</a>,
  2184. <a href="../lib/gs_l2img.ps">lib/gs_l2img.ps</a>.
  2185. </dl>
  2186. </dl>
  2187. <h3><a name="PDF_interpreter"></a>PDF interpreter</h3>
  2188. <p>
  2189. Ghostscript's PDF interpreter is written entirely in PostScript, because its
  2190. data structures are the same as PostScript's, and it is much more convenient
  2191. to manipulate PostScript-like data structures in PostScript than in C.
  2192. There is definitely a performance cost, but apparently not a substantial
  2193. one: we considered moving the main interpreter loop (read a token using
  2194. slightly different syntax than PostScript, push it on the stack if literal,
  2195. look it up in a special dictionary for execution if not) into C, but we did
  2196. some profiling and discovered that this wasn't accounting for enough of the
  2197. time to be worthwhile.
  2198. <p>
  2199. Until recently, there was essentially no C code specifically for the purpose
  2200. of supporting PDF interpretation. The one major exception is the PDF 1.4
  2201. transparency features, which we (but not Adobe) have made available to
  2202. PostScript code.
  2203. <p>
  2204. In addition to patching the <b><tt>run</tt></b> operator to detect PDF
  2205. files, the interpreter provides some procedures in <a
  2206. href="../lib/pdf_main.ps">lib/pdf_main.ps</a> that are meant to be called
  2207. from applications such as previewers.
  2208. <dl>
  2209. <dt>
  2210. Files:
  2211. <dd>
  2212. <a href="../lib/pdf_base.ps">lib/pdf_base.ps</a>,
  2213. <a href="../lib/pdf_draw.ps">lib/pdf_draw.ps</a>,
  2214. <a href="../lib/pdf_font.ps">lib/pdf_font.ps</a>,
  2215. <a href="../lib/pdf_main.ps">lib/pdf_main.ps</a>,
  2216. <a href="../lib/pdf_ops.ps">lib/pdf_ops.ps</a>,
  2217. <a href="../lib/pdf_sec.ps">lib/pdf_sec.ps</a>.
  2218. </dl>
  2219. <h3><a name="Build_process"></a>Build process</h3>
  2220. <h4><a name="Makefile_structure"></a>Makefile structure</h4>
  2221. <p>
  2222. Ghostscript's makefiles embody a number of design decisions and assumptions
  2223. that may not be obvious from a casual reading of the code.
  2224. <ul>
  2225. <li>All files are stored in subdirectories. The names of all subdirectories
  2226. used in the build process are defined in the top-level makefiles for the
  2227. various platforms: there are no "hard wired" directory names in any makefile
  2228. rule. Subdirectory names in the makefiles are relative to the directory
  2229. that is current at build time: normally this directory is the parent of the
  2230. various subdirectories, and holds only a <b><tt>makefile</tt></b>, which in
  2231. turn simply references the real top-level makefile in the source
  2232. subdirectory.
  2233. <li>All compiler and linker switches are likewise defined by macros, again
  2234. preferably in the top-level platform makefile.
  2235. <li>There is an absolute distinction between "source-like" subdirectories,
  2236. which are read-only during the build process, and "object-like"
  2237. subdirectories, all of whose contents are generated by the build process and
  2238. which can be emptied (<b><tt>rm&nbsp;*</tt></b>) at any time with no bad
  2239. effects. The source subdirectories are defined by macros named
  2240. <b><tt>xxxSRCDIR</tt></b>.
  2241. <li>Object subdirectories may distinguish further between those that hold
  2242. the results of the build process that are needed at run time (i.e., that
  2243. should be included in a run-time distribution), defined by
  2244. <b><tt>BINDIR</tt></b>, and those that are not needed at run time, defined
  2245. by <b><tt>xxxGENDIR</tt></b> and <b><tt>xxxOBJDIR</tt></b>. (The
  2246. distinction between these is historical and probably no longer relevant.)
  2247. <li>There may be multiple object subdirectories for different build
  2248. configurations. On Unix, the <b><tt>obj</tt></b> and <b><tt>bin</tt></b>
  2249. directories are used for normal production builds, the
  2250. <b><tt>debugobj</tt></b> directory for debugging builds, and the
  2251. <b><tt>pgobj</tt></b> directory for profiling builds; other platforms may
  2252. use different conventions. The Unix makefiles support targets named
  2253. <b><tt>debug</tt></b> and <b><tt>pg</tt></b> for debugging and profiling
  2254. builds respectively; other platforms generally do not.
  2255. <li>Makefiles will be maintained by hand. This requires editing the
  2256. following makefile elements whenever the relevant source files changes:
  2257. <ul>
  2258. <li>Every header (.h) file must have a corresponding macro definition in a
  2259. makefile. If <b><tt>abc.h</tt></b> #includes <b><tt>def.h</tt></b> and
  2260. <b><tt>xyz.h</tt></b>, the definition must have the form
  2261. <blockquote><pre>
  2262. xyz_h=$(xxxSRCD)xyz.h $(def_h) $(xyz_h)
  2263. </pre></blockquote>
  2264. where <b><tt>xxxSRCD</tt></b> is the macro defining the relevant source
  2265. directory (including a trailing '/'). Note that the '.' in the file name
  2266. has been replaced by an underscore. Note also that the definition must
  2267. follow all definitions it references, since some <b><tt>make</tt></b>
  2268. programs expand macros in definitions at the time of definition rather than
  2269. at the time of use.
  2270. <li>Every .c file must have a corresponding rule in a makefile. If
  2271. <b><tt>abc.c</tt></b> #includes <b><tt>def.h</tt></b> and
  2272. <b><tt>lmn.h</tt></b>, the rule must have approximately the form
  2273. <blockquote><pre>
  2274. $(xxxOBJD)abc.$(OBJ) : $(xxxSRCD)abc.c $(def_h) $(lmn_h)
  2275. $(xxCC) $(xxO_)abc.$(OBJ) $(C_) $(xxxSRCD)abc.c
  2276. </pre></blockquote>
  2277. where <b><tt>xxxSRCD</tt></b> is as before; <b><tt>xxxOBJD</tt></b> is the
  2278. relevant object directory; <b><tt>xxCC</tt></b> defines the name of the C
  2279. compiler plus the relevant compilation switches; and <b><tt>xxO_</tt></b>
  2280. and <b><tt>C_</tt></b> are macros used to bridge syntactic differences
  2281. between different <b><tt>make</tt></b> programs.
  2282. </ul>
  2283. </ul>
  2284. <p>
  2285. The requirement to keep makefiles up to date by hand has been controversial.
  2286. Two alternatives are generally proposed.
  2287. <ul>
  2288. <li>Programs like <b><tt>makedeps</tt></b>, which generate build rules
  2289. automatically from the #include lists in C files. We have found such
  2290. programs useless: they "wire in" specific, concrete directory names, not
  2291. only for our own code but even for the system header files; they have to be
  2292. run manually whenever code files are added, renamed, or deleted, or whenever
  2293. the list of #includes in any file changes; and they cannot deal with
  2294. different source files requiring different compilation switches.
  2295. <li>MSVC-style "project" files. These are equally useless: they are not
  2296. portable across different vendors' tools -- in fact, there may not even be a
  2297. usable import/export facility to convert their data to or from text form --
  2298. and they cannot combine configuration-independent data with
  2299. configuration-specific data.
  2300. </ul>
  2301. <p>
  2302. We have seriously considered writing our own build program in Tcl or Python
  2303. that would eliminate these problems, or perhaps porting the tools developed
  2304. by Digital's Vesta research project (if we can get access to them); however,
  2305. either of these approaches would create potential portability problems of
  2306. its own, not to mention difficulties in integrating with others' build
  2307. systems.
  2308. <p>
  2309. In the meantime, to ease the pain for mortal users and developers on
  2310. Unix platforms, we have adopted the standard autoconf tool to
  2311. systematically generate an appropriate top-level makefile for the
  2312. target system. As currently implemented, its use makes no deep changes
  2313. to the Ghostscript build system, but rather generates a makefile, more
  2314. or less the same as would be achieved by starting from a
  2315. platform-specific toplevel makefile and hand-editing. The relevant
  2316. autoconf sources are in <a
  2317. href="../src/Makefile.in">src/Makefile.in</a>, and <a
  2318. href="../src/configure.ac">configure.ac</a>. These sources are used in
  2319. the release process to create a <a href="../configure">configure</a>
  2320. script in the toplevel directory of releases. Also, there is an <a
  2321. href="../autogen.sh">autogen.sh</a> script to automate the autoconf
  2322. process somewhat. The names and locations of these files were chosen
  2323. to be clear to those familiar with autoconf, even though they represent
  2324. a slight departure from Ghostscript tradition.
  2325. <p>
  2326. For more information about makefiles:
  2327. <ul>
  2328. <li>For a detailed list of makefiles, and a discussion of makefile issues
  2329. related to portability, see the <a href="#Makefiles">Makefiles</a> section
  2330. below.
  2331. <li>For more detailed information about editing configuration information in
  2332. makefiles, see <a
  2333. href="Make.htm#Makefile_overview">doc/Make.htm#Makefile_overview</a>.
  2334. <li>For a complete example of adding a new driver to a makefile, see <a
  2335. href="Drivers.htm#Adding_drivers">doc/Drivers.htm#Adding_drivers</a>.
  2336. <li>For a few more notes on makefile coding conventions, see <a
  2337. href="C-style.htm#Makefiles">doc/C-style.htm#Makefiles</a>.
  2338. </ul>
  2339. <h4><a name="dev_files"></a>.dev files</h4>
  2340. <p>
  2341. On top of the general conventions just described, Ghostscript's makefiles
  2342. add a further layer of structure in order to support an open-ended set of
  2343. fine-grained, flexible configuration options. Selecting an option (usually
  2344. called a "module") for inclusion in the build may affect the build in many
  2345. ways:
  2346. <ul>
  2347. <li>Almost always, it requires linking in some compiled code files.
  2348. <li>It may require running some additional initialization procedures at
  2349. startup.
  2350. <li>It may require reading in some additional PostScript files at startup.
  2351. For example, a Level 2 PostScript build requires support for PostScript
  2352. resources and for setpagedevice, which are implemented in PostScript code.
  2353. <li>It may require adding entries to a variety of internal tables that
  2354. catalogue such things as drivers, IODevices, Function types, etc.
  2355. <li>It may require that other particular modules be included. For example,
  2356. the "PostScript Level 2" module requires the modules for various filters,
  2357. color spaces, etc.
  2358. <li>It may require <em>removing</em> some other (default) module from the
  2359. build. For example, the core (Level 1) PostScript build has a "stub" for
  2360. binary tokens, which are a Level 2 feature but are referenced by the core
  2361. scanner: a Level 2 build must remove the stub. For more information about
  2362. this, look for the string <b><tt>-replace</tt></b> in the makefiles and in
  2363. <a href="../src/genconf.c">src/genconf.c</a>.
  2364. </ul>
  2365. <p>
  2366. Each module is defined in the makefiles by rules that create a file named
  2367. <b><em>xxx</em><tt>.dev</tt></b>. The dependencies of the rule include all
  2368. the files that make up the module (compiled code files, PostScript files,
  2369. etc.); the body of the rule creates the .dev file by writing the description
  2370. of the module into it. A program called <b><tt>genconf</tt></b>, described
  2371. in the next section, merges all the relevant .dev files together. For
  2372. examples of .dev rules, see any of the Ghostscript makefiles.
  2373. <p>
  2374. Ultimately, a person must specify the root set of modules to include in a
  2375. build (which of course may require other modules, recursively).
  2376. Ghostscript's makefiles do this with a set of macros called
  2377. <b><tt>FEATURE_DEVS</tt></b> and <b><tt>DEVICE_DEVS</tt>n</b>, defined in
  2378. each top-level makefile, but nothing in the module machinery depends on
  2379. this.
  2380. <h4><a name="Generators"></a>Generators</h4>
  2381. <p>
  2382. Ghostscript's build procedure is somewhat unusual in that it compiles and
  2383. then executes some support programs during the build process. These
  2384. programs then generate data or source code that is used later on in the
  2385. build.
  2386. <p>
  2387. The most important and complex of the generator programs is
  2388. <b><tt>genconf</tt></b>. <b><tt>genconf</tt></b> merges all the .dev files
  2389. that make up the build, and creates three or more output files used in later
  2390. stages:
  2391. <ul>
  2392. <li><b><tt>gconfig.h</tt></b>, consisting mainly of macro calls, one call
  2393. per "resource" making up the build, other than "resources" listed in the
  2394. other output files.
  2395. <li><b><tt>gconfigf.h</tt></b>, produced only for PostScript builds with
  2396. compiled-in fonts, consisting of one macro call per font.
  2397. <li>A linker control file whose name varies from one platform to another,
  2398. containing the list of compiled code files to be linked.
  2399. <li>If necessary, another linker control file, also varying between
  2400. platforms, that contains other information for the linker such as the list
  2401. of system libraries to be searched. (On Unix platforms, the two linker
  2402. control functions are combined in a single file.)
  2403. </ul>
  2404. <dl>
  2405. <dt>
  2406. Source generators:
  2407. <dd>
  2408. <dl>
  2409. <dt>
  2410. <a href="../src/ansi2knr.c">src/ansi2knr.c</a>
  2411. <dd>
  2412. Converts ANSI C source to traditional (also known as "K&amp;R") C. Used if
  2413. and only if compiling with a pre-ANSI C compiler.
  2414. <dt>
  2415. <a href="../src/genarch.c">src/genarch.c</a>
  2416. <dd>
  2417. Creates a header file containing a variety of information about the hardware
  2418. and compiler that isn't provided in any standard system header file. Always
  2419. used.
  2420. <dt>
  2421. <a href="../src/genconf.c">src/genconf.c</a> (also generates non-source)
  2422. <dd>
  2423. Constructs header files and linker control files from the collection of
  2424. options and modules that make up the build. See above. Always used.
  2425. <dt>
  2426. <a href="../src/genht.c">src/genht.c</a>
  2427. <dd>
  2428. Converts a PostScript halftone (in a particular constrained format) to a C
  2429. data structure that can be compiled into an executable. Only used if any
  2430. such halftones are included in the build.
  2431. <dt>
  2432. <a href="../src/geninit.c">src/geninit.c</a>
  2433. <dd>
  2434. Converts PostScript initialization files to C data structures that can be
  2435. compiled into an executable. Only used when building a PostScript
  2436. interpreter, and only if <b><tt>COMPILE_INITS</tt></b> was set to 1 in the
  2437. makefile.
  2438. </dl>
  2439. <dt>
  2440. Other generators:
  2441. <dd>
  2442. <dl>
  2443. <dt>
  2444. <a href="../src/echogs.c">src/echogs.c</a>
  2445. <dd>
  2446. Implements a variety of shell-like functions to get around quirks,
  2447. limitations, and omissions in the shells on various platforms. Always used.
  2448. <dt>
  2449. <a href="../src/genconf.c">src/genconf.c</a> (also generates source)
  2450. <dd>
  2451. See above.
  2452. <dt>
  2453. <a href="../src/gendev.c">src/gendev.c</a> (not used)
  2454. <dd>
  2455. Was intended as a replacement for <b><tt>genconf</tt></b>, but was never
  2456. completed.
  2457. </dl>
  2458. </dl>
  2459. <h4><a name="Build_support"></a>Support</h4>
  2460. <p>
  2461. There are a number of programs, scripts, and configuration files that exist
  2462. only for the sake of the build process.
  2463. <dl>
  2464. <dt>
  2465. Files for PC environments:
  2466. <dd>
  2467. <a href="../src/bcc32.cfg">src/bcc32.cfg</a>,
  2468. <a href="../src/cp.bat">src/cp.bat</a>,
  2469. <a href="../src/cp.cmd">src/cp.cmd</a>,
  2470. <a href="../src/dw32c.def">src/dw32c.def</a>,
  2471. <a href="../src/dwmain.rc">src/dwmain.rc</a>,
  2472. <a href="../src/dwmain16.def">src/dwmain16.def</a>,
  2473. <a href="../src/dwmain32.def">src/dwmain32.def</a>,
  2474. <a href="../src/dwsetup.def">src/dwsetup.def</a>,
  2475. <a href="../src/dwsetup.rc">src/dwsetup.rc</a>,
  2476. <a href="../src/dwuninst.def">src/dwuninst.def</a>,
  2477. <a href="../src/dwuninst.rc">src/dwuninst.rc</a>,
  2478. <a href="../src/gs16spl.def">src/gs16spl.def</a>,
  2479. <a href="../src/gs16spl.rc">src/gs16spl.rc</a>,
  2480. <a href="../src/gsdll2.def">src/gsdll2.def</a>,
  2481. <a href="../src/gsdll2.rc">src/gsdll2.rc</a>,
  2482. <a href="../src/gsdll32.def">src/gsdll32.def</a>,
  2483. <a href="../src/gsdll32.rc">src/gsdll32.rc</a>,
  2484. <a href="../src/gsdll32w.lnk">src/gsdll32w.lnk</a>,
  2485. <a href="../src/gsgraph.icx">src/gsgraph.icx</a>,
  2486. <a href="../src/gsos2.def">src/gsos2.def</a>,
  2487. <a href="../src/gsos2.icx">src/gsos2.icx</a>,
  2488. <a href="../src/gsos2.rc">src/gsos2.rc</a>,
  2489. <a href="../src/gspmdrv.def">src/gspmdrv.def</a>,
  2490. <a href="../src/gspmdrv.icx">src/gspmdrv.icx</a>,
  2491. <a href="../src/gspmdrv.rc">src/gspmdrv.rc</a>,
  2492. <a href="../src/gstext.icx">src/gstext.icx</a>,
  2493. <a href="../src/gswin.rc">src/gswin.rc</a>,
  2494. <a href="../src/gswin32.rc">src/gswin32.rc</a>,
  2495. <a href="../src/gswin386.rc">src/gswin386.rc</a>,
  2496. <a href="../src/mv.bat">src/mv.bat</a>,
  2497. <a href="../src/mv.cmd">src/mv.cmd</a>,
  2498. <a href="../src/rm.bat">src/rm.bat</a>,
  2499. <a href="../src/rm.cmd">src/rm.cmd</a>,
  2500. <a href="../src/turboc.cfg">src/turboc.cfg</a>.
  2501. <dt>
  2502. Files for OpenVMS:
  2503. <dd>
  2504. <a href="../src/append_l.com">src/append_l.com</a>,
  2505. <a href="../src/copy_one.com">src/copy_one.com</a>,
  2506. <a href="../src/rm_all.com">src/rm_all.com</a>,
  2507. <a href="../src/rm_one.com">src/rm_one.com</a>.
  2508. <dt>
  2509. Other files:
  2510. <dd>
  2511. <a href="../src/bench.c">src/bench.c</a>,
  2512. <a href="../src/catmake">src/catmake</a>,
  2513. <a href="../src/ccgs">src/ccgs</a>,
  2514. <a href="../src/instcopy">src/instcopy</a>.
  2515. </dl>
  2516. <h3><a name="Utilities"></a>Utilities</h3>
  2517. <p>
  2518. Ghostscript comes with many utilities for doing things like viewing bitmap
  2519. files and converting between file formats. Some of these are written in
  2520. PostScript, some as scripts, and some as scripts that invoke special
  2521. PostScript code.
  2522. <h4><a name="Utilities_in_PostScript"></a>Utilities in PostScript</h4>
  2523. <p>
  2524. These are all documented in <a href="Psfiles.htm">doc/Psfiles.htm</a>, q.v.
  2525. <h4><a name="Utility_scripts"></a>Utility scripts</h4>
  2526. <p>
  2527. Many of these scripts come in both Unix and MS-DOS (<b><tt>.bat</tt></b>
  2528. versions; some also have an OS/2 (<b><tt>.cmd</tt></b>) version. The choice
  2529. of which versions are provided is historical and irregular. These scripts
  2530. should all be documented somewhere, but currently, many of them have man
  2531. pages, a few have their own documentation in the doc directory, and some
  2532. aren't documented at all.
  2533. <dl>
  2534. <dt>
  2535. Script files without PC versions:
  2536. <dd>
  2537. <a href="../lib/afmdiff.awk">lib/afmdiff.awk</a>,
  2538. <a href="../lib/dvipdf">lib/dvipdf</a>,
  2539. <a href="../lib/fixmswrd.pl">lib/fixmswrd.pl</a>,
  2540. <a href="../lib/lprsetup.sh">lib/lprsetup.sh</a>,
  2541. <a href="../lib/pfbtopfa">lib/pfbtopfa</a>,
  2542. <a href="../lib/pj-gs.sh">lib/pj-gs.sh</a>,
  2543. <a href="../lib/pphs">lib/pphs</a>,
  2544. <a href="../lib/printafm">lib/printafm</a>,
  2545. <a href="../lib/pv.sh">lib/pv.sh</a>,
  2546. <a href="../lib/sysvlp.sh">lib/sysvlp.sh</a>,
  2547. <a href="../lib/unix-lpr.sh">lib/unix-lpr.sh</a>,
  2548. <a href="../lib/wftopfa">lib/wftopfa</a>.
  2549. <dt>
  2550. Script files with PC versions:
  2551. <dd>
  2552. <a href="../lib/bdftops">lib/bdftops</a>,
  2553. <a href="../lib/bdftops.bat">lib/bdftops.bat</a>,
  2554. <a href="../lib/bdftops.cmd">lib/bdftops.cmd</a>,
  2555. <a href="../lib/eps2eps">lib/eps2eps</a>,
  2556. <a href="../lib/eps2eps.bat">lib/eps2eps.bat</a>,
  2557. <a href="../lib/eps2eps.cmd">lib/eps2eps.cmd</a>,
  2558. <a href="../lib/font2c">lib/font2c</a>,
  2559. <a href="../lib/font2c.bat">lib/font2c.bat</a>,
  2560. <a href="../lib/font2c.cmd">lib/font2c.cmd</a>,
  2561. <a href="../lib/gsbj">lib/gsbj</a>,
  2562. <a href="../lib/gsbj.bat">lib/gsbj.bat</a>,
  2563. <a href="../lib/gsdj">lib/gsdj</a>,
  2564. <a href="../lib/gsdj.bat">lib/gsdj.bat</a>,
  2565. <a href="../lib/gsdj500">lib/gsdj500</a>,
  2566. <a href="../lib/gsdj500.bat">lib/gsdj500.bat</a>,
  2567. <a href="../lib/gslj">lib/gslj</a>,
  2568. <a href="../lib/gslj.bat">lib/gslj.bat</a>,
  2569. <a href="../lib/gslp">lib/gslp</a>,
  2570. <a href="../lib/gslp.bat">lib/gslp.bat</a>,
  2571. <a href="../lib/gsnd">lib/gsnd</a>,
  2572. <a href="../lib/gsnd.bat">lib/gsnd.bat</a>,
  2573. <a href="../lib/pdf2dsc">lib/pdf2dsc</a>,
  2574. <a href="../lib/pdf2dsc.bat">lib/pdf2dsc.bat</a>,
  2575. <a href="../lib/pdf2ps">lib/pdf2ps</a>,
  2576. <a href="../lib/pdf2ps.bat">lib/pdf2ps.bat</a>,
  2577. <a href="../lib/pdf2ps.cmd">lib/pdf2ps.cmd</a>,
  2578. <a href="../lib/pdfopt">lib/pdfopt</a>,
  2579. <a href="../lib/pdfopt.bat">lib/pdfopt.bat</a>,
  2580. <a href="../lib/pf2afm">lib/pf2afm</a>,
  2581. <a href="../lib/pf2afm.bat">lib/pf2afm.bat</a>,
  2582. <a href="../lib/pf2afm.cmd">lib/pf2afm.cmd</a>,
  2583. <a href="../lib/ps2ascii">lib/ps2ascii</a>,
  2584. <a href="../lib/ps2ascii.bat">lib/ps2ascii.bat</a>,
  2585. <a href="../lib/ps2ascii.cmd">lib/ps2ascii.cmd</a>,
  2586. <a href="../lib/ps2epsi">lib/ps2epsi</a>,
  2587. <a href="../lib/ps2epsi.bat">lib/ps2epsi.bat</a>,
  2588. <a href="../lib/ps2epsi.cmd">lib/ps2epsi.cmd</a>,
  2589. <a href="../lib/ps2pdf">lib/ps2pdf</a>,
  2590. <a href="../lib/ps2pdf.bat">lib/ps2pdf.bat</a>,
  2591. <a href="../lib/ps2pdf.cmd">lib/ps2pdf.cmd</a>,
  2592. <a href="../lib/ps2pdf12">lib/ps2pdf12</a>,
  2593. <a href="../lib/ps2pdf12.bat">lib/ps2pdf12.bat</a>,
  2594. <a href="../lib/ps2pdf12.cmd">lib/ps2pdf12.cmd</a>,
  2595. <a href="../lib/ps2pdf13">lib/ps2pdf13</a>,
  2596. <a href="../lib/ps2pdf13.bat">lib/ps2pdf13.bat</a>,
  2597. <a href="../lib/ps2pdf13.cmd">lib/ps2pdf13.cmd</a>,
  2598. <a href="../lib/ps2pdf14">lib/ps2pdf14</a>,
  2599. <a href="../lib/ps2pdf14.bat">lib/ps2pdf14.bat</a>,
  2600. <a href="../lib/ps2pdf14.cmd">lib/ps2pdf14.cmd</a>,
  2601. <a href="../lib/ps2pdfwr">lib/ps2pdfwr</a>,
  2602. <a href="../lib/ps2pdfxx.bat">lib/ps2pdfxx.bat</a>,
  2603. <a href="../lib/ps2ps">lib/ps2ps</a>,
  2604. <a href="../lib/ps2ps.bat">lib/ps2ps.bat</a>,
  2605. <a href="../lib/ps2ps.cmd">lib/ps2ps.cmd</a>.
  2606. <dt>
  2607. Script files with only PC versions:
  2608. <dd>
  2609. <a href="../lib/gsndt.bat">lib/gsndt.bat</a>,
  2610. <a href="../lib/gssetgs.bat">lib/gssetgs.bat</a>,
  2611. <a href="../lib/gst.bat">lib/gst.bat</a>,
  2612. <a href="../lib/gstt.bat">lib/gstt.bat</a>,
  2613. <a href="../lib/lp386.bat">lib/lp386.bat</a>,
  2614. <a href="../lib/lp386r2.bat">lib/lp386r2.bat</a>,
  2615. <a href="../lib/lpgs.bat">lib/lpgs.bat</a>,
  2616. <a href="../lib/lpr2.bat">lib/lpr2.bat</a>,
  2617. <a href="../lib/pftogsf.bat">lib/pftogsf.bat</a>,
  2618. <a href="../lib/wmakebat.bat">lib/wmakebat.bat</a>.
  2619. </dl>
  2620. <hr>
  2621. <h2><a name="Memory_management"></a>Memory management</h2>
  2622. <h3><a name="Memory_manager_architecture"></a>Memory manager architecture</h3>
  2623. <p>
  2624. In many environments, the memory manager is a set of library facilities that
  2625. implicitly manage the entire address space in a homogenous manner.
  2626. Ghostscript's memory manager architecture has none of these properties:
  2627. <ul>
  2628. <li>Rather than a single library accessed as procedures, Ghostscript
  2629. includes multiple allocator types, each of which in turn may have multiple
  2630. instances (allocators). Allocators are 'objects' with a substantial set of
  2631. virtual functions.
  2632. <li>Rather than managing the entire address space, each allocator manages a
  2633. storage pool, which it may or may not be able to expand or reduce by calling
  2634. on a 'parent' allocator.
  2635. <li>Rather than a single genus of untyped storage blocks, Ghostscript's
  2636. allocators provide two genera -- type-tagged 'objects', and 'strings' --
  2637. with substantially different properties.
  2638. </ul>
  2639. <h4><a name="Objects_vs_strings"></a>Objects vs strings</h4>
  2640. <p>
  2641. As noted above, allocators provide two different storage genera.
  2642. <p>
  2643. Objects:
  2644. <ul>
  2645. <li>Are aligned in storage to satisfy the most stringent alignment
  2646. requirement imposed by the CPU or compiler;
  2647. <li>Can be referenced only by pointers to their start, not to any internal
  2648. location, unless special arrangements are made;
  2649. <li>May contain pointers to other objects, or to strings;
  2650. <li>Have an associated <em>structure descriptor</em> that specifies their
  2651. size (usually) and the location of any pointers contained within them.
  2652. </ul>
  2653. <p>
  2654. Given a pointer to an object, the allocator that allocated it must be able
  2655. to return the object's size and the pointer to its structure descriptor.
  2656. (It is up to the client to know what allocator allocated an object.)
  2657. <p>
  2658. Strings:
  2659. <ul>
  2660. <li>Are not aligned in storage;
  2661. <li>Can be referenced by pointers (consisting of a starting address and a
  2662. length) to any substring, starting anywhere within the string;
  2663. <li>May not contain pointers;
  2664. <li>Do not have a structure descriptor.
  2665. </ul>
  2666. <p>
  2667. The object/string distinction reflects a space/capability tradeoff. The
  2668. per-object space overhead of the standard type of allocator is typically 12
  2669. bytes; this is too much to impose on every string of a few bytes. On the
  2670. other hand, restricting object pointers to reference the start of the object
  2671. currently makes object garbage collection and compaction more
  2672. space-efficient. If we were to redesign the standard allocator, we would
  2673. probably opt for a different design in which strings were allocated within
  2674. container objects of a few hundred bytes, and pointers into the middle of
  2675. all objects were allowed.
  2676. <h4><a name="Structure_descriptors"></a>Structure descriptors</h4>
  2677. <p>
  2678. Every object allocated by a Ghostscript allocator has an associated
  2679. structure descriptor, which the caller provides when allocating the object.
  2680. The structure descriptor serves several purposes:
  2681. <ul>
  2682. <li>Specifying the size of the object for allocation;
  2683. <li>Providing pointer-enumeration and pointer-relocation procedures for
  2684. the garbage collector;
  2685. <li>Providing an optional finalization procedure to be called when the
  2686. object is freed (either explicitly or automatically).
  2687. </ul>
  2688. <p>
  2689. Structure descriptors are read-only, and are normally defined statically
  2690. using one of the large set of <b><tt>gs_private_st_</tt></b> or
  2691. <b><tt>gs_public_st_</tt></b> macros in <a
  2692. href="../src/gsstruct.h">src/gsstruct.h</a>.
  2693. <p>
  2694. While the structure descriptor normally specifies the size of the object,
  2695. one can also allocate an array of bytes or objects, whose size is a multiple
  2696. of the size in the descriptor. For this reason, every object stores its
  2697. size as well as a reference to its descriptor.
  2698. <p>
  2699. Because the standard Ghostscript garbage collector is conservative and can
  2700. move objects, every object allocated by a Ghostscript allocator must have an
  2701. accurate structure descriptor. If you define a new type of object
  2702. (structure) that will be allocated in storage managed by Ghostscript, you
  2703. <em>must</em> create an accurate descriptor for it, and use that descriptor
  2704. to allocate it. The process of creating accurate descriptors for all
  2705. structures was long and painful, and accounted for many hard-to-diagnose
  2706. bugs.
  2707. <p>
  2708. By convention, the structure descriptor for structure type
  2709. <b><tt>xxx_t</tt></b> is named <b><tt>st_xxx</tt></b> (this is preferred),
  2710. or occasionally <b><tt>st_xxx_t</tt></b>.
  2711. <p>
  2712. Note that a structure descriptor is only required for objects allocated by
  2713. the Ghostscript allocator. A structure type <b><tt>xxx_t</tt></b> does not
  2714. require a structure descriptor if instances of that type are used
  2715. <em>only</em> in the following ways:
  2716. <ul>
  2717. <li>Instances are allocated only on the C stack, e.g., as
  2718. <b><tt>xxx_t&nbsp;xxx1,&nbsp;xxx2;</tt></b>, or on the C heap, with
  2719. <b><tt>malloc</tt></b> or through the Ghostscript "wrapper" defined in <a
  2720. href="../src/gsmalloc.h">src/gsmalloc.h</a>.
  2721. <li>Pointers to instances are not stored in places where the garbage
  2722. collector will try to trace the pointer.
  2723. <li>Code never attempts to get the structure type or size of an instance
  2724. through the allocator API.
  2725. </ul>
  2726. <p>
  2727. In general, structures without descriptors are problem-prone, and are
  2728. deprecated; in new code, they should only be used if the structure is
  2729. confined to a single .c file and its instances are only allocated on the C
  2730. stack.
  2731. <dl>
  2732. <dt>
  2733. Files:
  2734. <dd>
  2735. <a href="../src/gsstruct.h">src/gsstruct.h</a>,
  2736. <a href="../src/gsstype.h">src/gsstype.h</a>.
  2737. </dl>
  2738. <h4><a name="Garbage_collection"></a>Garbage collection</h4>
  2739. <p>
  2740. The allocator architecture is designed to support compacting garbage
  2741. collection. Every object must be able to enumerate all the pointers it
  2742. contains, both for tracing and for relocation. As noted just above, the
  2743. structure descriptor provides procedures that do this.
  2744. <p>
  2745. Whether or not a particular allocator type actually provides a garbage
  2746. collector is up to the allocator: garbage collection is invoked through a
  2747. virtual procedure. In practice, however, there are only two useful garbage
  2748. collectors for Ghostscript's own allocator:
  2749. <ul>
  2750. <li>The "real" garbage collector associated with the PostScript interpreter,
  2751. described <a href="#Interpreter_GC">below</a>;
  2752. <li>A "non" garbage collector that only merges adjacent free blocks.
  2753. </ul>
  2754. <dl>
  2755. <dt>
  2756. Files:
  2757. <dd>
  2758. <a href="../src/gsgc.h">src/gsgc.h</a>,
  2759. <a href="../src/gsnogc.c">src/gsnogc.c</a>,
  2760. <a href="../src/gsnogc.h">src/gsnogc.h</a>.
  2761. </dl>
  2762. <h4><a name="Movability"></a>Movability</h4>
  2763. <p>
  2764. As just noted, objects are normally movable by the garbage collector.
  2765. However, some objects must be immovable, usually because some other piece of
  2766. software must retain pointers to them. The allocator API includes
  2767. procedures for allocating both movable (default) and immovable objects.
  2768. Note, however, that even immovable objects must be traceable (have a
  2769. structure descriptor), and may be freed, by the garbage collector.
  2770. <h4><a name="Parent_hierarchy"></a>Parent hierarchy</h4>
  2771. <p>
  2772. When an allocator needs to add memory to the pool that it manages, it
  2773. requests the memory from its <em>parent</em> allocator. Every allocator has
  2774. a pointer to its parent; multiple allocators may share a single parent. The
  2775. ultimate ancestor of all allocators that can expand their pool dynamically
  2776. is an allocator that calls <b><tt>malloc</tt></b>, described <a
  2777. href="#malloc">below</a>. However, especially in embedded environments, an
  2778. allocator may be limited to a fixed-size pool assigned to it when it is
  2779. created.
  2780. <h4><a name="Allocator_API"></a>Allocator API</h4>
  2781. In summary, the allocator API provides the following principal operations:
  2782. <ul>
  2783. <li>Allocate and free movable (default) or immovable objects and strings.
  2784. <li>Return the structure type and size of an object.
  2785. <li>Resize (shrink or grow) movable objects and strings, preserving
  2786. the contents insofar as possible.
  2787. <li>Report the size of the managed pool, and how much of it is in use.
  2788. <li>Register and unregister root pointers for the garbage collector.
  2789. <li>Free the allocator itself.
  2790. <li>Consolidate adjacent free blocks to reduce fragmentation.
  2791. </ul>
  2792. <p>
  2793. For details, see <a href="../src/gsmemory.h">src/gsmemory.h</a>.
  2794. <p>
  2795. The allocator API also includes one special hook for the PostScript
  2796. interpreter: the concept of stable allocators. See the section on <a
  2797. href="#save_forgetsave_restore"><b><tt>save</tt></b> and
  2798. <b><tt>restore</tt></b></a> below for details.
  2799. <dl>
  2800. <dt>
  2801. Files:
  2802. <dd>
  2803. <a href="../src/gsmemraw.h">src/gsmemraw.h</a>,
  2804. <a href="../src/gsmemory.c">src/gsmemory.c</a>,
  2805. <a href="../src/gsmemory.h">src/gsmemory.h</a>,
  2806. <a href="../src/gsstruct.h">src/gsstruct.h</a>,
  2807. <a href="../src/gsstype.h">src/gsstype.h</a>.
  2808. </dl>
  2809. <h3><a name="Freeing_storage"></a>Freeing storage</h3>
  2810. <p>
  2811. Ghostscript's memory management architecture provides three different ways
  2812. to free objects: explicitly, by reference counting, or by garbage
  2813. collection. They provide different safety / performance / convenience
  2814. tradeoffs; we believe that all three are necessary.
  2815. <p>
  2816. Objects are always freed as a whole; strings may be freed piecemeal.
  2817. <p>
  2818. An object may have an associated finalization procedure, defined in the
  2819. structure descriptor. This procedure is called just before the object is
  2820. freed, independent of which method is being used to free the object. A few
  2821. types of objects have a virtual finalization procedure as well: the
  2822. finalization procedure defined in the descriptor simply calls the one in the
  2823. object.
  2824. <h4><a name="Explicit_freeing"></a>Explicit freeing</h4>
  2825. <p>
  2826. Objects and strings may be freed explicitly, using the
  2827. <b><tt>gs_free_</tt></b> virtual procedures in the allocator API. It is up
  2828. to the client to ensure that all allocated objects are freed at most once,
  2829. and that there are no dangling pointers.
  2830. <p>
  2831. Explicit freeing is the fastest method, but is the least convenient and
  2832. least safe. It is most appropriate when storage is freed in the same
  2833. procedure where it is allocated, or for storage that is known to be
  2834. referenced by only one pointer.
  2835. <h4><a name="Reference_counting"></a>Reference counting</h4>
  2836. <p>
  2837. Objects may be managed by reference counting. When an object is allocated,
  2838. its reference count may be set to 0 or 1. Subsequently, when the reference
  2839. count is decremented to 0, the object is freed.
  2840. <p>
  2841. The reference counting machinery provides its own virtual finalization
  2842. procedure for all reference-counted objects. The machinery calls this
  2843. procedure when it is about to free the object (but not when the object is
  2844. freed in any other way, which is probably a design bug). This is in
  2845. addition to (and called before) any finalization procedure associated with
  2846. the object type.
  2847. <p>
  2848. Reference counting is as fast as explicit freeing, but takes more space in
  2849. the object. It is most appropriate for relatively large objects which are
  2850. referenced only from a small set of pointers. Note that reference counting
  2851. cannot free objects that are involved in a pointer cycle (e.g., A -> B -> C
  2852. -> A).
  2853. <dl>
  2854. <dt>
  2855. Files:
  2856. <dd>
  2857. <a href="../src/gsrefct.h">src/gsrefct.h</a>.
  2858. </dl>
  2859. <h4><a name="Real_garbage_collection"></a>(Real) garbage collection</h4>
  2860. <p>
  2861. Objects and strings may be freed automatically by a garbage collector. See
  2862. <a href="#Interpreter_GC">below</a>.
  2863. <h3><a name="Special_implementations"></a>Special implementations</h3>
  2864. <h4><a name="malloc"></a>malloc</h4>
  2865. <p>
  2866. As mentioned <a href="#Parent_hierarchy">above</a>, the ultimate ancestor of
  2867. all allocators with an expandable pool is one that calls
  2868. <b><tt>malloc</tt></b>.
  2869. <dl>
  2870. <dt>
  2871. Files:
  2872. <dd>
  2873. <a href="../src/gsmalloc.h">src/gsmalloc.h</a>,
  2874. <a href="../src/gsmalloc.c">src/gsmalloc.c</a>.
  2875. </dl>
  2876. <h4><a name="Locking"></a>Locking</h4>
  2877. <p>
  2878. In a multi-threaded environment, if an allocator must be callable from
  2879. multiple threads (for example, if it is used to allocate structures in one
  2880. thread that are passed to, and freed by, another thread), the allocator must
  2881. provide mutex protection. Ghostscript provides this capability in the form
  2882. of a <em>wrapper</em> allocator, that simply forwards all calls to a
  2883. <em>target</em> allocator under protection of a mutex. Using the wrapper
  2884. technique, any allocator can be made thread-safe.
  2885. <dl>
  2886. <dt>
  2887. Files:
  2888. <dd>
  2889. <a href="../src/gsmemlok.h">src/gsmemlok.h</a>,
  2890. <a href="../src/gsmemlok.c">src/gsmemlok.c</a>.
  2891. </dl>
  2892. <h4><a name="Retrying"></a>Retrying</h4>
  2893. <p>
  2894. In an embedded environment, job failure due to memory exhaustion is very
  2895. undesirable. Ghostscript provides a wrapper allocator that, when an
  2896. allocation attempt fails, calls a client-provided procedure that can attempt
  2897. to free memory, then ask for the original allocation to be retried. For
  2898. example, such a procedure can wait for a queue to empty, or can free memory
  2899. occupied by caches.
  2900. <dl>
  2901. <dt>
  2902. Files:
  2903. <dd>
  2904. <a href="../src/gsmemret.h">src/gsmemret.h</a>,
  2905. <a href="../src/gsmemret.c">src/gsmemret.c</a>.
  2906. </dl>
  2907. <h3><a name="Standard_implementation"></a>Standard implementation</h3>
  2908. <p>
  2909. The standard Ghostscript allocator gets storage from its parent (normally
  2910. the <b><tt>malloc</tt></b> allocator) in large blocks called
  2911. <em>chunks</em>, and then allocates objects up from the low end and strings
  2912. down from the high end. Large objects or strings are allocated in their own
  2913. chunk.
  2914. <p>
  2915. The standard allocator maintains a set of free-block lists for small object
  2916. sizes, one list per size (rounded up to the word size), plus a free-block
  2917. list for large objects (but not for objects so large that they get their own
  2918. chunk: when such an object is freed, its chunk is returned to the parent).
  2919. The lists are not sorted; adjacent blocks are only merged if needed.
  2920. <p>
  2921. While the standard allocator implements the generic allocator API, and is
  2922. usable with the library alone, it includes a special hook for the PostScript
  2923. interpreter to aid in the efficient allocation of PostScript composite
  2924. objects (arrays and dictionaries). See the section on <a
  2925. href="#Refs">Refs</a> below for details.
  2926. <dl>
  2927. <dt>
  2928. Files:
  2929. <dd>
  2930. <a href="../src/gsalloc.c">src/gsalloc.c</a>,
  2931. <a href="../src/gsalloc.h">src/gsalloc.h</a>,
  2932. <a href="../src/gxalloc.h">src/gxalloc.h</a>,
  2933. <a href="../src/gxobj.h">src/gxobj.h</a>.
  2934. </dl>
  2935. <h3><a name="PostScript_interpreter_extensions"></a>PostScript interpreter extensions</h3>
  2936. <p>
  2937. The PostScript interpreter uses an allocator that extends the graphic
  2938. library's standard allocator to handle PostScript objects,
  2939. <b><tt>save</tt></b> and <b><tt>restore</tt></b>, and real garbage
  2940. collection.
  2941. <h4><a name="Refs"></a>Refs (PostScript "objects")</h4>
  2942. <p>
  2943. Ghostscript represents what the PLRM calls PostScript "objects" using a
  2944. structure called a <b><tt>ref</tt></b>, defined in <a
  2945. href="../src/iref.h">src/iref.h</a>; packed refs, used for the elements of
  2946. packed arrays, are defined in <a href="../src/ipacked.h">src/ipacked.h</a>.
  2947. See those files for detailed information.
  2948. <dl>
  2949. <dt>
  2950. Files:
  2951. <dd>
  2952. <a href="../src/ipacked.h">src/ipacked.h</a>,
  2953. <a href="../src/iref.h">src/iref.h</a>.
  2954. </dl>
  2955. <p>
  2956. The PLRM calls for two types of "virtual memory" (VM) space: global and
  2957. local. Ghostscript adds a third space, <em>system</em> VM, whose lifetime
  2958. is an entire session -- i.e., it is effectively "permanent". All three
  2959. spaces are subject to garbage collection. There is a separate allocator
  2960. instance for each VM space (actually, two instances each for global and
  2961. local spaces; see <a href="#save_forgetsave_restore">below</a>). In a
  2962. system with multiple contexts and multiple global or local VMs, each global
  2963. or local VM has its own allocator instance(s).
  2964. <p>
  2965. Refs that represent PostScript composite objects, and therefore include
  2966. pointers to stored data, include a 2-bit VM space tag to indicate in which
  2967. VM the object data are stored. In addition to system, global, and local VM,
  2968. there is a tag for "foreign" VM, which means that the memory is not managed
  2969. by a Ghostscript allocator at all. Every store into a composite object must
  2970. check for <b><tt>invalidaccess</tt></b>: the VM space tag values are chosen
  2971. to help make this check efficient. See <a
  2972. href="../src/ivmspace.h">src/ivmspace.h</a>, <a
  2973. href="../src/iref.h">src/iref.h</a>, and <a
  2974. href="../src/store.h">src/store.h</a> for details.
  2975. <dl>
  2976. <dt>
  2977. Files:
  2978. <dd>
  2979. <a href="../src/ivmspace.h">src/ivmspace.h</a>.
  2980. </dl>
  2981. <p>
  2982. PostScript composite objects (arrays and dictionaries) are usually small.
  2983. Using a separate memory manager object for each composite object would waste
  2984. a lot of space for object headers. Therefore, the interpreter's memory
  2985. manager packs multiple composite objects (also called "ref-containing
  2986. objects") into a single memory manager object, similar to the way the memory
  2987. manager packs multiple objects into a chunk (see <a
  2988. href="#Standard_implementation">above</a>). See <a
  2989. href="../src/gxalloc.h">src/gxalloc.h</a> for details. This memory manager
  2990. object has a structure descriptor, like all other memory manager objects.
  2991. <p>
  2992. Note that the <b><tt>value.pdict</tt></b>, <b><tt>value.refs</tt></b>, or
  2993. <b><tt>value.packed</tt></b> member of a ref must point to a PostScript
  2994. composite object, and therefore can point into the middle of a memory
  2995. manager object. This requires special handling by the garbage collector (<a
  2996. href="#Interpreter_GC">q.v.</a>).
  2997. <dl>
  2998. <dt>
  2999. Files:
  3000. <dd>
  3001. <a href="../src/ialloc.c">src/ialloc.c</a>,
  3002. <a href="../src/ialloc.h">src/ialloc.h</a>,
  3003. <a href="../src/iastate.h">src/iastate.h</a>,
  3004. <a href="../src/iastruct.h">src/iastruct.h</a>,
  3005. <a href="../src/ilocate.c">src/ilocate.c</a>,
  3006. <a href="../src/imemory.h">src/imemory.h</a>,
  3007. <a href="../src/istruct.h">src/istruct.h</a>.
  3008. </dl>
  3009. <h4><a name="save_forgetsave_restore"></a>save/.forgetsave/restore</h4>
  3010. <p>
  3011. In addition to <b><tt>save</tt></b> and <b><tt>restore</tt></b>, Ghostscript
  3012. provides a <b><tt>.forgetsave</tt></b> operator that makes things as though
  3013. a given <b><tt>save</tt></b> had never happened. (In data base terminology,
  3014. <b><tt>save</tt></b> is "begin transaction", <b><tt>restore</tt></b> is
  3015. "abort transaction", and <b><tt>.forgetsave</tt></b> is "end/commit
  3016. transaction"). <b><tt>.forgetsave</tt></b> was implemented for a specific
  3017. commercial customer (who may no longer even be using it): it was a pain to
  3018. make work, but it's in the code now, and should be maintained. See the
  3019. extensive comments in <a href="../src/isave.c">src/isave.c</a> for more
  3020. information about how these operations work.
  3021. <dl>
  3022. <dt>
  3023. Files:
  3024. <dd>
  3025. <a href="../src/idosave.h">src/idosave.h</a>,
  3026. <a href="../src/isave.c">src/isave.c</a>,
  3027. <a href="../src/isave.h">src/isave.h</a>,
  3028. <a href="../src/isstate.h">src/isstate.h</a>,
  3029. <a href="../src/store.h">src/store.h</a>.
  3030. </dl>
  3031. <h4><a name="Stable_allocators"></a>Stable allocators</h4>
  3032. <p>
  3033. Even though <b><tt>save</tt></b> and <b><tt>restore</tt></b> are concepts
  3034. from the PostScript interpreter, the generic allocator architecture and API
  3035. include a feature to support them, called <em>stable</em> allocators. Every
  3036. allocator has an associated stable allocator, which tags pointers with the
  3037. same VM space number but which is not subject to <b><tt>save</tt></b> and
  3038. <b><tt>restore</tt></b>. System VM is intrinsically stable (its associated
  3039. stable allocator is the same allocator), so there are only 5 allocators in
  3040. ordinary single-context usage: system VM, stable global VM, ordinary global
  3041. VM, stable local VM, ordinary local VM.
  3042. <p>
  3043. The reason that we cannot simply allocate all stable objects in system VM is
  3044. that their refs must still be tagged with the correct VM space number, so
  3045. that the check against storing pointers from global VM to local VM can be
  3046. enforced properly.
  3047. <p>
  3048. All PostScript objects are normally allocated with the non-stable
  3049. allocators. The stable allocators should be used with care, since using
  3050. them can easily create dangling pointers: if storage allocated with a stable
  3051. allocator contains any references to PostScript objects, the client is
  3052. responsible for ensuring that the references don't outlive the referenced
  3053. objects, normally by ensuring that any such referenced objects are allocated
  3054. at the outermost <b><tt>save</tt></b> level. (The original reason for
  3055. wanting stable allocators was the PostScript stacks, which are essentially
  3056. PostScript arrays but are not subject to <b><tt>save</tt></b> and
  3057. <b><tt>restore</tt></b>.) For more examples, search the sources for
  3058. references to <b><tt>gs_memory_stable</tt></b>.
  3059. <h4><a name="Interpreter_GC"></a>Garbage collection</h4>
  3060. <p>
  3061. The interpreter's garbage collector is a compacting, non-conservative,
  3062. mark-and-sweep collector.
  3063. <ul>
  3064. <li>It compacts storage because that is the only way to avoid permanent
  3065. sandbars, which is essential in limited-memory environments.
  3066. <li>It is non-conservative because conservative collectors (which attempt
  3067. to determine whether arbitrary bit patterns are pointers) cannot compact.
  3068. <li>It uses mark-and-sweep, rather than a more modern copying approach,
  3069. because it cannot afford the extra memory required for copying.
  3070. </ul>
  3071. <p>
  3072. Roots for tracing must be registered with the allocator. Most roots are
  3073. registered during initialization.
  3074. <p>
  3075. "Mark-and-sweep" is a bit of a misnomer. The garbage collector actually has
  3076. 5 main phases:
  3077. <ul>
  3078. <li>Sweep to clear marks;
  3079. <li>Trace and mark;
  3080. <li>Sweep to compute relocation;
  3081. <li>Sweep to relocate pointers;
  3082. <li>Sweep and compact.
  3083. </ul>
  3084. <p>
  3085. There is some extra complexity to handle collecting local VM only. In this
  3086. case, all pointers in global VM are treated as roots, and global VM is not
  3087. compacted.
  3088. <p>
  3089. As noted above, PostScript arrays and strings can have refs that point
  3090. within them (because of <b><tt>getinterval</tt></b>). Thus the garbage
  3091. collector must mark each element of an array, and even each byte of a
  3092. string, individually. Specifically, it marks objects, refs, and strings
  3093. using 3 different mechanisms:
  3094. <ul>
  3095. <li>Objects have a mark bit in their header: see
  3096. <a href="../src/gxobj.h">src/gxobj.h</a>,
  3097. <li>Refs and packed refs have a reserved mark bit: see <a
  3098. href="../src/iref.h">src/iref.h</a> and <a
  3099. href="../src/ipacked.h">src/ipacked.h</a>.
  3100. <li>Strings use a separate bit table, with one bit per string byte: see
  3101. <a href="../src/gxalloc.h">src/gxalloc.h</a>,
  3102. </ul>
  3103. <p>
  3104. Similarly, it records the relocation information for objects, refs, and
  3105. strings differently:
  3106. <ul>
  3107. <li>Objects record relocation in the object header.
  3108. <li>Refs record relocation in unused fields of refs such as nulls that
  3109. don't use their <b><tt>value</tt></b> field. Every memory manager object
  3110. that stores ref-containing objects as described above has an extra, unused
  3111. ref at the end for this purpose.
  3112. <li>Strings use a separate relocation table.
  3113. </ul>
  3114. <dl>
  3115. <dt>
  3116. Files:
  3117. <dd>
  3118. <a href="../src/igc.c">src/igc.c</a>,
  3119. <a href="../src/igc.h">src/igc.h</a>,
  3120. <a href="../src/igcref.c">src/igcref.c</a>,
  3121. <a href="../src/igcstr.c">src/igcstr.c</a>,
  3122. <a href="../src/igcstr.h">src/igcstr.h</a>,
  3123. <a href="../src/ireclaim.c">src/ireclaim.c</a>.
  3124. </dl>
  3125. <hr>
  3126. <h2><a name="Portability"></a>Portability</h2>
  3127. <p>
  3128. One of Ghostscript's most important features is its great portability across
  3129. platforms (CPUs, operating systems, compilers, and build tools). The code
  3130. supports portability through two mechanisms:
  3131. <ul>
  3132. <li><a href="#Structural">Structural mechanisms</a> -- segregating
  3133. platform-dependent information into files in a particular way.
  3134. <li><a href="#Coding">Coding standards</a> -- avoiding relying on byte
  3135. order, scalar size, and platform-specific compiler or library features.
  3136. </ul>
  3137. <h3><a name="Structural"></a>Structural</h3>
  3138. <h4><a name="CPU_and_compiler"></a>CPU and compiler</h4>
  3139. <p>
  3140. Ghostscript attempts to discover characteristics of the CPU and compiler
  3141. automatically during the build process, by compiling and then executing a
  3142. program called <b><tt>genarch</tt></b>. <b><tt>genarch</tt></b> generates a
  3143. file <b><tt>obj/arch.h</tt></b>, which almost all Ghostscript files then
  3144. include. This works well for things like word size, byte order, and
  3145. floating point representation, but it can't determine whether or not a
  3146. compiler supports a particular feature, because if a feature is absent, the
  3147. compilation may fail.
  3148. <dl>
  3149. <dt>
  3150. Files:
  3151. <dd>
  3152. <a href="../src/genarch.c">src/genarch.c</a>,
  3153. <a href="../obj/arch.h">obj/arch.h</a>.
  3154. </dl>
  3155. <h4><a name="Library_headers"></a>Library headers</h4>
  3156. <p>
  3157. Despite the supposed standardization of ANSI C, platforms vary considerably
  3158. in where (and whether) they provide various standard library facilities.
  3159. Currently, Ghostscript's build process doesn't attempt to sort this out
  3160. automatically. Instead, for each library header file
  3161. <b><tt>&lt;</tt></b><em>xxx</em><b><tt>.h&gt;</tt></b> there is a
  3162. corresponding Ghostscript source file
  3163. <b><tt>src/</tt></b><em>xxx</em><b><tt>_.h</tt></b>, containing a set of
  3164. compile-time conditionals that attempt to select the correct platform header
  3165. file, or in some cases substitute Ghostscript's own code for a missing
  3166. facility. You may need to edit these files when moving to platforms with
  3167. unusually non-standard libraries.
  3168. <dl>
  3169. <dt>
  3170. Files:
  3171. <dd>
  3172. <a href="../src/ctype_.h">src/ctype_.h</a>,
  3173. <a href="../src/dirent_.h">src/dirent_.h</a>,
  3174. <a href="../src/dos_.h">src/dos_.h</a>,
  3175. <a href="../src/errno_.h">src/errno_.h</a>,
  3176. <a href="../src/fcntl_.h">src/fcntl_.h</a>,
  3177. <a href="../src/jerror_.h">src/jerror_.h</a>,
  3178. <a href="../src/malloc_.h">src/malloc_.h</a>,
  3179. <a href="../src/math_.h">src/math_.h</a>,
  3180. <a href="../src/memory_.h">src/memory_.h</a>,
  3181. <a href="../src/pipe_.h">src/pipe_.h</a>,
  3182. <a href="../src/png_.h">src/png_.h</a>,
  3183. <a href="../src/stat_.h">src/stat_.h</a>,
  3184. <a href="../src/stdio_.h">src/stdio_.h</a>,
  3185. <a href="../src/string_.h">src/string_.h</a>,
  3186. <a href="../src/time_.h">src/time_.h</a>,
  3187. <a href="../src/unistd_.h">src/unistd_.h</a>,
  3188. <a href="../src/vmsmath.h">src/vmsmath.h</a>,
  3189. <a href="../src/windows_.h">src/windows_.h</a>,
  3190. <a href="../src/x_.h">src/x_.h</a>.
  3191. </dl>
  3192. <p>
  3193. It has been suggested that the GNU <b><tt>configure</tt></b> scripts do the
  3194. above better, for Unix systems, than Ghostscript's current methods. While
  3195. this may be true, we have found <b><tt>configure</tt></b> scripts difficult
  3196. to write, understand, and maintain; and the <b><tt>autoconf</tt></b> tool
  3197. for generating <b><tt>configure</tt></b> scripts, which we found easy to
  3198. use, doesn't cover much of the ground that Ghostscript requires.
  3199. <h4><a name="Cross_platform_APIs"></a>Cross-platform APIs</h4>
  3200. <p>
  3201. For a few library facilities that are available on all platforms but are not
  3202. well standardized, or that may need to be changed for special environments,
  3203. Ghostscript defines its own APIs. It is an architectural property of
  3204. Ghostscript that the implementations of these APIs are the only .c files for
  3205. which the choice of platform (as opposed to choices of drivers or optional
  3206. features) determines whether they are compiled and linked into an
  3207. executable.
  3208. <dl>
  3209. <dt>
  3210. API:
  3211. <dd>
  3212. <a href="../src/gp.h">src/gp.h</a>,
  3213. <a href="../src/gpcheck.h">src/gpcheck.h</a>,
  3214. <a href="../src/gpgetenv.h">src/gpgetenv.h</a>,
  3215. <a href="../src/gpmisc.h">src/gpmisc.h</a>,
  3216. <a href="../src/gpsync.h">src/gpsync.h</a>.
  3217. <dt>
  3218. Implementation files shared among multiple platforms:
  3219. <dd>
  3220. <a href="../src/gp_getnv.c">src/gp_getnv.c</a>,
  3221. <a href="../src/gp_mktmp.c">src/gp_mktmp.c</a>,
  3222. <a href="../src/gp_nsync.c">src/gp_nsync.c</a>,
  3223. <a href="../src/gp_psync.c">src/gp_psync.c</a>,
  3224. <a href="../src/gp_strdl.c">src/gp_strdl.c</a>,
  3225. <a href="../src/gpmisc.c">src/gpmisc.c</a>.
  3226. <dt>
  3227. Platform-specific implementation files:
  3228. <dd>
  3229. <a href="../src/gp_dosfe.c">src/gp_dosfe.c</a>,
  3230. <a href="../src/gp_dosfs.c">src/gp_dosfs.c</a>,
  3231. <a href="../src/gp_dvx.c">src/gp_dvx.c</a>,
  3232. <a href="../src/gp_iwatc.c">src/gp_iwatc.c</a>,
  3233. <a href="../src/gp_msdos.c">src/gp_msdos.c</a>,
  3234. <a href="../src/gp_mshdl.c">src/gp_mshdl.c</a>,
  3235. <a href="../src/gp_msio.c">src/gp_msio.c</a>,
  3236. <a href="../src/gp_mslib.c">src/gp_mslib.c</a>,
  3237. <a href="../src/gp_mswin.c">src/gp_mswin.c</a>,
  3238. <a href="../src/gp_mswin.h">src/gp_mswin.h</a>,
  3239. <a href="../src/gp_ntfs.c">src/gp_ntfs.c</a>,
  3240. <a href="../src/gp_os2.c">src/gp_os2.c</a>,
  3241. <a href="../src/gp_os9.c">src/gp_os9.c</a>,
  3242. <a href="../src/gp_stdia.c">src/gp_stdia.c</a>,
  3243. <a href="../src/gp_stdin.c">src/gp_stdin.c</a>,
  3244. <a href="../src/gp_sysv.c">src/gp_sysv.c</a>,
  3245. <a href="../src/gp_unifn.c">src/gp_unifn.c</a>,
  3246. <a href="../src/gp_unifs.c">src/gp_unifs.c</a>,
  3247. <a href="../src/gp_unix.c">src/gp_unix.c</a>,
  3248. <a href="../src/gp_vms.c">src/gp_vms.c</a>,
  3249. <a href="../src/gp_wgetv.c">src/gp_wgetv.c</a>,
  3250. <a href="../src/gp_win32.c">src/gp_win32.c</a>,
  3251. <a href="../src/gp_wsync.c">src/gp_wsync.c</a>.
  3252. </dl>
  3253. <h4><a name="Makefiles"></a>Makefiles</h4>
  3254. <p>
  3255. For information on the structure and conventions used within makefiles, see
  3256. the <a href="#Makefile_structure">Makefile structure</a> section above.
  3257. <p>
  3258. Ghostscript's makefiles are structured very similarly to the cross-platform
  3259. library files. The great majority of the makefiles are portable across all
  3260. platforms and all versions of <b><tt>make</tt></b>. To achieve this, the
  3261. platform-independent makefiles must obey two constraints beyond those of the
  3262. POSIX <b><tt>make</tt></b> program:
  3263. <ul>
  3264. <li>No conditionals or <b><tt>include</tt></b>s are allowed. While most
  3265. <b><tt>make</tt></b> programs now provide some form of conditional execution
  3266. and some form of inclusion, there is no agreement on the syntax.
  3267. (Conditionals and includes are allowed in platform-dependent makefiles; in
  3268. fact, an inclusion facility is required.)
  3269. <li>There must be a space on both sides of the : that separates the target
  3270. of a rule from its dependencies. This is required for compatibility with
  3271. the OpenVMS <b><tt>MMS</tt></b> and <b><tt>MMK</tt></b> programs.
  3272. </ul>
  3273. <p>
  3274. The top-level makefile for each platform (where "platform" includes the OS,
  3275. the compiler, and the flavor of <b><tt>make</tt></b>) contains all the build
  3276. options, plus <b><tt>include</tt></b>s for the generic makefiles and any
  3277. platform-dependent makefiles that are shared among multiple platforms.
  3278. <p>
  3279. While most of the top-level makefiles build a PostScript and/or PDF
  3280. interpreter configuration, there are also a few makefiles that build a test
  3281. program that only uses the graphics library without any language
  3282. interpreter. Among other things, this can be helpful in verifying that no
  3283. accidental dependencies on the interpreter have crept into the library or
  3284. drivers.
  3285. <p>
  3286. For families of similar platforms, the question arises whether to use
  3287. multiple top-level makefiles, or whether to use a single top-level makefile
  3288. that may require minor editing for some (or all) platforms. Ghostscript
  3289. currently uses the following top-level makefiles for building interpreter
  3290. configurations:
  3291. <ul>
  3292. <li>Unix (including Linux):
  3293. <ul>
  3294. <li><a href="../src/unix-gcc.mak">src/unix-gcc.mak</a>,
  3295. for Unix with gcc.
  3296. <li><a href="../src/unixansi.mak">src/unixansi.mak</a>,
  3297. for Unix with an ANSI C compiler other than gcc.
  3298. <li><a href="../src/unixtrad.mak">src/unixtrad.mak</a>,
  3299. for Unix with a "traditional" or "K&amp;R" compiler.
  3300. </ul>
  3301. <li>PC:
  3302. <ul>
  3303. <li><a href="../src/bcwin32.mak">src/bcwin32.mak</a>,
  3304. for MS Windows with Borland C++ Builder.
  3305. <li><a href="../src/msvc32.mak">src/msvc32.mak</a>,
  3306. for MS Windows with Microsoft Visual C (MSVC).
  3307. <li><a href="../src/os2.mak">src/os2.mak</a>,
  3308. for MS-DOS or OS/2 GCC/EMX environment.
  3309. <li><a href="../src/watc.mak">src/watc.mak</a>,
  3310. for extended MS-DOS with Watcom C.
  3311. <li><a href="../src/watcw32.mak">src/watcw32.mak</a>,
  3312. for MS Windows with Watcom C.
  3313. </ul>
  3314. <li>Macintosh:
  3315. <ul>
  3316. <li><a href="../src/macos-mcp.mak">src/macos-mcp.mak</a>,
  3317. for Macintosh MCP.
  3318. </ul>
  3319. <li>Other:
  3320. <ul>
  3321. <li><a href="../src/all-arch.mak">src/all-arch.mak</a>,
  3322. for building on many Unix systems in a networked test environment.
  3323. <li><a href="../src/dvx-gcc.mak">src/dvx-gcc.mak</a>,
  3324. for DesqView/X with gcc.
  3325. <li><a href="../src/openvms.mak">src/openvms.mak</a>,
  3326. for OpenVMS with Digital's CC compiler and the MMS build program.
  3327. <li><a href="../src/openvms.mmk">src/openvms.mmk</a>,
  3328. for OpenVMS with Digital's CC compiler and the MMK build program.
  3329. </ul>
  3330. </ul>
  3331. <p>
  3332. The following top-level makefiles build the library test program:
  3333. <ul>
  3334. <li><a href="../src/ugcclib.mak">src/ugcclib.mak</a>,
  3335. on Unix with gcc.
  3336. <li><a href="../src/msvclib.mak">src/msvclib.mak</a>,
  3337. on MS Windows with MSVC.
  3338. <li><a href="../src/watclib.mak">src/watclib.mak</a>,
  3339. on extended MS-DOS with Watcom C.
  3340. </ul>
  3341. <p>
  3342. The MSVC makefiles may require editing to select between different versions
  3343. of MSVC, since different versions may have slightly incompatible command
  3344. line switches or customary installation path names. The Unix makefiles
  3345. often require editing to deal with differing library path names and/or
  3346. library names. For details, see <a href="Make.htm#Unix_build">the Unix
  3347. section</a> of the documentation for building Ghostscript.
  3348. <dl>
  3349. <dt>
  3350. Library test program:
  3351. <dd>
  3352. <a href="../src/gslib.c">src/gslib.c</a>.
  3353. <dt>
  3354. Platform-independent makefiles:
  3355. <dd>
  3356. <dl>
  3357. <dt>
  3358. Graphics library and support:
  3359. <dd>
  3360. <a href="../src/contrib.mak">src/contrib.mak</a>,
  3361. <a href="../src/devs.mak">src/devs.mak</a>,
  3362. <a href="../src/gs.mak">src/gs.mak</a>,
  3363. <a href="../src/lib.mak">src/lib.mak</a>,
  3364. <a href="../src/version.mak">src/version.mak</a>.
  3365. <dt>
  3366. PostScript interpreter and fonts:
  3367. <dd>
  3368. <a href="../src/cfonts.mak">src/cfonts.mak</a>,
  3369. <a href="../src/int.mak">src/int.mak</a>,
  3370. <a href="../src/wmin.mak">src/wmin.mak</a>.
  3371. <dt>
  3372. Third-party libraries:
  3373. <dd>
  3374. <a href="../src/icclib.mak">src/icclib.mak</a>,
  3375. <a href="../src/ijs.mak">src/ijs.mak</a>,
  3376. <a href="../src/jpeg.mak">src/jpeg.mak</a>,
  3377. <a href="../src/libpng.mak">src/libpng.mak</a>,
  3378. <a href="../src/zlib.mak">src/zlib.mak</a>.
  3379. </dl>
  3380. <dt>
  3381. Shared platform-dependent makefiles:
  3382. <dd>
  3383. <dl>
  3384. <dt>
  3385. Unix:
  3386. <dd>
  3387. <a href="../src/unix-aux.mak">src/unix-aux.mak</a>,
  3388. <a href="../src/unix-dll.mak">src/unix-dll.mak</a>,
  3389. <a href="../src/unix-end.mak">src/unix-end.mak</a>,
  3390. <a href="../src/unixhead.mak">src/unixhead.mak</a>,
  3391. <a href="../src/unixinst.mak">src/unixinst.mak</a>,
  3392. <a href="../src/unixlink.mak">src/unixlink.mak</a>.
  3393. <dt>
  3394. Microsoft Windows and MS-DOS:
  3395. <dd>
  3396. <a href="../src/msvccmd.mak">src/msvccmd.mak</a>,
  3397. <a href="../src/msvctail.mak">src/msvctail.mak</a>,
  3398. <a href="../src/pcwin.mak">src/pcwin.mak</a>,
  3399. <a href="../src/wccommon.mak">src/wccommon.mak</a>,
  3400. <a href="../src/wctail.mak">src/wctail.mak</a>,
  3401. <a href="../src/winint.mak">src/winint.mak</a>,
  3402. <a href="../src/winlib.mak">src/winlib.mak</a>,
  3403. <a href="../src/winplat.mak">src/winplat.mak</a>.
  3404. <dt>
  3405. Other:
  3406. <dd>
  3407. <a href="../src/dvx-head.mak">src/dvx-head.mak</a>,
  3408. <a href="../src/dvx-tail.mak">src/dvx-tail.mak</a>.
  3409. </dl>
  3410. </dl>
  3411. <h3><a name="Coding"></a>Coding</h3>
  3412. <p>
  3413. Coding for portability requires avoiding both <em>explicit</em>
  3414. dependencies, such as platform-dependent <b><tt>#ifdef</tt></b>s, and
  3415. <em>implicit</em> dependencies, such as dependencies on byte order or the
  3416. size of the integral types.
  3417. <h4><a name="Explicit_dependencies"></a>Explicit dependencies</h4>
  3418. <p>
  3419. The platform-independent .c files never, ever, use <b><tt>#ifdef</tt></b> or
  3420. <b><tt>#if</tt></b> to select code for specific platforms. Instead, we
  3421. always try to characterize some abstract property that is being tested. For
  3422. example, rather than checking for macros that are defined on those specific
  3423. platforms that have 64-bit <b><tt>long</tt></b> values, we define a macro
  3424. <b><tt>ARCH_SIZEOF_LONG</tt></b> that can then be tested. Such macros are
  3425. always defined in a .h file, either automatically in <b><tt>arch.h</tt></b>,
  3426. or explicitly in a <em>xxx</em><b><tt>_.h</tt></b> file, as described in
  3427. earlier sections.
  3428. <dl>
  3429. <dt>
  3430. Files:
  3431. <dd>
  3432. <a href="../src/std.h">src/std.h</a>,
  3433. <a href="../src/stdpre.h">src/stdpre.h</a>.
  3434. </dl>
  3435. <h4><a name="Implicit_dependencies"></a>Implicit dependencies</h4>
  3436. <p>
  3437. The most common source of byte ordering dependencies is casting between
  3438. types (T1 *) and (T2 *) where T1 and T2 are numeric types that aren't merely
  3439. signed/unsigned variants of each other. To avoid this, the only casts
  3440. allowed in the code are between numeric types, from a pointer type to a long
  3441. integral type, and between pointer types.
  3442. <p>
  3443. Ghostscript's code assumes the following about the sizes of various types:
  3444. <dl>
  3445. <dt>char<dd>8 bits
  3446. <dt>short<dd>16 bits
  3447. <dt>int<dd>32 or 64 bits
  3448. <dt>long<dd>32 or 64 bits
  3449. <dt>float<dd>32 bits (may work with 64 bits)
  3450. <dt>double<dd>64 bits (may work with 128 bits)
  3451. </dl>
  3452. <p>
  3453. The code does not assume that the <b><tt>char</tt></b> type is signed (or
  3454. unsigned); except for places where the value is always a literal string, or
  3455. for interfacing to library procedures, the code uses <b><tt>byte</tt></b> (a
  3456. Ghostscript synonym for <b><tt>unsigned char</tt></b>) almost everywhere.
  3457. <p>
  3458. Pointers are signed on some platforms and unsigned on others. In the few
  3459. places in the memory manager where it's necessary to reliably order-compare
  3460. (as opposed to equality-compare) pointers that aren't known to point to the
  3461. same allocated block of memory, the code uses the
  3462. <b><tt>PTR_</tt></b><em>relation</em> macros rather than direct comparisons.
  3463. <p>
  3464. See the files listed above for other situations where a macro provides
  3465. platform-independence or a workaround for bugs in specific compilers or
  3466. libraries (of which there are a distressing number).
  3467. <h4><a name="Platform_specific_code"></a>Platform-specific code</h4>
  3468. <p>
  3469. There are some features that are inherently platform-specific:
  3470. <ul>
  3471. <li>Microsoft Windows requires a lot of special top-level code, and also has
  3472. an installer and uninstaller.
  3473. <li>OS/2 requires a little special code.
  3474. <li>MacOS also requires special top-level code (now distributed with the
  3475. standard Ghostscript package).
  3476. <li>All platforms supporting DLLs (currently all three of the above) share
  3477. some special top-level code.
  3478. </ul>
  3479. <dl>
  3480. <dt>
  3481. MS Windows files:
  3482. <dd>
  3483. <a href="../src/dpmain.c">src/dpmain.c</a>,
  3484. <a href="../src/dwdll.c">src/dwdll.c</a>,
  3485. <a href="../src/dwdll.h">src/dwdll.h</a>,
  3486. <a href="../src/dwimg.c">src/dwimg.c</a>,
  3487. <a href="../src/dwimg.h">src/dwimg.h</a>,
  3488. <a href="../src/dwinst.cpp">src/dwinst.cpp</a>,
  3489. <a href="../src/dwinst.h">src/dwinst.h</a>,
  3490. <a href="../src/dwmain.c">src/dwmain.c</a>,
  3491. <a href="../src/dwmain.h">src/dwmain.h</a>,
  3492. <a href="../src/dwmainc.c">src/dwmainc.c</a>,
  3493. <a href="../src/dwnodll.c">src/dwnodll.c</a>,
  3494. <a href="../src/dwreg.c">src/dwreg.c</a>,
  3495. <a href="../src/dwreg.h">src/dwreg.h</a>,
  3496. <a href="../src/dwsetup.cpp">src/dwsetup.cpp</a>,
  3497. <a href="../src/dwsetup.h">src/dwsetup.h</a>,
  3498. <a href="../src/dwtext.c">src/dwtext.c</a>,
  3499. <a href="../src/dwtext.h">src/dwtext.h</a>,
  3500. <a href="../src/dwuninst.cpp">src/dwuninst.cpp</a>,
  3501. <a href="../src/dwuninst.h">src/dwuninst.h</a>,
  3502. <a href="../src/gp_msdll.c">src/gp_msdll.c</a>,
  3503. <a href="../src/gp_mspol.c">src/gp_mspol.c</a>,
  3504. <a href="../src/gp_msprn.c">src/gp_msprn.c</a>,
  3505. <a href="../src/gs16spl.c">src/gs16spl.c</a>,
  3506. <a href="../src/gsdllwin.h">src/gsdllwin.h</a>.
  3507. <dt>
  3508. OS/2 files:
  3509. <dd>
  3510. <a href="../src/gsdllos2.h">src/gsdllos2.h</a>.
  3511. <dt>
  3512. Unix files:
  3513. <dd>
  3514. <a href="../src/dxmain.c">src/dxmain.c</a>.
  3515. <a href="../src/dxmainc.c">src/dxmainc.c</a>.
  3516. <dt>
  3517. Macintosh files:
  3518. <dd>
  3519. <a href="../src/gdevmac.c">src/gdevmac.c</a>.
  3520. <a href="../src/gdevmac.h">src/gdevmac.h</a>.
  3521. <a href="../src/gdevmacpictop.h">src/gdevmacpictop.h</a>.
  3522. <a href="../src/gdevmacttf.h">src/gdevmacttf.h</a>.
  3523. <a href="../src/gdevmacxf.c">src/gdevmacxf.c</a>.
  3524. <a href="../src/gp_mac.c">src/gp_mac.c</a>.
  3525. <a href="../src/gp_mac.h">src/gp_mac.h</a>.
  3526. <a href="../src/gp_macio.c">src/gp_macio.c</a>.
  3527. <a href="../src/macgenmcpxml.sh">src/macgenmcpxml.sh</a>.
  3528. <a href="../src/macsysstat.h">src/macsysstat.h</a>.
  3529. <a href="../src/macsystypes.h">src/macsystypes.h</a>.
  3530. <dt>
  3531. VMS files:
  3532. <dd>
  3533. <a href="../src/vms_x_fix.h">src/vms_x_fix.h</a>.
  3534. <dt>
  3535. DLL files:
  3536. <dd>
  3537. <a href="../src/gsdll.c">src/gsdll.c</a>,
  3538. <a href="../src/gsdll.h">src/gsdll.h</a>,
  3539. <a href="../src/gdevdsp.c">src/gdevdsp.c</a>,
  3540. <a href="../src/gdevdsp.h">src/gdevdsp.h</a>,
  3541. <a href="../src/gdevdsp2.h">src/gdevdsp2.h</a>,
  3542. <a href="../src/iapi.c">src/iapi.c</a>,
  3543. <a href="../src/iapi.h">src/iapi.h</a>,
  3544. <a href="../src/idisp.c">src/idisp.c</a>,
  3545. <a href="../src/idisp.h">src/idisp.h</a>.
  3546. <p>
  3547. The new DLL interface (new as of 7.0) is especially useful with the
  3548. new display device, so it is included here. Both are due to Russell
  3549. Lang.
  3550. </dl>
  3551. <hr>
  3552. <h2><a name="Adding_features_and_options"></a>Adding features and options</h2>
  3553. <p>
  3554. [Ray, please supply more information about what you want here]
  3555. <h2><a name="Troubleshooting"></a>Troubleshooting</h2>
  3556. <p>
  3557. The Ghostscript code has many tracing and debugging features that can be
  3558. enabled at run time using the <b><tt>-Z</tt></b> command line switch, if the
  3559. executable was compiled with <b><tt>DEBUG</tt></b> defined. One
  3560. particularly useful combination is <b><tt>-Z@\?</tt></b>, which fills free
  3561. memory blocks with a pattern and also turns on run-time memory consistency
  3562. checking. For more information, see <a
  3563. href="Use.htm#Debugging">doc/Use.htm#Debugging</a>; you can also search for
  3564. occurrences of <b><tt>if_debug</tt></b> or <b><tt>gs_debug_c</tt></b> in the
  3565. source code. Note that many of these features are in the graphics library
  3566. and do not require a PostScript interpreter.
  3567. <p>
  3568. The code also contains many run-time procedures whose only purpose is to be
  3569. called from the debugger to print out various data structures, including all
  3570. the procedures in <a href="../src/idebug.c">src/idebug.c</a> (for the
  3571. PostScript interpreter) and the <b><tt>debug_dump_</tt></b> procedures in <a
  3572. href="../src/gsmisc.c">src/gsmisc.c</a>.
  3573. <dl>
  3574. <dt>
  3575. Files:
  3576. <dd>
  3577. <a href="Use.htm#Debugging">doc/Use.htm#Debugging</a>,
  3578. <a href="../src/gdebug.h">src/gdebug.h</a>,
  3579. <a href="../src/gsmdebug.h">src/gsmdebug.h</a>,
  3580. <a href="../src/idebug.h">src/idebug.h</a>,
  3581. <a href="../src/idebug.c">src/idebug.c</a>.
  3582. </dl>
  3583. <!-- [2.0 end contents] ==================================================== -->
  3584. <!-- [3.0 begin visible trailer] =========================================== -->
  3585. <hr>
  3586. <p>
  3587. <small>Copyright &copy; 2001 artofcode LLC.
  3588. All rights reserved.</small>
  3589. <p>
  3590. <small>This file is part of AFPL Ghostscript. See the <a
  3591. href="Public.htm">Aladdin Free Public License</a> (the "License") for full
  3592. details of the terms of using, copying, modifying, and redistributing
  3593. AFPL Ghostscript.</small>
  3594. <p>
  3595. <small>Ghostscript version 7.04, 31 January 2002
  3596. <!-- [3.0 end visible trailer] ============================================= -->
  3597. </body>
  3598. </html>