diff --git a/qgreenland/models/config/layer.py b/qgreenland/models/config/layer.py index 042e523c..a0c05f60 100644 --- a/qgreenland/models/config/layer.py +++ b/qgreenland/models/config/layer.py @@ -1,5 +1,6 @@ from pathlib import Path from typing import Any, Optional, Union +from xml.etree import ElementTree from pydantic import Field, validator @@ -57,6 +58,24 @@ class Layer(QgrBaseModel): _validate_description = reusable_validator("description", validate_paragraph_text) + @validator("style") + @classmethod + def style_file_only_contains_allowed_fonts(cls, value): + allowed_fonts = ["Open Sans"] + if value: + style_filepath = _style_filepath(value) + tree = ElementTree.parse(style_filepath) + for elem in tree.getroot().iter(): + if font_family := elem.attrib.get("fontFamily", False): + if font_family not in allowed_fonts: + raise exc.QgrInvalidConfigError( + f"Style {style_filepath} contains disallowed font:" + f" '{font_family}'." + f" Only the following fonts are allowed: {allowed_fonts}." + ) + + return value + @validator("style") @classmethod def style_file_exists(cls, value):