Skip to content

Commit

Permalink
Merge branch 'main' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Apr 23, 2024
2 parents 422d74a + 648ff61 commit c904a78
Show file tree
Hide file tree
Showing 51 changed files with 1,314 additions and 7,226 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -78,3 +78,6 @@
[submodule "third_party/qoi"]
path = third_party/qoi
url = https://github.com/aseprite/qoi.git
[submodule "third_party/tinyxml2"]
path = third_party/tinyxml2
url = https://github.com/aseprite/tinyxml2.git
12 changes: 6 additions & 6 deletions CMakeLists.txt
@@ -1,5 +1,5 @@
# Aseprite
# Copyright (C) 2018-2022 Igara Studio S.A.
# Copyright (C) 2018-2024 Igara Studio S.A.
# Copyright (C) 2001-2018 David Capello

cmake_minimum_required(VERSION 3.16)
Expand Down Expand Up @@ -161,7 +161,7 @@ set(PIXMAN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/pixman)
set(FREETYPE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/freetype2)
set(HARFBUZZ_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/harfbuzz)
set(SIMPLEINI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/simpleini)
set(TINYXML_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/tinyxml)
set(TINYXML_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/tinyxml2)
set(ZLIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/zlib)

# Search in the "cmake" directory for additional CMake modules.
Expand Down Expand Up @@ -223,12 +223,12 @@ endif()
include_directories(${PNG_INCLUDE_DIRS})
add_definitions(-DPNG_NO_MMX_CODE) # Do not use MMX optimizations in PNG code

# tinyxml
# tinyxml2
if(USE_SHARED_TINYXML)
find_library(TINYXML_LIBRARY NAMES tinyxml)
find_path(TINYXML_INCLUDE_DIR NAMES tinyxml.h)
find_library(TINYXML_LIBRARY NAMES tinyxml2)
find_path(TINYXML_INCLUDE_DIR NAMES tinyxml2.h)
else()
set(TINYXML_LIBRARY tinyxml)
set(TINYXML_LIBRARY tinyxml2)
set(TINYXML_INCLUDE_DIR ${TINYXML_DIR})
endif()
include_directories(${TINYXML_INCLUDE_DIR})
Expand Down
10 changes: 2 additions & 8 deletions docs/LICENSES.md
Expand Up @@ -1153,10 +1153,10 @@ freely, subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
```

# [tinyxml](http://www.grinninglizard.com/tinyxml/)
# [tinyxml2](https://github.com/leethomason/tinyxml2)

```
TinyXML is released under the zlib license:
Original code by Lee Thomason (www.grinninglizard.com)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
Expand All @@ -1176,12 +1176,6 @@ must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
--
TinyXML was originally written by Lee Thomason. Lee reviews changes
and releases new versions, with the help of Yves Berquin, Andrew
Ellerton, and the tinyXml community.
```

# [ucdn](https://github.com/grigorig/ucdn)
Expand Down
2 changes: 1 addition & 1 deletion laf
10 changes: 10 additions & 0 deletions src/app/app.cpp
Expand Up @@ -267,9 +267,19 @@ int App::initialize(const AppOptions& options)

#ifdef ENABLE_UI
m_isGui = options.startUI() && !options.previewCLI();

// Notify the scripting engine that we're going to enter to GUI
// mode, this is useful so we can mark the stdin file handle as
// closed so no script can hang the program if it tries to read from
// stdin when the GUI is running.
#ifdef ENABLE_SCRIPTING
if (m_isGui)
m_engine->notifyRunningGui();
#endif
#else
m_isGui = false;
#endif

m_isShell = options.startShell();
m_coreModules = std::make_unique<CoreModules>();

Expand Down
107 changes: 48 additions & 59 deletions src/app/app_brushes.cpp
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020-2023 Igara Studio S.A.
// Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
Expand All @@ -23,22 +23,25 @@
#include "doc/image.h"
#include "doc/image_impl.h"

#include "tinyxml2.h"

#include <fstream>

namespace app {

using namespace doc;
using namespace base::serialization;
using namespace base::serialization::little_endian;
using namespace tinyxml2;

namespace {

ImageRef load_xml_image(const TiXmlElement* imageElem)
ImageRef load_xml_image(const XMLElement* imageElem)
{
ImageRef image;
int w, h;
if (imageElem->QueryIntAttribute("width", &w) != TIXML_SUCCESS ||
imageElem->QueryIntAttribute("height", &h) != TIXML_SUCCESS ||
if (imageElem->QueryIntAttribute("width", &w) != XML_SUCCESS ||
imageElem->QueryIntAttribute("height", &h) != XML_SUCCESS ||
w < 0 || w > 9999 ||
h < 0 || h > 9999)
return image;
Expand Down Expand Up @@ -109,7 +112,7 @@ ImageRef load_xml_image(const TiXmlElement* imageElem)
return image;
}

void save_xml_image(TiXmlElement* imageElem, const Image* image)
void save_xml_image(XMLElement* imageElem, const Image* image)
{
int w = image->width();
int h = image->height();
Expand Down Expand Up @@ -167,8 +170,7 @@ void save_xml_image(TiXmlElement* imageElem, const Image* image)

std::string data_base64;
base::encode_base64(data, data_base64);
TiXmlText textElem(data_base64.c_str());
imageElem->InsertEndChild(textElem);
imageElem->InsertNewText(data_base64.c_str());
}

} // anonymous namespace
Expand Down Expand Up @@ -305,11 +307,11 @@ static const int kBrushFlags =

void AppBrushes::load(const std::string& filename)
{
XmlDocumentRef doc = app::open_xml(filename);
TiXmlHandle handle(doc.get());
TiXmlElement* brushElem = handle
.FirstChild("brushes")
.FirstChild("brush").ToElement();
XMLDocumentRef doc = app::open_xml(filename);
XMLHandle handle(doc.get());
XMLElement* brushElem = handle
.FirstChildElement("brushes")
.FirstChildElement("brush").ToElement();

while (brushElem) {
// flags
Expand Down Expand Up @@ -339,9 +341,9 @@ void AppBrushes::load(const std::string& filename)

// Brush image
ImageRef image, mask;
if (TiXmlElement* imageElem = brushElem->FirstChildElement("image"))
if (XMLElement* imageElem = brushElem->FirstChildElement("image"))
image = load_xml_image(imageElem);
if (TiXmlElement* maskElem = brushElem->FirstChildElement("mask"))
if (XMLElement* maskElem = brushElem->FirstChildElement("mask"))
mask = load_xml_image(maskElem);

if (image) {
Expand All @@ -351,45 +353,45 @@ void AppBrushes::load(const std::string& filename)
}

// Colors
if (TiXmlElement* fgcolorElem = brushElem->FirstChildElement("fgcolor")) {
if (XMLElement* fgcolorElem = brushElem->FirstChildElement("fgcolor")) {
if (auto value = fgcolorElem->Attribute("value")) {
fgColor = app::Color::fromString(value);
flags |= int(BrushSlot::Flags::FgColor);
}
}

if (TiXmlElement* bgcolorElem = brushElem->FirstChildElement("bgcolor")) {
if (XMLElement* bgcolorElem = brushElem->FirstChildElement("bgcolor")) {
if (auto value = bgcolorElem->Attribute("value")) {
bgColor = app::Color::fromString(value);
flags |= int(BrushSlot::Flags::BgColor);
}
}

// Ink
if (TiXmlElement* inkTypeElem = brushElem->FirstChildElement("inktype")) {
if (XMLElement* inkTypeElem = brushElem->FirstChildElement("inktype")) {
if (auto value = inkTypeElem->Attribute("value")) {
inkType = app::tools::string_id_to_ink_type(value);
flags |= int(BrushSlot::Flags::InkType);
}
}

if (TiXmlElement* inkOpacityElem = brushElem->FirstChildElement("inkopacity")) {
if (XMLElement* inkOpacityElem = brushElem->FirstChildElement("inkopacity")) {
if (auto value = inkOpacityElem->Attribute("value")) {
inkOpacity = base::convert_to<int>(std::string(value));
flags |= int(BrushSlot::Flags::InkOpacity);
}
}

// Shade
if (TiXmlElement* shadeElem = brushElem->FirstChildElement("shade")) {
if (XMLElement* shadeElem = brushElem->FirstChildElement("shade")) {
if (auto value = shadeElem->Attribute("value")) {
shade = shade_from_string(value);
flags |= int(BrushSlot::Flags::Shade);
}
}

// Pixel-perfect
if (TiXmlElement* pixelPerfectElem = brushElem->FirstChildElement("pixelperfect")) {
if (XMLElement* pixelPerfectElem = brushElem->FirstChildElement("pixelperfect")) {
pixelPerfect = bool_attr(pixelPerfectElem, "value", false);
flags |= int(BrushSlot::Flags::PixelPerfect);
}
Expand All @@ -414,13 +416,13 @@ void AppBrushes::load(const std::string& filename)

void AppBrushes::save(const std::string& filename) const
{
XmlDocumentRef doc(new TiXmlDocument());
TiXmlElement brushesElem("brushes");

//<?xml version="1.0" encoding="utf-8"?>
auto doc = std::make_unique<XMLDocument>();
XMLElement* brushesElem = doc->NewElement("brushes");

doc->InsertEndChild(doc->NewDeclaration("xml version=\"1.0\" encoding=\"utf-8\""));
doc->InsertEndChild(brushesElem);
for (const auto& slot : m_slots) {
TiXmlElement brushElem("brush");
XMLElement* brushElem = brushesElem->InsertNewChildElement("brush");
if (slot.locked()) {
// Flags
int flags = int(slot.flags());
Expand All @@ -435,86 +437,73 @@ void AppBrushes::save(const std::string& filename) const
ASSERT(slot.brush());

if (flags & int(BrushSlot::Flags::BrushType)) {
brushElem.SetAttribute(
brushElem->SetAttribute(
"type", brush_type_to_string_id(slot.brush()->type()).c_str());
}

if (flags & int(BrushSlot::Flags::BrushSize)) {
brushElem.SetAttribute("size", slot.brush()->size());
brushElem->SetAttribute("size", slot.brush()->size());
}

if (flags & int(BrushSlot::Flags::BrushAngle)) {
brushElem.SetAttribute("angle", slot.brush()->angle());
brushElem->SetAttribute("angle", slot.brush()->angle());
}

if (slot.brush()->type() == kImageBrushType &&
slot.brush()->originalImage()) {
TiXmlElement elem("image");
save_xml_image(&elem, slot.brush()->originalImage());
brushElem.InsertEndChild(elem);
XMLElement* elem = brushElem->InsertNewChildElement("image");
save_xml_image(elem, slot.brush()->originalImage());

if (slot.brush()->maskBitmap()) {
TiXmlElement maskElem("mask");
save_xml_image(&maskElem, slot.brush()->maskBitmap());
brushElem.InsertEndChild(maskElem);
XMLElement* maskElem = brushElem->InsertNewChildElement("mask");
save_xml_image(maskElem, slot.brush()->maskBitmap());
}

// Image color
brushElem.SetAttribute(
brushElem->SetAttribute(
"imagecolor",
(flags & int(BrushSlot::Flags::ImageColor)) ? "true": "false");
}
}

// Colors
if (flags & int(BrushSlot::Flags::FgColor)) {
TiXmlElement elem("fgcolor");
elem.SetAttribute("value", slot.fgColor().toString().c_str());
brushElem.InsertEndChild(elem);
XMLElement* elem = brushElem->InsertNewChildElement("fgcolor");
elem->SetAttribute("value", slot.fgColor().toString().c_str());
}

if (flags & int(BrushSlot::Flags::BgColor)) {
TiXmlElement elem("bgcolor");
elem.SetAttribute("value", slot.bgColor().toString().c_str());
brushElem.InsertEndChild(elem);
XMLElement* elem = brushElem->InsertNewChildElement("bgcolor");
elem->SetAttribute("value", slot.bgColor().toString().c_str());
}

// Ink
if (flags & int(BrushSlot::Flags::InkType)) {
TiXmlElement elem("inktype");
elem.SetAttribute(
XMLElement* elem = brushElem->InsertNewChildElement("inktype");
elem->SetAttribute(
"value", app::tools::ink_type_to_string_id(slot.inkType()).c_str());
brushElem.InsertEndChild(elem);
}

if (flags & int(BrushSlot::Flags::InkOpacity)) {
TiXmlElement elem("inkopacity");
elem.SetAttribute("value", slot.inkOpacity());
brushElem.InsertEndChild(elem);
XMLElement* elem = brushElem->InsertNewChildElement("inkopacity");
elem->SetAttribute("value", slot.inkOpacity());
}

// Shade
if (flags & int(BrushSlot::Flags::Shade)) {
TiXmlElement elem("shade");
elem.SetAttribute("value", shade_to_string(slot.shade()).c_str());
brushElem.InsertEndChild(elem);
XMLElement* elem = brushElem->InsertNewChildElement("shade");
elem->SetAttribute("value", shade_to_string(slot.shade()).c_str());
}

// Pixel-perfect
if (flags & int(BrushSlot::Flags::PixelPerfect)) {
TiXmlElement elem("pixelperfect");
elem.SetAttribute("value", slot.pixelPerfect() ? "true": "false");
brushElem.InsertEndChild(elem);
XMLElement* elem = brushElem->InsertNewChildElement("pixelperfect");
elem->SetAttribute("value", slot.pixelPerfect() ? "true": "false");
}
}

brushesElem.InsertEndChild(brushElem);
}

TiXmlDeclaration declaration("1.0", "utf-8", "");
doc->InsertEndChild(declaration);
doc->InsertEndChild(brushesElem);
save_xml(doc, filename);
save_xml(doc.get(), filename);
}

// static
Expand Down

0 comments on commit c904a78

Please sign in to comment.