For example, suppose you want to output the string "VA" with kerning; to achieve the correct character spacing the V and the A need to be moved closer together than they would normally be printed; let's assume by two pixels. What FNkern would do in that case is to convert the character sequence '&56 &41' into the sequence '&56 &19 &00 &FE &FF &00 &00 &41', which when interpreted by the VDU emulator is equivalent to:
Code: Select all
PRINT "V";
MOVE BY -2,0
PRINT "A";
Code: Select all
OSCLI "FONT """ + @lib$ + "DejaVuSans"", 48"
VDU 5,30
PRINT "TATATA"
PRINT FNkern("TATATA")
END
DEF FNkern(a$)
LOCAL I%, K%, k$
IF LEN(a$) < 2 THEN = a$
FOR I% = 1 TO LEN(a$) - 1
k$ += MID$(a$,I%,1)
K% = FNwidth(MID$(a$,I%,2)) - WIDTH(MID$(a$,I%,1)) - WIDTH(MID$(a$,I%+1,1))
IF K% k$ += CHR$25 + CHR$0 + CHR$(K%) + CHR$(K% >> 8) + CHR$0 + CHR$0
NEXT
= k$ + RIGHT$(a$)
DEF FNwidth(a$) IF INKEY(-256)<>&57 THEN = WIDTH(a$)
LOCAL G%, W% : DIM G% LOCAL 35 : !G% = 36 : G%!28 = LENa$
SYS "GetCharacterPlacement", @memhdc%, a$, LENa$, 0, G%, 8 TO W%
= (W% AND &FFFF) * 2