subtitles: implemented very basic renderer

This commit is contained in:
itsmattkc
2022-05-08 14:45:43 -07:00
parent 197f94f8d6
commit bdb917c591
7 changed files with 146 additions and 4 deletions
+36
View File
@@ -79,4 +79,40 @@ QString QtUtils::GetFormattedDateTime(const QDateTime &dt)
return dt.toString(Qt::TextDate);
}
QStringList QtUtils::WordWrapString(const QString &s, const QFontMetrics &fm, int bounding_width)
{
QStringList list;
QStringList lines = s.split('\n');
// Iterate every line
for (int i=0; i<lines.size(); i++) {
QString this_line = lines.at(i);
while (this_line.size() > 1 && QFontMetricsWidth(fm, this_line) >= bounding_width) {
for (int j=this_line.size()-1; j>=0; j--) {
if (this_line.at(j).isSpace()) {
QString chopped = this_line.left(j);
if (QFontMetricsWidth(fm, chopped) < bounding_width) {
list.append(chopped);
int k = j+1;
while (k < this_line.size() && this_line.at(k).isSpace()) {
k++;
}
this_line.remove(0, k);
break;
}
}
}
}
if (!this_line.isEmpty()) {
list.append(this_line);
}
}
return list;
}
}