setTextInlineInfo method
Implementation
void setTextInlineInfo(LyricDrawInfo drawInfo, LyricUI ui, String text) {
var linePaint = drawInfo.playingMainTextPainter!;
var metrics = linePaint.computeLineMetrics();
var targetLineHeight = 0.0;
var start = 0;
List<LyricInlineDrawInfo> lineList = [];
metrics.forEach((element) {
//起始偏移量X
var startOffsetX = 0.0;
switch (ui.getLyricTextAligin()) {
case TextAlign.right:
startOffsetX = linePaint.width - element.width;
break;
case TextAlign.center:
startOffsetX = (linePaint.width - element.width) / 2;
break;
default:
break;
}
var offsetX = element.width;
switch (ui.getLyricTextAligin()) {
case TextAlign.right:
offsetX = linePaint.width;
break;
case TextAlign.center:
offsetX = (linePaint.width - element.width) / 2 + element.width;
break;
default:
break;
}
var end = linePaint
.getPositionForOffset(Offset(offsetX, targetLineHeight))
.offset;
var lineText = text.substring(start, end);
LyricsLog.logD("获取行内信息:第${element.lineNumber}行,内容:$lineText");
lineList.add(LyricInlineDrawInfo()
..raw = lineText
..number = element.lineNumber
..width = element.width
..height = element.height
..offset = Offset(startOffsetX, targetLineHeight));
start = end;
targetLineHeight += element.height;
});
drawInfo.inlineDrawList = lineList;
}