From 7f59633afa9c46e341794be1cae05617edef103b Mon Sep 17 00:00:00 2001 From: Bert Frees Date: Mon, 2 May 2016 21:43:20 +0200 Subject: [PATCH] Parent version 1.9.12 --- pom.xml | 2 +- .../pipeline/braille/impl/NotaTranslator.java | 59 +++++++++++-------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 2dafc0a..aaa9229 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.daisy.pipeline.modules.braille braille-modules-parent - 1.9.11 + 1.9.12 diff --git a/src/main/java/nu/nota/pipeline/braille/impl/NotaTranslator.java b/src/main/java/nu/nota/pipeline/braille/impl/NotaTranslator.java index bf0e128..a1ae95e 100644 --- a/src/main/java/nu/nota/pipeline/braille/impl/NotaTranslator.java +++ b/src/main/java/nu/nota/pipeline/braille/impl/NotaTranslator.java @@ -4,6 +4,7 @@ import java.util.Arrays; import static java.util.Arrays.copyOfRange; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.net.URI; @@ -15,6 +16,14 @@ import static com.google.common.collect.Iterables.size; import static com.google.common.collect.Lists.newArrayList; +import cz.vutbr.web.css.CSSProperty; +import cz.vutbr.web.css.Term; +import cz.vutbr.web.css.TermIdent; +import cz.vutbr.web.css.TermList; + +import org.daisy.braille.css.BrailleCSSProperty.TextTransform; +import org.daisy.braille.css.SimpleInlineStyle; + import org.daisy.pipeline.braille.common.AbstractBrailleTranslator; import org.daisy.pipeline.braille.common.AbstractTransformProvider; import org.daisy.pipeline.braille.common.AbstractTransformProvider.util.Function; @@ -25,6 +34,7 @@ import static org.daisy.pipeline.braille.common.AbstractTransformProvider.util.logSelect; import org.daisy.pipeline.braille.common.BrailleTranslator; import org.daisy.pipeline.braille.common.BrailleTranslatorProvider; +import org.daisy.pipeline.braille.common.CSSStyledText; import org.daisy.pipeline.braille.common.Query; import org.daisy.pipeline.braille.common.Query.Feature; import org.daisy.pipeline.braille.common.Query.MutableQuery; @@ -129,10 +139,6 @@ public BrailleTranslator _apply(LiblouisTranslator uncontractedTranslator) { return empty; } - private final static Splitter.MapSplitter CSS_PARSER - = Splitter.on(';').omitEmptyStrings().withKeyValueSeparator(Splitter.on(':').limit(2).trimResults()); - private final static Splitter TEXT_TRANSFORM_PARSER = Splitter.on(' ').omitEmptyStrings().trimResults(); - private class TransformImpl extends AbstractBrailleTranslator { private final FromStyledTextToBraille translator; @@ -163,7 +169,7 @@ public FromStyledTextToBraille fromStyledTextToBraille() { public java.lang.Iterable transform(java.lang.Iterable styledText) { int size = size(styledText); String[] text = new String[size]; - String[] style = new String[size]; + SimpleInlineStyle[] style = new SimpleInlineStyle[size]; int i = 0; for (CSSStyledText t : styledText) { text[i] = t.getText(); @@ -173,46 +179,53 @@ public java.lang.Iterable transform(java.lang.Iterable st } }; - private String[] transform(String[] text, String[] cssStyle) { + private String[] transform(String[] text, SimpleInlineStyle[] cssStyle) { if (text.length == 0) return new String[]{}; String[] result = new String[text.length]; boolean uncont = false; int j = 0; - List uncontStyle = null; + List uncontStyle = null; for (int i = 0; i < text.length; i++) { - Map style = new HashMap(CSS_PARSER.split(cssStyle[i])); - List textTransform = null; { - String t = style.remove("text-transform"); - if (t != null) - textTransform = newArrayList(TEXT_TRANSFORM_PARSER.split(t)); } - if (textTransform != null && textTransform.remove("uncontracted")) { + SimpleInlineStyle style = cssStyle[i]; + boolean thisUncont; { + thisUncont = false; + if (style != null) { + CSSProperty val = style.getProperty("text-transform"); + if (val != null) { + if (val == TextTransform.list_values) { + TermList values = style.getValue(TermList.class, "text-transform"); + Iterator> it = values.iterator(); + while (it.hasNext()) { + String tt = ((TermIdent)it.next()).getValue(); + if (tt.equals("uncontracted")) { + thisUncont = true; + it.remove(); + break; }} + if (values.isEmpty()) + style.removeProperty("text-transform"); }}}} + if (thisUncont) { if (i > 0 && !uncont) for (String s : transformArray(translator, copyOfRange(text, j, i), copyOfRange(cssStyle, j, i))) result[j++] = s; if (uncontStyle == null) - uncontStyle = new ArrayList(); - String newStyle = ""; - for (Map.Entry kv : style.entrySet()) - newStyle += (kv.getKey() + ": " + kv.getValue() + ";"); - if (textTransform != null && textTransform.size() > 0) - newStyle += ("text-transform: " + join(textTransform, " ") + ";"); - uncontStyle.add(newStyle); + uncontStyle = new ArrayList(); + uncontStyle.add(style); uncont = true; } else { if (i > 0 && uncont) { for (String s : transformArray(uncontractedTranslator, copyOfRange(text, j, i), - uncontStyle.toArray(new String[i - j]))) + uncontStyle.toArray(new SimpleInlineStyle[i - j]))) result[j++] = s; uncontStyle = null; } uncont = false; }} if (uncont) for (String s : transformArray(uncontractedTranslator, copyOfRange(text, j, text.length), - uncontStyle.toArray(new String[text.length - j]))) + uncontStyle.toArray(new SimpleInlineStyle[text.length - j]))) result[j++] = s; else for (String s : transformArray(translator, @@ -222,7 +235,7 @@ private String[] transform(String[] text, String[] cssStyle) { return result; } - private String[] transformArray(FromStyledTextToBraille translator, String[] text, String[] style) { + private String[] transformArray(FromStyledTextToBraille translator, String[] text, SimpleInlineStyle[] style) { List styledText = new ArrayList(); for (int i = 0; i < text.length; i++) styledText.add(new CSSStyledText(text[i], style[i]));