def read_text_border(parent, dest): border_color = border_style = border_width = padding = inherit elems = XPath('./w:bdr')(parent) if elems: border_color = simple_color('auto') border_style = 'solid' border_width = 1 for elem in elems: color = get(elem, 'w:color') if color is not None: border_color = simple_color(color) style = get(elem, 'w:val') if style is not None: border_style = LINE_STYLES.get(style, 'solid') space = get(elem, 'w:space') if space is not None: try: padding = float(space) except (ValueError, TypeError): pass sz = get(elem, 'w:sz') if sz is not None: # we dont care about art borders (they are only used for page borders) try: # A border of less than 1pt is not rendered by WebKit border_width = min(96, max(8, float(sz))) / 8 except (ValueError, TypeError): pass setattr(dest, 'border_color', border_color) setattr(dest, 'border_style', border_style) setattr(dest, 'border_width', border_width) setattr(dest, 'padding', padding)
def read_text_border(parent, dest, XPath, get): border_color = border_style = border_width = padding = inherit elems = XPath('./w:bdr')(parent) if elems and elems[0].attrib: border_color = simple_color('auto') border_style = 'none' border_width = 1 for elem in elems: color = get(elem, 'w:color') if color is not None: border_color = simple_color(color) style = get(elem, 'w:val') if style is not None: border_style = LINE_STYLES.get(style, 'solid') space = get(elem, 'w:space') if space is not None: try: padding = float(space) except (ValueError, TypeError): pass sz = get(elem, 'w:sz') if sz is not None: # we dont care about art borders (they are only used for page borders) try: # A border of less than 1pt is not rendered by WebKit border_width = min(96, max(8, float(sz))) / 8 except (ValueError, TypeError): pass setattr(dest, 'border_color', border_color) setattr(dest, 'border_style', border_style) setattr(dest, 'border_width', border_width) setattr(dest, 'padding', padding)
def read_text_border(parent, dest): border_color = border_style = border_width = padding = inherit elems = XPath("./w:bdr")(parent) if elems: border_color = simple_color("auto") border_style = "solid" border_width = 1 for elem in elems: color = get(elem, "w:color") if color is not None: border_color = simple_color(color) style = get(elem, "w:val") if style is not None: border_style = LINE_STYLES.get(style, "solid") space = get(elem, "w:space") if space is not None: try: padding = float(space) except (ValueError, TypeError): pass sz = get(elem, "w:sz") if sz is not None: # we dont care about art borders (they are only used for page borders) try: # A border of less than 1pt is not rendered by WebKit border_width = min(96, max(8, float(sz))) / 8 except (ValueError, TypeError): pass setattr(dest, "border_color", border_color) setattr(dest, "border_style", border_style) setattr(dest, "border_width", border_width) setattr(dest, "padding", padding)