sumatrapdf
sumatrapdf copied to clipboard
Toolbar should use XOR bitmap-mask
https://github.com/sumatrapdfreader/sumatrapdf/blob/ad67e643440a64b28c3521be4a136a07d640432d/src/Toolbar.cpp#L787
This should use ImageList_Add
instead, and construct the following bitmaps:
Main bitmap -- 0x00RRGGBB
for colored pixels, 0x00000000
for transparent pixels.
Mask bitmap -- 0x00000000
for colored pixels, 0x00FFFFFF
for transparent pixels.
This will create bitmap images that flips the underlying color.
Alternatively, if you require antialiased images that uses alpha compositing, then use ImageList_Add
with the mask set to null and the main bitmap using the color format 0xAARRGGBB. You could also use ImageList_AddIcon
for pre-generated icons.
This addresses the problem in #3669
Explanation:
There are two compositing modes that are automatically determined: alpha-blend mode and color filter mode.
When any pixel in the main bitmap has a nonzero alpha, alpha-blend mode is activated. When all pixels in the main bitmap have zero alpha, color filter mode is activated.
In alpha blend mode, the mask bitmap is ignored and the color is applied as you'd expect in typical alpha compositing.
In color filter mode, the mask bitmap sets the pixels to either SET BIT (if mask pixel is 0x00FFFFFF) or FLIP BIT (if mask pixel is anything other than 0x00FFFFFF) based on the bitflags set in the main bitmap.
So for example, if the mask pixel is FLIP BIT and the main pixel is 0x00FF00FF, this will result in the Red and Blue channels of the background being inverted while leaving the Green channel untouched.
Or if the mask pixel is FLIP BIT and the main pixel is 0x00808080, this results in the most significant bit of the Red, Green, and Blue channels of background becoming flipped -- i.e. effectively swapping the 50% intensity region but keeping the relative color contours the same.
(https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-drawiconex)
Thanks for the explanation. I did struggle writing this code.
Would you mind writing a patch? I'll eventually get to trying that but right now I'm focusing on monitoring and fixing major 3.5 bugs and regressions .
@kjk the icons you are using have a generic common currentColor (black by default) as far as I know you are not setting a value but if they were addressable here I set to "red" then that might resolve the theming aspect
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-folder" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
<path d="M5 4h4l3 3h7a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2" />
</svg>
Tried creating a a mask bitmap but it didn't fix how disabled version is shown and made non-disabled look worse (thicker lines).
I think I've implemented 0xAARRGGBB suggestion which fixes default theme but still not great for non-default themes (but better than before due to earlier change).
I tried the version with 2 rgb bitmaps (with mask bitmap) but it's the same as a single rgba bitmap (without mask)
one alternative suggestion https://github.com/sumatrapdfreader/sumatrapdf/issues/3794 was use a "white/light" or other colour in the SVG as its the aliasing of vector to pixel causes part of the issue so a white font on blackground should "work". Fonts as you know are usually an inner fill and outer stroke so the TTF needs both to be addressable.
I believe I fixed all the issues, even in dark themes.
Even in the latest prerelease 16189. W11 23H2, dark mode on.
@ArmanHayots
That is odd so Win 10 without any 3rd party enhancements uses Windows colours which dont allow for pure Black otherwise there is no contrast, so High contrast modes need careful system theme settings. Again why you cant use Black as a theme color.