VC + + Programming fonts and text drawing

Source: Internet
Author: User

Font is the appearance of text display and printing, it includes the characters of words, style and size, and many other attributes. Appropriate choice of different fonts, can greatly enrich the external expression of the text. For example, some important words in the text with a thicker font display, can reflect the prominent, emphasis of the intention. Of course, text output can also use its formatting properties and display quality to optimize the effect of text display.

Font properties and font creation

There are a number of properties for the font, which mainly describes the three main attributes of typeface, style, and size.

The typeface is the specific pattern which the character writes and displays, for example, to the Chinese character, usually has the song body, the italics, The imitation, the blackbody, the official script as well as the young circle and so on many words. GDI + uses the FontFamily class to define the typeface, such as the following code:

Program code:

FontFamily FontFamily (L "Young Circle"); Define the word "Young circle"

Font style is mainly characterized by the weight and inclination of the font. GDI + provides users with some predefined font styles: Fontstyleregular (normal), Fontstylebold (bold), Fontstyleitalic (Italic), Fontstylebolditalic (Bold Italic), Fontstyleunderline (underline) and Fontstylestrikeout (strikethrough).

The font size is used to specify the size of the area that the character occupies, usually described as a character height. The font size can be measured in millimeters or inches, but for the sake of visualization, a unit called a point is often used, at a point of approximately 1/72 inches. For Chinese characters, also commonly used numbers to indicate the font size, the first word is the largest, followed by small first, one, small 一、二号, small two??, and so on, the smaller the size of the font. GDI + provides users with Unitdisplay (1/75 inches), unitpixel (pixels), unitpoint (dots), unitinch (inches), unitdocument (1/300 inches), Unitmillimeter (mm) and other font size units.

Using the font class in GDI +, you can create a font object directly from the constructor, such as the following code:

Program code:

Font font (&fontfamily, fontstyleregular, Unitpoint);

The first parameter of the constructor is used to specify the FontFamily class object pointer, and the second parameter is used to specify the size of the font, and its actual size depends on the size unit specified by the fourth parameter. The third parameter is used to specify the font style.

In order to be compatible with the original GDI font, the font constructor has another style:

Program code:

Font (HDC HDC, const logfontw* LOGFONT)

Where HDC is used to specify the device environment handle for a window, Logfon is a pointer to the LOGFONT (logical font) data structure.

Text output

The final output of text depends not only on the font of the text, but also on the color, alignment, character spacing, and so on. GDI + has only one output text function drawstring, its prototype is as follows:
Program code:

DrawString( const WCHAR* string, INT length, const Font* font,
const RectF& layoutRect, const StringFormat* stringFormat,
const Brush* brush );

DrawString( const WCHAR* string, INT length, const Font* font,
const PointF& origin, const Brush* brush );

DrawString( const WCHAR* string, INT length, const Font* font,
const PointF& origin, const StringFormat* stringFormat,
const Brush* brush);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.