diff options
Diffstat (limited to 'src/ui/text.c')
-rw-r--r-- | src/ui/text.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/ui/text.c b/src/ui/text.c index c8e8c787..800ebc14 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -274,7 +274,7 @@ static const iGlyph *glyph_Font_(iFont *d, iChar ch) { | |||
274 | return glyph; | 274 | return glyph; |
275 | } | 275 | } |
276 | 276 | ||
277 | enum iRunMode { measure_RunMode, draw_RunMode, drawPermanentColor_RunMode }; | 277 | enum iRunMode { measure_RunMode, measureNoWrap_RunMode, draw_RunMode, drawPermanentColor_RunMode }; |
278 | 278 | ||
279 | static iChar nextChar_(const char **chPos, const char *end) { | 279 | static iChar nextChar_(const char **chPos, const char *end) { |
280 | if (*chPos == end) { | 280 | if (*chPos == end) { |
@@ -298,7 +298,7 @@ static iInt2 run_Font_(iFont *d, enum iRunMode mode, iRangecc text, size_t maxLe | |||
298 | const iInt2 orig = pos; | 298 | const iInt2 orig = pos; |
299 | float xpos = pos.x; | 299 | float xpos = pos.x; |
300 | float xposMax = xpos; | 300 | float xposMax = xpos; |
301 | iAssert(xposLimit == 0 || mode == measure_RunMode); | 301 | iAssert(xposLimit == 0 || mode == measure_RunMode || mode == measureNoWrap_RunMode); |
302 | const char *lastWordEnd = text.start; | 302 | const char *lastWordEnd = text.start; |
303 | if (continueFrom_out) { | 303 | if (continueFrom_out) { |
304 | *continueFrom_out = text.end; | 304 | *continueFrom_out = text.end; |
@@ -338,19 +338,18 @@ static iInt2 run_Font_(iFont *d, enum iRunMode mode, iRangecc text, size_t maxLe | |||
338 | continue; | 338 | continue; |
339 | } | 339 | } |
340 | } | 340 | } |
341 | /* TODO: Remember the glyph's font, no need to look it up constantly. */ | ||
342 | const iGlyph *glyph = glyph_Font_(d, ch); | 341 | const iGlyph *glyph = glyph_Font_(d, ch); |
343 | int x1 = xpos; | 342 | int x1 = xpos; |
344 | const int hoff = enableHalfPixelGlyphs_Text ? (xpos - x1 > 0.5f ? 1 : 0) : 0; | 343 | const int hoff = enableHalfPixelGlyphs_Text ? (xpos - x1 > 0.5f ? 1 : 0) : 0; |
345 | int x2 = x1 + glyph->rect[hoff].size.x; | 344 | int x2 = x1 + glyph->rect[hoff].size.x; |
345 | /* Out of the allotted space? */ | ||
346 | if (xposLimit > 0 && x2 > xposLimit) { | 346 | if (xposLimit > 0 && x2 > xposLimit) { |
347 | /* Out of space. */ | ||
348 | *continueFrom_out = lastWordEnd; | 347 | *continueFrom_out = lastWordEnd; |
349 | break; | 348 | break; |
350 | } | 349 | } |
351 | size.x = iMax(size.x, x2 - orig.x); | 350 | size.x = iMax(size.x, x2 - orig.x); |
352 | size.y = iMax(size.y, pos.y + glyph->font->height - orig.y); | 351 | size.y = iMax(size.y, pos.y + glyph->font->height - orig.y); |
353 | if (mode != measure_RunMode) { | 352 | if (mode != measure_RunMode && mode != measureNoWrap_RunMode) { |
354 | SDL_Rect dst = { x1 + glyph->d[hoff].x, | 353 | SDL_Rect dst = { x1 + glyph->d[hoff].x, |
355 | pos.y + glyph->font->baseline + glyph->d[hoff].y, | 354 | pos.y + glyph->font->baseline + glyph->d[hoff].y, |
356 | glyph->rect[hoff].size.x, | 355 | glyph->rect[hoff].size.x, |
@@ -359,7 +358,7 @@ static iInt2 run_Font_(iFont *d, enum iRunMode mode, iRangecc text, size_t maxLe | |||
359 | } | 358 | } |
360 | xpos += glyph->advance; | 359 | xpos += glyph->advance; |
361 | xposMax = iMax(xposMax, xpos); | 360 | xposMax = iMax(xposMax, xpos); |
362 | if (!isSpace_Char(prevCh) && isSpace_Char(ch)) { | 361 | if (mode == measureNoWrap_RunMode || (!isSpace_Char(prevCh) && isSpace_Char(ch))) { |
363 | lastWordEnd = chPos; | 362 | lastWordEnd = chPos; |
364 | } | 363 | } |
365 | /* Check the next character. */ | 364 | /* Check the next character. */ |
@@ -418,7 +417,7 @@ iInt2 advanceRange_Text(int fontId, iRangecc text) { | |||
418 | return init_I2(advance, height); | 417 | return init_I2(advance, height); |
419 | } | 418 | } |
420 | 419 | ||
421 | iInt2 tryAdvanceRange_Text(int fontId, iRangecc text, int width, const char **endPos) { | 420 | iInt2 tryAdvance_Text(int fontId, iRangecc text, int width, const char **endPos) { |
422 | int advance; | 421 | int advance; |
423 | const int height = run_Font_(&text_.fonts[fontId], | 422 | const int height = run_Font_(&text_.fonts[fontId], |
424 | measure_RunMode, | 423 | measure_RunMode, |
@@ -432,6 +431,20 @@ iInt2 tryAdvanceRange_Text(int fontId, iRangecc text, int width, const char **en | |||
432 | return init_I2(advance, height); | 431 | return init_I2(advance, height); |
433 | } | 432 | } |
434 | 433 | ||
434 | iInt2 tryAdvanceNoWrap_Text(int fontId, iRangecc text, int width, const char **endPos) { | ||
435 | int advance; | ||
436 | const int height = run_Font_(&text_.fonts[fontId], | ||
437 | measureNoWrap_RunMode, | ||
438 | text, | ||
439 | iInvalidSize, | ||
440 | zero_I2(), | ||
441 | width, | ||
442 | endPos, | ||
443 | &advance) | ||
444 | .y; | ||
445 | return init_I2(advance, height); | ||
446 | } | ||
447 | |||
435 | iInt2 advance_Text(int fontId, const char *text) { | 448 | iInt2 advance_Text(int fontId, const char *text) { |
436 | return advanceRange_Text(fontId, range_CStr(text)); | 449 | return advanceRange_Text(fontId, range_CStr(text)); |
437 | } | 450 | } |