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_textwidth (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
35 bne @L1 ; Jump if vector font
37 ; Return the width of the string for the bitmap font
46 ; Return the width of the string for the vector font. To save some code, we
47 ; will add up all the character widths and then multiply by the scale factor.
48 ; Since the output routine will scale each single character, the result may
49 ; be slightly different.
52 stx Text+1 ; Save pointer to string
57 beq @L9 ; Return zero if no font
61 adc #<(TGI_VECTORFONT::WIDTHS - TGI_VF_FIRSTCHAR)
64 adc #>(TGI_VECTORFONT::WIDTHS - TGI_VF_FIRSTCHAR)
69 sty Width+1 ; Zero the total width
71 ; Sum up the widths of the single characters
74 lda (Text),y ; Get next char
75 beq @L4 ; Bail out if end of text reached
76 jsr _toascii ; Convert to ascii
78 lda (WTab),y ; Get width of this char
89 ; We have the total width now, scale and return it
91 @L4: lda _tgi_textscalew
95 ; Exit point if no font installed