37 #include <QTextDocument> 38 #include <QGuiApplication> 39 #include <QAbstractTextDocumentLayout> 52 : 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)
66 image = std::make_shared<QImage>(width, height, QImage::Format_RGBA8888_Premultiplied);
67 image->fill(QColor(background_color.c_str()));
71 if (!painter.begin(image.get())) {
76 painter.setBackground(QBrush(background_color.c_str()));
79 QTextDocument text_document;
82 text_document.setUndoRedoEnabled(
false);
85 text_document.setTextWidth(width);
86 text_document.setDefaultStyleSheet(css.c_str());
87 text_document.setHtml(html.c_str());
89 int td_height = text_document.documentLayout()->documentSize().height();
92 painter.translate(x_offset, y_offset);
94 painter.translate(x_offset, (height - td_height) / 2 + y_offset);
96 painter.translate(x_offset, height - td_height + y_offset);
100 text_document.setDefaultTextOption(QTextOption(Qt::AlignLeft));
102 text_document.setDefaultTextOption(QTextOption(Qt::AlignHCenter));
104 text_document.setDefaultTextOption(QTextOption(Qt::AlignRight));
108 text_document.drawContents(&painter);
166 auto image_frame = std::make_shared<Frame>(
167 requested_frame, image->size().width(), image->size().height(),
168 background_color, 0, 2);
171 image_frame->AddImage(image);
177 auto image_frame = std::make_shared<Frame>(
178 1, 640, 480, background_color, 0, 2);
198 root[
"type"] =
"QtHtmlReader";
199 root[
"width"] = width;
200 root[
"height"] = height;
201 root[
"x_offset"] = x_offset;
202 root[
"y_offset"] = y_offset;
205 root[
"background_color"] = background_color;
206 root[
"gravity"] = gravity;
222 catch (
const std::exception& e)
225 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
236 if (!root[
"width"].isNull())
237 width = root[
"width"].asInt();
238 if (!root[
"height"].isNull())
239 height = root[
"height"].asInt();
240 if (!root[
"x_offset"].isNull())
241 x_offset = root[
"x_offset"].asInt();
242 if (!root[
"y_offset"].isNull())
243 y_offset = root[
"y_offset"].asInt();
244 if (!root[
"html"].isNull())
245 html = root[
"html"].asString();
246 if (!root[
"css"].isNull())
247 css = root[
"css"].asString();
248 if (!root[
"background_color"].isNull())
249 background_color = root[
"background_color"].asString();
250 if (!root[
"gravity"].isNull())
int num
Numerator for the fraction.
Align clip to the right of its parent (middle aligned)
void SetJson(const std::string value) override
Load JSON string into this object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
Align clip to the bottom right of its parent.
int width
The width of the video (in pixesl)
float duration
Length of time (in seconds)
double ToDouble() const
Return this fraction as a double (i.e. 1/2 = 0.5)
Header file for QtHtmlReader class.
const Json::Value stringToJson(const std::string value)
bool has_video
Determines if this file has a video stream.
std::string Json() const override
Generate JSON string of this object.
void Close() override
Close Reader.
int64_t file_size
Size of file (in bytes)
Align clip to the top right of its parent.
Align clip to the bottom left of its parent.
Header file for all Exception classes.
bool has_audio
Determines if this file has an audio stream.
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
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 void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
openshot::ReaderInfo info
Information about the current media file.
QtHtmlReader()
Default constructor (blank text)
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 SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
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) ...
void Open() override
Open Reader - which is called by the constructor automatically.
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square) ...
Align clip to the top center of its parent.
int den
Denominator for the fraction.
std::shared_ptr< openshot::Frame > GetFrame(int64_t requested_frame) override
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.