Before anything else, I'll want to make it clear that I wrote this code for a prototype of a text-based game I intend to make.
Positive07 wrote:Okey sir! You impress me A LOT!
Have you thought about the proposals I made before? I suggested both this things because I'm working on a general textarea module that can be plugged to any rendering engine (be it the console, LÖVE or maybe your text) but in order to handle cursors and such there must exist a way to go from the string to the screen and vice-versa.
Anyway your end results look AMAZING! I haven't taken a look at your code yet, I insist this needs to be in Github but well, I can wait
Hi. Thank you very much
!
I have thought about what you said.
For each paragraph, there is a list of words. Each word has x and y information. Both are relative to the top-left corner of the paragraph. Similarly, you can easily set an additional list of x information for the divisions between consecutive letters, relatively to the beginning of the word. I previously said that you could draw each letter individually, but this is actually a bad idea, since you would have to worry about kerning and the love api does not give that information directly. There is an easy way that would be something like this:
Code: Select all
local acc = 0
for i = 1, #str do
acc = acc + font:getWidth(str:sub(1, i))
divisions[#divisions + 1] = acc
end
That would be enough for what you want inside a word. Other problem, however, would be the spaces between words.
Currently, I don't store that information at all. I completely ignore the spaces in the original text and tokenize the words. This is enough for my objectives. If you just forget about the justification alignment (and assumes it will only have left, center and right alignments), then it would be fairly easy to modify the code. Space character could be treated as a word like any other. The only part that would need special care would be the LineWrap. When it decides to start a new line with the first word being a blank space, it would have to ignore its width (this is valid for both Dynamic Programming and Greedy solutions).
One more thing.. If you want to constantly recompute line wrapping for many paragraphs, perhaps you would have to give up on minimum raggedness. The algorithm to compute this is O(n^2), where n is the number of words in the paragraph. It's is generally cheap (none paragraph is too long to make it slow), but it's not ideal when you are doing it a lot of times. In any case, I don't feel like the visual difference is very noticeable.
SiENcE wrote:A good richtext library without rendering that can be integrated...would be welcome
.
As I'm not really making a text library of any sort, I decided to take the easiest and quickest route, that is just proxying Lua. I load a file and set its environment so that the "global" functions are changing an internal state. This looks good enough for now. I wish I have the time to write down something more robust like a parser/syntactic analysis for a markup language. However, my VIVA is on next Tuesday and I'm bit busy with my work/research right now
zorg wrote:How about RtL, or TtB, BtT, or arbitrary writing directions?
Oh, also arbitrary glyph rotations.
Who wouldn't want to be able to render Ferengi writing, right?
I am being serious. Not about Ferengis, but about the other stuff
That would be nice, indeed. I have to look at how languages that are written these ways are stored. No previous experience with that, here.