public void merge(QName name, String value) { merge(new StyleSpecification(name, value)); }
private static void elideInitialValues(StyleSet ss, Element elt, TransformerContext context) { QName eltName = new QName(elt.getNamespaceURI(), elt.getLocalName()); List<StyleSpecification> elisions = new java.util.ArrayList<StyleSpecification>(); for (StyleSpecification s : ss.getStyles().values()) { StyleSpecification initial = getInitialStyle(eltName, s.getName(), context, null); if (initial != null) { String value = initial.getValue(); if ((value != null) && value.equals(s.getValue())) elisions.add(s); } } for (StyleSpecification s : elisions) { ss.remove(s.getName()); } }
private static final int compare(Collection<StyleSpecification> styles1, Collection<StyleSpecification> styles2) { List<StyleSpecification> sl1 = new java.util.ArrayList<StyleSpecification>(styles1); List<StyleSpecification> sl2 = new java.util.ArrayList<StyleSpecification>(styles2); int nsl1 = sl1.size(); int nsl2 = sl2.size(); for (int i = 0, n = Math.min(nsl1, nsl2); i < n; ++i) { StyleSpecification s1 = sl1.get(i); StyleSpecification s2 = sl2.get(i); int d = s1.compareTo(s2); if (d != 0) return d; } if (nsl1 < nsl2) return -1; else if (nsl1 > nsl2) return 1; else return 0; }
private static StyleSpecification getInitialStyle(QName eltName, QName styleName, TransformerContext context, StyleSet overrides) { String value = context.getModel().getInitialStyleValue(eltName, styleName); if (value != null) { if (overrides != null) { StyleSpecification override = overrides.get(styleName); if (override != null) value = override.getValue(); } return new StyleSpecification(new ComparableQName(styleName), value); } else return null; }
private static String getStyleValue(StyleSet sss, QName styleName) { StyleSpecification s = getStyle(sss, styleName); if (s != null) return s.getValue(); else return null; }
public void merge(StyleSpecification style) { this.styles.put(style.getName(), style); }
public static boolean hasShowBackgroundAlways(Element region, StyleSet ss) { QName n = TTML1StyleVerifier.showBackgroundAttributeName; String v = null; if (ss != null) { StyleSpecification s = ss.get(n); if (s != null) v = s.getValue(); } if (v == null) v = Documents.getAttribute(region, n); return (v != null) ? v.equals("always") : true; }
private static StyleSet applicableStyles(StyleSet ss, Element elt, TransformerContext context) { boolean containsInapplicableStyle = false; QName eltName = new QName(elt.getNamespaceURI(), elt.getLocalName()); for (StyleSpecification s : ss.getStyles().values()) { if (!doesStyleApply(eltName, s.getName(), context)) { containsInapplicableStyle = true; break; } } if (!containsInapplicableStyle) return ss; else { StyleSet ssNew = new StyleSet(ss.getGeneration()); for (StyleSpecification s : ss.getStyles().values()) { if (doesStyleApply(eltName, s.getName(), context)) { ssNew.merge(s); } } return ssNew; } }
private static void generateAttributes(StyleSet ss, Element e) { String id = ss.getId(); if ((id != null) && !id.isEmpty()) { for (StyleSpecification s : ss.getStyles().values()) { ComparableQName n = s.getName(); e.setAttributeNS(n.getNamespaceURI(), n.getLocalPart(), s.getValue()); } e.setAttributeNS(XML.xmlNamespace, "id", id); } }
private boolean verifyLineHeight(Object root, Document isd, Element elt, Map<String,StyleSet> styleSets, VerifierContext context) { boolean failed = false; String style = Documents.getAttribute(elt, isdCSSAttributeName, null); String av = null; if (style != null) { StyleSet css = styleSets.get(style); if (css != null) { StyleSpecification ss = css.get(IMSC1StyleVerifier.lineHeightAttributeName); if (ss != null) av = ss.getValue(); } } if (av == null) av = "normal"; if (av.equals("normal")) { Reporter reporter = context.getReporter(); if (reporter.isWarningEnabled("uses-line-height-normal")) { Message message = reporter.message(getLocator(elt), "*KEY*", "Computed value of line height is ''{0}''.", av); if (reporter.logWarning(message)) { reporter.logError(message); failed = true; } } } return !failed; }
private static StyleSet getInlineStyles(Element e, int[] indices) { StyleSet styles = new StyleSet(generateStyleSetIndex(indices)); NamedNodeMap attrs = e.getAttributes(); for (int i = 0, n = attrs.getLength(); i < n; ++i) { Node node = attrs.item(i); if (node instanceof Attr) { Attr a = (Attr) node; String ns = a.getNamespaceURI(); if ((ns != null) && ns.equals(NAMESPACE_TT_STYLE)) { styles.merge(new StyleSpecification(new ComparableQName(a.getNamespaceURI(), a.getLocalName()), a.getValue())); } } } return styles; }
private static void generateAttributes(StyleSet ss, Element elt) { String id = ss.getId(); if ((id != null) && !id.isEmpty()) { for (StyleSpecification s : ss.getStyles().values()) { ComparableQName n = s.getName(); elt.setAttributeNS(n.getNamespaceURI(), n.getLocalPart(), s.getValue()); } elt.setAttributeNS(XML.xmlNamespace, "id", id); } }
private boolean verifyFontFamily(Object root, Document isd, Element elt, Map<String,StyleSet> styleSets, VerifierContext context) { boolean failed = false; String style = Documents.getAttribute(elt, isdCSSAttributeName, null); String av = null; if (style != null) { StyleSet css = styleSets.get(style); if (css != null) { StyleSpecification ss = css.get(IMSC1StyleVerifier.fontFamilyAttributeName); if (ss != null) av = ss.getValue(); } } if (av == null) av = "default"; if (!isRecommendedFontFamily(av)) { Reporter reporter = context.getReporter(); if (reporter.isWarningEnabled("uses-non-recommended-font-family")) { Message message = reporter.message(getLocator(elt), "*KEY*", "Computed value of font family is ''{0}''.", av); if (reporter.logWarning(message)) { reporter.logError(message); failed = true; } } } return !failed; }
private static StyleSet getInlineStyles(Element elt, TransformerContext context) { StyleSet styles = new StyleSet(); NamedNodeMap attrs = elt.getAttributes(); for (int i = 0, n = attrs.getLength(); i < n; ++i) { Node node = attrs.item(i); if (node instanceof Attr) { Attr a = (Attr) node; String nsUri = a.getNamespaceURI(); if (nsUri != null) { QName styleName = new ComparableQName(a.getNamespaceURI(), a.getLocalName()); if (isDefinedStyle(styleName, context)) styles.merge(new StyleSpecification(styleName, a.getValue())); } } } return styles; }