Page 1 of 1

Outline Font OT_BaseLine data not found

PostPosted: Fri Sep 22, 2017 11:49 pm
by blmara
Hi,

in my program I use Text() replacement for font kerning and outputting Unicode glyphs. Fonts are handled through diskfont.library/bullet.library routines. As the bullet.library doesn't seem to support underlining (and for other reasons) I need to find the baseline of font. The query seems to fail, while other type of query works ok. Here is VBCC/GCC compilable example:

Code: Select all
/* outline font baseline test */
/* gcc  testolfont.c -o ram:test -lauto */

#include <stdio.h>
#include <proto/exec.h>
#include <proto/diskfont.h>
#include <diskfont/diskfonttag.h>
#include <diskfont/oterrors.h>

STRPTR fname = "Dejavu Sans Mono.font";
uint32 devdpi = 72<<16|72;
uint32 ptheight = 16;
//struct DiskfontIFace *IDiskfont;

int main()
{
   struct OutlineFont *olfont;

   olfont = IDiskfont->OpenOutlineFont(fname,NULL,OFF_OPEN);
   if (olfont)
   {
      if (!IDiskfont->ESetInfo(&olfont->olf_EEngine,OT_DeviceDPI,devdpi,OT_PointHeight,ptheight << 16,TAG_END))
      {
         printf("Font %s point height %lu opened successfully!\n",fname,ptheight);
         {
            int Ascend, Descend;
             ULONG BaseLine,NumGlyphs;

             if (!IDiskfont->EObtainInfo(&olfont->olf_EEngine,OT_BaseLine, &BaseLine, TAG_END) && ((BaseLine & 0xffff0000) != 0))
            {
                Ascend = BaseLine >> 16;
                Descend = BaseLine & 0xffff;
               printf("Font ascend %d, descend %d\n",Ascend,Descend);
            }
            else
            {
               printf("Couldn't get font baseline data!\n");
            }
            if (!IDiskfont->EObtainInfo(&olfont->olf_EEngine, OT_NumGlyphs, &NumGlyphs, TAG_END))
               printf("The font contains %lu glyphs\n", NumGlyphs);
            else
               printf("The font engine does not support OT_NumGlyphs\n");   

         }
         IDiskfont->CloseOutlineFont(olfont,NULL);
      }
   }
   return(1);
}


The OT_BaseLine seems to return always 0, but the font seems to have ascender/descender data as show by TypeManager. Why? The example is modified from diskfont/diskfonttag.h.

Marko

Re: Outline Font OT_BaseLine data not found

PostPosted: Sun Sep 24, 2017 12:26 pm
by javierdlr
Can you try this:
Code: Select all
 struct TextAttr ta = {0};
 struct TextFont *font;

 ta.ta_Name = fname;
 ta.ta_YSize = ptheight;
 if( (font=IDiskfont->OpenDiskFont(&ta)) )
 {
  printf("Font: '%s' %d (%sproportional)\n",font->tf_Message.mn_Node.ln_Name,
           font->tf_YSize,(font->tf_Flags&FPF_PROPORTIONAL)? "":"no ");
  printf("Baseline=%d\n",font->tf_Baseline);
 }
 IGraphics->CloseFont(font);


I get:
#test
Font: 'DejaVu Sans Mono.font' 20 (no proportional)
Baseline=14

Hope it helps somehow.

Re: Outline Font OT_BaseLine data not found

PostPosted: Mon Sep 25, 2017 11:32 am
by salass00
TypeManager uses OT_BaseLine but also has fallback code which calculates the baseline based on the highest ascend and descend values of the glyphs if OT_BaseLine fails so I guess OT_BaseLine is not something that can be relied upon for all fonts.

Re: Outline Font OT_BaseLine data not found

PostPosted: Fri Sep 29, 2017 7:22 pm
by blmara
javierdlr wrote:Can you try this:
Code: Select all
 struct TextAttr ta = {0};
 struct TextFont *font;

 ta.ta_Name = fname;
 ta.ta_YSize = ptheight;
 if( (font=IDiskfont->OpenDiskFont(&ta)) )
 {
  printf("Font: '%s' %d (%sproportional)\n",font->tf_Message.mn_Node.ln_Name,
           font->tf_YSize,(font->tf_Flags&FPF_PROPORTIONAL)? "":"no ");
  printf("Baseline=%d\n",font->tf_Baseline);
 }
 IGraphics->CloseFont(font);


I get:
#test
Font: 'DejaVu Sans Mono.font' 20 (no proportional)
Baseline=14

Hope it helps somehow.


So, the OpenDiskFont() finds the baseline somehow while the code example based on include file comment doesn't. How does it do that?

Marko

Re: Outline Font OT_BaseLine data not found

PostPosted: Fri Oct 06, 2017 5:41 pm
by salass00
This should be about the same method that diskfont.library uses to calculate the font->tf_Baseline value:

https://gist.github.com/salass00/c5ed9b ... 02f9d8b5b3

Re: Outline Font OT_BaseLine data not found

PostPosted: Sat Oct 07, 2017 10:59 am
by blmara
salass00 wrote:This should be about the same method that diskfont.library uses to calculate the font->tf_Baseline value:

https://gist.github.com/salass00/c5ed9b ... 02f9d8b5b3


Thanks! So, if I understood correctly, in this method every glyph in the current character set (256 chars) is looked at and the baseline is calculated based on their metrics. In my program I use internally UCS-4 character coding and the utility.library functions to be able to import UTF-8 coded strings from (MusicXML) files. In theory, such a string can contain characters that are from multiple character sets. This probably means that one would need to go through all glyphs of the font to be sure of the baseline? Do you know why the OT_BaseLine doesn't seem to provide this information?

Marko