2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Class with Font related methods.
8 if (! defined('PHPMYADMIN')) {
13 * Class with Font related methods.
20 * Get list with characters and the corresponding width modifiers.
22 * @return array with characters and corresponding width modifier
25 public static function getCharLists()
27 // list of characters and their width modifiers
31 $charLists[] = array("chars" => array("i", "j", "l"), "modifier" => 0.23);
33 $charLists[] = array("chars" => array("f"), "modifier" => 0.27);
35 $charLists[] = array("chars" => array("t", "I"), "modifier" => 0.28);
37 $charLists[] = array("chars" => array("r"), "modifier" => 0.34);
39 $charLists[] = array("chars" => array("1"), "modifier" => 0.49);
42 "chars" => array("c", "k", "s", "v", "x", "y", "z", "J"),
45 //abdeghnopquL023456789
48 "a", "b", "d", "e", "g", "h", "n", "o", "p", "q", "u", "L",
49 "0", "2", "3", "4", "5", "6", "7", "8", "9"
54 $charLists[] = array("chars" => array("F", "T", "Z"), "modifier" => 0.61);
57 "chars" => array("A", "B", "E", "K", "P", "S", "V", "X", "Y"),
62 "chars" => array("w", "C", "D", "H", "N", "R", "U"),
66 $charLists[] = array("chars" => array("G", "O", "Q"), "modifier" => 0.78);
68 $charLists[] = array("chars" => array("m", "M"), "modifier" => 0.84);
70 $charLists[] = array("chars" => array("W"), "modifier" => 0.95);
72 $charLists[] = array("chars" => array(" "), "modifier" => 0.28);
78 * Get width of string/text
80 * The text element width is calculated depending on font name
83 * @param string $text string of which the width will be calculated
84 * @param string $font name of the font like Arial,sans-serif etc
85 * @param integer $fontSize size of font
86 * @param array $charLists list of characters and their width modifiers
88 * @return integer width of the text
91 public static function getStringWidth($text, $font, $fontSize, $charLists = null)
93 if (empty($charLists) ||
!is_array($charLists)
94 ||
!isset($charLists[0]["chars"]) ||
!is_array($charLists[0]["chars"])
95 ||
!isset($charLists[0]["modifier"])
97 $charLists = self
::getCharLists();
101 * Start by counting the width, giving each character a modifying value
105 foreach ($charLists as $charList) {
106 $count +
= ((/*overload*/mb_strlen($text)
107 - /*overload*/mb_strlen(str_replace($charList["chars"], "", $text))
108 ) * $charList["modifier"]);
111 $text = str_replace(" ", "", $text);//remove the " "'s
114 +
(/*overload*/mb_strlen(preg_replace("/[a-z0-9]/i", "", $text)) * 0.3);
117 $font = /*overload*/mb_strtolower($font);
120 * no modifier for arial and sans-serif
126 * .92 modifier for time, serif, brushscriptstd, and californian fb
130 case 'brushscriptstd':
131 case 'californian fb':
135 * 1.23 modifier for broadway
141 $textWidth = $count * $fontSize;
142 return (int)ceil($textWidth * $modifier);