Skip to content

Commit

Permalink
增加对emoji的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
linwenlong committed Jan 17, 2019
1 parent e972237 commit 2b96b20
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

A new Flutter application.

Aligns Text Vertical from right-top to left bottom.
排版文字从右往左。
Aligns Text Vertical from right-top to left bottom.support emoji.
排版文字从右往左。支持emoji。

Screenshot

Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class _MyHomePageState extends State<MyHomePage> {
height: 200,
child: CustomPaint(
painter: VerticalText(
text: "你好,这是垂直排版的文字,排版顺序从上到下,从右到左。",
text: "你好,这是垂直排版的文字,排版顺序从上到下,从右到左。😊😂😄",
textStyle: TextStyle(
color: Colors.red,
fontSize: 20,
Expand Down
20 changes: 12 additions & 8 deletions lib/vertival_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class VerticalText extends CustomPainter {

maxWidth = findMaxWidth(text, textStyle);

for (int i = 0; i < text.length; i++) {
TextSpan span = new TextSpan(style: textStyle, text: text[i]);
text.runes.forEach((rune) {
String str = new String.fromCharCode(rune);
TextSpan span = new TextSpan(style: textStyle, text: str);
TextPainter tp = new TextPainter(
text: span,
textAlign: TextAlign.center,
Expand All @@ -45,32 +46,35 @@ class VerticalText extends CustomPainter {
}

if (offsetX < -maxWidth) {
break;
return;
}

tp.paint(canvas, new Offset(offsetX, offsetY));
offsetY += tp.height;
}
});
}

double findMaxWidth(String text, TextStyle style) {
double maxWidth = 0;
for (int i = 0; i < text.length; i++) {
TextSpan span = new TextSpan(style: style, text: text[i]);

text.runes.forEach((rune) {
String str = new String.fromCharCode(rune);
TextSpan span = new TextSpan(style: style, text: str);
TextPainter tp = new TextPainter(
text: span,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr);
tp.layout();
maxWidth = max(maxWidth, tp.width);
}
});

return maxWidth;
}

@override
bool shouldRepaint(VerticalText oldDelegate) {
return oldDelegate.text != text ||
oldDelegate.textStyle != textStyle||
oldDelegate.textStyle != textStyle ||
oldDelegate.width != width ||
oldDelegate.height != height;
}
Expand Down
Binary file modified screenshot/screenshot.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2b96b20

Please sign in to comment.