@@ -238,6 +238,9 @@ public Image(Device device, Image srcImage, int flag) {
238
238
long srcImageHandle = win32_getHandle (srcImage , getZoom ());
239
239
switch (flag ) {
240
240
case SWT .IMAGE_COPY : {
241
+ if (createWithSVG (device , flag )) {
242
+ break ;
243
+ }
241
244
switch (type ) {
242
245
case SWT .BITMAP :
243
246
/* Get the HDC for the device */
@@ -273,12 +276,18 @@ public Image(Device device, Image srcImage, int flag) {
273
276
break ;
274
277
}
275
278
case SWT .IMAGE_DISABLE : {
279
+ if (createWithSVG (device , flag )) {
280
+ break ;
281
+ }
276
282
ImageData data = srcImage .getImageData (srcImage .getZoom ());
277
283
ImageData newData = applyDisableImageData (data , rect .height , rect .width );
278
284
init (newData , getZoom ());
279
285
break ;
280
286
}
281
287
case SWT .IMAGE_GRAY : {
288
+ if (createWithSVG (device , flag )) {
289
+ break ;
290
+ }
282
291
ImageData data = srcImage .getImageData (srcImage .getZoom ());
283
292
ImageData newData = applyGrayImageData (data , rect .height , rect .width );
284
293
init (newData , getZoom ());
@@ -291,6 +300,28 @@ public Image(Device device, Image srcImage, int flag) {
291
300
this .device .registerResourceWithZoomSupport (this );
292
301
}
293
302
303
+ private boolean createWithSVG (Device device , int flag ) {
304
+ ImageData data = null ;
305
+ Image customizedImage = null ;
306
+ if (imageProvider .getProvider () instanceof ImageFileNameProvider imageFileNameProvider ) {
307
+ ElementAtZoom <String > fileName = DPIUtil .validateAndGetImagePathAtZoom (imageFileNameProvider , getZoom ());
308
+ if (fileName .element ().endsWith (".svg" )) {
309
+ customizedImage = new Image (device , imageFileNameProvider , flag );
310
+ }
311
+ } else if (imageProvider .getProvider () instanceof ImageDataProvider imageDataProvider ) {
312
+ if (imageDataProvider .supportsRasterizationFlag (flag )) {
313
+ customizedImage = new Image (device , imageDataProvider , flag );
314
+ }
315
+ }
316
+ if (customizedImage != null ) {
317
+ data = customizedImage .getImageData (customizedImage .getZoom ());
318
+ init (data , getZoom ());
319
+ customizedImage .dispose ();
320
+ return true ;
321
+ }
322
+ return false ;
323
+ }
324
+
294
325
/**
295
326
* Constructs an empty instance of this class with the
296
327
* width and height of the specified rectangle. The result
@@ -471,7 +502,7 @@ public Image(Device device, ImageData source, ImageData mask) {
471
502
public Image (Device device , InputStream stream ) {
472
503
super (device );
473
504
initialNativeZoom = DPIUtil .getNativeDeviceZoom ();
474
- ImageData data = DPIUtil .autoScaleUp (device , new ElementAtZoom <>(new ImageData (stream , getZoom ()), 100 ));
505
+ ImageData data = DPIUtil .autoScaleUp (device , new ElementAtZoom <>(new ImageData (stream , getZoom (), SWT . IMAGE_COPY ), 100 ));
475
506
init (data , getZoom ());
476
507
init ();
477
508
this .device .registerResourceWithZoomSupport (this );
@@ -513,7 +544,7 @@ public Image (Device device, String filename) {
513
544
super (device );
514
545
if (filename == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
515
546
initialNativeZoom = DPIUtil .getNativeDeviceZoom ();
516
- ImageData data = DPIUtil .autoScaleUp (device , new ElementAtZoom <>(new ImageData (filename , getZoom ()), 100 ));
547
+ ImageData data = DPIUtil .autoScaleUp (device , new ElementAtZoom <>(new ImageData (filename , getZoom (), SWT . IMAGE_COPY ), 100 ));
517
548
init (data , getZoom ());
518
549
init ();
519
550
this .device .registerResourceWithZoomSupport (this );
@@ -556,16 +587,30 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
556
587
if (fileName .zoom () == getZoom ()) {
557
588
ImageHandle imageMetadata = initNative (fileName .element (), getZoom ());
558
589
if (imageMetadata == null ) {
559
- init (new ImageData (fileName .element (), getZoom ()), getZoom ());
590
+ init (new ImageData (fileName .element (), getZoom (), SWT . IMAGE_COPY ), getZoom ());
560
591
}
561
592
} else {
562
- ImageData resizedData = DPIUtil .autoScaleImageData (device , new ImageData (fileName .element (), getZoom ()), fileName .zoom ());
593
+ ImageData resizedData = DPIUtil .autoScaleImageData (device , new ImageData (fileName .element (), getZoom (), SWT . IMAGE_COPY ), fileName .zoom ());
563
594
init (resizedData , getZoom ());
564
595
}
565
596
init ();
566
597
this .device .registerResourceWithZoomSupport (this );
567
598
}
568
599
600
+ private Image (Device device , ImageFileNameProvider imageFileNameProvider , int flag ) {
601
+ super (device );
602
+ this .imageProvider = new ImageFileNameProviderWrapper (imageFileNameProvider );
603
+ initialNativeZoom = DPIUtil .getNativeDeviceZoom ();
604
+ int zoom = getZoom ();
605
+ ElementAtZoom <String > fileName = DPIUtil .validateAndGetImagePathAtZoom (imageFileNameProvider , zoom );
606
+ ImageHandle imageMetadata = initNative (fileName .element (), zoom );
607
+ if (imageMetadata == null ) {
608
+ init (new ImageData (fileName .element (), zoom , flag ), zoom );
609
+ }
610
+ init ();
611
+ this .device .registerResourceWithZoomSupport (this );
612
+ }
613
+
569
614
/**
570
615
* Constructs an instance of this class by loading its representation
571
616
* from the ImageData retrieved from the ImageDataProvider. Throws an
@@ -606,6 +651,16 @@ public Image(Device device, ImageDataProvider imageDataProvider) {
606
651
this .device .registerResourceWithZoomSupport (this );
607
652
}
608
653
654
+ private Image (Device device , ImageDataProvider imageDataProvider , int flag ) {
655
+ super (device );
656
+ this .imageProvider = new ImageDataProviderWrapper (imageDataProvider );
657
+ initialNativeZoom = DPIUtil .getNativeDeviceZoom ();
658
+ ImageData data = imageDataProvider .getCustomizedImageData (getZoom (), flag );
659
+ init (data , getZoom ());
660
+ init ();
661
+ this .device .registerResourceWithZoomSupport (this );
662
+ }
663
+
609
664
/**
610
665
* The provided ImageGcDrawer will be called on demand whenever a new variant of the
611
666
* Image for an additional zoom is required. Depending on the OS-specific implementation
@@ -2138,13 +2193,13 @@ protected Rectangle getBounds(int zoom) {
2138
2193
@ Override
2139
2194
ImageData getImageData (int zoom ) {
2140
2195
ElementAtZoom <String > fileName = DPIUtil .validateAndGetImagePathAtZoom (provider , zoom );
2141
- return DPIUtil .scaleImageData (device , new ImageData (fileName .element (), zoom ), zoom , fileName .zoom ());
2196
+ return DPIUtil .scaleImageData (device , new ImageData (fileName .element (), zoom , SWT . IMAGE_COPY ), zoom , fileName .zoom ());
2142
2197
}
2143
2198
2144
2199
@ Override
2145
2200
ImageHandle getImageMetadata (int zoom ) {
2146
2201
ElementAtZoom <String > imageCandidate = DPIUtil .validateAndGetImagePathAtZoom (provider , zoom );
2147
- ImageData imageData = new ImageData (imageCandidate .element (), zoom );
2202
+ ImageData imageData = new ImageData (imageCandidate .element (), zoom , SWT . IMAGE_COPY );
2148
2203
if (imageCandidate .zoom () == zoom ) {
2149
2204
/* Release current native resources */
2150
2205
ImageHandle imageMetadata = initNative (imageCandidate .element (), zoom );
0 commit comments