mirror of https://github.com/M66B/FairEmail.git
parent
7292d5d30f
commit
4727598373
@ -0,0 +1,64 @@
|
||||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FairEmail is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018-2020 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Typeface;
|
||||
import android.text.Layout;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextPaint;
|
||||
import android.text.style.BulletSpan;
|
||||
|
||||
public class NumberSpan extends BulletSpan {
|
||||
private TextPaint tp;
|
||||
private String number;
|
||||
private int margin;
|
||||
|
||||
public NumberSpan(int gapWidth, int color, float textSize, int index) {
|
||||
tp = new TextPaint();
|
||||
tp.setStyle(Paint.Style.FILL);
|
||||
tp.setColor(color);
|
||||
tp.setTypeface(Typeface.MONOSPACE);
|
||||
tp.setTextSize(textSize);
|
||||
|
||||
number = index + ".";
|
||||
margin = Math.round(tp.measureText(number) + gapWidth);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLeadingMargin(boolean first) {
|
||||
// https://issuetracker.google.com/issues/36956124
|
||||
// This is called before drawLeadingMargin to justify the text
|
||||
return margin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, CharSequence text, int start, int end, boolean first, Layout layout) {
|
||||
if (text instanceof Spanned &&
|
||||
((Spanned) text).getSpanStart(this) == start) {
|
||||
float textSize = tp.getTextSize();
|
||||
if (textSize > p.getTextSize())
|
||||
tp.setTextSize(p.getTextSize());
|
||||
c.drawText(number, x + dir, baseline, tp);
|
||||
tp.setTextSize(textSize);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
diff --git a/app/src/main/java/eu/faircode/email/HtmlEx.java b/app/src/main/java/eu/faircode/email/HtmlEx.java
|
||||
index 5cfceaccd..f6db9f051 100644
|
||||
--- a/app/src/main/java/eu/faircode/email/HtmlEx.java
|
||||
+++ b/app/src/main/java/eu/faircode/email/HtmlEx.java
|
||||
@@ -211,7 +211,7 @@ public class HtmlEx {
|
||||
|
||||
private /* static */ void withinBlockquoteIndividual(StringBuilder out, Spanned text, int start,
|
||||
int end) {
|
||||
- boolean isInList = false;
|
||||
+ Boolean isInBulletList = null;
|
||||
int next;
|
||||
for (int i = start; i <= end; i = next) {
|
||||
next = TextUtils.indexOf(text, '\n', i, end);
|
||||
@@ -220,42 +220,47 @@ public class HtmlEx {
|
||||
}
|
||||
|
||||
if (next == i) {
|
||||
- if (isInList) {
|
||||
+ if (isInBulletList != null) {
|
||||
// Current paragraph is no longer a list item; close the previously opened list
|
||||
- isInList = false;
|
||||
- out.append("</ul>\n");
|
||||
+ out.append(isInBulletList ? "</ul>\n" : "</ol>\n");
|
||||
+ isInBulletList = null;
|
||||
}
|
||||
out.append("<br>\n");
|
||||
} else {
|
||||
- boolean isListItem = false;
|
||||
+ Boolean isBulletListItem = null;
|
||||
ParagraphStyle[] paragraphStyles = text.getSpans(i, next, ParagraphStyle.class);
|
||||
for (ParagraphStyle paragraphStyle : paragraphStyles) {
|
||||
final int spanFlags = text.getSpanFlags(paragraphStyle);
|
||||
if ((spanFlags & Spanned.SPAN_PARAGRAPH) == Spanned.SPAN_PARAGRAPH
|
||||
&& paragraphStyle instanceof BulletSpan) {
|
||||
- isListItem = true;
|
||||
+ isBulletListItem = !(paragraphStyle instanceof eu.faircode.email.NumberSpan);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- if (isListItem && !isInList) {
|
||||
+ if (isBulletListItem != null && isInBulletList != null && isBulletListItem != isInBulletList) {
|
||||
+ out.append(isInBulletList ? "</ul>\n" : "</ol>\n");
|
||||
+ isInBulletList = null;
|
||||
+ }
|
||||
+
|
||||
+ if (isBulletListItem != null && isInBulletList == null) {
|
||||
// Current paragraph is the first item in a list
|
||||
- isInList = true;
|
||||
- out.append("<ul")
|
||||
+ isInBulletList = isBulletListItem;
|
||||
+ out.append(isInBulletList ? "<ul" : "<ol")
|
||||
.append(getTextStyles(text, i, next, true, false))
|
||||
.append(">\n");
|
||||
}
|
||||
|
||||
- if (isInList && !isListItem) {
|
||||
+ if (isInBulletList != null && isBulletListItem == null) {
|
||||
// Current paragraph is no longer a list item; close the previously opened list
|
||||
- isInList = false;
|
||||
- out.append("</ul>\n");
|
||||
+ out.append(isInBulletList ? "</ul>\n" : "</ol>\n");
|
||||
+ isInBulletList = null;
|
||||
}
|
||||
|
||||
- String tagType = isListItem ? "li" : "p";
|
||||
+ String tagType = isBulletListItem != null ? "li" : "p";
|
||||
out.append("<").append(tagType)
|
||||
.append(getTextDirection(text, i, next))
|
||||
- .append(getTextStyles(text, i, next, !isListItem, true))
|
||||
+ .append(getTextStyles(text, i, next, isBulletListItem == null, true))
|
||||
.append(">");
|
||||
|
||||
withinParagraph(out, text, i, next);
|
||||
@@ -264,9 +269,9 @@ public class HtmlEx {
|
||||
out.append(tagType);
|
||||
out.append(">\n");
|
||||
|
||||
- if (next == end && isInList) {
|
||||
- isInList = false;
|
||||
- out.append("</ul>\n");
|
||||
+ if (next == end && isInBulletList != null) {
|
||||
+ out.append(isInBulletList ? "</ul>\n" : "</ol>\n");
|
||||
+ isInBulletList = null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue