The V C++ GUI Framework:vFont

From EDM2
Jump to: navigation, search

Various screen fonts are available in V.

Synopsis

Class:
vFont
Header:
[vquickr.htm#vFont <v/vfont.h>]

Description

Fonts are difficult to make portable. V has adopted a font model that is somewhat portable, yet allows you to take advantage of various fonts available on different platforms. In fact, it is possible to write your programs to use the [vfontsel.htm vFontSelect] dialog class, and pretty much ignore many of the details of selecting fonts. The main characteristics of fonts your program will have to deal with are the height and width of text displayed on a canvas. These values are provided by vDC::TextHeight and vDC::TextWidth. Use these values to calculate how much space a text string will take up on the screen or page.

Fonts are associated with drawing canvases. For example, the vCanvasPane::SetFont method is used to set the font used by the canvas pane. The sizes of the actual fonts will probably differ on different kinds of canvases. Specifically, your program should not depend on getting the same TextWidth value for screen and printer canvases for the same font.

The class vFont is used to define font objects, and the characteristics of the font are set either by the class constructor when the font is instantiated, or by using the vFont :: SetFontValues method. The utility class vFontSelect can be used to interactively set font characteristics. The characteristics associated with a font are described in the following sections. Remember, however, that vFontSelect::FontSelect can be used to set these attributes.

Font Family

Each font belongs to a font family. There are eight font families defined by V with the vFontID attribute of the font object. Font families typically correspond to some typeface name such as Helvetica or Times Roman, but use more generic names. There are three system fonts, vfDefaultSystem, vfDefaultFixed, and vfDefaultVariable. These default fonts are defined by the specific platform. vfDefaultSystem will usually be a fixed space font, and is often settable by the user. On X, for example, the default system font can be changed by using a -fn fontname switch when starting the application. The vfDefaultSystem font will have fixed attributes, and will not be changeable by the program. The vfDefaultFixed (fixed spacing) and vfDefaultVariable (variable spacing) fonts are also system specified, but can usually have their attributes, such as size and weight changed.

V also supports five other font families. The vfSerif font is a seriffed font such as Times Roman. The vfSanSerif is a serifless font such as Swiss or Lucidia. Both of these are variable spaced fonts. The vfFixed is a fixed space font, often called Courier on the host platform. The vfDecorative font usually contains symbols or other drawing characters. It is not very portable across platforms. Finally, V supports a font family called vfOther. This is used when the system supports other fonts that are selectable via the vFontSelect dialog class. Windows supports a wide variety of fonts, while X does not support any additional fonts.

Font Style

V supports two kinds of font styles: vfNormal for normal fonts, and vfItalic for italic fonts.

Font Weight

V supports two kinds of font weights: vfNormal for normal weight fonts, and vfBold for boldface fonts.

Point Size

V supports a wide range of point size, usually ranging from 8 point to 40 or 72 point fonts. Not all point sizes are supported on each platform. How each point size maps to space on the screen or page also vary from platform to platform.

Underlining

You can also specify that a font is underlined.

Angled text

You can specify that a font is to be drawn at something other than horizontally, left to right. If you need a vertical font, for a graph perhaps, you can specify an angle in the font constructor. This means you must use one of V's standard fonts, and can't use the font select dialog. You also can't dynamically change the angle on the fly. If you need text at more than one angle, you need to create multiple instances of a vFont.

You specify the angle in degrees, with 0 representing standard horizontal text. Using 90 degrees gives vertical text, reading from bottom to top. Using 180 gives upside down horizontal text, and 270 gives vertical text, top to bottom. A simple example:

    vFont font90(vfSansSerif,10,vfNormal,vfNormal,0,90);
    myCanvas->SetFont(font90);
    myCanvas->DrawText(200,150,"Vertical Text");

The Windows version supports any arbitrary angle. The X version only supports 90, 180, and 270. Because X does not provide native support for non-horizontal text, the initial implementation of angled text (V Version 1.18) simulates angled text by drawing standard horizontal characters vertically or backwards. It doesn't look too bad, and is better than having to do it yourself. Real vertical text will probably be supported someday, and I will probably forget to remove this note when that happens, so go by the release notes.

Methods

vFont(vFontID fam = vfDefaultFixed, int size = 10, vFontID sty = vfNormal, vFontID wt = vfNormal, int und = 0, int angle = 0)

The constructor is used to declare a font with the specified family, size, style, weight, underline, and angle.

Assignment (=)

Changes the value of an existing font to the right hand side.

vFontID GetFamily()

Returns the family of the font object.

int GetPointSize()

Returns the point size of the font object.

vFontID GetStyle()

Returns the style of the font object.

vFontID GetWeight()

Returns the weight of the font object.

int GetUnderlined()

Returns the underline setting of the font object.

void SetFontValues(vFontID fam = vfDefaultFixed, int size = 10, vFontID sty = vfNormal, vFontID wt = vfNormal, int und = 0)

Changes the attributes of the font object. For example, the font selection dialog uses this method to change the font attributes. Note that you can't use this method to set font angles.