- Модуль: ui
- Путь к файлу: ~/bitrix/modules/ui/lib/barcode/barcodegenerator.php
- Класс: BitrixUIBarcodeBarcodeGenerator
- Вызов: BarcodeGenerator::linear_render_image
private function linear_render_image(
$image, $code, $x, $y, $w, $h, $colors, $widths, $options
) {
$textheight = (isset($options['th']) ? (int)$options['th'] : 10);
$textsize = (isset($options['ts']) ? (int)$options['ts'] : 1);
$textcolor = (isset($options['tc']) ? $options['tc'] : '000');
$textcolor = $this->allocate_color($image, $textcolor);
$width = 0;
foreach ($code['b'] as $block) {
foreach ($block['m'] as $module) {
$width += $module[1] * $widths[$module[2]];
}
}
if ($width) {
$scale = $w / $width;
$scale = (($scale > 1) ? floor($scale) : 1);
$x = floor($x + ($w - $width * $scale) / 2);
} else {
$scale = 1;
$x = floor($x + $w / 2);
}
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);
$my = round($y + min($h, $h + ($ly - 1) * $textheight));
$ly = ($y + $h + $ly * $textheight);
$ly = round($ly - imagefontheight($textsize));
} else {
$label = null;
$my = $y + $h;
}
$mx = $x;
foreach ($block['m'] as $module) {
$mc = $colors[$module[0]];
$mw = $mx + $module[1] * $widths[$module[2]] * $scale;
imagefilledrectangle($image, $mx, $y, $mw - 1, $my - 1, $mc);
$mx = $mw;
}
if (!is_null($label)) {
$lx = ($x + ($mx - $x) * $lx);
$lw = imagefontwidth($textsize) * strlen($label);
$lx = round($lx - $lw / 2);
imagestring($image, $textsize, $lx, $ly, $label, $textcolor);
}
$x = $mx;
}
}