Added matplotlib.colors to parse named colors

The svg parser will incorrectly parse colors such
as 'green' and 'red' to black. This commit fixes
that by using the code already written in matplotlib.colors
module
This commit is contained in:
vrroom
2021-05-13 16:12:12 +05:30
parent fd38f71527
commit b4639e5222

View File

@@ -10,6 +10,7 @@ import re
import warnings
import cssutils
import logging
import matplotlib.colors
cssutils.log.setLevel(logging.ERROR)
def remove_namespaces(s):
@@ -70,6 +71,10 @@ def parse_color(s, defs):
elif s == 'none':
return None
else:
try :
rgba = matplotlib.colors.to_rgba(s)
color = torch.tensor(rgba)
except ValueError :
warnings.warn('Unknown color command ' + s)
return color