Fix default font loading for 'add_grid' #24
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I think this has always been an issue but has become very apparent in my own code after switching to the AGG contour writer by default. The main issue is that the
_add_grid
method in the base writer will try to load a default font object if one is not provided. It was usingPIL.ImageFont.load_default()
to get anImageFont
object to use. The issue with that is thataggdraw
does not handleImageFont
objects, it only handlesaggdraw.Font
objects.This PR adds a font loading method implemented by the writer subclasses. It also moves the font loading in to the label adding method so it isn't loaded unless labels are actually going to be written.
This is a short term fix. The long term fix should some how handle the differences between
ImageFont
which accepts font path and size only andFont
accepts color (outline), font path, and size. Even worse theImageFont.load_default()
returned font can't have its size specified or changed which is...not very useful.git diff origin/develop **/*py | flake8 --diff