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

📄 125.html

📁 Tcl 语言的入门级图书
💻 HTML
字号:
<HTML><TITLE>Widget Characteristics: Fonts</TITLE><BODY BGCOLOR="#FFF0E0" VLINK="#0FBD0F" TEXT="#101000" LINK="#0F0FDD">
<A NAME="top"><H1>Fonts</H1></A>


<P>   Originally, Tcl adopted X Window's very flexible system for dealing with
fonts.  Tk's  font names are in <TT>X Logical Font Description</TT> format.
Here is a sample,

<DL><DD> <PRE>
-*-arial-bold-r-normal--*-*-*-*-*-*
</PRE> </DL>

<P>   I do not intend to describe the format in any detail but the variable
substitution in the following is illustrative of what you need to know:

<DL><DD> <PRE>
-*-$Family-$Weight-$Slant-normal--$Size-*-*-*-*-*-*-*
</PRE> </DL>

The variables have these meanings:

<P><DL>
<P> <DT><PRE>Family</PRE><DD>
<P>  This is what we normally think of as the name of the font.  Some
possible values are: courier, helvetica, and times.
<P> <DT><PRE>Weight</PRE><DD>
<P>  This describes how heavy the characters are.  Use it to achieve bold 
face.  Some possible values are: medium and bold.
<P> <DT><PRE>Slant</PRE><DD>
<P>  Are the characters up and down like normal or do they slant sideways like
italics.  Some possible values are: italics, oblique, and normal.
<P> <DT><PRE>Size</PRE><DD>
<P>  The size of the font as measured in points.
This size is the same measurement your word processor probably shows you.  Some
possible values are: 8, 10, 12, 14, 17, and 24.
<P>  </DL></P>

<P>  Widgets that deal with texts have a default font.  You override this font
with the <TT><NAME=#S12.5font>-font</A></TT> option followed by a font description in
the form explained above.

<P>  With version 8.0, Tk has a <TT><NAME=#G12.5font>font</A></TT> action family.  Once a font
has been created and named you can use the name as the value for a <TT>-font</TT>
option.

<P>  Create a font with one of these forms of the <TT><NAME=#Cfontcreate>font create</A></TT>
action.

<P><CENTER><TABLE BORDER><TR><TD><DL>
<DT><STRONG><PRE>font create <CITE>?OPTIONS?</CITE></PRE></STRONG><DD> Creates and names a new font with
the properties specified by <CITE>?OPTIONS</CITE>.  Returns the name of the
font.
<DT><STRONG><PRE>font create <CITE>NAME ?OPTIONS?</CITE></PRE></STRONG><DD> Creates a font named <CITE>NAME</CITE>
with the properties specified by <CITE>?OPTIONS</CITE>.  Returns <CITE>NAME</CITE>.
</DL></TD></TR></TABLE></CENTER></P>

Any options you do not specify will be given a default value.  Here
are some possible options.

<P><CENTER><TABLE BORDER><TR><TD><DL>
<P> <DT><STRONG><PRE><NAME=#S12.5familyfont>-family</A></PRE></STRONG><DD> Possible values are "Courier," "Times,"
and "Helvetica."
<P> <DT><STRONG><PRE><NAME=#S12.5sizefont>-size</A></PRE></STRONG><DD> A positive value is measured in points, a
negative value in pixels.  Tk will choose the closest available font to the
size you specify.
<P> <DT><STRONG><PRE><NAME=#S12.5weightfont>-weight</A></PRE></STRONG><DD> Possible values are "normal" and "bold."
<P> <DT><STRONG><PRE><NAME=#S12.5slantfont>-slant</A></PRE></STRONG><DD> Possible values are "roman" and "italic."
</DL></TD></TR></TABLE></CENTER></P>

<P> You cannot only use font names as the value of any <TT>-font</TT> option, but
you can also use an option/value list made up from the options expected by <TT>font
create</TT>.  Figure 12.5a shows two ways of creating the same label.

<P><CENTER><TABLE BORDER>
<CAPTION><ADDR>Figure 12.5a: Using the font Procedure of Exercise 12.5a.</ADDR></CAPTION>
<TR ALIGN=center><TD><IMG SRC="F12x5a.JPG" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Figs/F12x5a.JPG">
</TD></TR>
<TR><TD><PRE>pack [label .lbl1 -text {Hellow Orld} \
<P>                  -font {-family Times -slant italic -size 17 }]
font create LabelFont -family Times -slant italic -size 17
pack [label .lbl2 -text {Hellow Orld} -font LabelFont]
set LabelFont [font create  -family Times -slant italic -size 17]
pack  [label .lbl3 -text {Hellow Orld} -font $LabelFont] </PRE></TD></TR>
</TABLE></CENTER><P>

<P> <P><A NAME="12.5a">
<STRONG>Exercise 12.5a</STRONG> </A><DL><DD>
  Finish implementing this procedure which is useful
in Tk 4.2 or earlier.

<PRE>
proc font {Family Weight Slant Size} {
   ### Family: one of courier helvetica times
   ### Weight: one of b n  (for bold and normal)
   ### Slant:  one of i n  (for italics/oblique and normal)
   ### Size:   one of 8 10 12 14 17 24
   ### returns a font name usable on multiple platforms
...
}
</PRE>

<P> Note that both <TT>Weight</TT> and <TT>Slant</TT> take different values than
described above for X Windows fonts.  You will need to translate these values.
When translating the slant, map "i" to "italic" for the courier and helvetica
fonts and to "oblique" for the times font.  When translating the weight, map
"n" to "medium."

<P>  The solution to this exercise is available as Script ES12.5a.
<P>
<A HREF="12.8.html#Sol12.5a" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.8.html#Sol12.5a">Solution</A></DL>


<!-- Linkbar -->
<P><CENTER><FONT SIZE=2><NOBR>
<STRONG>From</STRONG>
<A HREF="javascript:if(confirm('http://www.mapfree.com/sbf/tcl/book/home.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.mapfree.com/sbf/tcl/book/home.html'" tppabs="http://www.mapfree.com/sbf/tcl/book/home.html">Tcl/Tk For Programmers</A><WBR>
<STRONG>Previous</STRONG>
<A HREF="12.4.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.4.html">section</A><WBR>
<STRONG>Next</STRONG>
<A HREF="12.6.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.6.html">section</A><WBR>
<STRONG>All</STRONG>
<A HREF="12.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.html">sections</A><WBR>
<STRONG>Author</STRONG>
<A HREF="javascript:if(confirm('http://www.mapfree.com/mp/jaz/home.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.mapfree.com/mp/jaz/home.html'" tppabs="http://www.mapfree.com/mp/jaz/home.html">J. A. Zimmer</A><WBR>
<STRONG>Copyright</STRONG>
<A HREF="copyright.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/copyright.html">Notice</A><WBR>
<P>
<I>Jun 17, 1998</I>
 </NOBR></FONT></CENTER></BODY></HTML>


⌨️ 快捷键说明

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