wxArt2D
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members

Defines a font to be set to a2dDrawer2D or stored in a2dCanvsObject etc. More...

#include <stylebase.h>

Inheritance diagram for a2dFont:
Inheritance graph
[legend]
Collaboration diagram for a2dFont:
Collaboration graph
[legend]

Public Types

enum  a2dFontLoadMethod {
  a2d_LOAD_DEFAULT = 0x0, a2d_LOAD_NO_SCALE = 0x1, a2d_LOAD_NO_HINTING = 0x2, a2d_LOAD_RENDER = 0x4,
  a2d_LOAD_NO_BITMAP = 0x8, a2d_LOAD_VERTICAL_LAYOUT = 0x10, a2d_LOAD_FORCE_AUTOHINT = 0x20, a2d_LOAD_CROP_BITMAP = 0x40,
  a2d_LOAD_PEDANTIC = 0x80, a2d_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH = 0x200, a2d_LOAD_NO_RECURSE = 0x400, a2d_LOAD_IGNORE_TRANSFORM = 0x800,
  a2d_LOAD_MONOCHROME = 0x1000, a2d_LOAD_LINEAR_DESIGN = 0x2000, a2d_LOAD_NO_AUTOHINT = 0x8000U
}
 load method of glyph, see Freetype refence for meaning of FT_LOAD_*
 

Public Member Functions

a2dFontType GetType (void) const
 
 a2dFont ()
 Constructor.
 
 a2dFont (const a2dFont &other)
 Copy constructor.
 
 a2dFont (const wxFont &font, double size, a2dFontType type=a2dFONT_WXDC, wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
 Constructor. More...
 
 a2dFont (double size, int family, int style=wxNORMAL, int weight=wxNORMAL, const bool underline=false, const wxString &faceName=wxT(""), wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
 Constructor. More...
 
 a2dFont (const wxString &filename, double size=0.0, wxFontEncoding encoding=wxFONTENCODING_DEFAULT, int faceindex=0)
 constructor of Freetype font based on filename of fontfile.
 
 a2dFont (const wxString &filename, double size, bool monoSpaced, double weight=0.0)
 constructor of stroked font based on filename of fontfile. See a2dFontStrokeData
 
virtual ~a2dFont ()
 Destructor.
 
bool operator== (const a2dFont &a)
 return true if the same font (same reference)
 
bool operator!= (const a2dFont &a)
 return true if not the same font (same reference)
 
bool Ok () const
 Check font validity. More...
 
const a2dFontInfoGetFontInfo () const
 Get fontinfo of the font.
 
void SetSize (double size)
 Set the font size. More...
 
double GetSize () const
 Get the font size. More...
 
double GetLineHeight () const
 Get the line height. More...
 
double GetDescent () const
 Get descent. More...
 
double GetWidth (wxChar c)
 Get width of a single character.
 
double GetKerning (wxChar c1, wxChar c2) const
 Get kerning space between two characters. More...
 
double GetStrokeWidth () const
 Get stroke width. More...
 
a2dStrokeGlyph GetGlyphStroke (wxChar c) const
 Get the glyph of a single character. More...
 
const a2dGlyphGetGlyphFreetype (wxChar c) const
 
void SetDeviceHeight (double sizeInPixels)
 
double GetDeviceHeight ()
 
wxFont & GetFont (void)
 wxFont in case of a2dFONT_WXDC
 
a2dBoundingBox GetTextExtent (const wxString &string, int alignment=wxMINX|wxMINY, double *w=NULL, double *h=NULL, double *descent=NULL, double *externalLeading=NULL) const
 Get the dimensions in world coordinates of the string. More...
 
void GetTextExtent (const wxString &string, double &w, double &h, double &descent, double &externalLeading) const
 Get the dimensions in world coordinates of the string. More...
 
void GetTextExtentWH (const wxString &string, double &w, double &h) const
 Get the dimensions in world coordinates of the string. More...
 
bool GetPartialTextExtents (const wxString &text, wxArrayInt &widths) const
 
bool GetVpath (wxChar c, a2dVpath &glyph, const a2dAffineMatrix &affine=a2dIDENTITY_MATRIX)
 Get the glyph of a single character as a vpath. More...
 
void GetVpath (const wxString &text, a2dVpath &vpath, double x=0, double y=0, int alignment=wxMINX|wxMINY, bool yaxis=true, const a2dAffineMatrix &affine=a2dIDENTITY_MATRIX)
 Render a text string into a vector path. More...
 
bool AlwaysWriteSerializationId () const
 
wxString CreateString ()
 Create a string description of the font. More...
 
void SetFilename (const wxString &filename)
 Set the font filename and load the font. More...
 
wxString GetFilename (bool filenameonly=false) const
 Get the font filename. More...
 
double GetWeight () const
 Get the weight of the font. More...
 
void SetWeight (double weight)
 Set the weight of the font. More...
 
void SetWeight (const wxString &weight)
 Set the weight of the font, from a string. More...
 
wxObjectRefData * CreateRefData () const
 
wxObjectRefData * CloneRefData (const wxObjectRefData *data) const
 

Static Public Member Functions

static void GetInfoList (a2dFontInfoList &list)
 Append fonts of this type to the list. More...
 
static a2dFont CreateFont (const a2dFontInfo &info, bool force=false)
 Create the font from a fontinfo description. More...
 
static wxString CreateString (const wxString &filename, double size, wxFontEncoding encoding, int weight)
 create a unique string presenting a a2dFONT_FREETYPE type font (see constructor for parameters)
 
static wxString CreateString (const wxString &filename, double size, bool monoSpaced, double weight)
 create a unique string presenting a a2dFONT_STROKED type font (see constructor for parameters)
 
static wxString CreateString (a2dFontType type, const wxFont &font, double size, wxFontEncoding encoding)
 create a unique string presenting a a2dFONT_WXDC type font (see constructor for parameters)
 
static void SetLoadFlags (wxInt32 loadMethodMask)
 

Friends

bool operator== (const a2dFont &a, const a2dFont &b)
 return true if the same font (same reference)
 
bool operator!= (const a2dFont &a, const a2dFont &b)
 return true if not the same font (same reference)
 

Detailed Description

Defines a font to be set to a2dDrawer2D or stored in a2dCanvsObject etc.

There are 3 types of fonts as in a2dFontType. The a2dDrawer2D classes know how to draw strings with these fonts.

Definition at line 779 of file stylebase.h.

Constructor & Destructor Documentation

a2dFont::a2dFont ( const wxFont &  font,
double  size,
a2dFontType  type = a2dFONT_WXDC,
wxFontEncoding  encoding = wxFONTENCODING_DEFAULT 
)

Constructor.

This constructor tries to locate the font file, belonging to the wxFont class, which is then used for drawing. At present only a Windows version is implemented.

Parameters
fontFont format. The size of the font is not used and should be set using the next parameter.
sizeSize in world coordinates.
encodingendocing of font

Definition at line 2814 of file stylebase.cpp.

a2dFont::a2dFont ( double  size,
int  family,
int  style = wxNORMAL,
int  weight = wxNORMAL,
const bool  underline = false,
const wxString &  faceName = wxT( "" ),
wxFontEncoding  encoding = wxFONTENCODING_DEFAULT 
)

Constructor.

Creates a font object (see font encoding overview, in the wxWidgets documentation, for the meaning of the last parameter).

Parameters
sizeSize in world coordinates.
familyFont family, a generic way of referring to fonts without specifying actual facename. One of:
  • wxDEFAULT Chooses a default font.
  • wxDECORATIVE A decorative font.
  • wxROMAN A formal, serif font.
  • wxSCRIPT A handwriting font.
  • wxSWISS A sans-serif font.
  • wxMODERN A fixed pitch font.
styleOne of wxNORMAL, wxSLANT and wxITALIC.
weightOne of wxNORMAL, wxLIGHT and wxBOLD.
underlineThe value can be true or false. At present this has an effect on Windows and Motif 2.x only.
faceNameAn optional string specifying the actual typeface to be used. If the empty string, a default typeface will chosen based on the family.
encodingAn encoding which may be one of
  • wxFONTENCODING_SYSTEM Default system encoding.
  • wxFONTENCODING_DEFAULT Default application encoding.
  • wxFONTENCODING_ISO8859_1...15 ISO8859 encodings.
  • wxFONTENCODING_KOI8 The standard Russian encoding for Internet.
  • wxFONTENCODING_CP1250...1252 Windows encodings similar to ISO8859 (but not identical).

If the specified encoding isn't available, no font is created.

wxFONTENCODING_DEFAULT is the encoding set by calls to SetDefaultEncoding and which may be set to, say, KOI8 to create all fonts by default with KOI8 encoding. Initially, the default application encoding is the same as default system encoding.

Remarks
  • If the desired font does not exist, the closest match will be chosen.
  • Under Windows, only scalable TrueType fonts are used.

Definition at line 2844 of file stylebase.cpp.

Member Function Documentation

a2dFont a2dFont::CreateFont ( const a2dFontInfo info,
bool  force = false 
)
static

Create the font from a fontinfo description.

The a2dFont::CreateFont will allways return a valid font. The derived fonts should return NULL.

This routine will first try to find the exact font, as described in the fontinfo. If it does not find this font, it will try to create any font of any font type, that matches part of the string. eg. if a user asks for a dc-font called "Arial Black" and this is not installed on the system, this routine might return as a replacement a freetype-font called "Arial".

Parameters
infofont info for creating font
forceThis param does not have a function in a2dFont, but it should be used in its descendants. When force is false, only the exact match should be made. When true, the routine should try to match any likely candidate.

Definition at line 3163 of file stylebase.cpp.

wxString a2dFont::CreateString ( )

Create a string description of the font.

Returns
A string of the format type-name-style-size-alignment(-extra)

Definition at line 2887 of file stylebase.cpp.

double a2dFont::GetDescent ( ) const

Get descent.

The descent is the distance from the basline to the bottom of the bounding box.

Returns
The descent in world coordinates.

Definition at line 3101 of file stylebase.cpp.

wxString a2dFont::GetFilename ( bool  filenameonly = false) const

Get the font filename.

Parameters
filenameonlyThe returned filename will be stripped of drive-letters and directories.
Returns
The filename of the font.

Definition at line 3269 of file stylebase.cpp.

a2dStrokeGlyph a2dFont::GetGlyphStroke ( wxChar  c) const

Get the glyph of a single character.

Returns
The glyph of the character, in a coordinate space, normalized to the font size.

Definition at line 2944 of file stylebase.cpp.

void a2dFont::GetInfoList ( a2dFontInfoList list)
static

Append fonts of this type to the list.

Using a2dFont::GetInfoList(list), will enumerate all fonts, of all types

Definition at line 3156 of file stylebase.cpp.

double a2dFont::GetKerning ( wxChar  c1,
wxChar  c2 
) const

Get kerning space between two characters.

Kerning is a method, which moves characters closer together/further apart, to improve the look of the font. Eg. the letter combination LT will be moved closer together. The return value is negative or positive, to respectively move characters closer together, or further apart.

Definition at line 2924 of file stylebase.cpp.

double a2dFont::GetLineHeight ( ) const

Get the line height.

The line height is calculated from the text bounding box.

Returns
The line height in world coordinates.

Definition at line 3096 of file stylebase.cpp.

double a2dFont::GetSize ( ) const

Get the font size.

Returns
The font size in world coordinates

Definition at line 2917 of file stylebase.cpp.

double a2dFont::GetStrokeWidth ( ) const

Get stroke width.

Returns
The stroke width in world coordinates. In case of a pixel font, 0.0 is returned.
See Also
GetWeight()

Definition at line 2931 of file stylebase.cpp.

a2dBoundingBox a2dFont::GetTextExtent ( const wxString &  string,
int  alignment = wxMINX | wxMINY,
double *  w = NULL,
double *  h = NULL,
double *  descent = NULL,
double *  externalLeading = NULL 
) const

Get the dimensions in world coordinates of the string.

Parameters
stringThe text string to measure (should be a single line of text).
alignmentAlignment of the text (eg. wxLEFT)
wTotal width in world coordinates.
hTotal height in world coordinates.
descentThe dimension from the baseline of the font to the bottom of the descender in world coordinates.
externalLeadingAny extra vertical space added to the font by the font designer in world coordinates (usually is zero).
Returns
A bounding box, with the anchor point positioned at (0, 0).

Definition at line 3044 of file stylebase.cpp.

void a2dFont::GetTextExtent ( const wxString &  string,
double &  w,
double &  h,
double &  descent,
double &  externalLeading 
) const

Get the dimensions in world coordinates of the string.

Parameters
stringThe text string to measure (should be a single line of text).
wTotal width in world coordinates.
hTotal height in world coordinates.
descentThe dimension from the baseline of the font to the bottom of the descender in world coordinates.
externalLeadingAny extra vertical space added to the font by the font designer in world coordinates (usually is zero).

Definition at line 3079 of file stylebase.cpp.

void a2dFont::GetTextExtentWH ( const wxString &  string,
double &  w,
double &  h 
) const

Get the dimensions in world coordinates of the string.

Parameters
stringThe text string to measure (should be a single line of text).
wTotal width in world coordinates.
hTotal height in world coordinates.

Definition at line 3085 of file stylebase.cpp.

bool a2dFont::GetVpath ( wxChar  c,
a2dVpath glyph,
const a2dAffineMatrix affine = a2dIDENTITY_MATRIX 
)

Get the glyph of a single character as a vpath.

The position, indicated by x and y, is the lowerleft bbox corner of the glyph.

Parameters
cThe character.
glyphA vectorpath, to which the glyph is added.
affinePosition etc., where the glyph is constructed.
Returns
A boolean, indicating if the glyph was succesfully added.

Definition at line 3111 of file stylebase.cpp.

void a2dFont::GetVpath ( const wxString &  text,
a2dVpath vpath,
double  x = 0,
double  y = 0,
int  alignment = wxMINX | wxMINY,
bool  yaxis = true,
const a2dAffineMatrix affine = a2dIDENTITY_MATRIX 
)

Render a text string into a vector path.

The position, indicated by x and y, is the lowerleft bbox corner of the text.

Parameters
textThe string to render.
vpathThe vectorpath, to which the string is rendered
xPosition, where the string is constructed.
yPosition, where the string is constructed.
alignmenthow to position text relative top position
yaxisup or down text
affinePosition etc., where the text is constructed.

Definition at line 3116 of file stylebase.cpp.

double a2dFont::GetWeight ( ) const

Get the weight of the font.

Returns
The weight (in this case stroke width) in percentages of the font size. There are two exceptions. 0: Draws the font with a pen of 1 pixel wide. -1: Draws the font with a normalized pen, as the font-designer intended it.

Definition at line 3283 of file stylebase.cpp.

bool a2dFont::Ok ( ) const

Check font validity.

Returns
True if this object is a valid font, false otherwise.

Definition at line 2894 of file stylebase.cpp.

void a2dFont::SetFilename ( const wxString &  filename)

Set the font filename and load the font.

Parameters
filenameThe filename of the font. This may either be a full path, or just the fontname. In the latter case, the fontpath of a2dGlobals will be used to search the font.
See Also
a2dGlobal

Definition at line 3253 of file stylebase.cpp.

void a2dFont::SetLoadFlags ( wxInt32  loadMethodMask)
static

Set the way glyphs are loaded by freetype. Important for small fonts. a2d_LOAD_DEFAULT; a2d_LOAD_DEFAULT | a2d_LOAD_NO_HINTING; a2d_LOAD_DEFAULT | a2d_LOAD_FORCE_AUTOHINT;

Definition at line 3247 of file stylebase.cpp.

void a2dFont::SetSize ( double  size)

Set the font size.

Parameters
sizeFont size in world coordinates.

Definition at line 2909 of file stylebase.cpp.

void a2dFont::SetWeight ( double  weight)

Set the weight of the font.

Parameters
weightThe weight (in this case stroke width) in percentages of the font size. There are two exceptions. 0: Draws the font with a pen of 1 pixel wide. -1: Draws the font with a normalized pen, as the font-designer intended it.

Definition at line 3295 of file stylebase.cpp.

void a2dFont::SetWeight ( const wxString &  weight)

Set the weight of the font, from a string.

Parameters
weightOne of: "Normalized Pen", "Pixel pen" or a string starting with the width in percentages, ending with %.

Definition at line 3311 of file stylebase.cpp.


The documentation for this class was generated from the following files:
a2dFont Class Reference -- Sun Oct 12 2014 17:04:39 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation