function draw_brush_line($x0, $y0, $x1, $y1, $size, $type, $colour) {
      //$this->dbug("line: $x0, $y0, $x1, $y1");
      $dy = $y1 - $y0;
      $dx = $x1 - $x0;
      $t = 0;
      $watchdog = 1024; // precaution to prevent infinite loops.

      $this->draw_brush($x0, $y0, $size, $type, $colour);
      if (abs($dx) > abs($dy)) { // slope < 1
        //$this->dbug("slope < 1");
        $m = $dy / $dx; // compute slope
        $t += $y0;
        $dx = ($dx < 0) ? -1 : 1;
        $m *= $dx;
        while (round($x0) != round($x1)) {
          if (!$watchdog--) break;
          $x0 += $dx; // step to next x value
          $t += $m;   // add slope to y value
          $y = round($t);
          //$this->dbug("x0=$x0, x1=$x1, y=$y watchdog=$watchdog");
          $this->draw_brush($x0, $y, $size, $type, $colour);

        }
      } else { // slope >= 1
        //$this->dbug("slope >= 1");
        $m = $dx / $dy; // compute slope
        $t += $x0;
        $dy = ($dy < 0) ? -1 : 1;
        $m *= $dy;
        while (round($y0) != round($y1)) {
          if (!$watchdog--) break;
          $y0 += $dy; // step to next y value
          $t += $m;   // add slope to x value
          $x = round($t);
          //$this->dbug("x=$x, y0=$y0, y1=$y1 watchdog=$watchdog");
          $this->draw_brush($x, $y0, $size, $type, $colour);

        }
      }
    }