def test_text_decoration_inheritance(self): doc = model.ContentDocument() r1 = model.Region("r1", doc) r1.set_style( styles.StyleProperties.TextDecoration, styles.TextDecorationType( line_through=False, underline=True, overline=True ) ) doc.put_region(r1) b = model.Body(doc) b.set_style( styles.StyleProperties.TextDecoration, styles.TextDecorationType( overline=False ) ) b.set_region(r1) doc.set_body(b) div1 = model.Div(doc) b.push_child(div1) p1 = model.P(doc) div1.push_child(p1) span1 = model.Span(doc) p1.push_child(span1) t1 = model.Text(doc, "hello") span1.push_child(t1) isd = ISD.from_model(doc, 0) region = list(isd.iter_regions())[0] span = region[0][0][0][0] self.assertEqual( span.get_style(styles.StyleProperties.TextDecoration), styles.TextDecorationType( line_through=False, underline=True, overline=False ) )
def extract(cls, context: StyleParsingContext, xml_attrib: str): if xml_attrib == "none": return styles.SpecialValues.none s = xml_attrib.split(" ") underline = styles.TextDecorationType.Action.none line_through = styles.TextDecorationType.Action.none overline = styles.TextDecorationType.Action.none if "underline" in s: underline = styles.TextDecorationType.Action.add elif "noUnderline" in s: underline = styles.TextDecorationType.Action.remove if "lineThrough" in s: line_through = styles.TextDecorationType.Action.add elif "noLineThrough" in s: line_through = styles.TextDecorationType.Action.remove if "overline" in s: overline = styles.TextDecorationType.Action.add elif "noOverline" in s: overline = styles.TextDecorationType.Action.remove return styles.TextDecorationType(underline=underline, line_through=line_through, overline=overline)
def handle_starttag(self, tag, attrs): span = model.Span(self.parent.get_doc()) self.parent.push_child(span) self.parent = span if tag.lower() in ("b", "bold"): span.set_style(styles.StyleProperties.FontWeight, styles.FontWeightType.bold) elif tag.lower() in ("i", "italic"): span.set_style(styles.StyleProperties.FontStyle, styles.FontStyleType.italic) elif tag.lower() in ("u", "underline"): span.set_style(styles.StyleProperties.TextDecoration, styles.TextDecorationType(underline=True)) elif tag.lower() == "font": for attr in attrs: if attr[0] == "color": color = parse_color(attr[1]) break else: LOGGER.warning("Font tag without a color attribute at line %s", self.line_num) return if color is None: LOGGER.warning("Unknown color %s at line %s", attrs["color"], self.line_num) return span.set_style(styles.StyleProperties.Color, color) else: LOGGER.warning("Unknown tag %s at line %s", tag, self.line_num) return
def extract(cls, context: StyleParsingContext, xml_attrib: str): if xml_attrib == "none": underline = False line_through = False overline = False else: s = xml_attrib.split(" ") underline = None line_through = None overline = None if "underline" in s: underline = True elif "noUnderline" in s: underline = False if "lineThrough" in s: line_through = True elif "noLineThrough" in s: line_through = False if "overline" in s: overline = True elif "noOverline" in s: overline = False return styles.TextDecorationType(underline=underline, line_through=line_through, overline=overline)
def start_span(self): if self.span is None: self.span = model.Span(self.parent.get_doc()) self.span.set_style(styles.StyleProperties.BackgroundColor, self.get_bg_color()) self.span.set_style(styles.StyleProperties.Color, self.get_fg_color()) if self.get_underline(): self.span.set_style( styles.StyleProperties.TextDecoration, styles.TextDecorationType(underline=True) ) if self.get_italic(): self.span.set_style( styles.StyleProperties.FontStyle, styles.FontStyleType.italic )
def test_tts_text_decoration(self): self.assertEqual( _get_set_style( imsc_styles.StyleProperties.TextDecoration, styles.TextDecorationType(underline=False, line_through=True)), "noUnderline lineThrough")