📄 sec-gdkfont.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html> <head> <title> Fonts </title> <meta name="GENERATOR" content= "Modular DocBook HTML Stylesheet Version 1.45"> <link rel="HOME" title="GTK+ / Gnome Application Development" href="ggad.html"> <link rel="UP" title="GDK Basics" href="cha-gdk.html"> <link rel="PREVIOUS" title="The Mouse Pointer" href= "sec-gdkcursor.html"> <link rel="NEXT" title="Graphics Contexts" href="sec-gc.html"> </head> <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink= "#840084" alink="#0000FF"> <div class="NAVHEADER"> <table width="100%" border="0" bgcolor="#ffffff" cellpadding= "1" cellspacing="0"> <tr> <th colspan="4" align="center"> <font color="#000000" size="2">GTK+ / Gnome Application Development</font> </th> </tr> <tr> <td width="25%" bgcolor="#ffffff" align="left"> <a href="sec-gdkcursor.html"><font color="#0000ff" size="2"><b><<< Previous</b></font></a> </td> <td width="25%" colspan="2" bgcolor="#ffffff" align= "center"> <font color="#0000ff" size="2"><b><a href="ggad.html"> <font color="#0000ff" size="2"><b> Home</b></font></a></b></font> </td> <td width="25%" bgcolor="#ffffff" align="right"> <a href="sec-gc.html"><font color="#0000ff" size="2"> <b>Next >>></b></font></a> </td> </tr> </table> </div> <div class="SECT1"> <h1 class="SECT1"> <a name="SEC-GDKFONT">Fonts</a> </h1> <p> An X font is (yet another) a server-side resource. In essence, a font is a collection of bitmaps representing characters. The bitmaps in a single font will have a similar size and style. GDK allows you to manipulate fonts with a client-side handle called <span class="STRUCTNAME"> GdkFont</span>. </p> <p> To obtain a <span class="STRUCTNAME">GdkFont</span>, call <tt class="FUNCTION">gdk_font_load()</tt> (or use the font from a preexisting <span class="STRUCTNAME"> GtkStyle</span>; more on this in <a href="sec-style.html"> the section called <i><span class="STRUCTNAME"> GtkStyle</span> and Themes</i></a>). Fonts are loaded by name; font names are a fairly involved topic. Names follow a convention called the "X Logical Font Description," or XLFD. The best way to get a feel for XLFD is to play with the <tt class="APPLICATION">xfontsel</tt> program that comes with X. You can also get a list of font names on your X server with the <tt class="APPLICATION">xlsfonts</tt> program. The standard X distribution includes a 30-page XLFD manual, but the basics aren't too complicated. </p> <p> A font name is a string made up of hyphen-separated fields. Each field describes some aspect of the font. For example: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> -misc-fixed-medium-r-normal--0-0-75-75-c-0-iso8859-1 </pre> </td> </tr> </table> <p> or </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> -adobe-new century schoolbook-bold-i-normal--11-80-100-100-p-66-iso8859-1 </pre> </td> </tr> </table> <p> The fourteen fields are: </p> <ul> <li> <p> Foundry: the vendor who created the font, such as Adobe or Sony. <span class="STRUCTNAME">misc</span> is used for some generic fonts that come with X. </p> </li> <li> <p> Family: the typeface or style of the font---Courier, Times, Helvetica, etc. </p> </li> <li> <p> Weight: Bold, demibold, medium, etc. </p> </li> <li> <p> Slant: Italic, Roman, Oblique (abbreviated as <span class="STRUCTNAME">i</span>, <span class="STRUCTNAME"> r</span>, or <span class="STRUCTNAME">o</span> </p> </li> <li> <p> Set Width: the "proportionate width" of the font; possible values include normal, condensed, semicondensed, etc. </p> </li> <li> <p> "Add Style": any additional information about the font can go in this field; it is used to distinguish two fonts that otherwise have the same name. There are no constraints on the string. </p> </li> <li> <p> Pixels: the pixel size of the font. </p> </li> <li> <p> Points: the point size of the font, in tenths of a point. A point is 1/72 of an inch; the relationship of point size to pixel size is determined by the resolution (dots per inch) the X server thinks the display has. Typically people do not configure their X server to match their monitor, so the X server's idea of the current resolution may be wildly inaccurate. </p> </li> <li> <p> Horizontal Resolution: horizontal display resolution in dots per inch (dpi) the font is designed for. </p> </li> <li> <p> Vertical Resolution: vertical display resolution the font is designed for. </p> </li> <li> <p> Spacing: Monospace (abbreviated <span class= "STRUCTNAME">m</span>) or proportional (abbreviated <span class="STRUCTNAME">p</span>). Indicates whether all characters have the same width or different characters may have different widths. </p> </li> <li> <p> Average Width: the mean width of all characters in the font, in tenths of a pixel. </p> </li> <li> <p> Character Set Registry: the organization or standard defining the character set. </p> </li> <li> <p> Character Set Encoding: specifies the specific character set encoding. These last two fields in combination specify the character set. For European languages <span class="STRUCTNAME">iso8859-1</span> will almost always be used. This is the "Latin-1" character set, which is an 8-bit encoding including ASCII as a subset. </p> </li> </ul> <p> It is not necessary to specify all 14 fields when requesting a font. "Wild cards" are allowed: <tt class= "APPLICATION">*</tt> matches any number of characters, and <tt class="APPLICATION">?</tt> matches a single character. For example, a 160 point Bold Roman Helvetica font can be requested like this: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> -*-helvetica-bold-r-*-*-*-160-*-*-*-*-*-* </pre> </td> </tr> </table> <p> When you pass a font name to <tt class="FUNCTION"> gdk_font_load()</tt>, you should consider it a default choice only. Users in other countries will certainly want to use a font appropriate to their language; US and European users might want to customize fonts too. Also, there are no fonts guaranteed to exist on all servers. Thus you should provide a way to customize any fonts you use. The easiest way is to use fonts from a widget's <span class="STRUCTNAME">GtkStyle</span> (again, see <a href= "sec-style.html">the section called <i><span class= "STRUCTNAME">GtkStyle</span> and Themes</i></a>). </p> <p> <tt class="FUNCTION">gdk_font_load()</tt> returns <span class="STRUCTNAME">NULL</span> if it fails to find a font matching the supplied name. When you are done with a font, you should release it by calling <tt class="FUNCTION"> gdk_font_unref()</tt>. <a href="sec-gdkfont.html#FL-FONTS"> Figure 10</a> summarizes these functions. </p> <p> When loading fonts, you will need to specify at least the font name, the weight, the slant, and a size---otherwise the <tt class="APPLICATION">*</tt> wildcards would probably load a random bold italic font, which is unlikely to be what you want. The <i class="EMPHASIS">Xlib Programming Manual</i> suggests that you always specify the font size in points, so that users with different monitors will get the right effect; however, X servers do not reliably know the display resolution, so this is more theory than reality. Perhaps it's better to specify pixels, because you do know the pixel size of other elements of your display. Neither is perfect; be sure you make your application's fonts configurable. </p> <div class="FIGURE"> <a name="FL-FONTS"></a> <div class="FUNCSYNOPSIS"> <a name="FL-FONTS.SYNOPSIS"></a> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="FUNCSYNOPSISINFO">#include <gdk/gdk.h></pre> </td> </tr> </table> <p> <code><code class="FUNCDEF">GdkFont* <tt class= "FUNCTION">gdk_font_load</tt></code>(const gchar* <tt class="PARAMETER"><i>font_name</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class="FUNCTION"> gdk_font_unref</tt></code>(GdkFont* <tt class= "PARAMETER"><i>font</i></tt>);</code> </p> </div> <p> <b>Figure 10. <span class="STRUCTNAME">GdkFont</span></b> </p> </div> <div class="SECT2"> <h2 class="SECT2"> <a name="Z131">Font Metrics</a>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -