28 #include "../include/TextReader.h"
33 TextReader::TextReader() : width(1024), height(768), x_offset(0), y_offset(0), text(
""), font(
"Arial"), size(10.0), text_color(
"#ffffff"), background_color(
"#000000"), is_open(false), gravity(
GRAVITY_CENTER) {
40 TextReader::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)
41 : width(width), height(height), x_offset(x_offset), y_offset(y_offset), text(text), font(font), size(size), text_color(text_color), background_color(background_color), is_open(false), gravity(gravity)
55 image = std::shared_ptr<Magick::Image>(
new Magick::Image(Magick::Geometry(width,height), Magick::Color(background_color)));
58 image->backgroundColor(Magick::Color(
"none"));
64 lines.push_back(Magick::DrawableGravity(Magick::NorthWestGravity));
67 lines.push_back(Magick::DrawableGravity(Magick::NorthGravity));
70 lines.push_back(Magick::DrawableGravity(Magick::NorthEastGravity));
73 lines.push_back(Magick::DrawableGravity(Magick::WestGravity));
76 lines.push_back(Magick::DrawableGravity(Magick::CenterGravity));
79 lines.push_back(Magick::DrawableGravity(Magick::EastGravity));
82 lines.push_back(Magick::DrawableGravity(Magick::SouthWestGravity));
85 lines.push_back(Magick::DrawableGravity(Magick::SouthGravity));
88 lines.push_back(Magick::DrawableGravity(Magick::SouthEastGravity));
93 lines.push_back(Magick::DrawableStrokeColor(Magick::Color(
"none")));
94 lines.push_back(Magick::DrawableStrokeWidth(0.0));
95 lines.push_back(Magick::DrawableFillColor(text_color));
96 lines.push_back(Magick::DrawableFont(font));
97 lines.push_back(Magick::DrawablePointSize(size));
98 lines.push_back(Magick::DrawableText(x_offset, y_offset, text));
151 std::shared_ptr<Frame> image_frame(
new Frame(requested_frame, image->size().width(), image->size().height(),
"#000000", 0, 2));
154 std::shared_ptr<Magick::Image> copy_image(
new Magick::Image(*image.get()));
155 copy_image->modifyImage();
157 image_frame->AddMagickImage(copy_image);
163 std::shared_ptr<Frame> image_frame(
new Frame(1, 640, 480,
"#000000", 0, 2));
183 root[
"type"] =
"TextReader";
184 root[
"width"] = width;
185 root[
"height"] = height;
186 root[
"x_offset"] = x_offset;
187 root[
"y_offset"] = y_offset;
191 root[
"text_color"] = text_color;
192 root[
"background_color"] = background_color;
193 root[
"gravity"] = gravity;
205 bool success = reader.parse( value, root );
208 throw InvalidJSON(
"JSON could not be parsed (or is invalid)",
"");
218 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)",
"");
229 if (!root[
"width"].isNull())
230 width = root[
"width"].asInt();
231 if (!root[
"height"].isNull())
232 height = root[
"height"].asInt();
233 if (!root[
"x_offset"].isNull())
234 x_offset = root[
"x_offset"].asInt();
235 if (!root[
"y_offset"].isNull())
236 y_offset = root[
"y_offset"].asInt();
237 if (!root[
"text"].isNull())
238 text = root[
"text"].asString();
239 if (!root[
"font"].isNull())
240 font = root[
"font"].asString();
241 if (!root[
"size"].isNull())
242 size = root[
"size"].asDouble();
243 if (!root[
"text_color"].isNull())
244 text_color = root[
"text_color"].asString();
245 if (!root[
"background_color"].isNull())
246 background_color = root[
"background_color"].asString();
247 if (!root[
"gravity"].isNull())