Re: Font Rendering: Multiple FT_Faces and baselines

2023-07-29 Thread Alexei Podtelezhnikov
> > ... calculate an "average" baseline and align to that ...

> Or align to the midpoints of the overall font glyph boxes (including
> font ascent and font descent). That may be a suitable compromise.

Or... whatever works.  FreeType provides a client with all kinds of
metrics and bounding boxes, bitmap sizes and offsets. Use them as you
see fit for text layout or graffiti.



Re: Font Rendering: Multiple FT_Faces and baselines

2023-07-19 Thread Werner LEMBERG

> I'm aware that when drawing text, all glyphs should be aligned on a
> single baseline.  The example I've given does not do this; it aligns
> the text on different font's baseline, causing the inconsistent
> look.

This is what I told you in the very beginning: Your logic to position
the glyphs vertically is flawed; you actually don't align them
correctly – somewhere, you are not using the correct vertical offsets.
I suggest that you check the FreeType demo programs for some guidance.

  https://gitlab.freedesktop.org/freetype/freetype-demos

> When I'm talking about "aligning the baselines", I'm referring to
> choosing a suitable baseline from different fonts. I use the term
> "baseline" loosely as when rendering text from top to bottom, the
> ascent value is used.

Why not position the baseline for all fonts at position y=0?

> Initially, I plan to calculate a global baseline from all the fonts
> by averaging their respective baselines. Another way is to pick the
> "lowest" baseline (as in the highest ascent value) as the global
> baseline. I'm unsure of what strategy to use, so I'm curious about
> what approach do other applications use to solve this problem.

If I understand you correctly, we have an XY problem here.  The real
issue seems not to be the alignment on a baseline but rather how to
compute the global bounding box of a text string that comprises
different fonts.  The answer to that was given repeatedly on the
mailing list: If you need a bounding box correct to the pixel and you
do hinting, you have to make FreeType compute all glyphs, store them
somewhere, *then* walk over all individual bounding boxes and take the
maximum dimensions to get the global one.  Finally, you can render the
glyphs with the correct offsets.


Werner


Re: Font Rendering: Multiple FT_Faces and baselines

2023-07-19 Thread takase1121
Hi,

Sorry for the mess of emails. This is my first time using a mailing list, and 
I'm still getting the hang of it.

I'm aware that when drawing text, all glyphs should be aligned on a single 
baseline. The example I've given does not do this; it aligns the text on 
different font's baseline, causing the inconsistent look.

When I'm talking about "aligning the baselines", I'm referring to choosing a 
suitable baseline from different fonts. I use the term "baseline" loosely as 
when rendering text from top to bottom, the ascent value is used. Initially, I 
plan to calculate a global baseline from all the fonts by averaging their 
respective baselines. Another way is to pick the "lowest" baseline (as in the 
highest ascent value) as the global baseline. I'm unsure of what strategy to 
use, so I'm curious about what approach do other applications use to solve this 
problem.


Kelvin

--- Original Message ---
On Thursday, July 20th, 2023 at 11:56, Werner LEMBERG w...@gnu.org wrote:


> [It would be nice if you could use a decent e-mail writer that creates
> readable plain-text messages (which we prefer on this mailing list),
> without completely garbling quoted material.]
> 
> > > This looks like a logic error in your program. If I say `ftdump cjk.otf` 
> > > I get
> > > 
> > > `ascender: 1160 descender: -288`
> > > 
> > > among other data.
> > > 
> > > The output of `ftdump en.ttf` gives
> > > 
> > > `ascender: 935 descender: -265`
> > > 
> > > This is perfectly fine. [...]
> > 
> > Thank you for pointing it out. I'm unsure about the strategy to
> > align the baselines. The simplest would be aligning to the lowest /
> > highest baselines, but that may break some faces.
> 
> Uh, oh, please update your knowledge on how fonts are actually working
> within the frame of typography. There is no 'lowest' or 'highest'
> baseline – there is only the baseline (assuming horizontal
> typesetting). It is the very idea of a baseline that all glyphs of
> all fonts are by default aligned on that! There exist additional
> concepts like superscript or subscript, but this is something else and
> not relevant here, as far as I can see.
> 
> Maybe you want to achieve something different, I don't know. Please
> educate yourself in advance to use the right technical terms so that
> we can actually communicate without misunderstandings.
> 
> You might have a look at
> 
> https://freetype.org/freetype2/docs/glyphs/glyphs-3.html
> 
> as a starter.
> 
> Werner



Re: Font Rendering: Multiple FT_Faces and baselines

2023-07-19 Thread Lawrence D'Oliveiro
On Thu, 20 Jul 2023 01:03:54 +, takase1121 via FreeType users wrote:

> ... calculate an "average" baseline and align to that ...

Or align to the midpoints of the overall font glyph boxes (including
font ascent and font descent). That may be a suitable compromise.



Re: Font Rendering: Multiple FT_Faces and baselines

2023-07-19 Thread takase1121 via FreeType users
Hi,

Thank you for pointing it out. I'm unsure about the strategy to align the 
baselines. The simplest would be aligning to the lowest / highest baselines, 
but that may break some faces. The other method would be the one I mentioned - 
calculate an "average" baseline and align to that, but it has the same 
drawbacks. Are there other methods that I've missed?
 Original Message 
On 19 Jul 2023, 20:20, Werner LEMBERG < w...@gnu.org> wrote:

>> Thank you for your reply. I attached a example program, test.c > which uses 
>> SDL2 to render text with the method I mentioned. The > program doesn't take 
>> any arguments and should produce a file called > result.bmp in the current 
>> directory. I've also attached two fonts, > cjk.otf and en.ttf as they're the 
>> font I used. Put everything in > the same directory and it should work. This 
>> looks like a logic error in your program. If I say `ftdump cjk.otf` I get 
>> ``` ascender: 1160 descender: -288 ``` among other data. The output of 
>> `ftdump en.ttf` gives ``` ascender: 935 descender: -265 height: 1200 ``` 
>> This is perfectly fine. I've attached images of ``` ftgrid -e unic -f 20320 
>> cjk.otf ftgrid -e unic -f 70 en.ttf ``` and you can see that the glyphs 
>> harmonize just fine if you align the baselines of the two fonts. Werner

Re: Font Rendering: Multiple FT_Faces and baselines

2023-07-19 Thread Werner LEMBERG

[It would be nice if you could use a decent e-mail writer that creates
 readable plain-text messages (which we prefer on this mailing list),
 without completely garbling quoted material.]


> > This looks like a logic error in your program.  If I say `ftdump
> > cjk.otf` I get
> >
> > ```
> > ascender: 1160
> > descender: -288
> > ```
> >
> > among other data.
> >
> > The output of `ftdump en.ttf` gives
> >
> > ```
> > ascender: 935
> > descender: -265
> > ```
> >
> > This is perfectly fine.  [...]
>
> Thank you for pointing it out.  I'm unsure about the strategy to
> align the baselines.  The simplest would be aligning to the lowest /
> highest baselines, but that may break some faces.

Uh, oh, please update your knowledge on how fonts are actually working
within the frame of typography.  There is no 'lowest' or 'highest'
baseline – there is only *the* baseline (assuming horizontal
typesetting).  It is the very idea of a baseline that *all* glyphs of
*all* fonts are by default aligned on that!  There exist additional
concepts like superscript or subscript, but this is something else and
not relevant here, as far as I can see.

Maybe you want to achieve something different, I don't know.  Please
educate yourself in advance to use the right technical terms so that
we can actually communicate without misunderstandings.

You might have a look at

  https://freetype.org/freetype2/docs/glyphs/glyphs-3.html

as a starter.


Werner


Re: Font Rendering: Multiple FT_Faces and baselines

2023-07-16 Thread Werner LEMBERG


> My problem arises when different faces have different baselines, and
> some faces (especially CJK) has weird baselines as CJK scripts
> technically don't have a concept of baselines. This causes the text
> using different faces to be offsetted vertically.  I've thought of
> choosing the lowest baseline or calculating the average baseline for
> the entire run, but all of them would potentially mess up the text.
> What would be a good way to solve this?

Well, you can only align to what the fonts provide.  Assuming that you
are using OpenType fonts, alignment is specified in the 'hhea' table,
and FreeType extracts those values to provide metrics.  Any
'averaging' sounds like a very bad idea, except for the case that your
set of fonts is fixed and will never change.

I guess you have found this out by yourself, and I probably
misunderstand your question, so please elaborate and give an example.


Werner