diff --git a/include/TextReader.h b/include/TextReader.h index 4cc9345c..7b276f7f 100644 --- a/include/TextReader.h +++ b/include/TextReader.h @@ -96,6 +96,7 @@ namespace openshot double size; string text_color; string background_color; + string text_background_color; std::shared_ptr image; MAGICK_DRAWABLE lines; bool is_open; @@ -116,9 +117,13 @@ namespace openshot /// @param font The font of the text /// @param size The size of the text /// @param text_color The color of the text - /// @param background_color The background color of the text (also supports Transparent) + /// @param background_color The background color of the text frame image (also supports Transparent) TextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, string text, string font, double size, string text_color, string background_color); + /// Draw a box under rendered text using the specified color. + /// @param text_background_color The background color behind the text + void SetTextBackgroundColor(string color); + /// Close Reader void Close(); diff --git a/src/TextReader.cpp b/src/TextReader.cpp index 27038283..2e1aeb6a 100644 --- a/src/TextReader.cpp +++ b/src/TextReader.cpp @@ -51,6 +51,14 @@ TextReader::TextReader(int width, int height, int x_offset, int y_offset, Gravit Close(); } +void TextReader::SetTextBackgroundColor(string color) { + text_background_color = color; + + // Open and Close the reader, to populate it's attributes (such as height, width, etc...) plus the text background color + Open(); + Close(); +} + // Open reader void TextReader::Open() { @@ -103,6 +111,10 @@ void TextReader::Open() lines.push_back(Magick::DrawablePointSize(size)); lines.push_back(Magick::DrawableText(x_offset, y_offset, text)); + if (!text_background_color.empty()) { + lines.push_back(Magick::DrawableTextUnderColor(Magick::Color(text_background_color))); + } + // Draw image image->draw(lines); @@ -196,6 +208,7 @@ Json::Value TextReader::JsonValue() { root["size"] = size; root["text_color"] = text_color; root["background_color"] = background_color; + root["text_background_color"] = text_background_color; root["gravity"] = gravity; // return JsonValue @@ -254,6 +267,8 @@ void TextReader::SetJsonValue(Json::Value root) { text_color = root["text_color"].asString(); if (!root["background_color"].isNull()) background_color = root["background_color"].asString(); + if (!root["text_background_color"].isNull()) + text_background_color = root["text_background_color"].asString(); if (!root["gravity"].isNull()) gravity = (GravityType) root["gravity"].asInt();