Skip to content

Commit

Permalink
Parent version 1.9.12
Browse files Browse the repository at this point in the history
  • Loading branch information
bertfrees committed May 2, 2016
1 parent 42f1e99 commit 7f59633
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.daisy.pipeline.modules.braille</groupId>
<artifactId>braille-modules-parent</artifactId>
<version>1.9.11</version>
<version>1.9.12</version>
<relativePath />
</parent>

Expand Down
59 changes: 36 additions & 23 deletions src/main/java/nu/nota/pipeline/braille/impl/NotaTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -163,7 +169,7 @@ public FromStyledTextToBraille fromStyledTextToBraille() {
public java.lang.Iterable<String> transform(java.lang.Iterable<CSSStyledText> 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();
Expand All @@ -173,46 +179,53 @@ public java.lang.Iterable<String> transform(java.lang.Iterable<CSSStyledText> 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<String> uncontStyle = null;
List<SimpleInlineStyle> uncontStyle = null;
for (int i = 0; i < text.length; i++) {
Map<String,String> style = new HashMap<String,String>(CSS_PARSER.split(cssStyle[i]));
List<String> 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<Term<?>> 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>();
String newStyle = "";
for (Map.Entry<String,String> 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<SimpleInlineStyle>();
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,
Expand All @@ -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<CSSStyledText> styledText = new ArrayList<CSSStyledText>();
for (int i = 0; i < text.length; i++)
styledText.add(new CSSStyledText(text[i], style[i]));
Expand Down

0 comments on commit 7f59633

Please sign in to comment.