Skip to content

Commit

Permalink
Add a list of blocked fonts and corresponding style validator
Browse files Browse the repository at this point in the history
  • Loading branch information
mfisher87 committed Jul 31, 2023
1 parent 9664b17 commit 123269b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions qgreenland/models/config/layer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
from typing import Any, Optional, Union
from xml.etree import ElementTree

from pydantic import Field, validator

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 123269b

Please sign in to comment.