OpenShot Library | libopenshot  0.1.9
TextReader.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for TextReader class
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  *
6  * @section LICENSE
7  *
8  * Copyright (c) 2008-2014 OpenShot Studios, LLC
9  * <http://www.openshotstudios.com/>. This file is part of
10  * OpenShot Library (libopenshot), an open-source project dedicated to
11  * delivering high quality video editing and animation solutions to the
12  * world. For more information visit <http://www.openshot.org/>.
13  *
14  * OpenShot Library (libopenshot) is free software: you can redistribute it
15  * and/or modify it under the terms of the GNU Lesser General Public License
16  * as published by the Free Software Foundation, either version 3 of the
17  * License, or (at your option) any later version.
18  *
19  * OpenShot Library (libopenshot) is distributed in the hope that it will be
20  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
26  */
27 
28 #ifndef OPENSHOT_TEXT_READER_H
29 #define OPENSHOT_TEXT_READER_H
30 
31 #include "ReaderBase.h"
32 
33 #include <cmath>
34 #include <ctime>
35 #include <iostream>
36 #include <omp.h>
37 #include <stdio.h>
38 #include <memory>
39 #include "Magick++.h"
40 #include "CacheMemory.h"
41 #include "Enums.h"
42 #include "Exceptions.h"
43 
44 using namespace std;
45 
46 namespace openshot
47 {
48 
49  /**
50  * @brief This class uses the ImageMagick++ libraries, to create frames with "Text", and return
51  * openshot::Frame objects.
52  *
53  * All system fonts are supported, including many different font properties, such as size, color,
54  * alignment, padding, etc...
55  *
56  * @code
57  * // Create a reader to generate an openshot::Frame containing text
58  * TextReader r(720, // width
59  * 480, // height
60  * 5, // x_offset
61  * 5, // y_offset
62  * GRAVITY_CENTER, // gravity
63  * "Check out this Text!", // text
64  * "Arial", // font
65  * 15.0, // size
66  * "#fff000", // text_color
67  * "#000000" // background_color
68  * );
69  * r.Open(); // Open the reader
70  *
71  * // Get frame number 1 from the video (in fact, any frame # you request will return the same frame)
72  * std::shared_ptr<Frame> f = r.GetFrame(1);
73  *
74  * // Now that we have an openshot::Frame object, lets have some fun!
75  * f->Display(); // Display the frame on the screen
76  *
77  * // Close the reader
78  * r.Close();
79  * @endcode
80  */
81  class TextReader : public ReaderBase
82  {
83  private:
84  int width;
85  int height;
86  int x_offset;
87  int y_offset;
88  string text;
89  string font;
90  double size;
91  string text_color;
92  string background_color;
93  std::shared_ptr<Magick::Image> image;
94  list<Magick::Drawable> lines;
95  bool is_open;
96  GravityType gravity;
97 
98  public:
99 
100  /// Default constructor (blank text)
101  TextReader();
102 
103  /// @brief Constructor for TextReader with all parameters.
104  /// @param width The width of the requested openshot::Frame (not the size of the text)
105  /// @param height The height of the requested openshot::Frame (not the size of the text)
106  /// @param x_offset The number of pixels to offset the text on the X axis (horizontal)
107  /// @param y_offset The number of pixels to offset the text on the Y axis (vertical)
108  /// @param gravity The alignment / gravity of the text
109  /// @param text The text you want to generate / display
110  /// @param font The font of the text
111  /// @param size The size of the text
112  /// @param text_color The color of the text
113  /// @param background_color The background color of the text (also supports Transparent)
114  TextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, string text, string font, double size, string text_color, string background_color);
115 
116  /// Close Reader
117  void Close();
118 
119  /// Get the cache object used by this reader (always returns NULL for this object)
120  CacheMemory* GetCache() { return NULL; };
121 
122  /// Get an openshot::Frame object for a specific frame number of this reader. All numbers
123  /// return the same Frame, since they all share the same image data.
124  ///
125  /// @returns The requested frame (containing the image)
126  /// @param requested_frame The frame number that is requested.
127  std::shared_ptr<Frame> GetFrame(int64_t requested_frame);
128 
129  /// Determine if reader is open or closed
130  bool IsOpen() { return is_open; };
131 
132  /// Return the type name of the class
133  string Name() { return "TextReader"; };
134 
135  /// Get and Set JSON methods
136  string Json(); ///< Generate JSON string of this object
137  void SetJson(string value); ///< Load JSON string into this object
138  Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
139  void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
140 
141  /// Open Reader - which is called by the constructor automatically
142  void Open();
143  };
144 
145 }
146 
147 #endif
Header file for ReaderBase class.
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:95
bool IsOpen()
Determine if reader is open or closed.
Definition: TextReader.h:130
Header file for CacheMemory class.
CacheMemory * GetCache()
Get the cache object used by this reader (always returns NULL for this object)
Definition: TextReader.h:120
string Name()
Return the type name of the class.
Definition: TextReader.h:133
Header file for all Exception classes.
Header file for TextReader class.
This namespace is the default namespace for all code in the openshot library.
This class uses the ImageMagick++ libraries, to create frames with "Text", and return openshot::Frame...
Definition: TextReader.h:81
This class is a memory-based cache manager for Frame objects.
Definition: CacheMemory.h:48
GravityType
This enumeration determines how clips are aligned to their parent container.
Definition: Enums.h:35