Temporary fix for gobs of logged deprecation warnings from the calendar module.
[openemr.git] / phpmyadmin / libraries / Font.class.php
blobb4c2024e091e38ccb3c406dc2d1ca2d1f79bf2e7
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Class with Font related methods.
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * Class with Font related methods.
15 * @package PhpMyAdmin
17 class PMA_Font
19 /**
20 * Get list with characters and the corresponding width modifiers.
22 * @param string $font name of the font like Arial,sans-serif etc
24 * @return array with characters and corresponding width modifier
25 * @access public
27 public static function getCharLists($font)
29 // list of characters and their width modifiers
30 $charLists = array();
32 //ijl
33 $charLists[] = array("chars" => array("i", "j", "l"), "modifier" => 0.23);
34 //f
35 $charLists[] = array("chars" => array("f"), "modifier" => 0.27);
36 //tI
37 $charLists[] = array("chars" => array("t", "I"), "modifier" => 0.28);
38 //r
39 $charLists[] = array("chars" => array("r"), "modifier" => 0.34);
40 //1
41 $charLists[] = array("chars" => array("1"), "modifier" => 0.49);
42 //cksvxyzJ
43 $charLists[] = array(
44 "chars" => array("c", "k", "s", "v", "x", "y", "z", "J"),
45 "modifier" => 0.5
47 //abdeghnopquL023456789
48 $charLists[] = array(
49 "chars" => array(
50 "a", "b", "d", "e", "g", "h", "n", "o", "p", "q", "u", "L",
51 "0", "2", "3", "4", "5", "6", "7", "8", "9"
53 "modifier" => 0.56
55 //FTZ
56 $charLists[] = array("chars" => array("F", "T", "Z"), "modifier" => 0.61);
57 //ABEKPSVXY
58 $charLists[] = array(
59 "chars" => array("A", "B", "E", "K", "P", "S", "V", "X", "Y"),
60 "modifier" => 0.67
62 //wCDHNRU
63 $charLists[] = array(
64 "chars" => array("w", "C", "D", "H", "N", "R", "U"),
65 "modifier" => 0.73
67 //GOQ
68 $charLists[] = array("chars" => array("G", "O", "Q"), "modifier" => 0.78);
69 //mM
70 $charLists[] = array("chars" => array("m", "M"), "modifier" => 0.84);
71 //W
72 $charLists[] = array("chars" => array("W"), "modifier" => 0.95);
73 //" "
74 $charLists[] = array("chars" => array(" "), "modifier" => 0.28);
76 return $charLists;
79 /**
80 * Get width of string/text
82 * The text element width is calculated depending on font name
83 * and font size.
85 * @param string $text string of which the width will be calculated
86 * @param string $font name of the font like Arial,sans-serif etc
87 * @param integer $fontSize size of font
88 * @param array $charLists list of characters and their width modifiers
90 * @return integer width of the text
91 * @access public
93 public static function getStringWidth($text, $font, $fontSize, $charLists = null)
95 if (empty($charLists) || !is_array($charLists)
96 || !isset($charLists[0]["chars"]) || !is_array($charLists[0]["chars"])
97 || !isset($charLists[0]["modifier"])
98 ) {
99 $charLists = self::getCharLists($font);
103 * Start by counting the width, giving each character a modifying value
105 $count = 0;
107 foreach ($charLists as $charList) {
108 $count += ((strlen($text)
109 - strlen(str_replace($charList["chars"], "", $text))
110 ) * $charList["modifier"]);
113 $text = str_replace(" ", "", $text);//remove the " "'s
114 //all other chars
115 $count = $count + (strlen(preg_replace("/[a-z0-9]/i", "", $text)) * 0.3);
117 $modifier = 1;
118 $font = strtolower($font);
119 switch ($font) {
121 * no modifier for arial and sans-serif
123 case 'arial':
124 case 'sans-serif':
125 break;
127 * .92 modifer for time, serif, brushscriptstd, and californian fb
129 case 'times':
130 case 'serif':
131 case 'brushscriptstd':
132 case 'californian fb':
133 $modifier = .92;
134 break;
136 * 1.23 modifier for broadway
138 case 'broadway':
139 $modifier = 1.23;
140 break;
142 $textWidth = $count*$fontSize;
143 return ceil($textWidth*$modifier);