CreateStyleTable.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. <?php
  2. /**
  3. * Create style table
  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 style table
  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 CreateStyleTable extends CreateStyle
  28. {
  29. /**
  30. * @access protected
  31. * @var string
  32. */
  33. protected $_xml;
  34. /**
  35. * @access private
  36. * @var CreateStyleTable
  37. * @static
  38. */
  39. private static $_instance = NULL;
  40. /**
  41. * Construct
  42. *
  43. * @access public
  44. */
  45. public function __construct()
  46. {
  47. }
  48. /**
  49. * Destruct
  50. *
  51. * @access public
  52. */
  53. public function __destruct()
  54. {
  55. }
  56. /**
  57. *
  58. * @access public
  59. * @return string
  60. */
  61. public function __toString()
  62. {
  63. return $this->_xml;
  64. }
  65. /**
  66. *
  67. * @access public
  68. * @return CreateStyleTable
  69. * @static
  70. */
  71. public static function getInstance()
  72. {
  73. if (self::$_instance == NULL) {
  74. self::$_instance = new CreateStyleTable();
  75. }
  76. return self::$_instance;
  77. }
  78. /**
  79. * Add table style
  80. *
  81. * @access public
  82. * @param array $args[0]
  83. */
  84. public function addStyleTable()
  85. {
  86. $this->_xml = '';
  87. $args = func_get_args();
  88. if (!empty($args[0]['type'])) {
  89. $this->generateTBLSTYLEPR($args[0]['type']);
  90. }
  91. if (!empty($args[0]['name'])) {
  92. $this->generateNAME($args[0]['name']);
  93. }
  94. if (!empty($args[0]['basedOn'])) {
  95. $this->generateBASEDON($args[0]['basedOn']);
  96. }
  97. if (!empty($args[0]['next'])) {
  98. $this->generateNEXT($args[0]['next']);
  99. }
  100. if (!empty($args[0]['link'])) {
  101. $this->generateLINK($args[0]['link']);
  102. }
  103. if ($args[0]['autoRedefine'] == 1) {
  104. $this->generateAUTOREDEFINE();
  105. }
  106. if (!empty($args[0]['uiPriority'])) {
  107. $this->generateUIPRIORITY($args[0]['uiPriority']);
  108. }
  109. if ($args[0]['semiHidden'] == 1) {
  110. $this->generateSEMIHIDDEN();
  111. }
  112. if ($args[0]['unhideWhenUsed'] == 1) {
  113. $this->generateUNHIDEWHENUSED();
  114. }
  115. if ($args[0]['qFormat'] == 1) {
  116. $this->generateQFORMAT();
  117. }
  118. if (!empty($args[0]['rsid'])) {
  119. $this->generateRSID($args[0]['rsid']);
  120. }
  121. if ($args[0]['keepNext'] == 1 ||
  122. !empty($args[0]['keepLines']) ||
  123. (isset($args[0]['spacing_before']) ||
  124. isset($args[0]['spacing_after']) ||
  125. isset($args[0]['spacing_line']) ||
  126. isset($args[0]['spacing_lineRule'])) ||
  127. !empty($args[0]['outlineLvl']) ||
  128. $args[0]['contextualSpacing'] == 1 ||
  129. isset($args[0]['ilvl']) ||
  130. isset($args[0]['ind_left'])
  131. ) {
  132. $this->generatePPR();
  133. if ($args[0]['keepNext'] == 1) {
  134. $this->generateKEEPNEXT();
  135. }
  136. if (!empty($args[0]['keepLines'])) {
  137. $this->generateKEEPLINES($args[0]['keepLines']);
  138. }
  139. if (isset($args[0]['pBdr_bottom_val']) &&
  140. isset($args[0]['pBdr_bottom_sz']) &&
  141. isset($args[0]['pBdr_bottom_space']) &&
  142. isset($args[0]['pBdr_bottom_color']) &&
  143. isset($args[0]['pBdr_bottom_themeColor'])
  144. ) {
  145. $this->generatePBDR();
  146. $this->generatePBDR_BOTTOM(
  147. $args[0]['pBdr_bottom_val'],
  148. $args[0]['pBdr_bottom_sz'],
  149. $args[0]['pBdr_bottom_space'],
  150. $args[0]['pBdr_bottom_color'],
  151. $args[0]['pBdr_bottom_themeColor']
  152. );
  153. }
  154. if (!empty($args[0]['tab_center']) || $args[0]['tab_right']) {
  155. $this->generateTABS();
  156. if (!empty($args[0]['tab_center'])) {
  157. $this->generateTABCENTER($args[0]['tab_center']);
  158. }
  159. if (!empty($args[0]['tab_right'])) {
  160. $this->generateTABRIGHT($args[0]['tab_right']);
  161. }
  162. }
  163. if (isset($args[0]['spacing_before']) ||
  164. isset($args[0]['spacing_after']) ||
  165. isset($args[0]['spacing_line']) ||
  166. isset($args[0]['spacing_lineRule'])
  167. ) {
  168. $this->generateSPACING(
  169. $args[0]['spacing_before'],
  170. $args[0]['spacing_after'],
  171. $args[0]['spacing_line'],
  172. $args[0]['spacing_lineRule']
  173. );
  174. }
  175. if (isset($args[0]['ind_left'])) {
  176. $this->generateIND($args[0]['ind_left']);
  177. }
  178. if ($args[0]['contextualSpacing'] == 1) {
  179. $this->generateCONTEXTUALSPACING();
  180. }
  181. if (isset($args[0]['outlineLvl'])) {
  182. $this->generateOUTLINELVL($args[0]['outlineLvl']);
  183. }
  184. if (isset($args[0]['ilvl'])) {
  185. $this->generateNUMPR();
  186. $this->generateILVL($args[0]['ilvl']);
  187. }
  188. }
  189. if ((!empty($args[0]['rFonts_asciiTheme']) &&
  190. !empty($args[0]['rFonts_eastAsiaTheme']) &&
  191. !empty($args[0]['rFonts_hAnsiTheme']) &&
  192. !empty($args[0]['rFonts_cstheme'])) ||
  193. $args[0]['b'] == 1 ||
  194. $args[0]['bCs'] == 1 ||
  195. $args[0]['i'] == 1 ||
  196. $args[0]['iCs'] == 1 ||
  197. $args[0]['u'] == 1 ||
  198. !empty($args[0]['color_val']) ||
  199. !empty($args[0]['sz']) ||
  200. !empty($args[0]['szCs']) ||
  201. !empty($args[0]['kern']) ||
  202. !empty($args[0]['rPr_spacing']) ||
  203. !empty($args[0]['u'])
  204. ) {
  205. $this->generateRPR();
  206. if (!empty($args[0]['rFonts_asciiTheme']) &&
  207. !empty($args[0]['rFonts_eastAsiaTheme']) &&
  208. !empty($args[0]['rFonts_hAnsiTheme']) &&
  209. !empty($args[0]['rFonts_cstheme'])
  210. ) {
  211. $this->generateRFONTS(
  212. $args[0]['rFonts_asciiTheme'],
  213. $args[0]['rFonts_eastAsiaTheme'],
  214. $args[0]['rFonts_hAnsiTheme'],
  215. $args[0]['rFonts_cstheme']
  216. );
  217. }
  218. if (!empty($args[0]['rFonts_ascii']) &&
  219. !empty($args[0]['rFonts_hAnsi']) &&
  220. !empty($args[0]['rFonts_cs'])
  221. ) {
  222. $this->generateRFONTS2(
  223. $args[0]['rFonts_ascii'],
  224. $args[0]['rFonts_hAnsi'],
  225. $args[0]['rFonts_cs']
  226. );
  227. }
  228. if ($args[0]['b'] == 1) {
  229. $this->generateB();
  230. }
  231. if ($args[0]['bCs'] == 1) {
  232. $this->generateBCS();
  233. }
  234. if (isset($args[0]['i'])) {
  235. $this->generateI($args[0]['i']);
  236. }
  237. if (isset($args[0]['iCs'])) {
  238. $this->generateICS($args[0]['iCs']);
  239. }
  240. if ($args[0]['u'] == 1) {
  241. $this->generateU();
  242. }
  243. if (!empty($args[0]['color_val'])) {
  244. $this->generateCOLOR(
  245. $args[0]['color_val'],
  246. $args[0]['color_themeColor'],
  247. $args[0]['color_themeShade']
  248. );
  249. }
  250. if (!empty($args[0]['u'])) {
  251. $this->generateU($args[0]['u']);
  252. }
  253. if (!empty($args[0]['rPr_spacing'])) {
  254. $this->generateRPR_SPACING($args[0]['rPr_spacing']);
  255. }
  256. if (!empty($args[0]['kern'])) {
  257. $this->generateKERN($args[0]['kern']);
  258. }
  259. if (!empty($args[0]['sz'])) {
  260. $this->generateSZ($args[0]['sz']);
  261. }
  262. if (!empty($args[0]['szCs'])) {
  263. $this->generateSZCS($args[0]['szCs']);
  264. }
  265. }
  266. if (isset($args[0]['tblPr'])) {
  267. $this->generateTBLPR();
  268. }
  269. if ((isset($args[0]['top_w']) &&
  270. isset($args[0]['top_type'])) ||
  271. (isset($args[0]['left_w']) &&
  272. isset($args[0]['left_type'])) ||
  273. (isset($args[0]['bottom_w']) &&
  274. isset($args[0]['bottom_type'])) ||
  275. (isset($args[0]['right_w']) &&
  276. isset($args[0]['right_type'])) ||
  277. (isset($args[0]['tblInd_w']) &&
  278. isset($args[0]['tblInd_type'])) &&
  279. isset($args[0]['tblborder_top_val']) ||
  280. isset($args[0]['tblborder_left_val']) ||
  281. isset($args[0]['tblborder_bottom_val']) ||
  282. isset($args[0]['tblborder_right_val']) ||
  283. isset($args[0]['tblborder_insideH_val']) ||
  284. isset($args[0]['tblborder_insideV_val']) ||
  285. (isset($args[0]['shd_val']) &&
  286. isset($args[0]['shd_color']) &&
  287. isset($args[0]['shd_fill']) &&
  288. isset($args[0]['shd_themeFill']))
  289. ) {
  290. $this->generateTCPR();
  291. if (isset($args[0]['tbl_style_row'])) {
  292. $this->generateTBLSTYLEROWBANDSIZE($args[0]['tbl_style_row']);
  293. }
  294. if (isset($args[0]['tbl_style_col'])) {
  295. $this->generateTBLSTYLECOLBANDSIZE($args[0]['tbl_style_col']);
  296. }
  297. if (isset($args[0]['tblInd_w']) &&
  298. isset($args[0]['tblInd_type'])
  299. ) {
  300. $this->generateTBLIND(
  301. $args[0]['tblInd_w'],
  302. $args[0]['tblInd_type']
  303. );
  304. }
  305. if (isset($args[0]['tblborder_top_val']) ||
  306. isset($args[0]['tblborder_left_val']) ||
  307. isset($args[0]['tblborder_bottom_val']) ||
  308. isset($args[0]['tblborder_right_val']) ||
  309. isset($args[0]['tblborder_insideH_val']) ||
  310. isset($args[0]['tblborder_insideV_val'])
  311. ) {
  312. $this->generateTCBORDERS();
  313. if (isset($args[0]['tblborder_top_val'])) {
  314. $this->generateTBLBORDERS_TOP(
  315. $args[0]['tblborder_top_val'],
  316. $args[0]['tblborder_top_sz'],
  317. $args[0]['tblborder_top_space'],
  318. $args[0]['tblborder_top_color'],
  319. $args[0]['tblborder_top_themeColor'],
  320. $args[0]['tblborder_insideV_themeTint']
  321. );
  322. }
  323. if (isset($args[0]['tblborder_left_val'])) {
  324. $this->generateTBLBORDERS_LEFT(
  325. $args[0]['tblborder_left_val'],
  326. $args[0]['tblborder_left_sz'],
  327. $args[0]['tblborder_left_space'],
  328. $args[0]['tblborder_left_color'],
  329. $args[0]['tblborder_left_themeColor'],
  330. $args[0]['tblborder_insideV_themeTint']
  331. );
  332. }
  333. if (isset($args[0]['tblborder_bottom_val'])) {
  334. $this->generateTBLBORDERS_BOTTOM(
  335. $args[0]['tblborder_bottom_val'],
  336. $args[0]['tblborder_bottom_sz'],
  337. $args[0]['tblborder_bottom_space'],
  338. $args[0]['tblborder_bottom_color'],
  339. $args[0]['tblborder_bottom_themeColor'],
  340. $args[0]['tblborder_insideV_themeTint']
  341. );
  342. }
  343. if (isset($args[0]['tblborder_right_val'])) {
  344. $this->generateTBLBORDERS_RIGHT(
  345. $args[0]['tblborder_right_val'],
  346. $args[0]['tblborder_right_sz'],
  347. $args[0]['tblborder_right_space'],
  348. $args[0]['tblborder_right_color'],
  349. $args[0]['tblborder_right_themeColor'],
  350. $args[0]['tblborder_insideV_themeTint']
  351. );
  352. }
  353. if (isset($args[0]['tblborder_insideH_val'])) {
  354. $this->generateTBLBORDERS_INSIDEH(
  355. $args[0]['tblborder_insideH_val'],
  356. $args[0]['tblborder_insideH_sz'],
  357. $args[0]['tblborder_insideH_space'],
  358. $args[0]['tblborder_insideH_color'],
  359. $args[0]['tblborder_insideH_themeColor'],
  360. $args[0]['tblborder_insideV_themeTint']
  361. );
  362. }
  363. if (isset($args[0]['tblborder_insideV_val'])) {
  364. $this->generateTBLBORDERS_INSIDEV(
  365. $args[0]['tblborder_insideV_val'],
  366. $args[0]['tblborder_insideV_sz'],
  367. $args[0]['tblborder_insideV_space'],
  368. $args[0]['tblborder_insideV_color'],
  369. $args[0]['tblborder_insideV_themeColor'],
  370. $args[0]['tblborder_insideV_themeTint']
  371. );
  372. }
  373. }
  374. if (isset($args[0]['shd_val']) &&
  375. isset($args[0]['shd_color']) &&
  376. isset($args[0]['shd_fill']) &&
  377. isset($args[0]['shd_themeFill'])
  378. ) {
  379. $this->generateSHD(
  380. $args[0]['shd_val'],
  381. $args[0]['shd_color'],
  382. $args[0]['shd_fill'],
  383. $args[0]['shd_themeFill'],
  384. $args[0]['shd_themeFillTint']
  385. );
  386. }
  387. if ((isset($args[0]['top_w']) &&
  388. isset($args[0]['top_type'])) ||
  389. (isset($args[0]['left_w']) &&
  390. isset($args[0]['left_type'])) ||
  391. (isset($args[0]['bottom_w']) &&
  392. isset($args[0]['bottom_type'])) ||
  393. (isset($args[0]['right_w']) &&
  394. isset($args[0]['right_type']))
  395. ) {
  396. $this->generateTBLCELLMAR();
  397. if (isset($args[0]['top_w']) &&
  398. isset($args[0]['top_type'])) {
  399. $this->generateTOP(
  400. $args[0]['top_w'],
  401. $args[0]['top_type']
  402. );
  403. }
  404. if (isset($args[0]['left_w']) &&
  405. isset($args[0]['left_type'])) {
  406. $this->generateLEFT(
  407. $args[0]['left_w'],
  408. $args[0]['left_type']
  409. );
  410. }
  411. if (isset($args[0]['bottom_w']) &&
  412. isset($args[0]['bottom_type'])) {
  413. $this->generateBOTTOM(
  414. $args[0]['bottom_w'],
  415. $args[0]['bottom_type']
  416. );
  417. }
  418. if (isset($args[0]['right_w']) &&
  419. isset($args[0]['right_type'])) {
  420. $this->generateRIGHT(
  421. $args[0]['right_w'],
  422. $args[0]['right_type']
  423. );
  424. }
  425. }
  426. }
  427. $this->cleanTemplate();
  428. $this->_xml .= '__GENERATESTYLE__';
  429. }
  430. /**
  431. * Generate w:tblStylePr
  432. *
  433. * @access protected
  434. * @param string $type
  435. */
  436. protected function generateTBLSTYLEPR($type)
  437. {
  438. $this->_xml .= '<' . CreateElement::NAMESPACEWORD .
  439. ':tblStylePr ' . CreateElement::NAMESPACEWORD .
  440. ':type="' . $type . '">__GENERATESTYLE__</' .
  441. CreateElement::NAMESPACEWORD . ':tblStylePr>';
  442. }
  443. /**
  444. * Generate w:tblPr
  445. *
  446. * @access protected
  447. */
  448. protected function generateTBLPR()
  449. {
  450. $this->_xml = str_replace(
  451. '__GENERATESTYLE__', '<' .
  452. CreateElement::NAMESPACEWORD .
  453. ':tblPr></' . CreateElement::NAMESPACEWORD .
  454. ':tblPr>__GENERATESTYLE__',
  455. $this->_xml
  456. );
  457. }
  458. /**
  459. * Generate w:tcPr
  460. *
  461. * @access protected
  462. */
  463. protected function generateTCPR()
  464. {
  465. $this->_xml = str_replace(
  466. '__GENERATESTYLE__', '<' .
  467. CreateElement::NAMESPACEWORD .
  468. ':tcPr>__GENERATETBLPR__</' . CreateElement::NAMESPACEWORD .
  469. ':tcPr>__GENERATESTYLE__',
  470. $this->_xml
  471. );
  472. }
  473. /**
  474. * Generate w:tcBorders
  475. *
  476. * @access protected
  477. */
  478. protected function generateTCBORDERS()
  479. {
  480. $this->_xml = str_replace(
  481. '__GENERATETBLPR__', '<' .
  482. CreateElement::NAMESPACEWORD .
  483. ':tcBorders>__GENERATETBLBORDERS__</' .
  484. CreateElement::NAMESPACEWORD . ':tcBorders>__GENERATETBLPR__',
  485. $this->_xml
  486. );
  487. }
  488. /**
  489. * Generate w:shd
  490. *
  491. * @access protected
  492. * @param string $val
  493. * @param string $color
  494. * @param string $fill
  495. * @param string $themeFill
  496. * @param string $themeFillTint
  497. */
  498. protected function generateSHD($val, $color = '', $fill = '',
  499. $themeFill = '', $themeFillTint = '')
  500. {
  501. $xmlAux = '<' . CreateElement::NAMESPACEWORD . ':shd ' .
  502. CreateElement::NAMESPACEWORD . ':val="' . $val . '"';
  503. if ($color != '')
  504. $xmlAux .= ' ' . CreateElement::NAMESPACEWORD .
  505. ':color="' . $color . '"';
  506. if ($fill != '')
  507. $xmlAux .= ' ' . CreateElement::NAMESPACEWORD .
  508. ':fill="' . $fill . '"';
  509. if ($themeFill != '')
  510. $xmlAux .= ' ' . CreateElement::NAMESPACEWORD .
  511. ':themeFill="' . $themeFill . '"';
  512. if ($themeFillTint != '')
  513. $xmlAux .= ' ' . CreateElement::NAMESPACEWORD .
  514. ':themeFillTint="' . $themeFillTint . '"';
  515. $xmlAux .= '></' . CreateElement::NAMESPACEWORD .
  516. ':shd>__GENERATETBLPR__';
  517. $this->_xml = str_replace('__GENERATETBLPR__', $xmlAux, $this->_xml);
  518. }
  519. }