From feef08af8a5406d6761abbac52ee7eed1ff80478 Mon Sep 17 00:00:00 2001 From: SurajDadral Date: Sun, 10 May 2020 23:40:14 +0530 Subject: [PATCH] Add FontSize parameter to BOMContent object --- BillOfMaterial/BillOfMaterialContent.py | 23 ++++++++++++++++++++++- BillOfMaterial/BillOfMaterial_SVG.py | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/BillOfMaterial/BillOfMaterialContent.py b/BillOfMaterial/BillOfMaterialContent.py index a64215da..5ff1aa09 100644 --- a/BillOfMaterial/BillOfMaterialContent.py +++ b/BillOfMaterial/BillOfMaterialContent.py @@ -32,6 +32,18 @@ def setProperties(self, obj): ) obj.Font = "DejaVu Sans" + if "FontSize" not in pl: + obj.addProperty( + "App::PropertyLength", + "FontSize", + "BOMContent", + QT_TRANSLATE_NOOP( + "App::Property", + "The font size of Bill of Material content.", + ), + ) + obj.FontSize = 3 + def onDocumentRestored(self, obj): """Upgrade BOMContent object.""" self.setProperties(obj) @@ -45,7 +57,16 @@ def execute(self, obj): if obj.Font: obj.Symbol = re.sub( 'font-family="([^"]+)"', - 'font-family="{}"'.format(str(obj.Font)), + 'font-family="{}"'.format(obj.Font), + obj.Symbol, + ) + obj.ViewObject.update() + + if hasattr(obj, "FontSize"): + if obj.FontSize: + obj.Symbol = re.sub( + 'font-size="([^"]+)"', + 'font-size="{}"'.format(obj.FontSize.Value), obj.Symbol, ) obj.ViewObject.update() diff --git a/BillOfMaterial/BillOfMaterial_SVG.py b/BillOfMaterial/BillOfMaterial_SVG.py index 022a6d05..9fe09a40 100644 --- a/BillOfMaterial/BillOfMaterial_SVG.py +++ b/BillOfMaterial/BillOfMaterial_SVG.py @@ -931,6 +931,7 @@ def makeBillOfMaterialSVG( bom_content_obj = bom_obj.Views[0] bom_content_obj.Symbol = svg_output bom_content_obj.Font = font_family + bom_content_obj.FontSize = font_size bom_content_obj.X = bom_width * scaling_factor / 2 + bom_left_offset bom_content_obj.Y = ( template_height - bom_height * scaling_factor / 2 - bom_top_offset