PHPOffice - PowerPoint:如何在 PowerPoint 幻灯片中绘制虚线?

PHPOffice - PowerPoint : How do I draw a dashed line in my PowerPoint slide?

我想使用 PHPOffice 在我的 PowerPoint 演示文稿中生成虚线,但我只能生成实线或双线。

线生成器代码

$shape->getBorder()
      ->setColor($color)
      ->setLineStyle(Border::LINE_SOLID);

如何正确生成虚线?

破折号生成代码

$shape->getBorder()->setDashStyle(Border::DASH_DASH);

我最终使用以下方案生成虚线。

我求助于生成恒定长度的短线段,而不管起点和终点的方向(线的斜率)。

我是如何生成等长斜线的短线段的,分为几个步骤。

算法

 0)  Initialize dashLen to an arbitrary value so that we increment to
     2x dashlen on each iteration of loop to cause empty holes to appear in
     line 
 1)  Calculate length of line    d=sqrt(dx*dx+dy*dy) 
 2)  Calculate negative slope since in the y axis is flipped (Y increases as points traverse screen space in downward direction)
 3)  Loop $x and $y and
     increment $y such that 
     $y += 2*$dashLen*sin(atan($m));
     $x -= 2*$dashLen*cos(atan($m));
 4)  Update endpoints

     $endY = $startY + (($dashLen)*sin(atan($m))); 
     $endX = $startX - (($dashLen)*cos(atan($m))); 
 5)  Draw Line Segments (dashes)

代码段

$d = sqrt(pow($toY-$fromY, 2) + pow($toX-$fromX, 2));
if ($toX != $fromX)
{
      $m = ($toY-$fromY)/($fromX-$toX);
      $dashLen = 2;
      for ($y = $fromY, $x = $fromX; $y < $toY || $x > $toX; $y += ((2*$dashLen*sin(atan($m)))), $x -= (2*$dashLen*cos(atan($m))))
      {   
          $startX = $x;
          $startY = $y;

          $endY = $startY + (($dashLen)*sin(atan($m))); 
          $endX = $startX - (($dashLen)*cos(atan($m)));

          $shape = $currentSlide->createLineShape($startX, $startY, $endX, $endY);


          $color = new Color('FF000000');


          $shape->getFill()
                ->setFillType(Fill::FILL_SOLID)
                ->setStartColor($color)
                ->setEndColor($color);
          $shape->getBorder()
                ->setColor($color)->setLineWidth(2)
                ->setLineStyle($this->getCategoryLine($category));  
      } 
}
else
{

      $dashLen = 2;
      for ($y = $toY; $y > $fromY; $y -= 2*$dashLen)
      {   
          $startX = $fromX;
          $startY = $y;
          $endX = $toX;
          $endY = $y - ($dashLen);             

          $shape = $currentSlide->createLineShape($startX, $startY, $endX, $endY);

          $color = new Color('FF000000');
           $shape->getFill()
                 ->setFillType(Fill::FILL_SOLID)
                 ->setStartColor($color)
                 ->setEndColor($color);
           $shape->getBorder()
                 ->setColor($color)->setLineWidth(2)
                 ->setLineStyle(); 
      }  
}