info-beamer icon indicating copy to clipboard operation
info-beamer copied to clipboard

Allow newlines in font:write

Open Sanic opened this issue 9 years ago • 10 comments

I'am trying to display the contents of multiple textfiles, where each of them contains newlines. Unfortunately, the newlines will not be rendered as expected with font:write. The newline will just be shown as a blank.

Is there any way to do this?

Sanic avatar Jul 24 '14 20:07 Sanic

I usually use a wrapper function. Take a look at this:

https://github.com/dividuum/info-beamer-nodes/blob/d90daf261648a1583a26fedee2c374b8ed33d94c/29c3-room-next-talk/node.lua#L89

dividuum avatar Jul 24 '14 20:07 dividuum

Thanks for the hint. That helped me alot in my current project. I think it would be nice to have such a function in info-beamer itself to avoid code duplication.

Sanic avatar Jul 28 '14 09:07 Sanic

I'd love to have this too, for the same reason as @Sanic

weeheavy avatar Jun 23 '16 07:06 weeheavy

I hacked something quickly for wrapping when using non-monospace fonts. It's pretty crude (doesn't understand hyphenation), but I think I can add newline support pretty easily.

superlou avatar Apr 26 '17 12:04 superlou

Text rendering of any non-trivial text is kind of a weak point right now. I'm not sure what the best approach to improve this without adding a ton of complexity. For full unicode support, something like harfbuzz.org is probably the way to go. I'm not sure how one would solve hyphenation and other locale dependent problems.

dividuum avatar Apr 26 '17 14:04 dividuum

I agree that some kind of text-shaping library would be a more universal solution. Would full Cairo be overkill? Making PNGs using Cairo/Pango, then loading them as image resources seems a little inefficient, but it might be good enough for some use cases.

superlou avatar Apr 26 '17 14:04 superlou

Would full Cairo be overkill?

Good question. I guess that would require a complete overhaul of the existing font rendering code. Right now (in the Pi version) I'm rendering glyphs into a dynamically growing texture (Example), then render strings as vertex buffers. For performance I cache those, so they can get reused across frames.

If I understand the scope of pango correctly, you basically hand it a string and get layout information for each glyph based on various rules (Fascinating!). I'm not sure how all of that would work together. All while being completely backwards compatible with the existing text rendering output.

dividuum avatar Apr 26 '17 15:04 dividuum

I 've got a "invalid utf8" at font:write when usin ' ãç ', how to preparer for full utf-8? thanks

jegue avatar May 31 '18 04:05 jegue

If it's a variable you source from somewhere (like a JSON file), be sure that its content is UTF-8 encoded. If you're using a string literal, make sure your code editor actually saves the file in UTF-8.

dividuum avatar May 31 '18 09:05 dividuum

thanks, I will try. let you know!

jegue avatar Jun 02 '18 16:06 jegue