HtmlToWorldBuilder.java: In method "parseProperties()" set default run fontSize to 11 & added cases for headers H1-H6 & if alignment is JUSTIFY set alignment to "both".

This commit is contained in:
Konstantina Galouni 2024-05-28 11:28:28 +03:00
parent 180ca8c378
commit c540e3e312
1 changed files with 26 additions and 0 deletions

View File

@ -75,6 +75,7 @@ public class HtmlToWorldBuilder implements NodeVisitor {
private void parseProperties(Node node) { private void parseProperties(Node node) {
properties.entrySet().forEach(stringBooleanEntry -> { properties.entrySet().forEach(stringBooleanEntry -> {
this.run.setFontSize(11);
switch (stringBooleanEntry.getKey()) { switch (stringBooleanEntry.getKey()) {
case "i" : case "i" :
case "em": case "em":
@ -121,6 +122,9 @@ public class HtmlToWorldBuilder implements NodeVisitor {
if (stringBooleanEntry.getValue()) { if (stringBooleanEntry.getValue()) {
if (node.hasAttr("align")) { if (node.hasAttr("align")) {
String alignment = node.attr("align"); String alignment = node.attr("align");
if(alignment.toUpperCase(Locale.ROOT).equals("JUSTIFY")) {
alignment = "both";
}
this.paragraph.setAlignment(ParagraphAlignment.valueOf(alignment.toUpperCase(Locale.ROOT))); this.paragraph.setAlignment(ParagraphAlignment.valueOf(alignment.toUpperCase(Locale.ROOT)));
} }
} }
@ -213,6 +217,28 @@ public class HtmlToWorldBuilder implements NodeVisitor {
this.run.addBreak(); this.run.addBreak();
} }
break; break;
case "h1":
System.out.println(this.run.getFontSize());
this.run.setFontSize(24);
break;
case "h2":
this.run.setFontSize(20);
break;
case "h3":
this.run.setFontSize(16);
break;
case "h4":
this.run.setFontSize(14);
this.run.setBold(stringBooleanEntry.getValue());
break;
case "h5":
this.run.setFontSize(14);
break;
case "h6":
this.run.setFontSize(11);
this.run.setBold(stringBooleanEntry.getValue());
this.run.setCapitalized(stringBooleanEntry.getValue());
break;
} }
}); });
} }