-
-
Notifications
You must be signed in to change notification settings - Fork 922
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix text rendering issue where spaces are missing (#3192)
Fix text rendering issue where spaces end up missing. What happens is that if a single paragraph is split into multiple spans, due to having different formatting, for example, the layouting engine will run into an edge case when trying to place the last span. It will: * split it and try to put each word at a time with the preceding space * it will eventually find a word that cannot fit, and return to a partial state * however, the layouting engine then keeps going and try the same element again. that is because there could be more elements, and the engine conflates bits and elements * now the element "starts" at the next word, and suddenly it fits, because a new space is not added. this only happens if the final word is such that it fits by itself but doesn't with the leading space. That is not normally an issue because if it doesn't fit, it will go to the next line and the space becomes unnecessary in that case. But in case we are still trying to populate the same line, we need to make sure we don't "eat up" the space. There could be other similar edge cases where a space could go missing, so I opted to make it explicit whether the initial space should be added or not by adding a parameter to determine if it is the start of a new line or not.
- Loading branch information
1 parent
abd43de
commit 28fd2a0
Showing
7 changed files
with
62 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ grayscale | |
hoverable | ||
hoverables | ||
inactives | ||
layouting | ||
microtask | ||
orientable | ||
platformer | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'package:flame/components.dart'; | ||
import 'package:flame/text.dart'; | ||
import 'package:flame_test/flame_test.dart'; | ||
import 'package:flutter/rendering.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
final _size = Vector2(100, 100); | ||
|
||
void main() { | ||
group('text layouting', () { | ||
testGolden( | ||
'Text is properly laid out across multiple lines', | ||
(game) async { | ||
game.addAll([ | ||
RectangleComponent( | ||
size: _size, | ||
paint: Paint()..color = const Color(0xffcfc6e5), | ||
), | ||
TextElementComponent.fromDocument( | ||
document: DocumentRoot([ | ||
ParagraphNode.group( | ||
['012345', '67 89'].map(PlainTextNode.new).toList(), | ||
), | ||
]), | ||
style: DocumentStyle( | ||
text: InlineTextStyle( | ||
// using DebugTextRenderer, this will make each char 10px wide | ||
fontSize: 10, | ||
), | ||
), | ||
size: _size, | ||
), | ||
]); | ||
}, | ||
goldenFile: '../_goldens/text_layouting_1.png', | ||
size: _size, | ||
); | ||
}); | ||
} |