Skip to content

Commit 70d3a1a

Browse files
committed
Merge pull request #118 from jhfangying/develop
suport for eastAsia fontstyle
2 parents 5e0fc7a + a6e91ef commit 70d3a1a

File tree

5 files changed

+123
-92
lines changed

5 files changed

+123
-92
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ vendor
1818
*.docx
1919
*.rtf
2020
*.txt
21-
*.xml
21+
*.xml
22+
nbproject

Classes/PHPWord.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ class PHPWord
4444
* Default font name (Arial)
4545
*/
4646
const DEFAULT_FONT_NAME = 'Arial';
47-
47+
/**
48+
* Default Font Content Type(default)
49+
* default|eastAsia|cs
50+
*/
51+
const DEFAULT_FONT_CONTENT_TYPE='default';
4852
/**
4953
* Default font size in points (10pt)
5054
*

Classes/PHPWord/Style/Font.php

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* PHPWord
45
*
@@ -24,14 +25,13 @@
2425
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
2526
* @version 0.7.0
2627
*/
27-
2828
use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
2929

3030
/**
3131
* Class PHPWord_Style_Font
3232
*/
33-
class PHPWord_Style_Font
34-
{
33+
class PHPWord_Style_Font {
34+
3535
const UNDERLINE_NONE = 'none';
3636
const UNDERLINE_DASH = 'dash';
3737
const UNDERLINE_DASHHEAVY = 'dashHeavy';
@@ -50,7 +50,6 @@ class PHPWord_Style_Font
5050
const UNDERLINE_WAVYDOUBLE = 'wavyDbl';
5151
const UNDERLINE_WAVYHEAVY = 'wavyHeavy';
5252
const UNDERLINE_WORDS = 'words';
53-
5453
const FGCOLOR_YELLOW = 'yellow';
5554
const FGCOLOR_LIGHTGREEN = 'green';
5655
const FGCOLOR_CYAN = 'cyan';
@@ -158,14 +157,20 @@ class PHPWord_Style_Font
158157
*/
159158
private $lineHeight = 1.0;
160159

160+
/**
161+
* Font Content Type
162+
*
163+
* @var string
164+
*/
165+
private $_hint = PHPWord::DEFAULT_FONT_CONTENT_TYPE;
166+
161167
/**
162168
* New font style
163169
*
164170
* @param string $type Type of font
165171
* @param array $paragraphStyle Paragraph styles definition
166172
*/
167-
public function __construct($type = 'text', $paragraphStyle = null)
168-
{
173+
public function __construct($type = 'text', $paragraphStyle = null) {
169174
$this->_type = $type;
170175

171176
if ($paragraphStyle instanceof PHPWord_Style_Paragraph) {
@@ -184,8 +189,7 @@ public function __construct($type = 'text', $paragraphStyle = null)
184189
* @param array $style
185190
* @return $this
186191
*/
187-
public function setArrayStyle(array $style = array())
188-
{
192+
public function setArrayStyle(array $style = array()) {
189193
foreach ($style as $key => $value) {
190194
if ($key === 'line-height') {
191195
$this->setLineHeight($value);
@@ -205,8 +209,7 @@ public function setArrayStyle(array $style = array())
205209
* @param string $key
206210
* @param mixed $value
207211
*/
208-
public function setStyleValue($key, $value)
209-
{
212+
public function setStyleValue($key, $value) {
210213
$method = 'set' . substr($key, 1);
211214
if (method_exists($this, $method)) {
212215
$this->$method($value);
@@ -218,8 +221,7 @@ public function setStyleValue($key, $value)
218221
*
219222
* @return bool
220223
*/
221-
public function getName()
222-
{
224+
public function getName() {
223225
return $this->_name;
224226
}
225227

@@ -229,22 +231,21 @@ public function getName()
229231
* @param string $pValue
230232
* @return PHPWord_Style_Font
231233
*/
232-
public function setName($pValue = PHPWord::DEFAULT_FONT_NAME)
233-
{
234+
public function setName($pValue = PHPWord::DEFAULT_FONT_NAME) {
234235
if (is_null($pValue) || $pValue == '') {
235236
$pValue = PHPWord::DEFAULT_FONT_NAME;
236237
}
237238
$this->_name = $pValue;
238239
return $this;
239240
}
241+
240242

241243
/**
242244
* Get font size
243245
*
244246
* @return int|float
245247
*/
246-
public function getSize()
247-
{
248+
public function getSize() {
248249
return $this->_size;
249250
}
250251

@@ -254,8 +255,7 @@ public function getSize()
254255
* @param int|float $pValue
255256
* @return PHPWord_Style_Font
256257
*/
257-
public function setSize($pValue = PHPWord::DEFAULT_FONT_SIZE)
258-
{
258+
public function setSize($pValue = PHPWord::DEFAULT_FONT_SIZE) {
259259
if (!is_numeric($pValue)) {
260260
$pValue = PHPWord::DEFAULT_FONT_SIZE;
261261
}
@@ -268,8 +268,7 @@ public function setSize($pValue = PHPWord::DEFAULT_FONT_SIZE)
268268
*
269269
* @return bool
270270
*/
271-
public function getBold()
272-
{
271+
public function getBold() {
273272
return $this->_bold;
274273
}
275274

@@ -279,8 +278,7 @@ public function getBold()
279278
* @param bool $pValue
280279
* @return PHPWord_Style_Font
281280
*/
282-
public function setBold($pValue = false)
283-
{
281+
public function setBold($pValue = false) {
284282
if (!is_bool($pValue)) {
285283
$pValue = false;
286284
}
@@ -293,8 +291,7 @@ public function setBold($pValue = false)
293291
*
294292
* @return bool
295293
*/
296-
public function getItalic()
297-
{
294+
public function getItalic() {
298295
return $this->_italic;
299296
}
300297

@@ -304,8 +301,7 @@ public function getItalic()
304301
* @param bool $pValue
305302
* @return PHPWord_Style_Font
306303
*/
307-
public function setItalic($pValue = false)
308-
{
304+
public function setItalic($pValue = false) {
309305
if (!is_bool($pValue)) {
310306
$pValue = false;
311307
}
@@ -318,8 +314,7 @@ public function setItalic($pValue = false)
318314
*
319315
* @return bool
320316
*/
321-
public function getSuperScript()
322-
{
317+
public function getSuperScript() {
323318
return $this->_superScript;
324319
}
325320

@@ -329,8 +324,7 @@ public function getSuperScript()
329324
* @param bool $pValue
330325
* @return PHPWord_Style_Font
331326
*/
332-
public function setSuperScript($pValue = false)
333-
{
327+
public function setSuperScript($pValue = false) {
334328
if (!is_bool($pValue)) {
335329
$pValue = false;
336330
}
@@ -344,8 +338,7 @@ public function setSuperScript($pValue = false)
344338
*
345339
* @return bool
346340
*/
347-
public function getSubScript()
348-
{
341+
public function getSubScript() {
349342
return $this->_subScript;
350343
}
351344

@@ -355,8 +348,7 @@ public function getSubScript()
355348
* @param bool $pValue
356349
* @return PHPWord_Style_Font
357350
*/
358-
public function setSubScript($pValue = false)
359-
{
351+
public function setSubScript($pValue = false) {
360352
if (!is_bool($pValue)) {
361353
$pValue = false;
362354
}
@@ -370,8 +362,7 @@ public function setSubScript($pValue = false)
370362
*
371363
* @return string
372364
*/
373-
public function getUnderline()
374-
{
365+
public function getUnderline() {
375366
return $this->_underline;
376367
}
377368

@@ -381,8 +372,7 @@ public function getUnderline()
381372
* @param string $pValue
382373
* @return PHPWord_Style_Font
383374
*/
384-
public function setUnderline($pValue = PHPWord_Style_Font::UNDERLINE_NONE)
385-
{
375+
public function setUnderline($pValue = PHPWord_Style_Font::UNDERLINE_NONE) {
386376
if ($pValue == '') {
387377
$pValue = PHPWord_Style_Font::UNDERLINE_NONE;
388378
}
@@ -395,8 +385,7 @@ public function setUnderline($pValue = PHPWord_Style_Font::UNDERLINE_NONE)
395385
*
396386
* @return bool
397387
*/
398-
public function getStrikethrough()
399-
{
388+
public function getStrikethrough() {
400389
return $this->_strikethrough;
401390
}
402391

@@ -406,8 +395,7 @@ public function getStrikethrough()
406395
* @param bool $pValue
407396
* @return PHPWord_Style_Font
408397
*/
409-
public function setStrikethrough($pValue = false)
410-
{
398+
public function setStrikethrough($pValue = false) {
411399
if (!is_bool($pValue)) {
412400
$pValue = false;
413401
}
@@ -420,8 +408,7 @@ public function setStrikethrough($pValue = false)
420408
*
421409
* @return string
422410
*/
423-
public function getColor()
424-
{
411+
public function getColor() {
425412
return $this->_color;
426413
}
427414

@@ -431,8 +418,7 @@ public function getColor()
431418
* @param string $pValue
432419
* @return PHPWord_Style_Font
433420
*/
434-
public function setColor($pValue = PHPWord::DEFAULT_FONT_COLOR)
435-
{
421+
public function setColor($pValue = PHPWord::DEFAULT_FONT_COLOR) {
436422
if (is_null($pValue) || $pValue == '') {
437423
$pValue = PHPWord::DEFAULT_FONT_COLOR;
438424
}
@@ -445,8 +431,7 @@ public function setColor($pValue = PHPWord::DEFAULT_FONT_COLOR)
445431
*
446432
* @return bool
447433
*/
448-
public function getFgColor()
449-
{
434+
public function getFgColor() {
450435
return $this->_fgColor;
451436
}
452437

@@ -456,8 +441,7 @@ public function getFgColor()
456441
* @param string $pValue
457442
* @return PHPWord_Style_Font
458443
*/
459-
public function setFgColor($pValue = null)
460-
{
444+
public function setFgColor($pValue = null) {
461445
$this->_fgColor = $pValue;
462446
return $this;
463447
}
@@ -467,8 +451,7 @@ public function setFgColor($pValue = null)
467451
*
468452
* @return string
469453
*/
470-
public function getStyleType()
471-
{
454+
public function getStyleType() {
472455
return $this->_type;
473456
}
474457

@@ -477,21 +460,18 @@ public function getStyleType()
477460
*
478461
* @return PHPWord_Style_Paragraph
479462
*/
480-
public function getParagraphStyle()
481-
{
463+
public function getParagraphStyle() {
482464
return $this->_paragraphStyle;
483465
}
484466

485-
486467
/**
487468
* Set the line height
488469
*
489470
* @param int|float|string $lineHeight
490471
* @return $this
491472
* @throws InvalidStyleException
492473
*/
493-
public function setLineHeight($lineHeight)
494-
{
474+
public function setLineHeight($lineHeight) {
495475
if (is_string($lineHeight)) {
496476
$lineHeight = floatval(preg_replace('/[^0-9\.\,]/', '', $lineHeight));
497477
}
@@ -508,8 +488,28 @@ public function setLineHeight($lineHeight)
508488
/**
509489
* @return int|float
510490
*/
511-
public function getLineHeight()
512-
{
491+
public function getLineHeight() {
513492
return $this->lineHeight;
514493
}
494+
/**
495+
* Get Font Content Type
496+
*
497+
* @return bool
498+
*/
499+
public function getHint() {
500+
return $this->_hint;
501+
}
502+
/**
503+
* Set Font Content Type
504+
*
505+
* @param string $pValue
506+
* @return PHPWord_Style_Font
507+
*/
508+
public function setHint($pValue = PHPWord::DEFAULT_FONT_CONTENT_TYPE) {
509+
if (is_null($pValue) || $pValue == '') {
510+
$pValue = PHPWord::DEFAULT_FONT_CONTENT_TYPE;
511+
}
512+
$this->_hint = $pValue;
513+
return $this;
514+
}
515515
}

0 commit comments

Comments
 (0)