GD::Text.3pm
上传用户:qdrechuli
上传日期:2022-08-01
资源大小:917k
文件大小:12k
- ." Automatically generated by Pod::Man version 1.15
- ." Tue Oct 8 11:46:52 2002
- ."
- ." Standard preamble:
- ." ======================================================================
- .de Sh " Subsection heading
- .br
- .if t .Sp
- .ne 5
- .PP
- fB\$1fR
- .PP
- ..
- .de Sp " Vertical space (when we can't use .PP)
- .if t .sp .5v
- .if n .sp
- ..
- .de Ip " List item
- .br
- .ie \n(.$>=3 .ne \$3
- .el .ne 3
- .IP "\$1" \$2
- ..
- .de Vb " Begin verbatim text
- .ft CW
- .nf
- .ne \$1
- ..
- .de Ve " End verbatim text
- .ft R
- .fi
- ..
- ." Set up some character translations and predefined strings. *(-- will
- ." give an unbreakable dash, *(PI will give pi, *(L" will give a left
- ." double quote, and *(R" will give a right double quote. | will give a
- ." real vertical bar. *(C+ will give a nicer C++. Capital omega is used
- ." to do unbreakable dashes and therefore won't be available. *(C` and
- ." *(C' expand to `' in nroff, nothing in troff, for use with C<>
- .tr (*W-|(bv*(Tr
- .ds C+ Cv'-.1v'h'-1p's-2+h'-1p'+s0v'.1v'h'-1p'
- .ie n {
- . ds -- (*W-
- . ds PI pi
- . if (n(.H=4u)&(1m=24u) .ds -- (*Wh'-12u'(*Wh'-12u'-" diablo 10 pitch
- . if (n(.H=4u)&(1m=20u) .ds -- (*Wh'-12u'(*Wh'-8u'-" diablo 12 pitch
- . ds L" ""
- . ds R" ""
- . ds C` ""
- . ds C' ""
- 'br}
- .el{
- . ds -- |(em|
- . ds PI (*p
- . ds L" ``
- . ds R" ''
- 'br}
- ."
- ." If the F register is turned on, we'll generate index entries on stderr
- ." for titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and
- ." index entries marked with X<> in POD. Of course, you'll have to process
- ." the output yourself in some meaningful fashion.
- .if nF {
- . de IX
- . tm Index:\$1t\n%t"\$2"
- ..
- . nr % 0
- . rr F
- .}
- ."
- ." For nroff, turn off justification. Always turn off hyphenation; it
- ." makes way too many mistakes in technical documents.
- .hy 0
- .if n .na
- ."
- ." Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
- ." Fear. Run. Save yourself. No user-serviceable parts.
- .bd B 3
- . " fudge factors for nroff and troff
- .if n {
- . ds #H 0
- . ds #V .8m
- . ds #F .3m
- . ds #[ f1
- . ds #] fP
- .}
- .if t {
- . ds #H ((1u-(\\n(.fu%2u))*.13m)
- . ds #V .6m
- . ds #F 0
- . ds #[ &
- . ds #] &
- .}
- . " simple accents for nroff and troff
- .if n {
- . ds ' &
- . ds ` &
- . ds ^ &
- . ds , &
- . ds ~ ~
- . ds /
- .}
- .if t {
- . ds ' \k:h'-(\n(.wu*8/10-*(#H)''h"|\n:u"
- . ds ` \k:h'-(\n(.wu*8/10-*(#H)'`h'|\n:u'
- . ds ^ \k:h'-(\n(.wu*10/11-*(#H)'^h'|\n:u'
- . ds , \k:h'-(\n(.wu*8/10)',h'|\n:u'
- . ds ~ \k:h'-(\n(.wu-*(#H-.1m)'~h'|\n:u'
- . ds / \k:h'-(\n(.wu*8/10-*(#H)'z(slh'|\n:u'
- .}
- . " troff and (daisy-wheel) nroff accents
- .ds : \k:h'-(\n(.wu*8/10-*(#H+.1m+*(#F)'v'-*(#V'z.h'.2m+*(#F'.h'|\n:u'v'*(#V'
- .ds 8 h'*(#H'(*bh'-*(#H'
- .ds o \k:h'-(\n(.wu+w'(de'u-*(#H)/2u'v'-.3n'*(#[z(dev'.3n'h'|\n:u'*(#]
- .ds d- h'*(#H'(pdh'-w'~'u'v'-.25m'f2(hyfPv'.25m'h'-*(#H'
- .ds D- D\k:h'-w'D'u'v'-.11m'z(hyv'.11m'h'|\n:u'
- .ds th *(#[v'.3m's+1Is-1v'-.3m'h'-(w'I'u*2/3)'s-1os+1*(#]
- .ds Th *(#[s+2Is-2h'-w'I'u*3/5'v'-.3m'ov'.3m'*(#]
- .ds ae ah'-(w'a'u*4/10)'e
- .ds Ae Ah'-(w'A'u*4/10)'E
- . " corrections for vroff
- .if v .ds ~ \k:h'-(\n(.wu*9/10-*(#H)'s-2u~ds+2h'|\n:u'
- .if v .ds ^ \k:h'-(\n(.wu*10/11-*(#H)'v'-.4m'^v'.4m'h'|\n:u'
- . " for low resolution devices (crt and lpr)
- .if n(.H>23 .if n(.V>19
- {
- . ds : e
- . ds 8 ss
- . ds o a
- . ds d- dh'-1'(ga
- . ds D- Dh'-1'(hy
- . ds th o'bp'
- . ds Th o'LP'
- . ds ae ae
- . ds Ae AE
- .}
- .rm #[ #] #H #V #F C
- ." ======================================================================
- ."
- .IX Title "Text 3"
- .TH Text 3 "perl v5.6.1" "2000-09-18" "User Contributed Perl Documentation"
- .UC
- .SH "NAME"
- &s-1GD:s0:Text - Text utilities for use with s-1GDs0
- .SH "SYNOPSIS"
- .IX Header "SYNOPSIS"
- .Vb 2
- & use GD;
- & use GD::Text;
- .Ve
- .Vb 7
- & my $gd_text = GD::Text->new() or die GD::Text::error();
- & $gd_text->set_font('funny.ttf', 12) or die $gd_text->error;
- & $gd_text->set_font(gdTinyFont);
- & $gd_text->set_font(GD::Font::Tiny);
- & ...
- & $gd_text->set_text($string);
- & my ($w, $h) = $gd_text->get('width', 'height');
- .Ve
- .Vb 4
- & if ($gd_text->is_ttf)
- & {
- & ...
- & }
- .Ve
- Or alternatively
- .PP
- .Vb 5
- & my $gd_text = GD::Text->new(
- & text => 'Some text',
- & font => 'funny.ttf',
- & ptsize => 14,
- & );
- .Ve
- .SH "DESCRIPTION"
- .IX Header "DESCRIPTION"
- This module provides a font-independent way of dealing with text in
- &s-1GDs0, for use with the s-1GD:s0:Text::* modules and s-1GD:s0:Graph.
- .SH "NOTES"
- .IX Header "NOTES"
- As with all Modules for Perl: Please stick to using the interface. If
- you try to fiddle too much with knowledge of the internals of this
- module, you could get burned. I may change them at any time.
- .PP
- You can only use TrueType fonts with version of s-1GDs0 > 1.20, and then
- only if compiled with support for this. If you attempt to do it
- anyway, you will get errors.
- .SH "METHODS"
- .IX Header "METHODS"
- .Sh "s-1GD:s0:Text->new( attrib => value, ... )"
- .IX Subsection "GD::Text->new( attrib => value, ... )"
- Create a new object. See the f(CW*(C`set()*(C'fR method for attributes.
- .Sh "s-1GD:\fIs0:Text::error()fP or f(CW$gd_textfP->fIerror()fP;"
- .IX Subsection "GD:f(ISs0:Text::error() or $gd_text->error();"
- Return the last error that occured in the class. This may be
- imperfect.
- .Sh "$gd_text->set_font( font, size )"
- .IX Subsection "$gd_text->set_font( font, size )"
- Set the font to use for this string. The arguments are either a s-1GDs0
- builtin font (like gdSmallFont or s-1GD:s0:Font->Small) or the name of a
- TrueType font file and the size of the font to use. See also
- the section on "font_path".
- .PP
- If you are not using an absolute path to the font file, you can leave of
- the .ttf file extension, but you have to append it for absolute paths:
- .PP
- .Vb 3
- & $gd_text->set_font('cetus', 12);
- & # but
- & $gd_text->set_font('/usr/fonts/cetus.ttf', 12);
- .Ve
- The first argument can be a reference to an array of fonts. The first
- font from the array that can be found will be used. This allows you to
- do something like
- .PP
- .Vb 3
- & $gd_text->font_path( '/usr/share/fonts:/usr/fonts');
- & $gd_text->set_font(
- & ['verdana', 'arial', gdMediumBoldFont], 14);
- .Ve
- if you'd prefer verdana to be used, would be satisfied with arial, but
- if none of that is available just want to make sure you can fall
- back on something that will be available.
- .PP
- Returns true on success, false on error.
- .Sh "$gd_text->set_text('some text')"
- .IX Subsection "$gd_text->set_text('some text')"
- Set the text to operate on.
- Returns true on success and false on error.
- .Sh "$gd_text->set( attrib => value, ... )"
- .IX Subsection "$gd_text->set( attrib => value, ... )"
- The set method provides a convenience replacement for the various other
- &f(CW*(C`set_xxx()*(C'fR methods. Valid attributes are:
- .Ip "text" 4
- .IX Item "text"
- The text to operate on, see also f(CW*(C`set_text()*(C'fR.
- .Ip "font, ptsize" 4
- .IX Item "font, ptsize"
- The font to use and the point size. The point size is only used for
- TrueType fonts. Also see f(CW*(C`set_font()*(C'fR.
- .PP
- Returns true on success, false on any error, even if it was partially
- successful. When an error is returned, no guarantees are given about
- the correctness of the attributes.
- .Sh "$gd_text->get( attrib, ... )"
- .IX Subsection "$gd_text->get( attrib, ... )"
- Get the value of an attribute.
- Return a list of the attribute values in list context, and the value of
- the first attribute in scalar context.
- .PP
- The attributes that can be retrieved are all the ones that can be set,
- and:
- .Ip "width, height" 4
- .IX Item "width, height"
- The width (height) of the string in pixels
- .Ip "space" 4
- .IX Item "space"
- The width of a space in pixels
- .Ip "char_up, char_down" 4
- .IX Item "char_up, char_down"
- The number of pixels that a character can stick out above and below the
- baseline. Note that this is only useful for TrueType fonts. For builtins
- char_up is equal to height, and char_down is always 0.
- .PP
- Note that some of these parameters (char_up, char_down and space) are
- generic font properties, and not necessarily a property of the text
- that is set.
- .Sh "$gd_text->width('string')"
- .IX Subsection "$gd_text->width('string')"
- Return the length of a string in pixels, without changing the current
- value of the text. Returns the width of 'string' rendered in the
- current font and size. On failure, returns undef.
- .PP
- The use of this method is vaguely deprecated.
- .Sh "$gd_text->is_builtin"
- .IX Subsection "$gd_text->is_builtin"
- Returns true if the current object is based on a builtin s-1GDs0 font.
- .Sh "$gd_text->is_ttf"
- .IX Subsection "$gd_text->is_ttf"
- Returns true if the current object is based on a TrueType font.
- .Sh "$gd_text->fIcan_do_ttf()fP or s-1GD:s0:Text->fIcan_do_ttf()fP"
- .IX Subsection "$gd_text->can_do_ttf() or GD::Text->can_do_ttf()"
- Return true if this object can handle s-1TTFs0 fonts.
- .PP
- This depends on whether your version of s-1GDs0 is newer than 1.19 and
- has s-1TTFs0 support compiled into it.
- .Sh "$gd_text->font_path(path_spec), s-1GD:s0:Text->font_path(path_spec)"
- .IX Subsection "$gd_text->font_path(path_spec), GD::Text->font_path(path_spec)"
- This sets the font path for the fIclassfR (i.e. not just for the object).
- The f(CW*(C`set_font*(C'fR method will search this path to find the font specified
- if it is a TrueType font. It should contain a list of
- paths. The current directory is always searched first, unless '.' is
- present in s-1FONT_PATHs0. Examples:
- .PP
- .Vb 2
- & GD::Text->font_path('/usr/ttfonts'); # Unix
- & GD::Text->font_path('c:/fonts'); # MS-OS
- .Ve
- Any font name that is not an absolute path will first be looked for in
- the current directory, and then in /usr/ttfonts (c:efonts).
- .PP
- .Vb 2
- & GD::Text->font_path('/usr/ttfonts:.:lib/fonts'); # Unix
- & GD::Text->font_path('c:/fonts;.;f:/fonts'); # MS-OS
- .Ve
- Any font name that is not an absolute path will first be looked for in
- /usr/ttfonts (c:efonts), then in the current directory. and then in
- lib/fonts (f:efonts),
- relative to the current directory.
- .PP
- .Vb 1
- & GD::Text->font_path(undef);
- .Ve
- Font files are only looked for in the current directory.
- .PP
- &s-1FONT_PATHs0 is initialised at module load time from the environment
- variables s-1FONT_PATHs0 or, if that's not present, s-1TTF_FONT_PATHs0.
- .PP
- Returns the value the font path is set to. If called without arguments
- &f(CW*(C`font_path*(C'fR returns the current font path.
- .PP
- Note: This currently only works for unices, and (hopefully) for
- Microsoft based s-1OSs0's. If anyone feels the urge to have a look at the
- code, and send me patches for their s-1OSs0, I'd be most grateful)
- .SH "BUGS"
- .IX Header "BUGS"
- This module has only been tested with anglo-centric 'normal' fonts and
- encodings. Fonts that have other characteristics may not work well.
- If that happens, please let me know how to make this work better.
- .PP
- The font height gets estimated by building a string with all printable
- characters that pass the s-1POSIX:\fIs0:isgraph()fR test. If your system doesn't
- have s-1POSIXs0, I make an approximation that may be false.
- .PP
- The whole font path thing works well on Unix, but probably not very well
- on other s-1OSs0's. This is only a problem if you try to use a font path. If
- you don't use a font path, there should never be a problem. I will try
- to expand this in the future, but only if there's a demand for it.
- Suggestions welcome.
- .SH "COPYRIGHT"
- .IX Header "COPYRIGHT"
- copyright 1999
- Martien Verbruggen (mgjv@comdyn.com.au)
- .SH "SEE ALSO"
- .IX Header "SEE ALSO"
- &fIGDfR|(3), s-1GD:\fIs0:Text::WrapfR|(3), s-1GD:\fIs0:Text::AlignfR|(3)