@@ -470,22 +470,38 @@ private TransparentColor getColorFromAttributeValue(SvgDrawContext context, Stri
470
470
return null ;
471
471
}
472
472
String tokenValue = token .getValue ();
473
- if (tokenValue .startsWith ("url(#" ) && tokenValue .endsWith (")" )) {
474
- Color resolvedColor = null ;
475
- float resolvedOpacity = 1 ;
476
- final String normalizedName = tokenValue .substring (5 , tokenValue .length () - 1 ).trim ();
477
- final ISvgNodeRenderer colorRenderer = context .getNamedObject (normalizedName );
478
- if (colorRenderer instanceof ISvgPaintServer ) {
479
- if (colorRenderer .getParent () == null ) {
480
- colorRenderer .setParent (this );
473
+ boolean isUrlInvalid = false ;
474
+ if (tokenValue .startsWith ("url(" ) && tokenValue .endsWith (")" )) {
475
+ String normalizedName = tokenValue .substring (4 , tokenValue .length () - 1 ).trim ();
476
+ normalizedName = CssUtils .extractUnquotedString (normalizedName );
477
+ if (normalizedName .startsWith ("#" )) {
478
+ Color resolvedColor = null ;
479
+ float resolvedOpacity = 1 ;
480
+ normalizedName = normalizedName .substring (1 );
481
+ final ISvgNodeRenderer colorRenderer = context .getNamedObject (normalizedName );
482
+ if (colorRenderer instanceof ISvgPaintServer ) {
483
+ if (colorRenderer .getParent () == null ) {
484
+ colorRenderer .setParent (this );
485
+ }
486
+ resolvedColor = ((ISvgPaintServer ) colorRenderer ).createColor (
487
+ context , getObjectBoundingBox (context ), objectBoundingBoxMargin , parentOpacity );
481
488
}
482
- resolvedColor = ((ISvgPaintServer ) colorRenderer ).createColor (
483
- context , getObjectBoundingBox (context ), objectBoundingBoxMargin , parentOpacity );
484
- }
485
- if (resolvedColor != null ) {
486
- return new TransparentColor (resolvedColor , resolvedOpacity );
489
+ if (resolvedColor != null ) {
490
+ return new TransparentColor (resolvedColor , resolvedOpacity );
491
+ }
492
+ if (colorRenderer == null ) {
493
+ isUrlInvalid = true ;
494
+ }
495
+ } else {
496
+ //we don't support those, but we need to make fill transparent anyway in such a case
497
+ isUrlInvalid = true ;
498
+ //try to get next token to work the same as for the local url values
487
499
}
488
500
token = tokenizer .getNextValidToken ();
501
+ } else if (tokenValue .startsWith ("url(" ) && !tokenValue .contains (" " )) {
502
+ //for cases like url\([\w\d]+ browser treats them as urls, but url\([\w\d]+\s[\w\d]+ are not
503
+ isUrlInvalid = true ;
504
+ token = tokenizer .getNextValidToken ();
489
505
}
490
506
// may become null after function parsing and reading the 2nd token
491
507
if (token != null ) {
@@ -498,6 +514,9 @@ private TransparentColor getColorFromAttributeValue(SvgDrawContext context, Stri
498
514
return new TransparentColor (result .getColor (), result .getOpacity () * parentOpacity );
499
515
}
500
516
}
517
+ if (isUrlInvalid ) {
518
+ return new TransparentColor (ColorConstants .BLACK , 0.0F );
519
+ }
501
520
return null ;
502
521
}
503
522
0 commit comments