home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>font - Create and inspect fonts.</TITLE>
- <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> font - Create and inspect fonts.</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- <LI><A HREF="#font description">FONT DESCRIPTION</A></LI>
- <LI><A HREF="#font metrics">FONT METRICS</A></LI>
- <LI><A HREF="#font options">FONT OPTIONS</A></LI>
- <LI><A HREF="#platformspecific issues">PLATFORM-SPECIFIC ISSUES</A></LI>
- <LI><A HREF="#compatibility with previous versions">COMPATIBILITY WITH PREVIOUS VERSIONS</A></LI>
- <LI><A HREF="#see also">SEE ALSO</A></LI>
- <LI><A HREF="#keywords">KEYWORDS</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>font - Create and inspect fonts.</P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <P> <EM>$widget</EM>-><STRONG>Font</STRONG>(<EM>option</EM>?, <EM>arg, arg, ...</EM>?)</P>
- <P> <EM>$font</EM>-><EM>Option</EM>?(<EM>arg, arg, ...</EM>)?</P>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>The <STRONG>Font</STRONG> method provides several facilities for dealing with
- fonts, such as defining named fonts and inspecting the actual attributes of
- a font. The command has several different forms, determined by the
- first argument. The following forms are currently supported:</P>
- <DL>
- <DT><STRONG><A NAME="item_actual"><EM>$font</EM>-><STRONG>actual</STRONG>(<EM>-option</EM>?)</A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_fontActual"><EM>$widget</EM>-><STRONG>fontActual</STRONG>(<EM>font</EM>?, <EM>-option</EM>?)</A></STRONG><BR>
- <DD>
- Returns information about the actual attributes that are obtained when
- <EM>font</EM> is used on <EM>$font</EM>'s display; the actual attributes obtained
- may differ from the attributes requested due to platform-dependant
- limitations, such as the availability of font families and pointsizes.
- <EM>font</EM> is a font description; see <A HREF="#font description">FONT DESCRIPTION</A> below. If
- <EM>option</EM> is specified, returns the value of that attribute; if it is
- omitted, the return value is a list of all the attributes and their values.
- See <A HREF="#font options">FONT OPTIONS</A> below for a list of the possible attributes.
- <P></P>
- <DT><STRONG><A NAME="item_configure"><EM>$font</EM>-><STRONG>configure</STRONG>(<EM>-option</EM>??=><EM>value</EM>, <EM>-option</EM>=><EM>value</EM>, ...?)</A></STRONG><BR>
- <DD>
- Query or modify the desired attributes for <EM>$font</EM>.
- If no <EM>-option</EM> is specified, returns a list describing
- all the options and their values for <EM>fontname</EM>. If a single <EM>-option</EM>
- is specified with no <EM>value</EM>, then returns the current value of that
- attribute. If one or more <EM>option-value</EM> pairs are specified,
- then the method modifies the given named font to have the given values; in
- this case, all widgets using that font will redisplay themselves using the
- new attributes for the font. See <A HREF="#font options">FONT OPTIONS</A> below for a list of the
- possible attributes.
- <P>Note: the above behaviour differs in detail to <STRONG>configure</STRONG> on widgets,
- images etc.</P>
- <P></P>
- <DT><STRONG><A NAME="item_Font"><EM>$font</EM> = <EM>$widget</EM>-><STRONG>Font</STRONG>(<EM>-option</EM>=><EM>value</EM>, ...>?)</A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_fontCreate"><EM>$font</EM> = <EM>$widget</EM>-><STRONG>fontCreate</STRONG>(?<EM>fontname</EM>??, <EM>-option</EM>=><EM>value</EM>, ...>?)</A></STRONG><BR>
- <DD>
- Creates a new font object and returns a reference to it.
- <EM>fontname</EM> specifies the name for the font; if it is omitted, then Tk generates
- a new name of the form <STRONG>font</STRONG><EM>x</EM>, where <EM>x</EM> is an integer. There may be any
- number of <EM>option-value</EM> pairs, which provide the desired attributes for
- the new named font. See <A HREF="#font options">FONT OPTIONS</A> below for a list of the possible
- attributes.
- <P>Note: the created font is <EM>not</EM> shared between widgets of different
- <A HREF="../../../site/lib/Tk/MainWindow.html">MainWindow</A>s.</P>
- <P></P>
- <DT><STRONG><A NAME="item_delete"><EM>$font</EM>-><STRONG>delete</STRONG></A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_fontDelete"><EM>$widget</EM>-><STRONG>fontDelete</STRONG>(<EM>fontname</EM>?, <EM>fontname</EM>, ...?)</A></STRONG><BR>
- <DD>
- Delete the specified named fonts. If there are widgets using the named font,
- the named font won't actually be deleted until all the instances are
- released. Those widgets will continue to display using the last known values
- for the named font. If a deleted named font is subsequently recreated with
- another call to <STRONG>fontCreate</STRONG>, the widgets will use the new named font
- and redisplay themselves using the new attributes of that font.
- <P></P>
- <DT><STRONG><A NAME="item_fontFamilies"><EM>$widget</EM>-><STRONG>fontFamilies</STRONG></A></STRONG><BR>
- <DD>
- The return value is a list of the case-insensitive names of all font families
- that exist on <EM>$widget</EM>'s display.
- <P></P>
- <DT><STRONG><A NAME="item_measure"><EM>$font</EM>-><STRONG>measure</STRONG>(<EM>text</EM>)</A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_fontMeasure"><EM>$widget</EM>-><STRONG>fontMeasure</STRONG>(<EM>font</EM>, <EM>text</EM>)</A></STRONG><BR>
- <DD>
- Measures the amount of space the string <EM>text</EM> would use in the given
- <EM>font</EM> when displayed in <EM>$widget</EM>. <EM>font</EM> is a font description;
- see <A HREF="#font description">FONT DESCRIPTION</A> below.
- The return value is the total width in pixels
- of <EM>text</EM>, not including the extra pixels used by highly exagerrated
- characters such as cursive ``<EM>f</EM>''. If the string contains newlines or tabs,
- those characters are not expanded or treated specially when measuring the
- string.
- <P></P>
- <DT><STRONG><A NAME="item_metrics"><EM>$font</EM>-><STRONG>metrics</STRONG>(<EM>-option</EM>?)</A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_fontMetrics"><EM>$widget</EM>-><STRONG>fontMetrics</STRONG>(<EM>font</EM>?, <EM>-option</EM>?)</A></STRONG><BR>
- <DD>
- Returns information about the metrics (the font-specific data), for
- <EM>font</EM> when it is used on <EM>$widget</EM>'s display. <EM>font</EM> is a font
- description; see <A HREF="#font description">FONT DESCRIPTION</A> below.
- If <EM>option</EM> is specified,
- returns the value of that metric; if it is omitted, the return value is a
- list of all the metrics and their values. See <A HREF="#font metrics">FONT METRICS</A> below for a list
- of the possible metrics.
- <P></P>
- <DT><STRONG><A NAME="item_fontNames"><EM>$widget</EM>-><STRONG>fontNames</STRONG></A></STRONG><BR>
- <DD>
- The return value is a list of all font objects that are currently defined for
- <EM>$widget</EM>'s MainWindow.
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="font description">FONT DESCRIPTION</A></H1>
- <P>The following formats are accepted as a font description anywhere
- <EM>font</EM> is specified as an argument above; these same forms are also
- permitted when specifying the <STRONG>-font</STRONG> option for widgets.</P>
- <DL>
- <DT><STRONG><A NAME="item_%5B1%5D_fontname">[1] <EM>fontname</EM></A></STRONG><BR>
- <DD>
- The name of a named font, created using the <STRONG>fontCreate</STRONG> method. When
- a widget uses a named font, it is guaranteed that this will never cause an
- error, as long as the named font exists, no matter what potentially invalid
- or meaningless set of attributes the named font has. If the named font
- cannot be displayed with exactly the specified attributes, some other close
- font will be substituted automatically.
- <P></P>
- <DT><STRONG><A NAME="item_%5B1a%5D_%24font">[1a] <EM>$font</EM></A></STRONG><BR>
- <DD>
- A font object created using the <STRONG>Font</STRONG> method. This is essentially the same
- as using a named font. The object is a reference to the name, and carries
- additional information e.g. which MainWindow it relates to in an manner peculiar
- to perl/Tk.
- <P></P>
- <DT><STRONG><A NAME="item_%5B3%5D_systemfont">[3] <EM>systemfont</EM></A></STRONG><BR>
- <DD>
- The platform-specific name of a font, interpreted by the graphics server.
- This also includes, under X, an XLFD (see <A HREF="#[4]">[4]</A>) for which a single ``<STRONG>*</STRONG>''
- character was used to elide more than one field in the middle of the
- name. See <A HREF="#platformspecific issues">PLATFORM-SPECIFIC ISSUES</A> for a list of the system fonts.
- <P></P>
- <DT><STRONG><A NAME="item_%5B3%5D_%5Bfamily%2C%3Fsize%2C%3F%3Fstyle%2C%3F%3F">[3] [<EM>family</EM>,?<EM>size</EM>,??<EM>style</EM>,??<EM>style ...</EM>?]</A></STRONG><BR>
- <DD>
- A properly formed list whose first element is the desired font
- <EM>family</EM> and whose optional second element is the desired <EM>size</EM>.
- The interpretation of the <EM>size</EM> attribute follows the same rules
- described for <A HREF="#size">-size</A> in <A HREF="#font options">FONT OPTIONS</A> below. Any additional optional
- arguments following the <EM>size</EM> are font <EM>style</EM>s. Possible values
- for the <EM>style</EM> arguments are as follows:
- <PRE>
- normal bold roman italic
- underline overstrike</PRE>
- <P></P>
- <DT><STRONG><A NAME="item_names">[4] X-font names (XLFD)</A></STRONG><BR>
- <DD>
- A Unix-centric font name of the form
- <EM>-foundry-family-weight-slant-setwidth-addstyle-pixel-point-resx-resy-spacing-width-charset-encoding</EM>.
- The ``<STRONG>*</STRONG>'' character may be used to skip individual fields that the
- user does not care about. There must be exactly one ``<STRONG>*</STRONG>'' for each
- field skipped, except that a ``<STRONG>*</STRONG>'' at the end of the XLFD skips any
- remaining fields; the shortest valid XLFD is simply ``<STRONG>*</STRONG>'', signifying
- all fields as defaults. Any fields that were skipped are given default
- values. For compatibility, an XLFD always chooses a font of the specified
- pixel size (not point size); although this interpretation is not strictly
- correct, all existing applications using XLFDs assumed that one ``point''
- was in fact one pixel and would display incorrectly (generally larger) if
- the correct size font were actually used.
- <P></P>
- <DT><STRONG><A NAME="item_%5B5%5D_option_value_%3Foption_value_%2E%2E%2E%3F">[5] <EM>option value </EM>?<EM>option value ...</EM>?</A></STRONG><BR>
- <DD>
- A properly formed list of <EM>option-value</EM> pairs that specify
- the desired attributes of the font, in the same format used when defining
- a named font; see <A HREF="#font options">FONT OPTIONS</A> below.
- <P></P></DL>
- <P>When font description <EM>font</EM> is used, the system attempts to parse the
- description according to each of the above five rules, in the order specified.
- Cases [1] and [2] must match the name of an existing named font or of a
- system font. Cases [3], [4], and [5] are accepted on all
- platforms and the closest available font will be used. In some situations
- it may not be possible to find any close font (e.g., the font family was
- a garbage value); in that case, some system-dependant default font is
- chosen. If the font description does not match any of the above patterns,
- an error is generated.</P>
- <P>
- <HR>
- <H1><A NAME="font metrics">FONT METRICS</A></H1>
- <P>The following options are used by the <STRONG>metrics</STRONG>/<STRONG>fontMetrics</STRONG> method to query
- font-specific data determined when the font was created. These properties are
- for the whole font itself and not for individual characters drawn in that
- font. In the following definitions, the ``baseline'' of a font is the
- horizontal line where the bottom of most letters line up; certain letters,
- such as lower-case ``g'' stick below the baseline.</P>
- <DL>
- <DT><STRONG><A NAME="item_%2Dascent"><STRONG>-ascent</STRONG></A></STRONG><BR>
- <DD>
- The amount in pixels that the tallest letter sticks up above the baseline of
- the font, plus any extra blank space added by the designer of the font.
- (<EM>$font</EM>-<gt><STRONG>ascent</STRONG> is provided for compatibility.)
- <P></P>
- <DT><STRONG><A NAME="item_%2Ddescent"><STRONG>-descent</STRONG></A></STRONG><BR>
- <DD>
- The largest amount in pixels that any letter sticks down below the baseline
- of the font, plus any extra blank space added by the designer of the font.
- (<EM>$font</EM>-<gt><STRONG>descent</STRONG> is provided for compatibility.)
- <P></P>
- <DT><STRONG><A NAME="item_%2Dlinespace"><STRONG>-linespace</STRONG></A></STRONG><BR>
- <DD>
- Returns how far apart vertically in pixels two lines of text using the same
- font should be placed so that none of the characters in one line overlap any
- of the characters in the other line. This is generally the sum of the ascent
- above the baseline line plus the descent below the baseline.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dfixed"><STRONG>-fixed</STRONG></A></STRONG><BR>
- <DD>
- Returns a boolean flag that is ``<STRONG>1</STRONG>'' if this is a fixed-width font,
- where each normal character is the the same width as all the other
- characters, or is ``<STRONG>0</STRONG>'' if this is a proportionally-spaced font, where
- individual characters have different widths. The widths of control
- characters, tab characters, and other non-printing characters are not
- included when calculating this value.
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="font options">FONT OPTIONS</A></H1>
- <P>The following options are supported on all platforms, and are used when
- constructing a named font or when specifying a font using style [5] as
- above:</P>
- <DL>
- <DT><STRONG><A NAME="item_%2Dfamily_%3D%3E_name"><STRONG>-family</STRONG> => <EM>name</EM></A></STRONG><BR>
- <DD>
- The case-insensitive font family name. Tk guarantees to support the font
- families named <STRONG>Courier</STRONG> (a monospaced ``typewriter'' font), <STRONG>Times</STRONG>
- (a serifed ``newspaper'' font), and <STRONG>Helvetica</STRONG> (a sans-serif
- ``European'' font). The most closely matching native font family will
- automatically be substituted when one of the above font families is used.
- The <EM>name</EM> may also be the name of a native, platform-specific font
- family; in that case it will work as desired on one platform but may not
- display correctly on other platforms. If the family is unspecified or
- unrecognized, a platform-specific default font will be chosen.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dsize_%3D%3E_size"><STRONG>-size</STRONG> => <EM>size</EM></A></STRONG><BR>
- <DD>
- The desired size of the font. If the <EM>size</EM> argument is a positive
- number, it is interpreted as a size in points. If <EM>size</EM> is a negative
- number, its absolute value is interpreted as a size in pixels. If a
- font cannot be displayed at the specified size, a nearby size will be
- chosen. If <EM>size</EM> is unspecified or zero, a platform-dependent default
- size will be chosen.
-
- <PRE>
-
- The original Tcl/Tk authors believe sizes should normally be specified in points
- so the application will remain the same ruler size on the screen, even when
- changing screen resolutions or moving scripts across platforms. While this is an
- admirable goal it does not work as well in practice as they hoped.
- The mapping between points and pixels is set when the application starts, based
- on alleged properties of the installed monitor, but it can be overridden by
- calling the L<scaling|Tk::Widget/scaling> command. However this can be
- problematic when system has no way of telling if (say) an 11" or 22" monitor is
- attached, also if it I<can> tell then some monitor sizes may result in poorer
- quality scaled fonts being used rather than a "tuned" bitmap font.
- In addition specifying pixels is useful in certain circumstances such as when a piece of text
- must line up with respect to a fixed-size bitmap.</PRE>
- <P>At present the Tcl/Tk scheme is used unchanged, with ``point'' size being returned
- by <EM>actual</EM> (as an integer), and used internally. Suggestions for work-rounds
- to undesirable behaviour welcome.</P>
- <P></P>
- <DT><STRONG><A NAME="item_%2Dweight_%3D%3E_weight"><STRONG>-weight</STRONG> => <EM>weight</EM></A></STRONG><BR>
- <DD>
- The nominal thickness of the characters in the font. The value
- <STRONG>normal</STRONG> specifies a normal weight font, while <STRONG>bold</STRONG> specifies a
- bold font. The closest available weight to the one specified will
- be chosen. The default weight is <STRONG>normal</STRONG>.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dslant_%3D%3E_slant"><STRONG>-slant</STRONG> => <EM>slant</EM></A></STRONG><BR>
- <DD>
- The amount the characters in the font are slanted away from the
- vertical. Valid values for slant are <STRONG>roman</STRONG> and <STRONG>italic</STRONG>.
- A roman font is the normal, upright appearance of a font, while
- an italic font is one that is tilted some number of degrees from upright.
- The closest available slant to the one specified will be chosen.
- The default slant is <STRONG>roman</STRONG>.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dunderline_%3D%3E_boolean"><STRONG>-underline</STRONG> => <EM>boolean</EM></A></STRONG><BR>
- <DD>
- The value is a boolean flag that specifies whether characters in this
- font should be underlined. The default value for underline is <STRONG>false</STRONG>.
- <P></P>
- <DT><STRONG><A NAME="item_%2Doverstrike_%3D%3E_boolean"><STRONG>-overstrike</STRONG> => <EM>boolean</EM></A></STRONG><BR>
- <DD>
- The value is a boolean flag that specifies whether a horizontal line should
- be drawn through the middle of characters in this font. The default value
- for overstrike is <STRONG>false</STRONG>.
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="platformspecific issues">PLATFORM-SPECIFIC ISSUES</A></H1>
- <P>The following named system fonts are supported:</P>
- <DL>
- <DT><STRONG><A NAME="item_X_Windows%3A">X Windows:</A></STRONG><BR>
- <DD>
- All valid X font names, including those listed by xlsfonts(1), are available.
- <P></P>
- <DT><STRONG><A NAME="item_MS_Windows%3A">MS Windows:</A></STRONG><BR>
- <DD>
- <PRE>
- system ansi device
- systemfixed ansifixed oemfixed</PRE>
- <DT><STRONG><A NAME="item_Macintosh%3A">Macintosh:</A></STRONG><BR>
- <DD>
- <PRE>
- system application</PRE>
- </DL>
- <P>
- <HR>
- <H1><A NAME="compatibility with previous versions">COMPATIBILITY WITH PREVIOUS VERSIONS</A></H1>
- <P>In prior versions of perl/Tk the <EM>$widget</EM>-><STRONG>Font</STRONG> method was a perl
- wrapper on the original ``[4] X-font names (XLFD)'' style as described above
- (which was the only form supported by versions of core tk prior to version
- tk8.0).
- This module is provided in its original form (it has just been renamed)
- via:</P>
- <PRE>
- use Tk::X11Font;
- I<$widget>-E<gt>B<X11Font>(...)</PRE>
- <P>However the methods of the old scheme have been mimiced as closely as possible
- with the new scheme. It is intended that code should work without modification,
- except for the case of using :</P>
- <PRE>
- @names = $font->Name;</PRE>
- <P>i.e. the <EM>Name</EM> method in an array/list context. This now returns one element
- on all platforms (as it did on Win32), while previously on X systems it returned
- a list of fonts that matched an under-specified pattern.</P>
- <P>Briefly the methods supported for compatibilty are as follows:</P>
- <DL>
- <DT><STRONG><A NAME="item_Clone">$newfont = <EM>$font</EM>-><STRONG>Clone</STRONG>(<EM>-option</EM>=><EM>value</EM>, ...>?)</A></STRONG><BR>
- <DD>
- Returns a new font object <EM>$newfont</EM> related to the original <EM>$font</EM> by
- changing the values of the specified <EM>-option</EM>s.
- <P></P>
- <DT><STRONG><A NAME="item_Family"><EM>$font</EM>->Family - maps to -family</A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_Weight"><EM>$font</EM>->Weight - maps to -weight</A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_Slant"><EM>$font</EM>->Slant - maps to -slant</A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_Pixel"><EM>$font</EM>->Pixel and Point - map to -size</A></STRONG><BR>
- <DD>
- </DL>
- <P>New code should use <EM>$font</EM>-><STRONG>configure</STRONG> to achieve same effect as last
- four items above.</P>
- <DL>
- <DT><STRONG><A NAME="item_Foundry%2C_Swidth%2C_Adstyle%2C_Xres%2C_Yres%2C_Sp">Foundry, Swidth, Adstyle, Xres, Yres, Space, Avgwidth, Registry, Encoding</A></STRONG><BR>
- <DD>
- Are all ignored if set, and return '*' if queried.
- <P></P>
- <DT><STRONG><A NAME="item_Name"><EM>$font</EM>-><STRONG>Name</STRONG></A></STRONG><BR>
- <DD>
- Returns the name of a named font, or a string representation of an unnamed
- font. Using <EM>$font</EM> in a scalar context does the same. Note this is distinctly
- different from behaviour of <A HREF="../../../site/lib/Tk/X11Font.html#name( [ $max ] )">X11Font's Name</A> in
- a list context.
- <P></P>
- <DT><STRONG><A NAME="item_Pattern"><EM>$font</EM>-><STRONG>Pattern</STRONG></A></STRONG><BR>
- <DD>
- Returns a XLFD string for the font based on <EM>actual</EM> values, and some heuristics
- to map Tk's forms to the ``standard'' X conventions.
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="see also">SEE ALSO</A></H1>
- <P><A HREF="../../../site/lib/Tk/options.html">Tk::options</A></P>
- <P><A HREF="../../../site/lib/Tk/X11Font.html">Tk::X11Font</A></P>
- <P>
- <HR>
- <H1><A NAME="keywords">KEYWORDS</A></H1>
- <P>font</P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> font - Create and inspect fonts.</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-