Skip to content

8360136: RFE: Add TextAttributes for OpenType font figure style features #26144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

VISTALL
Copy link

@VISTALL VISTALL commented Jul 6, 2025

Introducing to API constants, and implementation for controlling Figure Styles

Target font: Inter

Example screenshot

image


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires a CSR request matching fixVersion 26 to be approved (needs to be created)

Issue

  • JDK-8360136: RFE: Add TextAttributes for OpenType font figure style features (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26144/head:pull/26144
$ git checkout pull/26144

Update a local copy of the PR:
$ git checkout pull/26144
$ git pull https://git.openjdk.org/jdk.git pull/26144/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26144

View PR using the GUI difftool:
$ git pr show -t 26144

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26144.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper bridgekeeper bot added the oca Needs verification of OCA signatory status label Jul 6, 2025
@bridgekeeper
Copy link

bridgekeeper bot commented Jul 6, 2025

Hi @VISTALL, welcome to this OpenJDK project and thanks for contributing!

We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing /signed in a comment in this pull request.

If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user VISTALL" as summary for the issue.

If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing /covered in a comment in this pull request.

@VISTALL
Copy link
Author

VISTALL commented Jul 6, 2025

/issue JDK-8360136

@openjdk
Copy link

openjdk bot commented Jul 6, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Jul 6, 2025

@VISTALL The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@VISTALL VISTALL changed the title 8360136: Introducing TextAttribute#PROPORTIONAL_FIGURES & TABULAR_FIGURES 8360136: Support setting 'Figure Styles' while creating AWT Font Jul 6, 2025
@openjdk
Copy link

openjdk bot commented Jul 6, 2025

@VISTALL This issue is referenced in the PR title - it will now be updated.

@VISTALL
Copy link
Author

VISTALL commented Jul 6, 2025

/signed

@bridgekeeper bridgekeeper bot added the oca-verify Needs verification of OCA signatory status label Jul 6, 2025
@bridgekeeper
Copy link

bridgekeeper bot commented Jul 6, 2025

Thank you! Please allow for up to two weeks to process your OCA, although it is usually done within one to two business days. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated!

@VISTALL
Copy link
Author

VISTALL commented Jul 11, 2025

/signed

@bridgekeeper bridgekeeper bot removed oca Needs verification of OCA signatory status oca-verify Needs verification of OCA signatory status labels Jul 11, 2025
@bridgekeeper
Copy link

bridgekeeper bot commented Jul 11, 2025

You are already a known contributor!

@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 11, 2025
@mlbridge
Copy link

mlbridge bot commented Jul 11, 2025

Webrevs

Copy link
Contributor

@prrace prrace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if there's no easy way to verify it, there should be a test that at least uses these new values.

Also we need a CSR for this.

*
* <p>The constant value {@link #PROPORTIONAL_FIGURES_ON} is defined.
*
* <p>Conflicts with {@link #TABULAR_FIGURES}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. So at an API level, should it be allowed to specify both at the same time ?
Perhaps instead the attribute should be called FIGURE_WIDTH and have values of PROPORTIONAL and TABULAR
But what about the other figure related 'standard' opentype features : lining and old style ?

https://learn.microsoft.com/en-us/typography/opentype/spec/features_ko#lnum
https://learn.microsoft.com/en-us/typography/opentype/spec/features_ko#onum

They are the same idea but it affects height / vertical positioning instead of width

So do we add FIGURE_HEIGHT too with values of LINING and OLDSTYLE ?

Or .. do we add
FIGURE_STYLE and provide the combinations like
TABULAR_LINING and PROPORTIONAL_OLDSTYLE ?

There'd be 16 values so I am not sure about that.
May be have the WIDTH and HEIGHT options and let people select the pairs they want.
Also it means if they 'don't care" about one or the other they can just not set it instead of thinking.

Copy link
Author

@VISTALL VISTALL Jul 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello. Main idea - is to provide access to control this features in a simple way, without modification native & java too much.

Conflict described only in JavaDoc since - I don't want add special throws inside Font constructor with this options.

About what you say. Yes - I thought about that, but it's too big change.

For example - will be nice move control hb features control from C++ code to Java. For now it's controlled by flags, and not flexable.

What do you think about this api:

// internal api in sun.font

// enum for better control values, since there no sense give access to set 3,4,5+ values
public enum EFigureWidth {
    // unset? unknown? undefined?
    UNSET,
    PROPORTIONAL_FIGURES, // pnum=1
    TABULAR_FIGURES       // tnum=1
}

// public api
public class TextAttribute {

    public static final TextAttribute FIGURE_WIDTH = new TextAttribute("figure-width");

    public static final Object FIGURE_WIDTH_UNSET = EFigureWidth.UNSET;
    
    public static final Object FIGURE_WIDTH_TABULAR = EFigureWidth.TABULAR_FIGURES;

    public static final Object FIGURE_WIDTH_PROPORTIONAL = EFigureWidth.PROPORTIONAL_FIGURES;

    // same for figure height
}

@prrace
Copy link
Contributor

prrace commented Jul 11, 2025

/csr

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Jul 11, 2025
@openjdk
Copy link

openjdk bot commented Jul 11, 2025

@prrace has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@VISTALL please create a CSR request for issue JDK-8360136 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

@prrace
Copy link
Contributor

prrace commented Jul 11, 2025

I have changed the bug summary so you will need to change the PR summary to match -
8360136: RFE: Add TextAttributes for OpenType font figure style features

@VISTALL VISTALL changed the title 8360136: Support setting 'Figure Styles' while creating AWT Font 8360136: RFE: Add TextAttributes for OpenType font figure style features Jul 12, 2025
…bute#TABULAR_FIGURES for controlling Font figure styles
@VISTALL VISTALL force-pushed the feature/JDK-8360136 branch from a3b6912 to 0bb773d Compare July 12, 2025 07:42
@openjdk
Copy link

openjdk bot commented Jul 12, 2025

@VISTALL Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

@VISTALL
Copy link
Author

VISTALL commented Jul 12, 2025

Sure. My mistake

@VISTALL
Copy link
Author

VISTALL commented Jul 12, 2025

@prrace about tests. I can draw test image with font which is support tnum feature, and validate without it. Primitive one.

For example

  • at start - need load font, which supports this features. For example Inter (also need attach license of it inside repo?)
  • draw image 0123456789 with pnum
  • pnum
  • draw image 0123456789 with tnum
  • tnum
  • if all bytes of images equals - it's means tnum not works.

Also check default instance of Font without options

We can add this images inside repo, and validate image drawing (not sure)

@YaaZ
Copy link
Member

YaaZ commented Jul 14, 2025

Given that this needs to go through specification review anyway, I suggest to consider the more general solution with passing arbitrary OpenType features instead of a few more attributes. This would definitely be beneficial for other AWT users.
We have similar functionality implemented in JBR after requests of JetBrains users, wanting to customize their font appearance: JetBrains/JetBrainsRuntime@a2900b0

@YaaZ
Copy link
Member

YaaZ commented Jul 14, 2025

@VISTALL You can take a look at https://github.com/openjdk/jdk/blob/bcd86d575fe0682a234228c18b0c2e817d3816da/test/jdk/java/awt/font/TextLayout/FormatCharAdvanceTest.java - it has a good example of synthetic font generated specifically for the test and embedded into the test as base64. This avoids the hussle with licences and whatnot.
I would also suggest to avoid golden-image tests, as those tend to be burdensome to maintain. But in your case you can probably inspect line metrics and compare the widths of a sample text.

@VISTALL
Copy link
Author

VISTALL commented Jul 14, 2025

@YaaZ Thanks for example. About API. Will be good to make universal api - but I think it's too big task will be.

Maybe introduce api like nio2 - CopyOption* etc.

for example

interface FontFeature<V> (FontExtension?) {
   // some code
}

// V is Integer? or delegate to impl
class OpenTypeFontFeature implements FontFeature<Integer > {
   OpenTypeFontFeature (String name) {
   }
}

public final class OpenTypeFontFeatures {
    FontFeature<Integer> TABULAR_NUMBERS = new OpenTypeFontFeature<> ("tnum");
} 

There few questions:

  • conflicting features?
  • need method Font#supportsFeature(FontFeature) ?
  • need opentype class? or utilize to default font naming? (eg FontFeatureImpl)
  • need make public OpenTypeFontFeature class? (accesing from clients)
  • FontFeature will be extends TextAttribute?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client [email protected] csr Pull request needs approved CSR before integration rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

3 participants