Skip to content

Commit

Permalink
Merge pull request endroid#273 from tohokuaiki/svg_option_block_id
Browse files Browse the repository at this point in the history
add SvgWriter option for xlink:href
  • Loading branch information
endroid authored Oct 7, 2020
2 parents dcb70ea + c3ceeaa commit 58d5872
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Writer/SvgWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public function writeString(QrCodeInterface $qrCode): string
$svg->addChild('defs');

// Block definition
$block_id = isset($options['rect_id']) && $options['rect_id'] ? $options['rect_id'] : 'block';
$blockDefinition = $svg->defs->addChild('rect');
$blockDefinition->addAttribute('id', 'block');
$blockDefinition->addAttribute('id', $block_id);
$blockDefinition->addAttribute('width', strval($data['block_size']));
$blockDefinition->addAttribute('height', strval($data['block_size']));
$blockDefinition->addAttribute('fill', '#'.sprintf('%02x%02x%02x', $qrCode->getForegroundColor()['r'], $qrCode->getForegroundColor()['g'], $qrCode->getForegroundColor()['b']));
Expand All @@ -59,7 +60,7 @@ public function writeString(QrCodeInterface $qrCode): string
$block = $svg->addChild('use');
$block->addAttribute('x', strval($data['margin_left'] + $data['block_size'] * $column));
$block->addAttribute('y', strval($data['margin_left'] + $data['block_size'] * $row));
$block->addAttribute('xlink:href', '#block', 'http://www.w3.org/1999/xlink');
$block->addAttribute('xlink:href', '#'.$block_id, 'http://www.w3.org/1999/xlink');
}
}
}
Expand Down

0 comments on commit 58d5872

Please sign in to comment.