Blame view

site/jpgraph/docs/chunkhtml/ch03s04.html 17.5 KB
d72ac078   Guillaume   Ajout graphe V1.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
  <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Installing and configuring Font support</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="ch03.html" title="Chapter 3. The Long Version: Installing the Library"></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">Installing and configuring Font support</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center">Chapter 3. The Long Version: Installing the Library</th><td width="20%" align="right"> </td></tr></table><hr></div><div class="sect1" title="Installing and configuring Font support"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec1.installing-fonts"></a>Installing and configuring Font support</h2></div></div></div>
              
              <p>JpGraph supports two types of fonts, bitmap and TTF fonts. The advantage with
                  bitmap fonts are that they are supported from within the library without further
                  configuration. TTF fonts require some configuration and possible installation of the
                  actual TTF font specification file. (For more on installing TTF fonts see <a class="xref" href="ch03s04.html#sec1.getting_add_fonts" title="Configuring TTF fonts">Configuring TTF fonts</a>.) </p>
              <p>The drawbacks, on the other hand, with bitmap fonts are quite a few</p>
              <p>
                  </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
                          <p>they look quite crude and are only available in a few sizes</p>
                      </li><li class="listitem">
                          <p>italic font style is not supported for bitmap fonts</p>
                      </li><li class="listitem">
                          <p>they only support 7-bit ASCII characters</p>
                      </li><li class="listitem">
                          <p>they only support 0 and 90 degree rotated text</p>
                      </li></ul></div><p>
              </p>
              <p>You can read more about how to use and select among the different fonts in <a class="xref" href="ch08.html" title="Chapter 8. Text and font handling">Chapter 8. <i>Text and font handling</i></a></p>
              <div class="sect2" title="Configuring TTF fonts"><div class="titlepage"><div><div><h3 class="title"><a name="sec1.getting_add_fonts"></a>Configuring TTF fonts</h3></div></div></div>
                  
                  <p>
                      </p><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
                          <p>This could be considered an optional section since the library will
                              work even without TTF fonts. However, for th reasons listed previously
                              it is strongly recommended that TTF support is configured.</p>
                      </div><p>
                  </p>
                  <p>In the following we will assume that the FreeType library is enabled and
                      verified in the PHP installation (See <a class="xref" href="ch03s02.html#fig.phpinfo-gd" title="Figure 3.2. phphinfo() GD-Information">Figure 3.2. phphinfo() GD-Information</a>)</p>
                  <p>Due to various legal issues no TTF fonts are included in the distribution of
                      JpGraph since many commonly used TTF font files are copyrighted and there
                      distribution restricted. For the most commonly used WEB-fonts (the Microsoft
                      Core Fonts) the status is unclear. For many years Microsoft distributed them
                      freely but they are no longer available from Microsofts home page. Instead they
                      are available from <code class="uri"><a class="uri" href="http://corefonts.sourceforge.net/" target="_top">http://corefonts.sourceforge.net/</a></code>
                  </p>
                  <p>There are however a fair amount of freely available high quality TTF fonts
                      (see below). The first thing needed is to make sure that the path defines in the
                      file <code class="filename">jpg-config.inc.php</code> corresponds to the server setup (so
                      that the library can find the font files)</p>
                  <div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
                          <p>Open <code class="filename">jpg-config.inc.php</code> for editing</p>
                      </li><li class="listitem">
                          <p>Locate the define <code class="code">TTF_DIR</code> (this is the define that
                              possible needs updating depending on your system). By default this path
                              will have a sensible values depending on if the library is installed on
                              a Windows or a Unix system.</p>
                      </li><li class="listitem">
                          <p>If you are on a Windows platform you can just point the TTF directory
                              path in JpGraph to use the standard Window font directory (e.g
                                  <code class="filename">C:\windows\fonts\</code>)</p>
                      </li><li class="listitem">
                          <p>If you are on a Unix platform, which may not have any TTF fonts
                              installed, you can download and install the core MS WEB-initiative fonts
                              from <code class="uri"><a class="uri" href="http://corefonts.sourceforge.net/" target="_top">http://corefonts.sourceforge.net/</a></code>
                              many Linux distributions also have automatic ways to install these
                              fonts. These fonts were put in the public domain by the Microsoft
                              Corporation but they are no longer available directly from
                              Microsoft.</p>
                      </li><li class="listitem">
                          <p>You can also chose to install the freely available Vera Bitstream TTF
                              fonts available from <code class="uri"><a class="uri" href="http://www.gnome.org/fonts/" target="_top">http://www.gnome.org/fonts/</a></code></p>
                      </li><li class="listitem">
                          <p>You can also chose to install the freely available DejaVu TTF fonts <code class="uri"><a class="uri" href="http://sourceforge.net/projects/dejavu/" target="_top">http://sourceforge.net/projects/dejavu</a></code></p>
                      </li></ol></div>
                  <p>JpGraph uses a standard naming convention for the TTF font files in order to
                      be able to find the correct font file that correspond to a particular font
                      family. This naming convention follows the standard naming of the available font
                      files from the distributions listed above. </p>
                  <p>If the installation of the library is made on a computer running MS Windows
                      then it is recommended to use the already available font files in Windows
                      (usually located in <code class="filename">C:\WINDOWS\FONTS</code>). </p>
                  <p>If the installation is made on a UNIX derivate running X11 then the font
                      location can differ between versions and UNIX brands. One commonly used path in
                      modern installations are "<code class="filename">/usr/share/fonts/truetype/</code>" (In
                      older installations it was common to put the truetype fonts under
                          "<code class="filename">/usr/X11R6/lib/X11/fonts/truetype/</code>".)</p>
                  <p>Finally we note that it is possible to install additional fonts not natively
                      supported by the library by using the <code class="code">SetUserFont()</code> family of
                      methods. (In theory it is also possible to patch the jpgraph source files to
                      include support for other font files natively but since this requires code
                      modifications of the library we do not discuss this further here in the
                      introduction.)</p>
                  <p>Freely available TTF fonts can be found, for example, from</p>
                  <p>
                      </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
                              <p><code class="uri"><a class="uri" href="http://www.webfontlist.com" target="_top">http://www.webfontlist.com</a></code></p>
                          </li><li class="listitem">
                              <p><code class="uri"><a class="uri" href="http://www.webpagepublicity.com/free-fonts.html" target="_top">http://www.webpagepublicity.com/free-fonts.html</a></code></p>
                          </li><li class="listitem">
                              <p><code class="uri"><a class="uri" href="http://www.fontonic.com/fonts.asp?width=do&amp;offset=120" target="_top">http://www.fontonic.com/fonts.asp?width=do&amp;offset=120</a></code></p>
                          </li><li class="listitem">
                              <p><code class="uri"><a class="uri" href="http://www.fontspace.com/category/famous" target="_top">http://www.fontspace.com/category/famous</a></code></p>
                          </li></ul></div><p>
                  </p>
              </div>
              <div class="sect2" title="Using non-latin based fonts with JpGraph"><div class="titlepage"><div><div><h3 class="title"><a name="sec2.using-non-latin-fonts"></a>Using non-latin based fonts with JpGraph</h3></div></div></div>
                  
                  <p>In addition to European fonts it is also possible to use non-latin based fonts
                      such as Cyrillic, Japanese, Chinese, Hebrew and Greek. For any of these
                      languages a suitable TTF font that supports the non-latin based language must be
                      made available to the library. Some specific rules also applies to each of the
                      supported languages due to the necessary character encoding needed due to
                      different convention when writing the character for some languages. </p>
                  <p>
                      </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
                              <p>For Cyrillic support the define <code class="code">LANGUAGE_CYRILLIC</code> in
                                      <code class="filename">jpg-config.php</code> must be set to
                                      <code class="code">true</code>. It is then possible to use a suitable
                                  Cyrillic font as replacement of the ordinary font. This setting
                                  combined with the <code class="code">CYRILLIC_FROM_WINDOWS</code> and
                                      <code class="code">LANGUAGE_CHARSET</code> is used to fine tune the handling
                                  cyrillic input. The rules are as follows:</p>
                              <p>
                                  </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
                                          <p>If <code class="code">LANGUAGE_CYRILLIC</code> is <span class="bold"><strong>false</strong></span> no specific handling of
                                              Cyrillic characters at all will be done.</p>
                                      </li><li class="listitem">
                                          <p>If <code class="code">CYRILLIC_FROM_WINDOWS</code> is <span class="bold"><strong>true</strong></span> then it will be assumed
                                              the input coding by default is encoded using <span class="bold"><strong>WINDOWS-1251</strong></span>. </p>
                                          <p>The conversion is then done via a call to
                                                  <code class="code">convert_cyr_string($aTxt, 'w', 'k')</code>
                                              where <code class="code">$aTxt</code> is replaced with the input
                                              string to be encoded.</p>
                                      </li><li class="listitem">
                                          <p>If <code class="code">CYRILLIC_FROM_WINDOWS</code> is <span class="bold"><strong>false</strong></span> then it will be assumed
                                              the input coding by default is encoded using <span class="bold"><strong>KOI8-R</strong></span>.</p>
                                          <p>The conversion is then done via the sequence of
                                              callls</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
  </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">$isostring</span><span class="hl-code"> = </span><span class="hl-identifier">convert_cyr_string</span><span class="hl-brackets">(</span><span class="hl-var">$aTxt</span><span class="hl-code">, </span><span class="hl-quotes">&quot;</span><span class="hl-string">k</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-quotes">&quot;</span><span class="hl-string">i</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
  </span><span class="hl-var">$unistring</span><span class="hl-code"> = </span><span class="hl-identifier">LanguageConv</span><span class="hl-code">::</span><span class="hl-identifier">iso2uni</span><span class="hl-brackets">(</span><span class="hl-var">$isostring</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>in oder to get a proper utf-8 internal encoding
                                              (internally the library only uses utf-8 encoding)</p>
                                      </li><li class="listitem">
                                          <p><code class="code">LANGUAGE_CHARSET</code> can be used to
                                              dynamically adjust the conversion of the input character
                                              set when using cyrillic characters. This constant is
                                              used to auto-detect whether cyrillic conversion is
                                              really necessary if enabled (via the If
                                                  <code class="code">LANGUAGE_CYRILLIC</code>=true) . This constant
                                              can be set to a variable containing the currently used
                                              character input set .A typical such string would be
                                              'UTF-8' or 'utf-8' (the comparison is case-insensitive).
                                              If this charset is not 'koi8-r' nor 'windows-1251'
                                              derivate then no conversion is done. </p>
                                      </li></ol></div><p>
                              </p>
                              <p></p>
                          </li><li class="listitem">
                              <p>For Chinese character set JpGraph supports both BIG5 and GB2312
                                  encoding. For BIG5 encoding the PHP installation must have support
                                  for the "<code class="code">iconv()</code>" function. Furthermore the define
                                      <code class="code">CHINESE_TTF_FONT</code> must be set to the name of the
                                  Chinese BIG5 font that is to be used. By default this is set to
                                      "<code class="filename">bkai00mp.ttf</code>". To use the Chinese BIG5
                                  font in the scripts one must then specify the font family as
                                      <code class="code">FF_CHINESE</code>.</p>
                              <p>To use the alternative font files
                                  "<code class="filename">simsun.ttc</code>" and
                                      "<code class="filename">simhei.ttf</code>" (which uses the GB2312
                                  encoding) the only step needed is to install those fonts in the
                                  normal TTF font directory and then specify the font family as
                                      <code class="code">FF_SIMSUN</code>, the "<code class="filename">simhei.ttf</code>" is
                                  used when the font style is specified as
                                  <code class="code">FS_BOLD</code>.</p>
                          </li></ul></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="ch03.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>