Skip to content

Commit

Permalink
Added conversion from centimeters to points
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Aug 1, 2021
1 parent b446746 commit 7b4e636
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Common/Drawing.php
Expand Up @@ -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
*
Expand Down
7 changes: 7 additions & 0 deletions tests/Common/Tests/DrawingTest.php
Expand Up @@ -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);
Expand Down

0 comments on commit 7b4e636

Please sign in to comment.