@@ -33,25 +33,18 @@ public static long convertSurface(Image image) {
33
33
long newSurface = image .surface ;
34
34
int type = Cairo .cairo_surface_get_type (newSurface );
35
35
if (type != Cairo .CAIRO_SURFACE_TYPE_IMAGE ) {
36
- Rectangle bounds ;
37
- if (DPIUtil .useCairoAutoScale ()) {
38
- bounds = image .getBounds ();
39
- } else {
40
- bounds = image .getBoundsInPixels ();
41
- }
36
+ Rectangle bounds = image .getBounds ();
42
37
int format = Cairo .cairo_surface_get_content (newSurface ) == Cairo .CAIRO_CONTENT_COLOR ? Cairo .CAIRO_FORMAT_RGB24 : Cairo .CAIRO_FORMAT_ARGB32 ;
43
38
newSurface = Cairo .cairo_image_surface_create (format , bounds .width , bounds .height );
44
39
if (newSurface == 0 ) SWT .error (SWT .ERROR_NO_HANDLES );
45
40
//retain device scale set in the original surface
46
- if (DPIUtil .useCairoAutoScale ()) {
47
- double sx [] = new double [1 ];
48
- double sy [] = new double [1 ];
49
- Cairo .cairo_surface_get_device_scale (image .surface , sx , sy );
50
- if (sx [0 ] == 0 || sy [0 ] == 0 ){
51
- sx [0 ] = sy [0 ] = DPIUtil .getDeviceZoom () / 100f ;
52
- }
53
- Cairo .cairo_surface_set_device_scale (newSurface , sx [0 ], sy [0 ]);
41
+ double sx [] = new double [1 ];
42
+ double sy [] = new double [1 ];
43
+ Cairo .cairo_surface_get_device_scale (image .surface , sx , sy );
44
+ if (sx [0 ] == 0 || sy [0 ] == 0 ){
45
+ sx [0 ] = sy [0 ] = DPIUtil .getDeviceZoom () / 100f ;
54
46
}
47
+ Cairo .cairo_surface_set_device_scale (newSurface , sx [0 ], sy [0 ]);
55
48
long cairo = Cairo .cairo_create (newSurface );
56
49
if (cairo == 0 ) SWT .error (SWT .ERROR_NO_HANDLES );
57
50
Cairo .cairo_set_operator (cairo , Cairo .CAIRO_OPERATOR_SOURCE );
@@ -120,15 +113,13 @@ public static long createPixbuf(long surface) {
120
113
*
121
114
* We have to do this as surface has inherent auto scaling capability but pixbuf doesnot
122
115
*/
123
- if (DPIUtil .useCairoAutoScale ()) {
124
- double sx [] = new double [1 ];
125
- double sy [] = new double [1 ];
126
- Cairo .cairo_surface_get_device_scale (surface , sx , sy );
127
- if (sx [0 ] > 1 && sy [0 ] > 1 ){
128
- long oldPixbuf = pixbuf ;
129
- pixbuf = GDK .gdk_pixbuf_scale_simple (pixbuf , width /(int )sx [0 ], height /(int )sy [0 ], GDK .GDK_INTERP_BILINEAR );
130
- OS .g_object_unref (oldPixbuf );
131
- }
116
+ double sx [] = new double [1 ];
117
+ double sy [] = new double [1 ];
118
+ Cairo .cairo_surface_get_device_scale (surface , sx , sy );
119
+ if (sx [0 ] > 1 && sy [0 ] > 1 ){
120
+ long oldPixbuf = pixbuf ;
121
+ pixbuf = GDK .gdk_pixbuf_scale_simple (pixbuf , width /(int )sx [0 ], height /(int )sy [0 ], GDK .GDK_INTERP_BILINEAR );
122
+ OS .g_object_unref (oldPixbuf );
132
123
}
133
124
return pixbuf ;
134
125
}
@@ -295,12 +286,7 @@ void set (int index, Image image) {
295
286
w /= (int )sx [0 ];
296
287
h /= (int )sy [0 ];
297
288
298
- Rectangle bounds ;
299
- if (DPIUtil .useCairoAutoScale ()) {
300
- bounds = image .getBounds ();
301
- } else {
302
- bounds = image .getBoundsInPixels ();
303
- }
289
+ Rectangle bounds = image .getBounds ();
304
290
if (w == 0 ) {
305
291
w = bounds .width ;
306
292
}
@@ -334,26 +320,22 @@ long scaleSurface(Image image, int width, int height) {
334
320
long cairo = Cairo .cairo_create (scaledSurface );
335
321
if (cairo == 0 ) SWT .error (SWT .ERROR_NO_HANDLES );
336
322
323
+ int w = Cairo .cairo_image_surface_get_width (image .surface );
324
+ int h = Cairo .cairo_image_surface_get_height (image .surface );
337
325
Rectangle bounds ;
338
- if (DPIUtil .useCairoAutoScale ()) {
339
- int w = Cairo .cairo_image_surface_get_width (image .surface );
340
- int h = Cairo .cairo_image_surface_get_height (image .surface );
341
- if ((w == 0 ) && (h == 0 )) {
342
- bounds = image .getBounds ();
343
- } else {
344
- bounds = new Rectangle (0 , 0 , w , h );
345
- }
346
-
347
- double sx [] = new double [1 ];
348
- double sy [] = new double [1 ];
349
- Cairo .cairo_surface_get_device_scale (image .surface , sx , sy );
350
- if (sx [0 ] == 0 || sy [0 ] == 0 ){
351
- sx [0 ] = sy [0 ] = DPIUtil .getDeviceZoom () / 100f ;
352
- }
353
- Cairo .cairo_surface_set_device_scale (scaledSurface , sx [0 ], sy [0 ]);
326
+ if ((w == 0 ) && (h == 0 )) {
327
+ bounds = image .getBounds ();
354
328
} else {
355
- bounds = image .getBoundsInPixels ();
329
+ bounds = new Rectangle (0 , 0 , w , h );
330
+ }
331
+
332
+ double sx [] = new double [1 ];
333
+ double sy [] = new double [1 ];
334
+ Cairo .cairo_surface_get_device_scale (image .surface , sx , sy );
335
+ if (sx [0 ] == 0 || sy [0 ] == 0 ){
336
+ sx [0 ] = sy [0 ] = DPIUtil .getDeviceZoom () / 100f ;
356
337
}
338
+ Cairo .cairo_surface_set_device_scale (scaledSurface , sx [0 ], sy [0 ]);
357
339
double scaleX = (double ) width / (double ) bounds .width ;
358
340
double scaleY = (double ) height / (double ) bounds .height ;
359
341
Cairo .cairo_scale (cairo , scaleX , scaleY );
0 commit comments