⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch13.htm

📁 Visual C++ 的学习资料 Visual C++ 的学习资料
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>

<HEAD>
	
	<TITLE>Teach Yourself Visual C++&#174; 5 in 24 Hours -- Hour 13 -- Fonts</TITLE>
</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF">

<CENTER>
<H1><IMG SRC="../button/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"><BR>
<FONT COLOR="#000077">Teach Yourself Visual C++&#174; 5 in 24 Hours</FONT></H1>
</CENTER>
<CENTER>
<P><A HREF="../ch12/ch12.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"
ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch14/ch14.htm"><IMG
SRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"
BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"
HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> 
<HR>

</CENTER>
<CENTER>
<H1><FONT COLOR="#000077">- Hour 13 -<BR>
Fonts</FONT></H1>
</CENTER>
<P>Fonts define the symbols and characters used to display text in a Windows program.
In this hour, you will learn

<UL>
	<LI>The basic attributes that are available for fonts<BR>
	<BR>
	
	<LI>How to use the Common Font dialog box provided as part of Windows<BR>
	<BR>
	
	<LI>MFC class library support for creating and managing fonts
</UL>

<P>At the end of the hour is some sample code that extends the DCTest example to
show how fonts are used in a Windows program.
<H2><FONT COLOR="#000077"><B>What Are Fonts?</B></FONT></H2>
<P>Fonts are GDI objects, much like the pens and brushes discussed in Hour 12, &quot;Using
Pens and Brushes,&quot; and are used to define the characters used for output in
a Windows program. A collection of characters and other symbols that share the same
attributes is a <I>font</I>.


<BLOCKQUOTE>
	<P>
<HR>
<B> </B><FONT COLOR="#000077"><B>Just a Minute:</B></FONT><B> </B>Strictly speaking,
	fonts are not necessary for most programs written for Windows. A default font is
	selected into every device context automatically, and it can work just fine for most
	applications. However, almost every program can benefit from using fonts that have
	been selected to suit its specific needs. 
<HR>


</BLOCKQUOTE>

<P>In this hour you see some terms that are unique to programming with fonts.</P>
<P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>glyph</I> is an individual
character.</P>
<P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B><I>Font pitch</I> refers
to the width of individual characters; <I>fixed pitch</I> means that each character
has the same width; <I>variable pitch</I> means that some characters will be wider
than others.</P>
<P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>serif</I> is the small
cross at the ends of some characters. A font with a serif has short crosses at the
ends of lines making up the font; Times New Roman is such a <I>serif font</I>. A
font without serifs is often called a <I>sans-serif font</I>. Figure 13.1 shows examples
of a serif and a sans-serif font.</P>
<P><A NAME="01"></A><A HREF="01.htm"><B>Figure 13.1.</B></A> <BR>
<I>Serif and sans-serif fonts.</I></P>
<P>Fonts are maintained by Windows. Information about each currently installed font
is stored in a system table known as the <I>font table</I>.</P>
<P>There are three different types of fonts; each type has different capabilities:

<UL>
	<LI><I>Raster fonts</I> are created from bitmaps and are stored in resource files
	with an <TT>.FON</TT> extension. Each bitmap is created for a specific screen resolution
	and is used by Windows to map out exactly how the glyph will look when it is displayed.<BR>
	<BR>
	
	<LI><I>Vector fonts</I> consist of a series of endpoints that are connected together
	to create each glyph and also are found in files with an <TT>.FON</TT> extension.
	Unlike raster fonts, vector fonts are device independent, but they are the slowest
	of the three font types.<BR>
	<BR>
	
	<LI><I>TrueType</I> <I>fonts</I> are the most flexible of all Windows fonts. First
	introduced in Windows 3.1, TrueType fonts consist of line and curve information,
	as well as hints about each glyph. Each TrueType font is stored in two files: one
	with an <TT>.FOT</TT> extension, the other with a <TT>.TTF</TT> extension.
</UL>



<BLOCKQUOTE>
	<P>
<HR>
<B> </B><FONT COLOR="#000077"><B>Just a Minute:</B></FONT><B> </B>Scaleable fonts
	that can display italic, bold, or underlined text give a program an extra amount
	of usability. Most printers supported by Windows also allow TrueType fonts to be
	displayed on a printer exactly as they are on a video screen; this is an extra advantage
	because it greatly simplifies the work required for printing. 
<HR>


</BLOCKQUOTE>

<P>Fonts are also arranged into six families that define the general attributes of
the font. Fonts in the same family share similar strokes, serifs, and pitch. The
following are the six font families:

<UL>
	<LI><I>Decorative</I> specifies novelty fonts such as Old English.<BR>
	<BR>
	
	<LI><I>Dontcare</I> specifies a generic group of fonts; either the font family information
	doesn't exist or the font family is unimportant.<BR>
	<BR>
	
	<LI><I>Modern</I> specifies fonts that have fixed pitch and may or may not have serifs.
	Courier New is an example of a Modern font.<BR>
	<BR>
	
	<LI><I>Roman</I> specifies fonts that have variable pitch and have serifs, such as
	Times New Roman.<BR>
	<BR>
	
	<LI><I>Script</I> specifies fonts that are similar to handwriting.<BR>
	<BR>
	
	<LI><I>Swiss</I> specifies a font that is fixed pitch and doesn't have serifs, such
	as Arial.
</UL>

<H2><FONT COLOR="#000077"><B>Specifying Font Attributes</B></FONT></H2>
<P>Like other GDI objects, the easiest way to use a font is to use the MFC class
library. Like other GDI objects, fonts must be used with a device context, and they
are influenced by the current state of the device context, such as mapping mode and
color definitions. When you're working with text output, the <TT>CFont</TT> class
helps make using a font easy.</P>
<P>There are two basic ways to use a font in your program:

<UL>
	<LI>You can specify exactly what kind of font should be used.<BR>
	<BR>
	
	<LI>You can specify font general attributes and let Windows select a font for you.
</UL>

<P>In addition to the font families discussed earlier in this hour, you can use other
general attributes to specify a font. Many font attributes exist, mainly because
there are so many different ways to display characters in a program written for Windows.
Don't worry; after you've used fonts a few times, you'll be able to create fonts
with no trouble at all. Later in the hour you will build some examples to learn how
you can use these attributes.
<H3><FONT COLOR="#000077"><B>The Font Height and Width</B></FONT></H3>
<P>You can specify the height of the font using one of the following methods:

<UL>
	<LI>If a height greater than zero is specified, Windows tries to match the requested
	height with one of the available fonts, and the font is mapped using logical units.<BR>
	<BR>
	
	<LI>If a font height of zero is specified, a reasonable default font is used. In
	this case, &quot;reasonable&quot; is defined by Windows.<BR>
	<BR>
	
	<LI>If the specified height is a negative number, the font is mapped using hardware
	units. Windows searches for a font that matches the absolute value of the size provided.
</UL>

<P>Logical units normally are used for screen display, and physical units are normally
used for printing. In Hour 21, &quot;Printing,&quot; you use <TT>MM_TWIPS</TT> to
create fonts based on device units.


<BLOCKQUOTE>
	<P>
<HR>
<B> </B><FONT COLOR="#000077"><B>Just a Minute:</B></FONT><B> </B>The width of a
	font normally is set to zero, which tells Windows to select an appropriate default
	width. However, in some cases you might want to specify your own font width to display
	compressed or elongated text. 
<HR>


</BLOCKQUOTE>

<H3><FONT COLOR="#000077"><B>The Font Character Set</B></FONT></H3>
<P>Every font is made up of a large number of characters and other symbols that can
be displayed. The actual symbols that are contained in a font depend on the character
set supported by that font. These three character sets are available:

<UL>
	<LI><TT>ANSI_CHARSET</TT>: Used for most output when programming in Windows. This
	is the character set you're most likely to use. The symbol <TT>ANSI_CHARSET</TT>
	is defined as equal to zero, which makes it easy to use as a default parameter.<BR>
	<BR>
	
	<LI><TT>OEM_CHARSET</TT>: Used mainly for console-mode programs; it is almost identical
	to the ANSI character set. This character set is system dependent and can't be used
	reliably for every machine capable of running Windows. Some of the low- and high-numbered
	characters are different, but these are rarely used in Windows.<BR>
	<BR>
	
	<LI><TT>SYMBOL_CHARSET</TT>: Used to display symbols such as the ones used in math
	formulas.
</UL>

<H3><FONT COLOR="#000077"><B>Attributes that Affect Font Output</B></FONT></H3>
<P>Three parameters specify output attributes of the selected font: <I>output precision</I>,
<I>clipping precision</I>, and <I>output quality</I>.</P>
<P>Output precision is used to specify how closely the font returned by Windows must
match the requested font. A range of options is available, from allowing Windows
to select a reasonable match to requiring an exact match.

<UL>
	<LI><TT>OUT_DEFAULT_PRECIS</TT>: Used when Windows can choose a &quot;reasonable&quot;
	font. This is the option selected most often and is equivalent to using zero as a
	parameter.<BR>
	<BR>
	
	<LI><TT>OUT_STRING_PRECIS</TT>: Used to specify that the font chosen by Windows must
	match the requested font's size.<BR>
	<BR>
	
	<LI><TT>OUT_CHARACTER_PRECIS</TT>: Used to specify that the font must match all requested
	attributes except orientation and escapement, which are defined later in the section
	&quot;Other Font Attributes.&quot;<BR>
	<BR>
	
	<LI><TT>OUT_STROKE_PRECIS</TT>: Used to specify that the font chosen must exactly
	match the requested font.
</UL>

<P>Clipping precision is used to specify how characters are treated when they lie
on a clipping boundary. There are three options:

<UL>
	<LI><TT>CLIP_DEFAULT_PRECIS</TT>: Allows Windows to select a &quot;reasonable&quot;
	font. This is the option selected most often and is equal to zero.<BR>
	<BR>
	
	<LI><TT>CLIP_CHARACTER_PRECIS</TT>: Requires Windows to select a font that allows
	individual characters to be clipped if any part of the character lies outside the
	clipping region.<BR>
	<BR>
	
	<LI><TT>CLIP_STROKE_PRECIS</TT>: Requires Windows to choose a font that allows portions
	of an individual character to be clipped if a character falls on the clipping boundary.
</UL>

<P>The output quality of the font refers to the degree to which GDI routines must

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -