def baseline(run, val, data): if isinstance(val, str): val = val.strip().lower() # See https://github.com/scanny/python-pptx/pull/601 for unit values val = (0.3 if val.startswith('sup') else # noqa -0.25 if val.startswith('sub') else # noqa ST_Percentage._convert_from_percent_literal(val)) run.font._rPr.set('baseline', ST_Percentage.convert_to_xml(val))
def fill_opacity(fill: FillFormat, val: Union[int, float, None]) -> None: '''Set the FillFormat opacity to a number''' if fill.type != MSO_FILL.SOLID: raise ValueError('Cannot set opacity: %r on non-solid fill type %r' % (val, fill.type)) for tag in ('hslClr', 'sysClr', 'srgbClr', 'prstClr', 'scrgbClr', 'schemeClr'): color = fill._xPr.find('.//' + qn('a:%s' % tag)) if color is not None: alpha = color.find(qn('a:alpha')) if alpha is None: alpha = OxmlElement('a:alpha') color.append(alpha) alpha.set('val', ST_Percentage.convert_to_xml(val)) break
def it_can_convert_from_xml_percent_literals(self, percent_fixture): str_value, expected_value = percent_fixture assert ST_Percentage.convert_from_xml(str_value) == expected_value
def it_can_convert_from_xml_percent_literals(self, percent_fixture): str_value, expected_value = percent_fixture value = ST_Percentage.convert_from_xml(str_value) assert abs(value - expected_value) < 0.000001