Forum


Replies: 2   Views: 1475
Chinese font is not applied to chinese characters
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 04-12-2020 - 07:26

Hello,

Thanks for sending the requested files. The problem comes from one missing attribute support when using the font option with addText: w:eastAsia is not being applied and your font needs it.

We recommend you to use custom paragraph styles (and custom character styles if needed), both methods createParagraphStyle and createCharacterStyle support w:eastAsian attributes:

// style options
$style = array(
  'font' => 'fontname',
);
// create custom style
$docx->createParagraphStyle('myStyle', $style);

If you want to add support for w:eastAsian attribute in addText method with the font option without using custom paragraph/character styles, please edit CreateElement.php, and go to generateRFONTS method, instead of:

protected function generateRFONTS($font)
{
  $xml = '<' . CreateElement::NAMESPACEWORD .
    ':rFonts ' . CreateElement::NAMESPACEWORD .
    ':ascii="' . $font . '" ' . CreateElement::NAMESPACEWORD .
    ':hAnsi="' . $font . '" ' . CreateElement::NAMESPACEWORD .
    ':cs="' . $font . '"></' . CreateElement::NAMESPACEWORD .
    ':rFonts>__GENERATERPR__';

  $this->_xml = str_replace('__GENERATERPR__', $xml, $this->_xml);
}

replace it by:

protected function generateRFONTS($font)
{
  $xml = '<' . CreateElement::NAMESPACEWORD .
    ':rFonts ' . CreateElement::NAMESPACEWORD .
    ':ascii="' . $font . '" ' . CreateElement::NAMESPACEWORD .
    ':hAnsi="' . $font . '" ' . CreateElement::NAMESPACEWORD .
    ':eastAsia="' . $font . '" ' . CreateElement::NAMESPACEWORD .
    ':cs="' . $font . '"></' . CreateElement::NAMESPACEWORD .
    ':rFonts>__GENERATERPR__';

  $this->_xml = str_replace('__GENERATERPR__', $xml, $this->_xml);
}

The same change has been included in the current development branch and will be added to the next release of phpdocx.

Regards.