<< Click to Display Table of Contents >> Rendering Objects |
![]() ![]() ![]() |
In addition to the VFREE-flag, which instructs VPE to render the size of objects when they are inserted into the document, the rendering methods help to compute the size of text and images without inserting them into a document. The methods compute the size of text and images in metric or inch units. The text or image is NOT inserted into the document.
The properties nRenderWidth and nRenderHeight (DLL: VRENDERWIDTH and VRENDERHEIGHT) contain the appropriate values after the rendering has been executed.
Examples:
RenderWriteBox(VLEFTMARGIN, VTOPMARGIN, VRIGHTMARGIN, VFREE, "a long text ...")
Computes the height of the string "a long text …". The computed height can be retrieved in nRenderHeight (DLL: VpeGet(hDoc, VRENDERHEIGHT)). You supply all four coordinates to the RenderWriteBox() method, because the method will also return information, if the text will fit onto the current page, or if a page break will happen when the text is inserted at the specified coordinates.
Doc.RenderPicture(VFREE, VFREE, "..\images\fruits.bmp")
Computes the height and width of the "fruits.bmp" image file. The computed width can be retrieved in nRenderWidth (DLL: VpeGet(hDoc, VRENDERWIDTH)) and the height can be retrieved in nRenderHeight (DLL: VpeGet(hDoc, VRENDERHEIGHT)).
The Picture-Flags like PictureCache, PictureBestFit, etc. are also active.
The following command would then insert the image in the center of the page:
Doc.NoPen
Doc.Picture((Doc.PageWidth - Doc.nRenderWidth) / 2, (Doc.PageHeight -
Doc.nRenderHeight) / 2, VFREE, VFREE, "..\images\fruits.bmp")
NOTE: | If the text-output functions are used with VFREE to calculate widths and / or heights, the calculations need time. The more VPE has to calculate, the slower it works. If you have for example to output a lot of broken text into single lines with equal fonts and font sizes - like in a table - it is a good idea to render the height of the line once and to use the rendered height instead of VFREE. |
Example:
RenderPrint(0, 0, "X")
height = nRenderHeight
for page = 1 to 1000
for line = 1 to 18
for column = 1 to 17 step 2
Write(column, line, -2, -height, "Hello")
next column
next line
PageBreak()
next page
is much faster than
for page = 1 to 1000
for line = 1 to 18
for column = 1 to 17 step 2
Write(column, line, -2, VFREE, "Hello")
next column
next line
PageBreak()
next page
where the height of each "Hello" text is computed over and over again.
NOTE: | A text drawn with a frame around it requires more width and height than a text without a frame. Therefore you need to render the width and height of a framed text separately from text, which is not framed - even if the used fonts and font sizes are the same. Also a text that is printed in two (or more) lines has a different height than simply multiplying the height rendered for a single line with the total number of lines, especially if the text is framed. Therefore you would need to render a text separately, if one or more of the following properties change: • PenSize (text without a frame has a PenSize of zero) • FontSize • FontName • Number of lines of text to output The "Report" and "Speed + Tables" demos make use of the technique described above. |