CreateFontTable.inc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /**
  3. * Create font 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 font 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 CreateFontTable extends CreateElement
  28. {
  29. /**
  30. *
  31. * @var string
  32. * @access protected
  33. */
  34. protected $_xml;
  35. /**
  36. *
  37. * @var CreateFontTable
  38. * @access private
  39. * @static
  40. */
  41. private static $_instance = NULL;
  42. /**
  43. * Construct
  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. *
  60. * @return string
  61. * @access public
  62. */
  63. public function __toString()
  64. {
  65. return $this->_xml;
  66. }
  67. /**
  68. *
  69. * @return CreateFontTable
  70. * @access public
  71. * @static
  72. */
  73. public static function getInstance()
  74. {
  75. if (self::$_instance == NULL) {
  76. self::$_instance = new CreateFontTable();
  77. }
  78. return self::$_instance;
  79. }
  80. /**
  81. * Create font
  82. *
  83. * @access public
  84. * @param array args[0]
  85. */
  86. public function createFont()
  87. {
  88. $this->_xml = '';
  89. $args = func_get_args();
  90. if (!empty($args[0]['name']) && !empty($args[0]['pitch']) &&
  91. !empty($args[0]['usb0']) && !empty($args[0]['usb1']) &&
  92. !empty($args[0]['usb2']) && !empty($args[0]['usb3']) &&
  93. !empty($args[0]['csb0']) && !empty($args[0]['csb1']) &&
  94. !empty($args[0]['family']) && !empty($args[0]['charset']) &&
  95. !empty($args[0]['panose1'])
  96. ) {
  97. $this->generateFONT($args[0]['name']);
  98. $this->generatePANOSE1($args[0]['panose1']);
  99. $this->generateCHARSET($args[0]['charset']);
  100. $this->generateFAMILY($args[0]['family']);
  101. $this->generatePITCH($args[0]['pitch']);
  102. $this->generateSIG(
  103. $args[0]['usb0'], $args[0]['usb1'], $args[0]['usb2'],
  104. $args[0]['usb3'], $args[0]['csb0'], $args[0]['csb1']
  105. );
  106. } else {
  107. exit('You`re adding an empty font');
  108. }
  109. }
  110. /**
  111. * Generate w:font
  112. *
  113. * @param string $name
  114. * @access protected
  115. */
  116. protected function generateFONT($name = 'Calibri')
  117. {
  118. $this->_xml = '<' . CreateElement::NAMESPACEWORD .
  119. ':font ' . CreateDocx::NAMESPACEWORD .
  120. ':name="' . $name .
  121. '">__GENERATEFONT__</' . CreateElement::NAMESPACEWORD .
  122. ':font>';
  123. }
  124. /**
  125. * Generate w:panose1
  126. *
  127. * @param string $val
  128. * @access protected
  129. */
  130. protected function generatePANOSE1($val = '020F0502020204030204')
  131. {
  132. $xml = '<' . CreateElement::NAMESPACEWORD .
  133. ':panose1 ' . CreateElement::NAMESPACEWORD .
  134. ':val="' . $val .
  135. '"></' . CreateElement::NAMESPACEWORD .
  136. ':panose1>__GENERATEPANOSE1__';
  137. $this->_xml = str_replace('__GENERATEFONT__', $xml, $this->_xml);
  138. }
  139. /**
  140. * Generate w:charset
  141. *
  142. * @param string $val
  143. * @access protected
  144. */
  145. protected function generateCHARSET($val = '00')
  146. {
  147. $xml = '<' . CreateElement::NAMESPACEWORD .
  148. ':charset ' . CreateElement::NAMESPACEWORD .
  149. ':val="' . $val . '"></' . CreateElement::NAMESPACEWORD .
  150. ':charset>__GENERATECHARSET__';
  151. $this->_xml = str_replace('__GENERATEPANOSE1__', $xml, $this->_xml);
  152. }
  153. /**
  154. * Generate w:family
  155. *
  156. * @param string $val
  157. * @access protected
  158. */
  159. protected function generateFAMILY($val = 'swiss')
  160. {
  161. $xml = '<' . CreateElement::NAMESPACEWORD .
  162. ':family ' . CreateElement::NAMESPACEWORD .
  163. ':val="' . $val .
  164. '"></' . CreateElement::NAMESPACEWORD .
  165. ':family>__GENERATEFAMILY__';
  166. $this->_xml = str_replace('__GENERATECHARSET__', $xml, $this->_xml);
  167. }
  168. /**
  169. * Generate w:pitch
  170. *
  171. * @param string $val
  172. * @access protected
  173. */
  174. protected function generatePITCH($val = '00')
  175. {
  176. $xml = '<' . CreateElement::NAMESPACEWORD .
  177. ':pitch ' . CreateElement::NAMESPACEWORD .
  178. ':val="' . $val .
  179. '"></' . CreateElement::NAMESPACEWORD .
  180. ':pitch>__GENERATEPITCH__';
  181. $this->_xml = str_replace('__GENERATEFAMILY__', $xml, $this->_xml);
  182. }
  183. /**
  184. * Generate w:sig
  185. *
  186. * @param string $usbA
  187. * @param string $usbB
  188. * @param string $usbC
  189. * @param string $usbD
  190. * @param string $csbA
  191. * @param string $csbB
  192. * @access protected
  193. */
  194. protected function generateSIG($usbA = 'A00002EF', $usbB = '4000207B',
  195. $usbC = '00000000', $usbD = '00000000',
  196. $csbA = '0000009F', $csbB = '00000000')
  197. {
  198. $xml = '<' . CreateElement::NAMESPACEWORD .
  199. ':sig ' . CreateElement::NAMESPACEWORD .
  200. ':usb0="' . $usbA . '" ' . CreateElement::NAMESPACEWORD .
  201. ':usb1="' . $usbB . '" ' . CreateElement::NAMESPACEWORD .
  202. ':usb2="' . $usbC . '" ' . CreateElement::NAMESPACEWORD .
  203. ':usb3="' . $usbD . '" ' . CreateElement::NAMESPACEWORD .
  204. ':csb0="' . $csbA . '" ' . CreateElement::NAMESPACEWORD .
  205. ':csb1="' . $csbB . '"></' . CreateElement::NAMESPACEWORD .
  206. ':sig>';
  207. $this->_xml = str_replace('__GENERATEPITCH__', $xml, $this->_xml);
  208. }
  209. }