Skip to content

Commit dac2c9a

Browse files
committed
Add a text background colored box option to the text reader
1 parent a8f75a5 commit dac2c9a

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
@@ -90,6 +90,7 @@ namespace openshot
9090
double size;
9191
string text_color;
9292
string background_color;
93+
string text_background_color;
9394
std::shared_ptr<Magick::Image> image;
9495
list<Magick::Drawable> lines;
9596
bool is_open;
@@ -110,9 +111,13 @@ namespace openshot
110111
/// @param font The font of the text
111112
/// @param size The size of the text
112113
/// @param text_color The color of the text
113-
/// @param background_color The background color of the text (also supports Transparent)
114+
/// @param background_color The background color of the text frame image (also supports Transparent)
114115
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);
115116

117+
/// Draw a box under rendered text using the specified color.
118+
/// @param text_background_color The background color behind the text
119+
void SetTextBackgroundColor(string color);
120+
116121
/// Close Reader
117122
void Close();
118123

src/TextReader.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ TextReader::TextReader(int width, int height, int x_offset, int y_offset, Gravit
4545
Close();
4646
}
4747

48+
void TextReader::SetTextBackgroundColor(string color) {
49+
text_background_color = color;
50+
51+
// Open and Close the reader, to populate it's attributes (such as height, width, etc...) plus the text background color
52+
Open();
53+
Close();
54+
}
55+
4856
// Open reader
4957
void TextReader::Open()
5058
{
@@ -97,6 +105,10 @@ void TextReader::Open()
97105
lines.push_back(Magick::DrawablePointSize(size));
98106
lines.push_back(Magick::DrawableText(x_offset, y_offset, text));
99107

108+
if (!text_background_color.empty()) {
109+
lines.push_back(Magick::DrawableTextUnderColor(Magick::Color(text_background_color)));
110+
}
111+
100112
// Draw image
101113
image->draw(lines);
102114

@@ -190,6 +202,7 @@ Json::Value TextReader::JsonValue() {
190202
root["size"] = size;
191203
root["text_color"] = text_color;
192204
root["background_color"] = background_color;
205+
root["text_background_color"] = text_background_color;
193206
root["gravity"] = gravity;
194207

195208
// return JsonValue
@@ -244,6 +257,8 @@ void TextReader::SetJsonValue(Json::Value root) {
244257
text_color = root["text_color"].asString();
245258
if (!root["background_color"].isNull())
246259
background_color = root["background_color"].asString();
260+
if (!root["text_background_color"].isNull())
261+
text_background_color = root["text_background_color"].asString();
247262
if (!root["gravity"].isNull())
248263
gravity = (GravityType) root["gravity"].asInt();
249264

0 commit comments

Comments
 (0)