21#include <QTextDocument>
22#include <QGuiApplication>
23#include <QAbstractTextDocumentLayout>
36: 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)
50 image = std::make_shared<QImage>(width, height, QImage::Format_RGBA8888_Premultiplied);
51 image->fill(QColor(background_color.c_str()));
55 if (!painter.begin(image.get())) {
60 painter.setBackground(QBrush(background_color.c_str()));
63 QTextDocument text_document;
66 text_document.setUndoRedoEnabled(
false);
69 text_document.setTextWidth(width);
70 text_document.setDefaultStyleSheet(css.c_str());
71 text_document.setHtml(html.c_str());
73 int td_height = text_document.documentLayout()->documentSize().height();
76 painter.translate(x_offset, y_offset);
78 painter.translate(x_offset, (height - td_height) / 2 + y_offset);
80 painter.translate(x_offset, height - td_height + y_offset);
84 text_document.setDefaultTextOption(QTextOption(Qt::AlignLeft));
86 text_document.setDefaultTextOption(QTextOption(Qt::AlignHCenter));
88 text_document.setDefaultTextOption(QTextOption(Qt::AlignRight));
92 text_document.drawContents(&painter);
97 info.has_audio =
false;
98 info.has_video =
true;
99 info.has_single_image =
true;
101 info.vcodec =
"QImage";
103 info.height = height;
104 info.pixel_ratio.num = 1;
105 info.pixel_ratio.den = 1;
106 info.duration = 60 * 60 * 1;
109 info.video_timebase.num = 1;
110 info.video_timebase.den = 30;
111 info.video_length = round(
info.duration *
info.fps.ToDouble());
120 info.display_ratio.num = size.
num;
121 info.display_ratio.den = size.
den;
149 const std::lock_guard<std::recursive_mutex> lock(
getFrameMutex);
156 auto image_frame = std::make_shared<Frame>(
157 requested_frame, image->size().width(), image->size().height(),
158 background_color, sample_count,
info.channels);
161 image_frame->AddImage(image);
167 auto image_frame = std::make_shared<Frame>(
168 1, 640, 480, background_color, sample_count,
info.channels);
187 root[
"type"] =
"QtHtmlReader";
188 root[
"width"] = width;
189 root[
"height"] = height;
190 root[
"x_offset"] = x_offset;
191 root[
"y_offset"] = y_offset;
194 root[
"background_color"] = background_color;
195 root[
"gravity"] = gravity;
211 catch (
const std::exception& e)
214 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
225 if (!root[
"width"].isNull())
226 width = root[
"width"].asInt();
227 if (!root[
"height"].isNull())
228 height = root[
"height"].asInt();
229 if (!root[
"x_offset"].isNull())
230 x_offset = root[
"x_offset"].asInt();
231 if (!root[
"y_offset"].isNull())
232 y_offset = root[
"y_offset"].asInt();
233 if (!root[
"html"].isNull())
234 html = root[
"html"].asString();
235 if (!root[
"css"].isNull())
236 css = root[
"css"].asString();
237 if (!root[
"background_color"].isNull())
238 background_color = root[
"background_color"].asString();
239 if (!root[
"gravity"].isNull())
Header file for all Exception classes.
Header file for Frame class.
Header file for QtHtmlReader class.
This class represents a fraction.
int num
Numerator for the fraction.
void Reduce()
Reduce this fraction (i.e. 640/480 = 4/3).
int den
Denominator for the fraction.
int GetSamplesPerFrame(openshot::Fraction fps, int sample_rate, int channels)
Calculate the # of samples per video frame (for the current frame number).
Exception for invalid JSON.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
std::shared_ptr< openshot::Frame > GetFrame(int64_t requested_frame) override
Json::Value JsonValue() const override
Generate Json::Value for this object.
std::string Json() const override
Generate JSON string of this object.
void Close() override
Close Reader.
QtHtmlReader()
Default constructor (blank text).
void Open() override
Open Reader - which is called by the constructor automatically.
void SetJson(const std::string value) override
Load JSON string into this object.
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.
std::recursive_mutex getFrameMutex
Mutex for multiple threads.
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)