PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/mcmis/reportico/jpgraph/src/jpgraph_ttf.inc.php

http://mcmis.googlecode.com/
PHP | 617 lines | 429 code | 71 blank | 117 comment | 55 complexity | 4cffe7d882aec98686db178317522919 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. //=======================================================================
  3. // File: jpgraph_ttf.inc.php
  4. // Description: Handling of TTF fonts
  5. // Created: 2006-11-19
  6. // Ver: $Id: jpgraph_ttf.inc.php,v 1.1.1.1 2010-10-26 21:13:51 peter Exp $
  7. //
  8. // Copyright (c) Aditus Consulting. All rights reserved.
  9. //========================================================================
  10. // TTF Font families
  11. define("FF_COURIER",10);
  12. define("FF_VERDANA",11);
  13. define("FF_TIMES",12);
  14. define("FF_COMIC",14);
  15. define("FF_ARIAL",15);
  16. define("FF_GEORGIA",16);
  17. define("FF_TREBUCHE",17);
  18. // Gnome Vera font
  19. // Available from http://www.gnome.org/fonts/
  20. define("FF_VERA",18);
  21. define("FF_VERAMONO",19);
  22. define("FF_VERASERIF",20);
  23. // Chinese font
  24. define("FF_SIMSUN",30);
  25. define("FF_CHINESE",31);
  26. define("FF_BIG5",32);
  27. // Japanese font
  28. define("FF_MINCHO",40);
  29. define("FF_PMINCHO",41);
  30. define("FF_GOTHIC",42);
  31. define("FF_PGOTHIC",43);
  32. // Hebrew fonts
  33. define("FF_DAVID",44);
  34. define("FF_MIRIAM",45);
  35. define("FF_AHRON",46);
  36. // Dejavu-fonts http://sourceforge.net/projects/dejavu
  37. define("FF_DV_SANSSERIF",47);
  38. define("FF_DV_SERIF",48);
  39. define("FF_DV_SANSSERIFMONO",49);
  40. define("FF_DV_SERIFCOND",50);
  41. define("FF_DV_SANSSERIFCOND",51);
  42. // Extra fonts
  43. // Download fonts from
  44. // http://www.webfontlist.com
  45. // http://www.webpagepublicity.com/free-fonts.html
  46. // http://www.fontonic.com/fonts.asp?width=d&offset=120
  47. // http://www.fontspace.com/category/famous
  48. // define("FF_SPEEDO",71); // This font is also known as Bauer (Used for development gauge fascia)
  49. define("FF_DIGITAL",72); // Digital readout font
  50. define("FF_COMPUTER",73); // The classic computer font
  51. define("FF_CALCULATOR",74); // Triad font
  52. define("FF_USERFONT",90);
  53. define("FF_USERFONT1",90);
  54. define("FF_USERFONT2",91);
  55. define("FF_USERFONT3",92);
  56. // Limits for fonts
  57. define("_FIRST_FONT",10);
  58. define("_LAST_FONT",99);
  59. // TTF Font styles
  60. define("FS_NORMAL",9001);
  61. define("FS_BOLD",9002);
  62. define("FS_ITALIC",9003);
  63. define("FS_BOLDIT",9004);
  64. define("FS_BOLDITALIC",9004);
  65. //Definitions for internal font
  66. define("FF_FONT0",1);
  67. define("FF_FONT1",2);
  68. define("FF_FONT2",4);
  69. //------------------------------------------------------------------------
  70. // Defines for font setup
  71. //------------------------------------------------------------------------
  72. // Actual name of the TTF file used together with FF_CHINESE aka FF_BIG5
  73. // This is the TTF file being used when the font family is specified as
  74. // either FF_CHINESE or FF_BIG5
  75. define('CHINESE_TTF_FONT','bkai00mp.ttf');
  76. // Special unicode greek language support
  77. define("LANGUAGE_GREEK",false);
  78. // If you are setting this config to true the conversion of greek characters
  79. // will assume that the input text is windows 1251
  80. define("GREEK_FROM_WINDOWS",false);
  81. // Special unicode cyrillic language support
  82. define("LANGUAGE_CYRILLIC",false);
  83. // If you are setting this config to true the conversion
  84. // will assume that the input text is windows 1251, if
  85. // false it will assume koi8-r
  86. define("CYRILLIC_FROM_WINDOWS",false);
  87. // The following constant is used to auto-detect
  88. // whether cyrillic conversion is really necessary
  89. // if enabled. Just replace 'windows-1251' with a variable
  90. // containing the input character encoding string
  91. // of your application calling jpgraph.
  92. // A typical such string would be 'UTF-8' or 'utf-8'.
  93. // The comparison is case-insensitive.
  94. // If this charset is not a 'koi8-r' or 'windows-1251'
  95. // derivate then no conversion is done.
  96. //
  97. // This constant can be very important in multi-user
  98. // multi-language environments where a cyrillic conversion
  99. // could be needed for some cyrillic people
  100. // and resulting in just erraneous conversions
  101. // for not-cyrillic language based people.
  102. //
  103. // Example: In the free project management
  104. // software dotproject.net $locale_char_set is dynamically
  105. // set by the language environment the user has chosen.
  106. //
  107. // Usage: define('LANGUAGE_CHARSET', $locale_char_set);
  108. //
  109. // where $locale_char_set is a GLOBAL (string) variable
  110. // from the application including JpGraph.
  111. //
  112. define('LANGUAGE_CHARSET', null);
  113. // Japanese TrueType font used with FF_MINCHO, FF_PMINCHO, FF_GOTHIC, FF_PGOTHIC
  114. // Standard fonts from Infomation-technology Promotion Agency (IPA)
  115. // See http://mix-mplus-ipa.sourceforge.jp/
  116. define('MINCHO_TTF_FONT','ipam.ttf');
  117. define('PMINCHO_TTF_FONT','ipamp.ttf');
  118. define('GOTHIC_TTF_FONT','ipag.ttf');
  119. define('PGOTHIC_TTF_FONT','ipagp.ttf');
  120. // Assume that Japanese text have been entered in EUC-JP encoding.
  121. // If this define is true then conversion from EUC-JP to UTF8 is done
  122. // automatically in the library using the mbstring module in PHP.
  123. define('ASSUME_EUCJP_ENCODING',false);
  124. //=================================================================
  125. // CLASS LanguageConv
  126. // Description:
  127. // Converts various character encoding into proper
  128. // UTF-8 depending on how the library have been configured and
  129. // what font family is being used
  130. //=================================================================
  131. class LanguageConv {
  132. private $g2312 = null ;
  133. function Convert($aTxt,$aFF) {
  134. if( LANGUAGE_GREEK ) {
  135. if( GREEK_FROM_WINDOWS ) {
  136. $unistring = LanguageConv::gr_win2uni($aTxt);
  137. } else {
  138. $unistring = LanguageConv::gr_iso2uni($aTxt);
  139. }
  140. return $unistring;
  141. } elseif( LANGUAGE_CYRILLIC ) {
  142. if( CYRILLIC_FROM_WINDOWS && (!defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'windows-1251')) ) {
  143. $aTxt = convert_cyr_string($aTxt, "w", "k");
  144. }
  145. if( !defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'koi8-r') || stristr(LANGUAGE_CHARSET, 'windows-1251')) {
  146. $isostring = convert_cyr_string($aTxt, "k", "i");
  147. $unistring = LanguageConv::iso2uni($isostring);
  148. }
  149. else {
  150. $unistring = $aTxt;
  151. }
  152. return $unistring;
  153. }
  154. elseif( $aFF === FF_SIMSUN ) {
  155. // Do Chinese conversion
  156. if( $this->g2312 == null ) {
  157. include_once 'jpgraph_gb2312.php' ;
  158. $this->g2312 = new GB2312toUTF8();
  159. }
  160. return $this->g2312->gb2utf8($aTxt);
  161. }
  162. elseif( $aFF === FF_BIG5 ) {
  163. if( !function_exists('iconv') ) {
  164. JpGraphError::RaiseL(25006);
  165. //('Usage of FF_CHINESE (FF_BIG5) font family requires that your PHP setup has the iconv() function. By default this is not compiled into PHP (needs the "--width-iconv" when configured).');
  166. }
  167. return iconv('BIG5','UTF-8',$aTxt);
  168. }
  169. elseif( ASSUME_EUCJP_ENCODING &&
  170. ($aFF == FF_MINCHO || $aFF == FF_GOTHIC || $aFF == FF_PMINCHO || $aFF == FF_PGOTHIC) ) {
  171. if( !function_exists('mb_convert_encoding') ) {
  172. JpGraphError::RaiseL(25127);
  173. }
  174. return mb_convert_encoding($aTxt, 'UTF-8','EUC-JP');
  175. }
  176. elseif( $aFF == FF_DAVID || $aFF == FF_MIRIAM || $aFF == FF_AHRON ) {
  177. return LanguageConv::heb_iso2uni($aTxt);
  178. }
  179. else
  180. return $aTxt;
  181. }
  182. // Translate iso encoding to unicode
  183. public static function iso2uni ($isoline){
  184. $uniline='';
  185. for ($i=0; $i < strlen($isoline); $i++){
  186. $thischar=substr($isoline,$i,1);
  187. $charcode=ord($thischar);
  188. $uniline.=($charcode>175) ? "&#" . (1040+($charcode-176)). ";" : $thischar;
  189. }
  190. return $uniline;
  191. }
  192. // Translate greek iso encoding to unicode
  193. public static function gr_iso2uni ($isoline) {
  194. $uniline='';
  195. for ($i=0; $i < strlen($isoline); $i++) {
  196. $thischar=substr($isoline,$i,1);
  197. $charcode=ord($thischar);
  198. $uniline.=($charcode>179 && $charcode!=183 && $charcode!=187 && $charcode!=189) ? "&#" . (900+($charcode-180)). ";" : $thischar;
  199. }
  200. return $uniline;
  201. }
  202. // Translate greek win encoding to unicode
  203. public static function gr_win2uni ($winline) {
  204. $uniline='';
  205. for ($i=0; $i < strlen($winline); $i++) {
  206. $thischar=substr($winline,$i,1);
  207. $charcode=ord($thischar);
  208. if ($charcode==161 || $charcode==162) {
  209. $uniline.="&#" . (740+$charcode). ";";
  210. }
  211. else {
  212. $uniline.=(($charcode>183 && $charcode!=187 && $charcode!=189) || $charcode==180) ? "&#" . (900+($charcode-180)). ";" : $thischar;
  213. }
  214. }
  215. return $uniline;
  216. }
  217. public static function heb_iso2uni($isoline) {
  218. $isoline = hebrev($isoline);
  219. $o = '';
  220. $n = strlen($isoline);
  221. for($i=0; $i < $n; $i++) {
  222. $c=ord( substr($isoline,$i,1) );
  223. $o .= ($c > 223) && ($c < 251) ? '&#'.(1264+$c).';' : chr($c);
  224. }
  225. return utf8_encode($o);
  226. }
  227. }
  228. //=============================================================
  229. // CLASS TTF
  230. // Description: Handle TTF font names and mapping and loading of
  231. // font files
  232. //=============================================================
  233. class TTF {
  234. private $font_files,$style_names;
  235. function __construct() {
  236. // String names for font styles to be used in error messages
  237. $this->style_names=array(
  238. FS_NORMAL =>'normal',
  239. FS_BOLD =>'bold',
  240. FS_ITALIC =>'italic',
  241. FS_BOLDITALIC =>'bolditalic');
  242. // File names for available fonts
  243. $this->font_files=array(
  244. FF_COURIER => array(FS_NORMAL =>'cour.ttf',
  245. FS_BOLD =>'courbd.ttf',
  246. FS_ITALIC =>'couri.ttf',
  247. FS_BOLDITALIC =>'courbi.ttf' ),
  248. FF_GEORGIA => array(FS_NORMAL =>'georgia.ttf',
  249. FS_BOLD =>'georgiab.ttf',
  250. FS_ITALIC =>'georgiai.ttf',
  251. FS_BOLDITALIC =>'' ),
  252. FF_TREBUCHE =>array(FS_NORMAL =>'trebuc.ttf',
  253. FS_BOLD =>'trebucbd.ttf',
  254. FS_ITALIC =>'trebucit.ttf',
  255. FS_BOLDITALIC =>'trebucbi.ttf' ),
  256. FF_VERDANA => array(FS_NORMAL =>'verdana.ttf',
  257. FS_BOLD =>'verdanab.ttf',
  258. FS_ITALIC =>'verdanai.ttf',
  259. FS_BOLDITALIC =>'' ),
  260. FF_TIMES => array(FS_NORMAL =>'times.ttf',
  261. FS_BOLD =>'timesbd.ttf',
  262. FS_ITALIC =>'timesi.ttf',
  263. FS_BOLDITALIC =>'timesbi.ttf' ),
  264. FF_COMIC => array(FS_NORMAL =>'comic.ttf',
  265. FS_BOLD =>'comicbd.ttf',
  266. FS_ITALIC =>'',
  267. FS_BOLDITALIC =>'' ),
  268. FF_ARIAL => array(FS_NORMAL =>'arial.ttf',
  269. FS_BOLD =>'arialbd.ttf',
  270. FS_ITALIC =>'ariali.ttf',
  271. FS_BOLDITALIC =>'arialbi.ttf' ) ,
  272. FF_VERA => array(FS_NORMAL =>'Vera.ttf',
  273. FS_BOLD =>'VeraBd.ttf',
  274. FS_ITALIC =>'VeraIt.ttf',
  275. FS_BOLDITALIC =>'VeraBI.ttf' ),
  276. FF_VERAMONO => array(FS_NORMAL =>'VeraMono.ttf',
  277. FS_BOLD =>'VeraMoBd.ttf',
  278. FS_ITALIC =>'VeraMoIt.ttf',
  279. FS_BOLDITALIC =>'VeraMoBI.ttf' ),
  280. FF_VERASERIF=> array(FS_NORMAL =>'VeraSe.ttf',
  281. FS_BOLD =>'VeraSeBd.ttf',
  282. FS_ITALIC =>'',
  283. FS_BOLDITALIC =>'' ) ,
  284. /* Chinese fonts */
  285. FF_SIMSUN => array(
  286. FS_NORMAL =>'simsun.ttc',
  287. FS_BOLD =>'simhei.ttf',
  288. FS_ITALIC =>'',
  289. FS_BOLDITALIC =>'' ),
  290. FF_CHINESE => array(
  291. FS_NORMAL =>CHINESE_TTF_FONT,
  292. FS_BOLD =>'',
  293. FS_ITALIC =>'',
  294. FS_BOLDITALIC =>'' ),
  295. FF_BIG5 => array(
  296. FS_NORMAL =>CHINESE_TTF_FONT,
  297. FS_BOLD =>'',
  298. FS_ITALIC =>'',
  299. FS_BOLDITALIC =>'' ),
  300. /* Japanese fonts */
  301. FF_MINCHO => array(
  302. FS_NORMAL =>MINCHO_TTF_FONT,
  303. FS_BOLD =>'',
  304. FS_ITALIC =>'',
  305. FS_BOLDITALIC =>'' ),
  306. FF_PMINCHO => array(
  307. FS_NORMAL =>PMINCHO_TTF_FONT,
  308. FS_BOLD =>'',
  309. FS_ITALIC =>'',
  310. FS_BOLDITALIC =>'' ),
  311. FF_GOTHIC => array(
  312. FS_NORMAL =>GOTHIC_TTF_FONT,
  313. FS_BOLD =>'',
  314. FS_ITALIC =>'',
  315. FS_BOLDITALIC =>'' ),
  316. FF_PGOTHIC => array(
  317. FS_NORMAL =>PGOTHIC_TTF_FONT,
  318. FS_BOLD =>'',
  319. FS_ITALIC =>'',
  320. FS_BOLDITALIC =>'' ),
  321. /* Hebrew fonts */
  322. FF_DAVID => array(
  323. FS_NORMAL =>'DAVIDNEW.TTF',
  324. FS_BOLD =>'',
  325. FS_ITALIC =>'',
  326. FS_BOLDITALIC =>'' ),
  327. FF_MIRIAM => array(
  328. FS_NORMAL =>'MRIAMY.TTF',
  329. FS_BOLD =>'',
  330. FS_ITALIC =>'',
  331. FS_BOLDITALIC =>'' ),
  332. FF_AHRON => array(
  333. FS_NORMAL =>'ahronbd.ttf',
  334. FS_BOLD =>'',
  335. FS_ITALIC =>'',
  336. FS_BOLDITALIC =>'' ),
  337. /* Misc fonts */
  338. FF_DIGITAL => array(
  339. FS_NORMAL =>'DIGIRU__.TTF',
  340. FS_BOLD =>'Digirtu_.ttf',
  341. FS_ITALIC =>'Digir___.ttf',
  342. FS_BOLDITALIC =>'DIGIRT__.TTF' ),
  343. /* This is an experimental font for the speedometer development
  344. FF_SPEEDO => array(
  345. FS_NORMAL =>'Speedo.ttf',
  346. FS_BOLD =>'',
  347. FS_ITALIC =>'',
  348. FS_BOLDITALIC =>'' ),
  349. */
  350. FF_COMPUTER => array(
  351. FS_NORMAL =>'COMPUTER.TTF',
  352. FS_BOLD =>'',
  353. FS_ITALIC =>'',
  354. FS_BOLDITALIC =>'' ),
  355. FF_CALCULATOR => array(
  356. FS_NORMAL =>'Triad_xs.ttf',
  357. FS_BOLD =>'',
  358. FS_ITALIC =>'',
  359. FS_BOLDITALIC =>'' ),
  360. /* Dejavu fonts */
  361. FF_DV_SANSSERIF => array(
  362. FS_NORMAL =>array('DejaVuSans.ttf'),
  363. FS_BOLD =>array('DejaVuSans-Bold.ttf','DejaVuSansBold.ttf'),
  364. FS_ITALIC =>array('DejaVuSans-Oblique.ttf','DejaVuSansOblique.ttf'),
  365. FS_BOLDITALIC =>array('DejaVuSans-BoldOblique.ttf','DejaVuSansBoldOblique.ttf') ),
  366. FF_DV_SANSSERIFMONO => array(
  367. FS_NORMAL =>array('DejaVuSansMono.ttf','DejaVuMonoSans.ttf'),
  368. FS_BOLD =>array('DejaVuSansMono-Bold.ttf','DejaVuMonoSansBold.ttf'),
  369. FS_ITALIC =>array('DejaVuSansMono-Oblique.ttf','DejaVuMonoSansOblique.ttf'),
  370. FS_BOLDITALIC =>array('DejaVuSansMono-BoldOblique.ttf','DejaVuMonoSansBoldOblique.ttf') ),
  371. FF_DV_SANSSERIFCOND => array(
  372. FS_NORMAL =>array('DejaVuSansCondensed.ttf','DejaVuCondensedSans.ttf'),
  373. FS_BOLD =>array('DejaVuSansCondensed-Bold.ttf','DejaVuCondensedSansBold.ttf'),
  374. FS_ITALIC =>array('DejaVuSansCondensed-Oblique.ttf','DejaVuCondensedSansOblique.ttf'),
  375. FS_BOLDITALIC =>array('DejaVuSansCondensed-BoldOblique.ttf','DejaVuCondensedSansBoldOblique.ttf') ),
  376. FF_DV_SERIF => array(
  377. FS_NORMAL =>array('DejaVuSerif.ttf'),
  378. FS_BOLD =>array('DejaVuSerif-Bold.ttf','DejaVuSerifBold.ttf'),
  379. FS_ITALIC =>array('DejaVuSerif-Italic.ttf','DejaVuSerifItalic.ttf'),
  380. FS_BOLDITALIC =>array('DejaVuSerif-BoldItalic.ttf','DejaVuSerifBoldItalic.ttf') ),
  381. FF_DV_SERIFCOND => array(
  382. FS_NORMAL =>array('DejaVuSerifCondensed.ttf','DejaVuCondensedSerif.ttf'),
  383. FS_BOLD =>array('DejaVuSerifCondensed-Bold.ttf','DejaVuCondensedSerifBold.ttf'),
  384. FS_ITALIC =>array('DejaVuSerifCondensed-Italic.ttf','DejaVuCondensedSerifItalic.ttf'),
  385. FS_BOLDITALIC =>array('DejaVuSerifCondensed-BoldItalic.ttf','DejaVuCondensedSerifBoldItalic.ttf') ),
  386. /* Placeholders for defined fonts */
  387. FF_USERFONT1 => array(
  388. FS_NORMAL =>'',
  389. FS_BOLD =>'',
  390. FS_ITALIC =>'',
  391. FS_BOLDITALIC =>'' ),
  392. FF_USERFONT2 => array(
  393. FS_NORMAL =>'',
  394. FS_BOLD =>'',
  395. FS_ITALIC =>'',
  396. FS_BOLDITALIC =>'' ),
  397. FF_USERFONT3 => array(
  398. FS_NORMAL =>'',
  399. FS_BOLD =>'',
  400. FS_ITALIC =>'',
  401. FS_BOLDITALIC =>'' ),
  402. );
  403. }
  404. //---------------
  405. // PUBLIC METHODS
  406. // Create the TTF file from the font specification
  407. function File($family,$style=FS_NORMAL) {
  408. $fam = @$this->font_files[$family];
  409. if( !$fam ) {
  410. JpGraphError::RaiseL(25046,$family);//("Specified TTF font family (id=$family) is unknown or does not exist. Please note that TTF fonts are not distributed with JpGraph for copyright reasons. You can find the MS TTF WEB-fonts (arial, courier etc) for download at http://corefonts.sourceforge.net/");
  411. }
  412. $ff = @$fam[$style];
  413. if( is_array($ff) ) {
  414. // There are several optional file names. They are tried in order
  415. // and the first one found is used
  416. $n = count($ff);
  417. } else {
  418. $n = 1;
  419. $ff = array($ff);
  420. }
  421. $i = 0;
  422. do {
  423. $f = $ff[$i];
  424. // All font families are guaranteed to have the normal style
  425. if( $f==='' )
  426. JpGraphError::RaiseL(25047,$this->style_names[$style],$this->font_files[$family][FS_NORMAL]);//('Style "'.$this->style_names[$style].'" is not available for font family '.$this->font_files[$family][FS_NORMAL].'.');
  427. if( !$f ) {
  428. JpGraphError::RaiseL(25048,$fam);//("Unknown font style specification [$fam].");
  429. }
  430. if ($family >= FF_MINCHO && $family <= FF_PGOTHIC) {
  431. $f = MBTTF_DIR.$f;
  432. } else {
  433. $f = TTF_DIR.$f;
  434. }
  435. ++$i;
  436. } while( $i < $n && (file_exists($f) === false || is_readable($f) === false) );
  437. if( !file_exists($f) ) {
  438. JpGraphError::RaiseL(25049,$f);//("Font file \"$f\" is not readable or does not exist.");
  439. }
  440. return $f;
  441. }
  442. function SetUserFont($aNormal,$aBold='',$aItalic='',$aBoldIt='') {
  443. $this->font_files[FF_USERFONT] =
  444. array(FS_NORMAL => $aNormal,
  445. FS_BOLD => $aBold,
  446. FS_ITALIC => $aItalic,
  447. FS_BOLDITALIC => $aBoldIt ) ;
  448. }
  449. function SetUserFont1($aNormal,$aBold='',$aItalic='',$aBoldIt='') {
  450. $this->font_files[FF_USERFONT1] =
  451. array(FS_NORMAL => $aNormal,
  452. FS_BOLD => $aBold,
  453. FS_ITALIC => $aItalic,
  454. FS_BOLDITALIC => $aBoldIt ) ;
  455. }
  456. function SetUserFont2($aNormal,$aBold='',$aItalic='',$aBoldIt='') {
  457. $this->font_files[FF_USERFONT2] =
  458. array(FS_NORMAL => $aNormal,
  459. FS_BOLD => $aBold,
  460. FS_ITALIC => $aItalic,
  461. FS_BOLDITALIC => $aBoldIt ) ;
  462. }
  463. function SetUserFont3($aNormal,$aBold='',$aItalic='',$aBoldIt='') {
  464. $this->font_files[FF_USERFONT3] =
  465. array(FS_NORMAL => $aNormal,
  466. FS_BOLD => $aBold,
  467. FS_ITALIC => $aItalic,
  468. FS_BOLDITALIC => $aBoldIt ) ;
  469. }
  470. } // Class
  471. //=============================================================================
  472. // CLASS SymChar
  473. // Description: Code values for some commonly used characters that
  474. // normally isn't available directly on the keyboard, for example
  475. // mathematical and greek symbols.
  476. //=============================================================================
  477. class SymChar {
  478. static function Get($aSymb,$aCapital=FALSE) {
  479. $iSymbols = array(
  480. /* Greek */
  481. array('alpha','03B1','0391'),
  482. array('beta','03B2','0392'),
  483. array('gamma','03B3','0393'),
  484. array('delta','03B4','0394'),
  485. array('epsilon','03B5','0395'),
  486. array('zeta','03B6','0396'),
  487. array('ny','03B7','0397'),
  488. array('eta','03B8','0398'),
  489. array('theta','03B8','0398'),
  490. array('iota','03B9','0399'),
  491. array('kappa','03BA','039A'),
  492. array('lambda','03BB','039B'),
  493. array('mu','03BC','039C'),
  494. array('nu','03BD','039D'),
  495. array('xi','03BE','039E'),
  496. array('omicron','03BF','039F'),
  497. array('pi','03C0','03A0'),
  498. array('rho','03C1','03A1'),
  499. array('sigma','03C3','03A3'),
  500. array('tau','03C4','03A4'),
  501. array('upsilon','03C5','03A5'),
  502. array('phi','03C6','03A6'),
  503. array('chi','03C7','03A7'),
  504. array('psi','03C8','03A8'),
  505. array('omega','03C9','03A9'),
  506. /* Money */
  507. array('euro','20AC'),
  508. array('yen','00A5'),
  509. array('pound','20A4'),
  510. /* Math */
  511. array('approx','2248'),
  512. array('neq','2260'),
  513. array('not','2310'),
  514. array('def','2261'),
  515. array('inf','221E'),
  516. array('sqrt','221A'),
  517. array('int','222B'),
  518. /* Misc */
  519. array('copy','00A9'),
  520. array('para','00A7'),
  521. array('tm','2122'), /* Trademark symbol */
  522. array('rtm','00AE'), /* Registered trademark */
  523. array('degree','00b0'),
  524. array('lte','2264'), /* Less than or equal */
  525. array('gte','2265'), /* Greater than or equal */
  526. );
  527. $n = count($iSymbols);
  528. $i=0;
  529. $found = false;
  530. $aSymb = strtolower($aSymb);
  531. while( $i < $n && !$found ) {
  532. $found = $aSymb === $iSymbols[$i++][0];
  533. }
  534. if( $found ) {
  535. $ca = $iSymbols[--$i];
  536. if( $aCapital && count($ca)==3 )
  537. $s = $ca[2];
  538. else
  539. $s = $ca[1];
  540. return sprintf('&#%04d;',hexdec($s));
  541. }
  542. else
  543. return '';
  544. }
  545. }
  546. ?>