Skip to content

Commit

Permalink
Merge pull request #42 from Progi1984/cm2pt
Browse files Browse the repository at this point in the history
Added conversion from centimeters to points
  • Loading branch information
Progi1984 authored Aug 1, 2021
2 parents b446746 + 7b4e636 commit da4c7ad
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 da4c7ad

Please sign in to comment.