diff --git a/VERSION b/VERSION index e4c0d46..a6a3a43 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.3 \ No newline at end of file +1.0.4 \ No newline at end of file diff --git a/src/Common/Autoloader.php b/src/Common/Autoloader.php index 9269232..7f9d88d 100644 --- a/src/Common/Autoloader.php +++ b/src/Common/Autoloader.php @@ -1,4 +1,5 @@ |null Value in RGB */ - public static function pointsToPixels(float $pValue = 0): float + public static function htmlToRGB(string $pValue): ?array { - if ($pValue == 0) { - return 0; + if ($pValue[0] == '#') { + $pValue = substr($pValue, 1); } - return $pValue / 0.75; + if (strlen($pValue) == 6) { + list($colorR, $colorG, $colorB) = [$pValue[0] . $pValue[1], $pValue[2] . $pValue[3], $pValue[4] . $pValue[5]]; + } elseif (strlen($pValue) == 3) { + list($colorR, $colorG, $colorB) = [$pValue[0] . $pValue[0], $pValue[1] . $pValue[1], $pValue[2] . $pValue[2]]; + } else { + return null; + } + + $colorR = hexdec($colorR); + $colorG = hexdec($colorG); + $colorB = hexdec($colorB); + + return [$colorR, $colorG, $colorB]; } + // Source : Inches /** - * Convert pixels to centimeters + * Convert inches to points * - * @param int $pValue Value in pixels + * @param float $pValue * * @return float */ - public static function pixelsToCentimeters(int $pValue = 0): float + public static function inchesToPoints(float $pValue): float { - // return $pValue * 0.028; - return ($pValue / self::DPI_96) * 2.54; + return $pValue * 72; } /** - * Convert centimeters width to pixels + * Convert inches width to twips * - * @param float $pValue Value in centimeters + * @param int $pValue * * @return int */ - public static function centimetersToPixels(float $pValue = 0): int + public static function inchesToTwips(int $pValue = 0): int { if ($pValue == 0) { return 0; } - return (int) round(($pValue / 2.54) * self::DPI_96); + return $pValue * 1440; } + // Source : Picas /** - * Convert degrees to angle + * Convert picas to points * - * @param int $pValue Degrees + * @param float $pValue * - * @return int + * @return float */ - public static function degreesToAngle(int $pValue = 0): int + public static function picasToPoints(float $pValue): float { - return (int) round($pValue * 60000); + return $pValue * 12; } + // Source : Pixels /** - * Convert angle to degrees + * Convert pixels to centimeters * - * @param int $pValue Angle + * @param int $pValue Value in pixels * * @return float */ - public static function angleToDegrees(int $pValue = 0): float + public static function pixelsToCentimeters(int $pValue = 0): float { - if ($pValue == 0) { - return 0; - } - - return round($pValue / 60000); + // return $pValue * 0.028; + return ($pValue / self::DPI_96) * 2.54; } /** - * Convert centimeters width to twips + * Convert pixels to EMU * - * @param int $pValue + * @param float $pValue Value in pixels * * @return float */ - public static function centimetersToTwips(int $pValue = 0): float + public static function pixelsToEmu(float $pValue = 0): float { - if ($pValue == 0) { - return 0; - } + return round($pValue * 9525); + } - return $pValue * 566.928; + /** + * Convert pixels to points + * + * @param int $pValue Value in pixels + * + * @return float + */ + public static function pixelsToPoints(int $pValue = 0): float + { + return $pValue * 0.75; } + // Source : Points /** - * Convert twips width to centimeters + * Convert points width to centimeters * - * @param int $pValue + * @param float $pValue Value in points * * @return float */ - public static function twipsToCentimeters(int $pValue = 0): float + public static function pointsToCentimeters(float $pValue = 0): float { if ($pValue == 0) { return 0; } - return $pValue / 566.928; + return (($pValue / 0.75) / self::DPI_96) * 2.54; } /** - * Convert inches width to twips + * Convert points to emu * - * @param int $pValue + * @param float $pValue * * @return int */ - public static function inchesToTwips(int $pValue = 0): int + public static function pointsToEmu(float $pValue = 0): int { if ($pValue == 0) { return 0; } - return $pValue * 1440; + return (int) round(($pValue / 0.75) * 9525); } /** - * Convert twips width to inches + * Convert points width to pixels * - * @param int $pValue + * @param float $pValue Value in points * * @return float */ - public static function twipsToInches(int $pValue = 0): float + public static function pointsToPixels(float $pValue = 0): float { if ($pValue == 0) { return 0; } - return $pValue / 1440; + return $pValue / 0.75; } + // Source : Twips /** - * Convert twips width to pixels + * Convert twips width to centimeters * * @param int $pValue * * @return float */ - public static function twipsToPixels(int $pValue = 0): float + public static function twipsToCentimeters(int $pValue = 0): float { if ($pValue == 0) { return 0; } - return round($pValue / 15); + return $pValue / 566.928; } /** - * Convert points to emu + * Convert twips width to inches * - * @param float $pValue + * @param int $pValue * - * @return int + * @return float */ - public static function pointsToEmu(float $pValue = 0): int + public static function twipsToInches(int $pValue = 0): float { if ($pValue == 0) { return 0; } - return (int) round(($pValue / 0.75) * 9525); + return $pValue / 1440; } /** - * Convert HTML hexadecimal to RGB + * Convert twips width to pixels * - * @param string $pValue HTML Color in hexadecimal + * @param int $pValue * - * @return array|null Value in RGB + * @return float */ - public static function htmlToRGB(string $pValue): ?array + public static function twipsToPixels(int $pValue = 0): float { - if ($pValue[0] == '#') { - $pValue = substr($pValue, 1); - } - - if (strlen($pValue) == 6) { - list($colorR, $colorG, $colorB) = [$pValue[0] . $pValue[1], $pValue[2] . $pValue[3], $pValue[4] . $pValue[5]]; - } elseif (strlen($pValue) == 3) { - list($colorR, $colorG, $colorB) = [$pValue[0] . $pValue[0], $pValue[1] . $pValue[1], $pValue[2] . $pValue[2]]; - } else { - return null; + if ($pValue == 0) { + return 0; } - $colorR = hexdec($colorR); - $colorG = hexdec($colorG); - $colorB = hexdec($colorB); - - return [$colorR, $colorG, $colorB]; + return round($pValue / 15); } } diff --git a/src/Common/File.php b/src/Common/File.php index 7f35870..33d72ef 100644 --- a/src/Common/File.php +++ b/src/Common/File.php @@ -1,4 +1,5 @@ assertEquals(round($value / 60000), Drawing::angleToDegrees($value)); } + public function testInchesPoints(): void + { + $value = rand(1, 100); + + $this->assertEquals(0, Drawing::inchesToPoints(0)); + $this->assertEquals($value * 72, Drawing::inchesToPoints($value)); + $this->assertEquals($value / 100 * 72, Drawing::inchesToPoints($value / 100)); + } + + public function testPicasPoints(): void + { + $value = rand(1, 100); + + $this->assertEquals(0, Drawing::picasToPoints(0)); + $this->assertEquals($value * 12, Drawing::picasToPoints($value)); + $this->assertEquals($value / 100 * 12, Drawing::picasToPoints($value / 100)); + } + public function testPixelsCentimeters(): void { $value = rand(1, 100); diff --git a/tests/Common/Tests/FileTest.php b/tests/Common/Tests/FileTest.php index 557644f..7632b32 100644 --- a/tests/Common/Tests/FileTest.php +++ b/tests/Common/Tests/FileTest.php @@ -1,4 +1,5 @@