You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Merge remote-tracking branch 'upstream/develop' into develop
This commit is contained in:
@@ -3,9 +3,12 @@
|
||||
* @brief Source file for TextReader class
|
||||
* @author Jonathan Thomas <jonathan@openshot.org>
|
||||
*
|
||||
* @section LICENSE
|
||||
* @ref License
|
||||
*/
|
||||
|
||||
/* LICENSE
|
||||
*
|
||||
* Copyright (c) 2008-2014 OpenShot Studios, LLC
|
||||
* Copyright (c) 2008-2019 OpenShot Studios, LLC
|
||||
* <http://www.openshotstudios.com/>. This file is part of
|
||||
* OpenShot Library (libopenshot), an open-source project dedicated to
|
||||
* delivering high quality video editing and animation solutions to the
|
||||
@@ -25,6 +28,9 @@
|
||||
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Require ImageMagick support
|
||||
#ifdef USE_IMAGEMAGICK
|
||||
|
||||
#include "../include/TextReader.h"
|
||||
|
||||
using namespace openshot;
|
||||
@@ -45,6 +51,14 @@ TextReader::TextReader(int width, int height, int x_offset, int y_offset, Gravit
|
||||
Close();
|
||||
}
|
||||
|
||||
void TextReader::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 TextReader::Open()
|
||||
{
|
||||
@@ -97,6 +111,10 @@ void TextReader::Open()
|
||||
lines.push_back(Magick::DrawablePointSize(size));
|
||||
lines.push_back(Magick::DrawableText(x_offset, y_offset, text));
|
||||
|
||||
if (!text_background_color.empty()) {
|
||||
lines.push_back(Magick::DrawableTextUnderColor(Magick::Color(text_background_color)));
|
||||
}
|
||||
|
||||
// Draw image
|
||||
image->draw(lines);
|
||||
|
||||
@@ -190,6 +208,7 @@ Json::Value TextReader::JsonValue() {
|
||||
root["size"] = size;
|
||||
root["text_color"] = text_color;
|
||||
root["background_color"] = background_color;
|
||||
root["text_background_color"] = text_background_color;
|
||||
root["gravity"] = gravity;
|
||||
|
||||
// return JsonValue
|
||||
@@ -201,8 +220,12 @@ void TextReader::SetJson(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());
|
||||
|
||||
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)", "");
|
||||
@@ -244,6 +267,8 @@ void TextReader::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();
|
||||
|
||||
@@ -254,3 +279,5 @@ void TextReader::SetJsonValue(Json::Value root) {
|
||||
Open();
|
||||
}
|
||||
}
|
||||
|
||||
#endif //USE_IMAGEMAGICK
|
||||
|
||||
Reference in New Issue
Block a user