- Модуль: ui
- Путь к файлу: ~/bitrix/modules/ui/lib/barcode/barcodegenerator.php
- Класс: BitrixUIBarcodeBarcodeGenerator
- Вызов: BarcodeGenerator::linear_render_svg
private function linear_render_svg(
$code, $x, $y, $w, $h, $colors, $widths, $options
) {
$textheight = (isset($options['th']) ? (int)$options['th'] : 10);
$textfont = (isset($options['tf']) ? $options['tf'] : 'monospace');
$textsize = (isset($options['ts']) ? (int)$options['ts'] : 10);
$textcolor = (isset($options['tc']) ? $options['tc'] : 'black');
$width = 0;
foreach ($code['b'] as $block) {
foreach ($block['m'] as $module) {
$width += $module[1] * $widths[$module[2]];
}
}
if ($width) {
$scale = $w / $width;
if ($scale > 1) {
$scale = floor($scale);
$x = floor($x + ($w - $width * $scale) / 2);
}
} else {
$scale = 1;
$x = floor($x + $w / 2);
}
$tx = 'translate(' . $x . ' ' . $y . ')';
if ($scale != 1) $tx .= ' scale(' . $scale . ' 1)';
$svg = '';
$x = 0;
foreach ($code['b'] as $block) {
if (isset($block['l'])) {
$label = $block['l'][0];
$ly = (isset($block['l'][1]) ? (float)$block['l'][1] : 1);
$lx = (isset($block['l'][2]) ? (float)$block['l'][2] : 0.5);
$mh = min($h, $h + ($ly - 1) * $textheight);
$ly = $h + $ly * $textheight;
} else {
$label = null;
$mh = $h;
}
$svg .= '';
$mx = $x;
foreach ($block['m'] as $module) {
$mc = htmlspecialchars($colors[$module[0]]);
$mw = $module[1] * $widths[$module[2]];
if ($mc) {
$svg .= '';
}
$mx += $mw;
}
if (!is_null($label)) {
$lx = ($x + ($mx - $x) * $lx);
$svg .= '';
$svg .= htmlspecialchars($label);
$svg .= '';
}
$svg .= '';
$x = $mx;
}
return $svg . '';
}