text: keep text confined within text-safe area

This commit is contained in:
itsmattkc
2020-07-07 13:16:41 +10:00
parent 919314cce8
commit cb93b6bfa1
+22 -11
View File
@@ -110,23 +110,34 @@ void TextGenerator::GenerateFrame(FramePtr frame, const GenerateJob& job) const
QTextDocument text_doc; QTextDocument text_doc;
text_doc.setHtml(job.GetValue(text_input_).data().toString()); text_doc.setHtml(job.GetValue(text_input_).data().toString());
text_doc.setTextWidth(frame->video_params().width());
// Align to 80% width because that's considered the "title safe" area
int tenth_of_width = frame->video_params().width() / 10;
text_doc.setTextWidth(tenth_of_width * 8);
// Draw rich text onto image // Draw rich text onto image
QPainter p(&img); QPainter p(&img);
p.scale(1.0 / frame->video_params().divider(), 1.0 / frame->video_params().divider()); p.scale(1.0 / frame->video_params().divider(), 1.0 / frame->video_params().divider());
TextVerticalAlign valign = static_cast<TextVerticalAlign>(job.GetValue(valign_input_).data().toInt()); // Push 10% inwards to compensate for title safe area
if (valign != kVerticalAlignTop) { p.translate(tenth_of_width, 0);
int doc_height = text_doc.size().height();
if (valign == kVerticalAlignCenter) { TextVerticalAlign valign = static_cast<TextVerticalAlign>(job.GetValue(valign_input_).data().toInt());
// Center align int doc_height = text_doc.size().height();
p.translate(0, frame->video_params().height() / 2 - doc_height / 2);
} else { switch (valign) {
// Must be bottom align case kVerticalAlignTop:
p.translate(0, frame->video_params().height() - doc_height); // Push 10% inwards for title safe area
} p.translate(0, frame->video_params().height() / 10);
break;
case kVerticalAlignCenter:
// Center align
p.translate(0, frame->video_params().height() / 2 - doc_height / 2);
break;
case kVerticalAlignBottom:
// Push 10% inwards for title safe area
p.translate(0, frame->video_params().height() - doc_height - frame->video_params().height() / 10);
break;
} }
text_doc.drawContents(&p); text_doc.drawContents(&p);