File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,22 @@ public static function pointsToCentimeters(int $pValue = 0): float
7777 return (($ pValue / 0.75 ) / self ::DPI_96 ) * 2.54 ;
7878 }
7979
80+ /**
81+ * Convert centimeters width to points
82+ *
83+ * @param float $pValue Value in centimeters
84+ *
85+ * @return float
86+ */
87+ public static function centimetersToPoints (float $ pValue = 0 ): float
88+ {
89+ if ($ pValue == 0 ) {
90+ return 0 ;
91+ }
92+
93+ return ($ pValue / 2.54 ) * self ::DPI_96 * 0.75 ;
94+ }
95+
8096 /**
8197 * Convert points width to pixels
8298 *
Original file line number Diff line number Diff line change @@ -74,6 +74,13 @@ public function testPointsCentimeters(): void
7474 $ this ->assertEquals ($ value / 0.75 / Drawing::DPI_96 * 2.54 , Drawing::pointsToCentimeters ($ value ));
7575 }
7676
77+ public function testCentimetersPoints (): void
78+ {
79+ $ this ->assertEquals (0 , Drawing::centimetersToPoints ());
80+ $ this ->assertEquals (28.346456692913385 , Drawing::centimetersToPoints (1 ));
81+ $ this ->assertEquals (31.181102362204726 , Drawing::centimetersToPoints (1.1 ));
82+ }
83+
7784 public function testTwips (): void
7885 {
7986 $ value = rand (1 , 100 );
You can’t perform that action at this time.
0 commit comments