|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of PHPOffice Common |
|
4
|
|
|
* |
|
5
|
|
|
* PHPOffice Common is free software distributed under the terms of the GNU Lesser |
|
6
|
|
|
* General Public License version 3 as published by the Free Software Foundation. |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. For the full list of |
|
10
|
|
|
* contributors, visit https://github.com/PHPOffice/Common/contributors. |
|
11
|
|
|
* |
|
12
|
|
|
* @link https://github.com/PHPOffice/Common |
|
13
|
|
|
* @copyright 2009-2016 PHPOffice Common contributors |
|
14
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace PhpOffice\Common; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Font |
|
21
|
|
|
*/ |
|
22
|
|
|
class Font |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Calculate an (approximate) pixel size, based on a font points size |
|
26
|
|
|
* |
|
27
|
|
|
* @param int $fontSizeInPoints Font size (in points) |
|
28
|
|
|
* @return int Font size (in pixels) |
|
29
|
|
|
*/ |
|
30
|
1 |
|
public static function fontSizeToPixels($fontSizeInPoints = 12) |
|
31
|
|
|
{ |
|
32
|
1 |
|
return ((16 / 12) * $fontSizeInPoints); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Calculate an (approximate) pixel size, based on inch size |
|
37
|
|
|
* |
|
38
|
|
|
* @param int $sizeInInch Font size (in inch) |
|
39
|
|
|
* @return int Size (in pixels) |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public static function inchSizeToPixels($sizeInInch = 1) |
|
42
|
|
|
{ |
|
43
|
1 |
|
return ($sizeInInch * 96); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Calculate an (approximate) pixel size, based on centimeter size |
|
48
|
|
|
* |
|
49
|
|
|
* @param int $sizeInCm Font size (in centimeters) |
|
50
|
|
|
* @return int Size (in pixels) |
|
51
|
|
|
*/ |
|
52
|
1 |
|
public static function centimeterSizeToPixels($sizeInCm = 1) |
|
53
|
|
|
{ |
|
54
|
1 |
|
return ($sizeInCm * 37.795275591); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Convert centimeter to twip |
|
59
|
|
|
* |
|
60
|
|
|
* @param int $sizeInCm |
|
61
|
|
|
* @return double |
|
62
|
|
|
*/ |
|
63
|
1 |
|
public static function centimeterSizeToTwips($sizeInCm = 1) |
|
64
|
|
|
{ |
|
65
|
1 |
|
return $sizeInCm / 2.54 * 1440; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Convert inch to twip |
|
70
|
|
|
* |
|
71
|
|
|
* @param int $sizeInInch |
|
72
|
|
|
* @return double |
|
73
|
|
|
*/ |
|
74
|
1 |
|
public static function inchSizeToTwips($sizeInInch = 1) |
|
75
|
|
|
{ |
|
76
|
1 |
|
return $sizeInInch * 1440; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Convert pixel to twip |
|
81
|
|
|
* |
|
82
|
|
|
* @param int $sizeInPixel |
|
83
|
|
|
* @return double |
|
84
|
|
|
*/ |
|
85
|
1 |
|
public static function pixelSizeToTwips($sizeInPixel = 1) |
|
86
|
|
|
{ |
|
87
|
1 |
|
return $sizeInPixel / 96 * 1440; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Calculate twip based on point size, used mainly for paragraph spacing |
|
92
|
|
|
* |
|
93
|
|
|
* @param integer $sizeInPoint Size in point |
|
94
|
|
|
* @return integer Size (in twips) |
|
95
|
|
|
*/ |
|
96
|
1 |
|
public static function pointSizeToTwips($sizeInPoint = 1) |
|
97
|
|
|
{ |
|
98
|
1 |
|
return $sizeInPoint / 72 * 1440; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|