diff --git a/qgreenland/models/config/layer.py b/qgreenland/models/config/layer.py index 042e523c..353d698c 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_does_not_contain_blocked_fonts(cls, value): + blocked_fonts = ["Cantarell", "Sans Serif"] + 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 in blocked_fonts: + raise exc.QgrInvalidConfigError( + f"Style {style_filepath} contains blocked font:" + f" '{font_family}'." + f" When in doubt, use 'Open Sans'." + ) + + return value + @validator("style") @classmethod def style_file_exists(cls, value):