OpenShot Library | libopenshot  0.3.3
Caption.h
Go to the documentation of this file.
1 
9 // Copyright (c) 2008-2019 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #ifndef OPENSHOT_CAPTION_EFFECT_H
14 #define OPENSHOT_CAPTION_EFFECT_H
15 
16 #include <memory>
17 #include <string>
18 #include <vector>
19 #include <QFont>
20 #include <QFontMetrics>
21 #include <QRegularExpression>
22 #include "../Color.h"
23 #include "../EffectBase.h"
24 #include "../Json.h"
25 #include "../KeyFrame.h"
26 
27 
28 
29 namespace openshot
30 {
31 
38 class Caption : public EffectBase
39 {
40 private:
41  std::vector<QRegularExpressionMatch> matchedCaptions;
42  std::string caption_text;
43  QFontMetrics* metrics;
44  QFont* font;
45  bool is_dirty;
46 
48  void init_effect_details();
49 
51  void process_regex();
52 
53 
54 public:
70  std::string font_name;
71 
73  Caption();
74 
78  Caption(std::string captions);
79 
86  std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number) override { return GetFrame(std::make_shared<openshot::Frame>(), frame_number); }
87 
97  std::shared_ptr<openshot::Frame> GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number) override;
98 
99  // Get and Set caption data
100  std::string CaptionText();
101  void CaptionText(std::string new_caption_text);
102 
103  // Get and Set JSON methods
104  std::string Json() const override;
105  void SetJson(const std::string value) override;
106  Json::Value JsonValue() const override;
107  void SetJsonValue(const Json::Value root) override;
108 
111  std::string PropertiesJSON(int64_t requested_frame) const override;
112 };
113 
114 } // namespace openshot
115 
116 #endif // OPENSHOT_CAPTION_EFFECT_H
openshot::EffectBase
This abstract class is the base class, used by all effects in libopenshot.
Definition: EffectBase.h:53
openshot::Caption::stroke_width
Keyframe stroke_width
Width of text border / stroke.
Definition: Caption.h:61
openshot::Caption::GetFrame
std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number) override
This method is required for all derived classes of ClipBase, and returns a new openshot::Frame object...
Definition: Caption.h:86
openshot::Caption::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: Caption.cpp:363
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
openshot::Caption::fade_in
Keyframe fade_in
Fade in per caption (# of seconds)
Definition: Caption.h:68
openshot::Caption::stroke
Color stroke
Color of text border / stroke.
Definition: Caption.h:56
openshot::Caption::Caption
Caption()
Blank constructor, useful when using Json to load the effect properties.
Definition: Caption.cpp:30
openshot::Caption::background_corner
Keyframe background_corner
Background cornder radius.
Definition: Caption.h:59
openshot::Caption::left
Keyframe left
Size of left bar.
Definition: Caption.h:65
openshot::Caption::top
Keyframe top
Size of top bar.
Definition: Caption.h:66
openshot::Caption::font_name
std::string font_name
Font string.
Definition: Caption.h:70
openshot::Caption
This class adds captions/text over a video, based on timestamps. You can also animate some limited as...
Definition: Caption.h:38
openshot::Color
This class represents a color (used on the timeline and clips)
Definition: Color.h:27
openshot::Caption::SetJson
void SetJson(const std::string value) override
Load JSON string into this object.
Definition: Caption.cpp:391
openshot::Caption::background_padding
Keyframe background_padding
Background padding.
Definition: Caption.h:60
openshot::Keyframe
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition: KeyFrame.h:53
openshot::Caption::right
Keyframe right
Size of right bar.
Definition: Caption.h:67
openshot::Caption::fade_out
Keyframe fade_out
Fade in per caption (# of seconds)
Definition: Caption.h:69
openshot::Caption::color
Color color
Color of caption text.
Definition: Caption.h:55
openshot::Caption::background
Color background
Color of caption area background.
Definition: Caption.h:57
openshot::Caption::PropertiesJSON
std::string PropertiesJSON(int64_t requested_frame) const override
Definition: Caption.cpp:454
openshot::Caption::Json
std::string Json() const override
Generate JSON string of this object.
Definition: Caption.cpp:356
openshot::Caption::SetJsonValue
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: Caption.cpp:408
openshot::Caption::font_size
Keyframe font_size
Font size in points.
Definition: Caption.h:62
openshot::Caption::line_spacing
Keyframe line_spacing
Distance between lines (1.0 default / 100%)
Definition: Caption.h:64
openshot::Caption::background_alpha
Keyframe background_alpha
Background color alpha.
Definition: Caption.h:58
openshot::Caption::font_alpha
Keyframe font_alpha
Font color alpha.
Definition: Caption.h:63
openshot::Caption::CaptionText
std::string CaptionText()
Set the caption string to use (see VTT format)
Definition: Caption.cpp:69