#1153 Fix newlines in text literals and smart tags in SVGs

This commit is contained in:
Dion Moult
2022-04-14 21:08:06 +10:00
parent 5b1b8e8f50
commit 1ba7977587
3 changed files with 11 additions and 7 deletions
@@ -67,7 +67,7 @@ class SheetBuilder:
drawing_dir = os.path.join(self.data_dir, "diagrams")
sheet_path = os.path.join(sheet_dir, sheet_name + ".svg")
drawing_path = os.path.join(drawing_dir, filename + ".svg")
underlay_path = os.path.join(drawing_dir, filename + ".png")
underlay_path = os.path.join(drawing_dir, filename + "-underlay.png")
if not os.path.isfile(sheet_path):
raise FileNotFoundError
@@ -544,7 +544,7 @@ class SvgWriter:
if text_obj.BIMTextProperties.symbol != "None":
self.svg.add(
self.svg.use("#{}".format(text_obj.BIMTextProperties.symbol), insert=tuple(text_position * self.scale))
self.svg.use(f"#{text_obj.BIMTextProperties.symbol}", insert=tuple(text_position * self.scale))
)
if text_literal.BoxAlignment == "top-left":
@@ -575,11 +575,15 @@ class SvgWriter:
alignment_baseline = "baseline"
text_anchor = "end"
text_body = text_literal.Literal
if text_obj.name in self.annotations.get("template_variables", {}):
text_body = pystache.render(text_body, self.annotations["template_variables"][text_obj.name])
literal = text_literal.Literal
for line_number, text_line in enumerate(text_body.split("\n")):
product = tool.Drawing.get_text_product(element)
selector = ifcopenshell.util.selector.Selector
variables = {}
for variable in re.findall("{{.*?}}", literal):
literal = literal.replace(variable, selector.get_element_value(product, variable[2:-2]) or "")
for line_number, text_line in enumerate(literal.replace("\\n", "\n").split("\n")):
self.svg.add(
self.svg.text(
text_line,
+1 -1
View File
@@ -201,7 +201,7 @@ class Drawing(blenderbim.core.tool.Drawing):
name = document.Identification or "X"
else:
name = document.DocumentId or "X"
name += " - " + document.Name or "Unnamed"
name += " - " + (document.Name or "Unnamed")
return name
@classmethod