Formatvorlagen für Text eingefügt
This commit is contained in:
+32
-4
@@ -26,6 +26,24 @@ MM = QgsUnitTypes.LayoutMillimeters
|
||||
class Layout:
|
||||
"""Erzeugt ein QGIS-Layout für den Druck."""
|
||||
|
||||
_TEXT_FORMAT_TEMPLATES = {
|
||||
"Format_1": {
|
||||
"font_family": "Arial",
|
||||
"font_size": 12,
|
||||
"font_style": "normal",
|
||||
},
|
||||
"Format_2": {
|
||||
"font_family": "Arial",
|
||||
"font_size": 12,
|
||||
"font_style": "fett",
|
||||
},
|
||||
"Format_3": {
|
||||
"font_family": "Arial",
|
||||
"font_size": 10,
|
||||
"font_style": "normal",
|
||||
},
|
||||
}
|
||||
|
||||
_OBJECT_TEMPLATES = {
|
||||
"hauptkarte": {
|
||||
"id": "Hauptkarte",
|
||||
@@ -33,12 +51,12 @@ class Layout:
|
||||
"quellenangabe": {
|
||||
"id": "Quellenangabe",
|
||||
"size_mm": (180.0, 100.0),
|
||||
"font": ("Arial", 12),
|
||||
"format": "Format_1",
|
||||
},
|
||||
"seitenzahl": {
|
||||
"id": "Seitenzahl",
|
||||
"size_mm": (60.0, 8.0),
|
||||
"font": ("Arial", 12),
|
||||
"format": "Format_1",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -83,8 +101,10 @@ class Layout:
|
||||
x_mm: float,
|
||||
y_mm: float,
|
||||
*,
|
||||
text_format: str | None = None,
|
||||
font_name: str | None = None,
|
||||
font_size: int | None = None,
|
||||
font_style: str | None = None,
|
||||
width_mm: float | None = None,
|
||||
height_mm: float | None = None,
|
||||
html_mode: bool = False,
|
||||
@@ -109,8 +129,16 @@ class Layout:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
template_font_name, template_font_size = template.get("font", ("Arial", 12))
|
||||
label.setFont(QFont(font_name or template_font_name, font_size or template_font_size))
|
||||
format_name = text_format or template.get("format", "Format_1")
|
||||
format_template = self._TEXT_FORMAT_TEMPLATES.get(format_name, self._TEXT_FORMAT_TEMPLATES["Format_1"])
|
||||
resolved_font_name = font_name or format_template["font_family"]
|
||||
resolved_font_size = font_size or format_template["font_size"]
|
||||
resolved_font_style = font_style or format_template["font_style"]
|
||||
|
||||
font = QFont(resolved_font_name, resolved_font_size)
|
||||
if hasattr(font, "setBold"):
|
||||
font.setBold(resolved_font_style == "fett")
|
||||
label.setFont(font)
|
||||
|
||||
set_reference_point = getattr(label, "setReferencePoint", None)
|
||||
lower_left = getattr(getattr(QgsLayoutItem, "ReferencePoint", object), "LowerLeft", None)
|
||||
|
||||
Reference in New Issue
Block a user