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

Use stb_truetype for all text rendering #422

Merged
merged 12 commits into from
Feb 6, 2018
Merged

Use stb_truetype for all text rendering #422

merged 12 commits into from
Feb 6, 2018

Conversation

jlnr
Copy link
Member

@jlnr jlnr commented Nov 26, 2017

Goals:

  • Add tests for text rendering – this is possible without render-to-image functionality, we can use Image.from_text(...).save(...)
  • Ditch macOS-/iOS-specific code by using stb_truetype
  • Ditch Windows-specific code by using stb_truetype
  • Ditch Linux-specific code by using stb_truetype
  • Make Font handle Unicode more sensibly by bundling & using utf8proc (fixes Font.cpp: Use UCS-4 on all platforms, maybe precompose? #359)
  • Specifically, replace Font#[]= by a block passed to the constructor, for example: Font.new(...) { |grapheme| Image.new("glyphs/#{grapheme}.png") }. The "default block" just happens to render the grapheme cluster using Image.from_text. This will also be the loophole to test grapheme cluster parsing—the block will be called once per cluster.
  • Refactor markup handling, it's inefficient and probably buggy
  • Make register_entity available in Ruby (it wasn't?!)
  • Add Font#draw_markup and Image.from_markup as suggested in Fix the text/string mess #304, but make these aliases for the existing methods for now; Gosu 1.0.0 will then introduce a difference

@jlnr
Copy link
Member Author

jlnr commented Nov 26, 2017

Idea: Gosu currently uses OS APIs to locate and render fonts when a non-filename is passed as the font: option. If we can lookup TTF files by font name, Gosu could use stb_truetype even for system fonts. On Linux, that probably involves using the FontConfig API.

@jlnr jlnr added this to the 1.0 milestone Nov 26, 2017
@jlnr jlnr force-pushed the text-refactoring branch 6 times, most recently from 895890f to b3d0e84 Compare November 26, 2017 15:20
@jlnr
Copy link
Member Author

jlnr commented Feb 2, 2018

When I run this:

ruby -rgosu -e 'Gosu::Image.from_text("Was <b>geht <i>alder</i></b>", 40, font: "Arial").save("test.png")'

...the result does not look satisfactory :/ – I've darkened the colors because white on transparent is invisible on GitHub:

test

I need to check if this is caused by a terrible version of arial.ttf being loaded (shouldn't be?) or if my rendering code is just bad. Maybe I accidentally inverted the lsb offset?

Edit: Fixed, yay - turns out the lsb is not actually something that Gosu should pay attention to.

@jlnr jlnr changed the title Text/font refactoring Use stb_truetype for all text rendering Feb 6, 2018
@jlnr jlnr merged commit 0d99f05 into master Feb 6, 2018
@jlnr
Copy link
Member Author

jlnr commented Feb 6, 2018

This PR has been around long enough, I'll move the remaining bullet points into one or two separate branches.

@jlnr jlnr deleted the text-refactoring branch February 7, 2018 18:42
jlnr added a commit that referenced this pull request Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Font.cpp: Use UCS-4 on all platforms, maybe precompose?
1 participant