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

[FEATURE REQUEST] Lookup font in text render based on family and style name #4502

Closed
peterhorvath111 opened this issue Oct 22, 2024 · 1 comment · Fixed by #4509
Closed

Comments

@peterhorvath111
Copy link
Contributor

Currently, fonts are identified by the name of the file that defines the font. In Arnold we extended this logic to be able to find fonts based on the font family and style name. This makes it easier for end users to select fonts. For instance "Arial Bold" is defined by arialbd.ttf on Windows. Specifying arialbd is not that obvious and also file names could differ based on the platform.

If you find this useful, we can port our code back here.

I'd also like to point out that it's not that obvious from the current documentation that fontname supposed to be the file name and not the family name.

fontsize/fontname – Size and name of the font. If the name is not a full pathname to a font file, it will search for a matching font, defaulting to some reasonable system font if not supplied at all), and with a nominal height of fontsize (in pixels).

Specially because some examples suggest the family name should work, like this:

ImageBufAlgo::render_text(A, x, y, "Centered", 48, "Courier New");

Not sure about other platforms, but for instance on Windows this does not work currently, because "Courier New" is defined by cour.ttf.

@peterhorvath111
Copy link
Contributor Author

Created PR #4509 with the suggested changes.

@lgritz lgritz linked a pull request Oct 29, 2024 that will close this issue
5 tasks
lgritz pushed a commit that referenced this issue Oct 29, 2024
Fixes #4502.

This PR lets you specify fonts (for `IBA::render_text()` or `oiiotool --text`)
by family and style name, rather than only by filename of the font file.

The implementation is to add `init_font_families()` function, that iterates
over the available font files, reads family and style name via the freetype
API and caches them. The function is called from `resolve_font()` on
demand.

Added a new test to the oiiotool-text folder, that loads a font by the
name "Droid Serif Bold".

---------

Signed-off-by: peter.horvath <[email protected]>
lgritz pushed a commit to lgritz/OpenImageIO that referenced this issue Oct 29, 2024
…emySoftwareFoundation#4509)

Fixes AcademySoftwareFoundation#4502.

This PR lets you specify fonts (for `IBA::render_text()` or `oiiotool --text`)
by family and style name, rather than only by filename of the font file.

The implementation is to add `init_font_families()` function, that iterates
over the available font files, reads family and style name via the freetype
API and caches them. The function is called from `resolve_font()` on
demand.

Added a new test to the oiiotool-text folder, that loads a font by the
name "Droid Serif Bold".

---------

Signed-off-by: peter.horvath <[email protected]>
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

Successfully merging a pull request may close this issue.

1 participant