33 #include "../include/QtTextReader.h" 40 QtTextReader::QtTextReader() : width(1024), height(768), x_offset(0), y_offset(0), text(
""), font(QFont(
"Arial", 10)), text_color(
"#ffffff"), background_color(
"#000000"), is_open(false), gravity(
GRAVITY_CENTER)
48 : width(width), height(height), x_offset(x_offset), y_offset(y_offset), text(text), font(font), text_color(text_color), background_color(background_color), is_open(false), gravity(gravity)
56 text_background_color = color;
70 image = std::shared_ptr<QImage>(
new QImage(width, height, QImage::Format_RGBA8888));
71 image->fill(QColor(background_color.c_str()));
74 if (!painter.begin(image.get())) {
79 if (!text_background_color.empty()) {
80 painter.setBackgroundMode(Qt::OpaqueMode);
81 painter.setBackground(QBrush(text_background_color.c_str()));
85 painter.setPen(QPen(text_color.c_str()));
88 painter.setFont(font);
95 align_flag = Qt::AlignLeft | Qt::AlignTop;
98 align_flag = Qt::AlignHCenter | Qt::AlignTop;
101 align_flag = Qt::AlignRight | Qt::AlignTop;
104 align_flag = Qt::AlignVCenter | Qt::AlignLeft;
107 align_flag = Qt::AlignCenter;
110 align_flag = Qt::AlignVCenter | Qt::AlignRight;
113 align_flag = Qt::AlignLeft | Qt::AlignBottom;
116 align_flag = Qt::AlignHCenter | Qt::AlignBottom;
119 align_flag = Qt::AlignRight | Qt::AlignBottom;
124 painter.drawText(x_offset, y_offset, width, height, align_flag, text.c_str());
182 std::shared_ptr<Frame> image_frame(
new Frame(requested_frame, image->size().width(), image->size().height(), background_color, 0, 2));
185 image_frame->AddImage(image);
191 std::shared_ptr<Frame> image_frame(
new Frame(1, 640, 480, background_color, 0, 2));
211 root[
"type"] =
"QtTextReader";
212 root[
"width"] = width;
213 root[
"height"] = height;
214 root[
"x_offset"] = x_offset;
215 root[
"y_offset"] = y_offset;
217 root[
"font"] = font.toString().toStdString();
218 root[
"text_color"] = text_color;
219 root[
"background_color"] = background_color;
220 root[
"text_background_color"] = text_background_color;
221 root[
"gravity"] = gravity;
232 Json::CharReaderBuilder rbuilder;
233 Json::CharReader* reader(rbuilder.newCharReader());
236 bool success = reader->parse( value.c_str(),
237 value.c_str() + value.size(), &root, &errors );
242 throw InvalidJSON(
"JSON could not be parsed (or is invalid)");
249 catch (
const std::exception& e)
252 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
263 if (!root[
"width"].isNull())
264 width = root[
"width"].asInt();
265 if (!root[
"height"].isNull())
266 height = root[
"height"].asInt();
267 if (!root[
"x_offset"].isNull())
268 x_offset = root[
"x_offset"].asInt();
269 if (!root[
"y_offset"].isNull())
270 y_offset = root[
"y_offset"].asInt();
271 if (!root[
"text"].isNull())
272 text = root[
"text"].asString();
273 if (!root[
"font"].isNull())
274 font.fromString(QString::fromStdString(root[
"font"].asString()));
275 if (!root[
"text_color"].isNull())
276 text_color = root[
"text_color"].asString();
277 if (!root[
"background_color"].isNull())
278 background_color = root[
"background_color"].asString();
279 if (!root[
"text_background_color"].isNull())
280 text_background_color = root[
"text_background_color"].asString();
281 if (!root[
"gravity"].isNull())
int num
Numerator for the fraction.
Align clip to the right of its parent (middle aligned)
Align clip to the bottom right of its parent.
int width
The width of the video (in pixesl)
std::string Json()
Get and Set JSON methods.
This class represents a single frame of video (i.e. image & audio data)
void SetTextBackgroundColor(std::string color)
float duration
Length of time (in seconds)
void Close()
Close Reader.
void SetJsonValue(Json::Value root)
Load Json::JsonValue into this object.
bool has_video
Determines if this file has a video stream.
int64_t file_size
Size of file (in bytes)
void SetJson(std::string value)
Load JSON string into this object.
Align clip to the top right of its parent.
Align clip to the bottom left of its parent.
bool has_audio
Determines if this file has an audio stream.
int64_t video_length
The number of frames in the video stream.
int height
The height of the video (in pixels)
Align clip to the bottom center of its parent.
Align clip to the top left of its parent.
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
This class represents a fraction.
Align clip to the left of its parent (middle aligned)
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
virtual void SetJsonValue(Json::Value root)=0
Load Json::JsonValue into this object.
openshot::ReaderInfo info
Information about the current media file.
Align clip to the center of its parent (middle aligned)
std::string vcodec
The name of the video codec used to encode / decode the video stream.
This namespace is the default namespace for all code in the openshot library.
void Open()
Open Reader - which is called by the constructor automatically.
Exception for invalid JSON.
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3) ...
std::shared_ptr< openshot::Frame > GetFrame(int64_t requested_frame)
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square) ...
QtTextReader()
Default constructor (blank text)
Json::Value JsonValue()
Generate Json::JsonValue for this object.
Align clip to the top center of its parent.
int den
Denominator for the fraction.
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
GravityType
This enumeration determines how clips are aligned to their parent container.
std::string acodec
The name of the audio codec used to encode / decode the video stream.
double ToDouble()
Return this fraction as a double (i.e. 1/2 = 0.5)