From 0fe7994b420f2c1c2287e8cf0dfeaf76ce30879c Mon Sep 17 00:00:00 2001 From: vocx-fc Date: Tue, 15 Sep 2020 19:57:50 -0500 Subject: [PATCH] Draft: split svg.get_text into smaller readable functions Split the code for SVG string that will be displayed for TechDraw pages; also split the header for other cases. --- src/Mod/Draft/draftfunctions/svg.py | 165 ++++++++++++++++++---------- 1 file changed, 105 insertions(+), 60 deletions(-) diff --git a/src/Mod/Draft/draftfunctions/svg.py b/src/Mod/Draft/draftfunctions/svg.py index 145cd082ca..34f497e17f 100644 --- a/src/Mod/Draft/draftfunctions/svg.py +++ b/src/Mod/Draft/draftfunctions/svg.py @@ -354,6 +354,93 @@ def getOvershoot(point, shootsize, color, linewidth, angle=0): return get_overshoot(point, shootsize, color, linewidth, angle) +def _get_text_techdraw(text, tcolor, fontsize, anchor, + align, fontname, angle, base, + linespacing): + """Return the SVG representation of text for TechDraw display. + + `text` is a list of textual elements; they are iterated, styled, + and added around a `` tag. + :: + text[0] + text[1] + """ + svg = "" + for i in range(len(text)): + _t = text[i].replace("&", "&") + _t = _t.replace("<", "<") + t = _t.replace(">", ">") + + if six.PY2 and not isinstance(t, six.text_type): + t = t.decode("utf8") + + # possible workaround if UTF8 is unsupported + # import unicodedata as U + # v = list() + # for c in U.normalize("NFKD", t): + # if not U.combining(c): + # v.append(c) + # + # t = u"".join(v) + # t = t.encode("utf8") + + svg += ' tag with style options. + + The text must be added after this tag, and then must be closed. + :: + + ... + + """ + svg = '", ">") - - if six.PY2 and not isinstance(t, six.text_type): - t = t.decode("utf8") - - # possible workaround if UTF8 is unsupported - # import unicodedata as U - # v = list() - # for c in U.normalize("NFKD", t): - # if not U.combining(c): - # v.append(c) - # - # t = u"".join(v) - # t = t.encode("utf8") - - svg += ' text[0] + # text[1] + svg = _get_text_techdraw(text, tcolor, fontsize, anchor, + align, fontname, angle, base, + linespacing) else: - svg = ' text + # + # For multiple elements, place each element inside a tag. + # + # text[0] + # text[1] + # + svg = _get_text_header(tcolor, fontsize, anchor, align, + fontname, angle, base, flip) if len(text) == 1: try: