From c8b5300df3def39db056ea0aef7538d622dc3686 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Fri, 20 Sep 2019 21:25:09 +1000 Subject: [PATCH] Allow font bold and italic properties to be set --- include/QtTextReader.h | 6 +++++- src/QtTextReader.cpp | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/QtTextReader.h b/include/QtTextReader.h index a3fa014c..ee35dc28 100644 --- a/include/QtTextReader.h +++ b/include/QtTextReader.h @@ -95,6 +95,8 @@ namespace openshot std::string text; std::string font; double font_size; + bool is_bold; + bool is_italic; std::string text_color; std::string background_color; std::shared_ptr image; @@ -115,9 +117,11 @@ namespace openshot /// @param text The text you want to generate / display /// @param font The font of the text /// @param font_size The size of the text + /// @param is_bold Set to true to make text bold + /// @param is_italic Set to true to make text italic /// @param text_color The color of the text (valid values are a color string in #RRGGBB or #AARRGGBB notation or a CSS color name) /// @param background_color The background color of the frame image (valid values are a color string in #RRGGBB or #AARRGGBB notation, a CSS color name, or 'transparent') - QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double font_size, std::string text_color, std::string background_color); + QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double font_size, bool is_bold, bool is_italic, std::string text_color, std::string background_color); /// Close Reader void Close(); diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index 0c45ea4e..d56ca1af 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -37,15 +37,15 @@ using namespace openshot; /// Default constructor (blank text) -QtTextReader::QtTextReader() : width(1024), height(768), x_offset(0), y_offset(0), text(""), font("Arial"), font_size(10.0), text_color("#ffffff"), background_color("#000000"), is_open(false), gravity(GRAVITY_CENTER) +QtTextReader::QtTextReader() : width(1024), height(768), x_offset(0), y_offset(0), text(""), font("Arial"), font_size(10.0), is_bold(false), is_italic(false), text_color("#ffffff"), background_color("#000000"), is_open(false), gravity(GRAVITY_CENTER) { // Open and Close the reader, to populate it's attributes (such as height, width, etc...) Open(); Close(); } -QtTextReader::QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double font_size, std::string text_color, std::string background_color) -: width(width), height(height), x_offset(x_offset), y_offset(y_offset), text(text), font(font), font_size(font_size), text_color(text_color), background_color(background_color), is_open(false), gravity(gravity) +QtTextReader::QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double font_size, bool is_bold, bool is_italic, std::string text_color, std::string background_color) +: width(width), height(height), x_offset(x_offset), y_offset(y_offset), text(text), font(font), font_size(font_size), is_bold(is_bold), is_italic(is_italic), text_color(text_color), background_color(background_color), is_open(false), gravity(gravity) { // Open and Close the reader, to populate it's attributes (such as height, width, etc...) Open(); @@ -74,7 +74,10 @@ void QtTextReader::Open() painter.setPen(QPen(text_color.c_str())); // set font - painter.setFont(QFont(font.c_str(), font_size)); + QFont qFont(font.c_str(), font_size); + qFont.setBold(is_bold); + qFont.setItalic(is_italic); + painter.setFont(qFont); // Set gravity (map between OpenShot and Qt) int align_flag = 0;