Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement text-transform property #23

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
<xsl:attribute name="xml:space" select="$space"/>
</xsl:if>
<xsl:sequence select="css:style-attribute(css:serialize-declaration-list(
css:specified-properties($inline-properties, true(), false(), false(), $this)
[not(@value='initial')]))"/>
css:computed-properties($inline-properties, false(), $this)
[not(@value=css:initial-value(@name))]))"/>
<xsl:for-each select="current-group()">
<xsl:sequence select="."/>
</xsl:for-each>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ public void run() throws SaxonApiException {
XdmNode source = sourcePipe.read();
Document doc = (Document)DocumentOverNodeInfo.wrap(source.getUnderlyingNode());
URL defaultSheet = asURL(emptyToNull(getOption(_default_stylesheet, "")));
resultPipe.write((new InlineCSSWriter(doc, runtime, defaultSheet)).getResult()); }
resultPipe.write((new InlineCSSWriter(doc, runtime, defaultSheet)).getResult());
}
catch (Exception e) {
logger.error("css:inline failed", e);
throw new XProcException(step.getNode(), e); }
throw new XProcException(step.getNode(), e);
}
}

@Component(
Expand Down Expand Up @@ -202,7 +204,8 @@ else if (attr.getPrefix() != null)
addAttribute(new QName(attr.getPrefix(), attr.getNamespaceURI(), attr.getLocalName()), attr.getNodeValue());
else if ("style".equals(attr.getLocalName())) {}
else
addAttribute(new QName(attr.getNamespaceURI(), attr.getLocalName()), attr.getNodeValue()); }
addAttribute(new QName(attr.getNamespaceURI(), attr.getLocalName()), attr.getNodeValue());
}
StringBuilder style = new StringBuilder();
NodeData brailleData = brailleStylemap.get((Element)node);
if (brailleData != null)
Expand All @@ -226,17 +229,20 @@ else if ("style".equals(attr.getLocalName())) {}
else
page = pages.get(pageProperty.toString());
if (page != null)
insertPageStyle(style, page, pages.get("auto")); }
insertPageStyle(style, page, pages.get("auto"));
}
else if (isRoot) {
RulePage page = pages.get("auto");
if (page != null)
insertPageStyle(style, page, null); }
if (normalizeSpace(style).length() > 0) {
addAttribute(_style, style.toString().trim()); }
insertPageStyle(style, page, null);
}
if (normalizeSpace(style).length() > 0)
addAttribute(_style, style.toString().trim());
receiver.startContent();
for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling())
traverse(child);
addEndElement(); }
addEndElement();
}
else if (node.getNodeType() == Node.COMMENT_NODE)
addComment(node.getNodeValue());
else if (node.getNodeType() == Node.TEXT_NODE)
Expand All @@ -256,7 +262,8 @@ public void addStartElement(Element element) {
List<NamespaceBinding> namespaces = new ArrayList<NamespaceBinding>();
Iterators.<NamespaceBinding>addAll(namespaces, NamespaceIterator.iterateNamespaces(inode));
inscopeNS = Iterables.<NamespaceBinding>toArray(namespaces, NamespaceBinding.class);
seenRoot = true; }
seenRoot = true;
}
receiver.setSystemId(element.getBaseURI());
addStartElement(new NameOfNode(inode), inode.getSchemaType(), inscopeNS);
}
Expand All @@ -282,14 +289,17 @@ private static void insertStyle(StringBuilder builder, NodeData nodeData) {
builder.append(termToString.apply(value));
else {
CSSProperty prop = nodeData.getProperty(key);
builder.append(prop); }
builder.append("; "); }
builder.append(prop);
}
builder.append("; ");
}
}

private static void insertPseudoStyle(StringBuilder builder, NodeData nodeData, Selector.PseudoDeclaration decl) {
if (builder.length() > 0 && !builder.toString().endsWith("} ")) {
builder.insert(0, "{ ");
builder.append("} "); }
builder.append("} ");
}
builder.append(decl.isPseudoElement() ? "::" : ":").append(decl.value()).append(" { ");
insertStyle(builder, nodeData);
builder.append("} ");
Expand All @@ -298,7 +308,8 @@ private static void insertPseudoStyle(StringBuilder builder, NodeData nodeData,
private static void insertPageStyle(StringBuilder builder, RulePage rulePage, RulePage inheritFrom) {
if (builder.length() > 0 && !builder.toString().endsWith("} ")) {
builder.insert(0, "{ ");
builder.append("} "); }
builder.append("} ");
}
builder.append("@page ");
String pseudo = rulePage.getPseudo();
if (pseudo != null && !"".equals(pseudo))
Expand All @@ -307,15 +318,17 @@ private static void insertPageStyle(StringBuilder builder, RulePage rulePage, Ru
List<String> seen = new ArrayList<String>();
for (Declaration decl : Iterables.<Declaration>filter(rulePage, Declaration.class)) {
seen.add(decl.getProperty());
insertDeclaration(builder, decl); }
insertDeclaration(builder, decl);
}
if (inheritFrom != null)
for (Declaration decl : Iterables.<Declaration>filter(inheritFrom, Declaration.class))
if (!seen.contains(decl.getProperty()))
insertDeclaration(builder, decl);
seen.clear();
for (RuleMargin margin : Iterables.<RuleMargin>filter(rulePage, RuleMargin.class)) {
seen.add(margin.getMarginArea().value);
insertMarginStyle(builder, margin); }
insertMarginStyle(builder, margin);
}
if (inheritFrom != null)
for (RuleMargin margin : Iterables.<RuleMargin>filter(inheritFrom, RuleMargin.class))
if (!seen.contains(margin.getMarginArea().value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.daisy.braille.css.BrailleCSSProperty.Page;
import org.daisy.braille.css.BrailleCSSProperty.StringSet;
import org.daisy.braille.css.BrailleCSSProperty.TextIndent;
import org.daisy.braille.css.BrailleCSSProperty.TextTransform;

import cz.vutbr.web.css.CSSFactory;
import cz.vutbr.web.css.CSSProperty;
Expand Down Expand Up @@ -281,6 +282,32 @@ private boolean processTextIndent(Declaration d,
d, properties, values);
}

@SuppressWarnings("unused")
private boolean processTextTransform(Declaration d,
Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
if (d.size() == 1 && genericOneIdent(TextTransform.class, d, properties))
return true;

TermList list = tf.createList();
for (Term<?> t : d.asList()) {
if (t instanceof TermIdent) {
String value = ((TermIdent)t).getValue().toLowerCase();
if (!value.equals("none") && !value.equals("auto")
&& !value.equals("uppercase") && !value.equals("lowercase"))
list.add(t);
}
else
return false;
}

if (list.isEmpty())
return false;

properties.put("text-transform", TextTransform.list_values);
values.put("text-transform", list);
return true;
}

/****************************************************************
* GENERIC METHODS
****************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,27 @@ public String toString() {
return text;
}
}

public enum TextTransform implements BrailleCSSProperty {
list_values(""), NONE("none"), AUTO("auto"), UPPERCASE("uppercase"), LOWERCASE("lowercase"), INHERIT("inherit");

private String text;

private TextTransform(String text) {
this.text = text;
}

public boolean inherited() {
return false;
}

public boolean equalsInherit() {
return this == INHERIT;
}

@Override
public String toString() {
return text;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.daisy.braille.css.BrailleCSSProperty.Page;
import org.daisy.braille.css.BrailleCSSProperty.StringSet;
import org.daisy.braille.css.BrailleCSSProperty.TextIndent;
import org.daisy.braille.css.BrailleCSSProperty.TextTransform;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -43,7 +44,7 @@ public class SupportedBrailleCSS implements SupportedCSS {

private static Logger log = LoggerFactory.getLogger(SupportedBrailleCSS.class);

private static final int TOTAL_SUPPORTED_DECLARATIONS = 35;
private static final int TOTAL_SUPPORTED_DECLARATIONS = 36;

private static final TermFactory tf = CSSFactory.getTermFactory();

Expand Down Expand Up @@ -231,6 +232,8 @@ private void setSupportedCSS() {
embossedProperties.add("string-set");
props.put("content", Content.NONE);
embossedProperties.add("content");
props.put("text-transform", TextTransform.AUTO);
embossedProperties.add("text-transform");

/* ----------- */
/* media print */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@
</xsl:choose>
</xsl:template>

<xsl:template match="css:property" mode="css:compute">
<xsl:param name="validate" as="xs:boolean"/>
<xsl:param name="context" as="element()"/>
<xsl:sequence select="."/>
</xsl:template>

<xsl:function name="css:specified-properties" as="element()*">
<xsl:param name="properties"/>
<xsl:param name="concretize-inherit" as="xs:boolean"/>
Expand Down Expand Up @@ -456,6 +462,17 @@
</xsl:apply-templates>
</xsl:function>

<xsl:function name="css:computed-properties" as="element()*">
<xsl:param name="properties"/>
<xsl:param name="validate" as="xs:boolean"/>
<xsl:param name="context" as="element()"/>
<xsl:apply-templates select="css:specified-properties($properties, true(), true(), $validate, $context)"
mode="css:compute">
<xsl:with-param name="validate" select="$validate"/>
<xsl:with-param name="context" select="$context"/>
</xsl:apply-templates>
</xsl:function>

<!-- =========== -->
<!-- Serializing -->
<!-- =========== -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
'white-space',
'hyphens',
'size',
'text-transform',
'font-style',
'font-weight',
'text-decoration',
Expand Down Expand Up @@ -89,6 +90,7 @@
re:exact(re:or(('normal','pre-wrap','pre-line'))),
re:exact(re:or(('auto','manual','none'))),
re:exact(concat('(',$css:NON_NEGATIVE_INTEGER_RE,')\s+(',$css:NON_NEGATIVE_INTEGER_RE,')')),
re:exact(re:or(($css:IDENT_LIST_RE,'none','auto','uppercase','lowercase'))),
re:exact(re:or(('normal','italic','oblique'))),
re:exact(re:or(('normal','bold','100','200','300','400','500','600','700','800','900'))),
re:exact(re:or(('none','underline','overline','line-through','blink'))),
Expand Down Expand Up @@ -130,6 +132,7 @@
'.*',
'.*',
'.*',
'.*',
'.*')"/>

<xsl:variable name="css:initial-values" as="xs:string*"
Expand Down Expand Up @@ -165,6 +168,7 @@
'normal',
'manual',
'40 25',
'auto',
'normal',
'normal',
'none',
Expand Down Expand Up @@ -203,6 +207,7 @@
'embossed',
'embossed',
'embossed',
'embossed',
'print',
'print',
'print',
Expand Down Expand Up @@ -255,6 +260,31 @@
<xsl:sequence select="if ($index) then matches($display, $css:applies-to[$index]) else false()"/>
</xsl:function>

<!-- ================== -->
<!-- Special inheriting -->
<!-- ================== -->

<xsl:template match="css:property[@name='text-transform']" mode="css:compute">
<xsl:param name="validate" as="xs:boolean"/>
<xsl:param name="context" as="element()"/>
<xsl:variable name="parent" as="element()?" select="$context/ancestor::*[not(self::css:* except self::css:box)][1]"/>
<xsl:choose>
<xsl:when test="not(exists($parent))">
<xsl:sequence select="."/>
</xsl:when>
<xsl:when test="@value=('auto','initial')">
<xsl:sequence select="css:computed-properties(@name, $validate, $parent)"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="parent-computed" as="element()"
select="css:computed-properties(@name, $validate, $parent)"/>
<xsl:sequence select="if ($parent-computed/@value='auto')
then .
else css:property(@name, string-join((@value, $parent-computed/@value), ' '))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- ============== -->
<!-- Counter Styles -->
<!-- ============== -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,21 @@
</x:expect>
</x:scenario>

<x:scenario label="test_28">
<x:call function="css:computed-properties">
<x:param select="'text-transform'"/>
<x:param select="true()"/>
<x:param select="//foo">
<_ css:text-transform="bold">
<_>
<foo css:text-transform="italic"/>
</_>
</_>
</x:param>
</x:call>
<x:expect label="result">
<css:property name="text-transform" value="italic bold"/>
</x:expect>
</x:scenario>

</x:description>
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<xsl:variable name="style" as="xs:string*">
<xsl:for-each select="$text">
<xsl:variable name="inline-style" as="element()*"
select="css:specified-properties($inline-properties, true(), false(), true(), parent::*)"/>
<xsl:sequence select="css:serialize-declaration-list($inline-style[not(@value='initial')])"/>
select="css:computed-properties($inline-properties, true(), parent::*)"/>
<xsl:sequence select="css:serialize-declaration-list($inline-style[not(@value=css:initial-value(@name))])"/>
</xsl:for-each>
</xsl:variable>
<xsl:apply-templates select="node()[1]" mode="treewalk">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,25 @@
</x:expect>
</x:scenario>

<x:scenario label="test_02" pending="liblouis typeform broken">
<x:context>
<doc xml:lang="en">
<p style="display: block">
<span style="text-transform: louis-ital">
foo <span style="text-transform: louis-bold">bar</span>
</span>
</p>
</doc>
</x:context>
<x:expect label="result">
<doc xml:lang="en">
<p style="{{ display: block }}">
<span>
⠋⠕⠕ <span>⠃⠜</span>
</span>
</p>
</doc>
</x:expect>
</x:scenario>

</x:description>
Loading