diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h
index b3e169b9..ef61e362 100644
--- a/include/QtHtmlReader.h
+++ b/include/QtHtmlReader.h
@@ -5,7 +5,7 @@
*
* @section LICENSE
*
- * Copyright (c) 2008-2014 OpenShot Studios, LLC
+ * Copyright (c) 2008-2019 OpenShot Studios, LLC
* . This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
@@ -48,11 +48,10 @@ namespace openshot
{
/**
- * @brief This class uses the ImageMagick++ libraries, to create frames with "Text", and return
+ * @brief This class uses Qt libraries, to create frames with rendered HTML, and return
* openshot::Frame objects.
*
- * All system fonts are supported, including many different font properties, such as size, color,
- * alignment, padding, etc...
+ * Supports HTML/CSS subset available via Qt libraries, see: https://doc.qt.io/qt-5/richtext-html-subset.html
*
* @code
* // Create a reader to generate an openshot::Frame containing text
@@ -61,10 +60,7 @@ namespace openshot
* 5, // x_offset
* 5, // y_offset
* GRAVITY_CENTER, // gravity
- * "Check out this Text!", // text
- * "Arial", // font
- * 15.0, // size
- * "#fff000", // text_color
+ * "Check out this Text!", // html
* "#000000" // background_color
* );
* r.Open(); // Open the reader
@@ -102,7 +98,7 @@ namespace openshot
/// @param x_offset The number of pixels to offset the text on the X axis (horizontal)
/// @param y_offset The number of pixels to offset the text on the Y axis (vertical)
/// @param gravity The alignment / gravity of the text
- /// @param html The text you want to generate / display
+ /// @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, string html, string background_color);
diff --git a/include/QtTextReader.h b/include/QtTextReader.h
index 60023a87..10886cbf 100644
--- a/include/QtTextReader.h
+++ b/include/QtTextReader.h
@@ -5,7 +5,7 @@
*
* @section LICENSE
*
- * Copyright (c) 2008-2014 OpenShot Studios, LLC
+ * Copyright (c) 2008-2019 OpenShot Studios, LLC
* . This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
@@ -48,7 +48,7 @@ namespace openshot
{
/**
- * @brief This class uses the ImageMagick++ libraries, to create frames with "Text", and return
+ * @brief This class uses Qt libraries, to create frames with "Text", and return
* openshot::Frame objects.
*
* All system fonts are supported, including many different font properties, such as size, color,
diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp
index e5b01cf9..49fed776 100644
--- a/src/QtHtmlReader.cpp
+++ b/src/QtHtmlReader.cpp
@@ -5,7 +5,7 @@
*
* @section LICENSE
*
- * Copyright (c) 2008-2014 OpenShot Studios, LLC
+ * Copyright (c) 2008-2019 OpenShot Studios, LLC
* . This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
@@ -35,8 +35,8 @@
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(""), 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();
@@ -59,10 +59,12 @@ void QtHtmlReader::Open()
// create image
image = std::shared_ptr(new QImage(width, height, QImage::Format_RGBA8888));
image->fill(QColor(background_color.c_str()));
+
//start painting
QPainter painter;
- if(!painter.begin(image.get()))
+ if (!painter.begin(image.get())) {
return;
+ }
//set background
painter.setBackground(QBrush(background_color.c_str()));
@@ -74,22 +76,25 @@ void QtHtmlReader::Open()
int td_height = text_document.documentLayout()->documentSize().height();
- if(gravity == GRAVITY_TOP_LEFT || gravity == GRAVITY_TOP || gravity == GRAVITY_TOP_RIGHT)
+ if (gravity == GRAVITY_TOP_LEFT || gravity == GRAVITY_TOP || gravity == GRAVITY_TOP_RIGHT) {
painter.translate(x_offset, y_offset);
- else if(gravity == GRAVITY_LEFT || gravity == GRAVITY_CENTER || gravity == GRAVITY_RIGHT)
+ } else if (gravity == GRAVITY_LEFT || gravity == GRAVITY_CENTER || gravity == GRAVITY_RIGHT) {
painter.translate(x_offset, (height - td_height) / 2 + y_offset);
- else if(gravity == GRAVITY_BOTTOM_LEFT || gravity == GRAVITY_BOTTOM_RIGHT || gravity == GRAVITY_BOTTOM)
+ } else if (gravity == GRAVITY_BOTTOM_LEFT || gravity == GRAVITY_BOTTOM_RIGHT || gravity == GRAVITY_BOTTOM) {
painter.translate(x_offset, height - td_height + y_offset);
+ }
- if(gravity == GRAVITY_TOP_LEFT || gravity == GRAVITY_LEFT || gravity == GRAVITY_BOTTOM_LEFT)
+ if (gravity == GRAVITY_TOP_LEFT || gravity == GRAVITY_LEFT || gravity == GRAVITY_BOTTOM_LEFT) {
text_document.setDefaultTextOption(QTextOption(Qt::AlignLeft));
- else if(gravity == GRAVITY_CENTER || gravity == GRAVITY_TOP || gravity == GRAVITY_BOTTOM)
+ } else if (gravity == GRAVITY_CENTER || gravity == GRAVITY_TOP || gravity == GRAVITY_BOTTOM) {
text_document.setDefaultTextOption(QTextOption(Qt::AlignHCenter));
- else if(gravity == GRAVITY_TOP_RIGHT || gravity == GRAVITY_RIGHT|| gravity == GRAVITY_BOTTOM_RIGHT)
+ } else if (gravity == GRAVITY_TOP_RIGHT || gravity == GRAVITY_RIGHT|| gravity == GRAVITY_BOTTOM_RIGHT) {
text_document.setDefaultTextOption(QTextOption(Qt::AlignRight));
+ }
+ // Draw image
text_document.drawContents(&painter);
- //end painting
+
painter.end();
// Update image properties
@@ -229,8 +234,6 @@ void QtHtmlReader::SetJsonValue(Json::Value root) {
if (!root["gravity"].isNull())
gravity = (GravityType) root["gravity"].asInt();
-
-
// Re-Open path, and re-init everything (if needed)
if (is_open)
{
diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp
index 0089874a..d078b496 100644
--- a/src/QtTextReader.cpp
+++ b/src/QtTextReader.cpp
@@ -5,7 +5,7 @@
*
* @section LICENSE
*
- * Copyright (c) 2008-2014 OpenShot Studios, LLC
+ * Copyright (c) 2008-2019 OpenShot Studios, LLC
* . This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
@@ -32,8 +32,8 @@
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"), 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();
@@ -56,18 +56,19 @@ void QtTextReader::Open()
// create image
image = std::shared_ptr(new QImage(width, height, QImage::Format_RGBA8888));
image->fill(QColor(background_color.c_str()));
- //start painting
- QPainter painter;
- if(!painter.begin(image.get()))
- return;
- //set background
+ QPainter painter;
+ if (!painter.begin(image.get())) {
+ return;
+ }
+
+ // set background
painter.setBackground(QBrush(background_color.c_str()));
- //set font color
+ // set font color
painter.setPen(QPen(text_color.c_str()));
- //set font
+ // set font
painter.setFont(QFont(font.c_str(), size));
// Set gravity (map between OpenShot and Qt)
@@ -103,10 +104,9 @@ void QtTextReader::Open()
break;
}
- //draw text
+ // Draw image
painter.drawText(x_offset, y_offset, width, height, align_flag, text.c_str());
- //end painting
painter.end();
// Update image properties