OS2 Presentation Manager
OS2 Presentation Manager
Graham C. E. Winn
Rvffi\S?# a !K:: - ELJ a ELi !k3 iE€! A,f:BRA Fed?i i E-= |€iB
To Chris, Caroline, and Duncan
AIl rights reserved. No part of this work covered by the copyright hereon may be
reproduced or used in any form or by any means-graphic, electronic, or mechanical,
including photocopying, recording, taping, or information storage and retrieval
systems--without written permission of the publisher.
Manufactured in the United States of America
Published by Van Nostrand Reinhold
115 Fifth Avenue
New York, New York 10003
M]/ 7DE]Eli DDli
Chapman and Hall
2rfe Boundny Row
I.ondon, SE 1 8HN, England
Preface xl
Acknowledgments x]l[
Trademarks xw
iii
iv CONTENTS
DisplaywindowDCs 41
QueuedDCs 42
DirectDCs 42
InfoDCs 42
MetaFileDCs 42
MemoryDCs 43
PRESENTATION SPACES 43
Micro-PS 43
Normal-PS 43
CachedMicro-PS 43
PS CREATIONAND ASSOCIATION 44
GPI SETPS 46
surm4ARy OF ps AND Dc CREATION AND
ASSOCIATION 46
DisplaywindowDC 46
Non-Display window DC 46
Normal-Ps or uncached Micro-PS 46
Association of DC and a Normal-PS or an uncached
Micro-PS 46
Allocatiorroe-Allocation of cached Micro-PS/DC pair for a
window 46
Allocatiolroe-Allocation of cached Micro-Psroc for
WM_PAINT processing 46
Use of an existing PS and associated window DC for
WM_PAINT processing 47
Allocation and De-Allocation of cached Micro-Psroc pair for
thedesktop 47
GPICREATEPS IIARAMETERS 47
hab 47
hdc 47
psizlps 47
floptions 48
Retumvalue 49
PS AND DC CONTROLAND QUERY FUNCTIONS 49
DevEscape 49
DevQuerycaps 50
GpiErase 50
GpiQueryDevice 50
Gpikesetps 50
Gpisaveps/GpiFlestoreps 50
usset(ABB_SET) 79
ussymbol (ABB_SYMBOL) 80
ptlRefpoint (ABB_REF_POINT) 80
AreaHimitives 81
MARKERFUNCTIONS 82
Marker Bundle Attributes 82
lcolor orBB_COLOR) 82
lBackcolor orBB_BACK_COLOR) 82
usMixMode orBB_MIX_MODE) 82
usBackMixMode orBB_BACK_MIX_MODE) 83
ussetorBB_SET) 83
ussymbol orBB_SYMBOL) 83
sizfxcell orBB_BOX) 83
Marker Himitives 84
GpiMarker 84
GpipolyMarker 84
IMAGE AND BITBLTFUNCTIONS 84
Image Bundle Attributes 84
lcolor (IBB_COLOR) 84
lBackcolor (IBB_BACK_COLOR) 84
usMixMode (IBB_MIX_MODE) 85
usBackMixMode (IBB_BACK_MIX_MODE) 85
Image and BitBlt Drawing llrimitives 85
Gpilmage 85
GpiBitBit 85
GpiwcBitBlt 89
PATH S 90
Geometric wide Line Attributes (used with paths) 90
lGeomwidth (LBB_GEOM_WIDTH) 90
usEnd (LBB_END) 90
usJoin (LBB_JOIN) 91
Path Definition 91
Pathdreas 92
Pathoutlines 93
Geometric wide Lines 93
Clippaths 94
Chapter4 Fonts 98
PUBLIC AND PRIVATE FONTS 100
MONOSPACED AND PROPORTIONAL FONTS 101
RASTERAND OUTLINE FONTS 101
FONT METRICS 104
FONT SELECTION AND LOGICAL FONT CREATION 107
CONTENTS vii
Glossary 301
Index 313
Preface
The OSATM I+esentation ManagerTM provides a rich and powerful set of applica-
tion programming interfaces which, to a newcomer, can appear rather complex
and confusing. Many Ospe application developers use software tools (such as
application generators) or languages which shield them from the complexities of
the application programming interface and serve as a useful productivity aid. The
ma].ority of these are designed specifically for text based applications that require
only the graphical user interface and it is currently necessary for programs to use
the Graphics Programming Interface directly in order to exploit the full graphics
capabilities of the OSA FTesentation Manager. This book is written for C program-
mers wishing to use the OSA I+esentation Manager GPI and Dev functions for
providing high quality te]it and graphics output to displays and printers. It is
intended to be used along with the relevant IBMTM and MicrosoftTM Reference
Manuals and Online Reference, and is not a substitute for these.
My aim in writing this book is, as far as possible, to provide answers
(illustrated by programming examples) to any questions that Application Devel-
opers may have concerning the GPI and Dev functions. Rather than providing a
tutorial description, I have concentrated on making the description of each topic
as comprehensive as possible. Chapter 1 provides an introduction and explains
how to output simple graphics and text to displays and printers. The remaining
chapters provide an in-depth description of each subject, illustrated where
appropriate by examples consisting of simple, self-contained program functions.
Also included in the main body of the text is a description of the underlying GPI
Architecture to assist readers in understanding a particular function.
Some familiarity with OSA Presentation Manager Hogramming funda-
mentals by the reader is assumed. The reader should, as a minimum, be able to
write a basic I}resentation Manager application in C to create a message queue
and standard window, with a window procedure that processes the messages.
xl
xii PREFACE
Although the main subject of this book is graphics, it is written for non-mathe-
maticians. Where mathematics is essential (e.g., in the treatment of transforms),
it is kept to a mininum. Both GPI and Dev functions are described, and where
there is overlap with other components (such as the Win and nrf functions), a
description of these is also provided.
This book is based on IBM OSA Version 1.3 and includes a discussion of Version
2.0.
Acknowledgment
I would like to thank my many friends and colleagues without whose knowledge,
help, support, encouragement, and willingness to review my work, this book would
not have been possible. I would like to give special thanks to the following people:
David Edwards, Heather Gill, Nick Goodall, Mike Jewson, Pete Johnson, Kelvin
Lawrence, Glyn Normington, Kate Robinson, Sushil Sharma, Robin Speed, Mike
Walker, Ken Wilson, and Ian Yorke-Smith. I would also like to thank IBM for
providing me with the opportunity and facilities to complete this work. Finally, I
would like to thank my family for their support and encouragement.
xiii
Trademarks
The following terms used in this publication are trademarks or registered trade-
marks of International Business Machines Corporation in the U.S.A. andyor other
countries:
XV
Introduction: Simple Text and Graphics Output
This chapter describes how to generate simple GPI text and graphics output to
displays and printers, and introduces a number of important rules and concepts
required for the more advanced topics described in subsequent chapters.
The GPI (Graphics FTogramming Interface) enables a Presentation Manager
Application I+ogram to produce high quality text and graphics output to a variety
of output devices. These include both displays and printers and a number of
`special purpose' virtual output devices such as bitmaps and MetaFiles. Output
can, in fact, be directed at any of the following:
• A window on a display screen.
• A printer or plotter device.
• A memory bitmap (i.e., a memory pixel aITay).
• A memory MetaFile (for recording a picture for interchange).
• An information only context useful for querying device information
without incurring all of the memory overheads associated with dis-
playing output.
• Any other device or virtual device for which a I}resentation Driver
(i.e., Hesentation Manager Device Driver) exists.
The GPI graphics subsystem is illustrated in Figure 1-1 and consists of a hierar-
chy of layers below the application. These are the GPI layer, the Graphics Engine,
the Hesentation Driver, and, in the case of certain devices such as printers, the
appropriate Osve Kernel Device Driver. Current Display Presentation Drivers
communicate directly with the display adapter, whereas FTinter I+esentation
Drivers convert the low level graphics calls presented at their Device Driver
1
2 0S/2 PRESENTATION MANAGER GPI
APPLICATION as, I 2.
REREL
I)EVICE
I)RIVER
(NON
DISPLAY
I)EVIC.r:S
ONLY)
Interface (DDI) into raw printer data, and pass this to the OSA Kernel Pr.int
Device Driver.
Data ownership is also encapsulated within the different layers. The GPI layer
owns the I+esentation Space (PS), the Graphics Engine owns the Device Context
(DC), and the ELesentation Driver owns an extension of the Device Contezit called
the Device Drawing Context (DDC).
Although Figure 1-1 correctly illustrates GPI graphics output for displays and
directly attached printers, the situation when printing via the spooler is rather
more complex (see chapter 12).
GPI function calls are targeted at a FTesentation Space (PS) associated (i.e.,
linked) with a Device Contezat (DC). The DC identifies both the target output
device and the instance of that device (such as a printer or display window) to
which the output is directed. The DC stores such items as the current drawing
attribute values (color, mix, line style, etc.). Memory MetaFiles and Bitmaps also
receive output via DCs of the appropriate type associated with the target PS.
The PS stores presentation space environment attributes and resources. Its
purpose is to retain this information between application calls and across associ-
ations and disassociations of the PS with different DCs. PS data is normally, but
not exclusively, device independent and a PS may also optionally retain (i.e., store)
the entire picture.
For the majority of applications that require only a subset of the GPI functions, a
special PS called a Micro-PS should be used. This has a smaller memory overhead
than a Normal-PS. Also, where large numbers windows each require a PS and DC
for a short sequence of operations, a variation of the Micro-PS called a cached
Micro-PS may be used to allow a PS and DC to be shared between different windows.
(see chapter 2 for a detailed description of device contexts and presentation spaces.)
INTRODUCTION: SIMPLE TEXT AND GRAPHICS OUTPUT 3
Output of a simple tezit string (say) to a display window requires the following
steps:
1. Obtain a Dc forthe window.
2. Create a ps and associatethe ps andDC.
3. Drawthe text stringto the ps.
4. Destroy the ps if no longer required.
This is illustrated by the function OutputTowindow in Figure 1-2. Note that
WinopenwindowDC can be used only once to open the window DC which then
remains open until the window is destroyed. Thereafter the DC handle can be
obtained using WinQuerywindowDC. Note also that a DC can be associated only
with a single PS, and Gpicreateps (with the GPI_ASSOC option) will therefore
fail if the window DC is already associated.
Performing an equivalent operation for a printer (or plotter) requires the
following steps:
1. Query the printer DRIVDATA (driver data).
2. Open a Device context (DC) for the printer.
3. Create a ps and associatethe ps and DC.
4. Issue a `Start Document' escape to the device.
5. Draw the text stringto the ps.
6. Issue an `End Document' escape to the device.
7. Destroy the ps if no longer required.
8. Close the I+inter DC if no longer required. Note that a printer DC
(unlike a window DC) can be destroyed.
This is illustrated by the function OutputTonrinter in Figure 1-3. The Out-
putTowindow function in Figure 1-2 could have been implemented in a variety of
different ways. A PS type of GPIT_MICRO was, in fact, used to create a Micro-PS,
whereas a Normal or cached Micro-PS could have been used instead.
A number of different character string functions are also available. The function
used, GpicharstringAt, draws a character string starting from a specified posi-
tion. The GPI maintains a current drawing position attribute intemally that is
updated by most GPI output operations (including Gpichar.StringAt). This attri-
bute can also be set directly from an application using Gpisetcurrentposition or
GpiMove. Many GPI functions, including Gpicharstring, draw from (and update)
the current position. The function GpicharstringAt is therefore equivalent to:
Gpisetcurrentposition; and
Gpicharstring.
These two functions could therefore have been used in place of the single
GpicharstringAt function. Note that in the function OutputTowindow, PU ARBI-
TRARY page units are specified together with a default PS page size ;f zero.
PU_ARBITRARY page units cause the specified PS page to be scaled to fit the
4 0S/2 PRESENTATION MANAGER Gpl
available device output area while preserving the aspect ratio (such that a circle
remains a circle). In the case of a display window, the available device output area
is assumed to be constant and equal to the screen size. Either or both PS page
dimensions may be defaulted by specifying as zero, in which case they are
determined by the dimensions of the device output area Out note that for a printer
this is NOT the same as the cu]nent fo]rm. size).
Otherpageunitsarealsoavailable.Anapplicationwishingtodrawindeviceunits
should specify page units of PU_PELS whereas PU_TWIPS, PU_LOENGLISH,
PU_HIENGLISH, PU_LOMETRIC, and PU_HIMETRIC are available for drawing
objectsofspecifiedsizeinmillimetersorinches.TheoutputTonrinterfunctionuses
PS page units of PU_LOMETRIC (i.e., 0.1Inm) and the PS page size is selected to
match the 8.5xll inch printer form. PU_LOMETRIC page units were chosen be-
causetheformsizeinform.ationreturmedbyDevQueryHardcopycaps(usedlater)is
in millimeters. The precise PS page size values are generally unimportant for page
units other than PU_ARBITRARY Out very small values should be avoided).
Chapter 12 describes how the queue name ®szQueue), printer name ®sznrin-
ter), driver name ®szDriver), and device name ®szDevice) used by OutputTol}rin-
ter can be queried from the INI file. For the moment, however, hardcoded string
constants (e.g., "LASER1" or "LPI`1Q") copied from the nrint Manager dialogs will
suffice. Note that some printer drivers (e.g., IBM4019) support only a single device
and require a NULL device name, whereas others (e.g., LASERJET.HPTM
LaseruetTMplus) have a dot qualified extension that must be specified as the device
name.
Consider now the requirement to output a telit file first to a display window and
then to a printer. Assume the text file has already been read into a memory buffer
(e.g. , using DosAllocate-Dosopen-DosRead-Dosclose).
Clearly, the entire contents of the buffer are unlikely to fit on the display screen
simultaneously and scrolling must therefore be provided. The function Dis-
playTextBuffer in Figure 14 illustrates how this may be accomplished (this
function can, in fact, be substituted for GpicharstringAt in the OutputTowindow
function described earlier).
DisplayTextBuffer begins by erasing the window and resetting the default view
matrix before querying the font metrics. The font metrics provide the character
width and height values needed to convert the row and column scroll offsets into
world (i.e., drawing) coordinates. WinQuerywindowRect is used to determine the
top window coordinate (in pels) and Gpiconvert converts this to world coordinates.
The function GpisetDefaultviewMatrix is used to provide the translation required
by the (lRow, lcol) scroll parameters and GpicharstringAt is used to draw each
row of text. Output begins at the start of the text, works downward, and termi-
mates when the bottom of the window is reached.
The requirements of a function that outputs text to a printer are slightly
different from those of one that outputs to a display. Clearly, the printer is unable
INTRODualoN: slMPLE TEXT AND GRAPHlcs ouTpuT 5
Graphics differ from text in that they use a bottom left origin, whereas text
normally uses top left as illustrated above.
Each primitive group has its own attribute bundle (or structure) containing the
attributes for that particular primitive type. Instances of color and mix attributes
appear in all attribute bundles and are known as `global attributes.' Other bundle
attributes appear in only a single bundle. Exalnples of the latter are the area fill
pattern and character direction. Other general attributes apply to all primitives
and are not part of any attribute bundle. Exalnples of these are the Current
Position, Model Thansform, and Viewing (clip) Limits.
As mentioned above, the appearance (color, size, etc.) of GPI graphics output is
controlled by the bundle attributes for the primitive type concerned, which may be
set to the required values before drawing. For characters, the CIIARBUNDIE
(character bundle) is used; for lines, the LINEBUNDLE (line bundle) is used; for
areas, the AREABUNDLE (area bundle) is used; for markers, the MARKERBUN-
DLE (marker bundle) is used; and for BitBlt and image, the IMAGEBUNDLE
(image bundle) is used. It is not essential to set the bundle attributes before
drawing as the default value can be used for most bundle attributes ®undle
attributes are reset to default by GpiResetps). Note, however, that for most
devices, the default character set is a raster font and several of the CIIARBUNDLE
attributes are ignored for character mode CM MODE 1 raster characters. For those
devices that provide an outline font as the -default, the character box attribute
(height and width) must be set to the required character box size in world coordi-
mates to ensure that correctly sized characters are obtained. Character angle,
direction, and shear attributes can be defaulted for both outline and raster fonts.
The functions DrawText, DrawLines, DrawArea, DrawMarkers, and WCBitBlt
in Figures lno to 1-10 set each of the appropriate bundle attributes before
performing the text, line, area, marker or BitBlt output operation. Note that in the
case of DrawLines, certain of the LINEBUNDLE attributes that apply exclusively
to paths are not referenced by this function. These are discussed in chapter 3. In
the WCBitBlt example, the bitmap used would typically have been created using
the icon editor and included in the .rc file using a statement of the form:
Simple Transformations
The GPI transform functions enable rotation, scaling, and translation of subse-
quent output to be controlled by a transformi matrix attribute.
There are a number of different transforms to choose from but in general, the
model transform can be varied during drawing for the purpose of picture construc-
tion (i.e., picture modeling) and the default viewing transformi should be used for
scaling and scrolling and remain constant for the complete picture. The examples
in this section use the model transfo]rm. but apply equally to the default viewing
transform (although rotations other than 90 degrees would not normally be
applied to the whole picture).
INTRODUCTION: SIMPLE TEXT AND GRAPHICS OUTPUT I
The function Rotate in Figure 1-11 illustrates how a figure can be rotated about
a given point in the figure (note that rotation about the origin would produce an
additional undesired translation). The function Scale in Figure 1-12 illustrates
how a figure can be scaled relative to a given point in the figure (note that scaling
relative to the origin would produce an additional undesired translation). The
function Thanslate in Figure 1-13 illustrates how a figure can be translated by a
specified amount.
The `transformi helper functions,' GpiRotate, Gpiscale, and GpiThanslate, sim-
plify transformi construction but are not absolutely essential. It is possible to
calculate the correct matrix values and obtain the required result by a sequence
of set transfo]rm matrix operations (see chapter 7).
The GPI model views the graphics functions as belonging to one of two groups:
• Picture Functions; or
• PS Environment and Resource Functions.
Picture Functions are drawing primitive functions (such as line, arc, character
string) and drawing attribute setting functions (such as set color, set mix) used to
construct the picture and vary the drawing attributes as the picture is drawn. Any
function that can cause a graphics order to be built and stored in a retained
graphics segment (see chapter 9) can be regarded as a picture function. In addition,
there are a small number of picture functions for non-retained use only that do not
add an order to a retained segment. These are:
GpiBitBlt;
Gpipaintkegion;
Gpisetpel; and
WinDraw functions (e.g. , WinDrawText).
Except for the default attribute functions (which are envirormient attributes),
picture functions are those functions described in chapter 3. All other functions are
Environment and Resource Functions (or neither).
Environment and Resource Functions are functions that create and load re-
sources (such as logical fonts and color tables) or functions that establish environ-
ment attributes (such as graphics field and default viewing transform). These
shouldgenerallybeestablishedbeforethepictureisdrawnandremainunchanged
during drawing (although it is permissible to incrementally create and load
additional resources as they are needed). Of course it is quite possible for an
application to vary the resources and environment attributes during picture
construction. However, apart from this being unnecessary because of the rich set
of picture functions available, there are other good reasons for not doing so. It is
8 0S/2 PRESENTATION MANAGER GPI
extremely useful to have functions such as Graphics Field and Default Viewing
Thansfo]rm available exclusively for defining rectangular clipping and scaling for
the complete picture. Also, if the picture is to be recorded in a MetaFile for
interchange, an SAA conforming MetaFile will not be produced if environlnent
attributes or resources are modified during picture constmction. Such a MetaFile
will not properly conformi to the interchange architecture and, although it will
normally interchange successfully with other OSA nresentation Manager sys-
tens, picture information will be lost, or errors will occur, if interchange is
attempted with other products that support this architecture.
performingoptimizations.Forexample,ifpardofthewindowneedstoberepainted
and the area to be repainted does not intersect the bounding rectangle then no
drawing (other than an erase) need occur. The picture boundary data can also be
used to predict whether a particular transfo]rm operation will result in coordinate
overflow (see chapter 7).
ColTelation is provided for interactive graphics. A frequent end-user operation
is that of selecting an object on a display screen by pointing using a mouse and
screen pointer or cursor. The object might then, for example, be dragged to a
different position, changed to a different color or deleted by the user. To identify
the object, the application must determine which primitive or primitive group from
the picture corresponds to the screen coordinates of this selection.
Correlation assists this operation by establishing a movable correlation rectan-
gle (which an application would typically move with the pointer) and identifying
to the application which drawing primitives or retained graphics segments inter-
sect this rectangle. This correlation rectangle is known as the pick aperture.
Coordinates
Many GPI functions have one or more coordinate pairs as a parameter. In most
cases the coordinates are defined in a space known as world coordinate space, but
some functions require their coordinates to be specified in an intermediate space
above the device (e.g., the PS page) whereas others are specified directly in device
coordinates. World coordinates, as they are called, and other intermediate coordi-
nates are transformed by the various GPI transforms down to the device, produc-
ing output in device coordinates. These non-device coordinates are specified as 32
bit integers that must be in the (28 bit) range OxF8000000J)x07FFFFFF (i.e.,
-134217728 to 134217727). Furthermore, when transformed to device space, the
resultant device coordinates must be in the (16 bit) range OxFFFF8000-
Ox00007FFF (-32768 to 32767). This 16 bit restriction also applies to device
coordinates that are specified directly. These restrictions are necessary to avoid
coordinate overflow.
When GPI drawing primitives are used to construct a retained graphics picture or
recorded in a MetaFile, graphics drawing orders containing primitive coordinates
are built and accumulated in graphics segments. Depending on the coordinate
format option specified with Gpicreateps, drawing order coordinates are either
stored in long (4 byte) format which is the default, or short (2 byte) format.
Coordinates stored in short format require less memory for retained picture and
MetaFile storage but it is the responsibility of the application to ensure that
truncation of 32 bit primitive coordinates to 16 bit order coordinates does not result
inlossofdata(alargepositivevaluegreaterthan32767couldappearnegativeafter
truncation). For performance reasons, no checking is performed by the system.
10 0S/2 PRESENTATION MANAGER GPI
Rectangle Boundaries
FIXED Numbers
A number of GPI functions have parameters of type FIXED. Examples are char-
acter box attribute and transfo]rm matrix elements in the earlier examples. FIXED
numbers are signed 4 byte numbers with a notional decimal point between the
middle two bytes. This representation can be viewed as the original number
multiplied by 65.536. For example:
2.5 is Ox00028000;
2.0 is Ox00020000;
1.0 is OxOOO10000;
0.5 is OxOOOO8000;
0.25 is Ox00004000;
0.125 is Ox00002000;
etc.
INTRODUCTION: SIMPLE TEXT AND GRAPHICS OUTPUT 11
FIXED numbers obey all the normal rules of binary arithmetic and negative values
aresimplythetwoscomplementofthecorTespondingpositivenumber.Forexample:
Error Handling
GpiErrorsegmentData
For retained segment functions, this returns the segment name and element
number at which the error occurred. For GpiputData or GpiElement, it returns
the byte offset into the buffer at which the error occurred.
optowi.nd.c */
OutputTowi.ndow(HWND hwnd)
I :***************************************************************************** I
/**/
/* Obtai.n a Devi.ce Context (DC) for the wl.ndow. */
/**/
/******************************************************************************-/
/* query Wl.ndow DC
hdc = W1.nQueryw1.ndowDC(hwnd); /* -wl.ndow handle
I.f (hdc == NULL) /* open wi.ndow DC I.f NULL
hdc = Wl.nopenwl.ndowDC(hwnd) /* -wi.ndow handle
/ :.***************************************************************************** I
(: CreateaGpi presentatlonspace(PS)andassociatethepsandDC :)
1******************************************************************************-I
/ ****************************************************************************** /
/**/
/* Draw the text stri.ng to the PS. */
/**/
/ ****************************************************************************** 1
/ ****************************************************************************** 1
/**/
/* Destroy the PS. */
/**/
/ ****************************************************************************** /
/* destroy the PS
Gpi.Destroyps( hps ); /* -PS handle
return ;
/* Optoprtr.c */
VOID 0utputToprl.nter(
I,*,*****************************************************************************/
/* */
"Prl.nt Job„
#defi.ne PDOCNAME
#defi.ne PDOCNAMELEN ( LONG ) s i zeof ( PDOCNAM E )
"Gpi Prl.nt Text'.
#defi.ne GPIPTEXT
#defi.ne NGPIPTEXT ( LONG ) ( s 1. zeof ( GP I PTEXT ) -1 )
I,:.:**+**********************+*************************************+************1
/* */
/i Query the prl.nter drl.ver data. */
/* */
/***************+**************************************************************I/
: #rl.ver ;: :3::#:TAa::l.nter
pszDevl.ce /* -devl.ce name
pszprinter /* -pri.nter name
DPDM_QUERYJ0BPROP /* -opti.ons
in
/* query DRIVDATA
DevpostDevl.ceModes( hab /* -anchor block handle
pdri.vData /* -DRIVDATA poi.nter
pszDri.ver /* -dri.ver name
pszDevi.ce /* -devi.ce name
pszpri.nter /* -pri.nter name
DPDM_QUERYJ0BPROP /* -Optl.ons
):
/,*f****************************************************************************/
/L
/* */
/: Open a Devi.ce context (DC) for the prl.nter. */
/* *//
/******************************************************************************'/
/ ****************************************************************************** /
/**/
/* Create a Gpl. Presentatl.on Space (PS) and assocl.ate the PS and DC */
/**/
/ ****************************************************************************** 1
/ ****************************************************************************** 1
/**/
/* Issue a 'Start Document' escape to the pri.nter. */
/**/
1 ****************************************************************************** 1
/ ****************************************************************************** /
/**/
/* Draw the text strl.ng to the PS. */
/**/
/ ****************************************************************************** 1
/:_:***************************************+************************************1
/* */
/* Issue a .End Document. escape to the prl.nter. */
/* */
/******************************************************************************'1
/,*.***********************************************************************k*****1
/*
I
*/
/? Destroy the ps. */
/* */
1*********************************************+********************************'1
/,*+****************************************************************************/
rl IIT
/* */
/I Destroy the DC. */
/* */
/****************************************************************+*************'1
/* Close the DC
DevcloseDC( hdc ); /* -DC handle
return ;
dl.sptext.c */
D Di.splayTextBuffer(HPS hps, HWND hwnd, PCH pchData, LONG IRow, LONG ICol)
Di.splay a buffer of text, typl.cally read from a text fi.1e, i.n the
speci.fi.ed wi.ndow (vi.a the speci.fi.ed PS) usl.ng the current font.
PS handle
wi.ndow handle
row ori.gi.n (scrolli.ng offset)
colum orl.gi.n (scrolli.ng offset)
poi.nter to text buffer
I ****************************************************************************** I
/**/
/* Erase the wi.ndow and reset the default vi.ew matrl.x. */
/**/
1 ****************************************************************************** I
G p i. E r a s e ( h p s ) : /* -PS handle */
matlfDV.IM31 = OL;
matlfDV.IM32 = OL;
Gpi.SetDefaultvi.ewMatri.x( hps /* -PS handle */
9L /* -count of matri.x elements */
&matlfDV /* -transform matri.x */
TRANSFORM_REPLACE /* -opti.ons */
in
/ ****************************************************************************** /
/**/
/* Query the metrl.cs of the current font. */
/**/
1 ****************************************************************************** I
/ ****************************************************************************** 1
/**/
/* Query the wi.ndow coordl.nates 1.n pels and use thi.s to determi.ne the */
/* maxi.mum wi.ndow y coordi.nate i.n world coordi.nates. */
/* Ini.ti.all.ze the x and y starti.ng coordi.nates to top left of the wi.ndow */
/* and the row poi.nter to the buffer start. */
/**/
1****************************************************************************** I
ptlposn.x = OL:
ptlposn.y -= fmMetrl.cs.1MaxAscender;
pchRow = pchData:
1 ****************************************************************************** I
/**/
/* Set the Default Vi.ew Matri.x translatl.on to provi.de the speci.fi.ed */
/* (row, column) scroll offsets. */
/**/
I ****************************************************************************** I
/ ****************************************************************************** 1
/**/
/* Locate newll.ne, carri.age return or end of fl.le to fi.nd end of fl.rst row. */
/**/
/ ****************************************************************************** I
/ ****************************************************************************** /
/**/
/* Whi.1e end-of-fi.le has not been reached perform the followi.ng: */
/* 1. Draw characters i.n current row. */
/* 2. Process carri.age return and newll.ne at row end. */
/* 3. If bottom of wi.ndow 1.s reached then break (to i.mprove performance). */
/* 4. Locate end of next row. */
/**/
/ ************+***************************************************************** I
pchRow += 1Count;
whi.1e (*pchRow == .\r. || *pchRow == '\n')
(
l.f (*pchRow == .\r' )
ptlposn.x -OL:
else
ptlposn.y -= (fmMetrl.cs.1MaxBasell.neExt + fmMetrl.cs.1ExternalLeadl.ng);
pchROw++;
)
pri.ntext.c */
D Prl.ntTextBuffer(HPS hps, PCH pchData)
4. .start document' and lend document' escapes are 1.ssued by the caller
before and after i.nvocati.on.
1 ****************************************************************************** 1
/**/
/* margi.ns are defi.ned 1.n PU_LOMETRIC uni.ts of 0.1 mm */
/**/
/ ****************************************************************************** I
/ ****************************************************************************** /
/**/
/* Query the handle of the associ.ated DC. */
/**/
/ ****************************************************************************** /
/ ****************************************************************************** 1
/**/
/* Query the metrl.cs of the current font. */
/**/
/ ****************************************************************************** 1
/****************************************************************************** /
/**/
/* Determi.ne the paper si.ze and cli.p boundari.es of the current form. */
/* 1. Query number of forms. */
/* 2. Allocate Memory. */
/* 3. Query the forms. */
/* 4. Locate the current form. */
/* 5. Convert the forms 1.nformati.on from mm to PU_LOMETRIC uni.ts of 0.1 mm. */
/* 6. Free the memory. */
/**/
/ ****************************************************************************** 1
1FormHei.ght = phcl.Forms[i.].cy * 10 ;
lFormwi.dth = phci.Forms[i.].cx * 10 ;
1FormTopclip = phci.Forms[i.].yTopcli.p * 10:
lFormBottomcli.p = phci.Forms[i.].yBottomcli.p * 10 :
lFormLeftcli.p = phcl.Forms[i.].xLeftcli.p * 10 ;
/ ****************************************************************************** /
/**/
/* Set graphi.cs fl.eld to cli.p at ri.ght margi.n. */
/**/
/ ****************************************************************************** 1
rclFi.eld.xLeft = OL:
rclFi.eld.yBottom = OL:
rclFl.eld.yTop = lFormHel.ght;
rclFi.eld.xRight = lFormwi.dth -RIGHTMARGIN
Gpi.SetGraphi.csFi.eld( hps /* -PS handle
&rclField /* -graphi.cs fi.eld
);
1 ****************************************************************************** /
/**/
/* Inl.tl.all.ze drawl.ng posi.ti.on to top left and row pol.nter to buffer start. */
/**/
/ ****************************************************************************** I
/ ****************************************************************************** 1
/**/
/* Locate newli.ne, carri.age return or end of fi.le to fi.nd end of fi.rst row. */
/**/
1 ****************************************************************************** I
/ ****************************************************************************** 1
/**/
/* Whi.le end-of-fi.1e has not been reached perform the followi.ng: */
/* 1. Draw characters i.n current row. */
/* 2. Process carri.age return and newll.ne at row end. */
/* 3. If at bottom of page i.ssue 'new frame' escape & reset drawl.ng posi.ti.on.*/
/* 4. Locate end of next row. */
/**/
I ****************************************************************************** 1
pchRow += lcount;
whi.le (*pchRow == '\r' || *pchRow == '\n')
(
i.f (*pchRow == '\r' )
ptlposn.x = max(LEFTMARGIN,1FormLeftcli.p):
else
ptlposn.y -= (fmMetrl.cs.1MaxBasell.neExt + fmMetrl.cs.1ExternalLeadi.ng);
pchROw++:
)
drawtext.c */
DrawText(HPS hps)
Reset the PS, erase the wl.ndow, set the CHARBUNDLE (character bundle)
attri.butes and draw some text.
Note that for most devl.ces the default character set 1.s a raster font
and several CHARBUNDLE attri.butes are 1.gnored for CM_MODEl raster
characters. For those devi.ces that provi.de a vector font as default
the character box attrl.bute should be set to the requl.red character
hei.ght l.n world coordl.nates. Character angle, dl.rectl.on and shear can
be defaulted.
/ ****************************************************************************** /
/**/
/* Reset the PS and erase the wl.ndow. */
/**/
/ ****************************************************************************** 1
/ ****************************************************************************** I
/**/
/* Set the CHARBUNDLE attri.butes. */
/**/
/ ****************************************************************************** I
in
/* set character set (normally
/* default for si.mple text)
Gpi.Setcharset( hps /* -PS handle
LCID_DEFAULT /* -character set
in
/* set character mode (normally
/* default CM_MODEl for sl.mple text)
G p i. S e t C h a r M o d e ( hps /* -PS handle
CM MODE1 /* -character mode
in
/* set character box (l.gnored for
s I. z f x C h a r 8 o x . c x = MAKEFIXED(50,0); /* raster fonts: requi.red for all
s I. z fxc h a r 8 ox . cy = MAKEFIXED(50,0); /* outli.ne fonts I.n all modes)
G p I. S e t C h a r 8 o x ( hps /* -PS handle
& s i. z f x C h a r 8 o x /* -character box (50 x 50)
):
1 ****************************************************************************** I
/**/
/* Draw some text. */
/**/
1****************************************************************************** I
ptlposn.x = SOL:
ptlposn.y = 100L;
Gpi.Move( hps /* -PS handle
&ptlposn /* -coordi.nate posi.ti.on
in
return ;
drawll.ne.c */
DrawLl.nes(HPS hps)
Reset the PS, erase the wl.ndow, set the LINEBUNDLE (line bundle)
attrl.butes and draw some ll.nes (note that those ll.ne bundle attrl.butes
whl.ch apply only to paths are not referenced by thl.s functl.on).
1 ****************************************************************************** I
/**/
/* Reset the PS and erase the wl.ndow. */
/**/
I ****************************************************************************** /
/ ****************************************************************************** I
/**/
/* Set the LINEBUNDLE attrl.butes. */
1**1
/ ****************************************************************************** I
1 ****************************************************************************** 1
/**/
/* Draw some li.nes. */
/**/
/ ****************************************************************************** /
/* -PS handle
1 Posn /* -coordl.nate posi.ti.on
/* -PS handle
1 Posn /* -coordl.nate posl.tl.on
/* -PS handle
1 Posn /* -coordi.nate posl.ti.on
/* -PS handle
tl Posn /* -coordi.nate posi.ti.on
/* -PS handle
1 Posh /* -coordi.nate posi.ti.on
/* -PS handle
1 Posn /* -coordi.nate post.ti.on
return :
drawarea.c */
ID DrawArea(HPS hps)
Reset the PS, erase the window, set the AREABUNDLE (area bundle)
attrl.butes and draw an area.
I ****************************************************************************** I
/**/
/* Reset the PS and erase the wi.ndow. */
/**/
/ ****************************************************************************** I
/****************************************************************************** I
/**/
/* Set the AREABUNDLE attrl.butes. */
/**/
I ****************************************************************************** I
ptlpatRef.x = OL:
ptlpatRef.y -OL: /* set pattern orl.gl.n
Gpi.SetpatternRefpoi.nt( hps /* -PS handle
&ptlpatRef /* -pattern reference poi.nt
);
/ ****************************************************************************** 1
/**/
/* Drawan area. */
/**/
I ****************************************************************************** 1
ptlposn.x = 50L;
ptlposn.y = 100L;
Gpi.Move( hps /* -PS handle */
&ptlposn /* -coordl.nate posl.ti.on */
in
/* -PS handle
tl Posn /* -coordi.nate posi.ti.on
/* -PS handle
/* -coordl.nate posl.tl.on
/* -PS handle
&ptlposn /* -coordi.nate posi.ti.on
);
return :
drawmark.c */
ID DrawMarkers(HPS hps)
Reset the PS, Erase the wl.ndow, set the MARKERBUNDLE (marker bundle)
attri.butes and draw some markers.
I ****************************************************************************** I
/**/
/* Reset the PS and erase the wi.ndow. */
/**/
1 ****************************************************************************** 1
/****************************************************************************** /
/**/
/* Set the MARKERBUNDLE attrl.butes. */
/**/
/ ****************************************************************************** /
1 ****************************************************************************** I
/**/
/* Draw some markers. */
/**/
I ****************************************************************************** I
/* -PS handle
/* -coordi.nate posi.tl.on
/* -PS handle
/* -coordi.nate posi.tl.on
/* -PS handle
/* -coordi.nate posi.ti.on
/* -PS handle
/* -coordl.nate posi.tl.on
/* -PS handle
/* -coordl.nate posi.tl.on
return :
wcbl.tblt.c */
ID WCB1.tBlt(HPS hps, USHORT usBi.tmapld)
Reset the PS, erase the wi.ndow, set the IMAGEBUNDLE (i.mage bundle)
attri.butes and Bi.tBlt to the di.splay.
/************************************************************+***************** I
/**/
/* Load the bi.tmap. */
/**/
1 ****************************************************************************** 1
in
1 ****************************************************************************** /
/**/
/* Reset the PS and erase the wi.ndow. */
/**/
/ ****************************************************************************** I
I ****************************************************************************** /
/**/
/* Set the IMAGEBUNDLE attri.butes. */
/**/
/ ****************************************************************************** I
/ ****************************************************************************** /
/**/
/* Delete the bi.tmap. */
/**/
/ ****************************************************************************** 1
return ;
)
rotate.c */
Rotate(HPS hps)
Erase the wi.ndow, and rotate a fi.gure wi.th i.ts bottom left ori.gi.n
located at (100,150) 30.0 degrees counterclockwl.se about thi.s pol.nt
(usi.ng the model transform matri.x).
/ ****************************************************************************** I
/**/
/* Erase the wi.ndow. */
/**/
1****************************************************************************** I
1 ****************************************************************************** I
/**/
/* Construct and set the model transform matri.x to provi.de the requl.red */
/* rotati.on. */
/**/
/ ****************************************************************************** I
ptlposn.x = 100L;
ptlposn.y = 150L;
Gpi.Rotate( hps /* -PS handle
&matlfModel /* -transform matri.x
TRANSFORM_REPLACE /* -Optl'Ons
MAKEFIXED(30,0) /* -angle of rotation 30.0 deg.
&ptlposn /* -center of rotati.on
n
Gpi.SetModelTransformMatri.x( hps /* -PS handle */
9L /* -number of matri.x elements */
&matlfModel /* -transform matrl.x */
TRANSFORM_ADD /* -Optl`Ons */
in
I ****************************************************************************** I
/**/
/* Draw the figure. */
/**/
/ ****************************************************************************** 1
/* -PS handle
tl Posn /* -coordl.nate posl.tl.on
/* -PS handle
1 Posn /* -coordi.nate posi.ti.on
/* -PS handle
tl Posn /* -coordi.nate posi.ti.on
/* -PS handle
tl Posn /* -coordl.nate posi.tl.on
return :
scale.c */
Scale(HPS hps)
Erase the wi.ndow, and scale a fi.gure wi.th 1.ts bottom left ori.gi.n
located at (100,150) by a factor of 2.01.n both x and y di.rectl.ons
(usi.ng the model transform matri.x).
/ ****************************************************************************** /
/**/
/* Erase the wl.ndow. */
/**/
/ ****************************************************************************** I
1 ****************************************************************************** 1
/**/
/* Construct and set the model transform matrl.x to provl.de the required */
/* scaling. */
/**/
1 ****************************************************************************** I
1 ****************************************************************************** I
/**/
/* Draw the fi.gure. */
/**/
/ ****************************************************************************** I
/* -PS handle
1 Posn /* -coordi.nate posl.ti.on
/* -PS handle
tl Posn /* -coordi.nate posi.ti.on
/* -PS handle
1 Posn /* -coordi.nate posi.tion
/* -PS handle
1 Posn /* -coordl.nate posl.tl.on
return :
translat.c */
ID Translate(HPS hps)
/ ****************************************************************************** /
/**/
/* Erase the wl.ndow. */
/**/
/****************************************************************************** /
/ ****************************************************************************** 1
/**/
/* Construct and set the model transform matrl.x to provl.de the requl.red */
/* translatl.on. */
/**/
/ ****************************************************************************** /
ptlposn.x = 50L:
ptlposn.y = 100L;
Gpi.Translate( hps /* -PS handle */
&matlfModel /* -transform matrl.x */
TRANSFORM_REPLACE /* -Optl'Ons */
&ptlposn /* -translati.on coordi.nates */
in
/ ****************************************************************************** 1
/**/
/* Draw the fl.gure. */
/**/
/ ****************************************************************************** /
/* -PS handle
1 Posn /* -coordi.nate posl.ti.on
/* -PS handle
1 Posn /* -coordi.nate posl.ti.on
/* -PS handle
1 Posn /* -coordi.nate posi.tl.on
/* -PS handle
1 Posn /* -coordi.nate posi.ti.on
return ;
dsppmerr.c */
ID Dl.splaypMError(HAB hab, PSZ pszstri.ng)
PM Error Message 1.s a null terml.nated text strl.ng descrl.bl.ng the PM Error.
The pszstri.ng 1.nput parameter l.s aval.1able for use by the caller, for
example, to i.denti.fy the name of the PM call that failed.
errl.d = Wi.nGetLastError(hab);
perri.Info = Wi.nGetErrorlnfo(hab);
/* 1.f error code l.s PMERR_BASE_ERROR get base OS/2 error code */
sprl.ntf(achoutput,"%x/%x/%d/%s %s\n",
E R R 0 R I D E R R 0 R ( e r r i. d ) , /* PM error code
ERRORI DSEV ( erri d ) , /* severl'ty
sOS2Rc , /* base OS/2 error number
pszErrMsg , /* PM error message
p s z S t r 1' n 9 ) ; /* callers string
if (perrl.Info)
W i. n F r e e E r r o r I n f o ( p e r r 1. I n f o ) ;
return ;
DEVICE CONTEXTS
Display window DCs are created explicitly or, if already created previously,
queried using:
WinopenwindowDC; and
WinQuerywindowDC.
41
42 OS/2 PRESENTATION MANAGER GPI
Display window DCs are also implicitly allocated along with a presentation space
(see below) by:
WinGetps;
WinGetclipps;
WinGetscreenps; and
WinBeginpaint.
All display DCs are window DCs and the window must first be created to enable
its handle to be passed as a parameter to these functions. Display DCs are the only
DCs not created using DevopenDC.
Queued DCs
Queued DCs are used for printing and plotting queued output via the spooler and
are created using DevopenDC with a DC-type parameter of OD_QUEUED.
Direct DCs
Direct DCs are used for printing and plotting directly to a device ®ypassing the
spooler) and are used by the system to print queued print ].obs as they are
dequeued from the print queue. Direct DCs should not normally be used by
applications as, unlike queued DCs, they do not enable an output device to be
properly shared between different applications. Direct DCs are created using
DevopenDC with a DC-type parameter of OD_DIRECT.
Info DCs
Info DCs can be created for any device and have all the characteristics of a normal
DC but produce no output to the device. They have a smaller memory overhead
than a normal DC and exist solely for querying device information (e.g., device
capabilities, device fonts, printer forms, character positioning information). Info
DCs are created using DevopenDC with a DC-type parameter of OD_INFO.
MetaFile DCs
MetaFile DCs are used to record drawing primitives and resources (fonts, color
tables, etc.) in a MetaFile for interchange purposes. When the MetaFile DC is
closed, a memory MetaFile is established and its handle returned to the applica-
tion. The memory MetaFile can then be drawn, passed to other applications via
the clipboard, or saved in application memory or as a file for interchange. MetaFile
DCs are created using DevopenDC with a DC-type parameter of OD_METAFILE
or OD METAFILE_NOQUERY. These two types are the same except that the
latter provides better recording performance at the expense of not allowing
drawing attribute values to be queried.
PRESENTATION SPACES AND DEVICE CONTEXTS 43
Memory DCs
Memory DCs are required for bitmap operations. A bitmap is selected into a
Memory DC in order to draw to it or use it as the target or source of BitBlt
operations. Memory DCs are created using DevopenDC with a DC-type parame-
ter of OD MEMORY.
See Appendix 1 for a full description of DevopenDC parameters.
PRESEHTATIOH SPACES
Micro-PS
Applications, for which a DC alone can retain all the necessary information still
require a PS for consistency but a simple PS, called a Micro-PS, will suffice. A
Micro-PSispermanentlyassociatedwithitsDCandthePSpartofthisPsrocpair
effectively contains only handles of the associated DC and PS resources. A Micro-
PS therefore minimizes the amount of memory required and is fast to create. It
does, however, offer significantly less function than a Normal-PS. A Micro-PS
should be used in preference to a Normal-PS whenever possible.
Normal-PS
Cached Micro-PS
I)evlc®
Dravlng
Context
GPI DDI
Appllcatlon Pr®Bentatlon
Driver
D®vlce
D"t,in8
Context
ANormal-PScanbeassociatedwithaDCand,byspecifyingaNULLDChandle,
disassociated using:
GpiAssociate
As mentioned earlier, a cached Micro-Psroc pair is obtained using:
WinGetps;
WinGetclipps;
WinGetscreenps; and
WinBeginpaint.
WinGetclipps is similar to WinGetps but provides additional clipping.
WinReleaseps must be used with WinGetps/WinGetclipps/WinGetscreenps in
order to return the Psroc pair to the cache. WinBeginpaint and WinGetscreenps
are both for specialized use as described below.
WinBeginpaint is provided for responding to WM_PAINT messages to ensure
that the relevant parts of a window are correctly repainted when `healing' is
required (for example, when an overlaying window is removed). Note that when
an existing PS is available, its handle should be passed to WinBeginpaint as a
parameter rather than requesting the system to allocate a new cached Micro-PS.
Otherwise, a cached Micro-PS can be requested by specifying the PS handle
parameter as NULL prompting WinBeginpaint to allocate a cached Micro-PS and
return its handle. WinEndpaint must follow WinBeginpaint to signal completion
of WM_PAINT processing and to return any cached Psroc pair to the cache.
46 0S/2 PRESENTATION MANAGER GPI
WinGetscreenps will return a cached Psroc pair for the Desk Top window (i.e.,
the entire display screen). This function might be used, for example, by an
application wishing to capture the entire screen in a bitmap for printing. This
function makes it possible for an application to write over any part of the display
screen, including windows owned by other applications, and should, therefore,
only be used with extreme caution. Otherwise, use of WinGetscreenps is the same
as for WinGetps.
GPISETPS
Although the PS page size, page units, and long/short coordinate format specified
on Gpicreateps will often remain unchanged for the life of the PS, they can be
modified together with an optional PS reset using Gpisetps. However, certain
restrictions apply to the use of this function. In particular, it should not be used
for a PS associated with a DC of type OD_QUEUED with data type PM_Q_STD
(see chapter 12), or with a DC of type OD_METAFIIE or OD_METAFILE_NOQU-
ERY (see chapter 11).
Display Window DC
Non-Display Window DC
GPICREATEPS PARAMETERS
nab
hdc
If the GPIA_ASSOC option is specified, this is the handle of the DC with which
the newly created PS is to be associated. If GPIA_NOASSOC is specified this can
be specified as NULL.
psizlps
This specifies the size of the PS page in page units. The marimun. permissible
value for either dimension is Ox07FFFFFF (or 134217727). If GPIA ASSOC is
specified, either or both dimensions may be specified as zero causing them to be
defaulted to a size determined by the associated device output area. If this is a
display window then the defaults are deter.mined by the the screen dimensions. If
the page units are PU_ARBITRARY and only one dimension is defaulted, its value
is set to that which ensures that the picture aspect ratio is preserved. Where both
dimensions are defaulted, the default values are determined by the device pel
dimensions. The actual values of the PS page dimensions are only important in
certain cases as follows:
48 OS/2 PRESENTATION MANAGER GPI
floptions
This specifies a combination of the following:
PS_UNITS specifies page units as one of:
PU_ARBITRARY;
PU_PELS;
PU LOMETRIC;
PU_HIMETRIC;
PU_LOENGLISH;
PU_HIENGLISH; and
PU TWIPS.
See chapter 7 for a description of page units.
PS_FORMAT specifies the long or short retained segment and MetaFile world
coordinate format as one of:
GPIF_LONG (coordinate range is OxF8000000rox07FFFFFF);
GPIF_SHORT (coordinate range is OxFFFF8000rfu00007FFF); and
GPIF_DEFAULT (= GPIF_LONG).
This option controls the size of coordinates stored in the drawing orders of
retained graphics segments and MetaFiles and is ignored for non-retained graph-
ics output. Coordinates stored in GPIF_SHORT format require less memory but it
is the responsibility of the application to ensure that truncation of 32 bit primitive
coordinates to 16 bit order coordinates does not result in loss of data (for example,
PRESENTATION SPACES AND DEVICE CONTEXTS 49
a large positive value greater than 32767 could appear negative after truncation).
For performance reasons this checking is not performed by the system.
PS_TYPE specifies the type of PS (i.e., Micro-PS or Normal-PS) as one of:
GPIT_MICRO; and
GPIT NORhEL.
PS_ASSOC specifies association or no association as one of:
GPIA_ASSOC (mandatory for GPIT_MICRO); and
GPIA NOASSOC.
PS_MODE (the mode option) is not used.
Return Value
The handle of the newly created PS is returned or, if an error was detected, the
error is logged and a NULL PS handle (i.e., GPI_ERROR) is returned.
A number of useful PS control and query functions are provided, several of which
are used in the examples throughout this book.
DevEscape
DevEscape is provided to enable data to be sent directly to or received directly from
a FTesentation (device) Driver, bypassing the GPI. Escape codes may be unique to
a particular driver but a number of predefined codes exist. The most commonly
used are DEVESC STARTDOC, DEVESC ENDDOC, DEVESC ABORTDOC,
DEVESC_NEWFRdrE and DEVESC_RAwi)ATA, which are usea for printing.
DEVESC_STARTDOC and DEVESC_ENDDOC are in fact mandatory for print
jobs and DEVESC_RAWDATA is used to pass raw data (e.g., ASCII text for most
printers) to a Hesentation Driver. When a DevEscape function is issued to a
MetaFile or PM_Q_STD/OD_QUEUED DC, depending on the escape code value,
the function is either processed ilnlnediately by the driver or recorded in the
MetaFile or print file. The action taken for the different escape code ranges is as
follows:
DevQuerycaps
GpiErase
GpiErase is intended primarily for use with displays to erase the window to
background color.
GpiQueryDevice
GpiResetps
GpiResetps resets the presentation space. Three levels of reset are available:
GRES_ATI`RS resets the picture drawing attributes to default.
GRES_SEGMENTS, in addition to performing a GRES_ATrRS
reset operation, destroys all retained graphics segments and resets
all PS environment attributes (e.g., default viewing transform, de-
fault drawing attributes) to their initial value. I.ogical font and color
table resources are preserved.
GRES_ALL performs a full presentation space reset destroying all
resources (i.e., logical fonts and color tables) in addition to perform-
ing GRES_ATTRS and GRES_SEGMENTS reset operations.
Gpisaveps/GpiRestoreps
These are fairly coarse save and restore functions included mainly for compatibil-
ity. As they save and restore a combination of both picture and environment
PRESENTATION SPACES AND DEVICE CONTEXTS 51
information they do not fit tidily into the `picture and environment' model de-
scribed in chapter 1. For this reason, they cannot be used with retained graphics
segments and, if used for recording a MetaFile, will produce a MetaFile that does
not correctly conformi to the interchange architecture.
nmpsdraw.c */
OL NormalpsDraw(HWND hwnd, PDEVOPENDATA pdopData)
"wi.ndow text..
#defl.ne CHSTRW
#defi.ne NCHRSW ( LONG ) ( s I. zeof ( CHSTRW ) -1 )
``printer text..
#defi.ne CHSTRP
#defi.ne NCHRSP ( LONG ) ( s i zeof ( CHSTRP ) -1 )
"Prl.nt Job"
#defi.ne PDOCNAME
#defi.ne PDOCNAMELEN ( LONG ) s 1. zeof ( PDOCNAME )
ptlcoord.x = 100L:
ptlcoord.y = 100L;
I.f (hps!=GPI_ERROR)
fRet = (B00L)Gpi.Charstrl.ngAt
p O 1' n t
characters
s t r 1' n 9
ptlcoord.x = 100L;
ptlcoord.y = 100L:
l'f (fRet)
fRet = (B00L)Gpl.Charstri.ngAt
p o l' n t
characters
s t r 1' n 9
1 Length 2L;
1' f ( f R e t ) /* I.ssue lend document' DevEscape
f Ret = DevEscape( hdcprt /* -DC handle
DEVESC_ENDDOC /* -escape code
OL /* -length of i.nput data (OL)
NULL /* -1.nput data (not used)
&lLength /* -si.ze of output data (2L)
(PBYTE)&usiJobld /* -output data (returned job 1.d)
) --DEV_OK;
return ( fRet ) ;
upswdraw.c */
OL Ml.cropswl.ndowDraw(HWND hwnd)
ptlcoord.x = 100L;
ptlcoord.y = 100L;
if (hps!=GPI_ERROR)
fRet = (B00L)Gpi.Charstri.ngAt
p 0 1' n t
characters
s t r 1` n 9
return ( fRet ) ;
/* upsndraw.c */
B00L Mi.cropsNonDi.splayDraw(HAB hab, PDEVOPENDATA pdopData)
(
/* Usi.ng a non-cached Mi.cro PS, draw to a non-di.splay pri.nter devi.ce as
/* follows:
/*
/* Obtai.n a DC for the pri.nter.
/* Create a Ml.cro-PS and associate wl.th the prl.nter DC.
/* Issue 'start document' DevEscape requi.red by the pri.nter.
/* Draw to the PS.
/* Issue lend document' DevEscape.
/* Di.ssoci.ate the PS from the pri.nter DC.
/* Destroy the PS.
/* Close the pri.nter DC.
/*
/* I.nputs: hwnd Wi.ndow handle
/* pdopData Complete DEVOPENSTRUC structure for the target pri.nter
/* (see PrintDefpri.nter)
/*
/* open non-window DC
hdcprt = DevopenDC( hab /* -anchor block handle
OD_OUEUED /* -DC type
* ,, /* -token
9L /* -count of pdopData elements
pdopData /* -Open DC data
NULL /* -compati.ble hdc (n/a)
n
S1.Zips.CX = Sl.Zips.Cy = OL:
I.f (hdcprt != DEV_ERROR) /* create Mi.cro PS and assocl.ate
hps = Gpi.Createps( hab /* -anchor block handle
hdcprt /* -DC handle
&sl`zlps /* -PS page sl.ze
PU_PELS /* -Optl'Ons
GP I F_D E FAU LT
GPIT MICRO
GPIA-ASSOC
);
ptlcoord.x = 100L:
ptlcoord.y = 100L;
l'f (fRet)
fRet = (B00L)Gpi.Charstri.ngAt
poi nt
characters
s t r 1' n 9
lLength = 2L:
1' f ( f R e t ) /* i.ssue 'end document' DevEscape
fRet DevEscape( hdcprt /* -DC handle
DEVESC_ENDDOC /* -escape code
OL /* -length of 1.nput data (OL)
NULL /* -i.nput data (not used)
&lLength /* -sl.ze of output data (2L)
(PBYTE)&usJobld /* -output data (returned job 1.d)
) --DEV_OK;
return ( fRet ) ;
cachdraw.c */
OL CachedMi.cropswi.ndowDraw(HWND hwnd)
ptlcoord.x = 100L:
ptlcoord.y = 100L:
l.f (hps!=NULL)
fRet = (B00L)Gpi.Charstri.ngAt( hps
&ptlcoord p o l' n t
NCHRSC characters
CHSTRC s t r 1' n 9
in
return ( f Ret ) ;
pwmpai.nt.c */
OL Processwmpai.nt(HWND hwnd, HPS hps)
Perform WM_PAINT processi.ng. If hps 1.s NULL a cached Mi.cro-PS 1.s allocated
and used for the pal.nt. If hps l.s the handle of an exi.sti.ng PS already
associ.ated wi.th a DC for the window then thl.s exl.stl.ng PS l.s used for the
p a 1. n t .
/* begl'n pal.nt
hpspai.nt = Wl.nBegi.npal.nt( hwnd /* -wi.ndow handle
hps /* -ps handle (may be NULL)
&rclRect /* -returned boundl.ng rectangle
in
return ( fRet ) :
ATTRIBUTES
Bundle Attributes
Bundle attributes are those attributes that apply to a particular primitive type
according to the following five groups:
Characters and Text (CIIARBUNDLE);
Lines and Curves (LINEBUNDLE);
Filled Areas or Patterns (AREABUNDLE);
Markers (MARKERBUNDLE); and
Image and BitBlt pixel operations (IMAGEBUNDLE).
59
60 OS/2 PRESENTATION MANAGER GPI
GpisetcharAnglg/GpiQuerycharAngle;
Gpisetcharshear/GpiQuerycharshear; and
GpisetcharDirection/GpiQuerycharDirection.
For the AREABUNDIH these are:
Gpisetpattemset/GpiQuerypattermset;
Gpisetpattexp/GpiQuerypattem (i.e. , symbol); and
GpisetpattemRefpoinvGpiQuerypattermRefpoint.
For the MARKERBUNDLE these are:
GpisetMarkerset/GpiQueryMarkerset;
GpisetMarkel/GpiQueryMarker (i.e., symbol); and
GpisetMarkerBox/GpiQueryMarkerBox (i.e., cell).
All IMAGEBUNDLE attributes are global attributes and so the IMAGEBUNDLE
has no additional functions.
Note that although the `LinewidthGeom' LINEBUNDLE attribute is fully sup-
ported, currently (for IBM OSA Version 1.3 at least), the `Linewidth' attribute has
not been implemented for any device and can only be set to its initial default value
of 1.0.
The bundle attributes are described in detail with their corresponding drawing
primitive descriptions below.
Hen-Bundle Attributes
In addition to the bundle attributes described above, the following non-bundle
attributes exist:
CuITent Position;
Arc Parameters;
Viewing Limits;
Himitive Tag;
Model Thansform Matrix; and
Viewing 'Thansformi Matrix.
The set and query functions for these are:
GpiMovg/Gpisetcurrentposition/GpiQuerycurrentposition;
GpisetArcparamfy/GpiQueryArcparams;
GpisetviewingLimits/GpiQueryviewingLimits;
GpisetTag/GpiQueryTag;
62 0S/2 PRESENTATION MANAGER GPI
A Normal-PS contains a LIFO stack that holds the retu]m information for called
segments. This stack also allows the existing value of any of the above attributes
(except viewing limits and viewing transfo]rm matrix) to be automatically pushed
as a new value is set and restored later using Gpipop. This attribute pushing
occurs if the attribute mode is set to AM PRESERVE. Note that
GpisetcuITentposition allows the current positio= to be pushed whereas
GpiMove, which is otherwise identical, does not. The default (reset) value of
attribute mode is AM_NOPRESERVE. Attribute mode is set and queried using:
DRAwlNG PRIMiTlvES AND AFTRIBUTEs ee
RETAINED
SEGMENT
I)RAVING
ArmlBUThs
GpisetAttrMode; and
GpiQueryAttrMode.
Attributes are restored (or popped) in the reverse order from which they were
pushed. Gpipop includes a count parameter specifying the number of attributes to
be popped. For attributes pushed (and set) using a single global attribute setting
function (e.g., Gpisetcolor), a count of one is sufficient to pop the global attribute
for all bundles. If, however, multiple attributes are pushed (and set) using a single
GpisetAttrs call, a count of more than one is required to pop all the attributes.
Altematively, the attributes may be popped by using Gpipop multiple times with
a smaller count. In this case the attributes are popped in the order in which they
appear in their attribute bundle (i.e., color attribute first).
Unpopped attributes in a chained (root) segment are automatically popped and
discarded at the end the segment during any of the GpiDraw or Gpicorrelate
functions. Unpopped attributes in a called segment are automatically popped and
restored on retu]m to the caller.
Default Atwibutes
The above primitive attribute setting functions allow all attributes to be set to either
a specified or default value. The default values are initialized to defined constant
64 0S/2 PRESENTATION MANAGER GPI
values, certain of which are device dependent, or can be set to application defined
values. The initial default values are listed in the IBM OSA Hogramming Guide.
Default attributes are set to application defined values and queried using:
GpisetDefAttrs/GpiQueryDefAttrs;
GpisetDefArcparamdyGpiQueryDefArcparams;
GpisetDeITag/GpiQueryDeITag; and
GpisetDefviewingLimits/GpiQueryDefviewingLimits.
Unlike the other attribute setting functions described in this chapter, default
attributes are PS environment attributes and, therefore, should not be varied
during drawing.
Attribute Ouery[ng
Functions described earlier enable any drawing attribute value (except viewing
transform matrix) to be queried. It is, however, invalid to attempt to query drawing
attributes under either of the following conditions:
1. When a PS is associated with a DC of type OD_METAFILE_NOQU-
ERY.
2. When an open segment is being updated or edited without being
drawn (i.e., actual drawing mode is RETAIN).
Drawing attributes can be queried but are in an undefined state after any of the
following operations:
GpiDrawsegment;
GpiDrawFrom;
GpiDrawchain;
Gpicorrelatesegment;
GpicoITelateFrom;
Gpicorrelatechain;
Gpicallsegment;
Gpiopensegment (if AITR FASTCIIAIN = ATrR OFF for the
segment); and
Gpiclosesegment.
Attribute Resetting
Drawing attributes are reset to default value by any of the following:
• Any `set attribute' function specifying default value (e.g., GpisetMix
FM_DEFAUIJT).
DRAWING PRIMITIVES AND AFTRIBUTES 65
• GpisetAttrs with a flag set in both the attributes and defaults mask.
• GpiResetps.
• Gpisetps (with PS_NORESET option not specified).
• GpiplayMetaFile (with RES_RESET option specified).
• GpiAssociate.
• Gpiopensegment (in mode DM DRAW or DM DRAWANDRETAIN
ifATI`R_FASTCHAIN=ATI`R_6FF).
• At the start of any root segment during any of the following opera-
tions if ATrR_FASTCHAIN = AITR_OFF for the segment:
Gpicorrelatechain;
GpicoITelateFrom;
Gpicorrelatesegment;
GpiDrawchain;
GpiDrawFrom; and
GpiDrawsegment.
Default drawing attributes are reset to their initial default value by:
• GpisetDefAttrs with a flag set in both Attributes and Defaults Mask.
• GpiResetps (option: GRES_SEGMENTS or GRES_ALL).
• Gpisetps (with PS_NORESET option not specified).
• GpiplayMetaFile (with RES_RESET option specified).
IColor (CBB_COLOR)
lBackcolor (CBB_BACK_COLOR)
usMixMode (CBB_MIX_MODE)
usBackMixMode (CBB_BACK_MIX_MODE)
This specifies the character box (or cell) background mix mode.
usset (CBB_SET)
This defines the id of the font to be used for drawing characters. A value of zero
(LCID_DEFAULT) specified with Gpisetcharset sets the current character set to
default. A value of zero specified with GpisetAttrs or GpisetDefAttrs sets the
current or default character set back to the initial default set.
usprecision (CBB_MODE)
This defines the character mode or precision with which characters should be
drawn in terms of which character bundie attributes must be honored, which are
optional, and whether or not the font must be an outline font. This is specified as
one of:
CM_MODEl specifies that character box, angle, shear, and direc-
tion attributes may be ignored for raster font characters. All other
character attributes are fully honored. CM_MODE 1 raster charac-
ters are always drawn as normal left to right text.
CM_MODE2 specifies that character box, angle, shear, and direc-
tion attributes are used to determine the position of each raster font
character only. Orientation and size are unaffected by these attri-
butes and all other character attributes are fully honored.
CM_MODE3 specifies that characters must be drawn using an
outline font. Raster font characters are invalid in this mode. For out-
line characters, all attributes are fully honored regardless of mode.
sizfxcell (CBB_BOX)
This defines the character box or cell width and height in world coordinates. These
dimensions control the size of outline font characters (regardless of mode) and the
spacing of outline and CM_MODE2 raster font characters. For outline characters,
the lEmlnc and lEmHeight font metrics are set to the character box dimensions
with other width and height metrics (e.g., lAvecharwidth and lMaxBaselineExt)
scaled in the same proportion. The ratio CharacterwidthAEmlnc is normally
constant for a given character of a particular font or, for a non-proportional font,
for all characters of the font (i.e., lAvecharwidthtlEmlnc). The horizontal charac-
ter spacing of outline and CM_MODE2 raster characters can therefore be deter-
mined by CharacterBox. cx * CharacterwidthAEmlnc.
One or both character box dimensions can be specified as zero causing outline
characters to collapse into line or a single point.
Character box dimensions may also be negative causing outline characters to be
drawn reflected and the character spacing of both outline and CM_MODE2 raster
characters to be reversed.
For ideally proportioned (i.e., as designed) outline characters, the character box
DRAwlNG PRIMITlvES AND AFTRiBUTEs 6rf
ptlAngle (CBB_ANGLE)
This defines the character angle as the coordinates of a point that specifies the
angle of the baseline of a character string. For CM_MODEl raster characters,
character angle is ignored. For CM_MODE2 raster characters, character angle
affects only the position of each character but not its orientation. For CM_MODE3,
the cuITent font must be an outline font. For outline characters in all modes,
character angle affects both position and orientation of characters. Characters are
drawn perpendicular to the rotated baseline. A character angle value of (0,0) is
interpreted as `set to default.' The initial default value of character angle is (1,0)
representing a character angle of zero that positions characters left to right along
the x axis. Examples of the character angle attribute are illustrated in Figure 3-3.
REtline Font
I MMODE2Ragter
ptlshear (CBB_SHEAR)
This defines the character shear as the coordinates of a point that specifies a shear
angle. A non-zero shear angle gives the character an oblique or italicized appear-
ance. A character shear value of (0,0) is interpreted as `set to default.' The initial
default value of character shear is (0,1) giving upright characters. If the values are
both positive or both negative, the tops of the characters slope to the right. If the
signs are opposite, they slope to the left. An example of character shear is
illustrated in Figure 3-4.
usDirection (CBB_DIRECTION)
any width vector ®rovided with Gpicharstringpos) and any kerming adjustment.
The char_extra spacing is initialized to zero when a DC is created.
Such devices also allow the width of each break (or space) character to be
increased by an additional amount specified in world coordinates using
DevEscapeoEVESC_BREAK_EXTRA. The break_extra spacing is in addition to
the char_extra spacing. The break_extra spacing is initialized to zero when a DC
is created.
The codepoint of the space or break character of a font is returned by
GpiQueryFonts as one of the metrics.
Lines and arcs are drawn using the LINEBUNDLE (line bundle) attributes. In the
case of arcs (GpipointArc, GpipartialArc, and GpiFullArc), the ARCPARAMS (arc
parameters) are also used. In addition, the AREABUNDLE (area bundle) attri-
butes are used when either of the fill options are specified with GpiFulldrc or
GpiBox. The LINEBUNDLE attributes and flags ®arenthesized) are as follows:
IColor (LBB_COLOR)
usMixMode (LBB_MIX_MODE)
fxwidth (LBB_WIDTH)
This specifies the cosmetic line width as a multiplier consisting of an integer and
fractional part. As a minimum, if the cosmetic line width is greater than 1.0, this
should produce double width lines; otherwise, the lines should be single width. In
practice, however, values other than 1.0 are unsupported by IBM OSA Version 1.3.
Cosmetic line width is of type FIXED (see chapter 1).
IGeomwidth (LBB_GEOM_WIDTH)
This specifies the geometric line width. This is used exclusively with paths (see
below).
usType (LBB_TYPE)
This specifies the line style, for example, solid, dotted. (see Figure 3no).
-pr
12 0S/2 PRESENTATION MANAGER GPI
IINErYPE_SHORmASH
LINErmE.PASIIDOT
IJNEITYPEPOUBIEDOT
IniErypE+ONGDASH
IINErTPEPASIIDoUBIrooT
I-_SOLD
I.INEIT¥PEAILTmNATE
IINErypEPTvlslBu
Figure 3.6 Standard Line Types.
usEnd (LBB_END)
This specifies the line end attribute. This is used exclusively with paths (see
below).
usJoin (LBB_JOIN)
This specifies the line ].oin attribute. This is used exclusively with paths (see
below).
GpiLine
This draws a single straight line from the current position to a specified point and
updates the current position.
GpipolyLine
Thisdrawsasuccessionofconnectedstraightlinesfromthecurrentpositionthrough
a series of specified points. The current position is updated to the last point in the
series. Points may be coincident and the number of specified points can be zero, in
which case the function is a no-op. This function is a superset of that of GpiLine.
DRAWING PRIMITIVES AND AFTRIBUTES 13
GpipolyFillet
This draws a succession of fillets starting from the current position and ending at
the last in a series of specified points. The fillets pass through the mid-point of the
second and all subsequent imaginary straight lines up to and including, the last
but one of a series connecting the curent position and all adjacent specified points.
The fillets are tangential to the imaginary lines at the curent position, the last
point in the series, and all mid-points through which they pass. If only two points,
including current position, are specified, then the curve is tangential at the current
position and second point. The current position is updated to the last point in the
series. Points may be coincident and the number of specified points can be zero, in
which case the function is a no-op. Examples of the two cases of GpipolyFillet are
illustrated in Figure 3-7.
GpipolyFilletsharp
This draws a succession of fillets starting from the current position, passing
through alternate points and ending at the last of a series of 2*n specified points
(where n is the number of fillets). The fillets are tangential to imaginary straight
lines connecting adjacent points at each point through which they pass. The
alternate points through which fillets do not pass are control points used with a
sharpness value from a sharpness array supplied as a separate parameter. The
current position is updated to the last point in the series. Points may be coincident
and the number of specified points can be zero, in which case the function is a
no-op. GpipolyFilletsharp is illustrated in Figure 3-7.
Each sharpness value is a ratio controlling the shaxpness of one fillet (see Figure
3no) where:
shaxpness > 1.0 defines a hyperbola;
sharpness = 1.0 defines a parabola; and
sharpness < 1.0 defines an ellipse.
Gpipolyspline
This draws a succession of Bezier splines starting from the current position and
passing through every third point of a series of 3*n specified points (where n is the
number of splines). The pairs of intervening points are control points. The current
position is updated to the last point in the series. Points may be coincident and the
number of specified points can be zero, in which case the function is a no-op.
Gpipolyspline is illustrated in Figure 3-7.
GpiFullArc
This draws a complete circular or elliptical arc with its center at the curent
position.Thearcparameters(seebelow)togetherwithaspecifiedmultiplier(S255)
control the shape and size of the arc. The options allow the outline @RO_OUT-
74 OS/2 PRESENTATION MANAGER GPI
I-------I
D
SharpBees I DEpe
GpipartialArc
This draws a straight line from the current position to the start point of the arc
followed by a circular or elliptical arc with its center at a specified point. The arc
parameters (see below), together with a specified multiplier (S255), control the the
shape and size of the arc. The star and end points of the arc are defined by a
specified positive start and sweep angle (in degrees) measured counterclockwise
using the unit circle before application of the arc parameters (i.e., the specified
angles will be modified by the arc parameters if these do not define a circular arc).
The start angle is measured from the x-axis. The current position is updated to the
end point of the arc. GpipartialArc can be used to draw a pie slice (see the function
Drawpieslice in Figure 3-9) or a closed figure bounded by a chord and an arc (see
the function DrawchordAndArcFigure in Figure 3-10). The multiplier and start
and sweep angles are of type FIXED (see chapter 1).
GpipointArc
This draws an arc through three points starting from the current position. The arc
parameters (see below) control the the shape of the arc. The current position is
updated to the end point of the arc.
GpiBOx
This draws a box with diagonally opposite comers at the current position and a
specified point. The comers of the box may be optionally rounded with a quarter
ellipse defined by the rounding controls. If either or both rounding controls are
zero, then no rounding occurs. If both are non-zero, then they define the horizontal
and vertical full axes of the ellipse to be used for rounding. If they are non-zero
and equal, then the corners are rounded using a quarter circle. The options allow
the outline @RO_OUTLINE), the interior @RO_FIIIL), or both @RO OUT-
LINEFILL) to be drawn. The interior, if drawn, is filled using the AREABtinLE
attributes. The current position is not affected by this function.
76 OS/2 PRESENTATION MANAGER GPI
pl.esll.ce.c */
OL Drawpi.esli.ce (HPS hps)
arcpparms.1P = 500L;
arcpparms.1Q = 500L;
arcpparms.IR = OL;
arcpparms.1S = OL: /* set arc parameters
fRet = Gpl.SetArcparams( hps /* -PS handle
&arcpparms /* -arc parameters
in
ptlposn.x = 3000L:
ptlposn.y = 1000L;
1' f ( f R e t ) /* set center posi.ti.on
fRet = Gpl.Setcurrentpositl.on( hps /* -PS handle
&ptlposn /* -coordl.nate pol.nt
in
Gpioutlinepath
Arc Parameters
The arc parameters p, q, r, and s define a transform matrix that maps a unit circle
to the required ellipse, thus:
charcfl.g.c */
OL DrawchordAndArcFl.gure(HPS hps)
Draw closed fi.gure bounded by a chord and an arc usl.ng the current arc
pa rameters .
arcpparms.1P = 500L:
arcpparms.10 = 500L;
arcpparms.IR = OL:
arcpparms.1S = OL; /* set arc parameters */
fRet = Gpi.SetArcparams( hps /* -PS handle */
&arcpparms /* -arc parameters */
in
return (fRet);
Forgreatestaccuracy,thetransformshouldbeorthogonal(i.e.,suchthatp*r+s*q
= 0). Consider first a unit circle centered at the origin. This can be napped to the
required ellipse with ma].or and minor axes of 2a and 2b along the x and y axis
respectively by setting p=a, q=b, r=O and s=0.
78 OS/2 PRESENTATION MANAGER GPI
i.e. x, = a*x
y' = b*y
(ro ®JS)
p = 1500, q = 7sO, I = 0, 8 = 0
p = 1500 Cbs 30, q = 750 Cfo8 30, I = -750 Sin 30, a = 1500 Sin 30
Figure 3.11 Arc Parameters.
DRAWING PRIMITIVES AND AFTRIBUTES 19
Gpisetpel is similar to the BitBlt and Gpilmage functions except it uses the
LINEBUNDLE rather than the IMAGEBUNDIE attributes. It sets the pel at the
specified position using the LINEBUNDLE color and mix attributes. Gpisetpel is
never stored in a retained graphics segment but is always output directly to the
device, regardless of drawing mode. Note also that Gpisetpel does not conform to
the MetaFile interchange architecture and should not therefore be used when
creating a MetaFile for interchange with other products (see chapter 11).
GpiQuerypel is the reverse of Gpisetpel and returns the color index or RGB
value (according to the logical color table mode) of the pel at the specified position.
If the pel is not visible, because for example it is overlayed by another window, an
error is returned.
Areas are drawn using the AREABUNDLE (area bundle) attributes. The
AREABUNDLE attributes and flags ®arenthesized) are as follows:
lcolor (ABB_COLOR)
IBackcolor (ABB_BACK_COLOR)
usMixMode (ABB_MIX_MODE)
usBackMixMode (ABB_BACK_MIX_MODE)
usset (ABB_SET)
This defines the id of the pattern set, logical font, or bitmap to be used for the area
fill. An area fill operation can use a pattern from the standard pattern set, a
particular character from a logical font, or a bitmap tagged with a set id (see
chapter 4). A value of LCID_DEFAUIJT (zero) specifies default, which will initially
reference the standard pattern set illustrated in Figure 3-12.
80 OS/2 PRESENTATION MANAGER GPI
= PATSYM_IIALFTORE
PATSYM DENSE7
H PATSYM_NOSIIADE & PATSYM_BLANK
i.. .££..RE
PATSYM_DENSE6
= PATS"_DIAG4
:=: PATSYM_DENSE5
RE
PATS"_DIAG3
;
PATSYM_DENSE4
= PATSYM_DIAG2
:::;:::::::::::::;
PATSYM_DENSE3
Zi PATS"_DIAG1
;:;:;;::;:::::;:::
PATSYM_DENSE2
Ei PATSYM_HORE
E PATSYM_DENSE1
111111111
PATS"_VERT
ussymbol (ABB_SYMBOL)
This defines the pattern within the standard pattern set or the character codepoint
within the logical font specified by the usset attribute. If the current pattern set
is a bitmap then the ussymbol attribute is ignored.
ptlRefpoint (ABB_REF_POINT)
This defines the pattern origin in world coordinates. Its initial default value is
(0,0). The pattern origin can be outside the area to be filled.
This attribute is intended to avoid area boundary discontinuities that might
occur when part of a picture is scrolled using GpiBitBlt and the remainder is
redrawn. The scroll distance should be converted from device to world coordinates
using Gpiconverd and used to adjust the pattern origin before redrawing the
picture. Unfortunately, transform rounding errors make it impossible to always
guarantee complete freedom from all discontinuities.
DRAWING PRIMITIVES AND AFTRIBUTES 81
Area Primitiv®s
GpiBeginArea
GpiEndArea
All boundaries are inclusive and fo]rm part of the filled area.
If a figure inside an area bracket is not closed, GpiEndArea generates an
automatic closure line from the end to the staid of the figure.
Only certain functions are valid within an area. These are basically functions
that produce lines (including outline fonts) and certain attribute setting functions
(see the IBM OSA Hogramming Reference for a complete list of valid functions).
GpiBeginArea provides the following options :
BA_BOUNDARYZBA_NOBOUNDARY specifies whether or not
boundary lines are drawn in addition to the filled interior.
BA_ALTERNATE/BA_WINDING specifies whether the fill should
be performed using alternate or winding mode. This option is signifi-
cant for areas defined by multiple overlapping figures. In alternate
mode, a figure segment is filled if, counting from infinity to a point
in the segment, the number of figure boundary line crossings is odd.
Figure segments for which this number is even are not filled.
In winding mode, the direction of the boundary lines is signifi-
cant. Figure boundary lines drawn in one direction (e.g. clockwise)
can be considered to have a weight of +1 and those in the opposite di-
rection a weight of -1. A figure segment is filled if, counting from in-
finity to a point in the segment, the net weight of the figure bound-
any line crossings is non-zero. Figure segments for which the net
weight is zero are not filled.
An area consisting of a six-pointed star defined by two triangles
drawn using both BA_ALTERNATE and BA WINDING mode is
illustrated in Figure 3-13.
Areas can also be drawn by defining a path and issuing GpiFillpath (see below).
Areas are implemented intermally by the system using path functions. Note that
for IBM OSA Version 1.3 at least, there is an internal limit of 64K on the maximum.
size of a path and it is not possible to predict with any certainty when this limit
will be reached. When reached, an error is returned and the error code
PMERR_PATH_LIMIT_EXCEEDED is logged.
82 0S/2 PRESENTATION MANAGER GPI
MARKER FUMOTI0MS
Markers are typically used for displaying points on a graph and are similar to
characters except for the way in which they are positioned. Whereas characters
are positioned by a reference point near the bottom left corner of the first character
of a string, with each subsequent character positioned relative to that preceding
it, markers are individually positioned by their marker box center.
The system provides a standard marker set as illustrated in Figure 3-14. Altema-
tively a raster or outline font character can be used as a marker symbol. However,
a font character used as a marker will be imperfectly positioned if its sylnbol
definition is not positioned centrally within its character box.
Markers are drawn using the MARKERBUNDLE (marker bundle) attributes. The
MARKERBUNDLE attributes and flags ®arenthesized) are as follows:
IColor (MBB_COLOR)
lBackcolor (MBB_BACK_COLOR)
usMixMode (MBB_MIX_MODE)
X MARKSYM_CROSS
+ M-"LPLUS
a MARKSYM_DIAMOND
I MARE"_SQUARE
* MARKsyM_sEDOINrsTAR
* MARKsyM_EIGlrlrolNTSTAR
• MARKSYM_SOLDDIAMOND
I MARKSYELSOLDSQUARE
• MAus"_COT
0 MARKsyM_sMAIImaE
MARKS"_BLANI
Figure 3.14 Standard Marker Set
usBackMixMode (MBB_BACK_MIX_MODE)
This specifies the marker box (or cell) background mix mode.
usset (MBB_SET)
This defines the id of the marker set or font to be used for drawing markers. A
value of zero qcID_DEFAULT) specified with GpisetMarkerset sets the current
markersettodefault.AvalueofzerospecifiedwithGpisetAttrsorGpisetDefAttrs
sets the current or default marker set back to the standard marker set (i.e., the
initial default).
ussymbol (MBB_SYMBOL)
This specifies the codepoint of the marker symbol within the current marker set
(or character within the font) to be used for drawing markers.
sizfxcell (MBB_BOX)
This specifies the marker box width and height in world coordinates. These control
thesizeofmarkersdrawnusingoutlinefontcharacters.Formarkersdrawnusing
84 0S/2 PRESENTATION MANAC;ER GPI
the system (raster) marker set or raster font characters, the marker box attribute
is ignored. Although the marker box dimensions are of type FIXED for consistency
with the character box attribute, for marker box dimensions the fractional part
should always be specified as zero. This is because the `set marker set' order stored
in MetaFiles and retained segments is unable to support a fractional part and, in
such situations, the fractional part will be discarded.
Marker Pr]m]t[vcs
Markers are drawn using the GpiMarker and GpipolyMarker functions described
below.
GpiMarker
This draws a marker at a specified position and updates the current position.
GpipolyMarker
This draws a series of markers at specified positions and updates the current
position to that of the last marker. A count of zero is valid and in which case the
function will be treated as a no-op. This provides a superset of the function
provided by GpiMarker.
IColor (lBB_COLOR)
IBackcolor (IBB_BACK_COLOR)
usMixMode (IBB_MIX_MODE)
usBackMixMode (IBB_BACK_MIX_MODE)
Gpilmage
This draws a rectangular pixel image with its top left origin at the current
position. The image data consists of a single plane of data with one bit per pel
in application memory. The data is arranged as an array of bytes, where the first
byte represents the first eight pixels (of the top row) to be drawn from the
current position, with the most significant bit of each byte representing the
leftmost pel. The bits in the final byte of each row are padded, as necessary, to
a byte boundary. The image is drawn with `one' bits displayed using the IM-
AGEBUNDLE foreground mix and color and `zero' bits the background mix and
color.
Typically, the three separate planes of an RGB image would be drawn in turn
with a foreground mix of FM_OR, background mix of BM_LEAVEALONE, and
foreground color of CLR_RED, CLR_GREEN, and CLR_BLUE respectively.
The Gpilmage function is provided primarily for reasons of compatibility with
earlier products. The BitBlt functions are generally considered to be more suitable
for the ma].ority of new applications.
GpiBitBit
This function enables the rapid transfer of a rectangular array of pixel data
between a source and target pixel device or bitmap. The source and target of a
GpiBitBlt operation can include any of the following combinations:
Bitmaps are device dependent ob].ects and both the source and target of any BitBlt
operation must be `owned' by the same device (e.g., for the display, source and
86 OS/2 PRESENTATION MANAGER GPI
target must be either a display window or a bitmap owned by the display device).
Bitmap ownership is established at creation time by the PS (and associated DC)
specified with GpicreateBitmap and GpilloadBitmap.
It is possible to transfer bitmap ownership from one device to another using
GpisetBitmap to deselect the bitmap from the Psroc for the old device (if selected)
and select it to a Psroc for the new device (see chapter 5).
A bitmap can be created in any one of the four standard form.ats (i.e., a single
plane with 1, 4, 8, or 24 bits per pel) or may be in a device internal format that is
not one of the standard formats. The format with a single plane and 1-bit per pel
is referred to as a monochrome bitmap.
When using GpiBitBlt with a color source and monochrome target or with a
monochrome source and output device surface or color target, color conversion
occurs. The rules of color conversion are as follows:
Note that if part of the source is unavailable because, for example, it is overlayed
by another window on the display screen, then this part of the target is undefined
and no eITor is returned by GpiBitBlt.
The GpiBitBlt parameters are as follows:
DRAWING PRIMITIVES AND AFTRIBUTES &J
hpsTarget and hpssource These identify BitBlt source and target presentation
spaces. If the Rop mix value does not require a source (e.g., ROP_PATCOPY or
ROP_ZERO) then the source PS may be specified as NULL. Source or target
may be associated with a display window DC or an OD_DIRECT DC for any
raster device. Where the source or target is a bitmap, the bitmap must be
selected into an OD_MEMORY DC associated with the specified PS. The DC
associated with the target PS can also be a DC of type OD_QUEUED,
OD_METAFILE, or OD_METAFILE_NOQUERY. A MetaFile containing a re-
corded GpiBitBlt operation will not conform to the MetaFile interchange archi-
tecture (see chapter 11).
IRop This specifies the Rop (raster operation) mix mode value and optionally
allows a monochrome pattern (defined by the AREABUNDLE) to be included in
addition to (or in place of) the source bitmap, providing a `three-way' BitBlt
operation.
The Rop code mix value is determined by constructing a truth table containing
all combinations of input Pattern Q?), Source (S), and Target Original Value (0) for
any pixel and specifying the New Target Value (D required for each combination.
The number thus obtained from the eight bits defining T provides the Rop code
value.
For example, the Rop code required to replace the target with pattern fore-
ground or background at each source pixel that is `1' (i.e., if S=`1', T=P) and to leave
the target unchanged at every source pixel that is `0' (i.e., if S=`0' T=O) is OxOOE2L
as illustrated below.
88 OS/2 PRESENTATION MANAGER GPI
0 10 0
0 11 0
1 00 0
1 01 1
1 10 1
1 11 1 (most
significant bit)
The system provides predefined symbolic constants for the following most fre-
quently used Rop mix values:
ROP SRCCOPY (OxOOCCL) T= S
ROP SRCPAINT (OxOOEEL) T=S I O
ROP SRCAND (OxOO88L) T= S&O
ROP SRCINVERT (Ox0066L) T= S ^ O
ROP SRCERASE (OxcO44L) T=S&~ O
ROP NOTSRCCOPY (OxcO33L) T= ~ O
ROP NOTSRCERASE (OxOOllL) T=~ S&~ O
ROP MERGECOPY (OxOOCOL) T=P&S
ROP MERGEPAINT (OxOOBBL) T=~S I O
ROP IIATCOPY (OxOOFOL) T= P
ROP PATPAINT (OxOOFBL) T=~S I P I O
ROP PATINIRT (OxcO5AL) T= O ^ P
ROP DSTIIVERT (OxcO55L) T= ~ O
ROP ZERO (OxOOOOL) T= 0
ROP ONE (OxOOFFL) T= 1
For determining the effect of the Rop code on a color target, the target must be
regarded as multiple planes, each of one bit per pel (rather than one plane with
multiple bits per pel), with each plane processed separately.
DRAWINC; PRIMITIVES AND AFTRIBUTES 89
floptions The options are applicable only to compression and control the appear-
ance at positions where pels are eliminated:
BBO_OR specifies that multiple eliminated pels are ORed with a
remaining pel (this ensures that when `0' is foreground, background
`1' pels are preserved).
Note that GpiBitBlt, as well as being unaffected by the GPI transforms and not
conforming to the MetaFile interchange architecture, is always output directly to
the device and never stored in a retained segment, regardless of drawing mode.
These restrictions do not apply to GpiwcBitBlt (described below).
GpiwcBitBIt
The world coordinate BitBlt function GpiwcBitBlt is very similar to GpiBitBlt but
has a number of important differences as follows:
1. Whereas like GpiBitBlt, the source rectangle coordinates are specified
as device coordinates, the GpiwcBitBlt target rectangle coordinates
are specified in world coordinates and are consequently subject to all
of the GPI transforms. As a consequence of this, the aptlpoints array
must always include all four source and target rectangle coordinates
and lcount must always be specified as four. The operation does not
(for IBM OS# Version 1.3 at least) support rotation and shear. Note
that a change to the Default Viewing 'Thansform would result in
GpiwcBitBlt output being coITectly positioned relative to other
graphics output, whereas GpiBiBlt output would be incoITectly posi-
tioned.
2. As a consequence of the above, target coordinates for GpiwcBitBlt are
inclusive at all boundaries whereas GpiBitBlt target coordinates are
inclusive at the bottom and left and exclusive at the top and right
boundaries. The effect of this in practice is that with page units of
PU_PELS and all transforms set to identity, the top right GpiBitBlt
target coordinates would need to be one greater than the correspond-
ing GpiwcBitBlt coordinates for an identical operation.
3. The GpiwcBitBlt source parameter is a bitmap handle rather than a
PS handle. The source, therefore, can only be a bitmap and this should
not be selected into a PS/OD_MEMORY DC. The source and target of
a GpiwcBitBlt operation are therefore limited to the following combi-
nations:
90 0S/2 PRESENTATION MANAGER GPI
PATHS
Paths are picture functions that can be used for any of the following operations:
• Drawing a filled area (instead of using GpiBeginAreay/GpiEndArea).
• Drawing an unfilled outline that can include outline font characters.
• Defining an arbitrarily complex non-rectangular shape as a clip
boundary.
• Drawing geometric wide lines. These are lines, the appearance of
which is controlled by the line join, line end, and geometric line width
LINEBUNDLE attributes. Geometric line width can be defined by an
application and is subject to all the normal GPI transforms (scaling,
etc.). The resulting `geometric wide line' envelope definition is con-
tained in a modified path that can be filled in the same way as a
normal path to display the wide line.
lGeomwidth (LBB_GEOM_WIDTH)
This specifies the geometric line width attribute in world coordinates.
usEnd (LBB_END)
LINEEND_SQUARE; and
LIREEND ROUND.
usJoin (LBB_JOIN)
Path Dof[nltlon
A path is defined by issuing the drawing primitives and attributes for the required
(area, outline, clip path, or geometric wide line) path figures between:
GpiBeginpath; and
GpiEndpath.
GpiBeginpath and GpiEndpath, together with the path definition primitives can
be output directly in non-retained mode, accumulated in a retained segment, or
both, depending on the drawing mode. The path is created Out not displayed)
when the path definition primitives are actually output, whether directly, or from
a retained segment. Clearly, when stored in a retained segment, the same path can
be created at will merely by redrawing the segment. Note that the primitives (e.g.,
lines) inside a path bracket merely contribute to the path definition, and are not
actually displayed unless the completed path is subsequently drawn (e.g., using
Gpioutlinepath).
Path definition primitives (and orders stored inside a path in a retained seg-
ment) are specified in world coordinates and are therefore subject to all the normal
GPI transforms. However, once the path is created by outputting the path defini-
tion primitives, it becomes fixed in device coordinates and unaffected by subse-
quent transfo]rm. changes.
Any path can include outline font characters which, though normally filled, in
the contezit of a path bracket provide only the outline of the individual characters
as part of the path definition.
Only certain functions are valid inside a path. These are basically calls that
produce lines (including outline fonts) and certain attribute setting functions (see
the IBM OS# Hogramming Reference for a complete list of valid functions).
Note that for IBM OSA version 1.3 at least, there is an internal limit of 64K on
the maximum size of a path, and it is not possible to predict with any certainty
when this limit will be reached. When reached, an elTor is returned and the eITor
code PMERR_PATH_LIMIT_EXCEEDED will be logged.
92 OS/2 PRESENTATION MANAGER GPI
Paths are typically destroyed the first tilne they are used (see below).
Path Areas
To draw an area using paths, a path containing one or more figures describing the
required area shape must first be created. A path area fill operation is then
performed using the AREABUNDIE attributes by:
GpiFillpath
patharea.c */
L DrawpathArea(HPS hps)
Create a path defi.ni.ng a si.x poi.nted star made up of two tri.angles, and
fi.11 i.t usi.ng the FPATH_WINDING opti.on. Note that fi.1li.ng thi.s wi.th the
FPATH_ALTERNATE optl.on would leave the centre portl.on unfilled.
/* begl'n path
fRet = Gpi.Begi.npath( hps /* -PS handle
1L /* -path 1.d (must be
in
aptlpoi.nts[0].x = 200L:
aptlpoi.nts[0].y = 273L;
aptlpoi.nts[1].x = 300L:
aptlpoi.nts[1].y = 100L:
aptlpoi.nts[2].x = 100L;
aptlpoi.nts[2].y = 100L;
l'f (fRet)
fRet = Gpi.PolyLi.ne(hps, 3L, aptlpol.nts) != GPI_ERROR;
Pol'nt.x -100L;
Poi.nt.y = 215L;
aptlpoi.nts[0].x = 300L
aptlpoi.nts[0].y = 215L
aptlpoi.nts[1].x = 200L
aptlpoi.nts[1].y = 042L
aptlpoi.nts[2].x = 100L
aptlpoi.nts[2].y = 215L
l.f (fRet)
fRet Gpi.PolyLi.ne(hps, 3L, aptlpoi.nts) != GPI_ERROR:
return ( fRet ) ;
Path Outllnes
To draw an outline using paths, a path containing one or more figures defining the
required outline line shape must first be created. A path outline operation is
performed using the LINEBUNDLE attributes by:
Gpioutlinepath
On completion of drawing the outline, the path is destroyed.
This function can be used to draw an unfilled outline of an entire path including
that of any outline font characters in the path that would othe]owise be filled.
Clip Paths
Tocreateaclippath,a(normal)pathcontainingoneormorefiguresdescribingthe
required clip shape must first be created. A path is converted to a clip path using:
Gpisetclippath
LINErmL"T
HNERE_SQUARE
I
HNEueL[Roun
geomli.ne.c */
L DrawGeomwi.deLl.ne(HPS hps, B00L flopti.ons)
Create a path contai.ni.ng the requi.red li.nes and opti.onally close the
fi.gure. Modi.fy the path usl.ng the approprl.ate geometrl.c wl.de li.ne
attri.butes and fl.ll l.t to draw a geometri.c wi.de li.ne.
path
fRet = Gpl.Begi.npath( hps andl e
1L path i.d must be 1
n
P o l' n -200L: /* defi.ne path (li.ne) shape
P o l. n -100L;
aptlpoi.nts[0].x = 100L:
aptlpoi.nts[0].y = 100L;
aptlpoi.nts[1].x = 100L:
aptlpoi.nts[1].y = 300L:
aptlpoi.nts[2].x = 300L:
aptlpol.nts[2].y = 300L:
aptlpoi.nts[3].x = 300L:
aptlpol.nts[3].y = 100L:
aptlpoi.nts[4].x = 200L;
aptlpoi.nts[4].y = 100L:
l'f (fRet)
fRet = Gpl.PolyLi.ne(hps 5L, aptlpoi.nts) != GPI_ERROR;
1 b n d L 1. n e a u n d 1 e . 1 G e o in W 1. d t h 20L
l bnd Li neBundl e . us End LINEEND ROUND
1 b n d L i. n e a u n d 1 e . u s J o i. n LINEJ0IFT BEVEL
l'f (fRet)
fRet = Gpi.SetAttrs( hps /* set geometrl.c ll.ne attri.butes
PRIM_LINE /* -attri.bute type
L B B_G EON_W I DTH /* -attrl.butes mask
LBB_END
L B B_J 0 I N
0L /* -defaults mask
& 1 b n d L 1. n e 8 u n d 1 e /* -attrl.bute bundle
in
cli.ppath.c */
OL Createcli.ppath(HPS hps)
Create a path defi.ni.ng a si.x poi.nted star made up of two tri.angles and
select 1.t as the cll.p path.
/* begl'n path
fRet = Gpl.Begl.npath( hps /* PS handle
1L /* path i.d must be 1
in
aptlpoi.nts[0].x = 200L;
aptlpoi.nts[0].y = 273L:
aptlpol.nts[1].x = 300L;
aptlpol.nts[1].y = 100L;
aptlpoi.nts[2].x = 100L;
aptlpoi.nts[2].y = 100L;
l'f (fRet)
fRet = Gpl.PolyLl.ne(hps, 3L, aptlpol.nts) != GPI_ERROR:
Pol.nt.x = 100L;
Poi.nt.y = 215L;
aptlpoi.nts[0].x = 300L;
aptlpol.nts[0].y = 215L;
aptlpoi.nts[1].x = 200L:
aptlpoi.nts[1].y = 042L;
aptlpoi.nts[2].x = 100L:
aptlpol.nts[2].y = 215L;
1'f (fRet)
fRet Gpi.PolyLi.ne(hps, 3L, aptlpol.nts) != GPI_ERROR;
1'f (fRet)
fRet = Gpi.Endpath(hps); /* end path */
return ( fRet ) ;
Fonts are resources that allow text to be displayed in a variety of sizes, typefaces
(e.g.,Roman,Courier),andstyles(italic,bold,etc.).Rasterfontcharactershavefixed
size, whereas outline font characters can be scaled to any size using the character
box attribute and GPI transforms. Individual outline font characters or text strings
can be scaled independently or as part of an entire graphics picture or text page.
The GPI enables an application to specify the font to be used for drawing:
• Text.
• Characters within a graphics picture.
• Markers.
• Area fill patterns.
In the case of markers and patterns, font characters may be used in place of
markers and patterns from the standard marker and pattern sets. A font character
designed for text, however, may not be ideally suited for use as a marker that
requires precise positioning of its center, as the font design may not position a
character symbol centrally within its definition space.
Fonts may be shared by all applications across the entire system, relieving
applications and MetaFiles of the need to carry the individual character glyph
definitions. They need be concerned only with the attributes (facename, point size,
etc.) of the required fonts.
Font sizes are traditionally specified as the visible character height on the
output device in points, where a point is a `printers' point measuring 1/72 inches
(a 10 point font, for example, would therefore have a height of 10/72 or 0.139
inches). Font point size is roughly equivalent to the maximum baseline extent (i.e.,
the sum of the maximum ascender and maximum descender) in device coordi-
nates, but this is only an approximation. Font point size is not, in fact, precisely
defined in terms of any measurable characteristic of a visible character.
98
FO NTS 99
Characters output from an application may be displayed using fonts from any
of the following sources:
1. The default courier system outline font.
2. A font from a user supplied font file. This can include a raster font
created using the Font Editor and, for IBM OSA Version 1.3, Adobe
Type 1 Outline fonts (these are supplied with OS# and can be also
purchased independently). An Adobe Type 1 font is supplied as an
.AFM (Adobe Font Metrics) and a .PFB (Postscript Font Binary) file,
which are in the same format as soft fonts downloaded by the pscript
driver. These are similar to the .PSF files described below. User
supplied fonts of either type may be installed using the Control Panel
or loaded using Gpil.oadFonts.
3. A device font (i.e., a font suitable for use with only one particular
device).
Device fonts can include fonts built into the device hardware or driver,
provided on a separate device font card or cartridge, or provided as
downloadable `soft fonts' on diskette. See chapter 12 for a discussion of
printer fonts.
Normally a raster or outline device font will be provided as the default
font for a device. Devices that do not provide any device fonts will
normally use a built-in system Courier rasher font as their default.
4. A generic font from a system font file. These are pre-installed via the
Control Panel or can be loaded using GpiLoadFonts.
On IBM OS/2 Version 1.3, the following pre-installed system font files
are provided for use with Presentation Manager:
courier.fon;
times.fon;
helv.fon;
sysmono.fon;
courier.psf;
helvetic.psf; and
timesr-.psf.
Courier.fon, times.fon, helv.fon, and sysmono.fon provide a range of
raster fonts with various point sizes and device resolutions and the
following Facenames (or typefaces):
Courier;
Helv;
Tins ELn; and
System Monospaced.
100 0S/2 PRESENTATION MANAGER GPI
The 'Ihs Rmn and Helv fonts are proportionally spaced whereas
Courier and System Monospaced are monospaced (i.e., fixed pitch).
The .PSF files are a compiled version of the .AFM and .PFB files
described above. The courier.psf, helvetic.psf and timesnrm..psf files
are provided with IBM OSA Version 1.3 and provide a range of Adobe
Type 1 Outline fonts with the following Facenalnes:
Courier;
Courier Italic;
Courier Bold;
Courier Bold Italic;
HelveticaTM;
Helvetica Italic;
Helvetica Bold;
Helvetica Bold Italic;
Times New RomanTM;
Times New Roman Italic;
Times New Roman Bold; and
Times New Roman Bold Italic.
These same fonts also support the following previously supported
outline font Facenames for compatibility with 1.1 and 1.2 applications.
Helv;
Helv Italic;
Helv Bold;
Helv Bold Italic;
Tins ELn;
Tins ELn Italic;
Tins ELn Bold; and
Tins Rmn Bold Italic.
Fonts may be either public or private. A public font is one that is available to all
application processes within the system whereas a private font is available only to
the single application process from which it was loaded. External font files,
FONTS 101
including both system and user supplied font files, can be installed as public fonts
(and deleted) using the Control Panel or loaded as private fonts from an applica-
tion using GpiljoadFonts. All device fonts are public fonts.
It is recommended that applications should normally use public rather than
private fonts. This is because private fonts are not available on a different process
(e.g., the print process) from that on which they were loaded. They will not,
therefore, be available to print jobs with data type PM_Q_STD that are printed
via the spooler ®rint jobs with data type PM_Q_RAW will print private fonts
successfully but PM_Q_S'ID is the recommended method of printing).
Monospaced fonts are fonts for which every character has the same width, whereas
proportional fonts provide characters with different widths according to the indi-
vidual character shapes. FToportional fonts are generally considered to produce
text with a much more pleasing appearance than that obtained using monospaced
fonts but monospaced fonts are useful in situations where vertical alignment of
characters is important (e.g., for computer programs).
Raster fonts are fonts for which each character is defined as a fixed size bitmap or
rectangular pixel image. Outline fonts are fonts for which each character is defined
by a sequence of vector strokes and curves defining a closed figure that is
optionally filled. Raster (or image) font characters are fixed size whereas outline
(or vector) font characters are scalable and are transformed by the character box
attribute and the current transforms.
On IBM OSA Version 1.2, the outline fonts provided (originally within cou-
rier.fon, helv.fon, and times.fon) were only really suitable for displaying large
characters. When scaled to a small size, rounding errors caused the stroke
thickness to vary and their appearance became rather ugly. This was remedied by
the Adobe Type ManagerTM provided with IBM OSA 1.3 that supports Adobe Type
1 Fonts enabling outline fonts to be used to display high quality text over a wide
range of sizes, from quite small to very large.
The Adobe Type 1 Fonts also provide kerning support. This is an additional
refinement of proportional spacing which, for certain character pairs (e.g., Ta, To,
Th, We, and Yo), allows one character to overhang another providing a further
improvement in the text appearance (see Figure 4-1). The function Kermcharstr-
ing in Figure 4-2 is equivalent to Gpicharstring with keming adjustment applied
to each pair of characters for which keming inform.ation is available. This function
issues GpiQuerywidthTable to query the width table for all the characters in the
codepage. It then queries the font metrics to determine the number of keming
pairs available before querying issuing GpiQueryKerningpairs to obtain the kem-
ing pair information. An aITay of widths for the characters to be displayed is then
102 OS/2 PRESENTATION MANAGER GPI
ITo AVA I L
RTo AVAIL
Figure 4.1 Kemed and Unkemed Text.
kernchar.c */
OL Kerncharstri.ng(HPS hps, LONG ICount, PCH pchstrl.ng)
l'f (fRet)
(
for (1.=0 :1.<1count; I.++ ) /* assemble character */
alwi.dths[i.] = alwi.dthTable[pchstri.ng[i]]: /* strl.ng wl.dth array */
f r e e ( a 1 W i. d t h s ) ;
f ree( akrnprs ) ;
f r e e ( a 1 W i. d t h T a b 1 e ) ;
return ( fRet ) :
assembled from the width table inform.ation and each pair of characters is com-
pared for a match against each kerning pair. If a match is found then the keming
value is used to adjust the corresponding character width (for the first character
of the pair). The character string is displayed using Gpicharstringpos with the
character width array used as a vector of increment values. Clearly, if this function
were to be used multiple times for the same font then performance would be
lob 0S/2 PRESENTATION MANAGER GPI
improved by providing the width table and kerning pair arrays as parameters
rather than querying these for every character string. Also, the kerhing pairs are
returned in order of codepoint and a binary search could therefore be used to
improve performance.
Support for Adobe Type 1 Fonts requires no change to an application which
supports the earlier OSA outline fonts.
FONT METRI0S
Font terminology is derived from old fashioned printing technology giving rise to
terms such as `leading' ®ronounced ledding) from the use of metallic lead in early
printing.
Fonts are described by a collection of metrics contained in the fields of a
FONTMETRICS stmcture as follows:
szFamilyname;
szFacename;
idRegistry;
uscodepage;
lEmHeight;
lxHeight;
lMaxAscender;
lMaxDescender;
lIlowercaseAscent;
lljowercaseDescent;
llntermalLeading;
lExtemalLeading;
lAvecharwidth;
lMancharlnc;
lEmlnc;
lMarBaselineExt;
scharslope;
slnlineDir;
scharRot;
usweightclass;
FONTS 105
uswidthclass;
sXDeviceRes;
sYDeviceRes;
sFirstchar;
sLastchar;
sDefaultchar;
sBreakchar;
sNominalpointsize;
sMinimumpointsize;
sMaximumpointsize;
fsType;
fsDefn;
fsselection;
fscapabilities;
lsubscriptxsize;
lsubscriptYsize;
lsubscriptxoffset;
lsubscriptYoffset;
lsuperscriptxsize;
lsuperscriptYsize;
lsuperscriptxoffset;
lsuperscriptYoffset;
lunderscoresize;
lunderscoreposition;
lstrikeoutsize;
lstrikeoutposition;
sKemingpairs;
sFamilyclass; and
lMatch.
The font metrics can be queried for all available fonts using GpiQueryFonts and,
for the currently selected font, using GpiQueryFontMetrics. The FONTMETRICS
106 OS/2 PRESENTATION MANAGER GPI
I •Baseline
lMaxDe scender
J
lM axc harlnc lAv e charwi dth lExtemalLeading
llntemalLeading
-lincExt
lMaxBaseeicht
lEmH
(&C hay Box Height)I
Baseline
Lri:Ego:irse Em Squre
(& Outline Font Character Box Atthbute)
raster fonts only, point size (outline font point size is controlled by the transforms
and character box attribute).
GpiQueryFonts can specify the required szFacename value (or NULL if all
available fonts are to be returned) and whether public (QF_PUBLIC) fonts, private
(QF_PRIVATE) fonts, or both, are to be returned.
Included in the FON'ITVIETRICS information is a local font match number
(lMatch) that, subject to certain limitations, can be used to simplify font selection
by providing a `quick and dirty' alternative method. The lMatch value and
szFacename uniquely identify a font within the system and can be specified
together on GpicreatellogFont in place of the other metrics. The lMatch value
should not, however, be used for font selection in the following situations:
1. When the target PS is associated with a MetaFile DC ®ecause the
lMatch value will not be recorded in the MetaFile).
2. When printing remotely on a network print server (lMatch value is
unique only within the local system).
3. In any situation where the lMatch value would need to remain valid
after re-IPL (e.g., in a held print file).
IMatch value is suitable for direct printing, local printing via the spooler that
completes before re-IPL, or any queued printing using data type PM_Q_RAW.
For raster fonts, the alternative method to specifying the lMatch value on
GpicreateLogFont is to specify lMaxBaselineExt and lAvecharwidth in addition
to the required font szFacename. These must exactly match the values for the
required font or the match will fail and a default font will be returned. If any
transforms have changed since the font metrics were last queried, then the metrics
must be queried again to obtain updated values as described above. Similarly,
when printing via the spooler (i.e., with an OD_QUEUED DC) using data type
PM_Q_STD, to minilnize the risk of the font match failing on the print process, the
DevopenDC (DEVOPENDATA) pszQueueHrocparams should specify real size
(i.e., "XFM=0") rather than default which is `scale to fit.'
For outline fonts, the match number buys little. It is sufficient to specify only
szFacename together with the FATI`R FONTUSE OUTLINE and/or
FAITR FONTUSE TRANSFORMABLE fsFont-Use flags o= GpicreateLegFont.
As an o-utline font :an be scaled at will, lMaxBaseLineExt and lAvecharwidth
have little meaning and are ignored by the font matching algorithm.
GpicreateLogFont can also specify any combination of the following fsselection
indicators:
FATI`R SEL ITALIC;
FATrR SEL uNDERscoRE;
FATrR SEL STRIKEOUT, or
FAITR SEL BOLD.
These will cause the system to apply italic, underscore, strikeout, and bold
sinulations to non-device raster characters (and also outline font characters
FO NTS 109
although they are not really intended for, or ideal with the latter). These simula-
tions are in addition to any (italic, etc.) characteristics included in the font design.
These flags may not always be honored for device fonts.
For outline font characters, the FATI'RS_SEL_OU'ILINE flag causes unfilled
outline characters to be drawn (this was originally provided as a way of improving
performance).
When creating a raster font of specified point size, it is necessary to search the
metrics of the available fonts for a raster font with the required point size that also
matches the resolution of the target device. This is illustrated by the functions
CreateRasterFont and CreateRasterFont_lMatch in Figures 4-4 and 4-5. Note
that the CAPS_HORIZONTAL_FONT_RES and CAPS VERTICAL FONT RES
values returned from DevQuerycaps are conveniently -specified in ;els per-inch
(unlike CAPS_HORIZONTAL_RESOLUTION and CAPS_VERTICAL RESOLU-
TION which are in pels per meter). A careful analysis of these values-will reveal
that for most displays, the resolution for font selection is higher than the true
device resolution causing matching raster font characters to appear larger than
expected. This is quite intentional and is based on the observation that the normal
viewing distance for a display screen is significantly larger than that of printed
output. It is therefore considered desirable for characters to appear larger on a
display screen than when printed.
This size difference is not necessarily ideal. It makes WYSIWYG between screen
and printer difficult with raster fonts. Also, if, for example, GpiQuerycharstringpos
is used for raster font character positioning when creating a MetaFile for
subsequent printing, the position values obtained and recorded in the MetaFile
will be incorrect for the printer, even for a printer font with a matching Facename
and point size. This is because a MetaFile assumes compatibility with the display
and the MetaFile and printer font sizes will be different. To overcome this, a
separate PS associated with a printer DC and a separate printer font must be used
for determining the character positions recorded in the MetaFile.
The function CreateoutlineFont in Figure 4-6 illustrates outline font creation
and the function AllocatesetlD in Figure 4-7 illustrates the use of
GpiQueryNumbersetlds and GpiQuerysetlds to determine the set ids already in
use and to allocate an unused value.
When selecting a font, it is often desirable for performance reasons (and appear-
ance) to select a device rather than a generic font. This can be established by
examining either the fsDefii flags or the lMatch value in the FON'IMETRICS. For
a device font, the FM_DEFN_GENERIC flag is not set and the lMatch value is
negative (I have found that, for some drivers, the lMatch approach seems slightly
more reliable).
Outline fonts are designed in a notional font definition space above world coordi-
nate space (see Figure 7-1). The dimensions of this space, which is normally a
1000xl0cO square, are returned as the sXDeviceRes and sYDeviceRes
110 OS/2 PRESENTATION MANAGER GPI
FONTRETRICS fields and these particular metrics are unaffected by the trans-
forms and character box attribute. The transfo]rm from font definition space to
world coordinate space is defined by the ratio of the sXDeviceRes and
sYDeviceRes rectangle in font definition space and the character box attribute
rectangle in world coordinate space. For an outline font, the character box
attribute is, in fact, the same as the Em Square. As mentioned earlier, it is the
Em Square dimensions lEmHeight and lEmlnc that are set by the character box
attribute height and width values (for an outline font). It is therefore possible for
lAvecharwidth and lMaxBaseLineExt to exceed the character box dimensions
and for these to differ between fonts of different design, even though the character
box attribute dimensions may be identical. The effect of the character box attri-
bute on horizontal spacing of outline and CM_MODE2 raster font characters was
described earlier.
The function SetoutlineFontpointsize in Figure 4-8 illustrates how to scale an
outline font to a specified point size. Note that the lEmHeight metric is a measure
of font point size in world coordinates and, for an outline font, is equal to the height
of the character box attribute. The required point size is achieved by determining
the size in pels of the required font point size, converting this to world coordinates
to provide the required lEmHeight value and specifying this value as the character
box attribute dimensions.
The function ScaleoutlineTOFixed in Figure 4-9 illustrates how to scale an
outline font size to match that of a specified raster font. Note that this is achieved
by using the character box attribute to set the outline font lEmHeight value to
match that of the raster font. Any remaining size differences between outline and
raster font characters (even with the same szFacename) are due to differences in
font design. Alternative scaling algorithms can use different metrics such as
lxHeight (and can give better results). This is illustrated by the function
ScaleoutlineTOFixed2 in Figure 4-10. This queries the metrics of the raster font
and then sets the character box attribute to a known value of 1000xl000 before
querying the metrics of the outline font. The character box attribute is then scaled
by the amount (i.e., Raster_lxHeighi/Outline_lxHeight) required to set the outline
lxHeight to a value that matches the raster font.
A similar approach is used to set the horizontal pitch of a font to a specified value
in characters per inch, as illustrated by the function SetHorizontalpitch in Figure
4-11. Here the character box attribute is again set to a known value of 1000xl000
before querying the metrics of the outline font. The character box attribute is then
scaled by the value (i.e., Required_lAvecharwidth/Old_lAvecharwidth) required
to set the pitch to the specified value (where Required_lAvecharwidth in pels is
determined from lxResolution/pitch). Note that average character width must be
converted from world to device coordinates using Gpiconvert.
As mentioned above, outline fonts are normally defined in a 1000xl000 square
definition space. The major exceptions to this are built in device outline fonts such
as those provided by a plotter. To obtain ideally (i.e., as designed) outline font
characters, the aspect ratio of the character box attribute should match that of the
sXDeviceRes and sYDeviceRes font metric dimensions (for an isotropic coordinate
system).
FONTS 111
The system default codepage is the first codepage specified in the CODEPAGE
command of CONFIG.SYS, or is codepage 850 if CONFIG.SYS contains no
CODEPAGE command. Ovote that Dossetcp cannot be used in a Hesentation
Manager application but both Dossetnroccp and the CHCP command can be used
to switch between the two codepages specified in CONFIG.SYS). The GPI Hesen-
tation Space codepage is used for displaying GPI font characters and this will
default to the process codepage that will be either the system default or some other
value set by DossetHocCp or CHCP.
Regardless of the values specified in the CONFIG.SYS CODEPAGE command,
a GPI PS codepage can be set to any of the following values using Gpisetcp:
ASCII US ENGLISH 437
ASCII MUIJTILINGUAL 850
ASCII PORTUGUESE 860
ASCII CANADIAN FRENCH 863
ASCII NORWEGIAN 865
ASCII DESKTOP PUBLISHING lco4
EBCDIC US ENGLISH 37
EBCDIC AUSTRIAN GERMAN 273
EBCDIC BELGIAN 500
EBCDIC DANISH NORWEGIAN 277
EBCDIC FINNISH SWEDISH 278
EBCDIC ITALIAN 280
EBCDIC PORTUGUESE 37
EBCDIC SPANISH 284
EBCDIC UK ENGLISH 285
EBCDIC FRENCH 297
EBCDIC INTERNATIONAL 500
EBCDIC BELGIAN (M) 274 supported for migration
purposes
EBCDlc PORTUGUESE (ro 282 supported for migration
purposes
The GPI PS codepage can be queried using GpiQuerycp.
System font files are designed to provide a universal character set that includes
allcharactersrequiredbyalloftheabovecodepages,andtoprovidethenecessary
I+2 0S/2 PRESENTATION MANAGER GPI
In addition to its use for specifying a logical font as a character, pattern, or marker
set as described above, a set id can also be used to define a bitmap as an area fill
pattern. To use a bitmap for area fill, the bitmap must be tagged with a set id using
GpisetBitmapld. The bitmap can then be selected as the current area fill pattern
using Gpisetpattemset or GpisetAttrs in the normal way. Note that
Gpisetpattern is not required as this attribute is ignored for bitmaps. A bitmap
set id is deleted using GpiDeletesetld.
Note that a bitmap may be simplified when used as an area fill patterm, for
example, it will be converted to monochrome and only part of a large bitmap (e.g.,
an 8x8 pel rectangle) might be used.
crasfont.c */
G CreateRasterFont (HPS hps)
Create a logi.Gal font for a 12 pol.nt publi.c Courl.er raster font wl.thout
usl.ng lMatch and return the set i.d (or GPI_ERROR for error).
returns: LONG Set ID (Lci.d) of the newly created font (or GPI_ERROR)
/ :.*************************************************************************** 1
j§ :!;::in;::i:::::::i:::;::i::i:i;:;r:::eq|::yin:;: #:::Tr¥st:o:1:?Sa::bi:: ;j
/ ****************************************************************************-/
lReqFonts = OL;
Query Number of
lNumFonts = Gpl.QueryFonts( hps -PS handle
QF_PUBLIC Opti ons
FACENAME facename
&lReqFonts number of fonts
OL metrl.cs length
NULL returned metri.cs
in
I.f ((1NumFonts!=GPI_ALTERROR)&&(lNumFonts!= OL)) /* allocate memory for
afmMetri.cs = malloc((SHORT)(lNumFonts*si.zeof(FONTMETRICS))): /* metri.cs
QF_PUBLIC /* -opti.ons
FACENAME /* -facename
&1NumFonts /* -number of fonts
(LONG)si.zeof(FONTMETRICS) /* -metri.cs length
. afmMetrl.cs /* -returned metri.cs
n
/ :.*************************************************************************** I
/* */
/* Query the actual horl.zontal and vertl.cal resolutl.on for the devi.ce. */
/* */
/ ****************************************************************************' I
/ **************************************************************************** /
/**/
/* Search the font metri.cs for a font that sati.sfi.es all of the followi.ng */
/* condi.ti.ons and create a logi.cal font for i.t wl.thout usi.ng lMatch: */
/* font l.s raster */
/* facename matches requi.red facename */
/* font devi.ce resoluti.on matches actual devi.ce resoluti.on hori.zontally */
/* font devl.ce resoluti.on matches actual devl.ce resolutl.on verti.cally */
/**/
/ **************************************************************************** /
l'f (fRet)
{ /* step through and exami.ne */
for (I. = 0; i < (INT)lNumFonts: 1.++) /* metri.cs for each font */
(
(!(afmMetrl.cs[l.].fsDefn & FM_DEFN_OUTLINE) /* check for raster
(strcmp(afmMetri.cs[i.].szFacename, FACENAME)) /* compare facename
afmMetri.cs[i.].sNomi.nalpoi.ntsi.ze == P0INTSIZE)/* compare poi.nt si.ze
((LONG)afmMetri.cs[i].sXDevi.ceRes == lxDevRes) /* compare X and Y Res
((LONG)afmMetri.cs[i.].sYDevl.ceRes == lYDevRes))/* for thi.s devl.ce
1 **************************************************************************** 1
/**/
/* Free the memory. */
/* If error set returned lci.d to GPI_ERROR. */
/**/
/ **************************************************************************** /
return (lLcl.d);
crfmatch.c */
G CreateRasterFont_1Match(HPS hps)
Create a logi.cal font for a 12 pol.nt publl.c Couri.er raster font usl.ng
lMatch and return the set l.d (or GPI_ERROR for error).
returns: LONG Set ID (Lci.d) of the newly created font (or GPI_ERROR)
: 85i:!3bic ): ::g::::;e
&1NumFonts /* -number of fonts
(LONG)sl.zeof(FONTMETRICS) /* -metri.cs length
_ , L , , .
I,*****************************************************************************/
#Ouery the actual horizontal and vertical resolution for the device. :;
/****************************************************************************/
1.f (1RemFonts != GPI_ALTERROR)
hdc = Gpi.OueryDevice(hps); /* query associ.ated DC handle */
(
1.f (!(afmMetri.cs[i.].fsDefn & FM_DEFN_OUTLINE) /* check for raster
&& !(strcmp(afmMetri.cs[i.].szFacename, FACENAME)) /* compare facename
&& (afmMetrl.cs[i.].sNoml.nalpol.ntsi.ze == P0INTSIZE)/* compare pol.nt si.ze
&& ((LONG)afmMetri.cs[i.].sXDevi.ceRes == lxDevRes) /* compare X and Y Res
&& ((LONG)afmMetrl.cs[1.].sYDevl.ceRes == lYDevRes))/* for thl.s devl.ce
(
1Lci.d = AllocatesetlD(hps); /* get a set 1.d
I.fu!::::i:;:P±i§i§5:rycp(hps) ; ): 9;:r%a:§T:°depage
/ **************************************************************************** 1
/**/
/* Free the memory. */
/* If error set returned lci.d to GPI ERROR. */
/**/
1 **************************************************************************** I
f ree ( afmMet ri. cs ) ;
l'f (!fRet uscodepage==GPI_ERROR)
1 Lcl.d - in I_ERROR :
return (1Lcl.d);
crtolfnt.c */
G Createoutli.neFont (HPS hps)
1 **************************************************************************** I
/**/
/* Query the number of fonts to determl.ne how much memory to allocate for */
/* font metrl.cs, allocate the memory and query the metrl.cs for all publl.c */
/* fonts wl.th the requl.red facename. */
/**/
/ **************************************************************************** /
1 **************************************************************************** 1
/**/
/* Search the font metrl.cs for a font that sati.sfies the followi.ng */
/* condi.ti.ons and create a logi.cal font for i.t wl.thout usi.ng lMatch: */
/* font i.s outline */
/* facename matches requi.red facename */
/**/
/ **************************************************************************** /
font attrl.
fatAttrs.usRecordLength = sl.zeof(FATTRS) record length
fatAttrs.fsselectl.on = 0: selecti.on flags
-match value
fatAttrs . I Match
s t rcpy ( f atAtt rs . s z Fa cen ame afmMetri.cs[i.].szFacename): /* -facename
fatAttrs i d R e a 1' s t r y afmMetri.cs[l.].i.dRegl.stry: /* -regl.stry i.d
fatAttrs uscodepage uscodepage: /* -codepage
fatAttrs 1 M a x 8 a s e 1 i. n e E x t OL: /* -max ble
fatAttrs 1 A v e C h a r W i. d t h OL; /* -ave chw
fatAttrs fsType 0; /* -type flags
fatAttrs fsFontuse ( FATTR_FONTUSE_OUTLINE /* -font use
I FATTR_FONTUSE_TRANSFORMABLE) ;
f ree( afmMetri cs ) ;
return (lLcl.d):
allocset.c */
NG AllocatesetlD (HPS hps)
Return an unused set id (Lcl.d) or GPI_ERROR for error (or none aval.1able).
I.f (lcount!=GPI_ALTERROR)
(
alLci.ds = malloc((SHORT)(16 * 1Count)) /* allocate memory for
alTypes = (PLONG)(alLcids + lcount); /* set l.ds, types and
aNames = (PSTR8)(alTypes + lcount): /* names
setolpsz.c */
L Setoutli.neFontpol.nts1.ze( HPS hps, LONG 10utll.neLcl.d)
Set the character set to the speci.fi.ed outli.ne font set I.d and set the
character box attri.bute to gl.ve the outll.ne font the requi.red poi.nt sl.ze.
Note that thl.s functi.on i.s i.ntended to handle outll.ne fonts desl.gned 1.n a
square space wi.th sXDevi.ceRes and sYDevi.ceRes equal (thi.s 1.s true for all
Presentati.on Manager fonts that are not devl.ce fonts).
/ ****************************************************************************** 1
/**/
/* Query verti.cal devl.ce resoluti.on for font selectl.on. */
/**/
/ ****************************************************************************** 1
lpoi.nts1.zelnpels = ((1YDevResFont*P0INTSIZE+(P0INTSPERINCH/2))/P0INTSPERINCH):
aptlpoi.nts[0].x = OL:
aptlpoi.nts[0].y = 1L:
aptlpoi.nts[1].x = OL:
aptlpol.nts[1].y = 1Poi.ntsizelnpels+1;
i.f (fRet) /* convert coordi.nates
fRet = Gpi.Convert( hps /* -PS handle
CVTC_DEVICE /* - source
CVTC_WORLD /* -target
2L /* -count
aptlpoi.nts /* -coordi.nate array
in
lpol.ntsi.zelnwc = aptlpoints[1].y -aptlpol.nts[0].y:
/****************************************************************************** I
/**/
/* set the character set to the outll.ne font set i.d */
/* set the character box dl.mensl.ons to the pol.nt sl.ze l.n world coordi.nates */
/* converted to FIXED (l..e. tl.mes Oxl0000). */
/**/
1****************************************************************************** I
si.zfxcharBox.cx = lpoi.ntsi.zelnwc*Oxl0000;
si.zfxcharBox.cy = lpol.ntsi.zelnwc*Oxl0000:
return ( fRet ) ;
sclolfx.c */
L Scaleoutli.neTOFi.xed (HPS hps, LONG loutll.neLcl.d, LONG IRasterLcl.d)
Set the character set to the specl.fi.ed outli.ne font 1.d and set the
character box attrl.bute to gl.ve an outli.ne font the same si.ze as the
speci.fi.ed raster font (any remai.ni.ng vi.sual di.fferences ari.se from
di.fferences 1.n font desi.gn).
/*********************+******************************************************** I
/**/
/* set the character set to the raster font set 1.d */
/* query the font metrl.cs for the raster font */
/* set the character set to the outli.ne font set I.d */
/* set the outli.ne font character box attrl.bute di.mensi.ons to the lEmHei.ght */
/* lEmlnc metri.c values for the raster font */
/**/
/ ****************************************************************************** 1
si.zfxcharBox.cx = MAKEFIXED(fmRMetrics.1EmHeight,0);
si.zfxcharBox.cy = MAKEFIXED(fmRMetri.cs.IEmlnc,0);
sclolfx2.c */
L Scaleoutli.neTOFixed2( HPS hps, LONG loutll.neLci.d, LONG IRasterLci.d)
Set the character set to the speci.fi.ed outli.ne font l.d and set the
character box attri.bute to gi.ve an outli.ne font the same sl.ze as the
specl.fl.ed raster font. The character box l.s set to a value that scales
the lxHel.ght metrl.c of the outll.ne font to match that of the raster
font (any remai.ni.ng vi.sual di.fferences ari.se from di.fferences l.n font
d e s 1. 9 n ) .
/ ****************************************************************************** 1
/**/
/* set the character set to the raster font set l.d */
/* query the font metrl.cs for the raster font */
/* set the character set to the outli.ne font set i.d */
/* set the character box attri.bute di.mensi.ons to a known value (1000xl000) */
/* query the font metri.cs for the outli.ne font */
/* change character box di.mensi.ons to scale lxHei.ght for the outli.ne font to */
/* match that of the raster font and set the new character box attri.bute. */
/**/
/ ****************************************************************************** 1
sl.zfxcharBox.cy = sl.zfxcharBox.cx
= ( Ox03E80000/fmoMetri. cs .1 XHei. ght )*fmRMetrl. cs . I XHel. ght :
setpl'tch.c */
L SetHorl.zontalpi.tch(HPS hps, LONG loutli.neLci.d, LONG Ipi.tch)
Set the character set to the speci.fi.ed outll.ne font l.d and set the
character box attri.bute to provi.de the speci.fi.ed hori.zontal pi.tch i.n
characters per i.nch.
I ****************************************************************************** 1
/**/
/* query the devi.ce resoluti.on */
/* set the character set to the outli.ne font set l.d */
/* set the character box attri.bute di.mensi.ons to a known value (1000xl000) */
/* query the font metrl.cs for the outli.ne font */
/* convert the Avecharwi.dth to devi.ce coordi.nates (pels) */
/* calculate the new character box to gi.ve the requi.red pl.tch */
)= #:XF;:::T=t{:i;::€:idi:/:::t#:::Wi:t:i:X::;°:#:::P::::acter wi.dth :)
/* The char box 1.s thus scaled by the rati.o NewAvecharwi.dth/OldAvecharwi.dth */
/* set the new character box attri.bute
*/
/**/
/****************************************************************************** I
si.zfxcharBox.cy = si.zfxcharBox.cx
= ( ( Ox03E80000/1 P1. tch )*1 XResol utl. on ) /1 Avecharwi. dth ;
retu rn ( f Ret ) ;
BITmAp FORMATs
Bitmap formats are specified as the number of color planes and number of bits per
pel. Standard bitmap formats are all defined with only a single plane and one or
more bits per pel but this is only a convention. It is equally valid to describe the
same bitmap as having one plane with eight bits per pel or eight planes with one
bit per pel. The standard bitmap formats are as follows:
• A single plane with 1 bit per pel (i.e., monochrome).
• A single plane with 4 bits per pel (i.e., 16 color).
• A single plane with 8 bits per pel (i.e., 256 color).
• A single plane with 24 bits per pel (i.e., RGB).
A presentation driver must allow bitmap creation in any of the four standard
formats as well as in any non-standard internal device formats of its own.
Although drivers must allow bitmap creation in the standard formats, it is not
i26
BITMAPS IZ]
essential for these formats to be supported intermally. For formats not supported
intemally, the driver will select its most appropriate internal device format and
perform the necessary conversion of bitmap initialization data. In addition, all
drivers must be capable of supporting bitmap data conversion between any of the
standard formats and any internal device format. This is to allow bitmap data in
any standard format to be transferred between application memory and a bitmap
(in either direction) using GpicreateBitmap, GpisetBitmapsBits, and
GpiQueryBitmapBits.
Bitmap formats supported intermally by a driver, where the first format re-
turned is that which most closely matches the device, can be queried using:
GpiQueryDeviceBitmapFormats.
Bitmaps are created and deleted using the functions described below:
GpicreateBitmap
This creates a new bitmap of specified dimensions and format and optionally
initializes it. The bitmap dimensions theight, width) and format ®lanes, bits per
pel) are specified in a BIThVIAPINFOHEADER structure parameter. The format of
the bitmap initialization data may be different froln that of the bitmap and is
described by a separate BI'IMAPINFO structure parameter. The BI'IT\IAPINFO
structure is the same as a BI'IT\IAPINFOHEADER structure except that for
bitmap formats other than 24 bits per pel, it is followed by an alTay of color table
information describing the color represented by each combination of bits. This
color table will contain 2"n entries where n is the number of bits per pel. The
length of the bitmap initialization data may exceed 64K bytes.
For certain devices (e.g., 8514/A) bitmap creation in device internal format may be
considerably faster if the bitmap color table exactly matches that of the device
palette (this can be determined using GpiQueryRealcolors).
GpiLoadBitmap
This creates and loads a bitmap from a resource file and returns the bitmap
handle. The bitmap will typically have been originally created using the iconedit
utility and compiled with the resource compiler. The rc file will typically contain a
statement of the form:
BITMAP ID_BITMAP3 mybmap.bmp
where ID_BI'ITVIAP3 is a numeric constant (e.g., #define ID_BI'IMAP3 3) for the
bitmap ID to be specified with GpiLoadBitmap, and mybmap.bmp is the name of
the bitmap file created by iconedit. The compiled bitmap resource (res) file may be
added to the application exe file using the resource compiler or included in a DLL
resource file and loaded using DosLoadModule.
GpilloadBitmap specifies the height and width of the required bitmap and,
where these differ from the values in the resource file, stretching or compression
of the bitmap data will occur. Either or both dimensions may be specified as zero
on GpilioadBitmap causing the original value or values to be used unchanged (i.e.,
with no stretching or compression).
WinLoadpointer
This loads a pointer or icon (see below) from a DLL resource file and returns its
handle.
BITMAPS 129
GpiDeleteBitmap
BITMAP SELECTION
A bitmap may be used as the source or target of a BitBlt operation, or used as the
target of any valid drawing operation. In order to draw to a bitmap, use it as the
target of a GpiwcBitBlt operation, source, or target of GpiBitBlt, the bitmap must
be selected into an OD MEMORY DC associated with a PS.
Also, in order to tran-sfer bitmap ownership from one device to another, it must
be deselected from the Psroc for the old device (if selected) and then selected into
a PS associated with an OD MEMORY DC for the new device. This is accom-
plished as follows:
GpisetBitmap(hpsold, NULL); /* deselect from existing ps
(if selected) */
GpisetBitmap®psNew, hbitmap); /* select to PS/OD MEMORY
Dcfornewdevi;e */
Note that GpiwcBitBlt does not require its source bitmap to be selected into a
Psroc, although it must be owned by the target device. If GpisetBitmap is used
to transfer bitmap ownership, the bitmap should then be deselected from the new
device before GpiwcBitBlt is issued. Note also that bitmap ownership by a device
will continue after the bitmap has been deselected from its Psroc until it is
selected to a Psroc for a different device.
Pels
top row: red green blue red green
blue red green blue red
green blue red green blue
the type of image (as a bitmap, icon, pointer, color icon, or color pointer), the
hotspot position for icons and pointers, and an offset to the bitmap data in the
format described above. Icons and pointers both have the same format and, for
monochrome icons and pointers, the file contains a double height bitmap providing
XOR and AND masks. The AND mask determines whether the screen or
icon/pointer is displayed in each pel position (0 specifies display icon/pointer, 1
display screen) and the XOR mask determines whether or not each bit of the
resulting image must be inverted (i.e., black/white or screen/inverse screen). For
colored icons and pointers, a second bitmap defining the color content is provided.
In this case, a one bit in the XOR mask will invert the screen but leave the
icon/pointer color unchanged. The bitmap file format is described in the IBM OSA
FTogramming Reference.
Icons and pointers may be created (using the iconedit utility) in device indepen-
dent format, in which case the file will contain an array of different versions of the
icon or pointer to match each of the different device resolutions.
In order to print an icon or pointer, it can be loaded using WinLoadpointer, and
WinQuerypointerlnfo can then be used to obtain a POINTERINFO structure. This
contains handles for the two (double height XOIVAND and color) component
bitmaps. The double height bitmap must then be separated into its two parts and
the appropriate BitBlt Rop mix values applied. Because of inversion inconsisten-
cies in handling monochrome bitmaps some older print drivers may require
slightly different Rop mix values.
'two rather uninteresting functions exist for storing and retrieving a width and
height to and from a bitmap. These are:
Gpis etBitmapDimension; and
GpiQueryBitmapDimension.
These functions were included for reasons of compatibility with earlier products.
They exist for application convenience only and the data set by
GpisetBitmapDimension does not in any way affect the bitmap. It is stored with
the bitmap solely to enable it to be subsequently retrieved. These functions could,
in fact, be used to store any user data with the bitmap.
/* crbi.tmap.c */
HBITMAP CreateBl.tmap(HAB hab, HDC hdc)
(
/* Create a bi.tmap for the specifl.ed devl.ce and draw to i.t. Return the bi.tmap
/* handle or GPI_ERROR.
/*
/* i.nputs: hab anchor block handle
/* hdc DC handle i.denti.fyi.ng the devi.ce for whi.ch the bi.tmap i.s
/* to be created (can be NULL for the di.splay)
/*
/* returns: HBITMAP bi.tmap handle or GPI_ERROR on error
/*
b in p I n f o H d r . c b F i. x s 1. z e o f ( 8 I T M A P I N F 0 H E A D E R )
bmp I nfoHd r . cx BMAPWIDTH ;
bmp I nfoHd r . cy BMAPHEIGHT ;
bmplnfoHdr . cpl anes BMAPPLANES ;
b in p I n f o H d r . c 8 1. t C o u n t BMAPBITCOUNT :
/* i.f any error occurred attempt to delete bl.tmap and set return code to */
/* GPI_ERROR. */
I'f (!fRet)
(
I.f (hbm!=GPI_ERROR)
G p i. D e 1 e t e 8 1. t in a p ( h b in ) ;
hbm = GPI_ERROR;
)
return ( hbm) ;
/* bl'tblt.C */
B00L Bi.tBlt( HAB hab
hps hps
HBITMAP hbm
LONG ICount
PP0INTL aptlpoi.nts
' LONG IROp
ULONG fl0pti.ons
return ( fRet ) :
wcbltprt.c */
L WCBltToprl.nter(HAB hab. HPS hps, HBITMAP hbm)
Note that i.f the page uni.ts are PU_PELS, the source and target rectangl
wi.ll be i.denti.Gal and no stretchi.ng or compressi.on wi.11 occur. As the
source rectangle i.s l.n devl.ce coordl.nates (whl.ch are i.nclusl.ve-exclusl.ve
then (for Gpi.WCBi.tBlt) i.ts di.mensi.ons must be one larger than those
of the correspondi.ng target rectangle (whi.ch 1.s I.n world coordl.nates).
1.f (hpsMem!=GPI_ERROR)
fRet = Gpl.Destroyps(hpsMem) && fRet: /* destroy the PS
I.f (hdcMem!=DEV_ERROR)
fRet = DevcloseDC(hdcMem)!=DEV_ERROR && fRet: /* close the DC
return (fRet);
wbltload.c */
L WCBltLoadedBi.tmap(HPS hps, USHORT usResourceld)
Load a bi.tmap from the appli.cati.on EXE fl.le usi.ng Gpi.LoadBi.tmap and Bi.tBi.t
i.t to the PS usi.ng Gpi.WCBi.tBlt.
Note that i.f the page uni.ts are PU_PELS, the source and target rectangles
wi.1l be I.denti.cal and no stretchi.ng or compressi.on wl.ll occur. As the
source rectangle i.s i.n devl.ce coordi.nates (whl.ch are i.nclusi.ve-exclusi.ve)
then (for Gpi.WCBl.tBlt) l.ts dl.mensl.ons must be one larger than those
of the correspondi.ng target rectangle (whl.ch is i.n world coordi.nates).
bmplnfo.cbF1.x = sl.zeof(BITMAPINFOHEADER)
I.f (hbm!=GPI_ERROR) ery bi.tmap parameters
fRet = GpiQueryBi.tmapparameters tmap handle
TMAPINFOHEADER structure
return (fRet);
/* reali.ze.c */
B00L Reall.zecolorlmage( HAB hab
HPS hps
PBYTE pblni.tData
PBITMAPINF0 pbmi.InfoTable
/* Di.splay an 8 bi.t per pel scanned i.mage usi.ng the color reali.ze functi.ons
/* 1.f supported. Note that Gpi.Unreali.zecolorTable must be 1.ssued subsequently
/* to unreali.ze the color table.
/*
/* i.nputs: hab anchor block handle
/* hps Ps handle
/* pblni.tData Bl.tmap l.mage data
/* pbmi.InfoTable Bi.tmap BITMAPINF0 table
/*
/* If the I.nput data i.s provi.ded by a .bmp bl.tmap resource fi.le, the l.nput
/* parameters can be establl.shed from the data as shown below.
/*
/* PBYTE pbB1.tmapF1.leData ; pol.nter to start of .bmp fi.1e data
/* PBITMAPFILEHEADER pbmfh ; pol.nter to BITMAPFILEHEADER
/*
/* 1.f (((PBITMAPARRAYFILEHEADER)pbB1.tmapFi.1eData)->usType == BFT_BITMAPARRAY)
/* pbmfh = (PBITMAPFILEHEADER)((PBYTE)pbBi.tmapFi.leData
/* + sl.zeof(BITMAPARRAYFILEHEADER) -sl.zeof(BITMAPFILEHEADER));
/* else
/* pbmfh = (PBITMAPFILEHEADER)pbB1.tmapFi.1eData:
/* i.f (pbmfh->usType!=BFT_BMAP)
/* return(FALSE):
/* pbmi.InfoTable = (PBITMAPINFO)((PBYTE)pbmfh+sl.zeof(BITMAPFILEHEADER)
/* -si.zeof(BITMAPINFOHEADER));
/* pblni.tData = (PBYTE)pbBi.tmapF1.1eData+pbmfh->offB1.ts;
/*
sl'zlps.cx -0:
sl'ZIPS.cy -0:
I.f (hdcMem != DEV_ERROR) /* create PS and assocl.ate
hpsMem = Gpl.Createps( hab /* -anchor block handle
. hdcMem /* -DC handle for associ.ate
& s 1` z 1 P S /* -page sl'ze
PU PELS /* -Optl'Ons
GPTT MICRO
GPIA-ASSOC
)
l'f (fRet) /* query reall.ze support
fRet = DevQuerycaps( hdc /* -DC handle
CAPS_COLOR_TABLE_SUPPORT /* -start
1L /* -count
&1Devcolorsupport /* -returned flags
in
1.f (1Devcolorsupport & CAPS_COLTABL_REALIZE)
ulReali.ze= LCOL_REALIZABLE;
else
ulReali.ze = OL;
/* create logical color table for
/* bi.tmap PS (must be reali.zable
1'f (fRet) /* but need not be reali.zed)
fRet = Gpi.CreateLogcolorTable( hpsMem /* -PS handle
LCOL_RESET /* -vall.d options
u 1 R e a 1 i. z e
LCOLF_CONSECRGB /* -format
OL -start 1.ndex /*
ml.n( 1Numcolors /* -number of colors
lNumDevi.cecolors)
(PLONG)pbcolorTable /* -RGB table data
return ( f Ret ) ;
The default (or reset) color table mode is index mode and the system provides a
default color table of 16 entries with symbolic constants defined for each, plus
certain other predefined non-index values as illustrated below.
143
144 OS/2 PRESENTATION MANAGER GPI
PS LOGICAL
COLOR TABIE
(INDEX HOPE)
ROB-3 15
RGB+ 0
RGB-5 3
RGE-6 9
RGB-7 8
RGB-8 1
Rob-9 13
RGB-10 6
RGB-11 14
RGB-12 2
RGB-13 12
RGB-14 7
RGB-15 11
Note: RGB-6a, for example, 1s the dovlc® RGB color that Dost closely
DatcheB ROB-6, the r®qu®sted RGB color.
LCOLF RGB
LCOLF INDRGB
This loads the supplied color data, which consists of an array of index-RGB pairs.
Depending on its index value, each new pair of index-RGB values will either
replace an existing entry or extend the table. If the color table was previously in
RGB mode, it is switched to index mode and reset to the default color table before
the new data is loaded.
LCOLF CONSECF}GB
This loads the supplied color data, which consists of an array of RGB values with
consecutive indices starting from a specified index. Depending on its index value,
each new RGB value will either replace an existing entry or extend the table. If
the color table was previously in RGB mode, it is switched to index mode and reset
to the default color table before the new data is loaded.
LCOL RESET
This resets the color table to the default color table before loading the new data.
This reset is implicit whenever the format parameter specifies a switch from RGB
to index mode.
LCOLF REALIZABLE
If supported by the presentation driver, this creates a realizable color table (see
below). This option is valid only for index mode (i.e., LCOLF_INDRGB or
LCOLF_CONSEGRGB) and will force the LCOL_PURECOLOR option for any
drivers that support realizable color tables.
COLOR TABLES 14]
LCOLF PURECOLOR
This indicates that only pure colors are required. Dithering may not be used to
simulate unavailable colors.
For non-realizable color tables in either index or RGB mode, each RGB value is
napped to the nearest available RGB value in the fixed physical color palette of
the device. Realizable color table support enables an application to create its own
realizable color table and then realize it (i.e., reload the device color palette with
application specified RGB values). This enables high quality scanned images to be
displayed using bitmaps.
The actual colors obtained when a realizable color table is realized depend, of
course, on the color resolution of the particular device. The RGB values are
assumed to be psychometric and are corrected accordingly by the driver before
they are loaded into the physical device palette. It is not possible to load the device
palette with unmodified RGB values from an application.
Forabitmap,noremappingofbitmapconteritdataoccurswhenthecorrespond-
ing PS color table (i.e., the color table of the PS associated with the OD MEMORY
DC into which the bitmap is selected) is realized. For performance r:asons, the
color mapping for a bitmap occurs when its contents are initialized. A suitable
realizable color table must therefore be created Out not realized) before the
bitmap data is initialized.
Realizable color tables are supported only in index mode. To be realized, a color
table must first be created with the LCOLF_REALIZABLE Option. A realizable
color table can then be realized and unrealized using:
GpiRealizecolorTable; and
GpiunrealizecolorTable.
A complete screen repaint is essential after each of these operations in order to
obtain the correct display screen appearance.
Clearly, reloading the device color palette will affect the appearance of all
windows on the display screen. To avoid interfering with other applications visible
on the display screen, GpiRealizecolorTable should only be issued when the
relevant window is maximized and has the input focus. GpiuhRealizecolorTable
should be issued as soon as the window is unmaximized or loses the input focus.
For hard copy devices such as printers, realize is not applicable. These do not
have the problem of displaying the output from different applications simulta-
neously and should therefore always provide the best color match possible for the
requested colors.
While a realizable color table is unrealized, its colors will be displayed from the
physical device palette exactly as if it were realized, and are therefore unlikely to
appear correct.
On early levels of IBM OSA Version 1.2, GpiRealizecolorTable was not sup-
lan Os/2 pRESENTATioN MANAc;ER Gpl
ported by any driver. Support was added, together with gray scale palette im-
provements for image support, on a 1.2 Corrective Service Diskette and also on
Version 1.3. Support is for the 8514/A display driver only and it is not currently
supported by any other driver.
Realizable color tables should not be dissociated from their DC or the
LCOLF_REALIZABLE (and LCOLF_PURECOLOR) option will be lost. See chap-
ter 5 for a description of how bitmaps are used with realizable color tables.
COLOR 0lJERIES
GpiQueryLogcolorTable
For Index Mode, this returns the contents of the logical color table.
For RGB Mode, it provides a return value indicating that the table is in RGB mode.
GpiQuerycolorData
This returns the format (default, Index Mode, RGB Mode) and largest index
currently loaded for the logical color table.
GpiQueryRealcolors
This returns the RGB values of the actual colors available on the associated output
device. If applicable, it can be used to obtain the values that would apply when a
realizable color table is realized.
GpiQueryNearestcolor
This returns the actual RGB color of the associated device that is closest to a
specified RGB value.
GpiQuerycolorlndex
This returns the logical color index for the associated device color that is closest to
a specified RGB value.
GpiQueryRGBColor
This returns the actual RGB value that will be provided by the associated device
for a specified logical color index. If applicable, it can be used to obtain the value
that would apply when a realizable color table is realized.
COLOR TABLES 149
createlo.c */
OL CreateLogi.calcolorTable( HPS hps )
Reset the logl.Gal color table and load l.t 1.n l.ndex mode wl.th l.ndexed-RGB
val ues .
return ( fRet ) :
The Gpi transform functions provide a mechanism for two dimensional scaling,
translation, rotation, and shear in graphics pictures (and text). Device indepen-
dence is provided by allowing an application to define its picture in device
independent page units.
Chapter 1 illustrated how to perfo]rm simple rotation, scaling, and shear using
the transformation `helper' functions: GpiRotate, Gpiscale, and GpiThanslate, and
also pointed out that such operations could also be accomplished by specifying the
required matrices directly without using the `helper' functions. This is illustrated
in the examples below (see Appendix 3 for a brief introduction to coordinate
transformations and matrices).
For rotation, the following two sequences are exactly equivalent, performing a
30-degree counterclockwise rotation about the point (100,150).
and
(
stati.c MATRIXLF matlfModel = { Oxl0000, OL, OL, OL, Oxl0000, OL, OL, OL,1L }:
150
COORDINATE SPACES AND TRANSFORMATION 151
For scaling, the following two sequences are exactly equivalent, performing scal-
ing by a factor of 2.0 in both the x and y direction about the point (100,150).
(
/* scale by 2.0 1.n both x and y dl.rectl.on about the poi.nt (100,150) */
and
(
stati.c MATRIXLF matlfModel = { Oxl0000, OL, OL, OL, Oxl0000, OL, OL, OL,1L );
For translation, the following two sequences are exactly equivalent, performing
translations of +50 and +100 in the x and y directions respectively.
152 OS/2 PRESENTATION MANAGER GPI
(
/* translate by +50 and +100 i.n the x and y di.rectl.ons respecti.vely */
ptlposn.x = SOL;
ptlposn.y -100L:
Gpl.Translate( hps /* -PS handle */
&matlfModel /* -transform matrl.x */
TRANSFORM_REPLACE /* -Opt,.Ons */
&ptlposn /* -translati.on coordi.nates */
n
Gpi.SetModelTransformMatri.x( hps /* -PS handle */
9L /* -number of matri.x elements */
&matlfModel /* -transform matrl.x */
TRANSFORM_ADD /* -Opt,'Ons */
in
)
and
(
stati.c MATRIXLF matlfModel = { Oxl0000. OL. OL, OL, Oxl0000, OL, OL, OL,1L };
Note from the above examples that (when transforming a figure about a given
point) for operations other than translation, the figure origin must first be trans-
lated to (0,0) before the required (rotate, scale, shear, etc.) matrix operation is
performed, and translated back to its required position afterward. This is import-
ant to avoid undesirable translations (which occur when the translation offset is
scaled or rotated together with the figure). This translation is explicit when using
the `set transform' functions directly, whereas with the `helper functions' GpiRot-
ate and Gpiscale it is implicit. Note also that the TRANSFORM_ADD option
allows the transformi to be incrementally accumulated in steps, rather than being
overwritten each time.
The above examples illustrate use of the model transform matrix, which is
intended for transforming individual elements and figures within the picture
during drawing. Chapter 1 also mentioned the default view matrix that is provided
for scaling and scrolling the whole picture. The GPI, in fact, provides a hierarchy
of coordinate spaces and transforms each with its own distinct purpose.
Application specified coordinates are called world coordinates. These are trans-
formed by the various presentation space transforms, to provide the device inde-
pendent version of the picture in the PS page from where it is rendered to the
device. The units of the PS page together with the device resolution determine the
device transformi required to ensure that an inch (say) in the PS page appears as
an inch on the device. These conversions from world to presentation page to device
coordinates via the presentation space and device transforms are illustrated in
Figure 7-1.
COORDINATE SPACES AND TRANSFORMATION 153
!F:::in.te ir
Present.tlon
M Space TranafW
PS P®8®
As mentioned above, the page units together with the device resolution determine
the device transform. Page units are typically fractions of an inch or meter, but
can also be specified as device coordinates (i.e., PU_PELS) if required. The page
units (of the PS page) are specified as parameters to Gpicreateps and Gpisetps
(see chapter 2). For a cached PS, the page units default to PU_PELS.
The system provides the following choice of page units:
PU_ARBITRARY page units cause the picture to be displayed as
large as possible in the available device output area while preserv-
ing its aspect ratio (such that a circle remains a circle). For a display
window, the available device output area is assumed to be the maxi-
mized window or screen size.
PU_PELS page units are device units. These are pels for a raster
device and for a plotter are equal to the minimum line increment.
PU_LOMETRIC page units are 0.1 mm.
PU_HIMETRIC page units are 0.01 mm.
PU_LOENGLISH page units are 0.01 inches.
PU_HIENGLISH page units are 0.001 inches.
PU TWIPS page units are I/1440 inches (i.e., 1/20 of a printers
point)i
Although not recommended, an application can modify the device transfo]rm. using
Gpisetpageviewport to define its own page units (see below).
In addition to specifying the page units, an application must specify the page
154 OS/2 PRESENTATION MANAGER GPI
Apart from device transform, three presentation space transforms are visible to
an application. These are:
• Model Thansformi (including segment and instance transform).
• Viewing Thansform.
• Default Viewing Thransform.
Other system transforms, such as the translation associated with the position of
the window on the display screen, do exist, but these are transparent to an
application.
Model transform, viewing transfo]rm and default viewing transform are all
presentation space transforms affecting the appearance of the device independent
picture in the PS page, whereas device transfo]rm renders the PS page contents to
the device. The transformation `pipeline' showing the order in which these trans-
forms are applied is illustrated in Figure 7-2 and can be represented mathemati-
cally as:
Xd Yd = device coordinates;
Xw Yw = world coordinates;
M = model transforml matrix;
V = viewing transfo]rm. matrix;
DVT = default viewing transformi matrix; and
D = device transfo]rmi matrix.
In practice, world coordinates are not actually converted to each intermediate
coordinate space. The transforms are combined intemally allowing coordinates to
be transformed directly from world to device coordinates by the system in a single
operation. Nevertheless, the illustration in Figure 7-2 provides an accurate and
useful model for understanding the operation and purpose of the individual
matrices.
World
Coordinate
Space
HH
Model
Space
H
Vlowlng Transform
Default
Page
Coordin®to
Space
E3:::u=:Trap
PS page
Device
Coordinate
Space
The model and viewing transforms are picture attributes that can be varied
during drawing for the purpose of picture constmction, whereas the default
viewing (and device) transform. are environlnent attributes that should be estab-
lished before the picture is drawn.
Many applications need not be concerned with, or use, all of the available
transforms. As stated above, the basic model transfo]rm should be used for
transforming individual elements within a picture and the default viewing
transform for scrolling and scaling (i.e., pan and zoom) the entire picture. In
addition to the GpisetModelThansformMatrix function, the instance and segment
transforms provide two additional ways of controlling the model transformi
drawing attribute. Instance transform is a model transform specified with
GpicallsegmentMatrix, for use with called retained segments, and segment
transform is a model transform used exclusively at the star of retained segments.
Viewing transform is provided to enable the contents of an entire graphics
segment to be transformed without interference from (model) transform opera-
tions inside the segment.
The GpisetModelThansform.Matrix and GpisetDefaultviewMatrix functions
both have an options parameter controlling the way in which the new and existing
matrix values are combined. This may specify one of the following:
TRANSFORM REPLACE
The new transform matrix elements provided with the call are used to replace the
existing values.
TRANSFORM ADD
The new and existing transform matrix elements are combined by concatenating
the new matrix after the existing matrix. This can be represented mathematically
by:
TRANSFORM PREEMPT
The new and existing transformi matrix elements are combined by concatenating
the new matrix before the existing matrix. This can be represented mathemati-
cally by:
In a pipeline model (such as that illustrated in Figure 7-2), the new matrix is
placed before the original, and the output of the new matrix is effectively trans-
formed further by the original matr.ix (which is below it).
M21 M22 0
M31
IMll M32 0
M12 1
These matrix elements are passed as a parameter to any of the `set transformi
matrix' functions in a MATRIXLF structure in the order:
[ Mll M12 0 M21 M22 0 M31 M32 1 ]
The corresponding fields of the MATRIXLF structure are:
[fkM11 fkM12 lM13 fkM21 fxM22 lM23 lM31 lM32 lM33 ]
The elements fkMll, fkM12, fkM21, and fkM22 are of type FIXED while the
remainder are of type LONG. FIXED numbers are four-byte values with a notional
binary point between bytes 3 and 4. (See chapter 1 for a description of FIXED
numbers.)
000RD"ATE LIMITS
Where only rectangular transformations are used, the 16 bit device coordinate
limits (-32768, -32768) and (32767, 32767) can be back transformed (using
Gpiconvert) to world coordinate space to obtain the world coordinate limits that
will avoid device coordinate overdow. In the more complex case, when rotation and
shear are used, the device coordinate limits must be back transformed, using
Gpiconvert,tomodelspaceandcomparedagainsttheboundarydataofthepicture
(see chapter 10). Even this relies on the viewing and the default viewing trans-
forms providing only rectangular transformations.
GPI00NVERT
Model Transform
Model transform is a picture drawing attribute that can be varied during drawing
for the purpose of picture construction. This is is the `work-horse' transfol.in that
should be used for all picture modeling and construction purposes.
Using the TRANSFORM_REPLACE, TRANSFORM_ADD, and TRANS-
FORM_PREEMPI' options, an application can, if required, construct its own model
transformi pipeline of any complexity similar to that in Figure 7-2 but consisting
only of model transform matrices. The concatenation of all the matrices in such an
application model transformi pipeline provides the value of the model transform
drawing attribute represented by the single model transfo]rm in Figure 7-2.
Note that whenever model transfo]rm is changed, this is equivalent to beginning
a new sub-picture in a new world coordinate space (see Figure 7-2).
There are three forms of model transform, all of which contribute to the model
transformi drawing attribute. These are:
1. Model Thansform itself.
This is set and queried using:
GpisetModelThansformMatrix; and
GpiQueryModel'Thansform.Matrix.
GpisetModel'ThansformMatrix will set (or push and set) the current
value of model transfo]rm drawing attribute, store a set (or push and
COORDINATE SPACES AND TRANSFORMATION 189
RETAINED SEGRENI
GplQpons®gDent()
(Nan-Id®ntlty PS Matrix)
Internal Note that thl3
Gplset/Querys®gpent( ) > Segment ls not directly
Tran8forDHatrlx( . . s®gld. . ) Prolog vlslblo to an
application
ulil®sB recorded
ln a Hetdrlle
FIRST ELERERT >
Gplc.11S®gp®ntMatrlx()
2. Instance 'Thansform.
This is set using:
GpicallsegmentMatrix
Instance transform. is the name used for the model transform. matrix
specified as a parameter to GpicallsegmentMatrix. When the same
object (e.g., a wheel) is to be drawn more than once with different
positions and sizes, it can be stored once in a retained segment and
displayed by calling this segment multiple times. The instance trans-
form enables the position and size of each instance of the object to be
controlled by the matrix parameter on the individual calls.
GpicallsegmentMatrix will either `push and set' the current value of
the model transformi drawing attribute and then call the segment and
pop the old value, store a sequence of orders in the currently open
retained segment, or both, depending on drawing mode. In the re-
tained case, the orders stored are as illustrated in Figure 7-3. and
include push and set model transfol.in (GPSTM), call segment
(GCALLS), and pop (GPOP). The begin and end element orders serve
only to bracket together the group of orders identifying them as a
single element.
Note that regardless of attribute mode, in both non-retained and
retained cases the `push and set' version of set model transformi is
always generated by GpicallsegmentMatrix, and the call is always
followedbyapopfunctionthatensuresthattheoriginalvalueofmodel
transform attribute is preserved across the call.
Operation of the TRANSFORM_REpljACE, TRANSFORM_ADD,
and TRANSFORM_PREEMFT options with GpicallsegmentMatrix
is identical to that for GpisetModel'Thansfo]rmMatrix.
3. Segment Thansform.
This is set and queried using:
Gpis ets egmentThansform.Matrix; and
GpiQuerysegment'Thansfo]rmMatrix.
GpisetsegmentThansformMatrix applies only to retained segments
and does not modify the model transfo]rm drawing attribute until the
segment concerned is subsequently drawn. It creates and stores a
`push and set model transform' order (GPS'IM) in an internal prolog
at the start of an existing retained segment (see Figure 7-3). If a
segment has no intermal prolog, GpisetsegmentThansfo]rmMatrix will
create one and insert it at the start of the segment.
If TRANSFORM_REPIACE is specified with Gpisetsegment
ThansformMatrix, the existing value in the retained segment (if any)
is replaced. If TRANSFORM ADD or TRANSFORM PREEMFT are
specified,thenewvalueiscon-catenatedwiththeexistingvalueinthe
COORDINATE SPACES AND TRANSFORMATION 161
Viewing Transform
FORM_PREEMPI` options control the way in which the new matrix is combined
with the existing PS matrix. The viewing transform. drawing attribute is always
updated (from the segment prolog matrix) by a replace operation when the
segment is draun.
When Gpiopensegment is issued, the PS matrix is used to update the viewing
transformdrawingattributeortoconstructa`setviewingtransform'order(GSTV)
in an internal prolog at the start of a new retained segment, or both, depending on
drawing mode (see Figure 7-3). If the PS matrix value is identity, no internal
prolog is created when a segment is created. The segment, if chained, behaves as
if it contains an implicit `set viewing transform' order with an identity matrix (i.e.,
when the segment is drawn, the viewing transfo]rm drawing attribute is reset to
identity at the start of the segment). The viewing transform drawing attribute is
alwaysresettoidentityattheendofanydrawnrootsegmentandbyGpicloseseg-
ment when drawing mode is DM_DRAW or DM_DRAWANDRETAIN (see Figure
3-1).
When creating a segment for use as a called segment, the PS viewing transform
matrix should first be reset to identity (using GpisetviewingThansformMatrix)
before issuing Gpiopensegment to ensure that no set viewing transformi order is
stored in the segment. Such an order in a called seglnent would destroy the
transform pipeline model illustrated in Figure 7-2 and for this reason is ignored.
If present, it could result in an invalid interchange file when used to create a
MetaFile.
Note that for IBM OSA Version 1.3 at least, neither the viewing transform
drawing attribute nor the retained segment viewing transfo]rm matrix value can
be queried. Also, the retained segment viewing transfo]rm matrix value carmot be
modified. This is something of a disadvantage that affects the usefulness of this
p articular transform function.
Device Transform
It is the device transfo]rm that provides the requested page units for a particular
device. For page units of PU_PELS, its value is identity. For other page units, it is
the transformi from the page to the device that yields the required page units for
the particular device resolution. For any of the standard page units, its value is
established with the page units by:
Gpicreateps;
Gpisetps (without PS_NORESET option);
GpiplayMetaFile (with RES_RESET option); and
Cached PS allocation Gage units PU_PELS, device transfo]rm.
Identity).
Where its requirements are fully satisfied by the standard page units, an applica-
tion need not concern itself with device transform. If essential, however, it can
modify the device transfo]rm. to define its own page units. This is accomplished
using Gpisetpageviewport.
Unlike other transforms, device transfo]rm. is defined by two rectangles, those of
the page and the page viewport, with the actual matrix element values determined
as follows:
Mll = 0[2 -X1)/W
M12 = 0
M21 = 0
M22 = cr2 -¥1)/ H
M3i = xi + ive*quii - 1)
M32 = yi + i#*Or22 - 1)
(X1, Y1) and (X2,Y2) are the bottom left and top right coordinates of the page
viewport, with the top right coordinate (X2,Y2), exclusive (i.e., outside the rectan-
gle) because these are in device coordinates. W and H are the width and height of
the PS page where the page coordinates are (0,0) and (W-1,H-1). These points are
both inclusive (i.e., inside the rectangle).
This definition of device transfo]rm is illustrated in Figure 74. Like the page
viewport, which consists of a rectangular aITay of device pixels, the PS page is
viewed as a rectangular array of cells. One might assume that the center bottom
left cell (0,0) would transfo]rm to the center bottom left pel O[1,Y1) but this is
not the case. In the GPI model, the bottom left comer of the bottom left cell
(-1/2,-1#) transforms to the bottom left corner of the bottom left pel Q[1-1#,Y1-
1#). Similarly, the top right comer of the top right cell (W-|#, H-1#) transforms
to the top right comer of the top right pel (X2-14,Y2-1#). This model gives
greater accuracy when (say) the number of cells is small compared to the
number of pels.
164 OS/2 PRESENTATION MANAGER GPI
(V-I/2'II-|/2)
PAGE
(-112..-L12:)
(X2-1/2,Y2-I/2)
PACE
VIEWPORT
(Xl-1/2,Y1-1/2)
As the page coordinates are fixed by the page dimensions on PS creation (or by
Gpisetps), page units can only be changed by modifying page viewport coordi-
nates. The page viewport is set and queried using:
Gpisetpageviewport; and
GpiQuerypageviewport.
Note that page viewport is not automatically the same as the rectangle returned
from WinQuerywindowRect and neither the page nor the page viewport are
clipping rectangles. These two rectangles merely serve to define the device trans-
formi that provides the required page units.
As mentioned earlier, either or both page dimensions may be defaulted causing
them to be set to the corresponding default device dimensions or, in the case of a
display, the display screen size. In the case of PU_ARBITRARY page units, the size
of one dimension will be constrained, where necessary, to ensure that the picture
aspect ratio is preserved.
The system will compute page viewpori coordinates for existing page units even
when Gpisetpageviewport has not been issued. These can then be queried and
used in the calculation of new page viewpord values or used at any time with
Gpisetpageviewpord to restore the page units to their original value.
It is recommended that, wherever possible, applications should use standard
page units rather than defining their own. This is because application defined page
units are not stored in either a MetaFile or an OD_QUEUED (PM_Q_STD) print
file (see chapters 11 and 12).
COORDINATE SPACES AND TRANSFORMATION 165
With one exception, page viewport (i.e., device transform) should not be used for
operations such as scaling and scrolling. The exception is for PU_ARBITRARY
page units where it is required to scale the picture to fit the window as it is sized.
The function ScaleTOFitwindow in Figure 7-5 illustrates how to scale a PU AR-
BITRARY presentation space to fit the window ®y default it is scaled to- the
display screen size rather than the maximized window size as doculnented).
scltofl't.c */
OL ScaleTOF1.twi.ndow(HPS hps, HWND hwnd, PRECTL prclpvlni.t)
Scale a pi.cture 1.n a PS wl.th PU_ARBITRARY page unl.ts to fl.t the wi.ndow
when l.t has been sl.zed.
/ ****************************************************************************** I
/**/
/* If current wi.ndow x/y > i.deal wi.ndow maxl.mi.zed x/y aspect rati.o */
/* calculate scale factor to fi.ll wi.ndow verti.cally */
1* else *1
/* calculate scale factor to fl.11 wi.ndow hori.zontally */
/**/
I ****************************************************************************** 1
/ ****************************************************************************** /
/**/
/* Use scale factor to calculate new page vl.ewport hel.ght and wi.dth then */
/* calculate new page vi.ewport coordi.nates. */
/**/
1 ****************************************************************************** /
return ( fRet ) ;
)
removetr.c */
OL RemoveTranslati.on(HPS hps)
retu rn ( f Ret ) ;
The GPI provides four different application clipping functions providing both
picture and environment clipping. These provide clipping to a single rectangle, a
shape defined by a number of rectangles, or an arbitrary shape of almost unlimited
complexity. By default, each of these functions provides no clipping.
The four GPI clipping functions are:
Viewing Limits
The viewing limits define a single clipping rectangle in model space. This is a
primitive drawing attribute that can be varied as the picture is drawn. Its purpose
is to enable part of a picture to be clipped to a single rectangle in model space
during picture construction® Points on all boundaries of the viewing limits are
inclusive (i.e., inside the rectangle) and are therefore unclipped. See chapter 3 for
a description of the viewing limits attribute functions.
Graphics Field
The graphics field defines a single clipping rectangle in the PS page. This is an
environment attribute that should be set initially and not varied as the picture is
drawn. Its purpose is to enable the entire picture to be clipped to a single rectangle
in the page. Points on all boundaries of the graphics field are inclusive (i.e., inside
the rectangle) and are therefore unclipped. The graphics field is set and queried
using:
168
CLIPPING AND REGIONS leo
GpisetGraphicsField
GpiQueryGraphicsField
Note that graphics field does not confo]rm to the MetaFile interchange architecture
and, although it can be used in MetaFiles for interchange with other OSA
workstations, it should not be used when recording MetaFiles for interchange with
other products (see chapter 11).
Clip Path
The clip path defines an arbitrary clipping shape of any complexity (subject to
intermal implementation limits). A clip path is defined initially as a normal path
in world coordinates using normal GPI drawing primitives. Once `output' and
converted to a clip path, it becomes fixed in device coordinates and is unaffected
by subsequent transformi changes. Clip path is a picture clipping object that can
be varied as the picture is drawn. Its purpose is to enable part of, or the entire
picture, to be clipped to any complex shape. Points on all boundaries of the clip
path are inclusive (i.e., inside the clip path) and are therefore unclipped. See
chapter 3 for a further description of the clip path.
Clip Region
The clip region provides a clip boundary defined by one or more rectangles in
device space. This is a PS environment attribute that should be set initially and
not varied as the picture is drawn. Its purpose is to enable the entire picture to be
clipped to a complex shape defined by a number of rectangles in device space. As
it is defined in device space, clip region is not subject to rounding eITors that may
occur with other clipping functions. Atypical use is to provide the clipping required
by the newly exposed area that must be redrawn after (say) a scroll operation is
performed using GpiBitBlt.
Note that the clip region does not confo]rm to the MetaFile interchange architec-
ture and although it can be used in MetaFiles for interchange with other OSA
workstations,itshouldnotbeusedwhenrecordingMetaFilesforinterchangewith
other products (see chapter 11).
A further description of region and clip region functions is provided below.
coordinates, are inclusive at the bottom and left coordinate boundaries, and
exclusive at the top and right coordinate boundaries (i.e., the bottom and left
boundaries are inside the rectangle and are unclipped; the top and right bound-
aries are outside the rectangles and are clipped).
A region must be explicitly selected as a clip region to enable it to be used for
clipping.
Region Functions
GpiExcludeclipRectangle; and
GpilntersectclipRectangle.
These functions automatically create a clip region if one does not already exist
(such a region does not need to be destroyed by the application when no longer in
use).
Functions also exist to query the bounding rectangle of a region and to query the
handle of the currently selected clip region. These are:
GpiQueryclipBox; and
GpiQueryclipFlegion.
Region Complexity
A number of the above region and clip region functions return the complexity of
the region or clip region as one of:
RGN_NULL The region or clip region is a null rectangle (no clip-
ping).
RGN_RECT The region or clip region is a simple rectangle.
RGN_COMPIEX The region or clip region is a complex shape de-
fined by two or more rectangles.
Orders, Elements, and Segments
DRAWING ORDERS
172
ORDERS, ELEMENTS, AND SEGMENTS 113
Long Orders
These are orders of variable length between 3 and 257 bytes. Long orders have the
form:
Byteo = order code (not 1-byte, 2-byte or extended)
Bytel = length of following data (255)
Byte2+ order data
An order is a long order if the order code is neither a 1-byte nor an extended order
code, and does not satisfy the criteria for a 2-byte order (i.e., order code is not OxOO,
OxFF, OxFE and bit7=1 or bit3=0). Examples of long orders are:
Byteo = Ox81 GCLINE qine at Current Position)
Bytel = length of following data
Byte2+ xy coordinate points
Extended Orders
These are orders that have a variable length of up to 64K bytes. They are
identified by a unique order code (OxFE) followed by an order qualifier, providing
the real order code, and a 2-byte length field. Note that bytes 2 and 3 of the order,
which contain the 2-byte length field, have the high order byte first; this is the
reverse of the normal 2-byte numerical representation. Extended orders have the
form:
Byteo = OxFE (extended order)
Bytel = order qualifier (i.e., actual order code)
Byte2 = length of following data (MS byte)
Byte3 = length of following data (LS byte)
Byte4-n order data
An order is an extended order if its order code is OxFE. Examples of extended
orders are:
Byteo = OxFE (extended order)
Bytel = OxC3 GCHST (Character String at Given Position)
Byte2 = length (MS byte)
Byte3 = length (LS byte)
Byte4-n xy position, character string
Order Buffers
Although normally used within elements and segments, order buffers can be
transferred between application memory and the presentation space using:
GpifutData; and
GpiGetData.
GpiputData can be used to draw a buffer of orders, store them in a retained
segment, or both, depending on the drawing mode. The buffer need not contain a
whole number of complete orders. If there is an incomplete order at the end of the
buffer, then this will be returned to the application unprocessed enabling the
116 0S/2 PRESENTATION MANAGER GPI
ELEMENTS
GRAPHICS SEGMENTS
S®gr®nt Attrlbut®s
11
ATTh I)ETECTABLE
ATm_vlslBIE
AT" CHAINED
Am_I)vNAMlc
Am_FASTCRAIN
Arm_pROp_I)ETECTA814E
Am_pRop_vlslBIE
crretseg.c */
L CreateRetai.nedsegment(HPS hps, LONG Isegld)
nt.x -100L:
nt.y -100L;
/* draw to segment */
fRet = (B00L)Gpl.Charstrl.ngAt( hps
&ptlpo,tnt
NSEGCHARS
SEGCHARS
in
return ( f Ret ) :
The GPI allows the entire graphics picture to be stored in, and redrawn from, a
Normal-PS segment store. This is called `retained graphics.' The GPI retained
graphics model defines a picture as a single chain of one or more retained graphics
segments. A segment is chained if its ATI`R_CrlAINED segment attribute is set.
A chained segment is sometimes called a root segment. Unchained retained
segments may also exist and may be drawn individually by the application using
GpiDrawsegment, called from other chained or unchained segments, or called
directly by an application using GpicallsegmentMatrix.
A typical retained segment store stmcture containing both root (chained) and
called (unchained) segments is shown in Figure 9-3, which also illustrates the
segment drawing functions :
GpiDrawchain;
GpiDrawFrom; and
GpiDrawsegment.
GpiDrawchain draws the entire segment chain including all segments called
directly and indirectly from the root segments. GpiDrawFrom draws a range of
segments in the chain from a specified first to a specified last segment. All
segments called directly and indirectly from the drawn root segments are also
drawn. The first segment must be in the chain and neither first nor last segment
id may be specified as zero. If the specified last segment does not appear
between the first segment and the end of the chain, it is not an eITor; drawing
continues to the end of the chain. GpiDrawseglnent draws a single specified
segment including all segments called directly and indirectly from it. The
specified segment may be chained or unchained but its id may not be specified
as zero.
When using GpiDrawFrom or GpiDrawchain, the position of a root segment in
the chain determines whether it is drawn on top of, or beneath the other segments
in the chain and is called the Segment nriority. The segment drawn last in the
chain is displayed on top of all the others and therefore has highest priority. Each
new segment that is created is added to the end of the chain. The priority of a
segment can be queried and changed using:
GpiQuerysegmentl}riority; and
Gpisetsegmentllriority.
GpiQuerysegmentFlriority specifies a reference seglnent id together with either
LOWER_PRI or HIGRER_PRI and the function returns the id of the segment
immediately before or immediately after the reference segment (or zero if the
reference segment is at the start or end of the chain).
Gpisetsegmentnriority specifies the id of both a target and reference segment
and specifies either LOWER_PRI or HIGHER_PRI to indicate where the target
should be positioned relative to (i.e., immediately before or immediately after) the
reference segment. If LOWER_PRI is specified with a reference segment id of Zero,
then the target is given highest priority in the chain (i.e., positioned at the end of
the chain). If HIGHER_PRI is specified with a reference segment id of a zero, then
the target is given lowest priority in the chain (i.e., positioned at the start of the
chain).
The segment chain structure for a MetaFile is similar to that for segment store.
The main difference is that called segments in an imported MetaFile may be
chained or unchained (as permitted by the architecture) whereas those in the GPI
PS segment store must be unchained.
DRAWING MODES
GPI primitive drawing and attribute functions are either drawn immediately,
stored as elements in the currently open retained segment, or both, depending on
the PS drawing mode (i.e., draw, retain, or draw and retain). Drawing mode is
controlled by:
GpisetDrawingMode
ORDERS, ELEMENTS, AND SEGMENTS 181
SEGMENT ATTRIBUTES
Segments have a number of properties called segment attributes (see Figure 9-1)
that each have a Boolean value of AITR_ON or ATI`R_OFF. In addition, the PS
contains a set of `initial segment attributes' that determine the initial segment
attribute values for a newly created segment at the time it is first opened. The
`initial segment attributes' of the PS can be set and queried using:
ATTR DETECTABLE
The segment is enabled for the detection of retained correlation hits (see
chapter 10).
182 0S/2 PRESENTATION MANAGER GPI
AITR VISIBLE
ATTR CHAINED
The segment is chained. Setting or resetting this attribute for an existing retained
segment causes the segment to be added to or removed from the segment chain.
ATTR DYNAMIC
ATTR FASTCHAIN
The segment is fast chained. This is a performance hint allowing the system to
omit the attribute reset that otherwise occurs at the start of each root segment as
it is drawn. The ATI`R_FASTCHAIN attribute applies to chained (root) segments
drawn using GpiDrawchain and GpiDrawFrom.
If fast chaining is specified then the application undertakes to set every attri-
bute used within the segment to the required value before it is used. It is good
practice to set fast chaining off for the first segment in the chain at least, or else
issue GpiResetps (to ensure that the attributes are reset) before each
GpiDrawchain or GpiDrawFrom function call is issued. Failure to do this can give
strange effects. For example, if all segments are fast chained with no reset
performed, then one segment setting the model transfo]rm with some translation
can cause the picture to move progressively across the screen (and eventually out
of view) each time GpiDrawchain is issued.
Note also that fast chaining does not guarantee that attributes will not be
reset-it merely gives the system this option. In a future implementation, the fast
chaining attribute could well be ignored such that attributes are always reset at
the start of each root segment. This would still represent a valid implementation
of the architecture. An application should therefore never rely on the inheritance
of non-default attribute settings from one chained segment to another.
The segment will propagate the ATI`R_VISIBLE attribute to any segment it calls.
In general, every retained segment in segment store must have its own unique
segment id. The one exception to this rule is for segments with an id of zero that
can occur more than once in the segment chain. Whereas Gpiopensegment
ORDERs, ELEMENTs, AND SEGMENTs lee
specifying a non-zero segment id will reopen any existing retained segment with
that id, if the id is zero, a new segment will always be opened. Segments with zero
id have the following restrictions:
• They cannot be edited.
• They must be chained.
• They cannot have their segment transfo]rm set or queried.
• They cannot have their segment attributes set or queried.
• They cannot have their segment priority set or queried.
• They cannot return a coITelate hit.
• They cannot be specified with GpiDrawsegment or GpiDrawFrom.
Segments with a zero id can be drawn by GpiDrawchain or GpiDrawFrom as part
of the segment chain and will contribute to boundary data.
Any primitive or attribute functions issued outside a segment bracket when
recording a MetaFile are recorded in the MetaFile as segments with an id of zero.
The function SubpictureMetaFile (in chapter 11), for example, illustrates the
use of Gpiopensegment with a zero segment id for the purpose of setting the
viewing transform matrix attribute before clearing the background rectangle.
HOH-RETAINED SEGMENTS
DRAW CONTROLS
The PS has a number of draw controls each with a Boolean value of DCTL ON or
DCTL_OFF. These can be set and queried using:
GpisetDrawcontrol
GpiQueryDrawcontrol
184 OS/2 PRESENTATION MANAGER GPI
DCTL ERASE
DCTL DISPLAY
This causes output to be visible on the device. If this control is not set, no output
is displayed. GpiErase is unaffected by this attribute.
DCTL BOUNDARY
DCTL DYNAMIC
This causes dynamic segments to be implicitly removed and redrawn around any
GpiDrawFrom or GpiDrawchain operation (see below).
DCTL COPRELATE
STOP DRAW
Many GPI graphics drawing operations can take a considerable time to complete
and should normally be performed on a separate thread from that used for
message queue processing. For most GPI functions, it is invalid to use the same
PS on more than one one thread simultaneously. The one exception to this is
GpisetstopDraw, which enables any of the following functions to be terminated
(with a logged waming):
GpiDrawsegment;
GpiDrawFrom;
GpiDrawchain;
GpiDrawDynamics;
GpiplayMetaFile; and
GpifutData.
A draw operation would normally be terminated (and perhaps restarted with
different data) in response to an event on the message queue. A GpisetstopDraw
ORDERS, ELEMENTS, AND SEGMENTS 1&5
DYNAMIC SEGMENTS
SEGMENT EDITING
The GPI provides functions for editing the contents of existing retained segments.
These allow deletion, insertion, and replacement of elements in the cuITently open
retained segment.
To assist editing, label elements with numerical label values can be used to mark
reference points in the segment. A label element is similar to the segment tag
element used for correlation (see chapter 10) and like the segment tag, produces
no output to the device when drawn. Label elements are normally stored in the
segment at creation time using:
GpiLabel
To edit an existing retained segment, the segment is reopened by specifying its id
with:
Gpiopensegment
Many segment editing operations use the element pointer. The element pointer
starts at zero and increases by one for each element from the start of the segment.
Elements can be replaced or inserted in the segment at the cument element
pointer position using any of the normal drawing primitive and attribute functions
(including GpiBeginElement, GpiEndElement, and GpiElement).
On reopening a segment, the element pointer position is reset to zero, which is
immediately in front of the first element, and is incremented by one each time an
element is inserted or replaced at the current element pointer. Note that when the
current element pointer position is zero, which is before the first element, a new
element can be inserted but not replaced.
The element pointer value can be set and queried using:
GpisetElementpointer;
GpisetElementpointerAtLabel;
GpioffsetElementpointer; and
GpiQueryElementpointer.
Whether a new element is inserted, or replaces an existing element, is determined
by the PS edit mode, which can be set to either SEGEM_INSERT which is the
default, or SEGEM_REPLACE. The PS edit mode is set and queried using:
ORDERS, ELEMENTS, AND SEGMENTS 1&J
GpisetEditMode; and
GpiQueryEditMode.
Functions also exist to delete the element at the cuITent element pointer, all the
elements in a given range (including the first and last in the range), and all the
elements between two labels (excluding the labels). These are performed using:
GpiDeleteElement;
GpiDeleteElementRange; and
GpiDeleteElementsBetweenLabels.
The element type and description string can be queried for the element at the
current element pointer position using:
GpiQueryElementType
Note that a segment with segment id of zero cannot be edited.
An example of segment editing is illustrated by the function Editsegment in
Figure 9-4. This opens a segment, replaces the first element, sets the element
pointer to a label, and inserts two new elements.
In addition to the functions for editing the contents of individual segments and for
modifying segment attributes, a number of whole segment editing functions exist,
some of which have been mentioned earlier. Segments are created, reopened and
closed using:
Gpiopensegment; and
Gpiclosesegment.
Segment priority is set and queried using:
Gpisets egmentpriority; and
GpiQuerysegmentl}riority.
The identity of all existing segments in a given range can be queried using:
GpiQuerysegmentNames
Individual segments or a range of segments can be deleted using:
GpiDeletesegment; and
GpiDeletesegments.
188 OS/2 PRESENTATION MANAGER GPI
edl.tsegm.c */
L Edi.tsegment(HPS hps, LONG Isegld)
Set drawl.ng mode to DM_RETAIN, reopen the specl.fl.ed segment, edi.t l.t as */
descrl.bed below and draw the chai.n. */
It i.s assumed that the PS drawl.ng mode may not be DM_RETAIN on entry. */
*/
segment 1.s edl.ted as follows: */
ace the fi.rst element wi.th a Set Current Posi.tl.on (OCODE_GCSP) element.*/
the element poi.nter to label wl.th value 6. */
rt a Set Current Posi.tl.on (OCODE_GSCP) element. */
rt a Li.ne at Current Posl.ti.on (OCODE_GCLINE) element */
*/
*/
puts: hps Ps handle
lsegld Segment ID */
*/
#defl.ne LBL6 6L
Pol.nt.x -300L;
Pol'nt.y -300L;
/* replace element by OCODE_GSCP
fRet = Gpi.Setcurrentposi.ti.on( hps /* -PS handle
&ptlpoi.nt /* -coordi.nate poi.nt
in
Poi.nt.x = 200L:
Pol'nt.y -200L;
/* 1.nsert OCODE_GSCP element
fRet = Gpi.Setcurrentposl.tl.on( hps /* -PS handle
&ptlpoi.nt /* -coordi.nate poi.nt
in
Pol'nt.x -OL;
PO,.nt.y -100L;
/* i.nsert OCODE_GCLINE element */
fRet =(B00L)Gpl.L1.ne( hps /* -PS handle */
&ptlpol'nt /* -coordi.nate pol.nt */
in
return ( fRet ) ;
CORRELATION
Hen-Retained Correlation
190
CORRELATION AND BOUNDARY DATA ACCUMULATION 191
Retained Correlation
Special puxpose functions exist to perfo]rm correlation on retained graphics seg-
ments. These specify the pick aperture position and the target segment or seg-
ments as parameters to the correlate request. The target can be an individual
segment, part of the segment ®icture) chain, or the complete chain.
In addition, where multiple hits are returned from a single retained correlation
operation, the segment tag attribute can be used by the application to distinguish
between the different hits.
Retained correlation is performed by processing the target segments exactly as
if they were being drawn, but performing correlation rather than drawing. Re-
tained coITelation is performed using:
Gpicorrelatechain;
GpicorrelateFrom; and
GpicoITelatesegment.
GpicorTelatechain performs correlation on the entire segment chain.
GpicorrelateFrom performs correlation starting from a specified segment and
stopping at a different specified segment. If the `stop' segment is not found during
the correlate operation, it is not an error, correlation continues to, and stops at, the
end of the chain. GpicoITelatesegment performs correlation on a single specified
segment.
Any retained correlation operation will also include all segments called directly
or indirectly from the specified segments, provided the segment attribute and tag
order values are set to enable correlation.
192 OS/2 PRESENTATION MANAGER GPI
The segment tag attribute associates a numerical tag value (or pick identifier)
with subsequent primitives in a retained segment for the puxpose of retained
correlation. GpisetTag will cause a Set (or Push and Set) Pick Identifier element
to be stored in the open segment at the cuITent element pointer position. When a
retained correlate hit is returmed, the tag attribute value at the hit location is
returned with the segment name to the application (see Figure 10-1). This enables
an application to determine the position of the hit and to distinguish between
different hits within the same segment. Multiple hits in the same segment with
the same tag value are registered as a single hit. When the segment is drawn, the
tag elements produce no output to the device.
If the tag value is zero (the initial default) or a segm.ent has a zero segment
identifier, correlation is disabled. Correlation is also enabled or disabled by the
GplsatTag(hp8 , 0) >
Gpls®tTag(hpB , 4) >
GplsetTag(hp8, 2) >
Asacalledsegmentmaybecalledmultipletimes,itmustbepossibletodeterm.ine
the calling context of any hit. The coITelate information is returned, last hit first, in
an array of `segment identifier -primitive tag' pairs. The application specifies both
the maximum number of hits 04ax Hits) and the maximum number of id/tag pairs
to be returned for each hit (MaxDepth). The retained coITelation functions also
provide the number of hits returned identifying the size of the returned array.
Unused icy/tag pairs in the array are set to zero. The following are examples of
returned correlate information for different values of MaxHits and MaxDepth.
MaxHits = 1 MaxDepth = 1
MaxHits = 2 MaxDepth =4
OxOOO8 Tag =8
0x0006 Tag =6
OxOOOO unus ed
OxOOOO unused
OxOOOO unused
OxOOOO unus e d
Ox0004 Tag =4
Ox000 3 Tag =3
Ox0002 Tag =2
194 0S/2 PRESENTATION MANAGER GPI
BOUNDARY ACCUMULATION
195
196 0S/2 PRESENTATION MANAGER GPI
operation. The offset and length parameters enable it to be issued multiple times
to transfer the data in blocks, one buffer at a time.
To transfer data from a MetaFile to application memory, GpiQueryMetaFile
Length can be used to determine the size of the MetaFile and, having allocated
sufficient memory, GpiQueryMetaFileBits can be used to transfer the data. Like
GpisetMetaFileBits, the offset and length parameters enable this function to be
issued multiple times to transfer the data in blocks, one buffer at a time.
A memory MetaFile may be drawn to a PS using GpiplayMetaFile described
below.
GPIPLAYMETAFILE
PMF SEGBASE
PMF LOADTYPE
PMF RESOLVE
PMF LCIDS
PMF RESET
PMF SUPPRESS
PMF COLORTABLES
PMF COLOREALIZABLE
PMF DEFAunTs
In general, any change to the PS environment or resources after the start of the
picture will be recorded as a MetaFile escape order. The picture staid occurs when
the first Gpiopensegment, drawing primitive, or primitive attribute function is
issued.
The rules for creating a valid MetaFile are as follows:
1. Page units and dimensions appear only once in a MetaFile and may
not be altered after the first association of a PS and MetaFile DC. Any
attempt to issue Gpisetps or GpiAssociate to associate the MetaFile
DC with a PS with different page units and/or size after the picture
start will return an error. The page units and size stored in the
MetaFile are specified for the PS either at creation tine or the last
Gpisetps (or GpiplayMetaFile with option RES_RESET) prior to
association with the MetaFile DC. Any modifications to page units/de-
vice transformi made using Gpisetpageviewport are ignored for the
purpose of MetaFile creation, even if performed before association
with the MetaFile DC.
Note that use of GpiAssociate to disassociate the MetaFile DC from its
PS and associate it with another PS is valid so long as the PS page
units and size of the new PS are identical to those already recorded in
the MetaFile.
2. Default viewing transfo]rm forms part of the MetaFile environment
information and should therefore be established before any drawing
occurs. If issued after the picture start GpisetDefaultviewMatrix will
be recorded as a MetaFile escape order.
3. WinDrawTezit and similar WinDraw functions are intended only for
output to display devices in non-retained mode. Such calls directed at
a PS associated with a MetaFile DC will be ignored and not recorded
in the MetaFile.
4. GpiBitBlt, Gpisetpel, and GpipaintRegion are intended for non-re-
tained use only. These functions, if issued during MetaFile recording,
are recorded as MetaFile escape orders. Note that GpiwcBitBlt is
supported by the MetaFile architecture and may be used for BitBlt
operations without producing MetaFile escape orders.
5. A valid MetaFile has no means of recording the graphics field. Graph-
ics field should therefore be set to no clipping (i.e., the default) for the
duration of MetaFile recording, otherwise GpisetGraphicsField will
be recorded as a MetaFile escape order.
6. Color tables form part of the MetaFile resources and should therefore
be established before any drawing occurs. If issued after the picture
start, Gpicreatel.ogcolorTable will be recorded as a MetaFile escape
order.
7. Default attributes form part of the MetaFile environment information
and should therefore be established before any drawing occurs. If
issued after the picture start, any of the following functions will be
recorded as MetaFile escape orders:
202 OS/2 PRESENTATION MANAGER GPI
GpisetDefAttrs;
GpisetDefviewingLimits;
GpisetDeITag; and
GpisetDefArcparans.
8. Avalid MetaFile has no means of recording the clip region. Clip region
should therefore be set to no clipping (i.e., the default) for the duration
of MetaFile recording, otherwise any of the following functions will be
recorded as MetaFile escape orders:
GpisetclipRegion;
GpiExcludeclipRectangle;
GpilntersectclipRectangle; and
GpioffsetclipRegion.
9. The draw control DCTL DISPLAY must be set (to DCTL_ONI for the
duration of MetaFile -recording. If the draw control is set to
DCTL_OFF during any drawing, or if GpisetDrawcontrol is used to
modify the DCTL_DISPLAY draw control after drawing has started,
this is recorded as a MetaFile escape order.
10. Logical font and bitmap ids form part of the MetaFile resources. These
are defined using GpicreateLogFont and GpisetBitmapld either be-
fore any drawing occurs or incrementally during drawing as they they
are required. GpiDeletesetld must not, however, be used to delete any
ids until after the PS and DC are disassociated, or, in the case of a
Micro-PS, should not be used at all (i.e., the system should be left to
delete the set ids when the PS and DC are destroyed). Any of these
functions, when used in an incorrect manner, are recorded as MetaFile
escape orders.
11. Bitmaps are used both as area fill patterns and as the source ofBitBlt
operations and therefore fo]rm part of the MetaFile resources. These
should be loaded (or created) before any drawing occurs or may be
added incrementally during drawing as they are required.
GpiDeleteBitmap should not, however, be used to delete any bitmap
before all required bitmaps have been created and bitmaps must not
be modified during drawing. If bitmaps are deleted prematurely or
modified during drawing, then incorrect data may be recorded in the
MetaFile.
12. None of the following functions should be issued. If issued, they will be
recorded as MetaFile escape orders.
GpiErase;
GpiResetps;
Gpisetcp;
M ETAFI LES TOO
Gpisaveps; and
GpiRIstoreps.
13. DevEscape calls with system escape codes in the range 8150-24449
and non-system escape codes in the range 40960-57343 are recorded
as MetaFile escape orders (note that for PM_Q_STD print files, the
corresponding ranges are 16300-32599 and 49152-65535 respectively).
Other DevEscapes may be passed to the display driver or ignored,
depending on the value of the individual escape code.
14. Only a limited range of foreground and background mix values should
be used. These are:
FM_DEFAULT,
FM_OR;
FM_OVERPAINI;
FM_LEAVEALONE;
BM_DEFAULT;
BM_OVERIIAINT; and
BM LEAVEALONE.
Other mix values will be recorded and will interchange successfully
with other OSA systems but may not be understood if interchanged
with other products conforming to the same interchange architecture.
15. Match numbers (i.e., the lMatch field in the FATI`RS structure) should
not be used for font creation when recording a MetaFile. Match
numbers are not recorded in the MetaFile.
16. Duplicate segment ids (other than zero) are invalid in a MetaFile.
GpiDrawchain, GpiDrawFrom, and GpiDrawsegment should not be
used to draw the same retained root segments more than once when
recording a MetaFile. Likewise, Gpiopensegment should not be used
to open a new non-retained segment with a previously used non-zero
segment id. A MetaFile containing segments with duplicate ids (other
than zero) may return an error when subsequently played.
17. Care must be taken when creating MetaFiles on one device for inter-
change with another. For example, whereas an 8514/A display driver
can support a color table (and color attributes) with up to 256 indices,
most other drivers can support only 64 (as returned by the
DevQuerycaps CAPS_COLOR_INDEX element). Exploiting the full
color capabilities of the 8514/A driver will therefore produce a MetaF-
ile that will not interchange successfully with a system using a VGA
for example.
204. OS/2 PRESENTATION MANAGER GPI
The PIF, or Picture Interchange File format, is an earlier IBM interchange format
that existed before the MetaFile architecture was established. PIF format resem-
bles that of a MetaFile and the Picture Utilities ®icichg, picshow, and picprint)
enable an end user to convert files from PIF to MetaFile format, and to display and
print both PIF files and MetaFiles. In addition, the Hcture function calls Piclchg
and Picprint allow equivalent PIF to MetaFile conversion and printing operations
to be accessed as application function calls.
Picnrint includes a parameter string, equivalent to the print queue processor
parameters on DevopenDC. Although PicFTint provides a simpler method of
printing a MetaFile than that described earlier using GpiplayMetaFile, it lacks
the flexibility provided by the GpiplayMetaFile options. Note that Piclchg also
provides the capability of converting symbol sets to fonts. Symbol sets resemble
fonts but represent an earlier character set architecture (used by PIF files and
other products).
recmeta.c */
OL RecordMetaFi.le (HAB hab, HPS hps, PSZ pszFi.lename )
Record a MetaFl.1e and save 1.t to di.sk. The i.nput PS must not be associated
wl.th a DC.
/* open a MetaFi.le DC
hdc = DevopenDC( hab /* -anchor block handle
OD_METAFILE /* -DC type
I * ,,
/* -token
9L /* -number of data elements
(PDEVOPENDATA)&dopData /* -open DC data
NULL /* -compati.ble hdc (N/A)
);
/,*,***************************************************************************1
/* */
): ::i!s:::?:::e:.:n:pT::::!e;: :::ira;T::Zs!g:eo::..::Tei:.::e]gg;:::r :)
/* color tables,1ogl.cal fonts, bl.tmaps, default attrl.butes, default vi.ew */
): 8:i|::o:T:t:: Page unl.ts). Note that GP1.Setps may not be I.ssued after :)
/* */
/****************************************************************************'1
&matlf
TRANSFORM_REPLACE
n
1` f ( f R e t ) /* assocl.ate PS and DC
fRet = Gpi.Associ.ate( hps /* -PS handle
hdc /* -DC handle
in
ptlpoi.nt.x = 100L;
ptlpo,.nt.y -100L;
l`f (fRet) /* draw to MetaFi.1e */
fRet = (B00L)Gpl.Charstrl.ngAt( hps
' &ptlpol'nt
M ETA F I L ET EXT L EN
METAFI LETEXT
1.f (hdc!=DEV_ERROR)
hmf = DevcloseDC(hdc); /* close the DC */
1.f (hmf !=DEV_ERROR && fRet) /* save MetaF1.1e to dl.sk */
fRet = Gpl.SaveMetaFi.1e( hmf /* -MetaF1.1e handle */
pszFi.lename /* -fi.le name */
n
else
fRet = FALSE:
retu rn ( f Ret ) ;
crtmeta.c */
CreateMetaFl.1e(HAB hab, LONG IDataLength, PBYTE pbMetaFi.leData)
/* open a MetaFi.le DC
hdc = DevopenDC( hab /* -anchor block handle
OD_METAFILE /* -DC type
* ,, /* -token
9L /* -number of data elements
(PDEVOPENDATA)&dopData /* -open DC data
NULL /* -compatible hdc (N/A)
in
I.f (hdc!=DEV_ERROR)
hmf = DevcloseDC(hdc); /* close MetaFi.le DC
playmeta.c */
OL PlayMetaF1.le(HPS hps, PSZ pszF1.1eName)
/* playmetm.c */
B00L PlayMetaF1.1e_Modi.fy(HPS hps, PSZ pszFi.leName)
/* Play the MetaFile fi.rst wl.th the reset and suppress opti.ons to reset the
/* PS to the page uni.ts etc. defi.ned i.n the MetaFi.1e. Next modi.fy the PS
/* resources as requi.red then play the MetaFi.le a second ti.me wi.thout
/* speci.fyi.ng reset and suppress to dl.splay I.t.
/*
/* In the example gi.ven here, the PS color table l.s modi.fi.ed to change the
/* background color to black and the neutral foreground color to whi.te. The
/* PS i.s then erased to black before drawl.ng the MetaFl.1e. Thl.s parti.cular
/* example wi.ll work for normal MetaFi.1es recorded wi.th default background
/* and foreground color table values as the MetaFl.le wi.ll not defi.ne the
/* actual RGB values for these colors. MetaFi.les that do defl.ne these RGB
/* values wi.ll requi.re the CTAB_NOMODIFY opti.on to be speci.fi.ed on the
/* second and fi.nal Gpi.PlayMetaFi.1e (i..e. to use the default color table).
/*
/* 1.nputs: hps PS handle
/* pszFl.leName fl.le name of MetaFi.le
/*
return (fRet);
prl'ntmet.c */
L Pri.ntMetaFi.1e(HAB hab, HPS hps, HDC hdc, PSZ pszMetaFi.le)
Note that the Reset opti.on must be used before Gpl.Assocl.ate to avoi.d a
PMERR_INCOMPATIBLE_METAFILE error. It 1.s assumed that the PS and DC are
not associ.ated on entry.
lLength -OL;
l'f (fRet) /* 1.ssue start doc DevEscape
fRet = DevEscape( hdc /* -DC handle
DEVESC_STARTDOC /* -escape code
PDOCNAMELEN /* -sl.ze of document name
PDOCNAME /* -null terml.nated doc name
&1Length /* -si.ze of output data (OL)
NULL /* -output data (not used
) --DEV_OK;
lLength = 2L:
1' f ( f R e t )
l.ssue end doc DevEscape
fRet = DevEscape( hdc -DC handle
DEVESC_ENDDOC escape code
OL length of i.nput data
NULL i.nput data (not used)
&lLength si.ze of output data
(PBYTE)&usJobld output data (ret job
) --DEV_OK:
1' f ( f R e t A )
fRet = Gpi.Associ.ate(hps, NULL) && fRet; /* di.ssoci.ate PS and DC
*/
return ( fRet ) ;
/* scalemet.c */
B00L ScaleMetaFi.le(HPS hps, HMF hmf, PRECTL prclTarget)
(
/* Play the speci.fl.ed MetaFl.le to the PS using the default vl.ew matri.x to
/* scale and translate the output to fi.t a speci.fl.ed rectangle i.n the PS
/* page, whi.le preservl.ng the aspect rati.o of the pl.cture. Note that l.f the
/* output devi.ce i.s a pri.nter then 1.t i.s the responsl.bl.1l.ty of the caller
/* to i.ssue the 'start document' and lend document' escapes before and after
/* I.nvocati.on.
/*
/* i.nputs: hps PS handle
/* hmf MetaFl.le handle
/* prclTarget Target rectangle 1.n page coordi.nates
/*
l.f (fRet) */
play MetaFi.1e
fRet = (B00L)Gpi.PlayMetaFi.le( hps -PS handle */
hmf -MetaFi.1e handle */
NOPTI0NS
-opti.on count */
alopns - 0 p t 1. 0 n s */
&lsegcount ret seg count (reserved) */
LDESC si.ze of descri.pti.ve array */
abDesc returned descri.pti.ve array*/
in
return (fRet);
)
/* subpi.cme.c */
B00L Subpi.ctureMetaFi.le(HPS hps, HMF hmf , PRECTL prclTarget)
return (fRet);
)
Throughout this chapter, the term printing is used to refer to both printing and
plotting. Also, in the examples, the terminology used for queue and printer names
is taken from IBM OS/2 Version 1.2 rather than 1.3. Queue names, for example,
are called LPI`1Q, LPI`2Q, COMIQ , and so forth, and printer names PRINTER1,
PRINTER2, PLOTI`ER1, and so forth. This scheme is followed in order to ensure
that queue names are distinct from printer names. Such a naming scheme can be
employed on Version 1.3, but by default, a queue and printer will both have the
same name (e.g., LASER1).
OSA provides a variety of different ways of printing enabling an end user or an
application to print:
• Gpi graphics and text.
• Raw (device dependent) printer data.
• Data in some other format unique to a particular print queue proces-
sor or queue processor and driver.
For many printer drivers, raw printer data is the same as raw ASCII text,
although raw printer data may include additional escapes that are specific to a
particular printer. The main exception is the Postscript driver ®script.drv), which
has its own unique format for raw data and does not currently support printing of
raw ASCII text.
Hrint operations can be either direct or queued (i.e., printed via the spooler).
With direct printing, data is output directly from an application (via the print
drivers) to the printer, bypassing the print queue. This method is used by the
system for printing queued print files when they are dequeued (see below).
219
220 OS/2 PRESENTATION MANAGER GPI
Direct printing is not really intended for norm.al application use. In a multi-ap-
plication system such as OSA, different applications may be attempting to print
concurrently. With direct (application) printing this could allow interference be-
tween print jobs from different applications, or force an end user to wait for
completion of one print job before being able to initiate another from the same
application.
If the OSA Spooler is disabled using the nrint Manager then this will force all
queued printing to be direct.
TYPES OF PRIHTIHG
OSA provides many different ways of initiating a print operation, all of which use
one of the following three types of printing.
The OSA Hrint Subsystem is illustrated in Figure 12-1 and shows the Spooler
Function Calls and the Base OSA File System (Base Control I}rogram I+inting)
outputbeingpassedtothespoolQueueManagerforenqueueingontheprintqueue.
Conceptually at least, presentation drivers consist of two parts. Hesentation
Driver (I) handles recording the data in the print file and Hesentation Driver (11)
handles the output to the printer. The output from PM print operations follows one
of two paths depending on whether printing is direct or queued. Direct output goes
directly to Hresentation Driver (11) for immediate printing, whereas queued output
PRINTING 223
->)>)ThoLPRIPta)S)CmFUNC
DevopenDC-
(OD.DIRECT
PMGPI
J
Present.tion Pro.ontation
D®vopenDC > Drlv®r (I) > Driver (11)
(OD_QUEUEI)
Hana8®r
Qu.u.
proce8aor
t[an&8er PMPRINITI3::i: . IPrintQu®u®[§p=::.qu.u.I
843® PrintI)ovlceI)riverBASEDD02.SYS
ING BaseOS/2>F1|®SyEtaaTI0NCALlis
Dosopen(LPT
Doswrlt®
Doacloae
INT17 (D0
PRINT Crm
COPY LFTI
Prtsc Key
Cro >pm
SPcOLER
i -I ±±
Spl API
Print®r3
Figure 12.1 0SA nrint Subsystem.
goes via the Hesentation Driver (I) to the Spool Queue Manager for enqueueing
on the print queue.
As mentioned earlier, queued operation print files from all applications are
removed from the print queue in turn, according to their priority, and printed by
the system using direct printing. All print jobs, both direct and queued, eventually
reach Fkesentation Driver (11) before being passed to the Base Print Device Driver
for printing. This enables the presentation driver, as a minimum, to reset the
driver between jobs, canceling any job related conditions remaining from the
T24 0S/2 PRESENTATION MANAGER GPI
previous job, and also enabling it to set any relevant job options (e.g., print quality,
number of characters per inch) required for the next job.
A ].ob in the print queue will only print if its `driver.device' name matehes that
of a printer associated with the queue, the printer is connected to a valid port, and
the form code specified for the job is either selectable or current (see below). If all
theseconditionsaresatisfied,thenthejobwiththehighestpriorityforaparticular
printer will be printed first on that printer.
If raw printer data is being printed and the reset between jobs is not required
®ecause, for example, the end user does not want the printer switch settings to be
overridden) then the IBENUIL driver, provided for this purpose, should be used.
In practice, I+esentation Drivers (I) and (11) do not normally exist as separate
components but they do provide a useful model for illustrating the operation of
direct and queued printing.
Although printer installation is a large and complex topic and is mainly outside
the scope of this book, an understanding of the underlying model is important.
Hinter presentation drivers (some of which have dot-qualified device names,
e.g., LASERJET.Iip LaserJet 11, PLOTTERS.IBM6180) are installed using the
Control Panel or nrint Manager.
FTinter set up involves establishing associations between:
• A printer name (e.g., PRINTER1).
• A single port or logical address (e.g., LPI'1).
•One or more presentation driver names (e.g., IBM4019,
PSCRIPT.QMSTMPS810Th) for use with this printer, with one of
these selected as the default.
and for the queue between:
• A print queue name (e.g., LPI`1Q).
• A default print queue processor name (e.g., PMPRINT).
• One or more printer names (e.g., PRINTER1, PRINTER2).
• A default presentation driver name for this queue (this must be one
that is associated with this printer name but need not be the same as
the above default for this printer).
Queue set up also establishes the first queue associated with a printer name as
the default queue for this printer.
A print queue and printer name can also be specified as application defaults. The
application default printer need not be one that is associated with the default
queue.
Hinter set-up examples are shown in Figures 12-2 and 12-3. The set up can be
very simple as illustrated in Figure 12-2, with just a single queue associated with
a single printer and presentation driver. Altematively, it can be complex as
illustrated in Figure 12-3, with multiple queues, multiple printers, and multiple
PRI NTI NG TZ5
printer
d®f®ult
qu®u®
queue
d®f&ult
driver
HErvoRK pRiHTIHG
For network printing from a requester to a remote print server, server queues and
printers are not visible to a requester application except by using the DosF+int API
(see below). It is not, therefore, possible for a requester application to open a DC
226 OS/2 PRESENTATION MANAGER GPI
printer
default printer
queue default
drlv®r
pLomRs . IBM6 180
queue
de£&ult
driver
IBM4019
PSCRIPT.QMS-PS810
for a server queue or port. The server must share a printer queue (e.g., using net
share lptlq/print) and the requester must alias the server queue as one of its ports
(e.g., using net use lpt4 \\server_name\lptlq). nrovided both print requester and
server are correctly set up, network printing on a remote print server node can be
made transparent to an application initiating print requests from the requester.
To achieve this, the server and requester must set up as follows:
PRINTING 227
Here the AFTER and BEFORE keywords identify the times at which printing may
occur and the SEPARATOR keyword identifies the name and location of the
separator definition file. Note that separator files for most print drivers use ASCII
text, but pscript drivers currently require separator page text to be defined using
the Postscript language. Network options are not required by the requester queue.
Note that on IBM Ospe EE Version 1.3 these are no longer referred to as network
options and are specified using individual dialog control windows rather than as
a single string of network options.
1. Establish a queue name for queued printing or port nam.e for direct
printing and the presentation driver and device names.
2. Establish the DRIVDATA (driver data) structure for the driver and
device.
3. Open an oD_QUEUED Dc for queued printing or an oD DIRECTDC
for direct printing.
4. Start the document by issuing a `start document' DevEscape.
5. Output the raw data using `raw data' DevEscapes.
6. End the document by issuing an `end document' DevEscape.
7. ClosetheDC.
In addition, `new frame' and `abort document' DevEscapes may be used ®etween
the `start document and `end document' DevEscapes) to staid a new page or to abort
the print operation respectively.
There are currently two main methods of establishing queue name, port name,
driver name, device name, and the DRIVDATA structure, one based on printer
selection and the other on queue selection.
With this method, the application is unable to vary the job properties for a printer
withoutenduserintervention.Itdoes,however,enabletheapplicationtooptionally
provide the user with a driver dialog on a `per job' basis, allowing the user to specify
printer properties as well as job properties and also update the INI file if required.
This method requires the application first to select a printer name and then use
this to determine:
port name (required only for direct printing);
presentation driver name for this printer;
device name for this driver; and
queue name (required only for queued printing).
The printer name is established either by querying the default printer name or by
querying a list of all available printer names and selecting one of these.
1. The default printer name is determined using:
HfQueryHofilestring (Application="PM_SPOOLER_PRINTER",
Key=frinter name).
This returns a null terminated string containing the port name, one or
more driver names (with or without dot qualified device names), and
one or more queue names. The names of the default driver and queue
for the printer are those returned first. The returned string will be in
one of the the following forms:
LFT1;IBM4019;LFTIQ;;
Or
COM1;PLOITERS.IBM6180;COMIQ;;
Or
Each name in the list is terminated by a null with the final name
terminated by two mulls. This is illustrated by the function
QueryQueueNames in Figure 12-9.
2. Having obtained a queue name, this is used to determine the default
presentation driver name for the queue and, where applicable, the
device name. The default driver name and device name for the queue
are determined using:
frfQueryHofilestring (Application="PM_SPOOLER_QUEUE_DD",
Key=queue name).
PSCRIFT.QMS-PS810;
This is illustrated by the function QueryQueueDriver in Figure 12-10
(which removes the `;' and `.' replacing them by null).
3. The driver name is used with the queue name to obtain the
DRIVDATA structure using:
Having obtained the port or queue name and DRIVDATA structure using one of
the above methods, it is now possible to open a DC and complete the print
operation (using these as parameters to DevopenDC). The functions
T32 0S/2 PRESENTATION MANAGER GPI
FORM SELEOTI0H
An application wishing to use the Current Form for a printer need not be
concerned with fo]rm. selection. The Current Fo]rm. will be selected automatically
using the DRIVDATA structure obtained by one of the methods described above.
Certain printers, such as those with multiple paper trays, allow the Fo]rm. to be
switched on a `per job' basis without intervention at the printer. This type of fo]rm.
selection can be accomplished in one of two ways:
1. Using DevpostDeviceModes as described above, with options of
DPDM_CIIANGEPROP or DPDM_POSTJOBPROP, the operator can
select the required fo]rm. for each job via the Job Hroperties dialog.
2. The application can query a list of all available forms using
DevQueryHardcopycaps. This is another function that is actually
issued twice, once to determine the number of forms and, having
allocated the required memory, a second time to obtain the form.s
information. The forms are returned as an array of HCINFO struc-
tures each containing fo]rm. name, dimensions, and attributes. The
attributes for each returned form specify HCAPS_CURREP`IT (form is
curent), HCAPS_SEIECTABLE (form is selectable) or neither of
these. The application may choose any fo]rm name with the
HCAPS SELECTABIE or HCAPS_CURRENT flag set and specify
this in tie DEVOPENSTRUC pszSpoolerparams of DevopenDC (see
Appendix 1). A job with a fo]rm name that is neither cuITent nor
selectable will stick in the print queue and not print.
The print queue processor (or queue driver) is responsible for interpreting the
queue processor parameters and outputting a dequeued print file to the printer.
A queue processor name is not required for direct printing and applications
PRINTING T33
using queued printing, if they have no special requirements, should default this
parameter ®y specifying NULL for the DevopenDC DEVOPENSTRUC
pszQueueHocName field). The following description of queue processor selection
applies only to those applications with special queue processor requirements.
Although a default print queue processor (PMPRIN'I) is provided and installed
with OSA, certain applications with special needs may require an alternative. For
example, an application sending output to a plotter may wish to use the PMPLOT
queue processor to performi hidden line removal or reverse clipping. Additional
queue processors can be installed using the Control Panel (Add Queue Driver
menu option) or the Dost.oadModule and SplQplnstall functions.
It is important when installing and deleting queue processors to ensure that the
default queue processor is always one that is suitable for normal printing. This
enablesapplicationstousethisdefaultforgeneralprintingwithouttheneedtoissue
a query, specify a name, or be aware of different queue processor characteristics.
When necessary, an application can query the installed queue processors using:
As explained earlier, PM_Q_S'ID print files are based on, and closely resemble
MetaFiles, and like MetaFiles, certain restrictions apply when they are being
recorded. Uhlike MetaFiles, Hint files need not conform to the interchange
architecture but some restrictions are necessary in order to preserve picture
integrity.
The following mles and guidelines apply to OD_QUEUEDflM_Q_STD printing:
1. All non-device fonts used in the picture must be installed as public
fonts on the local system for local printing or on the print server for
network printing.
2. IMatch (match number) should not be used for logical font creation if
printingistotakeplaceonadifferentnetworknodefromtheinitiating
application or if it is to be deferred until after a re-IPL. IMatch values
are only valid in the local system for the duration of the current IPL
session.
3. If logical font creation without lMatch is used, `scale to fit' options on
DevopenDC queue processor parameters should be avoided (i.e., spec-
ify XFM=0).
234 OS/2 PRESENTATION MANAGER GPI
PRINTER F0IITS
Some printers may also offer additional matching display fonts to provide
consistency between display and printer text appearance (this is sometimes
referred to as What-You-See-Is-What-You-Get or WYSIWYG).
As each raster font must be selected to match the resolution of the output device
and matching raster fonts do not exist for every device, WYSIWYG using raster
fonts is often difficult to achieve. This is not a problem with outline fonts that can
be used on any device. The Adobe Type Manager provided with IBM OSA Version
1.3 should make WYSIWYG possible using high quality outline font characters on
any output device.
When using Bitmaps and MetaFiles with printers, certain restrictions apply. Also,
bitmap inversion can occur under some conditions. For a discussion of bitmap and
MetaFile printing, see chapters 5 and 11.
The DosFTint Spooler API is included in IBM OSA Version 1.3 and provides three
groups of new functions:
Hint Destination Functions (e.g., DosnrintDestAdd)
These begin with the prefix DosHrintDest and enable named print-
ers to be queried, updated, created, deleted, and modified from an
application program as well as by nrint Manager set up.
Queue Destination Functions (e.g., DosHrintQAdd)
These begin with the prefix DosnrintQ and enable named printer
queues to be queried, updated, created, deleted, and modified
from an application program as well as by Ilrint Manager set up.
ELint Job Functions (e.g., DosprintlobDel)
These begin with the prefix Dosllrintlob and enable named print
jobs to be queried, updated, paused, restarted, and deleted from
an application program as well as by Ilrint Manager set up.
These functions are very powerful as, with a suitable privilege level, all opera-
tions can be performed on a remote server node as well as on the local system.
These functions all include a level number that determines the amount of data
ret-ed.
There is some overlap between these and the HrfQueryHofilestring functions
described earlier and some of the string parsing complexities associated with the
latter are eliminated. DosFhintDestEnum, for example, can be used to query (or
enumerate) the available printer names, their logical address, and the drivers
selectedforeachprinter.DosllrintQEnumcanbeusedtoquery(orenunerate)the
236 OS/2 PRESENTATION MANAGER GPI
available queue names, the names of the printers connected to each queue, and
the default driver (and its DRIVDATA structure) for each queue. Unlike
nrfQuerynrofilestring, however, these functions cannot be used to obtain the
application default queue and printer names.
qdefprtr.c */
Q u e r y D e f a u 1 t P r I. n t e r ( V 0 I D )
f ree ( pszstri ng ) ;
return ( pszprtName ) ;
qprtnams.c */
0 u e r y P r 1. n t e r N a in e s ( V 0 I D )
It i.s the responsi.bi.li.ty of the caller to free the memory associ.ated wi.th
the returned pri.nter names.
e.g. pszstri.ng = Querypri.nterNames();
f r e e ( p s z S t r i. n g ) ;
return ( pszprtNames ) ;
/* qprtinfo.c */
PSZ Querypri.nterlnfo( PSZ pszprtName
PSZ FAR* pszDefQ
PSZ FAR* pszDefDrv
PSZ FAR* pszDefDev
PSZ FAR* pszAddlQs
PSZ FAR* pszAdDrvDvs
/* Query the prl.nter port, default queue, default drl.ver and devl.ce name and
/* additl.onal queue and dri.ver.devi.ce names
/*
/* i.nputs: pszprtName Pri.nter name (e.g. PRINTER1).
/*
pszprtName
``.. /* -key-default
/* name strl.ng
I ************************************************************************** I
/**/
/* Now break the stri.ng i.nto three null terml.nated stri.ngs: */
/* port name */
/* dri.ver.devl.ce_names (begl.nnl.ng wl.th default drl.ver) */
/* queue_names (begl.nnl.ng wl.th default queue) */
/* (i.gnore the network parameters) */
/**/
/ ************************************************************************** 1
i.niti.alize pointer */
pszstart = ++pch;
pch = strchr(pszstart, I ; ' ) ; fi.nd clef dri.ver name end */
l.f (pch==NULL I I pch==pszstart) I.f no name exi.sts */
(
f ree( pszprfstr ) : f ree the memory */
return ( NU LL ) ; return NULL */
)
*pch -'\0': /* null termi.nate strl.ng */
/* set clef drl.ver name */
pszDefDrvLcl = pszstart;
/ ************************************************************************** /
/**/
/* now break the queue_name stri.ng i.nto two null terml.nated strl.ngs: */
/* default queue_name */
/* addi.tional queue_names */
/**/
/ ************************************************************************** /
I ************************************************************************** I
/**/
/* now break the default drl.ver.device_name strl.ng into two null */
/* termi.nated strl.ngs: */
/* default drl.ver.devi.ce_name */
/* addi.ti.onal dri.ver.devi.ce_names */
/**/
1 ************************************************************************** I
i;:::::::#ii::::::t,l, : , ,: ;: #!:::l;::::::i:::s
(
1************************************************************************** I
/**/
/* now break the default dri.ver.devl.ce_name strl.ng i.nto two null */
/* initi.all.ze pointer */
pszstart = pszDefDrvLcl */
ch = strchr(pszstart, ' . I ) /* find .,'separator
/* i.f separator exi.sts */
f (pch!=NULL)
return(pszport) :
/* postdevm.c */
B00L PostDevi.ceModes( HAB hab
PDRIVDATA FAR* pdri.vDataRet
PSZ pszDri.ver
PSZ pszDevi.ce
PSZ pszprl.nter
)
(
/* Return the DRIVDATA structure for the specl.fied drl.ver, devi.ce and
/* pri.nter using DevpostDevi.ceModes.
/*
/* l.nputs: hab Anchor block handle
/* pszDrl.ver Dri.ver name
/* pszDevl.ce Devl.ce name
/* pszpri.nter Pri.nter name
/*
/* outputs: pdrl.vDataRet DRIVDATA structure
/*
/* It i.s the responsi.bi.11.ty of the caller to free the memory associ.ated wi.th
/* the returned DRIVDATA structure.
/* e.g. fRet = PostDevl.ceModes(..&pdrl.vData..):
/*.
/* free(pdrl.vData);
*pdri.vDataRet = NULL;
/* i.nl.tl.all.ze DRIVDATA poi.nter*/
return ( fRet ) :
qdefqueu.c */
QueryDefa ul toueue ( V0 I D )
returns: PSZ Default pri.nter queue name or NULL (error or not found).
Thi.s functi.on null termi.nates the stri.ng (removi.ng .;').
It i.s the responsi.bi.1i.ty of the caller to free the memory assocl.ated wi.th
the returned default queue name.
e.g. pszstri.ng = OueryDefaultQueue():
f r e e ( p s z S t r i. n g ) ;
return ( pszQName ) ;
qqnames.c */
Que ryQueueNames ( V0 I D )
It 1.s the responsi.bl.11.ty of the caller to free the memory associ.ated wi.th
the returned queue names.
e.g. pszstrl.ng = QueryQueueNames():
f r e e ( p s z S t r 1. n g ) ;
return ( pszONames ) :
qqdri.ver.c */
QueryQueueDrl.ver(PSZ pszQueue, PSZ FAR* pszDevl.ce)
Return the name of the default dri.ver for the speci.fl.ed queue.
It i.s the responsi.bi.1i.ty of the caller to free the memory associ.ated wi.th
the returned default prl.nter name.
e.g. pszstri.ng = QueryQueueDri.ver(..);
f r e e ( p s z S t r i. n g ) ;
*pszDevi.ce = NULL;
/* I.ni.ti.all.ze devi.ce poi.nter */
pszQueue
..'. /* /*
-key name stri.ng
-default
r e t u r n ( p s z D r 1. v e r ) ;
/* qqdri.vda.c */
PDRIVDATA QueryQDrl.verData(PSZ pszQueue)
(
/* Return the DRIVDATA structure for the default dri.ver of the specl.fl.ed
/* queue.
/*
/* l.nputs: pszQueue Queue name.
/*
/* returns: PDRIVDATA pol.nter to DRIVDATA structure or NULL (error or none).
/*
/* It I.s the responsi.bi.1i.ty of the caller to free the memory associ.ated wi.th
/* the returned DRIVDATA structure.
/* e.g. pdrl.vData = QueryQDri.verData(..):
/*.
/* f r e e ( p d r i. v D a t a ) ;
pszQueue
.`'. /* /*
-key name stri.ng
-default
/* postjobp.c */
VOID PostiJobproperti.es( HAB hab
PDRIVDATA pdri.vData
PSZ pszDri.ver
PSZ pszDevl.ce
(
/* Post a Job Propertl.es dl.alog and return the suppll.ed DRIVDATA structure
/* modi.fi.ed by the end user selecti.ons. Note that thi.s method of usi.ng
/* DevpostDevi.ceModes may not be supported by all drl.vers. If an error 1.s
/* logged i.t can be i.gnored and i.s reset by thi.s functl.on before returni.ng
/* The ori.gi.nal DRIVDATA structure can sti.ll be used unmodi.fi.ed.
/*
/* i.nputs: hab Anchor block handle
/* pszDri.ver Dri.ver name
/* pszDevice Devl.ce name
/* pdri.vData DRIVDATA structure
/*
/* outputs: pdri.vData DRIVDATA structure modi.fi.ed by end user
/*
return :
/* prtdefpr.c */
B00L Pri.ntDefpri.nter(HAB hab)
(
/* Pri.nt Gpl. graphi.cs to the default pri.nter. */
.`Prl.nt Job"
#defi.ne PDOCNAME
#defi.ne PDOCNAMELEN ( LONG ) s 1. zeof ( PDOC NAM E )
"Hello World"
#defi.ne PRINTTEXTP
#defi.ne PRINTTEXTPLEN ( LONG ) ( s I. zeof ( PRI NTTEXTP ) -1 )
f r e e ( p s z P r I. n t e r ) ;
f ree ( pszport ) ;
f r e e ( p d r i. v D a t a ) ;
lLength -OL:
l.f (fRetA) /* i.ssue start document DevEscape
fRet = DevEscape( hdc /* -DC handle
DEVESC_STARTDOC /* -escape code
PDOCNAMELEN /* -sl.ze of document name
PDOCNAME /* -null terml.nated document name
&1Length /* -si.ze of output data (OL)
NULL /* -output data (not used
) --DEV_OK;
else
fRet = FALSE:
Pol'nt.x -1000L:
Pol'nt.y -1000L:
/* draw to the prl.nter */
fRet = (B00L)Gpi.Charstri.ngAt( hps
' &ptlpol'nt
PRINTTEXTPLEN
PRINTTEXTP
in
1 Length 2L;
1` f ( f R e t ) /* i.ssue end document DevEscape
f Ret = DevEscape( hdc /* ~DC handle
DEVESC_ENDDOC /* -escape code
OL /* -length of i.nput data (OL)
NULL /* -I.nput data (not used)
&lLength /* -si.ze of output data (2L)
(PBYTE)&usJobld /* -output data (returned job 1.d
) --DEV_OK;
1. f ( f R e t A )
fRet = Gpi.Associ.ate(hps, NULL) && fRet; /* di.ssoci.ate PS and DC
I. f ( hd c ! =D EV_E RRO R )
fRet = DevcloseDC(hdc) != DEV_ERROR && fRet: /* close DC
return ( fRet ) ;
prtdefqu.c */
L Prl.ntDefQueue(HAB hab, ULONG ulpostD1.alog)
Note that not all dri.vers support a Job Properti.es D1.alog l.n thi.s mode.
if (pdri.vData!=NULL)
(
lRet = DEV_OK;
/* Post Job Propertl.es Di.alog
i.f (ulpostD1.alog) /* this opti.on i.s requested
lRet = DevpostDevl.ceModes( hab /* -anchor block handle
pdri.vData /* -DRIVDATA pointer
pszDri.ver /* -dri.ver name
pszDevi.ce /* -devl.ce name
NULL /* -prl.nter name
DPDM_POSTJ0BPROP/* -opti.ons
);
)
/* set DevopenDC params
dopData . psz LogAdd ress pszQueue; /* -1ogl.cal address
d o p D a t a . p s z D r I. v e r N a in e pszDri.ver; /* -drl.ver name
d o p D a t a . p d r 1. v P dri.vData; /* -DRIVDATA
dopData . pszDataType PM_CLSTD'': /* -data type
dopData.pszcomment = "Gpl. Pri.nting'';/* -comment
dopData.pszQueueprocName = NULL: /* -queue proc name (default)
dopData.pszQueueprocparams ="COL=C XFM=O /* -queue proc params
dopData.pszSpoolerparams = NULL; /* -spooler params
dopData.pszNetworkparams = NULL; /* -network params (not used)
f ree ( pszQueue ) ;
f r e e ( p s z D r 1. v e r ) ;
f r e e ( p d r 1. v D a t a ) :
if (hps!=GPI_ERROR)
fRetA = Gpi.Assocl.ate(hps, hdc): /* associate PS and DC */
nt.x
nt.y
1. f ( f R e t A )
fRet = Gpi.Associ.ate(hps, NULL) && fRet; /* di.ssoci.ate PS and DC
I. f ( h p s ! = G P I _ E R R 0 R )
fRet = Gpi.Destroyps(hps) && fRet; /* destroy PS
i. f ( h d c ! = D E V _ E R R 0 R )
fRet = DevcloseDC(hdc) != DEV_ERROR && fRet; /* close DC
return ( fRet ) ;
/* prl.ntraw.c */
B00L Prl.ntRawData(HAB hab)
(
/* Pri.nt raw data to the default prl.nter. */
``Prl.nt Job"
#defl.ne RDOCNAME
#define RDOCNAMELEN ( L 0 N G ) s 1. z e o f ( R D 0 C N A M E )
"Raw Data Raw Data Raw Data Raw Data Raw Data"
#defl.ne RAWDATA
Jfdefl.ne RAWDATALEN ( LONG ) s 1. zeof ( RAWDATA )
lLength -OL;
l. f ( hd c ! =D EV_E RRO R ) /* i.ssue start document DevEscape
fRet = DevEscape( hdc /* -DC handle
DEVESC_STARTDOC /* -escape code
RDOCNAMELEN /* -si.ze of document name
RDOCNAME /* -null termi.nated document name
&lLength /* -sl.ze of output data (OL)
NULL /* -output data (not used
) --DEV_OK;
else
fRet = FALSE;
lLength -OL:
1' f ( f R e t ) /* i.ssue raw data DevEscape
fRet DevEscape( hdc /* -DC handle
DEVESC_RAWDATA /* -escape code
RAWDATALEN /* -length of raw data
RAWDATA /* -raw data
&lLength /* -si.ze of output data (OL)
NULL /* -output data (not used)
) --DEV_OK;
lLength = 2L;
1` f ( f R e t ) /* l.ssue end document DevEscape
fRet DevEscape( hdc /* -DC handle
DEVESC_ENDDOC /* -escape code
OL /* -length of i.nput data (OL)
NULL /* -i.nput data (not used)
&1Length /* -sl.ze of output data (2L)
(PBYTE)&usJobld /* -output data (returned job I.d
) --DEV_OK;
1. f ( h d c ! = D E V _ E R R 0 R )
fRet = DevcloseDC(hdc) != DEV_ERROR && fRet; /* close the DC */
return ( f Ret ) ;
qryqproc.c */
Que ryQueuep roces s ors ( V0 I D )
returns: PSZ Prl.nt queue processor names or NULL (error or not found).
Note that each name l.s null termi.nated wl.th the fl.nal name
termi.nated by two nulls.
It i.s the responsi.bi.lity of the caller to free the memory associ.ated wi.th
the returned pri.nt queue processor names.
e.g. pszstri.ng = Oueryoueueprocessors();
free ( pszstri ng ) ;
return ( pszQprocs ) :
IBM has made no secret of its intention of providing Osra Version 2.0, the 32-bit
version of the current operating system, and the IBMM4icrosoft Software Devel-
opment Kit (SDK) is already available. At the time of writing this book, much of
the content of OS# Version 2.0 is well established. Although is not possible to say
when this release will become available or what its exact content will be, with one
or two exceptions, it can be assumed that the nresentation Manager functions are
available (as described in this book) with the new 32-bit flat memory model API
discussed below. The only change for the majority of the GPI functions is a change
to the precise meaning of any pointers (this is frequently hidden by the compiler).
OSA version 2.0 proL|zidssLLa±inary comBa±ibls Apl for use witha±s]EzamJ
exisring 16-bit a licatio All program examples provided in this book should
Ore continue to operate successfully using the Version 2.0 16-bit API.
In addition, it provides a 32-bit flatmemory model API that hides the Segmen-
Of the Inte|TM
processor,provides improved portability, and eliminates the 64K addressing
limitations inherent in the segmented 16-bit memory model. Existing 16-bit
applications may be converted to the new 32-bit API by flattening any 16-bit
segment and offset operations and removing all `far' references. The application
must then be rebuilt using the new 32-bit language compiler and tools.
For the majority of the programs in this book, removal of `far' references,
recompilation, and so forth, is all that is required. For other functions (e.g., the
function DisplaypMError in chapter 1), segment and offset pointer operations
must be modified to conformi to the 32-bit flat memory model.
Although the 16-bit API provides binary compatibility for all existing I+esenta-
tion Manager functions, a few of these existing functions may not be available with
the 32-bit API, and some of these will be replaced by different (and better) 32-bit
255
256 OS/2 PRESENTATION MANAGER GPI
DevopenDC Parameters
);
nab
This is the anchor block handle returned by Winlnitialize.
IType
257
258 OS/2 PRESENTATION MANAGER GPI
pszToken
This is intended to identify the device information to be taken from the INI file
instead of from the pdopData parameter. This parameter is currently ignored and
should be specified as "*" indicating that no information should be taken from the
INI file.
lcount
pdopData
This provides a variable number of additional DevopenDC parameters. In theory,
not all the elements are required in all cases but it is normally safer to provide the
complete structure. For a DC type of OD_MEMORY, this should be specified as
NULL as the hdccomp parameter identifies the driver and, thus, provides all the
necessary information (see the note below for printers that support multiple
resolutions). Otherwise, this parameter can be viewed as either:
a pointer to a DEVOPENDATA structure
Or
hdc
Bitmaps are always owned by a particular device and, for a DC type of OD_MEM-
ORY, this is the handle of any existing DC of the device for which the OD REM-
ORY DC is required. An OD_MEMORY DC thus created, is suitable for u=e with
all DCs for the device, regardless of whether they are OD_QUEUED or OD DI-
RECT.
For DC types other than OD_MEMORY, this parameter should be NULL.
It was stated above that the pdopData (or DEVOPENPENDATA) paralneter
should be specified as NUIL when opening an OD_MEMORY DC. Although this
accurately reflects the API definition and works in the majority of cases, it does
require qualification. When drawing to a bitmap owned by a print driver that
supports a number of selectable resolutions (e.g., the IBM4019 driver supports
resolutions of 300, 150, loo, and 75 pels per inch), the driver is currently unable
to determine the correct resolution to use, and instead will use its own default. For
example, if the page units of the PS associated with the bitmap OD_MEMORY
memory DC are PU_LOENGLISH, a line 100 units long is drawn to the bitmap
and GpiBitBlt is used to output the bitmap to the printer, a line of one inch should
be printed. If the actual and driver default resolutions are the same, then the line
will be coITect. For example, if the default printer resolution is 150 and the actual
resolution is 300, then the length of the printed line will be halved; if the actual
resolution is 75, the length will be doubled. This problem does not apply when
working with device units (i.e., PU_PELS) or when performing straightforward
bitmap image operations. It is possible that this may eventually be corrected
intermally by changes to the drivers and device driver interface but presently, the
recommended bypass (for some drivers) is to supply a DEVOPENSTRUC param-
eter with a DRIVDATA structure providing the required resolution.
APPENDIX 2
COP=n
This specifies the number of copies n (n is an integer >=0).
ARE=
This specifies the size and position of the output area as follows:
ARE=C specifies that the required output area is maximum size
(i.e., equal to the size of maximum available output area) but does
not imply that the output is scaled to fill it.
ARE=w,h,I,t specifies the size and position of the required output
area (where w,h are width, height and I,t are left and top offsets of
the top left corner relative to the top left corner of the maximum
available output area, all expressed as integer percentages of the
maximum available output area). These are not particularly easy to
use but the example in Figure A2-1 should help to illustrate their
use. Other examples also appear in the IBM OSA nrogramming
Guide.
263
264 OS/2 PRESENTATION MANAGER GPI
<-c->Hreq
<-'r®q - >
i:5::::ee8?tTut A-red
I
tb
•-.-,I 1
--------
center
I
CI 1p
lil
1=c*100/VDex, t-nd*100/Hda]t
FIT=
This specifies the size and position of the actual output inside the
output area requested (using ARE=) as follows:
FIT=S specifies that the actual output (i.e., the PS page)
should be scaled to fit the required output area (i.e., drawn as
large as possible while retaining its aspect ratio such that a
circle remains a circle). At least one dimension of the picture
will completely fill the corresponding dimension of the required
output area while the other dimension will be centered where
applicable.
The `scale to fit' option may not provide the required results
in many cases (see below).
PMPRINT QUEUE PROCESSOR PARAMETERS Z65
The default for PMPRII\IT is "COP=1 ARE=C FIT=S XFM=1 XLT=O COL=M" for
a mono printer and "COP=1 ARE=C FIT=S XFM=1 XLT=O COL=C" for a color
printer. Note that these defaults will not give the same results as printing to an
OD DIRECT DC. The most noticeable difference is that OD_QUEUED output is,
by default, scaled to fit with one dimension centered. This default scaling may
result in an incoITect size and might prevent a required font match from occurring.
In addition, operations such GpiBitBlt that are specified using device coordi-
266 OS/2 PRESENTATION MANAGER GPI
mates are unaffected by any scaling or translation arising from these parameters
andarethereforelikelytoappearintheincorrectpositionrelativetoother..output
if the output is scaled to fit. This will occur unless these parameters are explicitly
specified to force the output to be real size and positioned with its origin at the
bottom left comer of the output area (i.e., XFM=O XLT=1). This can also be
achieved by defining the PS Page and page units to exactly reflect the size of the
outputarea(orinthecaseofPU_ARBITRARYensuringthatthepageaspectratio
exactly matches that of the output area).
Other queue processors may define their own requirements for this parameter.
For other DC types (or default) this parameter can be NUIL or omitted.
APPENDIX 3
x, = ar + cy + e
y' = bx + dy + f
This is illustrated by the equations below (with the corresponding matrices shown
on the right):
267
268 OS/2 PRESENTATION MANAGER GPI
x' = x + tl
y' = y + t2
;;=;+yTans [ianss: :I
x, = -x
y I _- y
x,=x
y' = -y
x,=x
y'=y
Matrix algebra defines the multiplication of a (1x3) and (3x3) matrix as:
The equations x±ax+cy+e and yEbx+dy+f are thus expressed in matrix form as:
[x,y,1] = [x y 1] .
The ones and zeros in column three of these matrices exist to enable the normal
rules of matrix algebra to be applied unchanged for coordinate transformations.
They ensure consistency between the dimensions of input and output matrices (of
matrix multiplications) and will, in fact, ensure that ones and zeros appear in the
same positions of all matrices produced by matrix multiplication using such
matrices.
Using matrix algebra to multiply out the (1x3) and (3x3) matrix expression on
the right above, gives a (1x3) matrix containing the required values for (x',y). That
is:
It follows that any of the above operations (rotation, scale, shear, etc.) can be
represented by the single (3x3) matrix as shown earlier with each of the equations.
Furthermore, any combination of such (rotation, scale, shear, etc.) matrices can be
concatenated by matrix multiplication into a single matrix of the above form
(although order of concatenation is important).
The identity or unit matrix (I) shown earlier produces output values that are
identical to its input values. The identity matrix represents the initial or reset
value of most GPI transform matrices.
The system frequently needs to determine the inverse of a matrix in order to
back transformi coordinates from an output to an input coordinate space. The
inverse of a matrix A is denoted by A-1
If X' = X.A then X = X'.A-1 and A.A-1 = I (where X' = [x' y' 1] and X = [x y 1])
For some matrices, it is impossible to find an inverse (e.g., a matrix that trans-
forms more than one input point to a single output point). Such matrices are said
to be singular and will cause the system to log an error (PMERR_COORDI-
NATE_OVERFLOW).
A word of caution is required about the use of coordinate transformation
matrices. The equations described earlier would all produce rotation, scaling,
INTRODUCTION TO TRANSFORMS AND MATRICES T]\
trfu rfu
shear, etc., relative to the origin (0,0). If, as is likely, a figure to be transformed is
not located at the origin and the transformation is required to be relative to a point
on the figure such as the bottom left corner, transformation relative to the origin
will introduce an undesired translation. This is illustrated (for rotation) in Figure
A3-2. The simplest remedy for this is to (1) provide a matrix to translate the figure
such that its bottom left corner (say) is at the origin; (2) provide a second matrix
to perform the required operation (e.g., rotation); and (3) provide a third matrix to
translate the figure back to its required position. For example, for rotation this
might appear as follows:
[x' y' 1] = [x y 1]
I;e :f ;loiR
(Where (e,f) are the coordinates of the center of rotation, and R is the angle of
rotation (counterclockwise) in degrees.) Clearly, it would be possible to multiply
out the above expression to reduce the three matrices to a single matrix. However,
this is unnecessary as the system provides options (e.g., TRANSFORM_ADD) that
enable transforms to be incrementally updated as would be required here. The
system can, in fact, perform all required matrix multiplications.
APPENDIX 4
(OC) (00)
@4) (03) (52)
272
SAMPLE METAFILE INTERNALS 273
Q7F)
(00) (00) (cO) (cO) (00) (OA) (cO) (OA)
(03)
qF)
(00) (cO) (00) (00) (OA) (00) (OA)
(0o) (oF) (co) (oC) (co) (co) (co) (co) (co) (co) (co) (co)
(75) (72) (69) (65) (72) (cO) (53) (01) (43) (cO)
(00) (00) (00) (cO) (40) (3F) ®8) (3F) (8F) (05)
(00) (OC) (00) (09) (00) (cO) (00) (cO) (cO) (00) (00) (00)
(03) (52)
(43) (6F) (75) (72) (69) (65) (72) (cO) (53) (01) (43) (00)
(iA) toi) (cO) (00) (cO) (cO) (40) (3F) a]8) (3F) (8F) (05)
Graphics Data
(cO) (66) @3) a]E) a3B) (cO) (cO) (00)
Graphics Data
(Oi> (66> @3> ®E) a3Bt too) toot toot
Bitblt (GBBLT)
@6)(2c) (cO) (cO) (cc) (cO) a]4) (3c) (cO) (04) (00) (01) (01) (00) (cO) (00)
(cO) (cO) (64) (cO) (00) (cO) (OA) (00) (cO) (cO) (6E) (cO) (cO) (00) (cO) (cO)
(cO) (cO) (cO) (00) (00) (cO) (OA) (00) (cO) (cO) (OA) (cO) (cO) (00)
GDF Begin Segment Order (ID = 0 - null segment zero with prolog)
(70) (OE) (00) (cO) (00) (cO) (71) (10) (cO) (3E) (cO) (cO) (cO) (00) (00) (cO)
End Document
(cO) (10) @3) (A9) (A8) (cO) (00) (00) (30) (30) (30) (30) (30) (30) (30) (31)
Sample Orders
Below are salnple orders that may be found in MetaFiles or used with and
returned by GpifutData, GpiGetData, GpiElement, and GpiQueryElement. The
"short format" orders apply to a PS created using the GPIF_SHORT Gpicreateps
option. The "push and set" versions of the orders are generated if the attribute
mode for the PS is set to AM_PRESERVE. The long and short format versions of
a particular order are not, in all cases, equivalent.
Arc at Given Position (GARC)
(C6) (18) (50) (cO) (00) (cO) (50) (00) (00) (cO) (32) (00) (00) (00) (32) (00)
(cO) (cO) (64) (cO) (00) (cO) (32) (00) (cO) (00)
283
284 OS/2 PRESENTATION MANAGER GPI
Begin Path
@0) (06) (cO) (00) (01) (cO) (cO) (00)
Bitblt (GBBLT)
are)(2c) (cO) (cO) (cc) (cO) G4) (3c) (cO) (04) (cO) (01) (01) (cO) (cO) (cO)
(cO) (cO) (64) (cO) (00) (cO) (OA) (cO) (cO) (cO) (6E) (cO) (cO) (cO) (cO) (cO)
(cO) (cO) (cO) (cO) (00) (cO) (OA) (00) (cO) (00) (OA) (00) (cO) (cO)
Comment (GCOMT)
(01) (07) (43) (4F) (4D) (4D) (45) (4E) (54)
End Path
(7F) (cO)
Escape (GESCP)
@5)(OA) (80) (01) (32) (00) (cO) (00) (32) (cO) (00) (cO)
I+abel (GIRL)
a]2) (05) (4c) (41) (42) (45) (4ct
No-Operation (GNOH )
(cO)
Pop (Glrop)
(3F) (cO)
297
298 OS/2 PRESENTATION MANAGER GPI
GpiEndElement
GpiErrorsegmentData
GpiGetData
GpiLabel
GpioffsetElementpointer
Gpiopensegment
Gpipop
GpiputData
GpiQueryAttrMode
GpiQueryDeITag
GpiQueryDrawcontrol
GpiQueryDrawingMode
GpiQueryEditMode
GpiQueryElement
GpiQueryElementpointer
GpiQueryElementType
GpiQuerylnitialsegmentAttrs
GpiQuerysegmentAttrs
GpiQuerysegmentNames
GpiQuerysegmentHriority
GpiQuerysegmentThansform.Matrix
GpiQuerystopDraw
GpiQueryTag
GpiQueryviewingThansformMatrix
GpiRemoveDynamics
GpisetAttrMode
GpisetDeITag
GpisetDrawc.ontrol
GpisetDrawingMode
GpisetEditMode
GpisetElementpointer
Gpl FUNaloNs suppORTED ONLy By A NORMAL-ps T99
GpisetElementpointerAtLabel
GpisetlnitialsegmentAttrs
GpisetsegmentAttrs
GpisetsegmentHriority
GpisetsegmentThansform.Matrix
GpisetstopDraw
GpisetTag
Gpisetviewin.g'ThansformMatrix
Note that GpisetDrawcontrovGpiQueryDrawcontrol are valid in a Micro-PS for
the DCTL_DISPLAY, DCTL_BOUNDARY, DCTL_CORRELATE controls only.
References and Bibliography
IBM Operatirig System/ 2 Version 1.2 Programming Tloozs cnd, Irrformation: Presen-
tation MCLrager Programming Roference. T989.
IBM Operating System/ 2 Version 1.3 Programming Tlools cnd, Irrformation: TlechTti-
cal Update. ±990.
Kogan, M.S. OS/2 2.a 32-8££ APT. IBM Personal Systems Developer. Spring 1990.
pp. 23-30.
Kogan, M.S. and Tycast, R. OS/2 2. 0 TooZs and Program Dez/ezapmeJ}£. IBM Personal
Systems Developer. Spring 1990. pp. 31-35.
300
Glossary
alternate mode. A mode used for defining which area segments formed by mul-
tiple overlapping closed figures are considered paid of the area interior. In alter-
nate mode a figure segment is considered part of the area interior if, counting from
infinity to a point in the segment, the number of figure boundary line crossings is
odd.
arbitrary page units. Page units that cause the PS page dimensions to be scaled
to fit the available device output area causing the picture to be displayed as large
as possible while retaining its correct aspect ratio.
arc parameters. A drawing attribute that maps a unit circle to the required
ellipse, controlling the shape and size of arcs drawn using GpiFullArc,
GpipartialArc, and the shape only of GpipointArc.
area bundle. A drawing or default attribute bundle structure containing the
group of attributes used for area fill operations.
apect ratio. The width to height ratio of a picture or shape.
301
302 OS/2 PRESENTATION MANAGER GPI
BitBlt. A Bit Block Thansfer operation that enables the rapid transfer of a rectan-
gular block of pixel image data between a bitmap and raster device.
bitmap. A rectangular array of pixel image data stored in memory that can be
used as the target of any output drawing operation (including BitBlt) or the source
of a BitBlt operation.
boundary accumulation. A process by which the coordinates of the smallest
rectangle into which the entire picture will fit, are accumulated in model space.
bundle. A drawing or default attribute structure containing the group of attri-
butes used for one particular type of primitive drawing operation (i.e., characters,
lines, areas, markers, or imaggBitBlt).
cached Micro-PS. An associated Micro-PS/WindowDC pair for use by applica-
tions where the large number of windows make it impractical to allocate a
separate Micro-PS and DC for each window.
chained segment. A root segment with its chained segment attribute set and
that forms part of the picture chain.
character angle attribute. A character bundle picture attribute defining the
baseline angle for outline and mode two raster font characters. This affects the
position and orientation of outline font characters and the position of mode two
raster font characters.
character box attribute. A character bundle picture attribute controlling the
height and width of outline font characters and the spacing of outline and mode
two raster font characters.
character bundle. A drawing or default attribute structure containing the group
of attributes used by character drawing primitives.
character cell. Synonym for character box.
character set. A character bundle picture attribute defining the id of the font to
be used for drawing characters.
G[OSSAR y 303
detectable segment. A segment with its detectable segment attribute set mak-
ing it eligible for returning a hit from a retained correlation operation.
device context (DC). A logical output device defining the target of drawing
operations. A device context typically identifies a display window, an instance of a
shared output device such as a printer, a bitmap, or a virtual output device such
as a MetaFile.
device coordinate space. The coordinate space of the device.
device drawing context (DDC). That part of the device context data owned by
the Hresentation Driver.
device driver interface (DDI). The presentation driver interface.
device transform. A transfo]rm from the PS page to device space that, together
with the device resolution, provides the required page units in the page. Device
transformi can be viewed as a PS environment attribute rather than a drawing
attribute (although it is, in fact, actually owned by the device rather than the PS).
direct DC. A device context used for direct printing.
direct printing. Output to a hard copy device that is passed directly to the device
for immediate output, bypassing the print queue and spooler.
disassociation. A process by which a presentation space and device contezit
association is broken.
display driver. A Pkesentation Driver used to output to the display device.
dithering. A process by which RGB colors that are not available on the device are
simulated by alternating the colors used for different pels when drawing an area.
draw controls. A selection of modal PS options that control subsequent drawing
operations (i.e., erase before draw, display, enable boundary accumulation, draw
dynamics, enable correlation).
drawing attribute. A picture attribute that controls the appearance (e.g., color)
of subsequent drawing primitives and may be varied during drawing for picture
constmction.
drawing mode. A PS mode controlling whether output primitives are drawn,
accumulated in retained segments, or both.
drawing order. A sequence of bytes used for representing a drawing primitive or
attribute in a retained graphics or MetaFile segment. An order is the smallest unit
of an element.
drawing primitive. A picture function that produces output to a device.
G[OSSAR y 305
dynamic segment. A chained segment with its dynamic segment attribute set
that can be rapidly drawn and removed using XOR mix mode without affecting the
picture beneath it.
DRIVDATA. A structure containing device dependant driver data (such as device
type, printer, and job properties) required when opening a printer DC.
element. A group of one one more related drawing orders in a retained segment
or MetaFile, typically generated by a single GPI function call, and treated as a
single entity addressed by the element pointer for segment editing purposes.
element pointer. An element offset used to identify the target element or ele-
ments of a retained segment editing operation.
em height. The height of the em square representing the font point size in world
coordinates. For an outline font, this is the same as the height of the character box
attribute.
em inc. The width of the em square in world coordinates. For an outline font, this
is the same as the width of the character box attribute.
em square. A square of size equivalent to the font point size in world coordinates.
geometric line width attribute. A line bundle picture attribute defining the
thickness of geometric wide lines created using GpiModifypath or Gpistrokepath.
geometric wide line. A line with thickness specified in world coordinates and
scaled using the GPI transforms. The line interior is filled using an area fill
pattern. Geometric wide lines are constructed using the path functions.
global attribute. A bundle attribute (i.e., color, mix, background color, or back-
ground mix) that occurs in multiple attribute bundles and can be set in all bundles
simultaneously using a single function call (e.g., Gpisetcolor).
91yph. A graphic symbol typically representing a single font character.
graphics engine. The component that, together with the device drivers, im-
plements the GPI graphics drawing algorithms.
graphics field. A PS environment drawing attribute that defines a clipping rec-
tangle in the PS page.
graphics segment. A graphics ob].ect containing a group of related elements (or
drawing orders).
image. A rectangular array of pixel data.
INI file. A file (e.g., OS2.INI, OS2SYS.INI) managed by the system and used to
store application and system profile information (e.g., printer properties).
instancetransform.A model transform attribute specified with
GpicallsegmentMatrix.
internal leading. A vertical distance in world coordinates equal to the difference
between the maximum baseline extent and the em height.
internal segment prolog. A segment prolog located before the first element of a
segment, used intemally to store the segment transfo]rm and viewing transform
and not directly visible to an application.
kerning. A process by which the spacing between certain pairs of characters (e.g.,
To) in a proportional font is adjusted such that the character boxes overlap to
provide a further improvement in the appearance of text.
G LOssARy Sow
marker set. A marker bundle picture attribute defining the id of the marker set
or font to be used for drawing markers.
marker symbol. A marker bundle picture attribute defining the marker or font
codepoint to be used for drawing markers.
maximum ascender. The maximum distance that a font character ascends above
the baseline in world coordinates.
maximum baseline extent. The maximum vertical extent of font characters in
308 OS/2 PRESENTATION MANAGER GPI
world coordinates determined by the sum of the lnaximum ascender plus the
maximum descender.
maximum character increment. The maximum horizontal character incre-
ment of a font in world coordinates. For a universal font, this represents the
maximum for the font rather than the maximuln for a particular codepage.
maximum descender. The maximum distance that a character in the font de-
scends below the baseline in world coordinates.
Memory DC. A device contelit into which a bitmap may be selected in order to use
thebitmapasthesourceortargetofaBitBltoperationorthetargetofanydrawing
operation.
MetaFile. A picture interchange file in architected SAA format held as a disk file
or in memory as a memory MetaFile.
MetaFile DC. A device context used for recording a MetaFile.
Micro-PS. A presentation space that requires less memory and provides reduced
function compared to a Normal-PS.
mix attribute. A picture attribute defining the foreground mix mode to be used
by subsequent drawing primitives. Mix is a global attribute.
mix mode. A mode defining the logical operation used to combine new output with
the existing color of the pels at the drawing position to produce the final output.
model space. A conceptual coordinate space between world and page coordinates
in which the picture is constructed by the output of the model transfo]rm matrix.
model transform matrix. A drawing attribute that defines a transformation
from world coordinate space to model space and is intended for picture modeling
purposes.
monospaced font. A font in which equal spacing is used for all characters.
non-retained graphics. Graphics output primitives and attributes that are im-
mediately drawn and then discarded.
Normal-PS. A full presentation space capable of supporting all GPI functions.
outline font. A font in which the shape of each character is defined by a sequence
of vector strokes and curves defining a closed figure that is optionally filled.
page coordinate space. A conceptual coordinate space immediately above de-
vice space in which the picture is constructed by the output of the default viewing
transform matrix.
page units. Application defined coordinates of the PS page.
page dimensions, defines the device transfo]rm matrix. The page viewpord repre-
sents the area of the output device in which the PS page is displayed and it is
neither a clipping rectangle nor the same as the window rectangle on a display.
path. An object defined in world coordinates by a sequence of drawing primitive
and attribute functions issued between GpiBeginpath and GpiEndpath. A path
can be used for defining a filled area, a complex clipping shape, an outline, and for
drawing geometric wide lines.
pattern attribute. An area bundle picture attribute defining the fill pattern or
font codepoint to be used for area fill operations. This attribute is ignored for
bitmaps that are used as area fill patterns.
pattern reference point. An area bundle picture attribute defining the pattern
origin to be used for area fill operations.
pattern set attribute. An area bundle picture attribute defining the pattern set,
font, or bitmap id to be used for area fill operations.
pel. A picture element representing the smallest addressable point of a raster
device.
PIF. Picture Interchange File (an earlier IBM picture interchange architecture
standard similar to the MetaFile architecture).
pick aperture. A rectangle against which drawing primitives are compared for a
correlation hit.
picture functions. Drawing primitives and attribute functions that may be var-
ied during drawing for picture construction purposes.
pixel. Synonym for pel.
print queue. The queue used by the spooler for queued print jobs.
point size. A measure of font character height in points. The point size is not
defined in terms of any measurable characteristic of a visible character.
presentation driver. A Hesentation Manager. device driver that converts the
graphics functions presented at the Device Driver Interface (DDI) into low level
OSA Kernel Device Driver requests or, in the case of a certain adapters (such as
displays), interfaces directly with the adapter hardware.
presentation space (PS). The object that owns the device independent resources
and environment attributes and that can optionally be used to store or retain a
complete graphics picture.
310 OS/2 PRESENTATION MANAGER GPI
proportional font. A font in which the characters are spaced according to the
widths of the individual characters in order to improve appearance.
psychometric RGB. A system by which increased RGB value yields a visually
linear increase in intensity rather than one based on photon intensity.
PS page. The presentation space page. This is a coordinate space with application
defined coordinates in which an application may define a picture in device inde-
pendent coordinates.
PS size. The dimensions of the presentation space page. These dimensions repre-
sent the area in page coordinates space that is displayed in the page viewport on
the output device.
queue processor. See print queue processor.
queued DC. A device contezit used to print queued output via the spooler.
queued printing. Output to a hard copy device that is enqueued on a print queue
for printing in sequence with other print jobs using the spooler.
raster font. A font in which the shape of each individual character is defined by
a rectangular pixel image or bitmap.
realizable color table. A color table that may be realized by using the RGB color
table values to load the physical device palette in order to obtain the closest
possible match to the requested colors.
region. An object defined by one or more rectangles in device coordinates that can
be used for area fill or converted to a clip region.
retained graphics. A PS mode in which the entire graphics picture is stored as
a collection of chained and called graphics segments in the PS retained graphics
segment store for subsequent display and editing.
RGB color. A color defined by a one byte red, a one b}rfe blue, and a one byte green
value.
RGB mode. A color table mode in which colors are specified directly as RGB
values.
root segment. Synonym for chained segment.
rop code. A code defining the mix mode for a BitBlt operation. A BitBlt rop code
value defines a three way mix operation combining source, pattern, and target
original pixel values to produce a final target output value.
SAA. Systems Application Architecture (a common application architecture for
IBM systems).
segment attributes. The properties of a graphics segment that apply to the
GLOSSARY 311
whole segment (i.e., detectable, visible, chained, dynamic, fast chaining, propagate
detectability, propagate visibility).
segment id. A 4 byte segment identifier that must be equal to or greater than
zero. Segment identifiers other than zero must be unique within a retained
graphics picture or a MetaFile.
segment prolog. A group of orders terminated by an end prolog order located at
the start of a graphics segment that has its prolog segment attribute set. Segment
prologs are not supported by the GPI except in MetaFiles.
segment transform. A model transfo]rm stored in the internal prolog of a seg-
ment.
set id. An application defined identifier used to identify a bitmap as an area fill
pattern or a logical font as a character set, marker set, or area fill pattern.
soft font. A device (e.g., printer) font in a format that enables it to be stored on
and installed from a disk or diskette.
spooler. The component that handles printing of queued output via the print
queue.
tag. A drawing attribute that defines a value to be associated with a group of one
or more elements or drawing orders in a segment for the purpose of identifying the
position of a subsequent correlate hit.
translation. A transform.ation operation producing a positional change.
typeface. The name used to describe the appearance or style of a particular font
(e.g., Roman).
viewing limits. A drawing attribute that defines a clipping rectangle in model
Space.
x device resolution. For a raster font, this is the horizontal resolution in pels-
per-inch of the device for which the font was designed. For an outline font, it is the
width of the em square rectangle in font definition space in which the font was
defined.
x height. The height above the baseline of lower case characters (excluding
ascenders) in world coordinates, typically represented by the height of lowercase
`x.,
y device resolution. For a raster font, this is the vertical resolution in pels-per-
inch of the device for which the font was designed. For an outline font, it is the
height of the em square rectangle in font definition space in which the font was
defined.
Index
Alternate mode area fill, 81 BitBit, 6, 85no9, horizontal spacing, 107, 110
Arc functions, see Curve functions BitBlt functions, 84-90 output, 6
Arc parameters, 76-78. See also Biinap: position recorded in MetaFile, 109
Non-bundle attributes changing ownership, 129, 132 vertical spacing, 106-107
Area, 6. See oiso Path area creation, 128, 131 Character angle attribute, 67
Area bundle, 6, 61, 79ngo data format, 130 Character box attr.ibute, 66rfe7, 110
Area drawing functions, 79nol data trzmsfer, 129 Character bundle, 6, 60nol, 65no9
Area fill using regions, 170 definition in resource file, 128 Character cell attribute, 66-67
Area primitives, 81 deletion, 129 Character direction attribute, 69
AREABUNDRE, see Area bundle drawing to, 131-132, 262 Character functions, 65-71
Associate option on Gpicreateps, 49 file format, 130-131 Character mode attribute, 66
Association, 2, 45 format conversion, 127, 129-130 Character precision attribute, 66
Attributes: modification by driver, 127 Characters, see Fonts
default, 7, 63", 199 ormership, 85ng6 Character set attribute, 66
drawing, 5no recording in MetaFile, 202 Character shear attribute, 68
querying, 64 selection, 129 Character string primitives, 70
resetting, 64no5 set id, 112 CHARBUNDIE, see Character
Attribute bundles, 5ng, 59ngl. See stretching and compression, 87, bundle
also Area bundle; Character 128 Char_Extra spacing, 70-71
bundle; Image bundle; Line supported formats, 126-127 Clip path, 94-96, 169
bundle; Marker bundle use as area fill pattern, 112 Clip region, 169-171
Attribute functions, 60no2 use with PM_QLSTD print Clipping, 168-171
Attribute mode, 62rfe3, 159 format, 234 Code pages, 111-112
ATrR_CIIAINED segment use with realizable color table, Color attribute:
attribute, 182 127, 147 area, 79
AITR_DETECTABLE segment Bitmap dimension functions, 131 area background, 79
attribute, 181, 192 Bold font simulation, 108 character, 65
AITR_DYNAMIC segment Boundary accumulation, 8-9, 194, character background, 65
attribute, 182, 185 199, 2cO image, 84
AITR_FASTCIIAIN segment Break_Extra spacing, 71 image background, 84
attribute, 182 Bundle, see Attribute bundles line, 71
ATI`R_PROP DETECTABLE BITMAPINFO, 129, 130 marker, 82
segment-attribute,182,192 BITMAPINFOHEADER, 129, 130 marker background, 82
AITR_PROP_VI S IBIE segment Color queries, 148
attribute, 182 Color table, See oiso I.ogical color
ATI`R_VISIBIE segment attribute, Cached Micro-PS, 2 table creation
182, 192 Character: default, 143-145
313
314 INDEX
GpisetcharDirection, see Character with PM_Q_STD print format, Matoh number, see Font, Match
bundle 234 n-her
GpisetcharMode, see Character GpisetRegion, see Regions MATRIXIF srfucture, 157
bundle GpisetsegmentAttrs, 181 Matrix multiplication, 269-271
Gpisetcharset, see Character GpisetsegmentHiority, 180 Memory DC, 262
bundle GpisetsegmenThaLnsformMatrix, Memory MetaFile, 195
Gpisetcharshear, see Character 160 MetaFile, 195-218
bundle GpisetstopDraw, 10, 184-185 creation, 195
Gpisetclippath, 96 GpisetTag, 192. See azso differences from PM_GLS'ID
GpisetclipRegion, see Clip region Non-bundie athibutes format, 222
Gpisetcolor, see Global attributes Gpis etviewinglinits, see display as sub-picture, 2cO
Gpisetcp, 111 Non-bundle attributes escape orders, 200-203, 280-282
Gpisetcurrentposition, 62. See azso GpisetviewingThansformMatrix, interchange with other systems,
Non-bundle attributes 161, 2cO. See also Non-bundle 2cO
GpisetDefArcparans, see athibutes internal sthicture, 272T282
Attributes, default Gpi strokepath, 93L94 printing, 199, 204, 222
GpisetDefAttrs, see Attributes, GpiTh-late, 7 rules for creation, 200L-203
default GpiunrealizecolorTable, 147 SAA conforming, 2cO
GpisetDefaultviewMatrix, 162 GpiwcBitBlt, 89-90, 129, 132 sealing to fit output area, 199
GpisetDefrag, see Attributes, recording in another MetaFile,
default 199
Gpis etDeIviewingLimits , see IBIVI\TUIL print driver, 224 MetaFile functions, 195-199
Attributes, default Icon, 130-131 MicrcLFrs, 2, 49, 297-299
Gpisetmawcontrol, 183, 190 IMAGEBUNDIH, see Image bundle Mix mode attribute:
GpisetDrawingMode, 180-181 Image bundle, 6, 61, 84ng5 aea, 79
GpisetEditMode, see Segment, Image display, 132, 147 area background, 79
editing Image functions, 84no5 character, 65
Gpi s etElementpointer, see Image primitives, 85-90 character background, 66
Segment, editing Instance transform, 160 image, 85
Gpi s etElementpointerAtLabel , see Internal prolog, 62, 160, 161-162 image background, 85
Segment, editing Italic font simulation, 108 line, 71
GpisetGraphicsField, 5, 169 marker, 82
GpisetlnitialsegmentAttrs, 181 marker background, 83
GpisetllineEnd, see Line bundle Keming, 101-104 Mixed 32-bit and 16-bit
GpisetLineJoin, see Line bundle applications, 256
Gpisetl.ineType, see Line bundle Model transform, 6, 158-161. See
GpisetLinewidth, see Line bundle Leid, see Set id also Non-bundle attributes
GpisetLinewidthGeom, see Line Line bundle, 6, 58, 71-72. See azso Multi-threaded applications, 10
bundle Geometric wide line attributes
GpisetMarker, see Marker bundle Line end attribute, 90-91
GpisetMarkerBox, see Marker Line functions, 71-79 Network printing, 225-227
bundle Line join attribute, 91 Non-bundle attributes, 61no2
GpisetMarkerset, see Marker Line prinitives, 72 Non-retained graphics, 8
bundle Line type attribute, 71 Non-retained only functions, 7
GpisetMetaFileBits, 195-196 Line width attribute, 61, 71 Non-retained segments, 177, 183
GpisetMix, see Global attributes Line width geometric attribute, 90 Normal-PS, 2, 49
GpisetModelThansformMatrix, 158. LINEBUNDIE, see Line bundle
See also Non-bundle attr.ibutes lMatch, see Font, match number
Gpisetpageviewport, 154, 163-165 IJogical color table creation, 145-147 Order buffer, 175-176
during MetaFile recording, 201 Ijogical font creation, 107-109 Orders:
with PM_Q_STD print format, 234 drawing, 172-176, 283-296
Gpisetpattem, see Area bundle extended, 174-175
GpisetpattemRefpoint, see Area Marker box attribute, 83" fixed 1 byte, 172
bundle Marker bundle, 6, 61, 82" fixed 2 byte, 173
Gpisetpatteinset, see Area bundle Marker cell attribute, 83no4 long, 173-174
Gpisetpel, 79 Marker functions, 82ng4 0D_DIRECT DC, see Device
Gpisetpel, in retain mode 7 Marker primitives, 84 context, direct
GpisetHckApertureposition, 191 Marker set attribute, 83 OD_INFO DC, see Device context,
GpisetHckAperturesize, 190 Marker symbol attribute, 83 info
Gpisetrs, 46, 163 MARKERBUNDIE, see Marker OD_MEMORY DC, see Device
during MetaFile recording, 201 bundle context, memory
INDEX 317
OD_RETAFIIH DC, see Device device name, 219, 228-229 GpipartialAro, figs 3.9-3.10, 76,
context, MetaFile driver name, 229, 231 77
OD_METAFILE_NOQUERY DC , fonts, 234-235 keming, fig 4.2, 102-103
See Device context, MetaFile installation, 224 line drawing, fig 1.7, 26T27
OD_QUEUED DC, see Device job property selection dialog, logical color table creation, fig 6.2,
context, queued 229-230, 231 149
OSA Version 2.0, 255-256 output to, 3 logical font creation, figs 4.4rd.6,
port name, 229 112-118
property selection dialog, 230 marker drawing, fig 1.9, 30-31
Page dimensions 4, 4748, 154, queue name, 229, 230-231 MetaFile examples, figs
163-164 frinter pcoling, 225 11.1-11.7, 204-218
Page units, 34, 48, 153-154, ELter set up, 224-225 Micro-PS draw, figs 2.4-2.5, 54ng6
163-164 ELter sbaring, 225 Normal-rs draw, fig 2.3, 51i3
recording in MetaFile, 201 ELting, 2ig-254 outline font scaling, figs 4.84.11
setting on GpiplayMetaFile, 197 ASCII text, 219, 232 120-125
Page viewport, 163-165 direct, 219-220 printer info, querying from INI
Path areas, 92 display screen, 232 file, figs 12.4-12.6, 236T240,
Path definition, 91-92 MetaFiles, 199, 204, 222 figs 12.8-12.10, 244-245
Path outlines, 93 moncdrome, 265 printer, output to, fig 1.3, 14-17
Paths, 90-97 multiple copies, 263 printing raw data, fig 12.15,
Pattern origin attribute, 80 output area definition, 263 252-253
Pattern set attribute, 79, 112 queued, 220 printing to default queue, fig
Pattern symbol attribute, 80 raw data, 219, 228, 232 12.14, 249-251
Ficlchg function, 204 real size, 265 print queue processor querying,
Hck aperture, 190 scaled to fit, 264 fig 12.16, 254
Pick identifier, 192. See azso using base control program retained segment operations, fig
Non-bundle attributes functions, 220 9.2, 178, fig 9.4, 188
HCHint function, 204 using PM_Q_RAW format, 221, transformation, figs 1.11-1.13,
Hcture functions, 7 222 34ng
Picture function calls, 204 using PM_QLSTD format, scale to fit window, fig 7.5,
Picture utilities, 204 221-222, 233-234 166-167
PIF files, 204 using Hesentation Manager set id allocation, fig 4.7, 119
PM_Q_RAW print format, 221, 222, functions, 221-222, 227-232 sub-picture display, fig 11.7,
260 using printer selection method, 214-218
PM_qsTD print format, 221-222, 228-230, 232 text output, figs 1.4-1.6, 18-26
260 using queue selection method, translation removal, fig 7.6, 167
differences from MetaFile, 222 230-231, 232 window, output to, fig 1.2, 13-14
rules for creation, 233-234 using special formats, 222 WM_PAINT prcoessing, fig 2.7, 58
Point size of font, 98, 106 with zero translation, 165, Holog, see Internal prolog
Pointer, 128, 130-131 265-266 Psychometric RGB, 143, 147
I}resentation driver, 1-2, 222-223 PS, see I+esentation space
Hesentation space, 2, 4349 Hograns:
asscoiation, 45, 46, 49 area drawing, fig 1.8, 28-29 Queue destination functions, 235
cached Micro-PS, 43rd4, 4546 BitBlt, fig 1.10, 32-33, figs Queue driver, see Queue processor
creation, 44, 46 5.3-5.5, 135-139 Queue name, 219, 229, 230
Micro-PS, 43, 44 BitBlt image with realizable color Queue prcoessor, 232-233, 261,
Normal-PS, 43, 4445 table, fig 5.6, 139-142 263-266
ormership, 2 bitmap, create and draw to, fig Queue selection method of printing,
rmQueryHofilestring, 228, 229, 5.2, 133-134 230-231
230, 231, 233 cached Micro-PS draw, fig 2.6, 57 Queued printing, 220
frimitive groups, 5. See oiso clip path definition, fig 3.18,
Attribute bundles 96-97
frinitives, drawing, 5no DevpostDeviceModes, fig 12.7, Realizable color table, 132, 146,
Hint destination functions, 235 241, fig 12.12, 246 198-199
Hint job functions, 235 DRIVDATA querying for queue, Reference point, pattern, 80
Hint queue processor, see Queue fig 12.11, 245 Flegion complexity, 171
prcroessor emor display using Legion functions, 170
Hint requester, 225-227 WinGetLastError, fig 1.14, Flegions, 169-171
flint server, 225-227 38J0 Reset option on GpiplayMetaFile,
frint subsystem, 222-224 geometric wide line, fig 3.17, 197, 198, 234
Hinter, 219-254 95-96 Resource fLmctions of PS, 7
318 INDEX
® .g8 gr
VNR Computer Library computer science/graphics
While 08/2 Presentation Manager offers a rich and powerful graphics interface, this complex
package is not generally well understood. In this volume, IBM's former GPI Development Team .
Leader for 08/2 1.1 clearly- describes the Graphics Programming Interface for the current
version of 08/2.
Designed to supplement the IBM and Microsoft ™ manuals, this guide addresses both GPI
and Device functions and their architectures. Graham C.E. Winn taps his extensive experience
with the GPI to show how it can provide high-quality text and graphics output to displays and
printers. He explains the full range of graphic functions from simple to complex, without use of
complicated mathematics.
Winn provides a detailed description of the Application Programming Interfaces, along with
more than 60 programming examples that help answer many questions about GP! and Device
functions. He covers use of the GP! to display text, characters, lines, curves, areas, markers,
images, and more. Chapters on all the facets of GPI drawing from an application expand your
understanding of:
• FontS'-public and private fonts, monospaced and proportional fonts, raster and outline
fonts, font selection, logical font creation
• BitmapS'-bitmap formats, creation, deletion, selection, data transfer
• Color tableS'-the standard color table, logical color table creation, color queries
■ Coordinate spaces and transformation-page units, matrix parameter formats, coordinate
limits, model transform , viewing transform, default viewing transform, device transform
• MetaFile5-MetaFile printing, MetaFile-to-MetaFile recording, scaling MetaFiles to fit an
output area, displaying a MetaFile as a subpicture, MetaFile restrictions
Printin5rqueued printing, base control program printing, Presentation Manager printing,
08/2 print subsystem, printer installation and setup, form selection, printer fonts
The author also explores the GPl's less obvious function capabilities, limitations, and restric-
tions. In addition, he helps clarify GPI operation through simple C programs that illustrate the
functions in use . The C programs may be purchased separately ~n a diskette.
Written by an IBM insider who has had extensive GP! involvement since its initial development,
this reference will open the door to superior 08/2 graphics and serve as a valuable aid to
application program developers.
ut D
Graham C.E. Winn, Ph.D., has worked at IBM since 1974 on display and workstation software in
both development and customer support roles. His involvement with Presentation Manager
began in 1986, when he became Lead GPI Developer for IBM's 0S/2 Version 1.1. He has
since worked as part of the team handling both service and non-defect questions relating to
GP! and other areas. Dr. Winn has also taught the GPI part of IBM's 0S/2 programming class
and presented a GPI seminar. He has written a number of journal art icles and technical dis-
closure bulletins, and holds a patent for a video display terminal with partitioned screen. He
earned his Ph.D. and B.Sc. degrees at Southampton University in England.
ISBN 0-442-00739-6
90000>
Van Nostrand Reinhold
115 Fifth Avenue, N.Y. , New York 10003
9 780442 007393