Class TGLBitmapFontAbstract

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TGLBitmapFontAbstract = class(TObject)

Description

Abstract class for all OpenGL bitmap fonts.

Hierarchy

  • TObject
  • TGLBitmapFontAbstract

Overview

Methods

Public procedure PrintAndMove(const s: string); virtual; abstract;
Public procedure Print(const s: string);
Public function TextWidth(const s: string): integer; virtual; abstract;
Public function TextHeight(const s: string): integer; virtual; abstract;
Public function TextHeightBase(const s: string): integer; virtual; abstract;
Public function Descend: integer; virtual;
Public procedure BreakLines(const unbroken: string; broken: TStrings; maxLineWidth: integer); overload;
Public procedure BreakLines(unbroken, broken: TStrings; maxLineWidth: integer); overload;
Public procedure BreakLines(broken: TStrings; maxLineWidth: integer; FirstToBreak: integer); overload;
Public function MaxTextWidth(SList: TStringList; const Tags: boolean = false): integer;
Public procedure PrintStrings(strs: TStrings; const Tags: boolean; BonusVerticalSpace: TGLint; const RasterX0: Integer = 0; const RasterY0: Integer = 0); overload;
Public procedure PrintStrings(const strs: array of string; const Tags: boolean; BonusVerticalSpace: TGLint; const RasterX0: Integer = 0; const RasterY0: Integer = 0); overload;
Public function PrintBrokenString(const s: string; MaxLineWidth, RasterX0, RasterY0: Integer; RasterPositionsFirst: boolean; BonusVerticalSpace: Integer): Integer;
Public procedure PrintStringsBox(const strs: array of string; const Tags: boolean; BonusVerticalSpace: TGLint; const InsideCol, BorderCol, TextCol: TVector4f; BoxPixelMargin: integer); overload;
Public procedure PrintStringsBox(strs: TStringList; const Tags: boolean; BonusVerticalSpace: TGLint; const InsideCol, BorderCol, TextCol: TVector4f; BoxPixelMargin: integer); overload;

Properties

Public property RowHeight: integer read FRowHeight;
Public property RowHeightBase: Integer read FRowHeightBase;

Description

Methods

Public procedure PrintAndMove(const s: string); virtual; abstract;

Draw text at the current OpenGL raster position, and move the raster position at the end. This way you can immediately call another PrintAndMove again, to add something at the end.

May require 1 free slot on the attributes stack. May only be called when current matrix is modelview. Doesn't modify any OpenGL state or matrix, except it moves raster position.

Public procedure Print(const s: string);

Draw text at the current OpenGL raster position. In contrast to PrintAndMove, raster position is not changed.

May require 1 free slot on the attributes stack. May only be called when current matrix is modelview. Doesn't modify any OpenGL state or matrix.

Public function TextWidth(const s: string): integer; virtual; abstract;
 
Public function TextHeight(const s: string): integer; virtual; abstract;
 
Public function TextHeightBase(const s: string): integer; virtual; abstract;

The height (above the baseline) of the text. This doesn't take into account height of the text below the baseline (for example letter "y" has the tail below the baseline in most fonts).

Public function Descend: integer; virtual;

How low the text may go below the baseline. By default this returns TextHeight('y')-TextHeight('a'), which is suitable for normal fonts.

Public procedure BreakLines(const unbroken: string; broken: TStrings; maxLineWidth: integer); overload;

Break lines (possibly break one long string into more strings) to fit the text with given MaxLineWidth.

This takes into account current font information (works also for non-monospace fonts, of course), and converts your Unbroken text into Broken text, such that TextWidth of the longest Broken line fits within MaxLineWidth.

Tries to break on white characters. If not possible (there's a long stream of non-white characters that really has to be broken), it will break in the middle of normal (non-white) characters. The only situation when we have to fail, and the resulting Broken text is wider than required MaxLineWidth, is when a single character in your font is wider than MaxLineWidth. In such case, there's really no solution, and we'll just let such character stay.

If you use the overloaded version where Unbroken is just a string, then note that already existing newlines (NL) inside Unbroken will be correctly preserved.

If you use the overloaded version with separate Unbroken and Broken parameters, then the previous Broken contents are not modified. We only append to Broken new strings, coming from Unbroken text. The overloaded version that takes only Broken parameter (no Unbroken parameter) simply modifies it's Broken parameter (from the line FirstToBreak).

Public procedure BreakLines(unbroken, broken: TStrings; maxLineWidth: integer); overload;
 
Public procedure BreakLines(broken: TStrings; maxLineWidth: integer; FirstToBreak: integer); overload;
 
Public function MaxTextWidth(SList: TStringList; const Tags: boolean = false): integer;

Largest width of the line of text in given list.

Parameters
Tags
Indicates that strings inside SList use HTML-like tags, the same as interpreted by PrintStrings. If your SList uses these tags (for example, you plan to call later PrintStrings with the same SList and Tags = True) then make sure you pass Tags = True to this method. Otherwise, MaxTextWidth will treat tags text (like <font ...>) like a normal text, usually making the width incorrectly large.
Public procedure PrintStrings(strs: TStrings; const Tags: boolean; BonusVerticalSpace: TGLint; const RasterX0: Integer = 0; const RasterY0: Integer = 0); overload;

Print all strings from the list. glRasterPos2i(RasterX0, RasterY0) is the position of the last string, each previous string will be RowHeight + BonusVerticalSpace higher.

Note that BonusVerticalSpace can be < 0 (as well as > 0), this may be sometimes useful if you really want to squeeze more text into some size. Still, make sure that (RowHeight + BonusVerticalSpace) is > 0.

Previous OpenGL raster position value will be ignored and then modified by this method.

May require 1 free slot on the attributes stack. May only be called when current matrix is modelview. Doesn't modify any OpenGL state or matrix, except it moves raster position.

Parameters
Tags
Enable some HTML-like tags to mark font changes inside the text. For now, these can only be used to surround whole lines (so you have to place opening tag at the beginnig of line, and closing tag at the end of line). And for now, the only tag handled is <font color="#rrggbb"> that changes line color to specified RGB. Close with </font>.

This functionality may be enhanced in the future (feature requests and patches welcome). Don't expect full HTML implementation inside, but some small set of useful tags may be doable and comfortable to use. Not necessarily replicating some (old version of) HTML standard.

Public procedure PrintStrings(const strs: array of string; const Tags: boolean; BonusVerticalSpace: TGLint; const RasterX0: Integer = 0; const RasterY0: Integer = 0); overload;
 
Public function PrintBrokenString(const s: string; MaxLineWidth, RasterX0, RasterY0: Integer; RasterPositionsFirst: boolean; BonusVerticalSpace: Integer): Integer;

Print the string, broken such that it fits within MaxLineWidth. The string is broken into many lines using BreakLines, so the original newlines insides are correctly used, and the length of lines fits inside MaxLineWidth.

The strings are printed on the screen, just like by PrintStrings (with Tags = always false for now, since our string breaking cannot omit tags). If RasterPositionsFirst then the RasterX0, RasterY0 determine the position of the first (top) line, otherwise they determine the position of the last (bottom) line.

BonusVerticalSpace has the same meaning as for PrintStrings: it adds an additional space between lines (if positive) or forces the lines to be more tightly squeezed (if negative). Always make sure that (RowHeight + BonusVerticalSpace) > 0.

Returns the number of lines printed, that is the number of lines after breaking the text into lines. This may be useful e.g. to calculate the height of the printed text.

May require 1 free slot on the attributes stack. May only be called when current matrix is modelview. Doesn't modify any OpenGL state or matrix.

Public procedure PrintStringsBox(const strs: array of string; const Tags: boolean; BonusVerticalSpace: TGLint; const InsideCol, BorderCol, TextCol: TVector4f; BoxPixelMargin: integer); overload;

Print all strings from the list, and draw a box with frames around it.

The text is printed like by PrintStrings.

The position of the text and box is determined by the current modelview matrix. The left-bottom box corner is at raster position 0, 0. The current raster position when this method is called doesn't matter. So your only way to move this box is to modify modelview matrix.

BonusVerticalSpace has the same interpretation as for PrintStrings: additional space between lines (if positive) or forces the lines to be more tightly squeezed (if negative). Always make sure that (RowHeight + BonusVerticalSpace) > 0.

The box background inside has color InsideCol. The box frame has color BorderCol. The text has color TextCol.

BoxPixelMargin is the distance (in pixels) between text and the box frame.

We assume that moving by 1 in modelview matrix is equal to moving 1 pixel. In other words, we assume you have normal 2D orthographic projection with the dimensions equal to pixel dimensions.

May require 1 free slot on the attributes stack. May only be called when current matrix is modelview. Doesn't modify any OpenGL state or matrix, except it modifies the raster position.

Public procedure PrintStringsBox(strs: TStringList; const Tags: boolean; BonusVerticalSpace: TGLint; const InsideCol, BorderCol, TextCol: TVector4f; BoxPixelMargin: integer); overload;
 

Properties

Public property RowHeight: integer read FRowHeight;

Height of a row of text in this font. This may be calculated as simply TextHeight('Wy') for most normal fonts.

Public property RowHeightBase: Integer read FRowHeightBase;

Height (above the baseline) of a row of text in this font. Similar to TextHeightBase and TextHeight, note that RowHeightBase is generally smaller than RowHeight, because RowHeightBase doesn't care how low the letter may go below the baseline.


Generated by PasDoc 0.12.1 on 2013-02-04 20:26:50