From dac2c9a58c2ebefed4212ec0e49d072b859dc502 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Sat, 15 Dec 2018 21:55:00 +1100 Subject: [PATCH] Add a text background colored box option to the text reader --- include/TextReader.h | 7 ++++++- src/TextReader.cpp | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/TextReader.h b/include/TextReader.h index d7d653d2..8e0bc18d 100644 --- a/include/TextReader.h +++ b/include/TextReader.h @@ -90,6 +90,7 @@ namespace openshot double size; string text_color; string background_color; + string text_background_color; std::shared_ptr image; list lines; bool is_open; @@ -110,9 +111,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 8234aa5d..245ca6a8 100644 --- a/src/TextReader.cpp +++ b/src/TextReader.cpp @@ -45,6 +45,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() { @@ -97,6 +105,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); @@ -190,6 +202,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 @@ -244,6 +257,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();