Skip to content

Commit f11acef

Browse files
authored
Merge pull request #180 from jeffski/text-background-box
Add a text background colored box option to the text reader
2 parents 16bb22c + dac2c9a commit f11acef

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

include/TextReader.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ namespace openshot
9696
double size;
9797
string text_color;
9898
string background_color;
99+
string text_background_color;
99100
std::shared_ptr<Magick::Image> image;
100101
MAGICK_DRAWABLE lines;
101102
bool is_open;
@@ -116,9 +117,13 @@ namespace openshot
116117
/// @param font The font of the text
117118
/// @param size The size of the text
118119
/// @param text_color The color of the text
119-
/// @param background_color The background color of the text (also supports Transparent)
120+
/// @param background_color The background color of the text frame image (also supports Transparent)
120121
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);
121122

123+
/// Draw a box under rendered text using the specified color.
124+
/// @param text_background_color The background color behind the text
125+
void SetTextBackgroundColor(string color);
126+
122127
/// Close Reader
123128
void Close();
124129

src/TextReader.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ TextReader::TextReader(int width, int height, int x_offset, int y_offset, Gravit
5151
Close();
5252
}
5353

54+
void TextReader::SetTextBackgroundColor(string color) {
55+
text_background_color = color;
56+
57+
// Open and Close the reader, to populate it's attributes (such as height, width, etc...) plus the text background color
58+
Open();
59+
Close();
60+
}
61+
5462
// Open reader
5563
void TextReader::Open()
5664
{
@@ -103,6 +111,10 @@ void TextReader::Open()
103111
lines.push_back(Magick::DrawablePointSize(size));
104112
lines.push_back(Magick::DrawableText(x_offset, y_offset, text));
105113

114+
if (!text_background_color.empty()) {
115+
lines.push_back(Magick::DrawableTextUnderColor(Magick::Color(text_background_color)));
116+
}
117+
106118
// Draw image
107119
image->draw(lines);
108120

@@ -196,6 +208,7 @@ Json::Value TextReader::JsonValue() {
196208
root["size"] = size;
197209
root["text_color"] = text_color;
198210
root["background_color"] = background_color;
211+
root["text_background_color"] = text_background_color;
199212
root["gravity"] = gravity;
200213

201214
// return JsonValue
@@ -254,6 +267,8 @@ void TextReader::SetJsonValue(Json::Value root) {
254267
text_color = root["text_color"].asString();
255268
if (!root["background_color"].isNull())
256269
background_color = root["background_color"].asString();
270+
if (!root["text_background_color"].isNull())
271+
text_background_color = root["text_background_color"].asString();
257272
if (!root["gravity"].isNull())
258273
gravity = (GravityType) root["gravity"].asInt();
259274

0 commit comments

Comments
 (0)