On Fri, 18 Aug 2023 13:24:00 GMT, Alexey Ivanov <[email protected]> wrote:

>> **Problem**
>> 
>> Glyphs aren't stretched by applying an affine transform `scale(2, 1)` to a 
>> font. Instead, the space between glyphs increases.
>> 
>> **Root Cause**
>> 
>> Bitmaps embedded in the font are used to render the glyphs; the bitmaps 
>> aren't transformed, so white-space is seen which fills the requested 
>> horizontal size.
>> 
>> **Fix**
>> 
>> Disable using embedded bitmaps if horizontal transform is different from the 
>> vertical one.
>> 
>> It's similar to [JDK-8204929](https://bugs.openjdk.org/browse/JDK-8204929) 
>> and [JDK-8255387](https://bugs.openjdk.org/browse/JDK-8255387).
>> 
>> **Test**
>> 
>> When embedded bitmaps are used, the right half of the image remains filled 
>> with the background colour. The test looks for non-white pixels in the right 
>> half of the image. If there are only white pixels in the right half of the 
>> image, the test fails; if there are other colours, the test passes.
>> 
>> I can reproduce the problem on Windows only. Without the fix, the test 
>> reports 6 failures for "MS Gothic", "MS PGothic" and "MS UI Gothic" fonts 
>> when text antialiasing is off and when LCD antialiasing is enabled. If 
>> greyscale antialiasing is enabled, the glyphs are stretched as expected, 
>> this case was handled in JDK-8204929; it can be used as a workaround.
>> 
>> All client tests pass.
>> 
>> ~~The test could be *headless*, but headless systems, especially with Linux, 
>> don't have fonts installed. Without fonts, the test is useless, therefore I 
>> made it *headful*.~~
>> 
>> The test is *headless*.
>
> Alexey Ivanov has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Add a translucent color to the test

A couple of screenshots of `ScaledFont.java` that's attached to the [JBS 
issue](https://bugs.openjdk.org/browse/JDK-8312555). The screenshots are taken 
on an English version of Windows 10.

Without the fix:  
![Screenshot of ScaledFont.java running on a recent build of JDK 22 from the CI 
on an English version of Windows 10. The text rendered with "MS Gothic" font 
has extra space between the glyphs, they're not 
stretched.](https://github.com/openjdk/jdk/assets/70774172/460c70c2-b620-416e-abf2-9f6cca1b679f)
  
The *MS Gothic* font is affected: both English characters and hieroglyphs have 
extra space between the glyphs rather than being stretched.

With the fix:  
![Screenshot of ScaledFont.java running on a development build of JDK 22 with 
the proposed fix on an English version of Windows 10. All the text, including 
the one rendered with "MS Gothic" font, has stretched 
glyphs.](https://github.com/openjdk/jdk/assets/70774172/5171f7b1-f382-4a9e-a4d5-06777ad14c8a)
  
All the characters are stretched as expected.

I modified the `ScaledFont.java` app to use a translucent color for rendering 
the text and enabled LCD text antialiasing for the first row (which uses 
`deriveFont(transform)`). @mrserb is right, it gives correct rendering in this 
case because LCD antialiasing is replaced with greyscale one. As we already 
know, greyscale AA disables using embedded bitmaps.  
![Screenshot of ScaledFont.java running on a recent build of JDK 22 from the CI 
on an English version of Windows 10. The text is rendered with a translucent 
colour, the first row for each font enables LCD text antialiasing, and the 
glyphs are stretched in this 
case.](https://github.com/openjdk/jdk/assets/70774172/c92f54c4-fb7d-4d58-b88d-2aa59790f475)

-------------

PR Comment: https://git.openjdk.org/jdk/pull/15335#issuecomment-1684032432

Reply via email to