@@ -215,20 +215,34 @@ def _to_rgba_no_colorcycle(c, alpha=None):
215
215
"%(since)s and will be removed %(removal)s; please "
216
216
"use lowercase instead." )
217
217
if isinstance (c , str ):
218
- # hex color with no alpha .
218
+ # hex color in #rrggbb format .
219
219
match = re .match (r"\A#[a-fA-F0-9]{6}\Z" , c )
220
220
if match :
221
221
return (tuple (int (n , 16 ) / 255
222
222
for n in [c [1 :3 ], c [3 :5 ], c [5 :7 ]])
223
223
+ (alpha if alpha is not None else 1. ,))
224
- # hex color with alpha.
224
+ # hex color in #rgb format, shorthand for #rrggbb.
225
+ match = re .match (r"\A#[a-fA-F0-9]{3}\Z" , c )
226
+ if match :
227
+ return (tuple (int (n , 16 ) / 255
228
+ for n in [c [1 ]* 2 , c [2 ]* 2 , c [3 ]* 2 ])
229
+ + (alpha if alpha is not None else 1. ,))
230
+ # hex color with alpha in #rrggbbaa format.
225
231
match = re .match (r"\A#[a-fA-F0-9]{8}\Z" , c )
226
232
if match :
227
233
color = [int (n , 16 ) / 255
228
234
for n in [c [1 :3 ], c [3 :5 ], c [5 :7 ], c [7 :9 ]]]
229
235
if alpha is not None :
230
236
color [- 1 ] = alpha
231
237
return tuple (color )
238
+ # hex color with alpha in #rgba format, shorthand for #rrggbbaa.
239
+ match = re .match (r"\A#[a-fA-F0-9]{4}\Z" , c )
240
+ if match :
241
+ color = [int (n , 16 ) / 255
242
+ for n in [c [1 ]* 2 , c [2 ]* 2 , c [3 ]* 2 , c [4 ]* 2 ]]
243
+ if alpha is not None :
244
+ color [- 1 ] = alpha
245
+ return tuple (color )
232
246
# string gray.
233
247
try :
234
248
c = float (c )
0 commit comments