OpenShot Library | libopenshot
0.2.5
|
Go to the documentation of this file.
33 #include "../include/QtHtmlReader.h"
36 #include <QTextDocument>
37 #include <QGuiApplication>
38 #include <QAbstractTextDocumentLayout>
51 : width(width), height(height), x_offset(x_offset), y_offset(y_offset), gravity(gravity), html(html), css(css), background_color(background_color), is_open(false)
65 image = std::shared_ptr<QImage>(
new QImage(width, height, QImage::Format_RGBA8888));
66 image->fill(QColor(background_color.c_str()));
70 if (!painter.begin(image.get())) {
75 painter.setBackground(QBrush(background_color.c_str()));
78 QTextDocument text_document;
81 text_document.setUndoRedoEnabled(
false);
84 text_document.setTextWidth(width);
85 text_document.setDefaultStyleSheet(css.c_str());
86 text_document.setHtml(html.c_str());
88 int td_height = text_document.documentLayout()->documentSize().height();
91 painter.translate(x_offset, y_offset);
93 painter.translate(x_offset, (height - td_height) / 2 + y_offset);
95 painter.translate(x_offset, height - td_height + y_offset);
99 text_document.setDefaultTextOption(QTextOption(Qt::AlignLeft));
101 text_document.setDefaultTextOption(QTextOption(Qt::AlignHCenter));
103 text_document.setDefaultTextOption(QTextOption(Qt::AlignRight));
107 text_document.drawContents(&painter);
165 std::shared_ptr<Frame> image_frame(
new Frame(requested_frame, image->size().width(), image->size().height(), background_color, 0, 2));
174 std::shared_ptr<Frame> image_frame(
new Frame(1, 640, 480, background_color, 0, 2));
194 root[
"type"] =
"QtHtmlReader";
195 root[
"width"] = width;
196 root[
"height"] = height;
197 root[
"x_offset"] = x_offset;
198 root[
"y_offset"] = y_offset;
201 root[
"background_color"] = background_color;
202 root[
"gravity"] = gravity;
218 catch (
const std::exception& e)
221 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
232 if (!root[
"width"].isNull())
233 width = root[
"width"].asInt();
234 if (!root[
"height"].isNull())
235 height = root[
"height"].asInt();
236 if (!root[
"x_offset"].isNull())
237 x_offset = root[
"x_offset"].asInt();
238 if (!root[
"y_offset"].isNull())
239 y_offset = root[
"y_offset"].asInt();
240 if (!root[
"html"].isNull())
241 html = root[
"html"].asString();
242 if (!root[
"css"].isNull())
243 css = root[
"css"].asString();
244 if (!root[
"background_color"].isNull())
245 background_color = root[
"background_color"].asString();
246 if (!root[
"gravity"].isNull())
const Json::Value stringToJson(const std::string value)
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
This namespace is the default namespace for all code in the openshot library.
This class represents a fraction.
openshot::ReaderInfo info
Information about the current media file.
std::shared_ptr< openshot::Frame > GetFrame(int64_t requested_frame)
@ GRAVITY_TOP_LEFT
Align clip to the top left of its parent.
@ GRAVITY_TOP_RIGHT
Align clip to the top right of its parent.
GravityType
This enumeration determines how clips are aligned to their parent container.
float duration
Length of time (in seconds)
This class represents a single frame of video (i.e. image & audio data)
bool has_video
Determines if this file has a video stream.
int width
The width of the video (in pixesl)
@ GRAVITY_RIGHT
Align clip to the right of its parent (middle aligned)
@ GRAVITY_TOP
Align clip to the top center of its parent.
int64_t video_length
The number of frames in the video stream.
int height
The height of the video (in pixels)
int num
Numerator for the fraction.
int den
Denominator for the fraction.
void Reduce()
Reduce this fraction (i.e. 640/480 = 4/3)
@ GRAVITY_BOTTOM
Align clip to the bottom center of its parent.
bool has_audio
Determines if this file has an audio stream.
Exception for invalid JSON.
void SetJson(const std::string value)
Load JSON string into this object.
int64_t file_size
Size of file (in bytes)
void AddImage(int new_width, int new_height, int bytes_per_pixel, QImage::Format type, const unsigned char *pixels_)
Add (or replace) pixel data to the frame.
Json::Value JsonValue() const override
Generate Json::Value for this object.
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
QtHtmlReader()
Default constructor (blank text)
@ GRAVITY_BOTTOM_LEFT
Align clip to the bottom left of its parent.
std::string vcodec
The name of the video codec used to encode / decode the video stream.
@ GRAVITY_BOTTOM_RIGHT
Align clip to the bottom right of its parent.
@ GRAVITY_LEFT
Align clip to the left of its parent (middle aligned)
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
double ToDouble()
Return this fraction as a double (i.e. 1/2 = 0.5)
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
std::string Json() const override
Get and Set JSON methods.
void Open()
Open Reader - which is called by the constructor automatically.
void Close()
Close Reader.
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
@ GRAVITY_CENTER
Align clip to the center of its parent (middle aligned)
std::string acodec
The name of the audio codec used to encode / decode the video stream.
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3)