Replies: 2 comments 3 replies
-
I think this is beyond the capabilities of the current implementation. You would need to implement the drawing algorithm in a way that it checks the state of the neighbour modules and draw the block with rounded corners accordingly. The SVG module is probably the easiest to implement in that way, see the current implementation: php-qrcode/src/Output/QRMarkup.php Lines 204 to 229 in 5a110e7 |
Beta Was this translation helpful? Give feedback.
2 replies
-
I overridden the function in this way, which worked for me : /**
* returns a path segment for a single module
*
* @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d
*/
protected function module(int $x, int $y, int $M_TYPE):string{
if(!$this->options->drawLightModules && !$this->matrix->check($x, $y)){
return '';
}
if($this->options->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->options->keepAsSquare)){
$r = $this->options->circleRadius;
return sprintf(
'M%1$s %2$s a%3$s %3$s 0 1 0 %4$s 0 a%3$s %3$s 0 1 0 -%4$s 0Z',
($x + 0.5 - $r),
($y + 0.5),
$r,
($r * 2)
);
}
// round corners
// corner top left, top right, bottom left et bottom right
if (!$this->matrix->check($x, $y +1) && !$this->matrix->check($x -1, $y) && !$this->matrix->check($x + 1, $y) && !$this->matrix->check($x, $y -1)) {
return sprintf(
'M%1$s %2$s h0.5 a0.25 0.25 0 0 0 0.25 -0.25 v-0.5 a0.25 0.25 0 0 0 -0.25 -0.25 h-0.5 a0.25 0.25 0 0 0 -0.25 0.25 v0.5 a0.25 0.25 0 0 0 0.25 0.25 Z',
$x + 0.25,
$y + 1,
);
}
// corner top left et top right
if (!$this->matrix->check($x, $y -1) && !$this->matrix->check($x -1, $y) && !$this->matrix->check($x + 1, $y)) {
return sprintf(
'M%1$s %2$s h1 v-0.75 a0.25 0.25 0 0 0 -0.25 -0.25 h-0.5 a0.25 0.25 0 0 0 -0.25 0.25 Z',
$x,
$y + 1,
);
}
// corner top left et bottom left
if (!$this->matrix->check($x, $y -1) && !$this->matrix->check($x -1, $y) && !$this->matrix->check($x, $y + 1)) {
return sprintf(
'M%1$s %2$s h0.75 v-1 h-0.75 a0.25 0.25 0 0 0 -0.25 0.25 v0.5 a0.25 0.25 0 0 0 0.25 0.25 Z',
$x + 0.25,
$y + 1,
);
}
// corner top right et bottom right
if (!$this->matrix->check($x, $y -1) && !$this->matrix->check($x + 1, $y) && !$this->matrix->check($x, $y + 1)) {
return sprintf(
'M%1$s %2$s h0.75 a0.25 0.25 0 0 0 0.25 -0.25 v-0.5 a0.25 0.25 0 0 0 -0.25 -0.25 h-0.75 Z',
$x,
$y + 1,
);
}
// corner bottom left et bottom right
if (!$this->matrix->check($x, $y +1) && !$this->matrix->check($x -1, $y) && !$this->matrix->check($x + 1, $y)) {
return sprintf(
'M%1$s %2$s h0.5 a0.25 0.25 0 0 0 0.25 -0.25 v-0.75 h-1 v0.75 a0.25 0.25 0 0 0 0.25 0.25 Z',
$x + 0.25,
$y + 1,
);
}
// corner top left
if (!$this->matrix->check($x, $y -1) && !$this->matrix->check($x -1, $y)) {
return sprintf(
'M%1$s %2$s h1 v-1 h-0.75 a0.25 0.25 0 0 0 -0.25 0.25 Z',
$x,
$y + 1,
);
}
// corner top right
if (!$this->matrix->check($x, $y -1) && !$this->matrix->check($x + 1, $y)) {
return sprintf(
'M%1$s %2$s h1 v-0.75 a0.25 0.25 0 0 0 -0.25 -0.25 h-0.75 Z',
$x,
$y + 1,
);
}
// corner bottom right
if (!$this->matrix->check($x, $y +1) && !$this->matrix->check($x +1, $y)) {
return sprintf(
'M%1$s %2$s h0.75 a0.25 0.25 0 0 0 0.25 -0.25 v-0.75 h-1 Z',
$x,
$y + 1,
);
}
// corner bottom left
if (!$this->matrix->check($x, $y +1) && !$this->matrix->check($x -1, $y)) {
return sprintf(
'M%1$s %2$s h0.75 v-1 h-1 v0.75 a0.25 0.25 0 0 0 0.25 0.25 Z',
$x + 0.25,
$y + 1,
);
}
return sprintf('M%1$s %2$s h1 v1 h-1Z', $x, $y);
}
}
Hope that will help someone. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there! I want to have bars with rounded corners, not just plain straight-edged ones.
How can I achieve that? With my own output interface? Or, maybe it should be a param in existing output interface?
Could you please tell me where to dig?
Beta Was this translation helpful? Give feedback.
All reactions