Exemplo n.º 1
0
function moveBSW($bsw, $mx, $my)
{
    if (isPunc($bsw)) {
        return $bsw;
    }
    $first = substr($bsw, 0, 3);
    $cluster = bsw2cluster($bsw);
    $seq = bsw2seq($bsw);
    $chars = str_split($cluster, 3);
    $bsw = $first;
    for ($i = 0; $i < count($chars); $i++) {
        //sym as base,fill,rot
        $bsw .= $chars[$i++];
        $bsw .= $chars[$i++];
        $bsw .= $chars[$i++];
        //move x and y
        $x = $chars[$i++];
        $bsw .= num2hex(hex2num($x) - $mx);
        $y = $chars[$i];
        $bsw .= num2hex(hex2num($y) - $my);
    }
    if ($seq) {
        $bsw .= '0fd' . $seq;
    }
    return $bsw;
}
Exemplo n.º 2
0
//binary signwriting markup
foreach ($units as $ubsw) {
    if (isPunc($ubsw)) {
        $fbsw .= $ubsw . ' ';
        $fupua .= bsw2utf($ubsw) . ' ';
        $fswcm .= bsw2utf($ubsw, 1);
        $fswpm .= bsw2utf($ubsw, 1);
        $fbswml .= '&lt;punc&gt;' . bsw2key($ubsw) . '&lt;/punc&gt;<br>';
    } else {
        $unit = new Sign($ubsw);
        $ubsw = moveBSW($unit->getBSW(), $unit->getCenterX(), $unit->getCenterY());
        $fbsw .= $ubsw . ' ';
        $fupua .= bsw2utf($ubsw) . ' ';
        $first = substr($ubsw, 0, 3);
        $cluster = bsw2cluster($ubsw);
        $seq = bsw2seq($ubsw);
        $chars = str_split($cluster, 3);
        $fswcm .= char2token($first);
        $fswpm .= char2token($first);
        $fbswml .= '&lt;sign lane="' . char2lane($first) . '"&gt;<br>';
        for ($i = 0; $i < count($chars); $i++) {
            //first 3 are symbol
            $sbsw = $chars[$i];
            $i++;
            $sbsw .= $chars[$i];
            $i++;
            $sbsw .= $chars[$i];
            //next 2 are coordinates
            $i++;
            $sx = hex2num($chars[$i]);
            $i++;
Exemplo n.º 3
0
 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;
     }
 }