diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h
index 456b5f1d..01defa8c 100644
--- a/include/QtHtmlReader.h
+++ b/include/QtHtmlReader.h
@@ -67,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
@@ -89,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;
@@ -106,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/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp
index 9bda8a18..d73554cb 100644
--- a/src/QtHtmlReader.cpp
+++ b/src/QtHtmlReader.cpp
@@ -40,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();
@@ -77,6 +77,7 @@ void QtHtmlReader::Open()
//draw text
QTextDocument text_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();
@@ -185,6 +186,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;
@@ -236,10 +238,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/examples/ExampleHtml.cpp b/src/examples/ExampleHtml.cpp
index 0148b6f7..3f466df0 100644
--- a/src/examples/ExampleHtml.cpp
+++ b/src/examples/ExampleHtml.cpp
@@ -45,6 +45,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