Base.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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. class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart {
  28. protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Text $text, $withoutP = false) {
  29. $styleFont = $text->getFontStyle();
  30. $SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
  31. if(!$withoutP) {
  32. $objWriter->startElement('w:p');
  33. $styleParagraph = $text->getParagraphStyle();
  34. $SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false;
  35. if($SpIsObject) {
  36. $this->_writeParagraphStyle($objWriter, $styleParagraph);
  37. } elseif(!$SpIsObject && !is_null($styleParagraph)) {
  38. $objWriter->startElement('w:pPr');
  39. $objWriter->startElement('w:pStyle');
  40. $objWriter->writeAttribute('w:val', $styleParagraph);
  41. $objWriter->endElement();
  42. $objWriter->endElement();
  43. }
  44. }
  45. $strText = htmlspecialchars($text->getText());
  46. $strText = PHPWord_Shared_String::ControlCharacterPHP2OOXML($strText);
  47. $objWriter->startElement('w:r');
  48. if($SfIsObject) {
  49. $this->_writeTextStyle($objWriter, $styleFont);
  50. } elseif(!$SfIsObject && !is_null($styleFont)) {
  51. $objWriter->startElement('w:rPr');
  52. $objWriter->startElement('w:rStyle');
  53. $objWriter->writeAttribute('w:val', $styleFont);
  54. $objWriter->endElement();
  55. $objWriter->endElement();
  56. }
  57. $objWriter->startElement('w:t');
  58. $objWriter->writeAttribute('xml:space', 'preserve'); // needed because of drawing spaces before and after text
  59. $objWriter->writeRaw($strText);
  60. $objWriter->endElement();
  61. $objWriter->endElement(); // w:r
  62. if(!$withoutP) {
  63. $objWriter->endElement(); // w:p
  64. }
  65. }
  66. protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_TextRun $textrun) {
  67. $elements = $textrun->getElements();
  68. $styleParagraph = $textrun->getParagraphStyle();
  69. $SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false;
  70. $objWriter->startElement('w:p');
  71. if($SpIsObject) {
  72. $this->_writeParagraphStyle($objWriter, $styleParagraph);
  73. } elseif(!$SpIsObject && !is_null($styleParagraph)) {
  74. $objWriter->startElement('w:pPr');
  75. $objWriter->startElement('w:pStyle');
  76. $objWriter->writeAttribute('w:val', $styleParagraph);
  77. $objWriter->endElement();
  78. $objWriter->endElement();
  79. }
  80. if(count($elements) > 0) {
  81. foreach($elements as $element) {
  82. if($element instanceof PHPWord_Section_Text) {
  83. $this->_writeText($objWriter, $element, true);
  84. } elseif($element instanceof PHPWord_Section_Link) {
  85. $this->_writeLink($objWriter, $element, true);
  86. }
  87. }
  88. }
  89. $objWriter->endElement();
  90. }
  91. protected function _writeParagraphStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Paragraph $style, $withoutPPR = false) {
  92. $align = $style->getAlign();
  93. $spaceBefore = $style->getSpaceBefore();
  94. $spaceAfter = $style->getSpaceAfter();
  95. $spacing = $style->getSpacing();
  96. if(!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) || !is_null($spaceAfter)) {
  97. if(!$withoutPPR) {
  98. $objWriter->startElement('w:pPr');
  99. }
  100. if(!is_null($align)) {
  101. $objWriter->startElement('w:jc');
  102. $objWriter->writeAttribute('w:val', $align);
  103. $objWriter->endElement();
  104. }
  105. if(!is_null($spaceBefore) || !is_null($spaceAfter) || !is_null($spacing)) {
  106. $objWriter->startElement('w:spacing');
  107. if(!is_null($spaceBefore)) {
  108. $objWriter->writeAttribute('w:before', $spaceBefore);
  109. }
  110. if(!is_null($spaceAfter)) {
  111. $objWriter->writeAttribute('w:after', $spaceAfter);
  112. }
  113. if(!is_null($spacing)) {
  114. $objWriter->writeAttribute('w:line', $spacing);
  115. $objWriter->writeAttribute('w:lineRule', 'auto');
  116. }
  117. $objWriter->endElement();
  118. }
  119. if(!$withoutPPR) {
  120. $objWriter->endElement(); // w:pPr
  121. }
  122. }
  123. }
  124. protected function _writeLink(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Link $link, $withoutP = false) {
  125. $rID = $link->getRelationId();
  126. $linkName = $link->getLinkName();
  127. if(is_null($linkName)) {
  128. $linkName = $link->getLinkSrc();
  129. }
  130. $styleFont = $link->getFontStyle();
  131. $SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
  132. if(!$withoutP) {
  133. $objWriter->startElement('w:p');
  134. $styleParagraph = $link->getParagraphStyle();
  135. $SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false;
  136. if($SpIsObject) {
  137. $this->_writeParagraphStyle($objWriter, $styleParagraph);
  138. } elseif(!$SpIsObject && !is_null($styleParagraph)) {
  139. $objWriter->startElement('w:pPr');
  140. $objWriter->startElement('w:pStyle');
  141. $objWriter->writeAttribute('w:val', $styleParagraph);
  142. $objWriter->endElement();
  143. $objWriter->endElement();
  144. }
  145. }
  146. $objWriter->startElement('w:hyperlink');
  147. $objWriter->writeAttribute('r:id', 'rId'.$rID);
  148. $objWriter->writeAttribute('w:history', '1');
  149. $objWriter->startElement('w:r');
  150. if($SfIsObject) {
  151. $this->_writeTextStyle($objWriter, $styleFont);
  152. } elseif(!$SfIsObject && !is_null($styleFont)) {
  153. $objWriter->startElement('w:rPr');
  154. $objWriter->startElement('w:rStyle');
  155. $objWriter->writeAttribute('w:val', $styleFont);
  156. $objWriter->endElement();
  157. $objWriter->endElement();
  158. }
  159. $objWriter->startElement('w:t');
  160. $objWriter->writeAttribute('xml:space', 'preserve'); // needed because of drawing spaces before and after text
  161. $objWriter->writeRaw($linkName);
  162. $objWriter->endElement();
  163. $objWriter->endElement();
  164. $objWriter->endElement();
  165. if(!$withoutP) {
  166. $objWriter->endElement(); // w:p
  167. }
  168. }
  169. protected function _writePreserveText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footer_PreserveText $textrun) {
  170. $styleFont = $textrun->getFontStyle();
  171. $styleParagraph = $textrun->getParagraphStyle();
  172. $SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
  173. $SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false;
  174. $arrText = $textrun->getText();
  175. $objWriter->startElement('w:p');
  176. if($SpIsObject) {
  177. $this->_writeParagraphStyle($objWriter, $styleParagraph);
  178. } elseif(!$SpIsObject && !is_null($styleParagraph)) {
  179. $objWriter->startElement('w:pPr');
  180. $objWriter->startElement('w:pStyle');
  181. $objWriter->writeAttribute('w:val', $styleParagraph);
  182. $objWriter->endElement();
  183. $objWriter->endElement();
  184. }
  185. foreach($arrText as $text) {
  186. if(substr($text, 0, 1) == '{') {
  187. $text = substr($text, 1, -1);
  188. $objWriter->startElement('w:r');
  189. $objWriter->startElement('w:fldChar');
  190. $objWriter->writeAttribute('w:fldCharType', 'begin');
  191. $objWriter->endElement();
  192. $objWriter->endElement();
  193. $objWriter->startElement('w:r');
  194. if($SfIsObject) {
  195. $this->_writeTextStyle($objWriter, $styleFont);
  196. } elseif(!$SfIsObject && !is_null($styleFont)) {
  197. $objWriter->startElement('w:rPr');
  198. $objWriter->startElement('w:rStyle');
  199. $objWriter->writeAttribute('w:val', $styleFont);
  200. $objWriter->endElement();
  201. $objWriter->endElement();
  202. }
  203. $objWriter->startElement('w:instrText');
  204. $objWriter->writeAttribute('xml:space', 'preserve');
  205. $objWriter->writeRaw($text);
  206. $objWriter->endElement();
  207. $objWriter->endElement();
  208. $objWriter->startElement('w:r');
  209. $objWriter->startElement('w:fldChar');
  210. $objWriter->writeAttribute('w:fldCharType', 'separate');
  211. $objWriter->endElement();
  212. $objWriter->endElement();
  213. $objWriter->startElement('w:r');
  214. $objWriter->startElement('w:fldChar');
  215. $objWriter->writeAttribute('w:fldCharType', 'end');
  216. $objWriter->endElement();
  217. $objWriter->endElement();
  218. } else {
  219. $text = htmlspecialchars($text);
  220. $text = PHPWord_Shared_String::ControlCharacterPHP2OOXML($text);
  221. $objWriter->startElement('w:r');
  222. if($SfIsObject) {
  223. $this->_writeTextStyle($objWriter, $styleFont);
  224. } elseif(!$SfIsObject && !is_null($styleFont)) {
  225. $objWriter->startElement('w:rPr');
  226. $objWriter->startElement('w:rStyle');
  227. $objWriter->writeAttribute('w:val', $styleFont);
  228. $objWriter->endElement();
  229. $objWriter->endElement();
  230. }
  231. $objWriter->startElement('w:t');
  232. $objWriter->writeAttribute('xml:space', 'preserve');
  233. $objWriter->writeRaw($text);
  234. $objWriter->endElement();
  235. $objWriter->endElement();
  236. }
  237. }
  238. $objWriter->endElement(); // p
  239. }
  240. protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Font $style) {
  241. $font = $style->getName();
  242. $bold = $style->getBold();
  243. $italic = $style->getItalic();
  244. $color = $style->getColor();
  245. $size = $style->getSize();
  246. $fgColor = $style->getFgColor();
  247. $striketrough = $style->getStrikethrough();
  248. $underline = $style->getUnderline();
  249. $objWriter->startElement('w:rPr');
  250. // Font
  251. if($font != 'Arial') {
  252. $objWriter->startElement('w:rFonts');
  253. $objWriter->writeAttribute('w:eastAsia', $font);
  254. $objWriter->writeAttribute('w:ascii', $font);
  255. $objWriter->writeAttribute('w:hAnsi', $font);
  256. $objWriter->writeAttribute('w:cs', $font);
  257. $objWriter->endElement();
  258. }
  259. // Color
  260. if($color != '000000') {
  261. $objWriter->startElement('w:color');
  262. $objWriter->writeAttribute('w:val', $color);
  263. $objWriter->endElement();
  264. }
  265. // Size
  266. if($size != 20) {
  267. $objWriter->startElement('w:sz');
  268. $objWriter->writeAttribute('w:val', $size);
  269. $objWriter->endElement();
  270. $objWriter->startElement('w:szCs');
  271. $objWriter->writeAttribute('w:val', $size);
  272. $objWriter->endElement();
  273. }
  274. // Bold
  275. if($bold) {
  276. $objWriter->writeElement('w:b', null);
  277. }
  278. // Italic
  279. if($italic) {
  280. $objWriter->writeElement('w:i', null);
  281. $objWriter->writeElement('w:iCs', null);
  282. }
  283. // Underline
  284. if(!is_null($underline) && $underline != 'none') {
  285. $objWriter->startElement('w:u');
  286. $objWriter->writeAttribute('w:val', $underline);
  287. $objWriter->endElement();
  288. }
  289. // Striketrough
  290. if($striketrough) {
  291. $objWriter->writeElement('w:strike', null);
  292. }
  293. // Foreground-Color
  294. if(!is_null($fgColor)) {
  295. $objWriter->startElement('w:highlight');
  296. $objWriter->writeAttribute('w:val', $fgColor);
  297. $objWriter->endElement();
  298. }
  299. $objWriter->endElement();
  300. }
  301. protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null) {
  302. $objWriter->writeElement('w:p', null);
  303. }
  304. protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Table $table) {
  305. $_rows = $table->getRows();
  306. $_cRows = count($_rows);
  307. if($_cRows > 0) {
  308. $objWriter->startElement('w:tbl');
  309. $tblStyle = $table->getStyle();
  310. if($tblStyle instanceof PHPWord_Style_Table) {
  311. $this->_writeTableStyle($objWriter, $tblStyle);
  312. } else {
  313. if(!empty($tblStyle)) {
  314. $objWriter->startElement('w:tblPr');
  315. $objWriter->startElement('w:tblStyle');
  316. $objWriter->writeAttribute('w:val', $tblStyle);
  317. $objWriter->endElement();
  318. $objWriter->endElement();
  319. }
  320. }
  321. $_heights = $table->getRowHeights();
  322. for($i=0; $i<$_cRows; $i++) {
  323. $row = $_rows[$i];
  324. $height = $_heights[$i];
  325. $objWriter->startElement('w:tr');
  326. if(!is_null($height)) {
  327. $objWriter->startElement('w:trPr');
  328. $objWriter->startElement('w:trHeight');
  329. $objWriter->writeAttribute('w:val', $height);
  330. $objWriter->endElement();
  331. $objWriter->endElement();
  332. }
  333. foreach($row as $cell) {
  334. $objWriter->startElement('w:tc');
  335. $cellStyle = $cell->getStyle();
  336. $width = $cell->getWidth();
  337. $objWriter->startElement('w:tcPr');
  338. $objWriter->startElement('w:tcW');
  339. $objWriter->writeAttribute('w:w', $width);
  340. $objWriter->writeAttribute('w:type', 'dxa');
  341. $objWriter->endElement();
  342. if($cellStyle instanceof PHPWord_Style_Cell) {
  343. $this->_writeCellStyle($objWriter, $cellStyle);
  344. }
  345. $objWriter->endElement();
  346. $_elements = $cell->getElements();
  347. if(count($_elements) > 0) {
  348. foreach($_elements as $element) {
  349. if($element instanceof PHPWord_Section_Text) {
  350. $this->_writeText($objWriter, $element);
  351. } elseif($element instanceof PHPWord_Section_TextRun) {
  352. $this->_writeTextRun($objWriter, $element);
  353. } elseif($element instanceof PHPWord_Section_Link) {
  354. $this->_writeLink($objWriter, $element);
  355. } elseif($element instanceof PHPWord_Section_TextBreak) {
  356. $this->_writeTextBreak($objWriter);
  357. } elseif($element instanceof PHPWord_Section_ListItem) {
  358. $this->_writeListItem($objWriter, $element);
  359. } elseif($element instanceof PHPWord_Section_Image ||
  360. $element instanceof PHPWord_Section_MemoryImage) {
  361. $this->_writeImage($objWriter, $element);
  362. } elseif($element instanceof PHPWord_Section_Object) {
  363. $this->_writeObject($objWriter, $element);
  364. } elseif($element instanceof PHPWord_Section_Footer_PreserveText) {
  365. $this->_writePreserveText($objWriter, $element);
  366. }
  367. }
  368. } else {
  369. $this->_writeTextBreak($objWriter);
  370. }
  371. $objWriter->endElement();
  372. }
  373. $objWriter->endElement();
  374. }
  375. $objWriter->endElement();
  376. }
  377. }
  378. protected function _writeTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Table $style = null) {
  379. $margins = $style->getCellMargin();
  380. $mTop = (!is_null($margins[0])) ? true : false;
  381. $mLeft = (!is_null($margins[1])) ? true : false;
  382. $mRight = (!is_null($margins[2])) ? true : false;
  383. $mBottom = (!is_null($margins[3])) ? true : false;
  384. if($mTop || $mLeft || $mRight || $mBottom) {
  385. $objWriter->startElement('w:tblPr');
  386. $objWriter->startElement('w:tblCellMar');
  387. if($mTop) {
  388. $objWriter->startElement('w:top');
  389. $objWriter->writeAttribute('w:w', $margins[0]);
  390. $objWriter->writeAttribute('w:type', 'dxa');
  391. $objWriter->endElement();
  392. }
  393. if($mLeft) {
  394. $objWriter->startElement('w:left');
  395. $objWriter->writeAttribute('w:w', $margins[1]);
  396. $objWriter->writeAttribute('w:type', 'dxa');
  397. $objWriter->endElement();
  398. }
  399. if($mRight) {
  400. $objWriter->startElement('w:right');
  401. $objWriter->writeAttribute('w:w', $margins[2]);
  402. $objWriter->writeAttribute('w:type', 'dxa');
  403. $objWriter->endElement();
  404. }
  405. if($mBottom) {
  406. $objWriter->startElement('w:bottom');
  407. $objWriter->writeAttribute('w:w', $margins[3]);
  408. $objWriter->writeAttribute('w:type', 'dxa');
  409. $objWriter->endElement();
  410. }
  411. $objWriter->endElement();
  412. $objWriter->endElement();
  413. }
  414. }
  415. protected function _writeCellStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Cell $style = null) {
  416. $bgColor = $style->getBgColor();
  417. $valign = $style->getVAlign();
  418. $align = $style->getAlign();
  419. $textDir = $style->getTextDirection();
  420. $brdSz = $style->getBorderSize();
  421. $brdCol = $style->getBorderColor();
  422. $hMerge = $style->getHMerge(); // rowspan
  423. $vMerge = $style->getVMerge(); // colspan
  424. $bTop = (!is_null($brdSz[0])) ? true : false;
  425. $bLeft = (!is_null($brdSz[1])) ? true : false;
  426. $bRight = (!is_null($brdSz[2])) ? true : false;
  427. $bBottom = (!is_null($brdSz[3])) ? true : false;
  428. $borders = ($bTop || $bLeft || $bRight || $bBottom) ? true : false;
  429. $styles = (!is_null($bgColor) || !is_null($valign) || !is_null($align) || !is_null($textDir) || $borders || !is_null($hMerge) || !is_null($vMerge)) ? true : false;
  430. if($styles) {
  431. if(!is_null($textDir)) {
  432. $objWriter->startElement('w:textDirection');
  433. $objWriter->writeAttribute('w:val', $textDir);
  434. $objWriter->endElement();
  435. }
  436. if(!is_null($bgColor)) {
  437. $objWriter->startElement('w:shd');
  438. $objWriter->writeAttribute('w:val', 'clear');
  439. $objWriter->writeAttribute('w:color', 'auto');
  440. $objWriter->writeAttribute('w:fill', $bgColor);
  441. $objWriter->endElement();
  442. }
  443. if(!is_null($valign)) {
  444. $objWriter->startElement('w:vAlign');
  445. $objWriter->writeAttribute('w:val', $valign);
  446. $objWriter->endElement();
  447. }
  448. if ( !is_null($align))
  449. {
  450. $objWriter->startElement('w:jc');
  451. $objWriter->writeAttribute('w:val', $align);
  452. $objWriter->endElement();
  453. }
  454. if ( !is_null($hMerge))
  455. {
  456. $objWriter->startElement('w:hMerge');
  457. $objWriter->writeAttribute('w:val', $hMerge);
  458. $objWriter->endElement();
  459. }
  460. if ( !is_null($vMerge))
  461. {
  462. $objWriter->startElement('w:vMerge');
  463. $objWriter->writeAttribute('w:val', $vMerge);
  464. $objWriter->endElement();
  465. }
  466. if($borders) {
  467. $_defaultColor = $style->getDefaultBorderColor();
  468. $objWriter->startElement('w:tcBorders');
  469. if($bTop) {
  470. if(is_null($brdCol[0])) { $brdCol[0] = $_defaultColor; }
  471. $objWriter->startElement('w:top');
  472. $objWriter->writeAttribute('w:val', 'single');
  473. $objWriter->writeAttribute('w:sz', $brdSz[0]);
  474. $objWriter->writeAttribute('w:color', $brdCol[0]);
  475. $objWriter->endElement();
  476. }
  477. if($bLeft) {
  478. if(is_null($brdCol[1])) { $brdCol[1] = $_defaultColor; }
  479. $objWriter->startElement('w:left');
  480. $objWriter->writeAttribute('w:val', 'single');
  481. $objWriter->writeAttribute('w:sz', $brdSz[1]);
  482. $objWriter->writeAttribute('w:color', $brdCol[1]);
  483. $objWriter->endElement();
  484. }
  485. if($bRight) {
  486. if(is_null($brdCol[2])) { $brdCol[2] = $_defaultColor; }
  487. $objWriter->startElement('w:right');
  488. $objWriter->writeAttribute('w:val', 'single');
  489. $objWriter->writeAttribute('w:sz', $brdSz[2]);
  490. $objWriter->writeAttribute('w:color', $brdCol[2]);
  491. $objWriter->endElement();
  492. }
  493. if($bBottom) {
  494. if(is_null($brdCol[3])) { $brdCol[3] = $_defaultColor; }
  495. $objWriter->startElement('w:bottom');
  496. $objWriter->writeAttribute('w:val', 'single');
  497. $objWriter->writeAttribute('w:sz', $brdSz[3]);
  498. $objWriter->writeAttribute('w:color', $brdCol[3]);
  499. $objWriter->endElement();
  500. }
  501. $objWriter->endElement();
  502. }
  503. }
  504. }
  505. protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, $image) {
  506. $rId = $image->getRelationId();
  507. $style = $image->getStyle();
  508. $width = $style->getWidth();
  509. $height = $style->getHeight();
  510. $align = $style->getAlign();
  511. $objWriter->startElement('w:p');
  512. if(!is_null($align)) {
  513. $objWriter->startElement('w:pPr');
  514. $objWriter->startElement('w:jc');
  515. $objWriter->writeAttribute('w:val', $align);
  516. $objWriter->endElement();
  517. $objWriter->endElement();
  518. }
  519. $objWriter->startElement('w:r');
  520. $objWriter->startElement('w:pict');
  521. $objWriter->startElement('v:shape');
  522. $objWriter->writeAttribute('type', '#_x0000_t75');
  523. $objWriter->writeAttribute('style', 'width:'.$width.'px;height:'.$height.'px');
  524. $objWriter->startElement('v:imagedata');
  525. $objWriter->writeAttribute('r:id', 'rId'.$rId);
  526. $objWriter->writeAttribute('o:title', '');
  527. $objWriter->endElement();
  528. $objWriter->endElement();
  529. $objWriter->endElement();
  530. $objWriter->endElement();
  531. $objWriter->endElement();
  532. }
  533. protected function _writeWatermark(PHPWord_Shared_XMLWriter $objWriter = null, $image) {
  534. $rId = $image->getRelationId();
  535. $style = $image->getStyle();
  536. $width = $style->getWidth();
  537. $height = $style->getHeight();
  538. $marginLeft = $style->getMarginLeft();
  539. $marginTop = $style->getMarginTop();
  540. $objWriter->startElement('w:p');
  541. $objWriter->startElement('w:r');
  542. $objWriter->startElement('w:pict');
  543. $objWriter->startElement('v:shape');
  544. $objWriter->writeAttribute('type', '#_x0000_t75');
  545. $strStyle = 'position:absolute;';
  546. $strStyle .= ' width:'.$width.'px;';
  547. $strStyle .= ' height:'.$height.'px;';
  548. if(!is_null($marginTop)) {
  549. $strStyle .= ' margin-top:'.$marginTop.'px;';
  550. }
  551. if(!is_null($marginLeft)) {
  552. $strStyle .= ' margin-left:'.$marginLeft.'px;';
  553. }
  554. $objWriter->writeAttribute('style', $strStyle);
  555. $objWriter->startElement('v:imagedata');
  556. $objWriter->writeAttribute('r:id', 'rId'.$rId);
  557. $objWriter->writeAttribute('o:title', '');
  558. $objWriter->endElement();
  559. $objWriter->endElement();
  560. $objWriter->endElement();
  561. $objWriter->endElement();
  562. $objWriter->endElement();
  563. }
  564. protected function _writeTitle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Title $title) {
  565. $text = htmlspecialchars($title->getText());
  566. $text = PHPWord_Shared_String::ControlCharacterPHP2OOXML($text);
  567. $anchor = $title->getAnchor();
  568. $bookmarkId = $title->getBookmarkId();
  569. $style = $title->getStyle();
  570. $objWriter->startElement('w:p');
  571. if(!empty($style)) {
  572. $objWriter->startElement('w:pPr');
  573. $objWriter->startElement('w:pStyle');
  574. $objWriter->writeAttribute('w:val', $style);
  575. $objWriter->endElement();
  576. $objWriter->endElement();
  577. }
  578. $objWriter->startElement('w:r');
  579. $objWriter->startElement('w:fldChar');
  580. $objWriter->writeAttribute('w:fldCharType', 'end');
  581. $objWriter->endElement();
  582. $objWriter->endElement();
  583. $objWriter->startElement('w:bookmarkStart');
  584. $objWriter->writeAttribute('w:id', $bookmarkId);
  585. $objWriter->writeAttribute('w:name', $anchor);
  586. $objWriter->endElement();
  587. $objWriter->startElement('w:r');
  588. $objWriter->startElement('w:t');
  589. $objWriter->writeRaw($text);
  590. $objWriter->endElement();
  591. $objWriter->endElement();
  592. $objWriter->startElement('w:bookmarkEnd');
  593. $objWriter->writeAttribute('w:id', $bookmarkId);
  594. $objWriter->endElement();
  595. $objWriter->endElement();
  596. }
  597. }
  598. ?>