diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h
index ef9ad570..01defa8c 100644
--- a/include/QtHtmlReader.h
+++ b/include/QtHtmlReader.h
@@ -2,6 +2,8 @@
* @file
* @brief Header file for QtHtmlReader class
* @author Jonathan Thomas
+ * @author Sergei Kolesov (jediserg)
+ * @author Jeff Shillitto (jeffski)
*
* @ref License
*/
@@ -55,6 +57,9 @@ namespace openshot
* Supports HTML/CSS subset available via Qt libraries, see: https://doc.qt.io/qt-5/richtext-html-subset.html
*
* @code
+ * // Any application using this class must instantiate either QGuiApplication or QApplication
+ * QApplication a(argc, argv);
+ *
* // Create a reader to generate an openshot::Frame containing text
* QtHtmlReader r(720, // width
* 480, // height
@@ -62,6 +67,7 @@ namespace openshot
* 5, // y_offset
* GRAVITY_CENTER, // gravity
* "Check out this Text!", // html
+ * "b { color: #ff0000 }", // css
* "#000000" // background_color
* );
* r.Open(); // Open the reader
@@ -84,6 +90,7 @@ namespace openshot
int x_offset;
int y_offset;
std::string html;
+ std::string css;
std::string background_color;
std::shared_ptr image;
bool is_open;
@@ -101,7 +108,7 @@ namespace openshot
/// @param gravity The alignment / gravity of the text
/// @param html The html you want to render / display
/// @param background_color The background color of the text (also supports Transparent)
- QtHtmlReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string html, std::string background_color);
+ QtHtmlReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string html, std::string css, std::string background_color);
/// Close Reader
void Close();
diff --git a/include/QtTextReader.h b/include/QtTextReader.h
index 741fe74c..85187afe 100644
--- a/include/QtTextReader.h
+++ b/include/QtTextReader.h
@@ -2,6 +2,8 @@
* @file
* @brief Header file for QtTextReader class
* @author Jonathan Thomas
+ * @author Sergei Kolesov (jediserg)
+ * @author Jeff Shillitto (jeffski)
*
* @ref License
*/
@@ -56,6 +58,9 @@ namespace openshot
* alignment, padding, etc...
*
* @code
+ * // Any application using this class must instantiate either QGuiApplication or QApplication
+ * QApplication a(argc, argv);
+ *
* // Create a reader to generate an openshot::Frame containing text
* QtTextReader r(720, // width
* 480, // height
@@ -64,7 +69,7 @@ namespace openshot
* GRAVITY_CENTER, // gravity
* "Check out this Text!", // text
* "Arial", // font
- * 15.0, // size
+ * 15.0, // font size
* "#fff000", // text_color
* "#000000" // background_color
* );
@@ -89,7 +94,7 @@ namespace openshot
int y_offset;
std::string text;
std::string font;
- double size;
+ double font_size;
std::string text_color;
std::string background_color;
std::shared_ptr image;
@@ -109,10 +114,10 @@ namespace openshot
/// @param gravity The alignment / gravity of the text
/// @param text The text you want to generate / display
/// @param font The font of the text
- /// @param size The size of the text
+ /// @param font_size The size of the text
/// @param text_color The color of the text
/// @param background_color The background color of the text (also supports Transparent)
- QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double size, std::string text_color, std::string background_color);
+ QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double font_size, std::string text_color, std::string background_color);
/// Close Reader
void Close();
diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp
index c81508db..0d71c658 100644
--- a/src/QtHtmlReader.cpp
+++ b/src/QtHtmlReader.cpp
@@ -2,6 +2,8 @@
* @file
* @brief Source file for QtHtmlReader class
* @author Jonathan Thomas
+ * @author Sergei Kolesov (jediserg)
+ * @author Jeff Shillitto (jeffski)
*
* @ref License
*/
@@ -38,15 +40,15 @@
using namespace openshot;
/// Default constructor (blank text)
-QtHtmlReader::QtHtmlReader() : width(1024), height(768), x_offset(0), y_offset(0), html(""), background_color("#000000"), is_open(false), gravity(GRAVITY_CENTER)
+QtHtmlReader::QtHtmlReader() : width(1024), height(768), x_offset(0), y_offset(0), html(""), css(""), background_color("#000000"), is_open(false), gravity(GRAVITY_CENTER)
{
// Open and Close the reader, to populate it's attributes (such as height, width, etc...)
Open();
Close();
}
-QtHtmlReader::QtHtmlReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string html, std::string background_color)
-: width(width), height(height), x_offset(x_offset), y_offset(y_offset), gravity(gravity), html(html), background_color(background_color), is_open(false)
+QtHtmlReader::QtHtmlReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string html, std::string css, std::string background_color)
+: 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)
{
// Open and Close the reader, to populate it's attributes (such as height, width, etc...)
Open();
@@ -74,7 +76,13 @@ void QtHtmlReader::Open()
//draw text
QTextDocument text_document;
+
+ //disable redo/undo stack as not needed
+ text_document.setUndoRedoEnabled(false);
+
+ //create the HTML/CSS document
text_document.setTextWidth(width);
+ text_document.setDefaultStyleSheet(css.c_str());
text_document.setHtml(html.c_str());
int td_height = text_document.documentLayout()->documentSize().height();
@@ -183,6 +191,7 @@ Json::Value QtHtmlReader::JsonValue() {
root["x_offset"] = x_offset;
root["y_offset"] = y_offset;
root["html"] = html;
+ root["css"] = css;
root["background_color"] = background_color;
root["gravity"] = gravity;
@@ -234,10 +243,10 @@ void QtHtmlReader::SetJsonValue(Json::Value root) {
y_offset = root["y_offset"].asInt();
if (!root["html"].isNull())
html = root["html"].asString();
-
+ if (!root["css"].isNull())
+ css = root["css"].asString();
if (!root["background_color"].isNull())
background_color = root["background_color"].asString();
-
if (!root["gravity"].isNull())
gravity = (GravityType) root["gravity"].asInt();
diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp
index 7527894d..4205eb81 100644
--- a/src/QtTextReader.cpp
+++ b/src/QtTextReader.cpp
@@ -2,6 +2,8 @@
* @file
* @brief Source file for QtTextReader class
* @author Jonathan Thomas
+ * @author Sergei Kolesov (jediserg)
+ * @author Jeff Shillitto (jeffski)
*
* @ref License
*/
@@ -35,15 +37,15 @@
using namespace openshot;
/// Default constructor (blank text)
-QtTextReader::QtTextReader() : width(1024), height(768), x_offset(0), y_offset(0), text(""), font("Arial"), size(10.0), text_color("#ffffff"), background_color("#000000"), is_open(false), gravity(GRAVITY_CENTER)
+QtTextReader::QtTextReader() : width(1024), height(768), x_offset(0), y_offset(0), text(""), font("Arial"), font_size(10.0), text_color("#ffffff"), background_color("#000000"), is_open(false), gravity(GRAVITY_CENTER)
{
// Open and Close the reader, to populate it's attributes (such as height, width, etc...)
Open();
Close();
}
-QtTextReader::QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double size, std::string text_color, std::string background_color)
-: width(width), height(height), x_offset(x_offset), y_offset(y_offset), text(text), font(font), size(size), text_color(text_color), background_color(background_color), is_open(false), gravity(gravity)
+QtTextReader::QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double font_size, std::string text_color, std::string background_color)
+: width(width), height(height), x_offset(x_offset), y_offset(y_offset), text(text), font(font), font_size(font_size), text_color(text_color), background_color(background_color), is_open(false), gravity(gravity)
{
// Open and Close the reader, to populate it's attributes (such as height, width, etc...)
Open();
@@ -72,7 +74,7 @@ void QtTextReader::Open()
painter.setPen(QPen(text_color.c_str()));
// set font
- painter.setFont(QFont(font.c_str(), size));
+ painter.setFont(QFont(font.c_str(), font_size));
// Set gravity (map between OpenShot and Qt)
int align_flag = 0;
@@ -129,14 +131,14 @@ void QtTextReader::Open()
info.video_length = round(info.duration * info.fps.ToDouble());
// Calculate the DAR (display aspect ratio)
- Fraction size(info.width * info.pixel_ratio.num, info.height * info.pixel_ratio.den);
+ Fraction font_size(info.width * info.pixel_ratio.num, info.height * info.pixel_ratio.den);
// Reduce size fraction
- size.Reduce();
+ font_size.Reduce();
// Set the ratio based on the reduced fraction
- info.display_ratio.num = size.num;
- info.display_ratio.den = size.den;
+ info.display_ratio.num = font_size.num;
+ info.display_ratio.den = font_size.den;
// Mark as "open"
is_open = true;
@@ -196,7 +198,7 @@ Json::Value QtTextReader::JsonValue() {
root["y_offset"] = y_offset;
root["text"] = text;
root["font"] = font;
- root["size"] = size;
+ root["font_size"] = font_size;
root["text_color"] = text_color;
root["background_color"] = background_color;
root["gravity"] = gravity;
@@ -251,8 +253,8 @@ void QtTextReader::SetJsonValue(Json::Value root) {
text = root["text"].asString();
if (!root["font"].isNull())
font = root["font"].asString();
- if (!root["size"].isNull())
- size = root["size"].asDouble();
+ if (!root["font_size"].isNull())
+ font_size = root["font_size"].asDouble();
if (!root["text_color"].isNull())
text_color = root["text_color"].asString();
if (!root["background_color"].isNull())
diff --git a/src/examples/ExampleHtml.cpp b/src/examples/ExampleHtml.cpp
index feb1f153..155c98b5 100644
--- a/src/examples/ExampleHtml.cpp
+++ b/src/examples/ExampleHtml.cpp
@@ -46,6 +46,7 @@ int main(int argc, char* argv[]) {
5, // y_offset
GRAVITY_CENTER, // gravity
"Check out this Text!", // html
+ "b { color: #ff0000; }",
"#000000" // background_color
);
r.Open(); // Open the reader