Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/pagx/svg/SVGBlendMode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2026 Tencent. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// unless required by applicable law or agreed to in writing, software distributed under the
// license is distributed on an "as is" basis, without warranties or conditions of any kind,
// either express or implied. see the license for the specific language governing permissions
// and limitations under the license.
//
/////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#include <string>
#include "pagx/types/BlendMode.h"

namespace pagx {

struct SVGBlendModeEntry {
BlendMode mode = BlendMode::Normal;
const char* name = nullptr;
};

static constexpr SVGBlendModeEntry SVG_BLEND_MODES[] = {
{BlendMode::Normal, "normal"},
{BlendMode::Multiply, "multiply"},
{BlendMode::Screen, "screen"},
{BlendMode::Overlay, "overlay"},
{BlendMode::Darken, "darken"},
{BlendMode::Lighten, "lighten"},
{BlendMode::ColorDodge, "color-dodge"},
{BlendMode::ColorBurn, "color-burn"},
{BlendMode::HardLight, "hard-light"},
{BlendMode::SoftLight, "soft-light"},
{BlendMode::Difference, "difference"},
{BlendMode::Exclusion, "exclusion"},
{BlendMode::Hue, "hue"},
{BlendMode::Saturation, "saturation"},
{BlendMode::Color, "color"},
{BlendMode::Luminosity, "luminosity"},
};

inline const char* BlendModeToSVGString(BlendMode mode) {
for (const auto& entry : SVG_BLEND_MODES) {
if (entry.mode == mode) {
return entry.name;
}
}
return nullptr;
Comment thread
OnionsYu marked this conversation as resolved.
}

inline BlendMode SVGBlendModeFromString(const std::string& str) {
for (const auto& entry : SVG_BLEND_MODES) {
if (str == entry.name) {
return entry.mode;
}
}
return BlendMode::Normal;
}

} // namespace pagx
6 changes: 6 additions & 0 deletions src/pagx/svg/SVGImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "pagx/PAGXDocument.h"
#include "pagx/nodes/Image.h"
#include "pagx/nodes/SolidColor.h"
#include "pagx/svg/SVGBlendMode.h"
#include "pagx/svg/SVGParserContext.h"
#include "pagx/svg/SVGPathParser.h"
#include "pagx/utils/StringParser.h"
Expand Down Expand Up @@ -388,6 +389,11 @@ Layer* SVGParserContext::convertToLayer(const std::shared_ptr<DOMNode>& element,
layer->alpha = strtof(opacity.c_str(), nullptr);
}

std::string mixBlendMode = getAttribute(element, "mix-blend-mode");
if (!mixBlendMode.empty()) {
layer->blendMode = SVGBlendModeFromString(mixBlendMode);
}

// Handle mask attribute.
std::string maskAttr = getAttribute(element, "mask");
if (!maskAttr.empty() && maskAttr != "none") {
Expand Down
2 changes: 1 addition & 1 deletion test/baseline/version.json
Original file line number Diff line number Diff line change
Expand Up @@ -8603,7 +8603,7 @@
"5.7_multiple_fills": "625e411a",
"5.7_multiple_painters": "625e411a",
"5.7_multiple_strokes": "625e411a",
"Baseline": "31df77d3f",
"Baseline": "8932fe04",
"C.1_complete_example": "004b53bf",
"C.2_app_icons": "6a97e0e73",
"C.3_nebula_cadet": "f0958ddd1",
Expand Down
Loading