2 ; Ullrich von Bassewitz, 2009-10-30
6 .include "tgi-kernel.inc"
7 .include "tgi-vectorfont.inc"
8 .include "zeropage.inc"
10 .import _strlen, _toascii
13 ;-----------------------------------------------------------------------------
14 ; Aliases for zero page locations
22 ;-----------------------------------------------------------------------------
23 ; unsigned __fastcall__ tgi_gettextwidth (const char* s);
24 ; /* Calculate the width of the text in pixels according to the current text
28 ; Result is strlen (s) * tgi_textmagw * tgi_fontsizex
32 .proc _tgi_gettextwidth
35 bne @L1 ; Jump if vector font
37 ; Return the width of the string for the bitmap font
44 ; Return the width of the string for the vector font. To save some code, we
45 ; will add up all the character widths and then multiply by the scale factor.
46 ; Since the output routine will scale each single character, the result may
47 ; be slightly different.
50 stx Text+1 ; Save pointer to string
55 beq @L9 ; Return zero if no font
59 adc #<(TGI_VECTORFONT::WIDTHS - TGI_VF_FIRSTCHAR)
62 adc #>(TGI_VECTORFONT::WIDTHS - TGI_VF_FIRSTCHAR)
67 sty Width+1 ; Zero the total width
69 ; Sum up the widths of the single characters
72 lda (Text),y ; Get next char
73 beq @L4 ; Bail out if end of text reached
74 jsr _toascii ; Convert to ascii
76 lda (WTab),y ; Get width of this char
87 ; We have the total width now, scale and return it
89 @L4: lda _tgi_textscalew
93 ; Exit point if no font installed