OpenShot Library | libopenshot 1.1.1
Loading...
Searching...
No Matches
QtTextReader.h
Go to the documentation of this file.
1
11// Copyright (c) 2008-2019 OpenShot Studios, LLC
12//
13// SPDX-License-Identifier: LGPL-3.0-or-later
14
15#ifndef OPENSHOT_QT_TEXT_READER_H
16#define OPENSHOT_QT_TEXT_READER_H
17
18#include "ReaderBase.h"
19
20#include <atomic>
21#include <list>
22#include <memory>
23#include <string>
24#include <utility>
25
26#include "Enums.h"
27
28#include <QFont>
29
30class QImage;
31
32namespace openshot
33{
34 // Forward decls
35 class CacheBase;
36 class Frame;
37
73 class QtTextReader : public ReaderBase
74 {
75 private:
76 // Opt-in document layout keeps existing readers' drawText behavior intact.
77 // These settings round-trip through JSON; sizes are pixels. Style names match
78 // the Caption effect where they mean the same thing (stroke, background_padding,
79 // background_corner, line_spacing). text_animation keyframes only the styles that
80 // keep the image size: color, background, stroke, border, stroke_width,
81 // border_width and background_corner.
82 Json::Value text_animation;
83 Json::Value rendered_style;
84 int64_t render_frame = 1;
85 double render_scale = 1.0;
86 std::atomic<double> detail_scale{1.0};
87 double RasterScale(double& detail);
88 openshot::Fraction source_fps = openshot::Fraction(30, 1);
90 std::list<std::pair<std::string, std::shared_ptr<QImage>>> render_cache;
91 std::shared_ptr<QImage> Render(const Json::Value& style);
92 void UseStyle(const Json::Value& style);
93 void UpdateInfo();
94 Json::Value EvaluateStyle(int64_t frame) const;
95 bool document_layout = false;
96 double background_padding = 12.0;
97 double stroke_width = 0.0;
98 std::string stroke = "#000000";
99 double border_width = 0.0;
100 std::string border = "#ffffff";
101 double letter_spacing = 0.0;
102 double line_spacing = 1.0;
103 double background_corner = 0.0;
104 int width;
105 int height;
106 int x_offset;
107 int y_offset;
108 std::string text;
109 QFont font;
110 std::string text_color;
111 std::string background_color;
112 std::string text_background_color;
113 std::shared_ptr<QImage> image;
114 bool is_open;
115 openshot::GravityType gravity;
116
117 public:
118
120 QtTextReader();
121
132 QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, QFont font, std::string text_color, std::string background_color);
133
136 double DetailScale() const { return detail_scale; }
137
140 void SetTextBackgroundColor(std::string color);
141
143 void Close() override;
144
146 CacheBase* GetCache() override { return NULL; };
147
153 std::shared_ptr<openshot::Frame> GetFrame(int64_t requested_frame) override;
154
156 bool IsOpen() override { return is_open; };
157
159 std::string Name() override { return "QtTextReader"; };
160
161 // Get and Set JSON methods
162 std::string Json() const override;
163 void SetJson(const std::string value) override;
164 Json::Value JsonValue() const override;
165 void SetJsonValue(const Json::Value root) override;
166
168 void Open() override;
169 };
170
171}
172
173#endif
Header file for TextReader class.
Header file for ReaderBase class.
All cache managers in libopenshot are based on this CacheBase class.
Definition CacheBase.h:35
This class represents a fraction.
Definition Fraction.h:30
This class uses Qt libraries, to create frames with "Text", and return openshot::Frame objects.
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.
CacheBase * GetCache() override
Get the cache object used by this reader (always returns NULL for this object)
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
QtTextReader()
Default constructor (blank text)
std::string Name() override
Return the type name of the class.
std::shared_ptr< openshot::Frame > GetFrame(int64_t requested_frame) override
Json::Value JsonValue() const override
Generate Json::Value for this object.
double DetailScale() const
void Open() override
Open Reader - which is called by the constructor automatically.
bool IsOpen() override
Determine if reader is open or closed.
This abstract class is the base class, used by all readers in libopenshot.
Definition ReaderBase.h:76
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.
Definition Enums.h:22