Style.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * PHPWord
  4. *
  5. * Copyright (c) 2011 PHPWord
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPWord
  22. * @package PHPWord
  23. * @copyright Copyright (c) 010 PHPWord
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version Beta 0.6.3, 08.07.2011
  26. */
  27. /**
  28. * PHPWord_Style
  29. *
  30. * @category PHPWord
  31. * @package PHPWord_Style
  32. * @copyright Copyright (c) 2011 PHPWord
  33. */
  34. class PHPWord_Style {
  35. /**
  36. * Style Elements
  37. *
  38. * @var array
  39. */
  40. private static $_styleElements = array();
  41. /**
  42. * Add a paragraph style
  43. *
  44. * @param string $styleName
  45. * @param array $styles
  46. */
  47. public static function addParagraphStyle($styleName, $styles) {
  48. if(!array_key_exists($styleName, self::$_styleElements)) {
  49. $style = new PHPWord_Style_Paragraph();
  50. foreach($styles as $key => $value) {
  51. if(substr($key, 0, 1) != '_') {
  52. $key = '_'.$key;
  53. }
  54. $style->setStyleValue($key, $value);
  55. }
  56. self::$_styleElements[$styleName] = $style;
  57. }
  58. }
  59. /**
  60. * Add a font style
  61. *
  62. * @param string $styleName
  63. * @param array $styleFont
  64. * @param array $styleParagraph
  65. */
  66. public static function addFontStyle($styleName, $styleFont, $styleParagraph = null) {
  67. if(!array_key_exists($styleName, self::$_styleElements)) {
  68. $font = new PHPWord_Style_Font('text', $styleParagraph);
  69. foreach($styleFont as $key => $value) {
  70. if(substr($key, 0, 1) != '_') {
  71. $key = '_'.$key;
  72. }
  73. $font->setStyleValue($key, $value);
  74. }
  75. self::$_styleElements[$styleName] = $font;
  76. }
  77. }
  78. /**
  79. * Add a link style
  80. *
  81. * @param string $styleName
  82. * @param array $styles
  83. */
  84. public static function addLinkStyle($styleName, $styles) {
  85. if(!array_key_exists($styleName, self::$_styleElements)) {
  86. $style = new PHPWord_Style_Font('link');
  87. foreach($styles as $key => $value) {
  88. if(substr($key, 0, 1) != '_') {
  89. $key = '_'.$key;
  90. }
  91. $style->setStyleValue($key, $value);
  92. }
  93. self::$_styleElements[$styleName] = $style;
  94. }
  95. }
  96. /**
  97. * Add a table style
  98. *
  99. * @param string $styleName
  100. * @param array $styles
  101. */
  102. public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null, $styleLastRow = null) {
  103. if(!array_key_exists($styleName, self::$_styleElements)) {
  104. $style = new PHPWord_Style_TableFull($styleTable, $styleFirstRow, $styleLastRow);
  105. self::$_styleElements[$styleName] = $style;
  106. }
  107. }
  108. /**
  109. * Add a title style
  110. *
  111. * @param string $styleName
  112. * @param array $styleFont
  113. * @param array $styleParagraph
  114. */
  115. public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = null) {
  116. $styleName = 'Heading_'.$titleCount;
  117. if(!array_key_exists($styleName, self::$_styleElements)) {
  118. $font = new PHPWord_Style_Font('title', $styleParagraph);
  119. foreach($styleFont as $key => $value) {
  120. if(substr($key, 0, 1) != '_') {
  121. $key = '_'.$key;
  122. }
  123. $font->setStyleValue($key, $value);
  124. }
  125. self::$_styleElements[$styleName] = $font;
  126. }
  127. }
  128. /**
  129. * Get all styles
  130. *
  131. * @return PHPWord_Style_Font[]
  132. */
  133. public static function getStyles() {
  134. return self::$_styleElements;
  135. }
  136. }
  137. ?>