The text of a manual · part 11 of 18
Qlarity-Based Terminal Programmer's Reference Manual: Chapter 4 Qlarity API Function Reference, pages 65 to 73
Pages 65 to 73 of 134, from Qlarity-Based Terminal Programmer's Reference Manual
The original document is the PDF (1.5 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
Filed in the catalog under the QSI Corp QTERM-G70
Page 65
QSI Qlarity-based Terminal Programmer’s Reference
53
{height} The variable passed in as height should contain the desired height of the resultant pixmap.
{data} The data to be rendered as text. The type can be a unibyte or byte array (unistring or string).
Description:
{flags} A value of type “font_flags” (see below) that determines how the text will be rendered.
This function is used to retrieve a region of the pixel map for an object. This pixel map indicates the individual colors drawn up to this point in each pixel location for the object (based on the size of the object given to the resize function). The returned array will be a color array of size "width * height", indicating the colors drawn so far. Thus, the color drawn at pixel coordinate x,y in the object (with 0,0 being the top left pixel of the region) has the color indicated by the "(y * width) + x)"-th element in the returned array.
4.7 Rendering Text on the Display Qlarity includes support for both raster (BDF) and TrueType (TTF) font resources. This section describes the API functions to render and paint text using these fonts. 4.7.1
GetBdfTextSize
Description: This function finds the size of a given text string and returns it in the variables passed as parameters. The “{width}” and “{height}” variables receive the width and height in pixels of the rendered region. The “{xoffset}” and “{yoffset}” variables receive the offset from the upper left corner of the region to the origin of the first rendered character. The parameter “{flags}” is of type “font_flags,” which is a type that can have any combination of following legal values (other font_flags settings are ignored): FONT_NORMAL Render the text horizontally with the text in the foreground color and remainder of the region in the background color.
Syntax: getbdftextsize(width as reference to -> integer, height as reference to integer, -> xoffset as reference to integer, yoffset -> as reference to integer, font as bdffont, -> {data}[] as reference? to anytype, flags -> as font_flags)
Parameters: {width} An integer to receive the width of the text box. {height} An integer to receive the height of the text box. {xoffset} An integer to receive the horizontal offset from the upper left corner of the rendered region to the origin of the first character. {yoffset} An integer to receive the vertical offset from the upper left corner of the rendered region to the origin of the first character. {font} The bdffont resource.
FONT_VERTICAL Render the text vertically with the text in the foreground color and the remainder of the region in the background color. (Most fonts that use Latin characters do not support this option.) FONT_INVERSE Render the text horizontally with the text in the background color and the remainder of the region in the foreground color. FONT_HBASELINE Instead of calculating the standard width (text fits exactly in this width), calculate the baseline width (multiple lines will always have the same xoffset and thus will always line up properly). FONT_VBASELINE Instead of calculating the standard height (text fits exactly in this height), calculate the baseline height (multiple lines will always have the same yoffset and thus will always line up properly). Multiple flags may be specified by combining them with a boolean AND operation.
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 66
54
QSI Qlarity-based Terminal Programmer’s Reference
Typically, this function is called as a precursor to calling the DrawBDFText() API function. The “{width},” “{height},” “{xoffset},” and “{yoffset}” values obtained from this function call are used as parameters in the call to DrawBdfText(). 4.7.2
GetBDFTextFit input, the 0-th element is used to indicate the total height (in pixels) of the box that the text needs to fit into (unless FONT_VFIT is specified, in which case it is ignored). On return, the height for each line of text will be in the individual elements of the array, with the 0-th element always containing the final full height of all the text lines (if FONT_VFIT is specified then this is calculated, otherwise it is the same value as was passed in).
Syntax: getbdftextfit(multiflags[] as reference -> to multiline_flags, xpos[] as reference -> to integer, ypos[] as reference to -> integer, widths[] as reference to -> integer, heights[] as reference to -> integer, xoffsets[] as reference to -> integer, yoffsets[] as reference to -> integer, indices[] as reference to -> integer, lengths[] as reference to -> integer, font as bdffont, data[] as -> reference? to sametype!, wordbrks[] as -> reference? to sametype!, linebrks[] as -> reference? to sametype!, flags as -> font_flags)
Parameters: {multiflags} An array of type “multiline_flags” returned by the function giving information on how each line was fitted (see below). {xpos} An array of integers returned by the function that tells the relative horizontal offset for where each line of text should be drawn. {ypos} An array of integers returned by the function that tells the relative vertical offset for where each line of text should be drawn. {widths} An integer array used as both an input and an output. For input, the 0-th element is used to indicate the total width (in pixels) of the box that the text needs to fit into (unless FONT_HFIT is specified, in which case it is ignored). On return, the width for each line of text will be in the individual elements of the array, with the 0-th element always containing the final full width of all the text lines (if FONT_HFIT is specified then this is calculated, otherwise it is the same value as was passed in). {heights} An integer array used as both an input and an output. For
{xoffsets} An integer array used as both an input and an output. For input, if FONT_HLEFT, FONT_HRIGHT, or FONT_HCENTER is not specified (by default, this is the case), the 0-th element is used to determine how far from the left edge the origin of the first text character should be. On return, the elements indicate how far from the left edge each line's origin should be placed. {yoffsets} An integer array used as both an input and an output. For input, if FONT_VTOP, FONT_VBOTTOM, or FONT_VCENTER is not specified (by default, this is the case), the 0-th element is used to determine how far from the top edge the origin of the first text character should be. On return, the elements indicate how far from the top edge each line's origin should be placed. {indices} An integer array used as both an input and an output. For input, the 0-th element gives the first index into “{data}” indicating where to begin the text fitting. Characters before this index are not fitted. A value of 0 starts at the beginning. On return, the index to the first character for each line of text will be in the individual elements of the array, with the 0-th element containing the index where text fitting began. {lengths} An integer array used as both an input and an output. For input, The number of elements of “{data}” to fit, or -1 to indicate all elements from the starting index to the end of “{data}.” On return, the number of elements that should be drawn for each line of text is indicated in the individual elements of the array, with the 0-th element containing the total length of data fitted. {font} The bdffont resource. {data} The data to be rendered as text. The type can be a unibyte or byte array (unistring or string).
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 67
QSI Qlarity-based Terminal Programmer’s Reference
{wordbrks} An array of the same type as “{data}” that determines which characters to treat as word breaks (spaces, tabs, etc.). {linebrks} An array of the same type as “{data}” that determines which characters to treat as line breaks (newline, form feed, etc.). {flags} A value of type “font_flags” (see below) that determines how the text will be rendered. Description: This function tries to find the best text fit for “{data}.” A good understanding of the GetBDFTextSize and DrawBDFText functions should prelude attempts to use this function. The parameter “{flags}” is of type “font_flags,” which is a type that can have any combination of following legal values (other font_flags settings are ignored): FONT_NORMAL Render the text horizontally with the text in the foreground color and remainder of the region in the background color. FONT_VERTICAL Render the text vertically with the text in the foreground color and the remainder of the region in the background color. (Most fonts that use Latin characters do not support this option.) FONT_INVERSE Render the text horizontally with the text in the background color and the remainder of the region in the foreground color. FONT_DRAWLINEBREAKS Consider all line break characters as actually drawn when calculating fit (otherwise line break characters are NOT drawn). FONT_DRAWWORDBREAKS Consider all word break characters as actually drawn when calculating fit (otherwise word break characters are NOT drawn). FONT_NOSOFTBREAKS Disallow breaking a line anywhere that is not a line break or a word break.
55
FONT_HBASELINE Instead of calculating the standard width (text fits exactly in this width), calculate the baseline width (multiple lines will always have the same xoffset and thus will always line up properly). FONT_HFIT Don't use the passed in width, but calculate the actual width needed to fit all of the given text. FONT_HABS Use the 0-th element of the xoffsets array to determine how far from the left edge the origin of the text should be placed. NOTE: Specifying FONT_HLEFT, FONT_HRIGHT, FONT_HCENTER overrides FONT_HABS.
or
FONT_HLEFT Fit the text such that it is all left justified. FONT_HCENTER Fit the text such that it is all center justified (horizontally). FONT_HRIGHT Fit the text such that it is all right justified. FONT_VBASELINE Instead of calculating the standard height (text fits exactly in this height), calculate the baseline height (multiple lines will always have the same yoffset and thus will always line up properly). FONT_VFIT Don't use the passed in height, but calculate the actual height needed to fit all of the given text. FONT_VABS Use the 0-th element of the yoffsets array to determine how far from the top edge the origin of the text should be placed. NOTE: Specifying FONT_VTOP, FONT_VBOTTOM, FONT_VCENTER overrides FONT_VABS. FONT_VTOP Fit the text such that it is all top justified.
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770 or
Page 68
56
QSI Qlarity-based Terminal Programmer’s Reference
FONT_VCENTER Fit the text such that it is all center justified (vertically). FONT_VBOTTOM Fit the text such that it is all bottom justified.
“{multiflags}” element to determine if the line did not fit at all inside the given height. 4.7.3
GetBdfFontMetrics
Syntax: Multiple flags may be specified by combining them with a boolean AND operation. Typically, this function is called as a precursor to calling the DrawBDFTextFit() API function. All values obtained from this function call are used as parameters in the call to DrawBDFTextFit(). On return, the array “{multiflags}” will contain information about how each line was rendered. Any combination of the following flags can be expected: MULTILINE_SOFTBREAK Use a boolean AND with this flag and the returned “{multiflags}” element to determine if the line was terminated by using a soft break. MULTILINE_WORDBREAK Use a boolean AND with this flag and the returned “{multiflags}” element to determine if the line was terminated at a word break element. MULTILINE_LINEBREAK Use a boolean AND with this flag and the returned “{multiflags}” element to determine if the line was terminated at a line break element. MULTILINE_PARTIAL_WIDTH Use a boolean AND with this flag and the returned “{multiflags}” element to determine if the line only fits partially inside the given width. MULTILINE_NONE_WIDTH Use a boolean AND with this flag and the returned “{multiflags}” element to determine if the line did not fit at all inside the given width. MULTILINE_PARTIAL_HEIGHT Use a boolean AND with this flag and the returned “{multiflags}” element to determine if the line only fits partially inside the given height.
getbdffontmetrics(maxleft as reference to -> integer, maxright as reference to -> integer, maxup as reference to integer, -> maxdown as reference to integer, -> xnextline as reference to integer, -> ynextline as reference to integer, font -> as bdffont, flags as font_flags)
Parameters: {maxleft} An integer to receive the maximum distance in pixels from a character origin to the left edge of any character in the font. {maxright} An integer to receive the maximum distance from a character origin to the right edge of any character in the font. {maxup} An integer to receive the maximum distance from a character origin to the top edge of any character in the font. {maxdown} An integer to receive the maximum distance from a character origin to the bottom edge of any character in the font. {xnextline} An integer to receive the horizontal offset from the origin of the first character on a line to the origin of the first character on the next line. {ynextline} An integer to receive the vertical offset from the origin of the first character on a line to the origin of the first character on the next line. {font} The bdffont resource. {flags} A value of type “font_flags” (see section 4.7.1) that determines how the text will be rendered
MULTILINE_NONE_HEIGHT Use a boolean AND with this flag and the returned
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 69
QSI Qlarity-based Terminal Programmer’s Reference
Description: This function returns important metrics for the “{font}” resource which can be used to determine values for parameters in calls to DrawBdfText(). The diagram below illustrates the meaning of the various metrics. This function is particularly useful when rendering multiple lines of text.
maxright origin maxup
{width} The width of the region to use for rendering. {height} The height of the region to use for rendering. {xoffset} The horizontal offset from the upper left corner of the rendered region to the origin of the first character. {yoffset} The vertical offset from the upper left corner of the rendered region to the origin of the first character. {font} The bdffont resource.
maxdown ynextline
57 maxleft
{data} The data to be rendered as text. The type can be a unibyte or byte array (unistring or string). {flags} A value of type “font_flags” (see section 4.7.1) which determines how the text will be rendered. Description:
Origin of next line
4.7.4 xnextline
DrawBdfText
This function renders the text contained in “{data}” and paints the rendered region to the display. The “{width},” “{height},” “{xoffset},” and “{yoffset}” values are typically obtained from a call to GetBdfTextSize() or inferred from metrics obtained from a call to GetBdfFontMetrics(). The rendered text is clipped if the area of the region defined by “{width}” and “{height}” is not sufficient, or if the values of “{xoffset}” and “{yoffset}” place some or all of the text outside of the rendering region.
Syntax: drawbdftext(x as integer, y as integer, -> width as integer, height as integer, -> xoffset as integer, yoffset as integer, -> font as bdffont, data[] as reference? to -> anytype, {flags} as font_flags)
Parameters: {x} The x-position of the upper left corner of the rendered region (relative to the calling object's parent). {y} The y-position of the upper left corner of the rendered region (relative to the calling object's parent).
4.7.5
DrawBDFTextFit
Syntax: drawbdftextfit(multiflags[] as reference? -> to multiline_flags, xpos[] as reference? -> to integer, ypos[] as reference? to -> integer, widths[] as reference? to -> integer, heights[] as reference? to -> integer, xoffsets[] as reference? to -> integer, yoffsets[] as reference? to -> integer, indices [] as reference? to -> integer, lengths [] as reference? to -> integer, font as bdffont, data[] as -> reference? to anytype, flags as font_flags)
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 70
58
QSI Qlarity-based Terminal Programmer’s Reference
Parameters: {multiflags} An array of type “multiline_flags” indicating some information on how well the lines fit within the specified region. {xpos} An array of integers. The 0-th element indicates the x-position of the upper left corner of the rendered region (relative to the calling object's parent). Subsequent elements identify the relative horizontal offset from the initial x-position where each line of text should be drawn. {ypos} An array of integers. The 0-th element indicates the y-position of the upper left corner of the rendered region (relative to the calling object's parent). Subsequent elements identify the relative vertical offset from the initial y-position where each line of text should be drawn. {widths} An array of integers indicating the width for each line of text. {heights} An array of integers indicating the height for each line of text. {xoffsets} An array of integers indicating the horizontal offset from the upper left corner of the rendered region to the origin of the first character for each line.
{flags} A value of type “font_flags” (see below) that determines how the text will be rendered. Description: This function renders the text contained in “{data}.” The parameters are typically obtained by a call to GetBDFTextFit(). The rendered text is clipped as necessary. A good understanding of the GetBDFTextSize and DrawBDFText functions should prelude attempts to use this function. The parameter “{flags}” is of type “font_flags,” which is a type that can have any combination of following legal values (other font_flags settings are ignored): FONT_NORMAL Render the text horizontally with the text in the foreground color and remainder of the region in the background color. FONT_VERTICAL Render the text vertically with the text in the foreground color and the remainder of the region in the background color. (Most fonts that use Latin characters do not support this option.) FONT_INVERSE Render the text horizontally with the text in the background color and the remainder of the region in the foreground color.
{yoffsets} An array of integers indicating the vertical offset from the upper left corner of the rendered region to the origin of the first character for each line.
FONT_DRAW_HPARTIAL Draw any horizontal lines that are marked as appearing partially within the fitted text region.
{indices} An array of integers the tells the index into “{data}” where each line of text begins.
FONT_DRAW_VPARTIAL Draw any vertical lines that are marked as appearing partially within the fitted text region.
{lengths} An array of integers indicating the number of elements to draw in each line of “{data}.”
Multiple flags may be specified by combining them with a boolean AND operation.
{font} The bdffont resource.
This function is included mostly to increase the efficiency of drawing multiline text. In Qlarity, it would look something like the following:
{data} The data to be rendered as text. The type can be a unibyte or byte array (unistring or string).
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 71
QSI Qlarity-based Terminal Programmer’s Reference
59 for tmp = 1 to len(lengths) - 1 drawbdftext(x[0] + x[tmp], y[0] + y[tmp], -> widths[tmp], heights[tmp],xoffsets[tmp], ->
{flags} A value of type “font_flags” (see below) that determines how the text will be rendered.
yoffsets[tmp],thefont,mid(text,-> indices[tmp], lengths[tmp]), flags) next
Description:
4.7.6
GetTTFTextSize
Syntax: getttftextsize(width as reference to -> integer, height as reference to integer, -> xoffset as reference to integer, yoffset -> as reference to integer, {font} as ttfont,-> facenum as integer, {ptsize} as integer, -> data[] as reference? to anytype, {flags} -> as font_flags)
This function finds the size of a given text string rendered in the given point size and typeface. The calculated values are returned in the variables passed as parameters. The “{width}” and “{height}” variables receive the width and height in pixels of the rendered region, respectively. The “{xoffset}” and “{yoffset}” variables receive the offset from the upper left corner of this region to the origin of the first rendered character. The “{flags}” is of type “font_flags,” which is described in section 4.7.1.
Parameters:
Typically, this function is called as a precursor to calling DrawTTFText(). The “{width},” “{height},” “{xoffset},” and “{yoffset}” values obtained from this function call are used as parameters in the call to DrawTTFText().
{width} An integer to receive the width of the text box.
4.7.7
{height} An integer to receive the height of the text box. {xoffset} An integer to receive the horizontal offset from the upper left corner of the rendered region to the origin of the first character. {yoffset} An integer to receive the vertical offset from the upper left corner of the rendered region to the origin of the first character.
GetTTFFontMetrics
Syntax: getttfontmetrics(maxleft as reference to -> integer, maxright as reference to integer,-> maxup as reference to integer, maxdown as -> reference to integer, xnextline as -> reference to integer, ynextline as -> reference to integer, font} as ttfont, -> facenum as integer, ptsize as integer, -> flags as font_flags)
Parameters:
{font} The ttfont resource.
{maxleft} An integer to receive the maximum distance in pixels from a character origin to the left edge of any character in the font.
{facenum} The number for the desired face in the ttfont resource (typically 0).
{maxright} An integer to receive the maximum distance from a character origin to the right edge of any character in the font.
{ptsize} The desired point size of the rendered text.
{maxup} An integer to receive the maximum distance from a character origin to the top edge of any character in the font.
{data} The data to be rendered as text (same types as BDF functions allowed).
{maxdown} An integer to receive the maximum distance from a character origin to the bottom edge of any character in the font.
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 72
60
QSI Qlarity-based Terminal Programmer’s Reference
{xnextline} An integer to receive the horizontal offset from the origin of the first character on a line to the origin of the first character on the next line. {ynextline} An integer to receive the vertical offset from the origin of the first character on a line to the origin of the first character on the next line. {font} The ttfont resource. {facenum} The number for the desired face in the ttfont resource (typically 0). {ptsize} The point size.
{height} The height of the region to use for rendering. {xoffset} The horizontal offset from the upper left corner of the rendered region to the origin of the first character. {yoffset} The vertical offset from the upper left corner of the rendered region to the origin of the first character. {font} The ttfont resource. {facenum} The number for the desired face in the ttfont resource (typically 0). {ptsize} The desired point size for the rendered text.
{flags} A value of type “font_flags” (see section 4.7.1) that determines how the text is rendered
{data} The data to be rendered as text. The type can be a unibyte or byte array (unistring or string).
Description: This function returns important metrics for the “{font}” resource that can be used to determine values for parameters in calls to DrawTTFText(). It is very similar to the analogous GetBdfFontMetrics() API function.
{flags} A value of type “font_flags” (see section 4.7.1) that determines how the text is rendered. Description:
4.7.8
DrawTTFText drawttftext(x as integer, y as integer, -> width as integer, height as integer, -> xoffset as integer, yoffset as integer, -> font as ttfont, facenum as integer, -> ptsize as integer, {data}[]as reference? -> to anytype, {flags} as font_flags)
This function renders the text contained in “{data}” and paints the rendered region to the display. The “{width},” “{height},” “{xoffset},” and “{yoffset}” values are typically obtained from a call to GetTTFTextSize() or inferred from metrics obtained from a call to GetTTFontMetrics(). The rendered text is clipped if the area of the region defined by “{width}” and “{height}” is not sufficient, or if the values of “{xoffset}” and “{yoffset}” place some or all of the text outside of the rendering region.
Parameters:
4.7.9
{x} The x-position of the upper left corner of the rendered region (relative to the calling object's parent).
Syntax:
Syntax:
{y} The y-position of the upper left corner of the rendered region (relative to the calling object's parent). {width} The width of the region to use for rendering.
SetTTFAngle setttfangle(theta as float)
Parameters: {theta} The angle of the rendered text (in radians, relative to horizontal).
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 73
QSI Qlarity-based Terminal Programmer’s Reference
Description:
Parameters:
This function sets the angle at which text is rendered in using a ttfont resource, relative to the horizontal plane. The default angle is 0, indicating standard left-to-right horizontal rendering. This function should be called before GetTTFTextSize(). The last angle setting persists until the current message handler returns.
{width} An integer to receive the width of the text box.
4.7.10 GetSysFontCharacters Syntax: getsysfontcharacters(font as sysfont, -> facenum as integer, bRange as unibyte, -> eRange as unibyte) returns unibyte[]
Parameters: {font} The sysfont resource. {facenum} The number for the desired face in a ttfont resource (typically 0). {bRange} The first character to be checked for in a font. Character codes greater than “{bRange}” but less than “{eRange}” are also checked. {eRange} The last character to be checked for in a font. Character codes less than “{eRange}” but greater than “{bRange}” are also checked. Description: GetSysFontCharacters returns a unibyte array indicating the existing character codes between bRange and eRange (inclusive) in a font. 4.7.11 GetSysTextSize Syntax: getsystextsize(width as reference to -> integer, height as reference to integer,-> xoffset as reference to integer, yoffset -> as reference to integer, font as sysfont,-> facenum as integer, ptsize as integer,-> data[] as reference? to anytype, flags as -> font_flags)
61
{height} An integer to receive the width of the text box. {xoffset} An integer to receive the horizontal offset from the upper left corner of the rendered region to the origin of the first character. {yoffset} An integer to receive the vertical offset from the upper left corner of the rendered region to the origin of the first character. {font} The sysfont resource. This may be either a BDF or a TrueType font. {facenum} The number for the desired face. This value is only used with TrueType fonts and is typically zero (0). {ptsize} The desired point size of the rendered text. This value is ignored unless font specifies a TrueType font. {data} The data to be rendered as text. The type can be a unibyte or byte array (unistring, string or charstr). {flags} A value of type "font_flags" (see GetBDFTextSize) that determines how the text will be rendered. Description: This function finds the size of a given text string rendered in the given point size and typeface. The calculated values are returned in the variables passed as parameters. The "{width}" and "{height}" variables receive the width and height in pixels of the rendered region, respectively. The "{xoffset}" and "{yoffset}" variables receive the offset from the upper left corner of this region to the origin of the first rendered character. The "{flags}" is of type "font_flags" Typically, this function is called as a precursor to calling DrawSysText(). The "{width}," "{height}," "{xoffset},"
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770