Fix get_color_as_rgba() not working with var() colors

This commit is contained in:
Kovid Goyal 2020-08-07 10:37:26 +05:30
parent 132f6a710d
commit 9238df38d6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -70,6 +70,8 @@ def set_ui_colors(is_dark_theme):
for k in DEFAULT_COLORS: for k in DEFAULT_COLORS:
val = DEFAULT_COLORS[k][attr] val = DEFAULT_COLORS[k][attr]
s.setProperty('--calibre-color-' + k, val) s.setProperty('--calibre-color-' + k, val)
get_color_as_rgba.cache = {}
cached_color_to_rgba.cache = {}
def css_for_variables(): def css_for_variables():
@ -92,6 +94,8 @@ def color_to_rgba(color):
cvs = document.createElement('canvas') cvs = document.createElement('canvas')
cvs.height = 1 cvs.height = 1
cvs.width = 1 cvs.width = 1
if color.startsWith('var('):
color = window.getComputedStyle(document.documentElement).getPropertyValue(color[4:-1])
ctx = cvs.getContext('2d') ctx = cvs.getContext('2d')
ctx.fillStyle = color ctx.fillStyle = color
ctx.fillRect(0, 0, 1, 1) ctx.fillRect(0, 0, 1, 1)