1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-25 09:17:58 +00:00
FairEmail/patches/Html.patch

273 lines
12 KiB
Diff
Raw Normal View History

diff --git a/app/src/main/java/eu/faircode/email/HtmlEx.java b/app/src/main/java/eu/faircode/email/HtmlEx.java
index af06a672b..bbfcdc5fc 100644
--- a/app/src/main/java/eu/faircode/email/HtmlEx.java
+++ b/app/src/main/java/eu/faircode/email/HtmlEx.java
@@ -55,7 +55,7 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
* @deprecated use {@link #toHtml(Spanned, int)} instead.
*/
@Deprecated
- public /* static */ String toHtml(Spanned text) {
+ public static String toHtml(Spanned text) {
2020-08-21 07:46:32 +00:00
return toHtml(text, TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
}
@@ -69,7 +69,7 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
* {@link #TO_HTML_PARAGRAPH_LINES_INDIVIDUAL}
* @return string containing input converted to HTML
*/
- public /* static */ String toHtml(Spanned text, int option) {
+ public static String toHtml(Spanned text, int option) {
2020-08-21 07:46:32 +00:00
StringBuilder out = new StringBuilder();
withinHtml(out, text, option);
return out.toString();
@@ -78,13 +78,13 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
/**
* Returns an HTML escaped representation of the given plain text.
*/
- public /* static */ String escapeHtml(CharSequence text) {
+ public static String escapeHtml(CharSequence text) {
2020-08-21 07:46:32 +00:00
StringBuilder out = new StringBuilder();
withinStyle(out, text, 0, text.length());
return out.toString();
}
- private /* static */ void withinHtml(StringBuilder out, Spanned text, int option) {
+ private static void withinHtml(StringBuilder out, Spanned text, int option) {
2020-08-21 07:46:32 +00:00
if ((option & TO_HTML_PARAGRAPH_FLAG) == TO_HTML_PARAGRAPH_LINES_CONSECUTIVE) {
encodeTextAlignmentByDiv(out, text, option);
return;
@@ -93,7 +93,7 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
withinDiv(out, text, 0, text.length(), option);
}
- private /* static */ void encodeTextAlignmentByDiv(StringBuilder out, Spanned text, int option) {
+ private static void encodeTextAlignmentByDiv(StringBuilder out, Spanned text, int option) {
2020-08-21 07:46:32 +00:00
int len = text.length();
int next;
@@ -129,7 +129,7 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
}
}
- private /* static */ void withinDiv(StringBuilder out, Spanned text, int start, int end,
+ private static void withinDiv(StringBuilder out, Spanned text, int start, int end,
int option) {
2020-08-21 07:46:32 +00:00
int next;
for (int i = start; i < end; i = next) {
@@ -148,7 +148,7 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
}
}
- private /* static */ String getTextDirection(Spanned text, int start, int end) {
+ private static String getTextDirection(Spanned text, int start, int end) {
2020-08-21 07:46:32 +00:00
if (TextDirectionHeuristics.FIRSTSTRONG_LTR.isRtl(text, start, end - start)) {
return " dir=\"rtl\"";
} else {
@@ -156,7 +156,7 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
}
}
- private /* static */ String getTextStyles(Spanned text, int start, int end,
+ private static String getTextStyles(Spanned text, int start, int end,
boolean forceNoVerticalMargin, boolean includeTextAlign) {
2020-08-21 07:46:32 +00:00
String margin = null;
String textAlign = null;
@@ -200,7 +200,7 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
return style.append("\"").toString();
}
- private /* static */ void withinBlockquote(StringBuilder out, Spanned text, int start, int end,
+ private static void withinBlockquote(StringBuilder out, Spanned text, int start, int end,
int option) {
2020-08-21 07:46:32 +00:00
if ((option & TO_HTML_PARAGRAPH_FLAG) == TO_HTML_PARAGRAPH_LINES_CONSECUTIVE) {
withinBlockquoteConsecutive(out, text, start, end);
@@ -209,9 +209,9 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
}
}
- private /* static */ void withinBlockquoteIndividual(StringBuilder out, Spanned text, int start,
+ private static void withinBlockquoteIndividual(StringBuilder out, Spanned text, int start,
int end) {
- Boolean isInBulletList = null;
+ boolean isInList = false;
2020-08-21 07:46:32 +00:00
int next;
for (int i = start; i <= end; i = next) {
next = TextUtils.indexOf(text, '\n', i, end);
@@ -220,48 +220,42 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
}
if (next == i) {
- if (isInBulletList != null) {
+ if (isInList) {
2020-08-21 07:46:32 +00:00
// Current paragraph is no longer a list item; close the previously opened list
- out.append(isInBulletList ? "</ul>\n" : "</ol>\n");
- isInBulletList = null;
+ isInList = false;
+ out.append("</ul>\n");
2020-08-21 07:46:32 +00:00
}
- if (i != text.length())
- out.append("<br>\n");
+ out.append("<br>\n");
2020-08-21 07:46:32 +00:00
} else {
- Boolean isBulletListItem = null;
+ boolean isListItem = false;
2020-08-21 07:46:32 +00:00
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) {
- isBulletListItem = !(paragraphStyle instanceof eu.faircode.email.NumberSpan);
+ isListItem = true;
2020-08-21 07:46:32 +00:00
break;
}
}
- if (isBulletListItem != null && isInBulletList != null && isBulletListItem != isInBulletList) {
- out.append(isInBulletList ? "</ul>\n" : "</ol>\n");
- isInBulletList = null;
- }
-
- if (isBulletListItem != null && isInBulletList == null) {
+ if (isListItem && !isInList) {
2020-08-21 07:46:32 +00:00
// Current paragraph is the first item in a list
- isInBulletList = isBulletListItem;
- out.append(isInBulletList ? "<ul" : "<ol")
+ isInList = true;
+ out.append("<ul")
2020-08-21 07:46:32 +00:00
.append(getTextStyles(text, i, next, true, false))
.append(">\n");
}
- if (isInBulletList != null && isBulletListItem == null) {
+ if (isInList && !isListItem) {
2020-08-21 07:46:32 +00:00
// Current paragraph is no longer a list item; close the previously opened list
- out.append(isInBulletList ? "</ul>\n" : "</ol>\n");
- isInBulletList = null;
+ isInList = false;
+ out.append("</ul>\n");
2020-08-21 07:46:32 +00:00
}
- String tagType = isBulletListItem != null ? "li" : "span";
+ String tagType = isListItem ? "li" : "p";
2020-08-21 07:46:32 +00:00
out.append("<").append(tagType)
.append(getTextDirection(text, i, next))
- .append(getTextStyles(text, i, next, isBulletListItem == null, true))
+ .append(getTextStyles(text, i, next, !isListItem, true))
2020-08-21 07:46:32 +00:00
.append(">");
withinParagraph(out, text, i, next);
@@ -269,12 +263,10 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
out.append("</");
out.append(tagType);
out.append(">\n");
- if (isBulletListItem == null)
- out.append("<br>\n");
- if (next == end && isInBulletList != null) {
- out.append(isInBulletList ? "</ul>\n" : "</ol>\n");
- isInBulletList = null;
+ if (next == end && isInList) {
+ isInList = false;
+ out.append("</ul>\n");
2020-08-21 07:46:32 +00:00
}
}
@@ -282,9 +274,9 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
}
}
- private /* static */ void withinBlockquoteConsecutive(StringBuilder out, Spanned text, int start,
+ private static void withinBlockquoteConsecutive(StringBuilder out, Spanned text, int start,
int end) {
- out.append("<span").append(getTextDirection(text, start, end)).append(">");
+ out.append("<p").append(getTextDirection(text, start, end)).append(">");
2020-08-21 07:46:32 +00:00
int next;
for (int i = start; i < end; i = next) {
@@ -302,24 +294,24 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
withinParagraph(out, text, i, next - nl);
- if (nl == 0) {
+ if (nl == 1) {
2020-08-21 07:46:32 +00:00
out.append("<br>\n");
} else {
- for (int j = 0; j < nl; j++) {
+ for (int j = 2; j < nl; j++) {
2020-08-21 07:46:32 +00:00
out.append("<br>");
}
if (next != end) {
/* Paragraph should be closed and reopened */
- out.append("</span>\n");
- out.append("<span").append(getTextDirection(text, start, end)).append(">");
+ out.append("</p>\n");
+ out.append("<p").append(getTextDirection(text, start, end)).append(">");
2020-08-21 07:46:32 +00:00
}
}
}
- out.append("</span>\n");
+ out.append("</p>\n");
2020-08-21 07:46:32 +00:00
}
- private /* static */ void withinParagraph(StringBuilder out, Spanned text, int start, int end) {
+ private static void withinParagraph(StringBuilder out, Spanned text, int start, int end) {
2020-08-21 07:46:32 +00:00
int next;
for (int i = start; i < end; i = next) {
next = text.nextSpanTransition(i, end, CharacterStyle.class);
@@ -339,11 +331,9 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
if (style[j] instanceof TypefaceSpan) {
String s = ((TypefaceSpan) style[j]).getFamily();
- //if ("monospace".equals(s)) {
- // out.append("<tt>");
- //}
-
- out.append("<span style=\"font-family:" + s + ";\">");
+ if ("monospace".equals(s)) {
+ out.append("<tt>");
+ }
2020-08-21 07:46:32 +00:00
}
if (style[j] instanceof SuperscriptSpan) {
out.append("<sup>");
@@ -374,8 +364,8 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
AbsoluteSizeSpan s = ((AbsoluteSizeSpan) style[j]);
float sizeDip = s.getSize();
if (!s.getDip()) {
- //Application application = ActivityThread.currentApplication();
- sizeDip /= context.getResources().getDisplayMetrics().density;
+ Application application = ActivityThread.currentApplication();
+ sizeDip /= application.getResources().getDisplayMetrics().density;
2020-08-21 07:46:32 +00:00
}
// px in CSS is the equivalance of dip in Android
@@ -427,13 +417,11 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
out.append("</sup>");
}
if (style[j] instanceof TypefaceSpan) {
- //String s = ((TypefaceSpan) style[j]).getFamily();
-
- //if (s.equals("monospace")) {
- // out.append("</tt>");
- //}
+ String s = ((TypefaceSpan) style[j]).getFamily();
2020-08-21 07:46:32 +00:00
- out.append("</span>");
+ if (s.equals("monospace")) {
+ out.append("</tt>");
+ }
2020-08-21 07:46:32 +00:00
}
if (style[j] instanceof StyleSpan) {
int s = ((StyleSpan) style[j]).getStyle();
@@ -449,8 +437,8 @@ public class HtmlEx {
2020-08-21 07:46:32 +00:00
}
}
- //@UnsupportedAppUsage
- private /* static */ void withinStyle(StringBuilder out, CharSequence text,
+ @UnsupportedAppUsage
+ private static void withinStyle(StringBuilder out, CharSequence text,
2020-08-21 07:46:32 +00:00
int start, int end) {
for (int i = start; i < end; i++) {
char c = text.charAt(i);