tomolt / libschrift

A lightweight TrueType font rendering library
ISC License
471 stars 32 forks source link

Is yOffset correct? #36

Closed jeannekamikaze closed 6 months ago

jeannekamikaze commented 6 months ago

I am somewhat confused about yOffset, not sure if I'm using it correctly. I don't have a minimal example right now, but curious if somehow can give me a heads-up while I work on that.

I am using this monospace font: NK57.zip. (source, public domain, converted from OTF to TTF since libschrift can't load the OTF file.)

I can render the following text ("Good Stuff") just fine ignoring the yOffset:

00   .####.       **.        **.           #*               .####.     ##        .*    *.     *###*      *###*    
01   #######    ######     ######          #*              .#######    ##        *#    #*    *######    *######   
02  *#.   ##    #*  .#.    #*  .#.         #*              ##    ##   #######    *#    #*    ##   ##    ##   ##   
03  ##    **   *#.   #*   *#.   #*     *** #*              ##.   ..    ##        *#    #*    ##         ##        
04  ##  *##*   .#.   #*   .#.   #*    ######*              .####*      ##        *#    #*   #######    #######    
05  ##  ####    ##  *#     ##  *#    *#*  ##*                *####*    ##   ..    #* .##*    ##         ##        
06  ##    ##    ######     ######    *#    #*                   .##    ##   ##    ######*    ##         ##        
07  ##    ##      .*         .*      *#    #*              ##    ##    .#####*     ..        ##         ##        
08  .#* .###                         *#*  ##*              ##.  *#*      .**.                ##         ##        
09   #######                          ######*              .######                           ##         ##        
10    .*                               .*                    .*.                                                  
11                                                                                                                
12                                                                                                                
13                                                                                                                
14                                                                                                                
15

But applying the yOffset:

00  ##                                                     ## .##                   .**.                          
01  ##                                                     ##  *#*                                                
02  ##                                                     ##   ##.                                               
03  ##                                                     ##    ##                                               
04                                                                                                                
05                                                                                                                
06                                                                                                                
07                **.        **.                                                 .*    *.                         
08              ######     ######                                      ##        *#    #*                         
09              #*  .#.    #*  .#.                                     ##        *#    #*                         
10   .####.    *#.   #*   *#.   #*         #*               .####.    #######    *#    #*     *###*      *###*    
11   #######   .#.   #*   .#.   #*         #*              .#######    ##        *#    #*    *######    *######   
12  *#.   ##    ##  *#     ##  *#          #*              ##    ##    ##         #* .##*    ##   ##    ##   ##   
13  ##    **    ######     ######      *** #*              ##.   ..    ##   ..    ######*    ##         ##        
14  ##  *##*      .*         .*       ######*              .####*      ##   ##     ..       #######    #######    
15  ##  ####                         *#*  ##*                *####*    .#####*               ##         ##

This is with SFT_DOWNWARD_Y, negating yOffset (comes out negative from the library), and adding it to the y-coordinate to render (origin at the top left). Things look slightly better if I apply an offset of -yOffset / 2, but text is still off.

Curious if someone can give that font a try? Thank you.

lhf commented 6 months ago

That font works fine with my libschrift-show.

out

jeannekamikaze commented 6 months ago

Ah, thank you, I was not aware of libschrift-show. That definitely makes debugging a lot easier.

Closing this since this is a problem with my implementation.

lhf commented 6 months ago

I'm glad that libschrift-show is useful.

Just note that it is my interpretation of how to use libschrift, not an official demo by its author.