X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Faxwin2_src%2FWM%2Fvideo_text.c;h=b776424867f3859065aa993176d548ee842fa7ad;hb=242c4abde7ae20df10f0e7b6e3774312c1f26910;hp=5dc462f27608a9ee07755bb0463180042e693b4b;hpb=7758e1bf2e2a1ad35def1eb8cf9aab55d13e05a0;p=tpg%2Facess2.git diff --git a/Usermode/Applications/axwin2_src/WM/video_text.c b/Usermode/Applications/axwin2_src/WM/video_text.c index 5dc462f2..b7764248 100644 --- a/Usermode/Applications/axwin2_src/WM/video_text.c +++ b/Usermode/Applications/axwin2_src/WM/video_text.c @@ -46,11 +46,11 @@ struct sFont { tGlyph *_GetGlyph(tFont *Font, uint32_t Codepoint); void _RenderGlyph(short X, short Y, tGlyph *Glyph, uint32_t Color); tGlyph *_SystemFont_CacheGlyph(tFont *Font, uint32_t Codepoint); - int ReadUTF8(char *Input, uint32_t *Output); + int ReadUTF8(const char *Input, uint32_t *Output); // === GLOBALS === tFont gSystemFont = { - CacheGlyph: _SystemFont_CacheGlyph + .CacheGlyph = _SystemFont_CacheGlyph }; // === CODE === @@ -96,6 +96,27 @@ int Video_DrawText(short X, short Y, short W, short H, tFont *Font, uint32_t Col return xOfs; } +void Video_GetTextDims(tFont *Font, const char *Text, int *W, int *H) +{ + int w=0, h=0; + uint32_t ch; + tGlyph *glyph; + if( !Font ) Font = &gSystemFont; + + while( *Text ) + { + Text += ReadUTF8(Text, &ch); + glyph = _GetGlyph(Font, ch); + if( !glyph ) continue; + + w += glyph->Width; + if( h < glyph->Height ) h = glyph->Height; + } + + if(W) *W = w; + if(H) *H = h; +} + tGlyph *_GetGlyph(tFont *Font, uint32_t Codepoint) { tGlyph *next = NULL, *prev = NULL; @@ -245,6 +266,10 @@ tGlyph *_SystemFont_CacheGlyph(tFont *Font, uint32_t Codepoint) _SysDebug(" index = %i", index); ret = malloc( sizeof(tGlyph) + FONT_WIDTH*FONT_HEIGHT ); + if( !ret ) { + _SysDebug("ERROR: malloc(%i) failed", sizeof(tGlyph) + FONT_WIDTH*FONT_HEIGHT); + return NULL; + } ret->Codepoint = Codepoint; @@ -279,9 +304,9 @@ tGlyph *_SystemFont_CacheGlyph(tFont *Font, uint32_t Codepoint) * \fn int ReadUTF8(char *Input, uint32_t *Val) * \brief Read a UTF-8 character from a string */ -int ReadUTF8(char *Input, uint32_t *Val) +int ReadUTF8(const char *Input, uint32_t *Val) { - uint8_t *str = (uint8_t *)Input; + const uint8_t *str = (const uint8_t *)Input; *Val = 0xFFFD; // Assume invalid character // ASCII