@@ -399,6 +399,10 @@ func (widget *StdWidget) paintImageBrushInRect(w Writer, image *BrushImageStyle,
399399 if image == nil || strings .TrimSpace (image .Src ) == "" {
400400 return fmt .Errorf ("brush image src must be specified" )
401401 }
402+ opacity := normalizeBrushOpacity (image )
403+ if opacity <= 0 {
404+ return nil
405+ }
402406 ref , err := widget .resolveBrushImageSource (image .Src )
403407 if err != nil {
404408 return err
@@ -423,7 +427,7 @@ func (widget *StdWidget) paintImageBrushInRect(w Writer, image *BrushImageStyle,
423427 }
424428
425429 return widget .paintClippedRect (w , x , y , width , height , func () error {
426- return paintRepeatedBrushImage (w , ref .identifier , tileX , tileY , tileWidth , tileHeight , x , y , width , height , repeatMode )
430+ return paintRepeatedBrushImage (w , ref .identifier , tileX , tileY , tileWidth , tileHeight , x , y , width , height , repeatMode , opacity )
427431 })
428432}
429433
@@ -455,6 +459,20 @@ func normalizeBrushRepeat(image *BrushImageStyle) string {
455459 return strings .TrimSpace (strings .ToLower (image .Repeat ))
456460}
457461
462+ func normalizeBrushOpacity (image * BrushImageStyle ) float64 {
463+ if image == nil {
464+ return 1
465+ }
466+ switch {
467+ case image .Opacity <= 0 :
468+ return 0
469+ case image .Opacity >= 1 :
470+ return 1
471+ default :
472+ return image .Opacity
473+ }
474+ }
475+
458476func resolveBrushImageSize (fit string , boxWidth , boxHeight , imageWidth , imageHeight float64 ) (width , height float64 ) {
459477 if imageWidth <= 0 || imageHeight <= 0 {
460478 return boxWidth , boxHeight
@@ -496,7 +514,7 @@ func resolveBrushAnchor(anchor string, x, y, width, height, contentWidth, conten
496514 }
497515}
498516
499- func paintRepeatedBrushImage (w Writer , filename string , tileX , tileY , tileWidth , tileHeight , clipX , clipY , clipWidth , clipHeight float64 , repeatMode string ) error {
517+ func paintRepeatedBrushImage (w Writer , filename string , tileX , tileY , tileWidth , tileHeight , clipX , clipY , clipWidth , clipHeight float64 , repeatMode string , opacity float64 ) error {
500518 if tileWidth <= 0 || tileHeight <= 0 {
501519 return nil
502520 }
@@ -533,7 +551,7 @@ func paintRepeatedBrushImage(w Writer, filename string, tileX, tileY, tileWidth,
533551 if ! repeatX && drawX != startX {
534552 break
535553 }
536- if err := w .PaintImageFile (filename , drawX , drawY , tileWidth , tileHeight ); err != nil {
554+ if err := w .PaintImageFile (filename , drawX , drawY , tileWidth , tileHeight , opacity ); err != nil {
537555 return err
538556 }
539557 }
0 commit comments