bungfaz46

cobak

Sep 1st, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 1.14 KB | None | 0 0
  1. public function getBarcodeSVGcode($w=2, $h=30, $color='black') {
  2.         // replace table for special characters
  3.         $repstr = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
  4.         $svg = '<'.'?'.'xml version="1.0" standalone="no"'.'?'.'>'."\n";
  5.         $svg .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'."\n";
  6.         $svg .= '<svg width="'.round(($this->barcode_array['maxw'] * $w), 3).'" height="'.$h.'" version="1.1" xmlns="http://www.w3.org/2000/svg">'."\n";
  7.         $svg .= "\t".'<desc>'.strtr($this->barcode_array['code'], $repstr).'</desc>'."\n";
  8.         $svg .= "\t".'<g id="bars" fill="'.$color.'" stroke="none">'."\n";
  9.         // print bars
  10.         $x = 0;
  11.         foreach ($this->barcode_array['bcode'] as $k => $v) {
  12.             $bw = round(($v['w'] * $w), 3);
  13.             $bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3);
  14.             if ($v['t']) {
  15.                 $y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3);
  16.                 // draw a vertical bar
  17.                 $svg .= "\t\t".'<rect x="'.$x.'" y="'.$y.'" width="'.$bw.'" height="'.$bh.'" />'."\n";
  18.             }
  19.             $x += $bw;
  20.         }
  21.         $svg .= "\t".'</g>'."\n";
  22.         $svg .= '</svg>'."\n";
  23.         return $svg;
  24.     }
Add Comment
Please, Sign In to add comment