No Description

Line.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * This file is part of PHPWord - A pure PHP library for reading and writing
  4. * word processing documents.
  5. *
  6. * PHPWord is free software distributed under the terms of the GNU Lesser
  7. * General Public License version 3 as published by the Free Software Foundation.
  8. *
  9. * For the full copyright and license information, please read the LICENSE
  10. * file that was distributed with this source code. For the full list of
  11. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
  12. *
  13. * @link https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2014 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Writer\Word2007\Style;
  18. use PhpOffice\PhpWord\Style\Line as LineStyle;
  19. /**
  20. * Line style writer
  21. *
  22. */
  23. class Line extends Frame
  24. {
  25. /**
  26. * Write Line stroke.
  27. *
  28. * @return void
  29. * @todo Merge with `Stroke` style
  30. */
  31. public function writeStroke()
  32. {
  33. $xmlWriter = $this->getXmlWriter();
  34. $style = $this->getStyle();
  35. if (!$style instanceof LineStyle) {
  36. return;
  37. }
  38. $dash = $style->getDash();
  39. $dashStyles = array(
  40. LineStyle::DASH_STYLE_DASH => 'dash',
  41. LineStyle::DASH_STYLE_ROUND_DOT => '1 1',
  42. LineStyle::DASH_STYLE_SQUARE_DOT => '1 1',
  43. LineStyle::DASH_STYLE_DASH_DOT => 'dashDot',
  44. LineStyle::DASH_STYLE_LONG_DASH => 'longDash',
  45. LineStyle::DASH_STYLE_LONG_DASH_DOT => 'longDashDot',
  46. LineStyle::DASH_STYLE_LONG_DASH_DOT_DOT => 'longDashDotDot',
  47. );
  48. $xmlWriter->startElement('v:stroke');
  49. $xmlWriter->writeAttributeIf($style->getWeight() !== null, 'weight', $style->getWeight() . 'pt');
  50. $xmlWriter->writeAttributeIf($style->getColor() !== null, 'color', $style->getColor());
  51. $xmlWriter->writeAttributeIf($style->getBeginArrow() !== null, 'startarrow', $style->getBeginArrow());
  52. $xmlWriter->writeAttributeIf($style->getEndArrow() !== null, 'endarrow', $style->getEndArrow());
  53. if ($dash !== null) {
  54. if (isset($dashStyles[$dash])) {
  55. $xmlWriter->writeAttribute('dashstyle', $dashStyles[$dash]);
  56. }
  57. if ($dash == LineStyle::DASH_STYLE_ROUND_DOT) {
  58. $xmlWriter->writeAttribute('endcap', 'round');
  59. }
  60. }
  61. $xmlWriter->endElement(); //v:stroke
  62. }
  63. }