Nav apraksta

MarginBorder.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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\Shared\XMLWriter;
  19. /**
  20. * Margin border style writer
  21. *
  22. * @since 0.10.0
  23. */
  24. class MarginBorder extends AbstractStyle
  25. {
  26. /**
  27. * Sizes
  28. *
  29. * @var integer[]
  30. */
  31. private $sizes = array();
  32. /**
  33. * Colors
  34. *
  35. * @var string[]
  36. */
  37. private $colors = array();
  38. /**
  39. * Other attributes
  40. *
  41. * @var array
  42. */
  43. private $attributes = array();
  44. /**
  45. * Write style.
  46. *
  47. * @return void
  48. */
  49. public function write()
  50. {
  51. $xmlWriter = $this->getXmlWriter();
  52. $sides = array('top', 'left', 'right', 'bottom', 'insideH', 'insideV');
  53. foreach ($this->sizes as $i => $size) {
  54. if ($size !== null) {
  55. $color = null;
  56. if (isset($this->colors[$i])) {
  57. $color = $this->colors[$i];
  58. }
  59. $this->writeSide($xmlWriter, $sides[$i], $this->sizes[$i], $color);
  60. }
  61. }
  62. }
  63. /**
  64. * Write side.
  65. *
  66. * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
  67. * @param string $side
  68. * @param int $width
  69. * @param string $color
  70. * @return void
  71. */
  72. private function writeSide(XMLWriter $xmlWriter, $side, $width, $color = null)
  73. {
  74. $xmlWriter->startElement('w:' . $side);
  75. if (!empty($this->colors)) {
  76. if ($color === null && !empty($this->attributes)) {
  77. if (isset($this->attributes['defaultColor'])) {
  78. $color = $this->attributes['defaultColor'];
  79. }
  80. }
  81. $xmlWriter->writeAttribute('w:val', 'single');
  82. $xmlWriter->writeAttribute('w:sz', $width);
  83. $xmlWriter->writeAttribute('w:color', $color);
  84. if (!empty($this->attributes)) {
  85. if (isset($this->attributes['space'])) {
  86. $xmlWriter->writeAttribute('w:space', $this->attributes['space']);
  87. }
  88. }
  89. } else {
  90. $xmlWriter->writeAttribute('w:w', $width);
  91. $xmlWriter->writeAttribute('w:type', 'dxa');
  92. }
  93. $xmlWriter->endElement();
  94. }
  95. /**
  96. * Set sizes.
  97. *
  98. * @param integer[] $value
  99. * @return void
  100. */
  101. public function setSizes($value)
  102. {
  103. $this->sizes = $value;
  104. }
  105. /**
  106. * Set colors.
  107. *
  108. * @param string[] $value
  109. * @return void
  110. */
  111. public function setColors($value)
  112. {
  113. $this->colors = $value;
  114. }
  115. /**
  116. * Set attributes.
  117. *
  118. * @param array $value
  119. * @return void
  120. */
  121. public function setAttributes($value)
  122. {
  123. $this->attributes = $value;
  124. }
  125. }