JDK-8360165 : Font.canDisplayUpTo does not work correctly with variation selectors
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 21
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2025-06-16
  • Updated: 2025-09-03
  • Resolved: 2025-08-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
Font.canDisplay(int) and Font.canDisplayUpTo do not work correctly with variation selectors.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Install some Japanese fonts for all users and run the test code.


---------- BEGIN SOURCE ----------
public static void main(String[] args) {
    int cp[] = { 0x8FBB, 0xE0101 };

    String str = new String(cp, 0, cp.length);
    System.out.println(str);

    Font font = new Font(fontName, Font.PLAIN, 12);

    System.out.println(font.canDisplayUpTo(str) == -1);  // => false
    System.out.println(font.canDisplay(cp[0]));  // => true
    System.out.println(font1.canDisplay(cp[1]));  // => false
}
---------- END SOURCE ----------


Comments
This was fixed by JDK-8208377. The fix is that we ignore variation selectors (and other such code points) when determining if a string can be displayed. This is a big improvement, as before, any string with a variation selector would be reported as undisplayable by any font. So what that fix doesn't do is check that the font actually supports variation selectors, and in particular doesn't mean that particular sequence will display a different glyph than without the selector. That would require checking the cmap format 14 table (if there is one) and seeing if there is a mapping for the sequence. I don't think canDisplay as it is should return false if that fails. Perhaps a new API - some kind of overload of canDisplay - could be created for this if there is a need.
23-08-2025

Code written 20 years ago won't have heard of variation selectors.
23-06-2025

Impact -> M (Somewhere in-between the extremes) Likelihood -> L (Probably only happens with Japanese fonts) Workaround -> M (Somewhere in-between the extremes) Priority -> P4
21-06-2025

No response from the submitter.
21-06-2025

Requested a complete reproducer from the submitter.
17-06-2025