Multiple fonts on the same line of speech(?)

Started by Stupot, Tue 10/05/2016 01:11:03

Previous topic - Next topic

Stupot

I have a feeling the answer is no, but some clever clogs might know a workaround. Is it at all possible to use different fonts within a single line of speech.

We normally change the fonts outside of the speech commands so you can change the font from one time to the next, but how about within the same line?, much like we do all the time in any basic word processing (including this  forum)?

Any ideas?

Snarky

Render it yourself with DrawString() on an Overlay. You might be able to use the HyperText module as a template: http://www.adventuregamestudio.co.uk/forums/index.php?topic=29358.0

Stupot


Danvzare

You could (and I honestly don't know if this could work) make a custom font, with the unused characters in one font replaced with the letters from another font. And then just use that font for whenever you need to have multiple fonts on a single line of text.

It's just an idea though. There's probably all sorts of problems I'm not considering here.

Monsieur OUXX

Quote from: Danvzare on Tue 10/05/2016 15:22:12
You could (and I honestly don't know if this could work) make a custom font, with the unused characters in one font replaced with the letters from another font. And then just use that font for whenever you need to have multiple fonts on a single line of text.

It's just an idea though. There's probably all sorts of problems I'm not considering here.
That would work, but why make things complicated when you can just use a module ten times more simple and powerful?
 

Stupot

The hypertext module links are all broken. Does anyone have a mirror?

@Dan, that's not a terrible idea but it wouldn't quite work for what I'm hoping to achieve, for various reasons.

Snarky

I think I have it on some other drive, and will try to dig it up. However, it is a bit of an overkill for what you describe, and what you need shouldn't be terribly hard to write yourself (I'm assuming that you want to render the text across multiple lines in a bottom-expanding box of predefined width):

-Divide up the text into segments, one for each time you switch font (probably easiest to just pass a string array in the first place, and a corresponding array of FontTypes; alternatively you could write some text parsing functions that would allow you to put formatting tags into the string, but that would be a lot more work)
-Figure out how to render each string segment inside the defined rendering area (i.e. the given width). For each string segment:
--calculate its size when rendered in the appropriate font, using GetTextHeight()/GetTextWidth(). Keep track of these values.
--work line by line. Calculate and keep track of the starting x-position of each segment (by adding the widths of the preceding segments together), and the max text height seen on this line so far.
--given the starting x-position of the rendering and the width of the rendering area, determine if you need to line-break (doing line-breaking internally within a segment is probably the most complicated part, so avoid it if you can)
--once you've reached the end of the line, use the max text height (for line spacing) and the various x-positions to position and draw each string segment, and move on to the next line.

I don't remember how AGS DrawString() positions text vertically, but I suspect it's by the upper edge. So you may need to define a vertical displacement for each font so that they'll all have the same baseline.

SMF spam blocked by CleanTalk