@@ -37,6 +37,11 @@ class Font extends AbstractStyle
37
37
*/
38
38
private $ colorIndex = 0 ;
39
39
40
+ /**
41
+ * @var int Font lang index
42
+ */
43
+ private $ langIndex = 0 ;
44
+
40
45
/**
41
46
* Write style.
42
47
*
@@ -50,20 +55,66 @@ public function write()
50
55
}
51
56
52
57
$ content = '' ;
53
- $ content .= $ this -> getValueIf ( $ style -> isRTL (), ' \rtlch ' );
54
- $ content .= ' \cf ' . $ this -> colorIndex ;
58
+
59
+ // Font Name
55
60
$ content .= '\f ' . $ this ->nameIndex ;
56
61
57
- $ size = $ style ->getSize ();
58
- $ content .= $ this ->getValueIf (is_numeric ($ size ), '\fs ' . round ($ size * 2 ));
62
+ // Basic - same order as array found in PhpOffice\PhpWord\Style\Font\getStyleValues
63
+ $ content .= $ this ->getValueIf ($ style ->getName () !== null , '\f ' . $ this ->nameIndex ); // Doesn't work; fonts not implemented.
64
+ $ content .= $ this ->getValueIf ($ style ->getSize () !== null , '\fs ' . round ($ style ->getSize () * 2 ));
65
+ $ content .= $ this ->getValueIf ($ style ->getColor () !== null , '\cf ' . $ this ->colorIndex ); // Doesn't work; coloring not implemented.
66
+ // Hint (font content type) not implemented.
67
+
68
+ // Underline Keywords
69
+ $ underlines = [
70
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_DASH => '\uldash ' ,
71
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_DASHHEAVY => '\ulth ' ,
72
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_DASHLONG => '\ulldash ' ,
73
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_DASHLONGHEAVY => '\ulthldash ' ,
74
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_DOUBLE => '\uldb ' ,
75
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_DOTDASH => '\uldashd ' ,
76
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_DOTDASHHEAVY => '\ulthdashd ' ,
77
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_DOTDOTDASH => '\uldashdd ' ,
78
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_DOTDOTDASHHEAVY => '\ulthdashdd ' ,
79
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_DOTTED => '\uld ' ,
80
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_DOTTEDHEAVY => '\ulthd ' ,
81
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_HEAVY => '\ulth ' ,
82
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_SINGLE => '\ul ' ,
83
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_WAVY => '\ulwave ' ,
84
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_WAVYDOUBLE => '\ululdbwave ' ,
85
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_WAVYHEAVY => '\ulhwave ' ,
86
+ \PhpOffice \PhpWord \Style \Font::UNDERLINE_WORDS => '\ulw ' ,
87
+ ];
59
88
89
+ // Style - same order as array found in PhpOffice\PhpWord\Style\Font\getStyleValues
60
90
$ content .= $ this ->getValueIf ($ style ->isBold (), '\b ' );
61
91
$ content .= $ this ->getValueIf ($ style ->isItalic (), '\i ' );
62
- $ content .= $ this -> getValueIf ( $ style ->getUnderline () != FontStyle:: UNDERLINE_NONE , ' \ul ' );
92
+ if ( isset ( $ underlines [ $ style -> getUnderline ()])) { $ content .= $ underlines [ $ style ->getUnderline ()]; }
63
93
$ content .= $ this ->getValueIf ($ style ->isStrikethrough (), '\strike ' );
94
+ $ content .= $ this ->getValueIf ($ style ->isDoubleStrikethrough (), '\striked1 ' );
64
95
$ content .= $ this ->getValueIf ($ style ->isSuperScript (), '\super ' );
65
96
$ content .= $ this ->getValueIf ($ style ->isSubScript (), '\sub ' );
97
+ $ content .= $ this ->getValueIf ($ style ->isSmallCaps (), '\scaps ' );
98
+ $ content .= $ this ->getValueIf ($ style ->isAllCaps (), '\caps ' );
99
+ $ content .= $ this ->getValueIf ($ style ->getFgColor () !== null , '\highlight ' . $ this ->colorIndex ); // Doesn't work; coloring not implemented.
100
+ $ content .= $ this ->getValueIf ($ style ->isHidden (), '\v ' );
101
+
102
+ // Spacing - same order as array found in PhpOffice\PhpWord\Style\Font\getStyleValues
103
+ $ content .= $ this ->getValueIf ($ style ->getScale () !== null , '\charscalex ' . $ style ->getScale ());
104
+ $ content .= $ this ->getValueIf ($ style ->getSpacing () !== null , '\expnd ' . $ style ->getSpacing ());
105
+ $ content .= $ this ->getValueIf ($ style ->getKerning () !== null , '\kerning ' . $ style ->getKerning () * 2 );
106
+ $ content .= $ this ->getValueIf ($ style ->getPosition () !== null , '\up ' . $ style ->getPosition ());
66
107
108
+ // General - same order as array found in PhpOffice\PhpWord\Style\Font\getStyleValues
109
+ // Paragraph not implemented.
110
+ $ content .= $ this ->getValueIf ($ style ->isRTL (), '\rtlch ' );
111
+ $ content .= $ this ->getValueIf ($ style ->getShading () !== null , '\chcfpat ' . $ this ->colorIndex ); // Doesn't work; coloring not implemented.
112
+ $ content .= $ this ->getValueIf ($ style ->getColor () !== null , '\lnag ' . $ this ->langIndex ); // Doesn't work; language not implemented.
113
+ // Whitespace and fallbackFont are HTML specific
114
+
115
+ // Other items not in included in array found in PhpOffice\PhpWord\Style\Font\getStyleValues
116
+ $ content .= $ this ->getValueIf ($ style ->isNoProof (), '\noproof ' );
117
+ $ content .= $ this ->getValueIf ($ style ->getBgColor () !== null , '\cb ' . $ this ->colorIndex ); // Doesn't work; coloring not implemented.
67
118
return $ content . ' ' ;
68
119
}
69
120
@@ -86,4 +137,13 @@ public function setColorIndex($value = 0): void
86
137
{
87
138
$ this ->colorIndex = $ value ;
88
139
}
140
+ /**
141
+ * Set font lang index.
142
+ *
143
+ * @param int $value
144
+ */
145
+ public function setLangIndex ($ value = 0 ): void
146
+ {
147
+ $ this ->langIndex = $ value ;
148
+ }
89
149
}
0 commit comments