Translated using Weblate (Slovenian)
[phpmyadmin.git] / libraries / Font.class.php
blob78d561f142210b02b07422bea1c8248dadc2d8ff
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 * @return array with characters and corresponding width modifier
23 * @access public
25 public static function getCharLists()
27 // list of characters and their width modifiers
28 $charLists = array();
30 //ijl
31 $charLists[] = array("chars" => array("i", "j", "l"), "modifier" => 0.23);
32 //f
33 $charLists[] = array("chars" => array("f"), "modifier" => 0.27);
34 //tI
35 $charLists[] = array("chars" => array("t", "I"), "modifier" => 0.28);
36 //r
37 $charLists[] = array("chars" => array("r"), "modifier" => 0.34);
38 //1
39 $charLists[] = array("chars" => array("1"), "modifier" => 0.49);
40 //cksvxyzJ
41 $charLists[] = array(
42 "chars" => array("c", "k", "s", "v", "x", "y", "z", "J"),
43 "modifier" => 0.5
45 //abdeghnopquL023456789
46 $charLists[] = array(
47 "chars" => array(
48 "a", "b", "d", "e", "g", "h", "n", "o", "p", "q", "u", "L",
49 "0", "2", "3", "4", "5", "6", "7", "8", "9"
51 "modifier" => 0.56
53 //FTZ
54 $charLists[] = array("chars" => array("F", "T", "Z"), "modifier" => 0.61);
55 //ABEKPSVXY
56 $charLists[] = array(
57 "chars" => array("A", "B", "E", "K", "P", "S", "V", "X", "Y"),
58 "modifier" => 0.67
60 //wCDHNRU
61 $charLists[] = array(
62 "chars" => array("w", "C", "D", "H", "N", "R", "U"),
63 "modifier" => 0.73
65 //GOQ
66 $charLists[] = array("chars" => array("G", "O", "Q"), "modifier" => 0.78);
67 //mM
68 $charLists[] = array("chars" => array("m", "M"), "modifier" => 0.84);
69 //W
70 $charLists[] = array("chars" => array("W"), "modifier" => 0.95);
71 //" "
72 $charLists[] = array("chars" => array(" "), "modifier" => 0.28);
74 return $charLists;
77 /**
78 * Get width of string/text
80 * The text element width is calculated depending on font name
81 * and font size.
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
89 * @access public
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"])
96 ) {
97 $charLists = self::getCharLists();
101 * Start by counting the width, giving each character a modifying value
103 $count = 0;
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
112 //all other chars
113 $count = $count
114 + (/*overload*/mb_strlen(preg_replace("/[a-z0-9]/i", "", $text)) * 0.3);
116 $modifier = 1;
117 $font = /*overload*/mb_strtolower($font);
118 switch ($font) {
120 * no modifier for arial and sans-serif
122 case 'arial':
123 case 'sans-serif':
124 break;
126 * .92 modifier for time, serif, brushscriptstd, and californian fb
128 case 'times':
129 case 'serif':
130 case 'brushscriptstd':
131 case 'californian fb':
132 $modifier = .92;
133 break;
135 * 1.23 modifier for broadway
137 case 'broadway':
138 $modifier = 1.23;
139 break;
141 $textWidth = $count * $fontSize;
142 return (int)ceil($textWidth * $modifier);