41QtTextReader::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)
49: 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)
57 text_background_color = color;
71 image = std::make_shared<QImage>(width, height, QImage::Format_RGBA8888_Premultiplied);
72 image->fill(QColor(background_color.c_str()));
75 if (!painter.begin(image.get())) {
80 if (!text_background_color.empty()) {
81 painter.setBackgroundMode(Qt::OpaqueMode);
82 painter.setBackground(QBrush(text_background_color.c_str()));
86 painter.setPen(QPen(text_color.c_str()));
89 painter.setFont(font);
96 align_flag = Qt::AlignLeft | Qt::AlignTop;
99 align_flag = Qt::AlignHCenter | Qt::AlignTop;
102 align_flag = Qt::AlignRight | Qt::AlignTop;
105 align_flag = Qt::AlignVCenter | Qt::AlignLeft;
108 align_flag = Qt::AlignCenter;
111 align_flag = Qt::AlignVCenter | Qt::AlignRight;
114 align_flag = Qt::AlignLeft | Qt::AlignBottom;
117 align_flag = Qt::AlignHCenter | Qt::AlignBottom;
120 align_flag = Qt::AlignRight | Qt::AlignBottom;
125 painter.drawText(x_offset, y_offset, width, height, align_flag, text.c_str());
183 auto image_frame = std::make_shared<Frame>(
184 requested_frame, image->size().width(), image->size().height(),
185 background_color, 0, 2);
188 image_frame->AddImage(image);
194 auto image_frame = std::make_shared<Frame>(1, 640, 480, background_color, 0, 2);
214 root[
"type"] =
"QtTextReader";
215 root[
"width"] = width;
216 root[
"height"] = height;
217 root[
"x_offset"] = x_offset;
218 root[
"y_offset"] = y_offset;
220 root[
"font"] = font.toString().toStdString();
221 root[
"text_color"] = text_color;
222 root[
"background_color"] = background_color;
223 root[
"text_background_color"] = text_background_color;
224 root[
"gravity"] = gravity;
240 catch (
const std::exception& e)
243 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
254 if (!root[
"width"].isNull())
255 width = root[
"width"].asInt();
256 if (!root[
"height"].isNull())
257 height = root[
"height"].asInt();
258 if (!root[
"x_offset"].isNull())
259 x_offset = root[
"x_offset"].asInt();
260 if (!root[
"y_offset"].isNull())
261 y_offset = root[
"y_offset"].asInt();
262 if (!root[
"text"].isNull())
263 text = root[
"text"].asString();
264 if (!root[
"font"].isNull())
265 font.fromString(QString::fromStdString(root[
"font"].asString()));
266 if (!root[
"text_color"].isNull())
267 text_color = root[
"text_color"].asString();
268 if (!root[
"background_color"].isNull())
269 background_color = root[
"background_color"].asString();
270 if (!root[
"text_background_color"].isNull())
271 text_background_color = root[
"text_background_color"].asString();
272 if (!root[
"gravity"].isNull())
Header file for all Exception classes.
Header file for QtTextReader class.
This class represents a fraction.
int num
Numerator for the fraction.
double ToDouble() const
Return this fraction as a double (i.e. 1/2 = 0.5)
void Reduce()
Reduce this fraction (i.e. 640/480 = 4/3)
int den
Denominator for the fraction.
Exception for invalid JSON.
void SetJson(const std::string value) override
Load JSON string into this object.
void SetTextBackgroundColor(std::string color)
void Close() override
Close Reader.
std::string Json() const override
Generate JSON string of this object.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
QtTextReader()
Default constructor (blank text)
std::shared_ptr< openshot::Frame > GetFrame(int64_t requested_frame) override
Json::Value JsonValue() const override
Generate Json::Value for this object.
void Open() override
Open Reader - which is called by the constructor automatically.
openshot::ReaderInfo info
Information about the current media file.
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
This namespace is the default namespace for all code in the openshot library.
GravityType
This enumeration determines how clips are aligned to their parent container.
@ GRAVITY_TOP_LEFT
Align clip to the top left of its parent.
@ GRAVITY_LEFT
Align clip to the left of its parent (middle aligned)
@ GRAVITY_TOP_RIGHT
Align clip to the top right of its parent.
@ GRAVITY_RIGHT
Align clip to the right of its parent (middle aligned)
@ GRAVITY_BOTTOM_LEFT
Align clip to the bottom left of its parent.
@ GRAVITY_BOTTOM
Align clip to the bottom center of its parent.
@ GRAVITY_TOP
Align clip to the top center of its parent.
@ GRAVITY_BOTTOM_RIGHT
Align clip to the bottom right of its parent.
@ GRAVITY_CENTER
Align clip to the center of its parent (middle aligned)
const Json::Value stringToJson(const std::string value)
float duration
Length of time (in seconds)
int width
The width of the video (in pixesl)
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3)
int height
The height of the video (in pixels)
int64_t video_length
The number of frames in the video stream.
std::string acodec
The name of the audio codec used to encode / decode the video stream.
std::string vcodec
The name of the video codec used to encode / decode the video stream.
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
bool has_video
Determines if this file has a video stream.
bool has_audio
Determines if this file has an audio stream.
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
int64_t file_size
Size of file (in bytes)