Class TCastleFont
Unit
Declaration
type TCastleFont = class(TCastleAbstractFont)
Description
Font loaded from a font file, like ttf or otf. This class is typically used for outline (scalable, vector) fonts in ttf or otf formats. But it can really deal with any font supported by the FreeType library, even bitmap fonts, see the summary of font formats supported by FreeType.
This can load a font file, or it can use ready data in TTextureFontData. The latter allows to use this for fonts embedded in a Pascal source code, since our texture-font-to-pascal can convert a font file to a unit that defines ready TTextureFontData instance.
Hierarchy
- TObject
- TPersistent
- TComponent
- TCastleComponent
- TCastleAbstractFont
- TCastleFont
Overview
Fields
nested const DefaultOptimalSize = 20; |
Methods
constructor Create(AOwner: TComponent); overload; override; |
|
destructor Destroy; override; |
|
function PropertySections(const PropertyName: String): TPropertySections; override; |
|
function FontLoaded: Boolean; overload; override; |
|
constructor Create(const Url: String; const ASize: Cardinal; const AnAntiAliased: Boolean; const ACharacters: TUnicodeCharList = nil); reintroduce; overload; deprecated 'use Create(Owner: TComponent), then assign properties to load font: OptimalSize, LoadCharacters, AntiAliased, Url'; |
|
constructor Create(const Url: String; const ASize: Cardinal; const AnAntiAliased: Boolean; const ACharacters: TSetOfChars); reintroduce; overload; deprecated 'use Create(Owner: TComponent), then assign properties to load font: OptimalSize, LoadCharacters, AntiAliased, Url'; |
|
procedure Load(const Url: String; const ASize: Cardinal; const AnAntiAliased: Boolean; const ACharacters: TUnicodeCharList = nil; const AdjustProperties: Boolean = true); overload; deprecated 'assign properties to load font: OptimalSize, LoadCharacters, AntiAliased, Url'; |
|
procedure Load(const Data: TTextureFontData; const OwnsData: Boolean = false; const AdjustProperties: Boolean = true); overload; |
|
procedure PrepareResources; override; |
|
procedure Print(const X, Y: Single; const Color: TCastleColor; const S: String); override; |
|
function TextWidth(const S: String): Single; override; |
|
function TextHeight(const S: String): Single; override; |
|
function TextHeightBase(const S: String): Single; override; |
|
function TextMove(const S: String): TVector2; override; |
Properties
property FontData: TTextureFontData read FFont; deprecated 'you should not need to use this directly'; |
|
property Scale: Single read GetScale write SetScale; |
|
property Url: String read FUrl write SetUrl; |
|
property DistanceField: Boolean read FDistanceField write SetDistanceField
default false; |
|
property OptimalSize: Cardinal read FOptimalSize write SetOptimalSize default DefaultOptimalSize; |
|
property AntiAliased: Boolean read FAntiAliased write SetAntiAliased default true; |
|
property LoadBasicCharacters: Boolean read FLoadBasicCharacters write SetLoadBasicCharacters default true; |
|
property LoadCharacters: String read FLoadCharacters write SetLoadCharacters; |
Description
Fields
nested const DefaultOptimalSize = 20; |
|
This item has no description. |
Methods
constructor Create(AOwner: TComponent); overload; override; |
|
This item has no description. |
destructor Destroy; override; |
|
This item has no description. |
function PropertySections(const PropertyName: String): TPropertySections; override; |
|
This item has no description. Showing description inherited from TCastleComponent.PropertySections. Section where to show property in the editor. |
function FontLoaded: Boolean; overload; override; |
|
This item has no description. Showing description inherited from TCastleAbstractFont.FontLoaded. If the font is loaded, it can actually display and measure some characters. |
constructor Create(const Url: String; const ASize: Cardinal; const AnAntiAliased: Boolean; const ACharacters: TUnicodeCharList = nil); reintroduce; overload; deprecated 'use Create(Owner: TComponent), then assign properties to load font: OptimalSize, LoadCharacters, AntiAliased, Url'; |
|
Warning: this symbol is deprecated: use Create(Owner: TComponent), then assign properties to load font: OptimalSize, LoadCharacters, AntiAliased, Url This item has no description. |
constructor Create(const Url: String; const ASize: Cardinal; const AnAntiAliased: Boolean; const ACharacters: TSetOfChars); reintroduce; overload; deprecated 'use Create(Owner: TComponent), then assign properties to load font: OptimalSize, LoadCharacters, AntiAliased, Url'; |
|
Warning: this symbol is deprecated: use Create(Owner: TComponent), then assign properties to load font: OptimalSize, LoadCharacters, AntiAliased, Url This item has no description. |
procedure Load(const Url: String; const ASize: Cardinal; const AnAntiAliased: Boolean; const ACharacters: TUnicodeCharList = nil; const AdjustProperties: Boolean = true); overload; deprecated 'assign properties to load font: OptimalSize, LoadCharacters, AntiAliased, Url'; |
|
Warning: this symbol is deprecated: assign properties to load font: OptimalSize, LoadCharacters, AntiAliased, Url Load by reading a FreeType font file, like ttf. Providing charaters list as Loading a font data also changes Size to the underlying (optimal to render) font data size. |
procedure Load(const Data: TTextureFontData; const OwnsData: Boolean = false; const AdjustProperties: Boolean = true); overload; |
|
Load from a ready TTextureFontData instance. Parameters
|
procedure PrepareResources; override; |
|
This item has no description. Showing description inherited from TCastleAbstractFont.PrepareResources.
The font may require some OpenGL resources for drawing. You can explicitly create them using |
procedure Print(const X, Y: Single; const Color: TCastleColor; const S: String); override; |
|
This item has no description. Showing description inherited from TCastleAbstractFont.Print. Draw text at the given position with given color. If the last Color component is not 1, the text is rendered with blending. Overloaded version without X, Y uses WindowPos (but doesn't modify it, in contrast to PrintAndMove). Overloaded version without Color uses CurrentColor, last color set by glColorv. It is not adviced to use overloaded versions without X, Y or Color — using global state leads to messy code. You should upgrade your code to use the version that gets X,Y,Color explicitly. 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. |
function TextWidth(const S: String): Single; override; |
|
This item has no description. |
function TextHeight(const S: String): Single; override; |
|
This item has no description. |
function TextHeightBase(const S: String): Single; override; |
|
This item has no description. Showing description inherited from TCastleAbstractFont.TextHeightBase. 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). |
function TextMove(const S: String): TVector2; override; |
|
This item has no description. |
Properties
property FontData: TTextureFontData read FFont; deprecated 'you should not need to use this directly'; |
|
Warning: this symbol is deprecated: you should not need to use this directly Underlying font data. |
property Scale: Single read GetScale write SetScale; |
|
Scale applied to the rendered font, compared to FontData.Size. Changing this is equivalent to changing the Size property. |
property Url: String read FUrl write SetUrl; |
|
Loaded font file. Typically this is used for outline (scalable, vector) fonts in ttf or otf formats. But it can really deal with any font format supported by the FreeType library, even bitmap fonts, see the summary of font formats supported by FreeType. |
property DistanceField: Boolean read FDistanceField write SetDistanceField
default false; |
|
Use "distance field" font rendering. This is a font rendering technique that may result in a better quality when the text is large. Underneath, the font is processed to a different texture than usual (that expresses distances to glyphs) and rendered usign a special shader. The positive outcome is that the font looks better (not blurred) even when scaled up. "Scaling up" occurs when the actual font size (derived from TCastleUserInterfaceFont.FontSize and UI scaling) is significantly larger than the optimal size for which the font image was prepared (OptimalSize). In this case, rendering without distance field (when this is Disadvantages: One, preparing a distance field font texture is more time-consuming. So loading time may be slightly larger. This increased loading time is generally negligible if you just have a few fonts. But be sure to profile your loading time (see https://castle-engine.io/manual_optimization.php ) if you use a lot of fonts with A more serious disadvantage is that the result is not always a better quality: At really large sizes, the artifacts of distance field rendering may be visible – the letters are "crisp" but their shape may be slightly distorted. If you don't mind extra memory usage, you can likely get better quality by just loading a larger font texture (with larger OptimalSize) and leaving this property at Morover, when the final font size is *smaller* than the size for which the font was prepared, it will definitely look worse. TODO: We could defeat some of the issues mentioned above. You're welcome to ping us ( https://castle-engine.io/talk.php ) and support ( https://www.patreon.com/castleengine ) to make it happen.
|
property OptimalSize: Cardinal read FOptimalSize write SetOptimalSize default DefaultOptimalSize; |
|
Optimal font size (in real device pixels), the font will be scaled when other size is actually needed. This also sets default Size used for rendering this font. |
property LoadBasicCharacters: Boolean read FLoadBasicCharacters write SetLoadBasicCharacters default true; |
|
Load from font all "basic" characters, which include digits, English letters and standard ASCII symbols. See SimpleAsciiCharacters for exact definition. These are loaded in addition to characters listed on LoadCharacters. |
Generated by PasDoc 0.16.0-snapshot.