Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EPS & SVG Rendering usable on international locales #84

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/Renderer/Image/EpsImageBackEnd.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function scale(float $size) : void
throw new RuntimeException('No image has been started');
}

$this->eps .= sprintf("%1\$s %1\$s s\n", round($size, self::PRECISION));
$this->eps .= sprintf("%1\$1.".self::PRECISION."F %1\$1.".self::PRECISION."F s\n", round($size, self::PRECISION));
}

public function translate(float $x, float $y) : void
Expand All @@ -84,7 +84,7 @@ public function translate(float $x, float $y) : void
throw new RuntimeException('No image has been started');
}

$this->eps .= sprintf("%s %s t\n", round($x, self::PRECISION), round($y, self::PRECISION));
$this->eps .= sprintf("%1.".self::PRECISION."F %1.".self::PRECISION."F t\n", round($x, self::PRECISION), round($y, self::PRECISION));
}

public function rotate(int $degrees) : void
Expand Down Expand Up @@ -176,13 +176,13 @@ private function drawPathOperations(Iterable $ops, &$fromX, &$fromY) : string
case $op instanceof Move:
$fromX = $toX = round($op->getX(), self::PRECISION);
$fromY = $toY = round($op->getY(), self::PRECISION);
$pathData[] = sprintf('%s %s m', $toX, $toY);
$pathData[] = sprintf('%1.".self::PRECISION."F %1.".self::PRECISION."F m', $toX, $toY);
break;

case $op instanceof Line:
$fromX = $toX = round($op->getX(), self::PRECISION);
$fromY = $toY = round($op->getY(), self::PRECISION);
$pathData[] = sprintf('%s %s l', $toX, $toY);
$pathData[] = sprintf('%1.".self::PRECISION."F %1.".self::PRECISION."F l', $toX, $toY);
break;

case $op instanceof EllipticArc:
Expand All @@ -196,7 +196,7 @@ private function drawPathOperations(Iterable $ops, &$fromX, &$fromY) : string
$y2 = round($op->getY2(), self::PRECISION);
$fromX = $x3 = round($op->getX3(), self::PRECISION);
$fromY = $y3 = round($op->getY3(), self::PRECISION);
$pathData[] = sprintf('%s %s %s %s %s %s c', $x1, $y1, $x2, $y2, $x3, $y3);
$pathData[] = sprintf('%1.".self::PRECISION."F %1.".self::PRECISION."F %1.".self::PRECISION."F %1.".self::PRECISION."F %1.".self::PRECISION."F %1.".self::PRECISION."F c', $x1, $y1, $x2, $y2, $x3, $y3);
break;

case $op instanceof Close:
Expand Down Expand Up @@ -271,7 +271,7 @@ private function createGradientFill(Gradient $gradient, float $x, float $y, floa
switch ($gradient->getType()) {
case GradientType::HORIZONTAL():
$this->eps .= sprintf(
" /Coords [ %s %s %s %s ]\n",
" /Coords [ %1.".self::PRECISION."F %1.".self::PRECISION."F %1.".self::PRECISION."F %1.".self::PRECISION."F ]\n",
round($x, self::PRECISION),
round($y, self::PRECISION),
round($x + $width, self::PRECISION),
Expand All @@ -281,7 +281,7 @@ private function createGradientFill(Gradient $gradient, float $x, float $y, floa

case GradientType::VERTICAL():
$this->eps .= sprintf(
" /Coords [ %s %s %s %s ]\n",
" /Coords [ %1.".self::PRECISION."F %1.".self::PRECISION."F %1.".self::PRECISION."F %1.".self::PRECISION."F ]\n",
round($x, self::PRECISION),
round($y, self::PRECISION),
round($x, self::PRECISION),
Expand All @@ -291,7 +291,7 @@ private function createGradientFill(Gradient $gradient, float $x, float $y, floa

case GradientType::DIAGONAL():
$this->eps .= sprintf(
" /Coords [ %s %s %s %s ]\n",
" /Coords [ %1.".self::PRECISION."F %1.".self::PRECISION."F %1.".self::PRECISION."F %1.".self::PRECISION."F ]\n",
round($x, self::PRECISION),
round($y, self::PRECISION),
round($x + $width, self::PRECISION),
Expand All @@ -301,7 +301,7 @@ private function createGradientFill(Gradient $gradient, float $x, float $y, floa

case GradientType::INVERSE_DIAGONAL():
$this->eps .= sprintf(
" /Coords [ %s %s %s %s ]\n",
" /Coords [ %1.".self::PRECISION."F %1.".self::PRECISION."F %1.".self::PRECISION."F %1.".self::PRECISION."F ]\n",
round($x, self::PRECISION),
round($y + $height, self::PRECISION),
round($x + $width, self::PRECISION),
Expand All @@ -314,7 +314,7 @@ private function createGradientFill(Gradient $gradient, float $x, float $y, floa
$centerY = ($y + $height) / 2;

$this->eps .= sprintf(
" /Coords [ %s %s 0 %s %s %s ]\n",
" /Coords [ %1.".self::PRECISION."F %1.".self::PRECISION."F 0 %1.".self::PRECISION."F %1.".self::PRECISION."F %1.".self::PRECISION."F ]\n",
round($centerX, self::PRECISION),
round($centerY, self::PRECISION),
round($centerX, self::PRECISION),
Expand Down Expand Up @@ -354,12 +354,12 @@ private function getColorSetString(ColorInterface $color) : string
private function getColorString(ColorInterface $color) : string
{
if ($color instanceof Rgb) {
return sprintf('%s %s %s', $color->getRed() / 255, $color->getGreen() / 255, $color->getBlue() / 255);
return sprintf("%1.".self::PRECISION."F %1.".self::PRECISION."F %1.".self::PRECISION."F", $color->getRed() / 255, $color->getGreen() / 255, $color->getBlue() / 255);
}

if ($color instanceof Cmyk) {
return sprintf(
'%s %s %s %s',
"% %1.".self::PRECISION."F %1.".self::PRECISION."F %1.".self::PRECISION."F",
$color->getCyan() / 100,
$color->getMagenta() / 100,
$color->getYellow() / 100,
Expand All @@ -368,7 +368,7 @@ private function getColorString(ColorInterface $color) : string
}

if ($color instanceof Gray) {
return sprintf('%s', $color->getGray() / 100);
return sprintf("%1.".self::PRECISION."F", $color->getGray() / 100);
}

return $this->getColorString($color->toCmyk());
Expand Down
12 changes: 6 additions & 6 deletions src/Renderer/Image/SvgImageBackEnd.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function scale(float $size) : void
$this->xmlWriter->startElement('g');
$this->xmlWriter->writeAttribute(
'transform',
sprintf('scale(%s)', round($size, self::PRECISION))
sprintf('scale(%1.'.self::PRECISION.'F)', round($size, self::PRECISION))
);
++$this->stack[$this->currentStack];
}
Expand All @@ -111,7 +111,7 @@ public function translate(float $x, float $y) : void
$this->xmlWriter->startElement('g');
$this->xmlWriter->writeAttribute(
'transform',
sprintf('translate(%s,%s)', round($x, self::PRECISION), round($y, self::PRECISION))
sprintf('translate(%1.'.self::PRECISION.'F,%1.'.self::PRECISION.'F)', round($x, self::PRECISION), round($y, self::PRECISION))
);
++$this->stack[$this->currentStack];
}
Expand Down Expand Up @@ -222,23 +222,23 @@ private function startPathElement(Path $path) : void
switch (true) {
case $op instanceof Move:
$pathData[] = sprintf(
'M%s %s',
'M%1.'.self::PRECISION.'F %1.'.self::PRECISION.'F',
round($op->getX(), self::PRECISION),
round($op->getY(), self::PRECISION)
);
break;

case $op instanceof Line:
$pathData[] = sprintf(
'L%s %s',
'L%1.'.self::PRECISION.'F %1.'.self::PRECISION.'F',
round($op->getX(), self::PRECISION),
round($op->getY(), self::PRECISION)
);
break;

case $op instanceof EllipticArc:
$pathData[] = sprintf(
'A%s %s %s %u %u %s %s',
'A%1.'.self::PRECISION.'F %1.'.self::PRECISION.'F %1.'.self::PRECISION.'F %u %u %1.'.self::PRECISION.'F %1.'.self::PRECISION.'F',
round($op->getXRadius(), self::PRECISION),
round($op->getYRadius(), self::PRECISION),
round($op->getXAxisAngle(), self::PRECISION),
Expand All @@ -251,7 +251,7 @@ private function startPathElement(Path $path) : void

case $op instanceof Curve:
$pathData[] = sprintf(
'C%s %s %s %s %s %s',
'C%1.'.self::PRECISION.'F %1.'.self::PRECISION.'F %1.'.self::PRECISION.'F %1.'.self::PRECISION.'F %1.'.self::PRECISION.'F %1.'.self::PRECISION.'F',
round($op->getX1(), self::PRECISION),
round($op->getY1(), self::PRECISION),
round($op->getX2(), self::PRECISION),
Expand Down