Font.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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_Font
  29. *
  30. * @category PHPWord
  31. * @package PHPWord_Style
  32. * @copyright Copyright (c) 2011 PHPWord
  33. */
  34. class PHPWord_Style_Font {
  35. const UNDERLINE_NONE = 'none';
  36. const UNDERLINE_DASH = 'dash';
  37. const UNDERLINE_DASHHEAVY = 'dashHeavy';
  38. const UNDERLINE_DASHLONG = 'dashLong';
  39. const UNDERLINE_DASHLONGHEAVY = 'dashLongHeavy';
  40. const UNDERLINE_DOUBLE = 'dbl';
  41. const UNDERLINE_DOTHASH = 'dotDash';
  42. const UNDERLINE_DOTHASHHEAVY = 'dotDashHeavy';
  43. const UNDERLINE_DOTDOTDASH = 'dotDotDash';
  44. const UNDERLINE_DOTDOTDASHHEAVY = 'dotDotDashHeavy';
  45. const UNDERLINE_DOTTED = 'dotted';
  46. const UNDERLINE_DOTTEDHEAVY = 'dottedHeavy';
  47. const UNDERLINE_HEAVY = 'heavy';
  48. const UNDERLINE_SINGLE = 'single';
  49. const UNDERLINE_WAVY = 'wavy';
  50. const UNDERLINE_WAVYDOUBLE = 'wavyDbl';
  51. const UNDERLINE_WAVYHEAVY = 'wavyHeavy';
  52. const UNDERLINE_WORDS = 'words';
  53. const FGCOLOR_YELLOW = 'yellow';
  54. const FGCOLOR_LIGHTGREEN = 'green';
  55. const FGCOLOR_CYAN = 'cyan';
  56. const FGCOLOR_MAGENTA = 'magenta';
  57. const FGCOLOR_BLUE = 'blue';
  58. const FGCOLOR_RED = 'red';
  59. const FGCOLOR_DARKBLUE = 'darkBlue';
  60. const FGCOLOR_DARKCYAN = 'darkCyan';
  61. const FGCOLOR_DARKGREEN = 'darkGreen';
  62. const FGCOLOR_DARKMAGENTA = 'darkMagenta';
  63. const FGCOLOR_DARKRED = 'darkRed';
  64. const FGCOLOR_DARKYELLOW = 'darkYellow';
  65. const FGCOLOR_DARKGRAY = 'darkGray';
  66. const FGCOLOR_LIGHTGRAY = 'lightGray';
  67. const FGCOLOR_BLACK = 'black';
  68. /**
  69. * Font style type
  70. *
  71. * @var string
  72. */
  73. private $_type;
  74. /**
  75. * Paragraph Style
  76. *
  77. * @var PHPWord_Style_Paragraph
  78. */
  79. private $_paragraphStyle;
  80. private $_size;
  81. private $_name;
  82. private $_bold;
  83. private $_italic;
  84. private $_superScript;
  85. private $_subScript;
  86. private $_underline;
  87. private $_strikethrough;
  88. private $_color;
  89. private $_fgColor;
  90. public function __construct($type = 'text', $styleParagraph = null) {
  91. $this->_type = $type;
  92. $this->_name = 'Arial';
  93. $this->_size = 20;
  94. $this->_bold = false;
  95. $this->_italic = false;
  96. $this->_superScript = false;
  97. $this->_subScript = false;
  98. $this->_underline = PHPWord_Style_Font::UNDERLINE_NONE;
  99. $this->_strikethrough = false;
  100. $this->_color = '000000';
  101. $this->_fgColor = null;
  102. if(!is_null($styleParagraph)) {
  103. $paragraph = new PHPWord_Style_Paragraph();
  104. foreach($styleParagraph as $key => $value) {
  105. if(substr($key, 0, 1) != '_') {
  106. $key = '_'.$key;
  107. }
  108. $paragraph->setStyleValue($key, $value);
  109. }
  110. $this->_paragraphStyle = $paragraph;
  111. } else {
  112. $this->_paragraphStyle = null;
  113. }
  114. }
  115. public function getName() {
  116. return $this->_name;
  117. }
  118. public function setStyleValue($key, $value) {
  119. if($key == '_size') {
  120. $value *= 2;
  121. }
  122. $this->$key = $value;
  123. }
  124. public function setName($pValue = 'Arial') {
  125. if($pValue == '') {
  126. $pValue = 'Arial';
  127. }
  128. $this->_name = $pValue;
  129. return $this;
  130. }
  131. public function getSize() {
  132. return $this->_size;
  133. }
  134. public function setSize($pValue = 20) {
  135. if($pValue == '') {
  136. $pValue = 20;
  137. }
  138. $this->_size = ($pValue*2);
  139. return $this;
  140. }
  141. public function getBold() {
  142. return $this->_bold;
  143. }
  144. public function setBold($pValue = false) {
  145. if($pValue == '') {
  146. $pValue = false;
  147. }
  148. $this->_bold = $pValue;
  149. return $this;
  150. }
  151. public function getItalic() {
  152. return $this->_italic;
  153. }
  154. public function setItalic($pValue = false) {
  155. if($pValue == '') {
  156. $pValue = false;
  157. }
  158. $this->_italic = $pValue;
  159. return $this;
  160. }
  161. public function getSuperScript() {
  162. return $this->_superScript;
  163. }
  164. public function setSuperScript($pValue = false) {
  165. if($pValue == '') {
  166. $pValue = false;
  167. }
  168. $this->_superScript = $pValue;
  169. $this->_subScript = !$pValue;
  170. return $this;
  171. }
  172. public function getSubScript() {
  173. return $this->_subScript;
  174. }
  175. public function setSubScript($pValue = false) {
  176. if($pValue == '') {
  177. $pValue = false;
  178. }
  179. $this->_subScript = $pValue;
  180. $this->_superScript = !$pValue;
  181. return $this;
  182. }
  183. public function getUnderline() {
  184. return $this->_underline;
  185. }
  186. public function setUnderline($pValue = PHPWord_Style_Font::UNDERLINE_NONE) {
  187. if ($pValue == '') {
  188. $pValue = PHPWord_Style_Font::UNDERLINE_NONE;
  189. }
  190. $this->_underline = $pValue;
  191. return $this;
  192. }
  193. public function getStrikethrough() {
  194. return $this->_strikethrough;
  195. }
  196. public function setStrikethrough($pValue = false) {
  197. if($pValue == '') {
  198. $pValue = false;
  199. }
  200. $this->_strikethrough = $pValue;
  201. return $this;
  202. }
  203. public function getColor() {
  204. return $this->_color;
  205. }
  206. public function setColor($pValue = '000000') {
  207. $this->_color = $pValue;
  208. return $this;
  209. }
  210. public function getFgColor() {
  211. return $this->_fgColor;
  212. }
  213. public function setFgColor($pValue = null) {
  214. $this->_fgColor = $pValue;
  215. return $this;
  216. }
  217. public function getStyleType() {
  218. return $this->_type;
  219. }
  220. /**
  221. * Get Paragraph style
  222. *
  223. * @return PHPWord_Style_Paragraph
  224. */
  225. public function getParagraphStyle() {
  226. return $this->_paragraphStyle;
  227. }
  228. }
  229. ?>