MCPcopy Create free account
hub / github.com/M66B/FairEmail / getTextStyles

Method getTextStyles

app/src/main/java/eu/faircode/email/HtmlEx.java:190–232  ·  view source on GitHub ↗
(Spanned text, int start, int end,
                                              boolean forceNoVerticalMargin, boolean includeTextAlign)

Source from the content-addressed store, hash-verified

188 }
189
190 private /* static */ String getTextStyles(Spanned text, int start, int end,
191 boolean forceNoVerticalMargin, boolean includeTextAlign) {
192 String margin = null;
193 String textAlign = null;
194
195 if (forceNoVerticalMargin) {
196 margin = "margin-top:0; margin-bottom:0;";
197 }
198 if (includeTextAlign) {
199 final AlignmentSpan[] alignmentSpans = getSpans(text, start, end, AlignmentSpan.class);
200
201 // Only use the last AlignmentSpan with flag SPAN_PARAGRAPH
202 for (int i = alignmentSpans.length - 1; i >= 0; i--) {
203 AlignmentSpan s = alignmentSpans[i];
204 if ((text.getSpanFlags(s) & Spanned.SPAN_PARAGRAPH) == Spanned.SPAN_PARAGRAPH) {
205 final Layout.Alignment alignment = s.getAlignment();
206 if (alignment == Layout.Alignment.ALIGN_NORMAL) {
207 textAlign = "text-align:start;";
208 } else if (alignment == Layout.Alignment.ALIGN_CENTER) {
209 textAlign = "text-align:center;";
210 } else if (alignment == Layout.Alignment.ALIGN_OPPOSITE) {
211 textAlign = "text-align:end;";
212 }
213 break;
214 }
215 }
216 }
217
218 if (margin == null && textAlign == null) {
219 return "";
220 }
221
222 final StringBuilder style = new StringBuilder(" style=\"");
223 if (margin != null && textAlign != null) {
224 style.append(margin).append(" ").append(textAlign);
225 } else if (margin != null) {
226 style.append(margin);
227 } else if (textAlign != null) {
228 style.append(textAlign);
229 }
230
231 return style.append("\"").toString();
232 }
233
234 private /* static */ void withinBlockquote(StringBuilder out, Spanned text, int start, int end,
235 int option) {

Callers 1

Calls 4

getSpansMethod · 0.95
getSpanFlagsMethod · 0.45
appendMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected