Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions news/4.39/platform_isv.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,50 @@ pdf.dispose();

This enhancement eliminates the need for external PDF libraries and provides a native, platform-integrated solution for PDF generation in SWT applications.
See [Snippet388](https://github.com/eclipse-platform/eclipse.platform.swt/blob/master/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet388.java) for a complete working example.

### ImageDataAtSizeProvider Referencable

<details>
<summary>Contributors</summary>

- [Michael Bangas](https://github.com/Michael5601)
- [Arun Jose](https://github.com/arunjose696)
- [Heiko Klare](https://github.com/HeikoKlare)
</details>

The `ImageDataAtSizeProvider` interface is now available as public API.
It allows SWT users to provide image data at a custom width and height, rather than relying solely on zoom-based scaling.
To this end, the `getImageData(int width, int height)` method of the provider needs to be implemented.

The `ImageDataAtSizeProvider` is particularly useful in cases where precise control over image dimensions is needed, allowing users to create image data at a specific width and height.

If such a provider shall also be used to retrieve image data for specific zooms, the `getDefaultSize() : Point` method can overwritten to define the size that the image data shall have at 100% zoom.
In that case, calls to `getImageData(int zoom)` are delegated to `getImageData(int width, int height)` with the given zoom applied to the default size.

#### Example Usage

```java
// Lambda implementation of ImageDataAtSizeProvider
ImageDataAtSizeProvider provider = (width, height) -> {
PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
ImageData data = new ImageData(width, height, 32, palette);
int pixel = palette.getPixel(drawnRgb);

// Draw a border
for (int i = 0; i < width; i++) {
data.setPixel(i, 0, pixel);
data.setPixel(i, height - 1, pixel);
}
for (int i = 0; i < height; i++) {
data.setPixel(0, i, pixel);
data.setPixel(width - 1, i, pixel);
}
return data;
};

// Create an Image using the provider
Image image = new Image(display, provider);
```

Images from this provider can be drawn at a specific size using `GC.drawImage(Image, int, int, int, int)`.
See also the [news on the introduction of that method](../4.38/platform_isv.md#new-gc-api-for-drawing-scaled-images).