def to_blend(self, conf, pen_y): from docutils.utils import roman align, indent, style_id, list_type, list_count = self.data_src print(list_type) if list_type is None: body = " \u2022" elif list_type == 'arabic': body = " %d. " % (list_count + 1) elif list_type == 'loweralpha': body = " %s) " % (chr(ord('a') + list_count)) elif list_type == 'upperalpha': body = " %s) " % (chr(ord('A') + list_count)) elif list_type == 'lowerroman': body = "(%s) " % roman.toRoman(list_count + 1).lower() elif list_type == 'upperroman': body = "(%s) " % roman.toRoman(list_count + 1) else: raise Exception("unknown enum: %s" % list_type) body_fmt = bytearray([0]) * len(body) txt_ob = butil_text_to_blend(conf, indent, getattr(conf, style_id), body, body_fmt, align) txt_ob.location.y = pen_y self.data_dst = txt_ob butil_text_calc_advance(conf.scene, txt_ob) # dont advance return pen_y
def list_item_enumerator(node): start = node.parent.get('start', 1) index = node.parent.children.index(node) + start enumtype = node.parent['enumtype'] if enumtype == 'arabic': suffix = str(index) elif enumtype == 'loweralpha': suffix = chr(ord('a') + index - 1) elif enumtype == 'upperalpha': suffix = chr(ord('A') + index - 1) elif enumtype == 'lowerroman': suffix = toRoman(index).lower() elif enumtype == 'upperroman': suffix = toRoman(index).upper() else: raise Exception("unknown enumeration list type") if (isinstance(node.parent.parent, nodes.list_item) and isinstance( node.parent.parent.parent, nodes.enumerated_list)): prefix = list_item_enumerator(node.parent.parent) + '.' else: prefix = '' return prefix + suffix
def sectionname(self): """Return the LaTeX section name for current section `level`.""" level = self.top_sectionlevel + self.sectionlevel if level <= len(self.sec_names): return self.sec_names[level - 1] else: # unsupported levels return 'DUtitle[section%s]' % roman.toRoman(level)
def make_enumerator(ordinal, sequence, format): """Construct and return the next enumerated list item marker, and an auto-enumerator ("#" instead of the regular enumerator). Return ``None`` for invalid (out of range) ordinals. """ if sequence == "#": # pragma: no cover enumerator = "#" elif sequence == "arabic": enumerator = str(ordinal) else: if sequence.endswith("alpha"): if ordinal > 26: # pragma: no cover return None enumerator = chr(ordinal + ord("a") - 1) elif sequence.endswith("roman"): try: enumerator = roman.toRoman(ordinal) except roman.RomanError: # pragma: no cover return None else: # pragma: no cover raise ParserError(f'unknown enumerator sequence: "{sequence}"') if sequence.startswith("lower"): enumerator = enumerator.lower() elif sequence.startswith("upper"): enumerator = enumerator.upper() else: # pragma: no cover raise ParserError(f'unknown enumerator sequence: "{sequence}"') next_enumerator = format[0] + enumerator + format[1] return next_enumerator
def int2enum(value, enum_type): if enum_type == 'upperalpha': return chr(ord('A') + value - 1) elif enum_type == 'loweralpha': return chr(ord('a') + value - 1) elif enum_type in ('upperroman', 'lowerroman'): res = toRoman(value) if enum_type == 'upperroman': res = res.upper() return res raise NotImplementedError(enum_type)
def to_roman(i, lower=False): s = roman.toRoman(i) if lower: s = s.lower() return s