CreateText.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <?php
  2. /**
  3. * Create text
  4. *
  5. * @category Phpdocx
  6. * @package elements
  7. * @copyright Copyright (c) 2009-2011 Narcea Producciones Multimedia S.L.
  8. * (http://www.2mdc.com)
  9. * @license LGPL
  10. * @version 1.0
  11. * @link http://www.phpdocx.com
  12. * @since File available since Release 1.0
  13. */
  14. include_once dirname(__FILE__) . '/CreateElement.inc';
  15. /**
  16. * Create text
  17. *
  18. * @category Phpdocx
  19. * @package elements
  20. * @copyright Copyright (c) 2009-2011 Narcea Producciones Multimedia S.L.
  21. * (http://www.2mdc.com)
  22. * @license http://www.phpdocx.com/wp-content/themes/lightword/pro_license.php
  23. * @version 1.0
  24. * @link http://www.phpdocx.com
  25. * @since Class available since Release 1.0
  26. */
  27. class CreateText extends CreateElement
  28. {
  29. const IDTITLE = 229998237;
  30. /**
  31. *
  32. * @access private
  33. * @var string
  34. */
  35. private static $_instance = NULL;
  36. /**
  37. *
  38. * @access private
  39. * @var int
  40. */
  41. private static $_idTitle = 0;
  42. /**
  43. * Destruct
  44. *
  45. * @access public
  46. */
  47. public function __construct()
  48. {
  49. }
  50. /**
  51. * Destruct
  52. *
  53. * @access public
  54. */
  55. public function __destruct()
  56. {
  57. }
  58. /**
  59. * Magic method, returns current XML
  60. *
  61. * @access public
  62. * @return string Return current XML
  63. */
  64. public function __toString()
  65. {
  66. return $this->_xml;
  67. }
  68. /**
  69. * Singleton, return instance of class
  70. *
  71. * @access public
  72. * @return CreateText
  73. * @static
  74. */
  75. public static function getInstance()
  76. {
  77. if (self::$_instance == NULL) {
  78. self::$_instance = new CreateText();
  79. }
  80. return self::$_instance;
  81. }
  82. /**
  83. * Create text
  84. *
  85. * @access public
  86. * @param mixed $args[0]
  87. * @param array $args[1]
  88. */
  89. public function createText()
  90. {
  91. $this->_xml = '';
  92. $args = func_get_args();
  93. $this->generateP();
  94. if (!is_array($args[0])) {
  95. if (
  96. !empty($args[1]['jc']) ||
  97. !empty($args[1]['pageBreakBefore']) ||
  98. !empty($args[1]['widowControl']) ||
  99. !empty($args[1]['wordWrap'])
  100. ) {
  101. $this->generatePPR();
  102. if (!empty($args[1]['jc']))
  103. $this->generateJC($args[1]['jc']);
  104. if (!empty($args[1]['pageBreakBefore']))
  105. $this->generatePAGEBREAKBEFORE($args[1]['pageBreakBefore']);
  106. if (!empty($args[1]['widowControl']))
  107. $this->generateWIDOWCONTROL($args[1]['widowControl']);
  108. if (!empty($args[1]['wordWrap']))
  109. $this->generateWORDWRAP($args[1]['wordWrap']);
  110. }
  111. $this->generateR();
  112. if (
  113. $args[1]['b'] != '' ||
  114. $args[1]['i'] != '' ||
  115. $args[1]['u'] != '' ||
  116. $args[1]['sz'] != '' ||
  117. $args[1]['color'] != '' ||
  118. $args[1]['font'] != '' ||
  119. $args[1]['tabs'] != ''
  120. ) {
  121. $this->generateRPR();
  122. if (isset($args[1]['font']) && $args[1]['font'] != '') {
  123. $this->generateRFONTS($args[1]['font']);
  124. }
  125. if (isset($args[1]['b']) && $args[1]['b'] != '') {
  126. $this->generateB($args[1]['b']);
  127. }
  128. if (isset($args[1]['i']) && $args[1]['i'] != '') {
  129. $this->generateI($args[1]['i']);
  130. }
  131. if (isset($args[1]['u']) && $args[1]['u'] != '') {
  132. $this->generateU($args[1]['u']);
  133. }
  134. if (isset($args[1]['sz']) && $args[1]['sz'] != '') {
  135. $this->generateSZ($args[1]['sz']);
  136. }
  137. if (isset($args[1]['color']) && $args[1]['color'] != '') {
  138. $this->generateCOLOR($args[1]['color']);
  139. }
  140. }
  141. $this->generateT($args[0], $args[1]['spaces']);
  142. }
  143. }
  144. /**
  145. * Create title
  146. *
  147. * @access protected
  148. * @param string $arrArgs[0]
  149. * @param array $arrArgs[1]
  150. */
  151. public function createTitle()
  152. {
  153. $this->_xml = '';
  154. $args = func_get_args();
  155. if (!empty($args[1]['val']) && !empty($args[0])) {
  156. $this->generateP();
  157. $this->generatePPR();
  158. if ($args[1]['type'] == 'subtitle')
  159. $this->generatePSTYLE('Subttulo' . $args[1]['val']);
  160. else
  161. $this->generatePSTYLE('Ttulo' . $args[1]['val']);
  162. if (!empty($args[1]['pageBreakBefore']))
  163. $this->generatePAGEBREAKBEFORE($args[1]['pageBreakBefore']);
  164. if (!empty($args[1]['widowControl']))
  165. $this->generateWIDOWCONTROL($args[1]['widowControl']);
  166. if (!empty($args[1]['wordWrap']))
  167. $this->generateWORDWRAP($args[1]['wordWrap']);
  168. self::$_idTitle++;
  169. $this->generateBOOKMARKSTART(
  170. self::$_idTitle, '_Toc' . (self::$_idTitle + self::IDTITLE)
  171. );
  172. $this->generateR();
  173. if (
  174. $args[1]['b'] != '' ||
  175. $args[1]['i'] != '' ||
  176. $args[1]['u'] != '' ||
  177. $args[1]['sz'] != '' ||
  178. $args[1]['color'] != '' ||
  179. $args[1]['font'] != ''
  180. ) {
  181. $this->generateRPR();
  182. if ($args[1]['font'] != '') {
  183. $this->generateRFONTS($args[1]['font']);
  184. }
  185. if ($args[1]['b'] != '') {
  186. $this->generateB($args[1]['b']);
  187. }
  188. if ($args[1]['i'] != '') {
  189. $this->generateI($args[1]['i']);
  190. }
  191. if ($args[1]['u'] != '') {
  192. $this->generateU($args[1]['u']);
  193. }
  194. if ($args[1]['sz'] != '') {
  195. $this->generateSZ($args[1]['sz']);
  196. }
  197. if ($args[1]['color'] != '') {
  198. $this->generateCOLOR($args[1]['color']);
  199. }
  200. }
  201. $this->generateT($args[0]);
  202. $this->generateBOOKMARKEND(self::$_idTitle);
  203. $this->cleanTemplate();
  204. }
  205. }
  206. /**
  207. * Generate w:b
  208. *
  209. * @access protected
  210. * @param string $val
  211. */
  212. protected function generateB($strVal = 'single')
  213. {
  214. $element = '<' . CreateElement::NAMESPACEWORD . ':b ' .
  215. CreateElement::NAMESPACEWORD . ':val="' . $strVal . '"></' .
  216. CreateElement::NAMESPACEWORD . ':b>__GENERATERPR__';
  217. $this->_xml = str_replace('__GENERATERPR__', $element, $this->_xml);
  218. }
  219. /**
  220. * Generate w:color
  221. *
  222. * @access protected
  223. * @param string $val
  224. */
  225. protected function generateCOLOR($val = '000000')
  226. {
  227. $this->_xml = str_replace(
  228. '__GENERATERPR__', '<' . CreateElement::NAMESPACEWORD . ':color ' .
  229. CreateElement::NAMESPACEWORD . ':val="' . $val . '"></' .
  230. CreateElement::NAMESPACEWORD . ':color>__GENERATERPR__', $this->_xml
  231. );
  232. }
  233. /**
  234. * Generate w:jc
  235. *
  236. * @access protected
  237. * @param string $val
  238. */
  239. protected function generateJC($val = '')
  240. {
  241. $this->_xml = str_replace(
  242. '__GENERATEPPR__', '<' . CreateElement::NAMESPACEWORD . ':jc ' .
  243. CreateElement::NAMESPACEWORD . ':val="' . $val . '"></' .
  244. CreateElement::NAMESPACEWORD . ':jc>__GENERATESZ__', $this->_xml
  245. );
  246. }
  247. /**
  248. * Generate w:i
  249. *
  250. * @access protected
  251. * @param string $val
  252. */
  253. protected function generateI($val = 'single')
  254. {
  255. $this->_xml = str_replace(
  256. '__GENERATERPR__', '<' . CreateElement::NAMESPACEWORD . ':i ' .
  257. CreateElement::NAMESPACEWORD . ':val="' . $val . '"></' .
  258. CreateElement::NAMESPACEWORD . ':i>__GENERATERPR__', $this->_xml
  259. );
  260. }
  261. /**
  262. * Generate w:sz
  263. *
  264. * @access protected
  265. * @param string $val
  266. */
  267. protected function generateSZ($val = '11')
  268. {
  269. $val *= 2;
  270. $this->_xml = str_replace(
  271. '__GENERATERPR__', '<' . CreateElement::NAMESPACEWORD . ':sz ' .
  272. CreateElement::NAMESPACEWORD . ':val="' . $val . '"></' .
  273. CreateElement::NAMESPACEWORD . ':sz>__GENERATERPR__', $this->_xml
  274. );
  275. }
  276. /**
  277. * Generate w:u
  278. *
  279. * @access protected
  280. * @param string $val
  281. */
  282. protected function generateU($val = 'single')
  283. {
  284. $this->_xml = str_replace(
  285. '__GENERATERPR__', '<' . CreateElement::NAMESPACEWORD . ':u ' .
  286. CreateElement::NAMESPACEWORD . ':val="' . $val . '"></' .
  287. CreateElement::NAMESPACEWORD . ':u>__GENERATERPR__', $this->_xml
  288. );
  289. }
  290. /**
  291. * Generate w:pstyle
  292. *
  293. * @access protected
  294. * @param string $val
  295. */
  296. protected function generatePSTYLE($val = 'Ttulo')
  297. {
  298. $this->_xml = str_replace(
  299. '__GENERATEPPR__', '<' . CreateElement::NAMESPACEWORD . ':pStyle ' .
  300. CreateElement::NAMESPACEWORD . ':val="' . $val . '"></' .
  301. CreateElement::NAMESPACEWORD . ':pStyle>__GENERATEPPR__',
  302. $this->_xml
  303. );
  304. }
  305. /**
  306. * Generate w:pagebreakbefore
  307. *
  308. * @access protected
  309. * @param string $val
  310. */
  311. protected function generatePAGEBREAKBEFORE($val = 'on')
  312. {
  313. $this->_xml = str_replace(
  314. '__GENERATEPPR__', '<' . CreateElement::NAMESPACEWORD .
  315. ':pageBreakBefore val="' . $val . '"></' .
  316. CreateElement::NAMESPACEWORD . ':pageBreakBefore>__GENERATEPPR__',
  317. $this->_xml
  318. );
  319. }
  320. /**
  321. * Generate w:widowcontrol
  322. *
  323. * @access protected
  324. * @param string $val
  325. */
  326. protected function generateWIDOWCONTROL($val = 'on')
  327. {
  328. $this->_xml = str_replace(
  329. '__GENERATEPPR__', '<' . CreateElement::NAMESPACEWORD .
  330. ':widowControl val="' . $val . '"></' .
  331. CreateElement::NAMESPACEWORD . ':widowControl>__GENERATEPPR__',
  332. $this->_xml
  333. );
  334. }
  335. /**
  336. * Generate w:wordwrap
  337. *
  338. * @access protected
  339. * @param string $val
  340. */
  341. protected function generateWORDWRAP($val = 'on')
  342. {
  343. $this->_xml = str_replace(
  344. '__GENERATEPPR__', '<' . CreateElement::NAMESPACEWORD .
  345. ':wordWrap val="' . $val . '"></' . CreateElement::NAMESPACEWORD .
  346. ':wordWrap>__GENERATEPPR__', $this->_xml
  347. );
  348. }
  349. /**
  350. * Generate w:bookmarkstart
  351. *
  352. * @access protected
  353. * @param int $id
  354. * @param string $name
  355. */
  356. protected function generateBOOKMARKSTART($id, $name)
  357. {
  358. $this->_xml = str_replace(
  359. '__GENERATER__', '<' . CreateElement::NAMESPACEWORD .
  360. ':bookmarkStart ' . CreateElement::NAMESPACEWORD . ':id="' . $id .
  361. '" ' . CreateElement::NAMESPACEWORD . ':name="' . $name . '"></' .
  362. CreateElement::NAMESPACEWORD .
  363. ':bookmarkStart>__GENERATER____GENERATEBOOKMARKEND__', $this->_xml
  364. );
  365. }
  366. /**
  367. * Generate w:bookmarkend
  368. *
  369. * @access protected
  370. * @param int $id
  371. */
  372. protected function generateBOOKMARKEND($id)
  373. {
  374. $this->_xml = str_replace(
  375. '__GENERATEBOOKMARKEND__', '<' . CreateElement::NAMESPACEWORD .
  376. ':bookmarkEnd ' . CreateElement::NAMESPACEWORD . ':id="' . $id .
  377. '"></' . CreateElement::NAMESPACEWORD . ':bookmarkEnd>', $this->_xml
  378. );
  379. }
  380. }