@@ -96,19 +96,19 @@ protected static function parseInlineStyle($node, $styles = array())
96
96
$ attributes = $ node ->attributes ; // get all the attributes(eg: id, class)
97
97
98
98
foreach ($ attributes as $ attribute ) {
99
+ $ val = trim ($ attribute ->value );
99
100
switch (strtolower ($ attribute ->name )) {
100
101
case 'style ' :
101
102
$ styles = self ::parseStyle ($ attribute , $ styles );
102
103
break ;
103
104
case 'align ' :
104
- $ styles ['alignment ' ] = self ::mapAlign ($ attribute -> value );
105
+ $ styles ['alignment ' ] = self ::mapAlign ($ val );
105
106
break ;
106
107
case 'lang ' :
107
- $ styles ['lang ' ] = $ attribute -> value ;
108
+ $ styles ['lang ' ] = $ val ;
108
109
break ;
109
110
case 'width ' :
110
111
// tables, cells
111
- $ val = trim ($ attribute ->value );
112
112
if (false !== strpos ($ val , '% ' )){
113
113
// e.g. <table width="100%"> or <td width=50%>
114
114
$ styles ['width ' ] = intval ($ val ) * 50 ;
@@ -126,7 +126,13 @@ protected static function parseInlineStyle($node, $styles = array())
126
126
break ;
127
127
case 'bgcolor ' :
128
128
// tables, rows, cells e.g. <tr bgColor="#FF0000">
129
- $ styles ['bgColor ' ] = trim ($ attribute ->value , '# ' );
129
+ $ styles ['bgColor ' ] = trim ($ val , '# ' );
130
+ break ;
131
+ case 'valign ' :
132
+ // cells e.g. <td valign="middle">
133
+ if (preg_match ('#(?:top|bottom|middle|baseline)#i ' , $ val , $ matches )) {
134
+ $ styles ['valign ' ] = self ::mapAlignVertical ($ matches [0 ]);
135
+ }
130
136
break ;
131
137
}
132
138
}
@@ -678,6 +684,12 @@ protected static function parseStyle($attribute, $styles)
678
684
$ styles ["border {$ which }Style " ] = self ::mapBorderStyle ($ matches [3 ]);
679
685
}
680
686
break ;
687
+ case 'vertical-align ' :
688
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align
689
+ if (preg_match ('#(?:top|bottom|middle|sub|baseline)#i ' , $ cValue , $ matches )) {
690
+ $ styles ['valign ' ] = self ::mapAlignVertical ($ matches [0 ]);
691
+ }
692
+ break ;
681
693
}
682
694
}
683
695
@@ -842,6 +854,32 @@ protected static function mapAlign($cssAlignment)
842
854
}
843
855
}
844
856
857
+ /**
858
+ * Transforms a HTML/CSS alignment into a \PhpOffice\PhpWord\SimpleType\Jc
859
+ *
860
+ * @param string $cssAlignment
861
+ * @return string|null
862
+ */
863
+ protected static function mapAlignVertical ($ alignment )
864
+ {
865
+ $ alignment = strtolower ($ alignment );
866
+ switch ($ alignment ) {
867
+ case 'top ' :
868
+ case 'baseline ' :
869
+ case 'bottom ' :
870
+ return $ alignment ;
871
+ case 'middle ' :
872
+ return 'center ' ;
873
+ case 'sub ' :
874
+ return 'bottom ' ;
875
+ case 'text-top ' :
876
+ case 'baseline ' :
877
+ return 'top ' ;
878
+ default :
879
+ return '' ;
880
+ }
881
+ }
882
+
845
883
/**
846
884
* Map list style for ordered list
847
885
*
0 commit comments