XPRINT TEXT SIZE statement

Purpose

Calculate the size of text to be printed on a host printer.

Syntax

XPRINT TEXT SIZE txt$ TO nWidth!, nHeight!

Remarks

This statement calculates the total size of the printed text, based upon the current font for the host printer.  The sizes returned are specified in pixels, unless optional world coordinates have been defined with an XPRINT SCALE statement.

This allows you to easily calculate the appropriate print position, particularly when using a proportional font.  If this statement is executed without a host printer attached, error 57 is generated.

See also

XPRINT, XPRINT ATTACH, XPRINT CHR SIZE, XPRINT SET FONT

Example

FUNCTION PBMAIN

  ' The following example draws the text both horizontally

  ' and vertically centered on the host printer page

 

  LOCAL x, y, w, h, w2, h2 AS LONG

  LOCAL sText AS STRING

  sText = "PowerBASIC"

 

  XPRINT ATTACH "Lexmark C750"

  XPRINT COLOR %BLUE, -2  ' blue text, clear background

  XPRINT FONT "Times New Roman", 18, 3  ' 18p, bold, italic

 

  XPRINT GET CLIENT TO w, h  ' get client size

  XPRINT TEXT SIZE sText TO w2, h2      ' get text size

  x = (w-w2) / 2                        ' centered x-pos

  y = (h-h2) / 2                        ' centered y-pos

 

  XPRINT SET POS (x, y)                 ' set position

  XPRINT sText                          ' draw the text

  XPRINT CLOSE

END FUNCTION