Skip to content

Commit ea83d11

Browse files
author
Jui-Nan Lin
committed
feat(font): add default asian font name
1 parent feadceb commit ea83d11

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

src/PhpWord/PhpWord.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,26 @@ public function setDefaultFontName($fontName): void
256256
Settings::setDefaultFontName($fontName);
257257
}
258258

259+
/**
260+
* Get default asian font name.
261+
*
262+
* @return string
263+
*/
264+
public function getDefaultAsianFontName()
265+
{
266+
return Settings::getDefaultAsianFontName();
267+
}
268+
269+
/**
270+
* Set default font name.
271+
*
272+
* @param string $fontName
273+
*/
274+
public function setDefaultAsianFontName($fontName): void
275+
{
276+
Settings::setDefaultAsianFontName($fontName);
277+
}
278+
259279
/**
260280
* Get default font size.
261281
*

src/PhpWord/Settings.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ class Settings
117117
*/
118118
private static $defaultFontName = self::DEFAULT_FONT_NAME;
119119

120+
/**
121+
* Default font name.
122+
*
123+
* @var string
124+
*/
125+
private static $defaultAsianFontName = self::DEFAULT_FONT_NAME;
126+
120127
/**
121128
* Default font size.
122129
*
@@ -354,6 +361,14 @@ public static function getDefaultFontName(): string
354361
return self::$defaultFontName;
355362
}
356363

364+
/**
365+
* Get default font name.
366+
*/
367+
public static function getDefaultAsianFontName(): string
368+
{
369+
return self::$defaultAsianFontName;
370+
}
371+
357372
/**
358373
* Set default font name.
359374
*/
@@ -368,6 +383,17 @@ public static function setDefaultFontName(string $value): bool
368383
return false;
369384
}
370385

386+
public static function setDefaultAsianFontName(string $value): bool
387+
{
388+
if (trim($value) !== '') {
389+
self::$defaultAsianFontName = $value;
390+
391+
return true;
392+
}
393+
394+
return false;
395+
}
396+
371397
/**
372398
* Get default font size.
373399
*

src/PhpWord/Writer/Word2007/Part/Styles.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ private function writeDefaultStyles(XMLWriter $xmlWriter, $styles): void
8383
{
8484
$phpWord = $this->getParentWriter()->getPhpWord();
8585
$fontName = $phpWord->getDefaultFontName();
86+
$asianFontName = $phpWord->getDefaultAsianFontName();
8687
$fontSize = $phpWord->getDefaultFontSize();
8788
$language = $phpWord->getSettings()->getThemeFontLang();
8889
$latinLanguage = ($language == null || $language->getLatin() === null) ? 'en-US' : $language->getLatin();
@@ -94,7 +95,7 @@ private function writeDefaultStyles(XMLWriter $xmlWriter, $styles): void
9495
$xmlWriter->startElement('w:rFonts');
9596
$xmlWriter->writeAttribute('w:ascii', $fontName);
9697
$xmlWriter->writeAttribute('w:hAnsi', $fontName);
97-
$xmlWriter->writeAttribute('w:eastAsia', $fontName);
98+
$xmlWriter->writeAttribute('w:eastAsia', $asianFontName);
9899
$xmlWriter->writeAttribute('w:cs', $fontName);
99100
$xmlWriter->endElement(); // w:rFonts
100101
$xmlWriter->startElement('w:sz');

0 commit comments

Comments
 (0)