diff --git a/src/Common/Drawing.php b/src/Common/Drawing.php index 1f248da..b4674de 100644 --- a/src/Common/Drawing.php +++ b/src/Common/Drawing.php @@ -77,6 +77,22 @@ public static function pointsToCentimeters(int $pValue = 0): float return (($pValue / 0.75) / self::DPI_96) * 2.54; } + /** + * Convert centimeters width to points + * + * @param float $pValue Value in centimeters + * + * @return float + */ + public static function centimetersToPoints(float $pValue = 0): float + { + if ($pValue == 0) { + return 0; + } + + return ($pValue / 2.54) * self::DPI_96 * 0.75; + } + /** * Convert points width to pixels * diff --git a/tests/Common/Tests/DrawingTest.php b/tests/Common/Tests/DrawingTest.php index a8fa1b8..a545c06 100644 --- a/tests/Common/Tests/DrawingTest.php +++ b/tests/Common/Tests/DrawingTest.php @@ -74,6 +74,13 @@ public function testPointsCentimeters(): void $this->assertEquals($value / 0.75 / Drawing::DPI_96 * 2.54, Drawing::pointsToCentimeters($value)); } + public function testCentimetersPoints(): void + { + $this->assertEquals(0, Drawing::centimetersToPoints()); + $this->assertEquals(28.346456692913385, Drawing::centimetersToPoints(1)); + $this->assertEquals(31.181102362204726, Drawing::centimetersToPoints(1.1)); + } + public function testTwips(): void { $value = rand(1, 100);