Don’t allow <text> elements in letter logos

To render text in an SVG consistently the system rendering the SVG must
have the fonts specified by the SVG installed.

If the fonts are not installed then the renderer will fall back to a
system font and the text will look different. This is especially bad
news for branding where the right font is an integral part of any brand.

To fix this, the text should instead be converted to `<path>` elements.
This process is sometimes called ‘outlining’.

A few of our logos had this problem, and I’ve fixed most of them by
hand. Adding this validation will stop the problem, coming up again.
This commit is contained in:
Chris Hill-Scott
2022-01-06 11:21:12 +00:00
parent 5558af2527
commit 291906e9fd
3 changed files with 16 additions and 1 deletions

View File

@@ -53,6 +53,7 @@ from app.main.validators import (
NoCommasInPlaceHolders,
NoEmbeddedImagesInSVG,
NoPlaceholders,
NoTextInSVG,
OnlySMSCharacters,
ValidEmail,
ValidGovEmail,
@@ -1884,7 +1885,8 @@ class SVGFileUpload(StripWhitespaceForm):
validators=[
FileAllowed(['svg'], 'SVG Images only!'),
DataRequired(message="You need to upload a file to submit"),
NoEmbeddedImagesInSVG()
NoEmbeddedImagesInSVG(),
NoTextInSVG(),
]
)

View File

@@ -102,6 +102,11 @@ class NoEmbeddedImagesInSVG(NoElementInSVG):
message = 'This SVG has an embedded raster image in it and will not render well'
class NoTextInSVG(NoElementInSVG):
element = 'text'
message = 'This SVG has text which has not been converted to paths and may not render well'
class OnlySMSCharacters:
def __init__(self, *args, template_type, **kwargs):

View File

@@ -357,6 +357,14 @@ def test_create_letter_branding_when_uploading_valid_file(
''',
'This SVG has an embedded raster image in it and will not render well',
),
(
'''
<svg height="100" width="100">
<text>Will render differently depending on fonts installed</text>
</svg>
''',
'This SVG has text which has not been converted to paths and may not render well',
),
))
def test_create_letter_branding_fails_validation_when_uploading_SVG_with_bad_element(
mocker,