Skip to content
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

How to add font using InputStream ? #625

Closed
TGhoul opened this issue Dec 28, 2020 · 4 comments
Closed

How to add font using InputStream ? #625

TGhoul opened this issue Dec 28, 2020 · 4 comments
Assignees

Comments

@TGhoul
Copy link

TGhoul commented Dec 28, 2020

My application is a jar file, only use getResourceAsStream() to read font files, Is there a way for this?

@danfickle danfickle self-assigned this Jan 3, 2021
@danfickle
Copy link
Owner

Hi @TGhoul,

You can use the builder methods:

        // Longhand method lets you specify font weight and style.
        builder.useFont(() -> App8.class.getResourceAsStream("/font-bold-italic.ttf"), "my-font-family", 700, FontStyle.ITALIC, true);

        // Shorthand method assumes font is normal weight and style.
        builder.useFont(() -> App8.class.getResourceAsStream("/font.ttf"), "my-font-family");

Note: It is not recommended to use input streams if using SVG or Java 2D output. See #613.

P.S. If this answers your question, feel free to close this issue.

@TGhoul
Copy link
Author

TGhoul commented Jan 4, 2021

Thank you for your answer, I got a lot of inspiration.

@TGhoul TGhoul closed this as completed Jan 4, 2021
@okhandur
Copy link

You are the man!

@yasarutkuu
Copy link

thank you very much. it's life saving tip. we spent lots of time to import fonts.

ADAMSIN. KRALSIN. @danfickle @TGhoul

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants