From 123269b4ecc07a96cc444ee23d4f887ecdc60736 Mon Sep 17 00:00:00 2001 From: Matt Fisher Date: Mon, 31 Jul 2023 15:19:56 -0600 Subject: [PATCH] Add a list of blocked fonts and corresponding style validator --- qgreenland/models/config/layer.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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):