diff options
| author | Michael Williamson <mike@zwobble.org> | 2020-11-06 18:54:59 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2020-11-06 18:54:59 +0000 |
| commit | d8ff620412641d5a94085df703a8321e5964ae33 (patch) | |
| tree | 0d743f5fc3517ed3803a399387e4950e2309852f /src/main/java | |
| parent | 999fbc8dc29b87a0f9c4497ec680915ac7ecae26 (diff) | |
Add style mapping for all caps
Diffstat (limited to 'src/main/java')
6 files changed, 33 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/mammoth/internal/conversion/DocumentToHtml.java b/src/main/java/org/zwobble/mammoth/internal/conversion/DocumentToHtml.java index 7276232..0f5a066 100644 --- a/src/main/java/org/zwobble/mammoth/internal/conversion/DocumentToHtml.java +++ b/src/main/java/org/zwobble/mammoth/internal/conversion/DocumentToHtml.java @@ -166,6 +166,9 @@ public class DocumentToHtml { if (run.isSmallCaps()) { nodes = styleMap.getSmallCaps().orElse(HtmlPath.EMPTY).wrap(nodes); } + if (run.isAllCaps()) { + nodes = styleMap.getAllCaps().orElse(HtmlPath.EMPTY).wrap(nodes); + } if (run.isStrikethrough()) { nodes = styleMap.getStrikethrough().orElse(HtmlPath.collapsibleElement("s")).wrap(nodes); } diff --git a/src/main/java/org/zwobble/mammoth/internal/documents/Run.java b/src/main/java/org/zwobble/mammoth/internal/documents/Run.java index e047bf5..27631bd 100644 --- a/src/main/java/org/zwobble/mammoth/internal/documents/Run.java +++ b/src/main/java/org/zwobble/mammoth/internal/documents/Run.java @@ -8,6 +8,7 @@ public class Run implements DocumentElement, HasChildren { private final boolean isItalic; private final boolean isUnderline; private final boolean isStrikethrough; + private final boolean isAllCaps; private final boolean isSmallCaps; private final VerticalAlignment verticalAlignment; private final Optional<Style> style; @@ -18,6 +19,7 @@ public class Run implements DocumentElement, HasChildren { boolean isItalic, boolean isUnderline, boolean isStrikethrough, + boolean isAllCaps, boolean isSmallCaps, VerticalAlignment verticalAlignment, Optional<Style> style, @@ -27,6 +29,7 @@ public class Run implements DocumentElement, HasChildren { this.isItalic = isItalic; this.isUnderline = isUnderline; this.isStrikethrough = isStrikethrough; + this.isAllCaps = isAllCaps; this.isSmallCaps = isSmallCaps; this.verticalAlignment = verticalAlignment; this.style = style; @@ -49,6 +52,10 @@ public class Run implements DocumentElement, HasChildren { return isStrikethrough; } + public boolean isAllCaps() { + return isAllCaps; + } + public boolean isSmallCaps() { return isSmallCaps; } diff --git a/src/main/java/org/zwobble/mammoth/internal/docx/StatefulBodyXmlReader.java b/src/main/java/org/zwobble/mammoth/internal/docx/StatefulBodyXmlReader.java index af6b70f..9c270de 100644 --- a/src/main/java/org/zwobble/mammoth/internal/docx/StatefulBodyXmlReader.java +++ b/src/main/java/org/zwobble/mammoth/internal/docx/StatefulBodyXmlReader.java @@ -182,6 +182,7 @@ class StatefulBodyXmlReader { isItalic(properties), isUnderline(properties), isStrikethrough(properties), + isAllCaps(properties), isSmallCaps(properties), readVerticalAlignment(properties), style, @@ -216,6 +217,10 @@ class StatefulBodyXmlReader { return readBooleanElement(properties, "w:strike"); } + private boolean isAllCaps(XmlElementLike properties) { + return readBooleanElement(properties, "w:caps"); + } + private boolean isSmallCaps(XmlElementLike properties) { return readBooleanElement(properties, "w:smallCaps"); } diff --git a/src/main/java/org/zwobble/mammoth/internal/styles/StyleMap.java b/src/main/java/org/zwobble/mammoth/internal/styles/StyleMap.java index 2b1d19a..1b094fd 100644 --- a/src/main/java/org/zwobble/mammoth/internal/styles/StyleMap.java +++ b/src/main/java/org/zwobble/mammoth/internal/styles/StyleMap.java @@ -24,6 +24,7 @@ public class StyleMap { Optionals.first(high.italic, low.italic), Optionals.first(high.underline, low.underline), Optionals.first(high.strikethrough, low.strikethrough), + Optionals.first(high.allCaps, low.allCaps), Optionals.first(high.smallCaps, low.smallCaps), Optionals.first(high.commentReference, low.commentReference), Lists.eagerConcat(high.paragraphStyles, low.paragraphStyles), @@ -39,6 +40,7 @@ public class StyleMap { private final Optional<HtmlPath> italic; private final Optional<HtmlPath> underline; private final Optional<HtmlPath> strikethrough; + private final Optional<HtmlPath> allCaps; private final Optional<HtmlPath> smallCaps; private final Optional<HtmlPath> commentReference; private final List<StyleMapping<Paragraph>> paragraphStyles; @@ -51,6 +53,7 @@ public class StyleMap { Optional<HtmlPath> italic, Optional<HtmlPath> underline, Optional<HtmlPath> strikethrough, + Optional<HtmlPath> allCaps, Optional<HtmlPath> smallCaps, Optional<HtmlPath> commentReference, List<StyleMapping<Paragraph>> paragraphStyles, @@ -63,6 +66,7 @@ public class StyleMap { this.italic = italic; this.underline = underline; this.strikethrough = strikethrough; + this.allCaps = allCaps; this.smallCaps = smallCaps; this.commentReference = commentReference; this.paragraphStyles = paragraphStyles; @@ -92,6 +96,10 @@ public class StyleMap { return strikethrough; } + public Optional<HtmlPath> getAllCaps() { + return allCaps; + } + public Optional<HtmlPath> getSmallCaps() { return smallCaps; } diff --git a/src/main/java/org/zwobble/mammoth/internal/styles/StyleMapBuilder.java b/src/main/java/org/zwobble/mammoth/internal/styles/StyleMapBuilder.java index dbd4fa8..2d90219 100644 --- a/src/main/java/org/zwobble/mammoth/internal/styles/StyleMapBuilder.java +++ b/src/main/java/org/zwobble/mammoth/internal/styles/StyleMapBuilder.java @@ -12,6 +12,7 @@ import java.util.Optional; public class StyleMapBuilder { private Optional<HtmlPath> underline; private Optional<HtmlPath> strikethrough; + private Optional<HtmlPath> allCaps; private Optional<HtmlPath> smallCaps; private Optional<HtmlPath> bold; private Optional<HtmlPath> italic; @@ -25,6 +26,7 @@ public class StyleMapBuilder { this.bold = Optional.empty(); this.underline = Optional.empty(); this.strikethrough = Optional.empty(); + this.allCaps = Optional.empty(); this.smallCaps = Optional.empty(); this.italic = Optional.empty(); this.commentReference = Optional.empty(); @@ -50,6 +52,11 @@ public class StyleMapBuilder { return this; } + public StyleMapBuilder allCaps(HtmlPath path) { + this.allCaps = Optional.of(path); + return this; + } + public StyleMapBuilder smallCaps(HtmlPath path) { this.smallCaps = Optional.of(path); return this; @@ -86,6 +93,7 @@ public class StyleMapBuilder { italic, underline, strikethrough, + allCaps, smallCaps, commentReference, paragraphStyles, diff --git a/src/main/java/org/zwobble/mammoth/internal/styles/parsing/DocumentMatcherParser.java b/src/main/java/org/zwobble/mammoth/internal/styles/parsing/DocumentMatcherParser.java index f955431..fdd2797 100644 --- a/src/main/java/org/zwobble/mammoth/internal/styles/parsing/DocumentMatcherParser.java +++ b/src/main/java/org/zwobble/mammoth/internal/styles/parsing/DocumentMatcherParser.java @@ -30,6 +30,8 @@ public class DocumentMatcherParser { return StyleMapBuilder::underline; case "strike": return StyleMapBuilder::strikethrough; + case "all-caps": + return StyleMapBuilder::allCaps; case "small-caps": return StyleMapBuilder::smallCaps; case "comment-reference": |
