From b851508c9f3d53f667f55f4611de0ce41b44e7fd Mon Sep 17 00:00:00 2001 From: jediserg Date: Tue, 25 Jun 2019 03:41:28 -0700 Subject: [PATCH 01/33] --add QtTextWriter (it's based on TextReader and use Qt instead image magick) --- include/QtTextReader.h | 147 +++++++++++++++++++++++ src/CMakeLists.txt | 1 + src/QtTextReader.cpp | 262 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 410 insertions(+) create mode 100644 include/QtTextReader.h create mode 100644 src/QtTextReader.cpp diff --git a/include/QtTextReader.h b/include/QtTextReader.h new file mode 100644 index 000000000..60023a875 --- /dev/null +++ b/include/QtTextReader.h @@ -0,0 +1,147 @@ +/** + * @file + * @brief Header file for QtTextReader class + * @author Jonathan Thomas + * + * @section LICENSE + * + * Copyright (c) 2008-2014 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 + * world. For more information visit . + * + * OpenShot Library (libopenshot) is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * OpenShot Library (libopenshot) is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with OpenShot Library. If not, see . + */ + +#ifndef OPENSHOT_QT_TEXT_READER_H +#define OPENSHOT_QT_TEXT_READER_H + +#include "ReaderBase.h" + +#include +#include +#include +#include +#include +#include +#include "CacheMemory.h" +#include "Enums.h" +#include "Exceptions.h" + +using namespace std; + +class QImage; + +namespace openshot +{ + + /** + * @brief This class uses the ImageMagick++ 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, + * alignment, padding, etc... + * + * @code + * // Create a reader to generate an openshot::Frame containing text + * QtTextReader r(720, // width + * 480, // height + * 5, // x_offset + * 5, // y_offset + * GRAVITY_CENTER, // gravity + * "Check out this Text!", // text + * "Arial", // font + * 15.0, // size + * "#fff000", // text_color + * "#000000" // background_color + * ); + * r.Open(); // Open the reader + * + * // Get frame number 1 from the video (in fact, any frame # you request will return the same frame) + * std::shared_ptr f = r.GetFrame(1); + * + * // Now that we have an openshot::Frame object, lets have some fun! + * f->Display(); // Display the frame on the screen + * + * // Close the reader + * r.Close(); + * @endcode + */ + class QtTextReader : public ReaderBase + { + private: + int width; + int height; + int x_offset; + int y_offset; + string text; + string font; + double size; + string text_color; + string background_color; + std::shared_ptr image; + bool is_open; + GravityType gravity; + + public: + + /// Default constructor (blank text) + QtTextReader(); + + /// @brief Constructor for QtTextReader with all parameters. + /// @param width The width of the requested openshot::Frame (not the size of the text) + /// @param height The height of the requested openshot::Frame (not the size of the text) + /// @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 text The text you want to generate / display + /// @param font The font of the text + /// @param 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, string text, string font, double size, string text_color, string background_color); + + /// Close Reader + void Close(); + + /// Get the cache object used by this reader (always returns NULL for this object) + CacheMemory* GetCache() { return NULL; }; + + /// Get an openshot::Frame object for a specific frame number of this reader. All numbers + /// return the same Frame, since they all share the same image data. + /// + /// @returns The requested frame (containing the image) + /// @param requested_frame The frame number that is requested. + std::shared_ptr GetFrame(int64_t requested_frame); + + /// Determine if reader is open or closed + bool IsOpen() { return is_open; }; + + /// Return the type name of the class + string Name() { return "QtTextReader"; }; + + /// Get and Set JSON methods + string Json(); ///< Generate JSON string of this object + void SetJson(string value); ///< Load JSON string into this object + Json::Value JsonValue(); ///< Generate Json::JsonValue for this object + void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object + + /// Open Reader - which is called by the constructor automatically + void Open(); + }; + +} + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0c4ff990b..7df1b69bf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -215,6 +215,7 @@ SET ( OPENSHOT_SOURCE_FILES QtImageReader.cpp QtPlayer.cpp Timeline.cpp + QtTextReader.cpp # Qt Video Player ${QT_PLAYER_FILES} diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp new file mode 100644 index 000000000..c2c4c0873 --- /dev/null +++ b/src/QtTextReader.cpp @@ -0,0 +1,262 @@ +/** + * @file + * @brief Source file for QtTextReader class + * @author Jonathan Thomas + * + * @section LICENSE + * + * Copyright (c) 2008-2014 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 + * world. For more information visit . + * + * OpenShot Library (libopenshot) is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * OpenShot Library (libopenshot) is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with OpenShot Library. If not, see . + */ + +#include "../include/QtTextReader.h" +#include +#include + +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) { + + // 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, string text, string font, double size, string text_color, 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) +{ + // Open and Close the reader, to populate it's attributes (such as height, width, etc...) + Open(); + Close(); +} + +// Open reader +void QtTextReader::Open() +{ + // Open reader if not already open + if (!is_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 + painter.setBackground(QBrush(background_color.c_str())); + + //set font color + painter.setPen(QPen(text_color.c_str())); + + //set font + painter.setFont(QFont(font.c_str(), size)); + + // Set gravity (map between OpenShot and Qt) + int align_flag = 0; + switch (gravity) + { + case GRAVITY_TOP_LEFT: + align_flag = Qt::AlignLeft | Qt::AlignTop; + break; + case GRAVITY_TOP: + align_flag = Qt::AlignTop; + break; + case GRAVITY_TOP_RIGHT: + align_flag = Qt::AlignRight | Qt::AlignTop; + break; + case GRAVITY_LEFT: + align_flag = Qt::AlignLeft; + break; + case GRAVITY_CENTER: + align_flag = Qt::AlignCenter; + break; + case GRAVITY_RIGHT: + align_flag = Qt::AlignRight; + break; + case GRAVITY_BOTTOM_LEFT: + align_flag = Qt::AlignLeft | Qt::AlignBottom; + break; + case GRAVITY_BOTTOM: + align_flag = Qt::AlignBottom; + break; + case GRAVITY_BOTTOM_RIGHT: + align_flag = Qt::AlignRight | Qt::AlignBottom; + break; + } + + //draw text + painter.drawText(x_offset, y_offset, width, height, align_flag, text.c_str()); + + //end painting + painter.end(); + + // Update image properties + info.has_audio = false; + info.has_video = true; + info.file_size = 0; + info.vcodec = "Constant image uniform color"; + info.width = width; + info.height = height; + info.pixel_ratio.num = 1; + info.pixel_ratio.den = 1; + info.duration = 60 * 60 * 24; // 24 hour duration + info.fps.num = 30; + info.fps.den = 1; + info.video_timebase.num = 1; + info.video_timebase.den = 30; + 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); + + // Reduce size fraction + size.Reduce(); + + // Set the ratio based on the reduced fraction + info.display_ratio.num = size.num; + info.display_ratio.den = size.den; + + // Mark as "open" + is_open = true; + } +} + +// Close reader +void QtTextReader::Close() +{ + // Close all objects, if reader is 'open' + if (is_open) + { + // Mark as "closed" + is_open = false; + } +} + +// Get an openshot::Frame object for a specific frame number of this reader. +std::shared_ptr QtTextReader::GetFrame(int64_t requested_frame) +{ + if (image) + { + // Create or get frame object + std::shared_ptr image_frame(new Frame(requested_frame, image->size().width(), image->size().height(), background_color, 0, 2)); + + // Add Image data to frame + image_frame->AddImage(image); + + // return frame object + return image_frame; + } else { + // return empty frame + std::shared_ptr image_frame(new Frame(1, 640, 480, background_color, 0, 2)); + + // return frame object + return image_frame; + } + +} + +// Generate JSON string of this object +string QtTextReader::Json() { + + // Return formatted string + return JsonValue().toStyledString(); +} + +// Generate Json::JsonValue for this object +Json::Value QtTextReader::JsonValue() { + + // Create root json object + Json::Value root = ReaderBase::JsonValue(); // get parent properties + root["type"] = "QtTextReader"; + root["width"] = width; + root["height"] = height; + root["x_offset"] = x_offset; + root["y_offset"] = y_offset; + root["text"] = text; + root["font"] = font; + root["size"] = size; + root["text_color"] = text_color; + root["background_color"] = background_color; + root["gravity"] = gravity; + + // return JsonValue + return root; +} + +// Load JSON string into this object +void QtTextReader::SetJson(string value) { + + // Parse JSON string into JSON objects + Json::Value root; + Json::Reader reader; + bool success = reader.parse( value, root ); + if (!success) + // Raise exception + throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); + + try + { + // Set all values that match + SetJsonValue(root); + } + catch (exception e) + { + // Error parsing JSON (or missing keys) + throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); + } +} + +// Load Json::JsonValue into this object +void QtTextReader::SetJsonValue(Json::Value root) { + + // Set parent data + ReaderBase::SetJsonValue(root); + + // Set data from Json (if key is found) + if (!root["width"].isNull()) + width = root["width"].asInt(); + if (!root["height"].isNull()) + height = root["height"].asInt(); + if (!root["x_offset"].isNull()) + x_offset = root["x_offset"].asInt(); + if (!root["y_offset"].isNull()) + y_offset = root["y_offset"].asInt(); + if (!root["text"].isNull()) + text = root["text"].asString(); + if (!root["font"].isNull()) + font = root["font"].asString(); + if (!root["size"].isNull()) + size = root["size"].asDouble(); + if (!root["text_color"].isNull()) + text_color = root["text_color"].asString(); + if (!root["background_color"].isNull()) + background_color = root["background_color"].asString(); + if (!root["gravity"].isNull()) + gravity = (GravityType) root["gravity"].asInt(); + + // Re-Open path, and re-init everything (if needed) + if (is_open) + { + Close(); + Open(); + } +} From ac9ea27cce83375241650733fbb61494047937ea Mon Sep 17 00:00:00 2001 From: jediserg Date: Sat, 6 Jul 2019 14:50:50 -0700 Subject: [PATCH 02/33] --add QtHtmlReader --- include/OpenShot.h | 2 + include/QtHtmlReader.h | 143 ++++++++++++++++++++++++++ src/CMakeLists.txt | 1 + src/QtHtmlReader.cpp | 227 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 373 insertions(+) create mode 100644 include/QtHtmlReader.h create mode 100644 src/QtHtmlReader.cpp diff --git a/include/OpenShot.h b/include/OpenShot.h index e4b60f3eb..1fdc0652e 100644 --- a/include/OpenShot.h +++ b/include/OpenShot.h @@ -128,6 +128,8 @@ #include "ImageWriter.h" #include "TextReader.h" #endif +#include "QtTextReader.h" +#include "QtHtmlReader.h" #include "KeyFrame.h" #include "PlayerBase.h" #include "Point.h" diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h new file mode 100644 index 000000000..88b55ad7d --- /dev/null +++ b/include/QtHtmlReader.h @@ -0,0 +1,143 @@ +/** + * @file + * @brief Header file for QtHtmlReader class + * @author Jonathan Thomas + * + * @section LICENSE + * + * Copyright (c) 2008-2014 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 + * world. For more information visit . + * + * OpenShot Library (libopenshot) is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * OpenShot Library (libopenshot) is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with OpenShot Library. If not, see . + */ + +#ifndef OPENSHOT_QT_TEXT_READER_H +#define OPENSHOT_QT_TEXT_READER_H + +#include "ReaderBase.h" + +#include +#include +#include +#include +#include +#include +#include "CacheMemory.h" +#include "Enums.h" +#include "Exceptions.h" + +using namespace std; + +class QImage; + +namespace openshot +{ + + /** + * @brief This class uses the ImageMagick++ 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, + * alignment, padding, etc... + * + * @code + * // Create a reader to generate an openshot::Frame containing text + * QtHtmlReader r(720, // width + * 480, // height + * 5, // x_offset + * 5, // y_offset + * GRAVITY_CENTER, // gravity + * "Check out this Text!", // text + * "Arial", // font + * 15.0, // size + * "#fff000", // text_color + * "#000000" // background_color + * ); + * r.Open(); // Open the reader + * + * // Get frame number 1 from the video (in fact, any frame # you request will return the same frame) + * std::shared_ptr f = r.GetFrame(1); + * + * // Now that we have an openshot::Frame object, lets have some fun! + * f->Display(); // Display the frame on the screen + * + * // Close the reader + * r.Close(); + * @endcode + */ + class QtHtmlReader : public ReaderBase + { + private: + int width; + int height; + int x_offset; + int y_offset; + string html; + string background_color; + std::shared_ptr image; + bool is_open; + GravityType gravity; + public: + + /// Default constructor (blank text) + QtHtmlReader(); + + /// @brief Constructor for QtHtmlReader with all parameters. + /// @param width The width of the requested openshot::Frame (not the size of the text) + /// @param height The height of the requested openshot::Frame (not the size of the text) + /// @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 text The text you want to generate / display + /// @param font The font of the text + /// @param 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) + QtHtmlReader(int width, int height, int x_offset, int y_offset, string html, string background_color); + + /// Close Reader + void Close(); + + /// Get the cache object used by this reader (always returns NULL for this object) + CacheMemory* GetCache() { return NULL; }; + + /// Get an openshot::Frame object for a specific frame number of this reader. All numbers + /// return the same Frame, since they all share the same image data. + /// + /// @returns The requested frame (containing the image) + /// @param requested_frame The frame number that is requested. + std::shared_ptr GetFrame(int64_t requested_frame); + + /// Determine if reader is open or closed + bool IsOpen() { return is_open; }; + + /// Return the type name of the class + string Name() { return "QtHtmlReader"; }; + + /// Get and Set JSON methods + string Json(); ///< Generate JSON string of this object + void SetJson(string value); ///< Load JSON string into this object + Json::Value JsonValue(); ///< Generate Json::JsonValue for this object + void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object + + /// Open Reader - which is called by the constructor automatically + void Open(); + }; + +} + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7df1b69bf..bbad89ee8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -216,6 +216,7 @@ SET ( OPENSHOT_SOURCE_FILES QtPlayer.cpp Timeline.cpp QtTextReader.cpp + QtHtmlReader.cpp # Qt Video Player ${QT_PLAYER_FILES} diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp new file mode 100644 index 000000000..20de04661 --- /dev/null +++ b/src/QtHtmlReader.cpp @@ -0,0 +1,227 @@ +/** + * @file + * @brief Source file for QtHtmlReader class + * @author Jonathan Thomas + * + * @section LICENSE + * + * Copyright (c) 2008-2014 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 + * world. For more information visit . + * + * OpenShot Library (libopenshot) is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * OpenShot Library (libopenshot) is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with OpenShot Library. If not, see . + */ + +#include "../include/QtHtmlReader.h" +#include +#include +#include +#include + +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) { + + // 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, string html, string background_color) +: width(width), height(height), x_offset(x_offset), y_offset(y_offset), html(html), background_color(background_color), is_open(false) +{ + // Open and Close the reader, to populate it's attributes (such as height, width, etc...) + Open(); + Close(); +} + +// Open reader +void QtHtmlReader::Open() +{ + // Open reader if not already open + if (!is_open) + { + /*bool hasGuiApp = (qobject_cast(QCoreApplication::instance())!=0) || (qobject_cast(QCoreApplication::instance())!=0); + if(!hasGuiApp){ + static char appname[] = {"appname"}; + static char* argv[1] = {appname}; + + static int argc = 1; + static QGuiApplication app(argc, argv); + }*/ + // 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 + painter.setBackground(QBrush(background_color.c_str())); + + //draw text + QTextDocument text_document; + text_document.setPageSize(QSizeF(width, height)); + text_document.setHtml(html.c_str()); + painter.translate(x_offset, y_offset); + text_document.drawContents(&painter); + + //end painting + painter.end(); + + // Update image properties + info.has_audio = false; + info.has_video = true; + info.file_size = 0; + info.vcodec = "Constant image uniform color"; + info.width = width; + info.height = height; + info.pixel_ratio.num = 1; + info.pixel_ratio.den = 1; + info.duration = 60 * 60 * 24; // 24 hour duration + info.fps.num = 30; + info.fps.den = 1; + info.video_timebase.num = 1; + info.video_timebase.den = 30; + 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); + + // Reduce size fraction + size.Reduce(); + + // Set the ratio based on the reduced fraction + info.display_ratio.num = size.num; + info.display_ratio.den = size.den; + + // Mark as "open" + is_open = true; + } +} + +// Close reader +void QtHtmlReader::Close() +{ + // Close all objects, if reader is 'open' + if (is_open) + { + // Mark as "closed" + is_open = false; + } +} + +// Get an openshot::Frame object for a specific frame number of this reader. +std::shared_ptr QtHtmlReader::GetFrame(int64_t requested_frame) +{ + if (image) + { + // Create or get frame object + std::shared_ptr image_frame(new Frame(requested_frame, image->size().width(), image->size().height(), background_color, 0, 2)); + + // Add Image data to frame + image_frame->AddImage(image); + + // return frame object + return image_frame; + } else { + // return empty frame + std::shared_ptr image_frame(new Frame(1, 640, 480, background_color, 0, 2)); + + // return frame object + return image_frame; + } + +} + +// Generate JSON string of this object +string QtHtmlReader::Json() { + + // Return formatted string + return JsonValue().toStyledString(); +} + +// Generate Json::JsonValue for this object +Json::Value QtHtmlReader::JsonValue() { + + // Create root json object + Json::Value root = ReaderBase::JsonValue(); // get parent properties + root["type"] = "QtHtmlReader"; + root["width"] = width; + root["height"] = height; + root["x_offset"] = x_offset; + root["y_offset"] = y_offset; + root["html"] = html; + root["background_color"] = background_color; + + // return JsonValue + return root; +} + +// Load JSON string into this object +void QtHtmlReader::SetJson(string value) { + + // Parse JSON string into JSON objects + Json::Value root; + Json::Reader reader; + bool success = reader.parse( value, root ); + if (!success) + // Raise exception + throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); + + try + { + // Set all values that match + SetJsonValue(root); + } + catch (exception e) + { + // Error parsing JSON (or missing keys) + throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); + } +} + +// Load Json::JsonValue into this object +void QtHtmlReader::SetJsonValue(Json::Value root) { + + // Set parent data + ReaderBase::SetJsonValue(root); + + // Set data from Json (if key is found) + if (!root["width"].isNull()) + width = root["width"].asInt(); + if (!root["height"].isNull()) + height = root["height"].asInt(); + if (!root["x_offset"].isNull()) + x_offset = root["x_offset"].asInt(); + if (!root["y_offset"].isNull()) + y_offset = root["y_offset"].asInt(); + if (!root["html"].isNull()) + html = root["html"].asString(); + + if (!root["background_color"].isNull()) + background_color = root["background_color"].asString(); + + + // Re-Open path, and re-init everything (if needed) + if (is_open) + { + Close(); + Open(); + } +} From bf4323f3544b10df9c474e530b393cb1ffb525e2 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Fri, 12 Jul 2019 15:14:38 +1000 Subject: [PATCH 03/33] Fixed missing include and Qt gravity --- include/OpenShot.h | 1 + src/QtTextReader.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/OpenShot.h b/include/OpenShot.h index fb53164c5..fb4f4673b 100644 --- a/include/OpenShot.h +++ b/include/OpenShot.h @@ -136,6 +136,7 @@ #include "Point.h" #include "Profiles.h" #include "QtImageReader.h" +#include "QtTextReader.h" #include "Timeline.h" #include "Settings.h" diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index c2c4c0873..0089874a9 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -78,25 +78,25 @@ void QtTextReader::Open() align_flag = Qt::AlignLeft | Qt::AlignTop; break; case GRAVITY_TOP: - align_flag = Qt::AlignTop; + align_flag = Qt::AlignHCenter | Qt::AlignTop; break; case GRAVITY_TOP_RIGHT: align_flag = Qt::AlignRight | Qt::AlignTop; break; case GRAVITY_LEFT: - align_flag = Qt::AlignLeft; + align_flag = Qt::AlignVCenter | Qt::AlignLeft; break; case GRAVITY_CENTER: align_flag = Qt::AlignCenter; break; case GRAVITY_RIGHT: - align_flag = Qt::AlignRight; + align_flag = Qt::AlignVCenter | Qt::AlignRight; break; case GRAVITY_BOTTOM_LEFT: align_flag = Qt::AlignLeft | Qt::AlignBottom; break; case GRAVITY_BOTTOM: - align_flag = Qt::AlignBottom; + align_flag = Qt::AlignHCenter | Qt::AlignBottom; break; case GRAVITY_BOTTOM_RIGHT: align_flag = Qt::AlignRight | Qt::AlignBottom; From 40521c9d722314f902c54d0d8e588bdc27b36606 Mon Sep 17 00:00:00 2001 From: Sergei Kolesov Date: Mon, 22 Jul 2019 05:52:24 -0700 Subject: [PATCH 04/33] --add gravity to QtHtmlReader --- include/QtHtmlReader.h | 7 ++----- src/QtHtmlReader.cpp | 32 ++++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h index 88b55ad7d..cdf494ce2 100644 --- a/include/QtHtmlReader.h +++ b/include/QtHtmlReader.h @@ -102,12 +102,9 @@ 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 text The text you want to generate / display - /// @param font The font of the text - /// @param size The size of the text - /// @param text_color The color of the text + /// @param html The text you want to generate / display /// @param background_color The background color of the text (also supports Transparent) - QtHtmlReader(int width, int height, int x_offset, int y_offset, string html, string background_color); + QtHtmlReader(int width, int height, int x_offset, int y_offset, GravityType gravity, string html, string background_color); /// Close Reader void Close(); diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index 20de04661..3100e9873 100644 --- a/src/QtHtmlReader.cpp +++ b/src/QtHtmlReader.cpp @@ -34,15 +34,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) { +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(); } -QtHtmlReader::QtHtmlReader(int width, int height, int x_offset, int y_offset, string html, string background_color) -: width(width), height(height), x_offset(x_offset), y_offset(y_offset), html(html), background_color(background_color), is_open(false) +QtHtmlReader::QtHtmlReader(int width, int height, int x_offset, int y_offset, GravityType gravity, string html, 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) { // Open and Close the reader, to populate it's attributes (such as height, width, etc...) Open(); @@ -76,11 +76,26 @@ void QtHtmlReader::Open() //draw text QTextDocument text_document; - text_document.setPageSize(QSizeF(width, height)); + text_document.setTextWidth(width); text_document.setHtml(html.c_str()); - painter.translate(x_offset, y_offset); - text_document.drawContents(&painter); + + int td_height = text_document.documentLayout()->documentSize().height(); + + 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) + painter.translate(x_offset, (height - td_height) / 2 + y_offset); + 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) + text_document.setDefaultTextOption(QTextOption(Qt::AlignLeft)); + 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) + text_document.setDefaultTextOption(QTextOption(Qt::AlignRight)); + text_document.drawContents(&painter); //end painting painter.end(); @@ -168,6 +183,7 @@ Json::Value QtHtmlReader::JsonValue() { root["y_offset"] = y_offset; root["html"] = html; root["background_color"] = background_color; + root["gravity"] = gravity; // return JsonValue return root; @@ -216,6 +232,10 @@ void QtHtmlReader::SetJsonValue(Json::Value root) { if (!root["background_color"].isNull()) background_color = root["background_color"].asString(); + + if (!root["gravity"].isNull()) + gravity = (GravityType) root["gravity"].asInt(); + // Re-Open path, and re-init everything (if needed) From e9ba82dd5b6bc15fd667f02d42a73f17d69dcbd8 Mon Sep 17 00:00:00 2001 From: jediserg Date: Sat, 27 Jul 2019 18:13:45 -0700 Subject: [PATCH 05/33] --add missing include and header guard macro --- include/QtHtmlReader.h | 4 ++-- src/QtHtmlReader.cpp | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h index cdf494ce2..b3e169b91 100644 --- a/include/QtHtmlReader.h +++ b/include/QtHtmlReader.h @@ -25,8 +25,8 @@ * along with OpenShot Library. If not, see . */ -#ifndef OPENSHOT_QT_TEXT_READER_H -#define OPENSHOT_QT_TEXT_READER_H +#ifndef OPENSHOT_QT_HTML_READER_H +#define OPENSHOT_QT_HTML_READER_H #include "ReaderBase.h" diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index 3100e9873..e5b01cf97 100644 --- a/src/QtHtmlReader.cpp +++ b/src/QtHtmlReader.cpp @@ -30,6 +30,7 @@ #include #include #include +#include using namespace openshot; @@ -55,14 +56,6 @@ void QtHtmlReader::Open() // Open reader if not already open if (!is_open) { - /*bool hasGuiApp = (qobject_cast(QCoreApplication::instance())!=0) || (qobject_cast(QCoreApplication::instance())!=0); - if(!hasGuiApp){ - static char appname[] = {"appname"}; - static char* argv[1] = {appname}; - - static int argc = 1; - static QGuiApplication app(argc, argv); - }*/ // create image image = std::shared_ptr(new QImage(width, height, QImage::Format_RGBA8888)); image->fill(QColor(background_color.c_str())); From dbd80926b2437b37c04d2ea4f7c74843310d26fd Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Sun, 11 Aug 2019 22:06:34 +1000 Subject: [PATCH 06/33] General tidy up and code quality, consistency update --- include/QtHtmlReader.h | 14 +++++--------- include/QtTextReader.h | 4 ++-- src/QtHtmlReader.cpp | 29 ++++++++++++++++------------- src/QtTextReader.cpp | 20 ++++++++++---------- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h index b3e169b91..ef61e3622 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 60023a875..10886cbfe 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 e5b01cf97..49fed776f 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 0089874a9..d078b496d 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())) + if (!painter.begin(image.get())) { return; + } - //set background + // 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 From 3681121d81d625e1267708c51152f86cc6d530a0 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Sun, 11 Aug 2019 22:54:49 +1000 Subject: [PATCH 07/33] Remove std namespace usage --- include/QtHtmlReader.h | 20 +++++++++----------- include/QtTextReader.h | 22 ++++++++++------------ src/QtHtmlReader.cpp | 14 +++++++++----- src/QtTextReader.cpp | 14 +++++++++----- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h index ef61e3622..491164cb3 100644 --- a/include/QtHtmlReader.h +++ b/include/QtHtmlReader.h @@ -40,8 +40,6 @@ #include "Enums.h" #include "Exceptions.h" -using namespace std; - class QImage; namespace openshot @@ -82,11 +80,11 @@ namespace openshot int height; int x_offset; int y_offset; - string html; - string background_color; + std::string html; + std::string background_color; std::shared_ptr image; bool is_open; - GravityType gravity; + openshot::GravityType gravity; public: /// Default constructor (blank text) @@ -100,30 +98,30 @@ 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, string html, string background_color); + QtHtmlReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string html, std::string background_color); /// Close Reader void Close(); /// Get the cache object used by this reader (always returns NULL for this object) - CacheMemory* GetCache() { return NULL; }; + openshot::CacheMemory* GetCache() { return NULL; }; /// Get an openshot::Frame object for a specific frame number of this reader. All numbers /// return the same Frame, since they all share the same image data. /// /// @returns The requested frame (containing the image) /// @param requested_frame The frame number that is requested. - std::shared_ptr GetFrame(int64_t requested_frame); + std::shared_ptr GetFrame(int64_t requested_frame); /// Determine if reader is open or closed bool IsOpen() { return is_open; }; /// Return the type name of the class - string Name() { return "QtHtmlReader"; }; + std::string Name() { return "QtHtmlReader"; }; /// Get and Set JSON methods - string Json(); ///< Generate JSON string of this object - void SetJson(string value); ///< Load JSON string into this object + std::string Json(); ///< Generate JSON string of this object + void SetJson(std::string value); ///< Load JSON string into this object Json::Value JsonValue(); ///< Generate Json::JsonValue for this object void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object diff --git a/include/QtTextReader.h b/include/QtTextReader.h index 10886cbfe..3884113e1 100644 --- a/include/QtTextReader.h +++ b/include/QtTextReader.h @@ -40,8 +40,6 @@ #include "Enums.h" #include "Exceptions.h" -using namespace std; - class QImage; namespace openshot @@ -86,14 +84,14 @@ namespace openshot int height; int x_offset; int y_offset; - string text; - string font; + std::string text; + std::string font; double size; - string text_color; - string background_color; + std::string text_color; + std::string background_color; std::shared_ptr image; bool is_open; - GravityType gravity; + openshot::GravityType gravity; public: @@ -111,29 +109,29 @@ namespace openshot /// @param 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, string text, string font, double size, string text_color, string background_color); + 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); /// Close Reader void Close(); /// Get the cache object used by this reader (always returns NULL for this object) - CacheMemory* GetCache() { return NULL; }; + openshot::CacheMemory* GetCache() { return NULL; }; /// Get an openshot::Frame object for a specific frame number of this reader. All numbers /// return the same Frame, since they all share the same image data. /// /// @returns The requested frame (containing the image) /// @param requested_frame The frame number that is requested. - std::shared_ptr GetFrame(int64_t requested_frame); + std::shared_ptr GetFrame(int64_t requested_frame); /// Determine if reader is open or closed bool IsOpen() { return is_open; }; /// Return the type name of the class - string Name() { return "QtTextReader"; }; + std::string Name() { return "QtTextReader"; }; /// Get and Set JSON methods - string Json(); ///< Generate JSON string of this object + std::string Json(); ///< Generate JSON string of this object void SetJson(string value); ///< Load JSON string into this object Json::Value JsonValue(); ///< Generate Json::JsonValue for this object void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index 49fed776f..04dcfe666 100644 --- a/src/QtHtmlReader.cpp +++ b/src/QtHtmlReader.cpp @@ -42,7 +42,7 @@ QtHtmlReader::QtHtmlReader() : width(1024), height(768), x_offset(0), y_offset(0 Close(); } -QtHtmlReader::QtHtmlReader(int width, int height, int x_offset, int y_offset, GravityType gravity, string html, string background_color) +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) { // Open and Close the reader, to populate it's attributes (such as height, width, etc...) @@ -163,7 +163,7 @@ std::shared_ptr QtHtmlReader::GetFrame(int64_t requested_frame) } // Generate JSON string of this object -string QtHtmlReader::Json() { +std::string QtHtmlReader::Json() { // Return formatted string return JsonValue().toStyledString(); @@ -188,12 +188,16 @@ Json::Value QtHtmlReader::JsonValue() { } // Load JSON string into this object -void QtHtmlReader::SetJson(string value) { +void QtHtmlReader::SetJson(std::string value) { // Parse JSON string into JSON objects Json::Value root; - Json::Reader reader; - bool success = reader.parse( value, root ); + Json::CharReaderBuilder rbuilder; + Json::CharReader* reader(rbuilder.newCharReader()); + + std::string errors; + bool success = reader->parse( value.c_str(), + value.c_str() + value.size(), &root, &errors ); if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index d078b496d..3269991e7 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -39,7 +39,7 @@ QtTextReader::QtTextReader() : width(1024), height(768), x_offset(0), y_offset(0 Close(); } -QtTextReader::QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, string text, string font, double size, string text_color, string background_color) +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) { // Open and Close the reader, to populate it's attributes (such as height, width, etc...) @@ -175,7 +175,7 @@ std::shared_ptr QtTextReader::GetFrame(int64_t requested_frame) } // Generate JSON string of this object -string QtTextReader::Json() { +std::string QtTextReader::Json() { // Return formatted string return JsonValue().toStyledString(); @@ -203,12 +203,16 @@ Json::Value QtTextReader::JsonValue() { } // Load JSON string into this object -void QtTextReader::SetJson(string value) { +void QtTextReader::SetJson(std::string value) { // Parse JSON string into JSON objects Json::Value root; - Json::Reader reader; - bool success = reader.parse( value, root ); + Json::CharReaderBuilder rbuilder; + Json::CharReader* reader(rbuilder.newCharReader()); + + std::string errors; + bool success = reader->parse( value.c_str(), + value.c_str() + value.size(), &root, &errors ); if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); From 482ad6b14c66e5c07e5aaffe88a322999c5c0cc2 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Sun, 11 Aug 2019 22:58:15 +1000 Subject: [PATCH 08/33] Tidy and remove duplicate include --- include/OpenShot.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/OpenShot.h b/include/OpenShot.h index 3c9aac9a5..35cba1011 100644 --- a/include/OpenShot.h +++ b/include/OpenShot.h @@ -131,12 +131,11 @@ #include "ImageWriter.h" #include "TextReader.h" #endif -#include "QtTextReader.h" -#include "QtHtmlReader.h" #include "KeyFrame.h" #include "PlayerBase.h" #include "Point.h" #include "Profiles.h" +#include "QtHtmlReader.h" #include "QtImageReader.h" #include "QtTextReader.h" #include "Timeline.h" From b90a83dd4c7b9e747f40307ed75c7de65ce70f1d Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Mon, 12 Aug 2019 09:39:26 -0400 Subject: [PATCH 09/33] Fix documentation-comment formatting, for Doxygen --- include/QtHtmlReader.h | 5 ++++- include/QtTextReader.h | 5 ++++- src/QtHtmlReader.cpp | 5 ++++- src/QtTextReader.cpp | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h index 491164cb3..ef9ad5705 100644 --- a/include/QtHtmlReader.h +++ b/include/QtHtmlReader.h @@ -3,7 +3,10 @@ * @brief Header file for QtHtmlReader class * @author Jonathan Thomas * - * @section LICENSE + * @ref License + */ + +/* LICENSE * * Copyright (c) 2008-2019 OpenShot Studios, LLC * . This file is part of diff --git a/include/QtTextReader.h b/include/QtTextReader.h index 3884113e1..741fe74c2 100644 --- a/include/QtTextReader.h +++ b/include/QtTextReader.h @@ -3,7 +3,10 @@ * @brief Header file for QtTextReader class * @author Jonathan Thomas * - * @section LICENSE + * @ref License + */ + +/* LICENSE * * Copyright (c) 2008-2019 OpenShot Studios, LLC * . This file is part of diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index 04dcfe666..c81508dbd 100644 --- a/src/QtHtmlReader.cpp +++ b/src/QtHtmlReader.cpp @@ -3,7 +3,10 @@ * @brief Source file for QtHtmlReader class * @author Jonathan Thomas * - * @section LICENSE + * @ref License + */ + +/* LICENSE * * Copyright (c) 2008-2019 OpenShot Studios, LLC * . This file is part of diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index 3269991e7..7527894db 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -3,7 +3,10 @@ * @brief Source file for QtTextReader class * @author Jonathan Thomas * - * @section LICENSE + * @ref License + */ + +/* LICENSE * * Copyright (c) 2008-2019 OpenShot Studios, LLC * . This file is part of From 140b5fdad3e0a6bcb3d7c2d58a8478ca5ed8c153 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Mon, 12 Aug 2019 08:58:24 -0400 Subject: [PATCH 10/33] Add src/examples/ExampleHtml.cpp test program --- src/CMakeLists.txt | 5 +- src/examples/ExampleHtml.cpp | 89 ++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/examples/ExampleHtml.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 55a134849..1daacf1bb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -371,13 +371,16 @@ ENDIF(WIN32) target_link_libraries(openshot ${REQUIRED_LIBRARIES}) -############### CLI EXECUTABLE ################ +############### CLI EXECUTABLES ################ # Create test executable add_executable(openshot-example examples/Example.cpp) # Link test executable to the new library target_link_libraries(openshot-example openshot) +add_executable(openshot-html-test examples/ExampleHtml.cpp) +target_link_libraries(openshot-html-test openshot) + ############### PLAYER EXECUTABLE ################ # Create test executable add_executable(openshot-player Qt/demo/main.cpp) diff --git a/src/examples/ExampleHtml.cpp b/src/examples/ExampleHtml.cpp new file mode 100644 index 000000000..0148b6f78 --- /dev/null +++ b/src/examples/ExampleHtml.cpp @@ -0,0 +1,89 @@ +/** + * @file + * @brief Source file for Example Executable (example app for libopenshot) + * @author Jonathan Thomas + * + * @ref License + */ + +/* LICENSE + * + * 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 + * world. For more information visit . + * + * OpenShot Library (libopenshot) is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * OpenShot Library (libopenshot) is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with OpenShot Library. If not, see . + */ + +#include +#include +#include +#include "../../include/OpenShot.h" +//#include "../../include/CrashHandler.h" + +using namespace openshot; + +int main(int argc, char* argv[]) { + + // Create a reader to generate an openshot::Frame containing text + QtHtmlReader r(720, // width + 480, // height + 5, // x_offset + 5, // y_offset + GRAVITY_CENTER, // gravity + "Check out this Text!", // html + "#000000" // background_color + ); + r.Open(); // Open the reader + + // XXX: Not implemented + // r.DisplayInfo(); + + /* WRITER ---------------- */ + FFmpegWriter w9("/var/tmp/metadata.mp4"); + + // Set options + //w9.SetAudioOptions(true, "libmp3lame", r.info.sample_rate, r9.info.channels, r9.info.channel_layout, 128000); + w9.SetVideoOptions(true, "libx264", Fraction{30000, 1000}, 720, 480, Fraction(1,1), false, false, 3000000); + + w9.info.metadata["title"] = "testtest"; + w9.info.metadata["artist"] = "aaa"; + w9.info.metadata["album"] = "bbb"; + w9.info.metadata["year"] = "2015"; + w9.info.metadata["description"] = "ddd"; + w9.info.metadata["comment"] = "eee"; + w9.info.metadata["comment"] = "comment"; + w9.info.metadata["copyright"] = "copyright OpenShot!"; + + // Open writer + w9.Open(); + + for (long int frame = 1; frame <= 30; frame++) + { + std::shared_ptr f = r.GetFrame(1); // Same frame every time + w9.WriteFrame(f); + } + + // Close writer & reader + w9.Close(); + + // Close timeline + r.Close(); + + cout << "Completed successfully!" << endl; + + return 0; +} From b2942f412598bbc2d753b3ea39431bdabe533f40 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Mon, 12 Aug 2019 11:54:13 -0400 Subject: [PATCH 11/33] ExampleHtml.cpp updates --- src/examples/ExampleHtml.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/examples/ExampleHtml.cpp b/src/examples/ExampleHtml.cpp index 0148b6f78..feb1f1536 100644 --- a/src/examples/ExampleHtml.cpp +++ b/src/examples/ExampleHtml.cpp @@ -33,6 +33,7 @@ #include #include "../../include/OpenShot.h" //#include "../../include/CrashHandler.h" +#include using namespace openshot; @@ -49,8 +50,7 @@ int main(int argc, char* argv[]) { ); r.Open(); // Open the reader - // XXX: Not implemented - // r.DisplayInfo(); + r.DisplayInfo(); /* WRITER ---------------- */ FFmpegWriter w9("/var/tmp/metadata.mp4"); From c7457e51d19f8aa231c7dda36653af06c2eee20d Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Mon, 12 Aug 2019 11:55:30 -0400 Subject: [PATCH 12/33] Build example executables correctly --- src/CMakeLists.txt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1daacf1bb..126ea7df4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,8 +6,8 @@ # # 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 +# OpenShot Library (libopenshot), an open-source project dedicated to +# delivering high quality video editing and animation solutions to the # world. For more information visit . # # OpenShot Library (libopenshot) is free software: you can redistribute it @@ -259,7 +259,7 @@ SET ( OPENSHOT_SOURCE_FILES Timeline.cpp QtTextReader.cpp QtHtmlReader.cpp - + # Qt Video Player ${QT_PLAYER_FILES} @@ -309,6 +309,9 @@ set_target_properties(openshot INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib" ) +# Linked executables will need this propagated to them +target_compile_options(openshot PUBLIC ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS} ${Qt5Gui_EXECUTABLE_COMPILE_FLAGS} ${Qt5Multimedia_EXECUTABLE_COMPILE_FLAGS} ${Qt5MultimediaWidgets_EXECUTABLE_COMPILE_FLAGS}) + ############### LINK LIBRARY ################# SET ( REQUIRED_LIBRARIES ${LIBOPENSHOT_AUDIO_LIBRARIES} @@ -379,7 +382,10 @@ add_executable(openshot-example examples/Example.cpp) target_link_libraries(openshot-example openshot) add_executable(openshot-html-test examples/ExampleHtml.cpp) -target_link_libraries(openshot-html-test openshot) +target_link_libraries(openshot-html-test openshot Qt5::Gui) + +add_executable(openshot-text-test examples/ExampleText.cpp) +target_link_libraries(openshot-text-test openshot Qt5::Gui) ############### PLAYER EXECUTABLE ################ # Create test executable From 745225ad6257e6e8fc1f02f2407af717a4a9a497 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Tue, 13 Aug 2019 21:18:55 +1000 Subject: [PATCH 13/33] Rename variable to font_size. Add docs for QApplication --- include/QtHtmlReader.h | 3 +++ include/QtTextReader.h | 11 +++++++---- src/QtTextReader.cpp | 22 +++++++++++----------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h index ef9ad5705..3c6b7528f 100644 --- a/include/QtHtmlReader.h +++ b/include/QtHtmlReader.h @@ -55,6 +55,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 diff --git a/include/QtTextReader.h b/include/QtTextReader.h index 741fe74c2..316825b79 100644 --- a/include/QtTextReader.h +++ b/include/QtTextReader.h @@ -56,6 +56,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 +67,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 +92,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 +112,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/QtTextReader.cpp b/src/QtTextReader.cpp index 7527894db..a287bc435 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -35,15 +35,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 +72,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 +129,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 +196,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 +251,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()) From c8f2c08d344dd402ee55476bf3417c2b97f1a7d5 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Tue, 13 Aug 2019 21:24:42 +1000 Subject: [PATCH 14/33] Add authors to docs --- include/QtHtmlReader.h | 2 ++ include/QtTextReader.h | 2 ++ src/QtHtmlReader.cpp | 2 ++ src/QtTextReader.cpp | 2 ++ 4 files changed, 8 insertions(+) diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h index 3c6b7528f..456b5f1df 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 */ diff --git a/include/QtTextReader.h b/include/QtTextReader.h index 316825b79..85187afed 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 */ diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index c81508dbd..9bda8a188 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 */ diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index a287bc435..4205eb811 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 */ From 78f370ee14eb2f1b78b96dc597b2942f823798ea Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Tue, 13 Aug 2019 22:11:55 +1000 Subject: [PATCH 15/33] Add ability to apply style sheet/css to format HTML --- include/QtHtmlReader.h | 4 +++- src/QtHtmlReader.cpp | 12 +++++++----- src/examples/ExampleHtml.cpp | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h index 456b5f1df..01defa8c4 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 9bda8a188..d73554cb0 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 0148b6f78..3f466df05 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 From ada13ddebd80d135f41be2a7d517ef57004b3356 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Tue, 13 Aug 2019 22:17:49 +1000 Subject: [PATCH 16/33] Disable undo/redo stack --- src/QtHtmlReader.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index d73554cb0..0d71c6585 100644 --- a/src/QtHtmlReader.cpp +++ b/src/QtHtmlReader.cpp @@ -76,6 +76,11 @@ 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()); From 8ab535fc9631de823d7370bae7458c770c8a01d1 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Tue, 13 Aug 2019 17:21:15 -0400 Subject: [PATCH 17/33] Update ExampleHtml.cpp for QGuiApplication --- src/examples/ExampleHtml.cpp | 53 ++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/examples/ExampleHtml.cpp b/src/examples/ExampleHtml.cpp index 155c98b58..96e98e2a8 100644 --- a/src/examples/ExampleHtml.cpp +++ b/src/examples/ExampleHtml.cpp @@ -34,24 +34,28 @@ #include "../../include/OpenShot.h" //#include "../../include/CrashHandler.h" #include +#include using namespace openshot; int main(int argc, char* argv[]) { - // Create a reader to generate an openshot::Frame containing text - QtHtmlReader r(720, // width - 480, // height - 5, // x_offset - 5, // y_offset - GRAVITY_CENTER, // gravity - "Check out this Text!", // html - "b { color: #ff0000; }", - "#000000" // background_color - ); - r.Open(); // Open the reader + QGuiApplication app(argc, argv); - r.DisplayInfo(); + // Create a reader to generate an openshot::Frame containing text + QtHtmlReader r(720, // width + 480, // height + 5, // x_offset + 5, // y_offset + GRAVITY_CENTER, // gravity + "Check out this Text!", // html + "b { color: #ff0000; }", + "#000000" // background_color + ); + + r.Open(); // Open the reader + + r.DisplayInfo(); /* WRITER ---------------- */ FFmpegWriter w9("/var/tmp/metadata.mp4"); @@ -61,30 +65,31 @@ int main(int argc, char* argv[]) { w9.SetVideoOptions(true, "libx264", Fraction{30000, 1000}, 720, 480, Fraction(1,1), false, false, 3000000); w9.info.metadata["title"] = "testtest"; - w9.info.metadata["artist"] = "aaa"; - w9.info.metadata["album"] = "bbb"; - w9.info.metadata["year"] = "2015"; - w9.info.metadata["description"] = "ddd"; - w9.info.metadata["comment"] = "eee"; - w9.info.metadata["comment"] = "comment"; + w9.info.metadata["artist"] = "aaa"; + w9.info.metadata["album"] = "bbb"; + w9.info.metadata["year"] = "2015"; + w9.info.metadata["description"] = "ddd"; + w9.info.metadata["comment"] = "eee"; + w9.info.metadata["comment"] = "comment"; w9.info.metadata["copyright"] = "copyright OpenShot!"; // Open writer w9.Open(); - for (long int frame = 1; frame <= 30; frame++) + for (long int frame = 1; frame <= 30; ++frame) { - std::shared_ptr f = r.GetFrame(1); // Same frame every time + std::shared_ptr f = r.GetFrame(frame); // Same frame every time w9.WriteFrame(f); } // Close writer & reader w9.Close(); - - // Close timeline r.Close(); - cout << "Completed successfully!" << endl; + // Set a timer with 0 timeout to terminate immediately after + // processing events + QTimer::singleShot(0, &app, SLOT(quit())); - return 0; + // Run QGuiApplication to completion + return app.exec(); } From acc27064841ecfc91f06859d2def3eae52c1957f Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Tue, 13 Aug 2019 17:25:20 -0400 Subject: [PATCH 18/33] Remove nonexistent example from cmake build --- src/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 126ea7df4..b24d590ed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -384,9 +384,6 @@ target_link_libraries(openshot-example openshot) add_executable(openshot-html-test examples/ExampleHtml.cpp) target_link_libraries(openshot-html-test openshot Qt5::Gui) -add_executable(openshot-text-test examples/ExampleText.cpp) -target_link_libraries(openshot-text-test openshot Qt5::Gui) - ############### PLAYER EXECUTABLE ################ # Create test executable add_executable(openshot-player Qt/demo/main.cpp) From 3b4580ab7c413a04f9ca53614dbd670e14ff5bd8 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Wed, 14 Aug 2019 22:15:05 +1000 Subject: [PATCH 19/33] Update documentation with css parameter and valid color values --- include/QtHtmlReader.h | 5 +++-- include/QtTextReader.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/QtHtmlReader.h b/include/QtHtmlReader.h index 01defa8c4..ca5f45c44 100644 --- a/include/QtHtmlReader.h +++ b/include/QtHtmlReader.h @@ -106,8 +106,9 @@ 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 html you want to render / display - /// @param background_color The background color of the text (also supports Transparent) + /// @param html The HTML you want to render / display + /// @param css The CSS you want to apply to style the HTML + /// @param background_color The background color of the frame image (valid values are a color string in #RRGGBB or #AARRGGBB notation, a CSS color name, or 'transparent') 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 diff --git a/include/QtTextReader.h b/include/QtTextReader.h index 85187afed..a3fa014c5 100644 --- a/include/QtTextReader.h +++ b/include/QtTextReader.h @@ -115,8 +115,8 @@ namespace openshot /// @param text The text you want to generate / display /// @param font The font 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) + /// @param text_color The color of the text (valid values are a color string in #RRGGBB or #AARRGGBB notation or a CSS color name) + /// @param background_color The background color of the frame image (valid values are a color string in #RRGGBB or #AARRGGBB notation, a CSS color name, or 'transparent') 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 From 5a08afdb3f138ae7f1b175ac5e59f6d2f32d99c6 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Wed, 14 Aug 2019 22:18:26 +1000 Subject: [PATCH 20/33] Set info.vcodec to QImage --- src/QtHtmlReader.cpp | 2 +- src/QtTextReader.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index 0d71c6585..7a1bf5845 100644 --- a/src/QtHtmlReader.cpp +++ b/src/QtHtmlReader.cpp @@ -112,7 +112,7 @@ void QtHtmlReader::Open() info.has_audio = false; info.has_video = true; info.file_size = 0; - info.vcodec = "Constant image uniform color"; + info.vcodec = "QImage"; info.width = width; info.height = height; info.pixel_ratio.num = 1; diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index 4205eb811..b11a3b552 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -118,7 +118,7 @@ void QtTextReader::Open() info.has_audio = false; info.has_video = true; info.file_size = 0; - info.vcodec = "Constant image uniform color"; + info.vcodec = "QImage"; info.width = width; info.height = height; info.pixel_ratio.num = 1; From 0ee9ed8e3a08985e60751be4d7515f79ae8a17dc Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Wed, 14 Aug 2019 22:38:41 +1000 Subject: [PATCH 21/33] Delete image on close --- src/QtHtmlReader.cpp | 6 ++++++ src/QtTextReader.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index 7a1bf5845..9d22fedaa 100644 --- a/src/QtHtmlReader.cpp +++ b/src/QtHtmlReader.cpp @@ -147,6 +147,12 @@ void QtHtmlReader::Close() { // Mark as "closed" is_open = false; + + // Delete the image + image.reset(); + + info.vcodec = ""; + info.acodec = ""; } } diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index b11a3b552..de5d4542f 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -153,6 +153,12 @@ void QtTextReader::Close() { // Mark as "closed" is_open = false; + + // Delete the image + image.reset(); + + info.vcodec = ""; + info.acodec = ""; } } From 74c9869c96844721ec3e2c7bf9aa85f51bc1456f Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 14 Aug 2019 10:21:57 -0400 Subject: [PATCH 22/33] Python & Ruby bindings for new Readers --- src/bindings/python/openshot.i | 8 ++++++-- src/bindings/ruby/openshot.i | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/bindings/python/openshot.i b/src/bindings/python/openshot.i index 512224efd..34aada1b0 100644 --- a/src/bindings/python/openshot.i +++ b/src/bindings/python/openshot.i @@ -6,8 +6,8 @@ # # 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 +# OpenShot Library (libopenshot), an open-source project dedicated to +# delivering high quality video editing and animation solutions to the # world. For more information visit . # # OpenShot Library (libopenshot) is free software: you can redistribute it @@ -83,8 +83,10 @@ #include "../../../include/PlayerBase.h" #include "../../../include/Point.h" #include "../../../include/Profiles.h" +#include "../../../include/QtHtmlReader.h" #include "../../../include/QtImageReader.h" #include "../../../include/QtPlayer.h" +#include "../../../include/QtTextReader.h" #include "../../../include/KeyFrame.h" #include "../../../include/RendererBase.h" #include "../../../include/Settings.h" @@ -151,8 +153,10 @@ %include "../../../include/PlayerBase.h" %include "../../../include/Point.h" %include "../../../include/Profiles.h" +%include "../../../include/QtHtmlReader.h" %include "../../../include/QtImageReader.h" %include "../../../include/QtPlayer.h" +%include "../../../include/QtTextReader.h" %include "../../../include/KeyFrame.h" %include "../../../include/RendererBase.h" %include "../../../include/Settings.h" diff --git a/src/bindings/ruby/openshot.i b/src/bindings/ruby/openshot.i index 1f3e0d993..9b16aee2b 100644 --- a/src/bindings/ruby/openshot.i +++ b/src/bindings/ruby/openshot.i @@ -6,8 +6,8 @@ # # 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 +# OpenShot Library (libopenshot), an open-source project dedicated to +# delivering high quality video editing and animation solutions to the # world. For more information visit . # # OpenShot Library (libopenshot) is free software: you can redistribute it @@ -95,8 +95,10 @@ namespace std { #include "../../../include/PlayerBase.h" #include "../../../include/Point.h" #include "../../../include/Profiles.h" +#include "../../../include/QtHtmlReader.h" #include "../../../include/QtImageReader.h" #include "../../../include/QtPlayer.h" +#include "../../../include/QtTextReader.h" #include "../../../include/KeyFrame.h" #include "../../../include/RendererBase.h" #include "../../../include/Settings.h" @@ -182,8 +184,10 @@ namespace std { %include "../../../include/PlayerBase.h" %include "../../../include/Point.h" %include "../../../include/Profiles.h" +%include "../../../include/QtHtmlReader.h" %include "../../../include/QtImageReader.h" %include "../../../include/QtPlayer.h" +%include "../../../include/QtTextReader.h" %include "../../../include/KeyFrame.h" %include "../../../include/RendererBase.h" %include "../../../include/Settings.h" From 0d067b33a316c61ce9ba403545e5af15c32bb1b3 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 14 Aug 2019 10:22:29 -0400 Subject: [PATCH 23/33] new ExampleHtml.py and updated ExampleHtml.cpp --- src/examples/ExampleHtml.cpp | 3 +- src/examples/ExampleHtml.py | 88 ++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100755 src/examples/ExampleHtml.py diff --git a/src/examples/ExampleHtml.cpp b/src/examples/ExampleHtml.cpp index 96e98e2a8..26ec42be6 100644 --- a/src/examples/ExampleHtml.cpp +++ b/src/examples/ExampleHtml.cpp @@ -1,7 +1,8 @@ /** * @file - * @brief Source file for Example Executable (example app for libopenshot) + * @brief Source file for QtHtmlReader Example (example app for libopenshot) * @author Jonathan Thomas + * @author FeRD (Frank Dana) * * @ref License */ diff --git a/src/examples/ExampleHtml.py b/src/examples/ExampleHtml.py new file mode 100755 index 000000000..116df0ca7 --- /dev/null +++ b/src/examples/ExampleHtml.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 + +""" + @file + @brief Python source file for QtHtmlReader example + @author Jonathan Thomas + @author FeRD (Frank Dana) + + @ref License +""" + +# LICENSE +# +# 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 +# world. For more information visit . +# +# OpenShot Library (libopenshot) is free software: you can redistribute it +# and/or modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# OpenShot Library (libopenshot) is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with OpenShot Library. If not, see . + +import sys +from PyQt5.QtCore import QTimer +from PyQt5.QtGui import QGuiApplication +import openshot + +app = QGuiApplication(sys.argv) + +html_code = "Check out this Text!" + +# Create a QtHtmlReader +r = openshot.QtHtmlReader(720, + 480, + 5, + 5, + openshot.GRAVITY_CENTER, + html_code, + "b { color: #ff0000; }", + "#000000" + ) + +r.Open() # Open the reader + +r.DisplayInfo() # Display metadata + +# Set up Writer +w = openshot.FFmpegWriter("/var/tmp/pyHtmlExample.mp4") + +w.SetVideoOptions(True, "libx264", openshot.Fraction(30000, 1000), 720, 480, + openshot.Fraction(1, 1), False, False, 3000000) + +w.info.metadata["title"] = "testtest"; +w.info.metadata["artist"] = "aaa"; +w.info.metadata["album"] = "bbb"; +w.info.metadata["year"] = "2015"; +w.info.metadata["description"] = "ddd"; +w.info.metadata["comment"] = "eee"; +w.info.metadata["comment"] = "comment"; +w.info.metadata["copyright"] = "copyright OpenShot!"; + +# Open the Writer +w.Open() + +# Grab 30 frames from Reader and encode to Writer +for i in range(30): + f = r.GetFrame(i) + w.WriteFrame(f) + +# Close out Reader & Writer +w.Close() +r.Close() + +# Set a timer to terminate the app as soon as the event queue empties +QTimer.singleShot(0, app.quit) + +# Run QGuiApplication to completion +sys.exit(app.exec()) From bcaa9ace988591c395f1a0a78a60db6aa72ebbc8 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 14 Aug 2019 11:40:29 -0400 Subject: [PATCH 24/33] QtText/QtHtmlReader: Don't leak memory in SetJson --- src/QtHtmlReader.cpp | 8 +++++--- src/QtTextReader.cpp | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index 9d22fedaa..0627d55bd 100644 --- a/src/QtHtmlReader.cpp +++ b/src/QtHtmlReader.cpp @@ -84,9 +84,9 @@ void QtHtmlReader::Open() text_document.setTextWidth(width); text_document.setDefaultStyleSheet(css.c_str()); text_document.setHtml(html.c_str()); - + int td_height = text_document.documentLayout()->documentSize().height(); - + 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) { @@ -94,7 +94,7 @@ void QtHtmlReader::Open() } 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) { text_document.setDefaultTextOption(QTextOption(Qt::AlignLeft)); } else if (gravity == GRAVITY_CENTER || gravity == GRAVITY_TOP || gravity == GRAVITY_BOTTOM) { @@ -216,6 +216,8 @@ void QtHtmlReader::SetJson(std::string value) { std::string errors; bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index de5d4542f..0c45ea4e5 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -224,6 +224,8 @@ void QtTextReader::SetJson(std::string value) { std::string errors; bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); From 74869ffa70de4fa631d94076ed987e1df8a8f2a8 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 14 Aug 2019 12:18:49 -0400 Subject: [PATCH 25/33] ExampleHtml.cpp cleanup * Change writer var from 'w9' to 'w' * More descriptive output filename * Write output file to current directory * More readable formatting --- src/examples/ExampleHtml.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/examples/ExampleHtml.cpp b/src/examples/ExampleHtml.cpp index 26ec42be6..298d52b46 100644 --- a/src/examples/ExampleHtml.cpp +++ b/src/examples/ExampleHtml.cpp @@ -43,13 +43,15 @@ int main(int argc, char* argv[]) { QGuiApplication app(argc, argv); + std::string html_code = "Check out this Text!"; + // Create a reader to generate an openshot::Frame containing text QtHtmlReader r(720, // width 480, // height 5, // x_offset 5, // y_offset GRAVITY_CENTER, // gravity - "Check out this Text!", // html + html_code, // html "b { color: #ff0000; }", "#000000" // background_color ); @@ -59,32 +61,32 @@ int main(int argc, char* argv[]) { r.DisplayInfo(); /* WRITER ---------------- */ - FFmpegWriter w9("/var/tmp/metadata.mp4"); + FFmpegWriter w("cppHtmlExample.mp4"); // Set options - //w9.SetAudioOptions(true, "libmp3lame", r.info.sample_rate, r9.info.channels, r9.info.channel_layout, 128000); - w9.SetVideoOptions(true, "libx264", Fraction{30000, 1000}, 720, 480, Fraction(1,1), false, false, 3000000); - - w9.info.metadata["title"] = "testtest"; - w9.info.metadata["artist"] = "aaa"; - w9.info.metadata["album"] = "bbb"; - w9.info.metadata["year"] = "2015"; - w9.info.metadata["description"] = "ddd"; - w9.info.metadata["comment"] = "eee"; - w9.info.metadata["comment"] = "comment"; - w9.info.metadata["copyright"] = "copyright OpenShot!"; + //w.SetAudioOptions(true, "libmp3lame", r.info.sample_rate, r.info.channels, r.info.channel_layout, 128000); + w.SetVideoOptions(true, "libx264", Fraction(30000, 1000), 720, 480, Fraction(1, 1), false, false, 3000000); + + w.info.metadata["title"] = "testtest"; + w.info.metadata["artist"] = "aaa"; + w.info.metadata["album"] = "bbb"; + w.info.metadata["year"] = "2015"; + w.info.metadata["description"] = "ddd"; + w.info.metadata["comment"] = "eee"; + w.info.metadata["comment"] = "comment"; + w.info.metadata["copyright"] = "copyright OpenShot!"; // Open writer - w9.Open(); + w.Open(); for (long int frame = 1; frame <= 30; ++frame) { std::shared_ptr f = r.GetFrame(frame); // Same frame every time - w9.WriteFrame(f); + w.WriteFrame(f); } // Close writer & reader - w9.Close(); + w.Close(); r.Close(); // Set a timer with 0 timeout to terminate immediately after From 0048294528573d5e3b2357c22874dd00717181f5 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 14 Aug 2019 12:19:54 -0400 Subject: [PATCH 26/33] ExampleHtml.py cleanup * Remove semicolons from cut-and-paste C++ code * Write output file to current directory * More readable formatting --- src/examples/ExampleHtml.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/examples/ExampleHtml.py b/src/examples/ExampleHtml.py index 116df0ca7..610176f56 100755 --- a/src/examples/ExampleHtml.py +++ b/src/examples/ExampleHtml.py @@ -55,26 +55,26 @@ r.DisplayInfo() # Display metadata # Set up Writer -w = openshot.FFmpegWriter("/var/tmp/pyHtmlExample.mp4") +w = openshot.FFmpegWriter("pyHtmlExample.mp4") w.SetVideoOptions(True, "libx264", openshot.Fraction(30000, 1000), 720, 480, openshot.Fraction(1, 1), False, False, 3000000) -w.info.metadata["title"] = "testtest"; -w.info.metadata["artist"] = "aaa"; -w.info.metadata["album"] = "bbb"; -w.info.metadata["year"] = "2015"; -w.info.metadata["description"] = "ddd"; -w.info.metadata["comment"] = "eee"; -w.info.metadata["comment"] = "comment"; -w.info.metadata["copyright"] = "copyright OpenShot!"; +w.info.metadata["title"] = "testtest" +w.info.metadata["artist"] = "aaa" +w.info.metadata["album"] = "bbb" +w.info.metadata["year"] = "2015" +w.info.metadata["description"] = "ddd" +w.info.metadata["comment"] = "eee" +w.info.metadata["comment"] = "comment" +w.info.metadata["copyright"] = "copyright OpenShot!" # Open the Writer w.Open() # Grab 30 frames from Reader and encode to Writer -for i in range(30): - f = r.GetFrame(i) +for frame in range(30): + f = r.GetFrame(frame) w.WriteFrame(f) # Close out Reader & Writer From 7c48bec484b48d27898deb1664a647e482482f3f Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Sun, 25 Aug 2019 23:54:28 -0400 Subject: [PATCH 27/33] HTML examples: Code updates - Use same `html_code` and `css_code` - Sync up offsets and gravity (BOTTOM_RIGHT) - Create 1280x720 frames - Generate 100 frames of output video --- src/examples/ExampleHtml.cpp | 33 +++++++++++++++++++-------------- src/examples/ExampleHtml.py | 25 +++++++++++++++---------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/examples/ExampleHtml.cpp b/src/examples/ExampleHtml.cpp index 298d52b46..f315e2527 100644 --- a/src/examples/ExampleHtml.cpp +++ b/src/examples/ExampleHtml.cpp @@ -43,18 +43,23 @@ int main(int argc, char* argv[]) { QGuiApplication app(argc, argv); - std::string html_code = "Check out this Text!"; - - // Create a reader to generate an openshot::Frame containing text - QtHtmlReader r(720, // width - 480, // height - 5, // x_offset - 5, // y_offset - GRAVITY_CENTER, // gravity - html_code, // html - "b { color: #ff0000; }", - "#000000" // background_color - ); + std::string html_code = R"html(

Check out this HTML!

)html"; + + std::string css_code = R"css( + * {font-family:sans-serif; font-size:18pt; color:#ffffff;} + #red {color: #ff0000;} + )css"; + +// Create a reader to generate an openshot::Frame containing text +QtHtmlReader r(1280, // width + 720, // height + -16, // x_offset + -16, // y_offset + GRAVITY_BOTTOM_RIGHT, // gravity + html_code, // html + css_code, // css + "#000000" // background_color + ); r.Open(); // Open the reader @@ -65,7 +70,7 @@ int main(int argc, char* argv[]) { // Set options //w.SetAudioOptions(true, "libmp3lame", r.info.sample_rate, r.info.channels, r.info.channel_layout, 128000); - w.SetVideoOptions(true, "libx264", Fraction(30000, 1000), 720, 480, Fraction(1, 1), false, false, 3000000); + w.SetVideoOptions(true, "libx264", Fraction(30000, 1000), 1280, 720, Fraction(1, 1), false, false, 3000000); w.info.metadata["title"] = "testtest"; w.info.metadata["artist"] = "aaa"; @@ -79,7 +84,7 @@ int main(int argc, char* argv[]) { // Open writer w.Open(); - for (long int frame = 1; frame <= 30; ++frame) + for (long int frame = 1; frame <= 100; ++frame) { std::shared_ptr f = r.GetFrame(frame); // Same frame every time w.WriteFrame(f); diff --git a/src/examples/ExampleHtml.py b/src/examples/ExampleHtml.py index 610176f56..1938f2fe8 100755 --- a/src/examples/ExampleHtml.py +++ b/src/examples/ExampleHtml.py @@ -37,17 +37,22 @@ app = QGuiApplication(sys.argv) -html_code = "Check out this Text!" +html_code = """

Check out this HTML!

""" + +css_code = """ + * {font-family:sans-serif; font-size:18pt; color:#ffffff;} + #red {color: #ff0000;} +""" # Create a QtHtmlReader -r = openshot.QtHtmlReader(720, - 480, - 5, - 5, - openshot.GRAVITY_CENTER, +r = openshot.QtHtmlReader(1280, # width + 720, # height + -16, # x offset + -16, # y offset + openshot.GRAVITY_BOTTOM_RIGHT, html_code, - "b { color: #ff0000; }", - "#000000" + css_code, + "#000000" # background color ) r.Open() # Open the reader @@ -57,7 +62,7 @@ # Set up Writer w = openshot.FFmpegWriter("pyHtmlExample.mp4") -w.SetVideoOptions(True, "libx264", openshot.Fraction(30000, 1000), 720, 480, +w.SetVideoOptions(True, "libx264", openshot.Fraction(30000, 1000), 1280, 720, openshot.Fraction(1, 1), False, False, 3000000) w.info.metadata["title"] = "testtest" @@ -73,7 +78,7 @@ w.Open() # Grab 30 frames from Reader and encode to Writer -for frame in range(30): +for frame in range(100): f = r.GetFrame(frame) w.WriteFrame(f) From c8b5300df3def39db056ea0aef7538d622dc3686 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Fri, 20 Sep 2019 21:25:09 +1000 Subject: [PATCH 28/33] Allow font bold and italic properties to be set --- include/QtTextReader.h | 6 +++++- src/QtTextReader.cpp | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/QtTextReader.h b/include/QtTextReader.h index a3fa014c5..ee35dc28c 100644 --- a/include/QtTextReader.h +++ b/include/QtTextReader.h @@ -95,6 +95,8 @@ namespace openshot std::string text; std::string font; double font_size; + bool is_bold; + bool is_italic; std::string text_color; std::string background_color; std::shared_ptr image; @@ -115,9 +117,11 @@ namespace openshot /// @param text The text you want to generate / display /// @param font The font of the text /// @param font_size The size of the text + /// @param is_bold Set to true to make text bold + /// @param is_italic Set to true to make text italic /// @param text_color The color of the text (valid values are a color string in #RRGGBB or #AARRGGBB notation or a CSS color name) /// @param background_color The background color of the frame image (valid values are a color string in #RRGGBB or #AARRGGBB notation, a CSS color name, or 'transparent') - 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); + QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double font_size, bool is_bold, bool is_italic, std::string text_color, std::string background_color); /// Close Reader void Close(); diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index 0c45ea4e5..d56ca1afc 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -37,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"), font_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), is_bold(false), is_italic(false), 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 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) +QtTextReader::QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double font_size, bool is_bold, bool is_italic, 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), is_bold(is_bold), is_italic(is_italic), 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(); @@ -74,7 +74,10 @@ void QtTextReader::Open() painter.setPen(QPen(text_color.c_str())); // set font - painter.setFont(QFont(font.c_str(), font_size)); + QFont qFont(font.c_str(), font_size); + qFont.setBold(is_bold); + qFont.setItalic(is_italic); + painter.setFont(qFont); // Set gravity (map between OpenShot and Qt) int align_flag = 0; From 738dd62132ab209616dab497b6a4af374f89bf10 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Fri, 20 Sep 2019 22:10:07 +1000 Subject: [PATCH 29/33] Enable background fill color to be set behind text --- include/QtTextReader.h | 5 +++++ src/QtTextReader.cpp | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/QtTextReader.h b/include/QtTextReader.h index ee35dc28c..c9f82f703 100644 --- a/include/QtTextReader.h +++ b/include/QtTextReader.h @@ -99,6 +99,7 @@ namespace openshot bool is_italic; std::string text_color; std::string background_color; + std::string text_background_color; std::shared_ptr image; bool is_open; openshot::GravityType gravity; @@ -123,6 +124,10 @@ namespace openshot /// @param background_color The background color of the frame image (valid values are a color string in #RRGGBB or #AARRGGBB notation, a CSS color name, or 'transparent') QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double font_size, bool is_bold, bool is_italic, std::string text_color, std::string background_color); + /// Draw a box under rendered text using the specified color. + /// @param text_background_color The background color behind the text (valid values are a color string in #RRGGBB or #AARRGGBB notation or a CSS color name) + void SetTextBackgroundColor(std::string color); + /// Close Reader void Close(); diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index d56ca1afc..d17a486ab 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -52,6 +52,14 @@ QtTextReader::QtTextReader(int width, int height, int x_offset, int y_offset, Gr Close(); } +void QtTextReader::SetTextBackgroundColor(string color) { + text_background_color = color; + + // Open and Close the reader, to populate it's attributes (such as height, width, etc...) plus the text background color + Open(); + Close(); +} + // Open reader void QtTextReader::Open() { @@ -68,7 +76,10 @@ void QtTextReader::Open() } // set background - painter.setBackground(QBrush(background_color.c_str())); + if (!text_background_color.empty()) { + painter.setBackgroundMode(Qt::OpaqueMode); + painter.setBackground(QBrush(text_background_color.c_str())); + } // set font color painter.setPen(QPen(text_color.c_str())); @@ -210,6 +221,7 @@ Json::Value QtTextReader::JsonValue() { root["font_size"] = font_size; root["text_color"] = text_color; root["background_color"] = background_color; + root["text_background_color"] = text_background_color; root["gravity"] = gravity; // return JsonValue @@ -270,6 +282,8 @@ void QtTextReader::SetJsonValue(Json::Value root) { text_color = root["text_color"].asString(); if (!root["background_color"].isNull()) background_color = root["background_color"].asString(); + if (!root["text_background_color"].isNull()) + text_background_color = root["text_background_color"].asString(); if (!root["gravity"].isNull()) gravity = (GravityType) root["gravity"].asInt(); From 0cae5da6fad9b8a12e039af7775b5a1e99404b2a Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Fri, 20 Sep 2019 22:38:31 +1000 Subject: [PATCH 30/33] Correct parameter documentation --- include/QtTextReader.h | 2 +- include/TextReader.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/QtTextReader.h b/include/QtTextReader.h index c9f82f703..2e0b6840a 100644 --- a/include/QtTextReader.h +++ b/include/QtTextReader.h @@ -125,7 +125,7 @@ namespace openshot QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double font_size, bool is_bold, bool is_italic, std::string text_color, std::string background_color); /// Draw a box under rendered text using the specified color. - /// @param text_background_color The background color behind the text (valid values are a color string in #RRGGBB or #AARRGGBB notation or a CSS color name) + /// @param color The background color behind the text (valid values are a color string in #RRGGBB or #AARRGGBB notation or a CSS color name) void SetTextBackgroundColor(std::string color); /// Close Reader diff --git a/include/TextReader.h b/include/TextReader.h index 7b276f7f5..0995357d8 100644 --- a/include/TextReader.h +++ b/include/TextReader.h @@ -121,7 +121,7 @@ namespace openshot 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); /// Draw a box under rendered text using the specified color. - /// @param text_background_color The background color behind the text + /// @param color The background color behind the text void SetTextBackgroundColor(string color); /// Close Reader From 33f16d3a55c555e035c4f7ded95a7e8fecf1c7c6 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Sat, 21 Sep 2019 21:11:29 +1000 Subject: [PATCH 31/33] Use QFont instead of setting parameters --- include/QtTextReader.h | 7 ++----- src/QtTextReader.cpp | 18 ++++++------------ 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/include/QtTextReader.h b/include/QtTextReader.h index 2e0b6840a..3bcb22368 100644 --- a/include/QtTextReader.h +++ b/include/QtTextReader.h @@ -93,10 +93,7 @@ namespace openshot int x_offset; int y_offset; std::string text; - std::string font; - double font_size; - bool is_bold; - bool is_italic; + QFont font; std::string text_color; std::string background_color; std::string text_background_color; @@ -122,7 +119,7 @@ namespace openshot /// @param is_italic Set to true to make text italic /// @param text_color The color of the text (valid values are a color string in #RRGGBB or #AARRGGBB notation or a CSS color name) /// @param background_color The background color of the frame image (valid values are a color string in #RRGGBB or #AARRGGBB notation, a CSS color name, or 'transparent') - QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, std::string font, double font_size, bool is_bold, bool is_italic, std::string text_color, std::string background_color); + QtTextReader(int width, int height, int x_offset, int y_offset, GravityType gravity, std::string text, QFont font, std::string text_color, std::string background_color); /// Draw a box under rendered text using the specified color. /// @param color The background color behind the text (valid values are a color string in #RRGGBB or #AARRGGBB notation or a CSS color name) diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index d17a486ab..e32835cf8 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -37,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"), font_size(10.0), is_bold(false), is_italic(false), 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(QFont("Arial", 10)), 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 font_size, bool is_bold, bool is_italic, 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), is_bold(is_bold), is_italic(is_italic), 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, QFont font, std::string text_color, std::string background_color) +: width(width), height(height), x_offset(x_offset), y_offset(y_offset), text(text), font(font), 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(); @@ -85,10 +85,7 @@ void QtTextReader::Open() painter.setPen(QPen(text_color.c_str())); // set font - QFont qFont(font.c_str(), font_size); - qFont.setBold(is_bold); - qFont.setItalic(is_italic); - painter.setFont(qFont); + painter.setFont(font); // Set gravity (map between OpenShot and Qt) int align_flag = 0; @@ -217,8 +214,7 @@ Json::Value QtTextReader::JsonValue() { root["x_offset"] = x_offset; root["y_offset"] = y_offset; root["text"] = text; - root["font"] = font; - root["font_size"] = font_size; + root["font"] = font.toString().toStdString(); root["text_color"] = text_color; root["background_color"] = background_color; root["text_background_color"] = text_background_color; @@ -275,9 +271,7 @@ void QtTextReader::SetJsonValue(Json::Value root) { if (!root["text"].isNull()) text = root["text"].asString(); if (!root["font"].isNull()) - font = root["font"].asString(); - if (!root["font_size"].isNull()) - font_size = root["font_size"].asDouble(); + font.fromString(QString::fromStdString(root["font"].asString())); if (!root["text_color"].isNull()) text_color = root["text_color"].asString(); if (!root["background_color"].isNull()) From 21951bea5c8cf177b0b977d2567aa67219a42fa1 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Wed, 30 Oct 2019 09:43:31 +1100 Subject: [PATCH 32/33] Set duration to 1 hour Co-Authored-By: Frank Dana --- src/QtTextReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index e32835cf8..38240c964 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -134,7 +134,7 @@ void QtTextReader::Open() info.height = height; info.pixel_ratio.num = 1; info.pixel_ratio.den = 1; - info.duration = 60 * 60 * 24; // 24 hour duration + info.duration = 60 * 60 * 1; // 1 hour duration info.fps.num = 30; info.fps.den = 1; info.video_timebase.num = 1; From 6c20fa43c21b45128c9c8c480c29b80b35a1050b Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Wed, 30 Oct 2019 09:44:01 +1100 Subject: [PATCH 33/33] Set HTML reader duration to 1 hour Co-Authored-By: Frank Dana --- src/QtHtmlReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index 0627d55bd..e3cdc6021 100644 --- a/src/QtHtmlReader.cpp +++ b/src/QtHtmlReader.cpp @@ -117,7 +117,7 @@ void QtHtmlReader::Open() info.height = height; info.pixel_ratio.num = 1; info.pixel_ratio.den = 1; - info.duration = 60 * 60 * 24; // 24 hour duration + info.duration = 60 * 60 * 1; // 1 hour duration info.fps.num = 30; info.fps.den = 1; info.video_timebase.num = 1;