dongpingwu8378 2018-12-14 19:07
浏览 118
已采纳

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

I want to generate a dashed line in my PowerPoint presentation using PHPOffice but I can only generate solid or double lines.

Line Generator Code

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

How do I properly generate a dashed line?

Dash Generation Code

$shape->getBorder()->setDashStyle(Border::DASH_DASH);
  • 写回答

1条回答 默认 最新

  • douqin6785 2018-12-17 00:33
    关注

    I ended up using the following scheme to generate a dashed line.

    I resorted to generating short line segments of constant length regardless of orientation of start end point (slope of line).

    How I generated the short line segments for sloped line of equal length was in several steps.

    Algorithm

     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)
    

    Code Snippet

    $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(); 
          }  
    }
    

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3