@@ -36,10 +36,6 @@ class Paragraph extends AbstractStyle
3636 */
3737 private $ nestedLevel = 0 ;
3838
39- private const LEFT = Jc::LEFT ;
40- private const RIGHT = Jc::RIGHT ;
41- private const JUSTIFY = Jc::JUSTIFY ;
42-
4339 /**
4440 * Write style.
4541 *
@@ -57,69 +53,75 @@ public function write()
5753 Jc::END => '\qr ' ,
5854 Jc::CENTER => '\qc ' ,
5955 Jc::BOTH => '\qj ' ,
60- self ::LEFT => '\ql ' ,
61- self ::RIGHT => '\qr ' ,
62- self ::JUSTIFY => '\qj ' ,
56+ Jc::LEFT => '\ql ' ,
57+ Jc::RIGHT => '\qr ' ,
58+ Jc::JUSTIFY => '\qj ' ,
59+ Jc::DISTRIBUTE => '\qd ' ,
60+ Jc::THAI_DISTRIBUTE => '\qt ' ,
61+ Jc::HIGH_KASHIDA => '\qk20 ' ,
62+ Jc::MEDIUM_KASHIDA => '\qk10 ' ,
63+ Jc::LOW_KASHIDA => '\qk0 ' ,
6364 ];
6465 $ bidiAlignments = [
6566 Jc::START => '\qr ' ,
6667 Jc::END => '\ql ' ,
6768 Jc::CENTER => '\qc ' ,
6869 Jc::BOTH => '\qj ' ,
69- self ::LEFT => '\ql ' ,
70- self ::RIGHT => '\qr ' ,
71- self ::JUSTIFY => '\qj ' ,
70+ Jc::LEFT => '\ql ' ,
71+ Jc::RIGHT => '\qr ' ,
72+ Jc::JUSTIFY => '\qj ' ,
73+ Jc::DISTRIBUTE => '\qd ' ,
74+ Jc::THAI_DISTRIBUTE => '\qt ' ,
75+ Jc::HIGH_KASHIDA => '\qk20 ' ,
76+ Jc::MEDIUM_KASHIDA => '\qk10 ' ,
77+ Jc::LOW_KASHIDA => '\qk0 ' ,
7278 ];
7379
74- $ spaceAfter = $ style ->getSpaceAfter ();
75- $ spaceBefore = $ style ->getSpaceBefore ();
76-
7780 $ content = '' ;
7881 if ($ this ->nestedLevel == 0 ) {
79- $ content .= '\pard\nowidctlpar ' ;
82+ $ content .= '\pard ' ;
8083 }
84+
85+ // Alignment
8186 $ alignment = $ style ->getAlignment ();
8287 $ bidi = $ style ->isBidi ();
8388 if ($ alignment === '' && $ bidi !== null ) {
8489 $ alignment = Jc::START ;
8590 }
91+
92+ // Right to left
8693 if (isset ($ alignments [$ alignment ])) {
8794 $ content .= $ bidi ? $ bidiAlignments [$ alignment ] : $ alignments [$ alignment ];
8895 }
89- $ content .= $ this ->writeIndentation ($ style ->getIndentation ());
90- $ content .= $ this ->getValueIf ($ spaceBefore !== null , '\sb ' . round ($ spaceBefore ?? 0 ));
91- $ content .= $ this ->getValueIf ($ spaceAfter !== null , '\sa ' . round ($ spaceAfter ?? 0 ));
92- $ lineHeight = $ style ->getLineHeight ();
93- if ($ lineHeight ) {
94- $ lineHeightAdjusted = (int ) ($ lineHeight * 240 );
95- $ content .= "\\sl $ lineHeightAdjusted \\slmult1 " ;
96- }
97- if ($ style ->hasPageBreakBefore ()) {
98- $ content .= '\\page ' ;
99- }
96+ $ content .= $ this ->getValueIf ($ style ->isBidi (), '\rtlpar ' );
97+
98+ // Indentation
99+ $ content .= $ this ->writeChildStyle ('Indentation ' , $ style ->getIndentation ());
100+ $ content .= $ this ->writeChildStyle ('Spacing ' , $ style ->getSpace ());
101+ // Future: Add Shading
100102
101103 $ styles = $ style ->getStyleValues ();
102104 $ content .= $ this ->writeTabs ($ styles ['tabs ' ]);
103105
104- return $ content ;
105- }
106+ // Contextual Spacing
107+ $ content .= $ this ->getValueIf ($ style ->hasContextualSpacing (), '\contextualspace ' );
108+ // Future: Add Text Alignment
106109
107- /**
108- * Writes an \PhpOffice\PhpWord\Style\Indentation.
109- *
110- * @param null|\PhpOffice\PhpWord\Style\Indentation $indent
111- *
112- * @return string
113- */
114- private function writeIndentation ($ indent = null )
115- {
116- if (isset ($ indent ) && $ indent instanceof \PhpOffice \PhpWord \Style \Indentation) {
117- $ writer = new Indentation ($ indent );
110+ // Pagination
111+ $ content .= $ this ->getValueIf ($ style ->hasWidowControl (), '\widctlpar ' );
112+ $ content .= $ this ->getValueIf (!$ style ->hasWidowControl (), '\nowidctlpar ' );
113+ $ content .= $ this ->getValueIf ($ style ->isKeepNext (), '\keepn ' );
114+ $ content .= $ this ->getValueIf ($ style ->isKeepLines (), '\keep ' );
115+ $ content .= $ this ->getValueIf ($ style ->hasPageBreakBefore (), '\pagebb ' );
118116
119- return $ writer ->write ();
120- }
117+ // Hyphenation
118+ $ content .= $ this ->getValueIf ($ style ->hasSuppressAutoHyphens (), '\hyphpar0 ' );
119+
120+ // Tabs
121+ $ styles = $ style ->getStyleValues ();
122+ $ content .= $ this ->writeTabs ($ styles ['tabs ' ]);
121123
122- return ' ' ;
124+ return $ content . ' ' ;
123125 }
124126
125127 /**
0 commit comments