mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #6353
6353: Fix text rendering over maximum line width with newline r=def- a=Robyt3 When a word is rendered over the maximum line width it should be moved to the next line. However, this was not working correctly if the word ends with a newline instead of a space, because then the text x-advance including this word did not exceed the maximum width, as the newline caused the x-advance to be reset before it can be used. This is fixed by replacing the unused flag `TEXTFLAG_ALLOW_NEWLINE` with the flag `TEXTFLAG_DISALLOW_NEWLINE`, which causes newline characters to be replaced with space characters. This flag is then used when calculating whether the next word fits in the current line. Closes #4541. Before: ![newline old](https://user-images.githubusercontent.com/23437060/220475413-e46c75b2-30f2-4e69-8ca0-91dfeaf9189c.png) After: ![newline new](https://user-images.githubusercontent.com/23437060/220475426-dd29cd73-3298-4a8e-bcb7-b7353667ded3.png) ## Checklist - [X] Tested the change ingame - [X] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test (especially base/) or added coverage to integration test - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
commit
b9a2f62ca9
|
@ -1182,6 +1182,7 @@ public:
|
|||
Compare.m_X = DrawX;
|
||||
Compare.m_Y = DrawY;
|
||||
Compare.m_Flags &= ~TEXTFLAG_RENDER;
|
||||
Compare.m_Flags |= TEXTFLAG_DISALLOW_NEWLINE;
|
||||
Compare.m_LineWidth = -1;
|
||||
TextEx(&Compare, pCurrent, Wlen);
|
||||
|
||||
|
@ -1196,7 +1197,7 @@ public:
|
|||
Cutter.m_X = DrawX;
|
||||
Cutter.m_Y = DrawY;
|
||||
Cutter.m_Flags &= ~TEXTFLAG_RENDER;
|
||||
Cutter.m_Flags |= TEXTFLAG_STOP_AT_END;
|
||||
Cutter.m_Flags |= TEXTFLAG_STOP_AT_END | TEXTFLAG_DISALLOW_NEWLINE;
|
||||
|
||||
TextEx(&Cutter, pCurrent, Wlen);
|
||||
Wlen = Cutter.m_CharCount;
|
||||
|
@ -1221,17 +1222,24 @@ public:
|
|||
{
|
||||
pCursor->m_CharCount += pTmp - pCurrent;
|
||||
pCurrent = pTmp;
|
||||
const int Character = NextCharacter;
|
||||
int Character = NextCharacter;
|
||||
NextCharacter = str_utf8_decode(&pTmp);
|
||||
|
||||
if(Character == '\n')
|
||||
{
|
||||
LastCharGlyphIndex = 0;
|
||||
++CharacterCounter;
|
||||
StartNewLine();
|
||||
if(pCursor->m_MaxLines > 0 && LineCount > pCursor->m_MaxLines)
|
||||
break;
|
||||
continue;
|
||||
if((pCursor->m_Flags & TEXTFLAG_DISALLOW_NEWLINE) == 0)
|
||||
{
|
||||
LastCharGlyphIndex = 0;
|
||||
++CharacterCounter;
|
||||
StartNewLine();
|
||||
if(pCursor->m_MaxLines > 0 && LineCount > pCursor->m_MaxLines)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Character = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
const SFontSizeChar *pChr = GetChar(TextContainer.m_pFont, pSizeData, Character);
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
|
||||
enum
|
||||
{
|
||||
TEXTFLAG_RENDER = 1,
|
||||
TEXTFLAG_ALLOW_NEWLINE = 2,
|
||||
TEXTFLAG_STOP_AT_END = 4,
|
||||
TEXTFLAG_ELLIPSIS_AT_END = 8,
|
||||
TEXTFLAG_RENDER = 1 << 0,
|
||||
TEXTFLAG_DISALLOW_NEWLINE = 1 << 1,
|
||||
TEXTFLAG_STOP_AT_END = 1 << 2,
|
||||
TEXTFLAG_ELLIPSIS_AT_END = 1 << 3,
|
||||
};
|
||||
|
||||
enum ETextAlignment
|
||||
|
|
Loading…
Reference in a new issue