*/ $bases = array(); $fills = array(); $rots = array(); $xs = array(); $ys = array(); if ($bsw) { $bsw = bsw2cluster($bsw); $chars = str_split($bsw, 3); $cnt = count($chars); for ($i = 0; $i < $cnt; $i++) { $bases[] = $chars[$i]; $i++; $fills[] = char2fill($chars[$i]); $i++; $rots[] = char2rot($chars[$i]); $i++; $xs[] = hex2num($chars[$i]); $i++; $ys[] = hex2num($chars[$i]); } } /** * Step 2: load images and determine size */ $xMin = $xs[0]; $xMax = $xMin + 2; $yMin = $ys[0]; $yMax = $yMin + 2; $centering = 0; foreach ($bases as $num => $base) {
function bsw2key($bsw) { $base = substr($bsw, 0, 3); $fill = substr($bsw, 3, 3); $rot = substr($bsw, 6, 3); return $base . char2fill($fill) . char2rot($rot); }
} /** * Step 1: break apart */ $keys = array(); $xs = array(); $ys = array(); if ($data) { $chars = str_split($data, 3); $cnt = count($chars); for ($i = 0; $i < $cnt; $i++) { $base = $chars[$i]; $i++; $hfill = char2fill($chars[$i]); $i++; $hrot = char2rot($chars[$i]); $keys[] = $base . $hfill . $hrot; $i++; $xs[] = hex2num($chars[$i]); $i++; $ys[] = hex2num($chars[$i]); } /** * Step 2: load images and determine size */ $xMin = $xs[0]; $xMax = $xMin + 2; $yMin = $ys[0]; $yMax = $yMin + 2; } else { $xMin = 0;
$drot = $offset % 16; $dfill = ($offset - $drot) / 16; $base = dechex(intval(($code - 1) / 96) + 256); $key = $base . dechex($dfill) . dechex($drot); } else { if ($base) { $key = base2view($base); } else { if ($key) { $base = substr($key, 0, 3); } else { if ($bsw) { $base = substr($bsw, 0, 3); if (strlen($bsw) > 3) { $hfill = char2fill(substr($bsw, 3, 3)); $hrot = char2rot(substr($bsw, 6, 3)); $key = $base . $hfill . $hrot; } else { $key = base2view($base); } } else { die; } } } } $file = 'iswa/' . $base . '/' . $key . '.png'; $im_src = imagecreatefrompng($file); if ($colorize) { $line = ''; }
public function __construct($bsw) { $this->bsw = $bsw; $this->lane = substr($bsw, 0, 3); $this->cluster = bsw2cluster($bsw); $this->seq = bsw2seq($bsw); /** * Step 1: break apart */ $keys = array(); $xs = array(); // x position $ys = array(); // y position $ws = array(); // width $hs = array(); // height $bsw = bsw2cluster($bsw); $chars = str_split($bsw, 3); $cnt = count($chars); if ($bsw != "") { for ($i = 0; $i < $cnt; $i++) { $char = $chars[$i]; $i++; $fill = char2fill($chars[$i]); $i++; $rot = char2rot($chars[$i]); $key = $char . $fill . $rot; $keys[] = $key; $i++; $xs[] = hex2num($chars[$i]); $i++; $ys[] = hex2num($chars[$i]); $sym = new Symbol($key); $ws[] = $sym->getWidth(); $hs[] = $sym->getHeight(); } /** * Step 2: determing width, height, and center */ $xMin = $xs[0]; $xMax = $xMin + 2; $yMin = $ys[0]; $yMax = $yMin + 2; $cxMin = 0; $cxMax = 0; $cyMin = 0; $cyMax = 0; $centering = 0; // centering count } else { //make up values $xMin = 0; $xMax = $xMin + 2; $yMin = 0; $yMax = $yMin + 2; $cxMin = 0; $cxMax = 0; $cyMin = 0; $cyMax = 0; $centering = 0; // centering count } foreach ($keys as $num => $key) { $base = substr($key, 0, 3); $W = $ws[$num]; $H = $hs[$num]; $X = $xs[$num]; $Y = $ys[$num]; if ($xMin > $X) { $xMin = $X; } if ($yMin > $Y) { $yMin = $Y; } if ($xMax < $X + $W) { $xMax = $X + $W; } if ($yMax < $Y + $H) { $yMax = $Y + $H; } //check for centering if (isHead($base) or isTrunk($base)) { if ($centering == 0) { $cxMin = $X; $cxMax = $X + $W; $cyMin = $Y; $cyMax = $Y + $H; } else { if ($cxMin > $X) { $cxMin = $X; } if ($cyMin > $Y) { $cyMin = $Y; } if ($cxMax < $X + $W) { $cxMax = $X + $W; } if ($cyMax < $Y + $H) { $cyMax = $Y + $H; } } $centering++; } } $this->width = $xMax - $xMin; $this->height = $yMax - $yMin; if ($centering) { $this->centerX = ($cxMin + $cxMax) / 2 - $xMin; $this->centerY = ($cyMin + $cyMax) / 2 - $yMin; } else { $this->centerX = ($xMin + $xMax) / 2; $this->centerY = ($yMin + $yMax) / 2; } //rebuild bsw with zero relative x and y $this->bsw = $this->lane; foreach ($keys as $num => $key) { $this->bsw .= key2bsw($key); $X = $xs[$num]; $this->bsw .= num2hex($X - $xMin); //$this->centerX); $Y = $ys[$num]; $this->bsw .= num2hex($Y - $yMin); //$this->centerY); } //already zero based // $this->centerX -= $xMin; // $this->centerY -= $yMin; if ($this->seq) { $this->bsw .= '0fd' . $this->seq; } }