Text Drawing
[Drawing Functions]


Functions

void column_widths (const int *i)
const int * column_widths ()
void drawtext (const char *, int length, const Rectangle &, Flags)
void fltk::drawtext (const char *, const Rectangle &, Flags)
void fltk::drawtext (const char *, int length, float x, float y)
void fltk::drawtext (const char *, float x, float y)
void fltk::drawtext_transformed (const char *, int n, float x, float y)
const char * fltk::get_encoding ()
float fltk::getascent ()
float fltk::getdescent ()
Font * fltk::getfont ()
float fltk::getsize ()
float fltk::getwidth (const char *, int length)
float fltk::getwidth (const char *)
void measure (const char *, int length, int &w, int &h, Flags)
void fltk::measure (const char *, int &w, int &h, Flags=0)
void fltk::set_encoding (const char *)
void setfont (const char *, int attributes, float size)
void setfont (const char *, float size)
void fltk::setfont (Font *, float size)

Variables

const int * column_widths_
Font * current_font_
float current_size_
const char * encoding_

Detailed Description

See the fltk::Font class for a description of what can be passed as a font. For most uses one of the built-in constant fonts like fltk::HELVETICA can be used.

Function Documentation

void setfont fltk::Font font,
float  psize
 

Set the current font and font scaling so the size is size pixels. The size is unaffected by the current transformation matrix (you may be able to use fltk::transform() to get the size to get a properly scaled font).

The size is given in pixels. Many pieces of software express sizes in "points" (for mysterious reasons, since everything else is measured in pixels!). To convert these point sizes to pixel sizes use the following code:

const fltk::Monitor& monitor = fltk::Monitor::all();
float pixels_per_point = monitor.dpi_y()/72.0;
float font_pixel_size = font_point_size*pixels_per_point;

const char * get_encoding  )  [inline]
 

Returns the string sent to the most recent set_encoding().

void set_encoding const char *  f  ) 
 

Obsolete function to encourage FLTK to choose a 256-glyph font with the given encoding. You must call setfont() after changing this for it to have any effect.

Notice that this is obsolete! Only the non-Xft X version actually uses it and that may be eliminated as well. In addition FLTK uses UTF-8 internally, and assummes that any font it prints with is using Unicode encoding (or ISO-8859-1 if there are only 256 characters).

The default is "iso10646-1"

Font * getfont  )  [inline]
 

Return the Font sent to the last setfont().

float getsize  )  [inline]
 

Return the size sent to the last setfont(). You should use this as a minimum line spacing (using ascent()+descent() will produce oddly spaced lines for many fonts).

float getwidth const char *  text  ) 
 

Return the width of a nul-terminated UTF-8 string drawn in the font set by the most recent setfont().

float getwidth const char *  text,
int  n
 

Return the width of the first n bytes of this UTF-8 string drawn in the font set by the most recent setfont().

float getascent  ) 
 

Return the distance from the baseline to the top of letters in the current font.

float getdescent  ) 
 

Return the distance from the baseline to the bottom of letters in the current font.

void drawtext_transformed const char *  text,
int  n,
float  x,
float  y
 

Draw text starting at a point returned by fltk::transform(). This is needed for complex text layout when the current transform may not match the transform being used by the font.

void drawtext const char *  text,
float  x,
float  y
 

Draw a nul-terminated string.

void drawtext const char *  text,
int  n,
float  x,
float  y
 

Draw the first n bytes (not characters if utf8 is used) starting at the given position.

void measure const char *  str,
int &  w,
int &  h,
Flags  flags = 0
 

Measure the size of box necessary for drawtext() to draw the given string inside of it. The flags are used to set the alignment, though this should not make a difference except for fltk::ALIGN_WRAP. To correctly measure wrap w must be preset to the width you want to wrap at if fltk::ALIGN_WRAP is on in the flags! w and h are changed to the size of the resulting box.

void drawtext const char *  str,
const Rectangle r1,
Flags  flags
 

This is the fancy string-drawing function that is used to draw all labels in fltk. The string is formatted and aligned inside the passed rectangle. This also:

  • Breaks the text into lines at \n characters. Word-wraps (if flags has fltk::ALIGN_WRAP set) so the words fit in the columns.
  • Looks up "@xyz;" sequeces to see if they are a Symbol, if so it prints that symbol instead. This is skipped if the flags has fltk::RAW_LABEL set.
  • Parses "&x" combinations to produce Microsoft style underscores, unless RAW_LABEL flag is set.
  • Splits it at every \t tab character and uses column_widths() to set each section into a column.


Sun May 8 21:48:57 2005. FLTK ©2004 Bill Spitzak and others. See Main Page for details.