Reviewed and revised November 2018
Updated axcall MIAMEX, MX_GDICALC, MXGDI_CALCRECT, handle, status, lft, top, rght, btm, memo, height, overflow {,flags}
This operation calculates how much text will fit in a specified rectangle, based on the current printer context and font.
Parameter |
Type |
I/O |
Description |
---|---|---|---|
handle |
B,4 |
in |
Device context handle (from MXGDI_OPEN) |
status |
F6 |
out |
|
lft,top, rght,btm |
Num |
in/out |
Coordinates of the rectangle, in the units specified by mapmode when the printer device context was established. Coordinates rght and btm are are updated only when flags parameter contains TRF_CALCRECT option. lft and top are never updated. |
memo |
in/out |
On input, specifies the text we want to output within the rectangle. On return, it contains the amount of the original text that actually fits in the rectangle. |
|
height |
Num |
out |
If memo fits entirely within the rectangle, height returns the rectangle height actually required (which may be less than the full rectangle height). Otherwise, it will return the input height of the rectangle. |
overflow |
out |
Returns the trailing portion of memo which does not fit within the rectangle. If it all fits, then a null string is returned here. Note that this operation supports a dynamic string (S,0). |
|
Num |
in |
Optional flags used when calculating the optimum rectangle based on various formatting options. |
Comments
The vertical spacing used for the calculation is the natural vertical spacing for the current font and printer device context. To make sure you get the same spacing when actually printing, use the GDI printing directive RESETLPP after SETFONT and before TEXTRECTANGLE. The vertical spacing is not automatically reset by SETFONT.
If memo must be wrapped to multiple lines to fit within the rectangle, standard word-wrapping logic will be used to avoid breaking lines mid-word. Embedded CRLFs are also respected.
You can use this operation iteratively (changing the font size incrementally each time) to determine the optimum font size for the specified memo text to fit within the rectangle.
The test program GDICALC in EXLIB:[908,37] is to illustrate this kind of logic.
Note that MXGDI_CALCRECT assumes vertical spacing optimum for the font, i.e. as if a RESETLPP command had been executed after SETFONT. If you don't do this in the actual GDI print file, the spacing for the print operation may not match that used for the calculations.