Image scaling for Platform RegisterImage and RegisterRGBAImage?

33 views
Skip to first unread message

Mitchell

unread,
May 6, 2025, 6:11:52 PMMay 6
to scintilla-interest
Hi Neil,

Is there any appetite for modifying the Platform RegisterImage and RegisterRGBAImage interfaces to add a scaling parameter? Presumably one can call SCI_RGBAIMAGESETSCALE before calling SCI_REGISTERIMAGE or SCI_REGISTERRGBAIMAGE, just like for registering marker images.

I have a proof-of-concept for Qt that draws 16x16@2x images in autocompletion lists on a HiDPI/Retina display. Currently Scintilla draws a 16x16 image as a 32x32 image on a HiDPI display, but my test draws a 32x32 image as if it was a 16x16 scaled up by 2.

On Qt, the key is to set `QPixmap.setDevicePixelRatio(2.0)`, but the QPixmap is constructed inside `ListBoxImpl::RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage)`, which does not have a scale factor, and I cannot find a way to set it before or after the fact using the Scintilla message API. (There’s also the matter of dividing every call to `QPixmap.width()` and `QPixmap.height()` by `QPixmap.devicePixelRatio()`, but that’s trivial once the ratio is set.)

It might be possible to make scale=1 an optional default parameter, but I don’t know enough about C++ to know if that’ll still require downstream Platform changes or not.

Cheers,
Mitchell

P.S. I looked up how to do this for GTK and it’s pretty much not possible without using Cairo contexts instead of GdkPixbufs (https://gitlab.gnome.org/GNOME/gtk/-/issues/613), so that’s a bummer :(

Neil

unread,
May 7, 2025, 2:57:43 AMMay 7
to scintilla-interest
Mitchell:
Is there any appetite for modifying the Platform RegisterImage and RegisterRGBAImage interfaces to add a scaling parameter? 
...

It might be possible to make scale=1 an optional default parameter, but I don’t know enough about C++ to know if that’ll still require downstream Platform changes or not.

It is not possible to add a parameter without modifying each downstream platform layer implementation. A defaulted parameter doesn't help this case - it helps the opposite case where user (or platform layer) code calls into platform-independent code.

Using the scale set with SCI_RGBAIMAGESETSCALE for SCI_REGISTERRGBAIMAGE could potentially cause problems for applications which set a scale for SCI_MARKERDEFINERGBAIMAGE but don't currently reset it before calling SCI_REGISTERRGBAIMAGE.

It may be possible to specify a scale factor by adding a scale field to the ListOptions struct as that will be ignored by current platform layers. However, ListOptions is a set of options to the whole ListBox, not to a specific image so would only be OK if all the images were scaled by the same factor.

Another approach is to subvert the types used with ScintillaQt::WndProc or similar handling Message::RegisterRGBAImage by dynamic casting the ac.lb (autocomplete listbox) from interface ListBox to concrete ListBoxImpl then calling a private RegisterRGBAImageScaled method. 

Neil

Mitchell

unread,
May 7, 2025, 1:51:21 PMMay 7
to scintilla...@googlegroups.com
Hi Neil,
Thanks for your input. I like the ListOptions idea. I would expect anyone taking advantage of this image scaling would be supplying same-size images for listbox items.

I can start working on this feature, but it will be Qt-only. Is that acceptable? If not, then I’ll probably just make something application-specific and we can leave this for another time.

Cheers,
Mitchell

Mitchell

unread,
May 8, 2025, 11:43:19 PMMay 8
to scintilla...@googlegroups.com
Hi Neil,
Small update: I got my proof-of-concept working for GTK 3.10+ as well, so I would be able to potentially submit changes for Qt and GTK.

Cheers,
Mitchell

Neil

unread,
May 9, 2025, 5:43:39 PMMay 9
to scintilla-interest
Mitchell:

I can start working on this feature, but it will be Qt-only. Is that acceptable?

Its OK to have functions that behave differently on different platforms but that should be documented.

Where possible, differences between platforms should be minimized although that sometimes takes time.

Neil
Reply all
Reply to author
Forward
0 new messages