public void testInlineAttributes() throws IOException, SubtitleDecoderException { TtmlSubtitle subtitle = getSubtitle(INLINE_ATTRIBUTES_TTML_FILE); assertEquals(4, subtitle.getEventTimeCount()); TtmlNode root = subtitle.getRoot(); TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0); TtmlNode firstDiv = queryChildrenForTag(body, TtmlNode.TAG_DIV, 0); TtmlStyle firstPStyle = queryChildrenForTag(firstDiv, TtmlNode.TAG_P, 0).style; assertEquals(ColorParser.parseTtmlColor("yellow"), firstPStyle.getFontColor()); assertEquals(ColorParser.parseTtmlColor("blue"), firstPStyle.getBackgroundColor()); assertEquals("serif", firstPStyle.getFontFamily()); assertEquals(TtmlStyle.STYLE_BOLD_ITALIC, firstPStyle.getStyle()); assertTrue(firstPStyle.isUnderline()); }
public void testInheritGlobalAndParent() throws IOException, SubtitleDecoderException { TtmlSubtitle subtitle = getSubtitle(INHERIT_GLOBAL_AND_PARENT_TTML_FILE); assertEquals(4, subtitle.getEventTimeCount()); assertSpans(subtitle, 10, "text 1", "sansSerif", TtmlStyle.STYLE_NORMAL, 0xFFFF0000, ColorParser.parseTtmlColor("lime"), false, true, Layout.Alignment.ALIGN_CENTER); assertSpans(subtitle, 20, "text 2", "serif", TtmlStyle.STYLE_BOLD_ITALIC, 0xFF0000FF, 0xFFFFFF00, true, true, Layout.Alignment.ALIGN_CENTER); }
private static void parseStyleDeclaration(ParsableByteArray input, WebvttCssStyle style, StringBuilder stringBuilder) { skipWhitespaceAndComments(input); String property = parseIdentifier(input, stringBuilder); if ("".equals(property)) { return; } if (!":".equals(parseNextToken(input, stringBuilder))) { return; } skipWhitespaceAndComments(input); String value = parsePropertyValue(input, stringBuilder); if (value == null || "".equals(value)) { return; } int position = input.getPosition(); String token = parseNextToken(input, stringBuilder); if (";".equals(token)) { // The style declaration is well formed. } else if (BLOCK_END.equals(token)) { // The style declaration is well formed and we can go on, but the closing bracket had to be // fed back. input.setPosition(position); } else { // The style declaration is not well formed. return; } // At this point we have a presumably valid declaration, we need to parse it and fill the style. if ("color".equals(property)) { style.setFontColor(ColorParser.parseCssColor(value)); } else if (PROPERTY_BGCOLOR.equals(property)) { style.setBackgroundColor(ColorParser.parseCssColor(value)); } else if (PROPERTY_TEXT_DECORATION.equals(property)) { if (VALUE_UNDERLINE.equals(value)) { style.setUnderline(true); } } else if (PROPERTY_FONT_FAMILY.equals(property)) { style.setFontFamily(value); } else if (PROPERTY_FONT_WEIGHT.equals(property)) { if (VALUE_BOLD.equals(value)) { style.setBold(true); } } else if (PROPERTY_FONT_STYLE.equals(property)) { if (VALUE_ITALIC.equals(value)) { style.setItalic(true); } } // TODO: Fill remaining supported styles. }
public void testInheritInlineAttributes() throws IOException, SubtitleDecoderException { TtmlSubtitle subtitle = getSubtitle(INLINE_ATTRIBUTES_TTML_FILE); assertEquals(4, subtitle.getEventTimeCount()); assertSpans(subtitle, 20, "text 2", "sansSerif", TtmlStyle.STYLE_ITALIC, 0xFF00FFFF, ColorParser.parseTtmlColor("lime"), false, true, null); }