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
43 ldy _tgi_textscalew+2 ; Get rounded scale factor
47 ; Return the width of the string for the vector font. To save some code, we
48 ; will add up all the character widths and then multiply by the scale factor.
49 ; Since the output routine will scale each single character, the result may
50 ; be slightly different.
53 stx Text+1 ; Save pointer to string
58 beq @L9 ; Return zero if no font
62 adc #<(TGI_VECTORFONT::WIDTHS - TGI_VF_FIRSTCHAR)
65 adc #>(TGI_VECTORFONT::WIDTHS - TGI_VF_FIRSTCHAR)
70 sty Width+1 ; Zero the total width
72 ; Sum up the widths of the single characters
75 lda (Text),y ; Get next char
76 beq @L4 ; Bail out if end of text reached
77 jsr _toascii ; Convert to ascii
79 lda (WTab),y ; Get width of this char
90 ; We have the total width now, scale and return it
92 @L4: lda _tgi_textscalew
96 ; Exit point if no font installed