ch08.html 10.7 KB
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Chapter 8. Text and font handling</title><link rel="stylesheet" type="text/css" href="manual.css"><meta name="generator" content="DocBook XSL Stylesheets V1.76.0"><link rel="home" href="index.html" title="JpGraph Manual"><link rel="up" href="pt02.html" title="Part II. Basic graph creation"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 8. Text and font handling</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center">Part II. Basic graph creation</th><td width="20%" align="right"> </td></tr></table><hr></div><div class="chapter" title="Chapter 8. Text and font handling"><div class="titlepage"><div><div><h2 class="title"><a name="chap.text_handling"></a>Chapter 8. Text and font handling</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch08.html#id2496825">8.1. Different types of fonts</a></span></dt><dt><span class="sect1"><a href="ch08s02.html">8.2. Font families and font styles</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch08s02.html#id2496988">8.2.1. Default TrueType Font</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch08s03.html">8.3. Understanding text alignment and anchor point</a></span></dt><dt><span class="sect1"><a href="ch08s04.html">8.4. Rotating text</a></span></dt><dt><span class="sect1"><a href="ch08s05.html">8.5. Formatting text paragraphs</a></span></dt><dt><span class="sect1"><a href="ch08s06.html">8.6. Adding custom TTF fonts</a></span></dt><dt><span class="sect1"><a href="ch08s07.html">8.7. Inserting Unicode entities</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch08s07.html#id2499171">8.7.1. The utility class "SymChar"</a></span></dt><dt><span class="sect2"><a href="ch08s07.html#id2500148">8.7.2. Graph example with Greek labels</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch08s08.html">8.8. Character encoding</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch08s08.html#id2500277">8.8.1. Japanese encoding options</a></span></dt><dt><span class="sect2"><a href="ch08s08.html#id2500408">8.8.2. Chinese encoding options</a></span></dt><dt><span class="sect2"><a href="ch08s08.html#id2500502">8.8.3. Cyrillic encoding options</a></span></dt><dt><span class="sect2"><a href="ch08s08.html#id2500687">8.8.4. Hebrew encoding options</a></span></dt><dt><span class="sect2"><a href="ch08s08.html#id2500718">8.8.5. Greek encoding options</a></span></dt></dl></dd></dl></div>
        
        <p>Before reading this chapter please make sure that your installation supports TTF fonts
            if you intend to use them (See <a class="xref" href="ch03s02.html" title="Necessary system requirements for the library">Necessary system requirements for the library</a>). The rest of this chapter assumes that a working
            installation with TTF fonts is available when needed.</p>
        <p>
            </p><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
                <p>It is highly recommended to create a setup where TTF fonts work since the
                    visual quality is significantly better than for the built-in bitmap fonts. In
                    addition the bitmap fonts are restricted to only display plain 7-bit ASCII
                    characters which means that no accented characters can be displayed, for example
                    the Scandinavian characters "åäö".</p>
            </div><p>
        </p>
        <p>
            </p><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
                <p>All files in the library are encoded in utf-8.</p>
            </div><p>
        </p>
        <div class="sect1" title="Different types of fonts"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2496825"></a>Different types of fonts</h2></div></div></div>
            
            <p>The library supports two fundamental types of fonts.</p>
            <p>
                </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
                        <p><span class="bold"><strong>Bitmap fonts</strong></span></p>
                        <p>There are three built in bitmap fonts. They are available as font
                            families <code class="code">FF_FONT0</code>, <code class="code">FF_FONT1</code> and
                                <code class="code">FF_FONT2</code>. The advantage with bitmap fonts is that they
                            are always available in all installations of GD. However, bitmap fonts
                            only supports 7-bit ASCII so if you need to display any character from
                            the extended character set it is not possible to use bitmap fonts. The
                            available sizes of the bitmap fonts are also limited, the three
                            available size corresponds to the three families where
                                <code class="code">FF_FONT0</code> is the smallest and <code class="code">FF_FONT2</code> the
                            largest available bitmap font.</p>
                        <p>Bitmap fonts also has a more "rugged" look since they do not use
                            anti-aliasing.</p>
                        <p><span class="bold"><strong>Example:</strong></span>
                            <span class="italic">The following script lines shows a typical use of bit
                                map font specified for the title of a graph</span></p>
                        <p>
                            </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-var">$graph</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">Graph</span><span class="hl-brackets">(</span><span class="hl-code">....</span><span class="hl-brackets">)</span><span class="hl-code">;
 
</span><span class="hl-comment">//</span><span class="hl-comment">  Adjust the title to use the largest built-in bitmap font in bold face</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_FONT2</span><span class="hl-code">,</span><span class="hl-identifier">FS_BOLD</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div><p>
                        </p>
                        <p>The remainder of this chapter will describe this in more
                            details.</p>
                    </li><li class="listitem">
                        <p><span class="bold"><strong>TTF Fonts (True Type Fonts)</strong></span></p>
                        <p>True Type Fonts (TTF) give a much better visual quality of the text.
                            They are available in all sizes and there are many more font family to
                            choose from. All font family specification apart from the three bitmap
                            fonts are TTF fonts. In order to use these fonts the installation must
                            be configured in the right way which is described in <a class="xref" href="ch03s02.html" title="Necessary system requirements for the library">Necessary system requirements for the library</a>. It is necessary to use TTF fonts in
                            order to display extended character sets (outside the traditional 7-bit
                            ASCII). TTF fonts must also be used when inserting unicode entities as
                            described in <a class="xref" href="ch08s07.html" title="Inserting Unicode entities">Inserting Unicode entities</a></p>
                        <p>In order to be able to use TTF fonts it is necessary to check if the
                            installations supports this. See <a class="xref" href="ch03s02.html" title="Necessary system requirements for the library">Necessary system requirements for the library</a></p>
                        <p><span class="bold"><strong>Example:</strong></span>
                            <span class="italic">The following script lines shows a typical use of the
                                Arial TTF fonts for the title of a graph</span></p>
                        <p>
                            </p><div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
2
3
4
5
6
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-var">$graph</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">Graph</span><span class="hl-brackets">(</span><span class="hl-code">....</span><span class="hl-brackets">)</span><span class="hl-code">;
 
</span><span class="hl-comment">//</span><span class="hl-comment">  Adjust the title to use 14pt Arial bold face</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$graph</span><span class="hl-code">-&gt;</span><span class="hl-identifier">title</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetFont</span><span class="hl-brackets">(</span><span class="hl-identifier">FF_ARIAL</span><span class="hl-code">,</span><span class="hl-identifier">FS_BOLD</span><span class="hl-code">,</span><span class="hl-number">14</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div><p>
                        </p>
                    </li></ol></div><p>
            </p>
        </div>

        
        
        
        
        
        
        
    </div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"><a accesskey="u" href="pt02.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>