Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
24e4a25
Accept baseline for NoiseFilter SVG export test.
zfw1234567 Jun 4, 2026
51084c1
Add NoiseStyle node definition and SVG export support
zfw1234567 Jun 5, 2026
60b8865
Remove NoiseFilterWithShadow test case
zfw1234567 Jun 5, 2026
d6f138f
Add NoiseFilter test for all element types and update feOffset to use…
zfw1234567 Jun 5, 2026
7f78297
Fix SVG contentBounds for Repeater and add second test group with lay…
zfw1234567 Jun 5, 2026
3ce4ced
Align ComputeElementBounds with tgfx rendering for Path, Group and Te…
zfw1234567 Jun 7, 2026
f88a1b7
Add Text::contentBounds and use it in ComputeElementBounds for SVG fi…
zfw1234567 Jun 7, 2026
1034537
Use TextBlob getTightBounds for precise Text contentBounds aligned wi…
zfw1234567 Jun 7, 2026
7328118
Add fontFamily and fontStyle to Text elements in NoiseFilterAllElemen…
zfw1234567 Jun 7, 2026
3b4b399
Use system Helvetica font in NoiseFilterAllElements test for consiste…
zfw1234567 Jun 7, 2026
1de37eb
Remove feOffset from noise filter SVG export and use stitchTiles=stit…
zfw1234567 Jun 8, 2026
940b6da
Align Multi noise filter SVG export with Figma using feComponentTrans…
zfw1234567 Jun 8, 2026
54a88d8
Align Multi noise SVG export with tgfx MakeDarkDensityFilter and remo…
zfw1234567 Jun 8, 2026
84b21d1
Fix CR issues: TextBox empty bounds early return, ComputeLayerBounds …
zfw1234567 Jun 8, 2026
71a68e3
Add NoiseFilterWithDropShadow test case with large shadow offset for …
zfw1234567 Jun 8, 2026
4098cb4
Apply code formatting to SVGExporter.cpp.
zfw1234567 Jun 8, 2026
493f125
Remove NoiseFilterOnText and NoiseFilterWithDropShadow test cases.
zfw1234567 Jun 8, 2026
330c852
Accept screenshot baseline for NoiseFilter tests.
zfw1234567 Jun 8, 2026
fedb2f8
Add NoiseStyleWithDropShadow test case for DuoNoiseStyle plus DropSha…
zfw1234567 Jun 8, 2026
d70000c
Change test to DuoNoiseFilter plus DropShadowStyle for cross-testing …
zfw1234567 Jun 8, 2026
7ef1187
Remove contentBounds parameter from SVG filter and style export pipel…
zfw1234567 Jun 8, 2026
84cc33c
Update baseline versions for noise filter tests after content simplif…
zfw1234567 Jun 8, 2026
275aabc
Remove NoiseFilterWithDropShadowStyle test case and its baseline entry.
zfw1234567 Jun 8, 2026
19fe1c4
Fix rebase conflict resolution issues in PAGXTest.cpp.
zfw1234567 Jun 8, 2026
87bb94c
Add NoiseStyleModes test covering Mono, Duo and Multi noise styles fo…
zfw1234567 Jun 9, 2026
1af0759
Fix writeShadowMerge skipping feMerge when only NoiseStyle exists wit…
zfw1234567 Jun 9, 2026
5011c3a
Accept screenshot baseline for NoiseStyleModes test.
zfw1234567 Jun 9, 2026
a4326a3
Add section separator for noise filter primitives in SVGExporter.
zfw1234567 Jun 9, 2026
e05133a
Fix merged separator lines in PAGXTest.cpp to match origin/main format.
zfw1234567 Jun 9, 2026
3d0e359
Restore blank lines between section separators and test cases in PAGX…
zfw1234567 Jun 9, 2026
3ed9283
Remove unused Text::contentBounds and TextBox::contentBounds functions.
zfw1234567 Jun 9, 2026
591fa99
Remove unused includes for GlyphRunRenderer in Text and TextBox.
zfw1234567 Jun 9, 2026
42a9333
Merge branch 'main' into feature/fengweizou_noise_svg_export
zfw1234567 Jun 9, 2026
4946b97
Add animation binding support for NoiseFilter and NoiseStyle.
zfw1234567 Jun 10, 2026
2813c87
Add animation binding tests for NoiseFilter and NoiseStyle channels.
zfw1234567 Jun 10, 2026
8498ae0
Update noise animation test with 40-frame export across 4 modes and c…
zfw1234567 Jun 10, 2026
a218983
Accept screenshot baseline for NoiseFilter animation export test.
zfw1234567 Jun 10, 2026
71a6baf
Revert package-lock.json to origin/main version.
zfw1234567 Jun 10, 2026
ae79c84
Reduce noise animation export test from 40 frames to 12 frames.
zfw1234567 Jun 10, 2026
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
8 changes: 8 additions & 0 deletions include/pagx/nodes/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ enum class NodeType {
* A background blur layer style.
*/
BackgroundBlurStyle,
/**
* A noise layer style.
*/
NoiseStyle,

// Layer Filters
/**
Expand All @@ -139,6 +143,10 @@ enum class NodeType {
* A color matrix filter.
*/
ColorMatrixFilter,
/**
* A noise filter.
*/
NoiseFilter,

// Elements (geometry, painters, modifiers, containers)
/**
Expand Down
92 changes: 92 additions & 0 deletions include/pagx/nodes/NoiseFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// 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 "pagx/nodes/LayerFilter.h"
#include "pagx/types/BlendMode.h"
#include "pagx/types/Color.h"
#include "pagx/types/NoiseMode.h"

namespace pagx {

/**
* A noise filter that overlays procedural Perlin noise on the layer. Three noise modes are
* available: Mono (single color), Duo (two complementary colors), and Multi (preserving original
* noise RGB with enhanced contrast).
*/
class NoiseFilter : public LayerFilter {
public:
/**
* The noise mode. The default value is Mono.
*/
NoiseMode mode = NoiseMode::Mono;

/**
* The noise grain size. Larger values produce coarser grains. Must be positive. The default value
* is 4.0.
*/
float size = 4.0f;

/**
* The noise density in [0, 1]. Controls the proportion of visible noise pixels. The default value
* is 0.5.
*/
float density = 0.5f;

/**
* The random seed for the noise pattern. The default value is 0.
*/
float seed = 0.0f;

/**
* The blend mode used to composite the noise with the source image. The default value is Normal.
*/
BlendMode blendMode = BlendMode::Normal;

/**
* The noise color for Mono mode. The alpha component controls the noise opacity.
*/
Color color = {};

/**
* The first noise color for Duo mode. The alpha component controls its opacity.
*/
Color firstColor = {};

/**
* The second noise color for Duo mode. The alpha component controls its opacity.
*/
Color secondColor = {};

/**
* The overall noise opacity for Multi mode, in [0, 1]. The default value is 0.15.
*/
float opacity = 0.15f;

NodeType nodeType() const override {
return NodeType::NoiseFilter;
}

private:
NoiseFilter() = default;

friend class PAGXDocument;
};

} // namespace pagx
86 changes: 86 additions & 0 deletions include/pagx/nodes/NoiseStyle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// 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 "pagx/nodes/LayerStyle.h"
#include "pagx/types/Color.h"
#include "pagx/types/NoiseMode.h"

namespace pagx {

/**
* A noise layer style that overlays procedural Perlin noise above the layer content. Three noise
* modes are available: Mono (single color), Duo (two complementary colors), and Multi (preserving
* original noise RGB with enhanced contrast).
*/
class NoiseStyle : public LayerStyle {
Comment on lines +28 to +32

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[API 设计 / 文档] NoiseStyle 同时暴露了 color(Mono 用)、firstColor/secondColor(Duo 用)、opacity(Multi 用)四个字段,但任意时刻只有一组生效。这种"扁平字段 + mode 切换"的设计是相对 tgfx 的子类层次(MonoNoiseStyle/DuoNoiseStyle/MultiNoiseStyle)的折衷,便于用户构造,但带来副作用:

  1. 用户从代码层面看不出哪些字段必须设置(Issue 请问下 ios有没有可以监听动画播放实时进度的API #5 默认值问题就是这个的副作用);
  2. 序列化/反序列化无法决定要不要写出未使用的字段;
  3. 引发 bindNoiseStyleChannels 中的 UB 风险(见 LayerBuilder.cpp 行级评论)。

建议在 class doc(这段顶部注释)中明确写出:"非当前 mode 对应的字段会被忽略;切换 mode 后请重新设置对应字段。"目前的字段级注释"used in X mode"较容易被忽略。

NoiseFilter.h 同样建议。

public:
/**
* The noise mode. The default value is Mono.
*/
NoiseMode mode = NoiseMode::Mono;

/**
* The noise grain size. Larger values produce coarser grains. Must be positive. The default value
* is 4.0.
*/
float size = 4.0f;

/**
* The noise density in [0, 1]. Controls the proportion of visible noise pixels. The default value
* is 0.5.
*/
float density = 0.5f;

/**
* The random seed for the noise pattern. The default value is 0.
*/
float seed = 0.0f;

/**
* The noise color for Mono mode. The alpha component controls the noise opacity.
*/
Color color = {};

/**
* The first noise color for Duo mode. The alpha component controls its opacity.
*/
Color firstColor = {};

/**
* The second noise color for Duo mode. The alpha component controls its opacity.
*/
Color secondColor = {};
Comment on lines +59 to +69

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[API 易用性] pagx::Color 默认 alpha = 1(见 pagx/types/Color.h:47),所以这三处 Color color = {} / Color firstColor = {} / Color secondColor = {} 实际值都是不透明黑 (0,0,0,1)

这意味着用户构造 Duo 模式但忘记同时设置 firstColorsecondColor 时,得到的是两个不透明黑——视觉上等同于禁用了 Duo 双色效果。

对应的 tgfx 端默认值更合理:MonoNoiseStyle._color = Color::Black()DuoNoiseStyle._firstColor = Black()_secondColor = White()(见 third_party/tgfx/include/tgfx/layers/layerstyles/NoiseStyle.h:154/201/202)。

建议让 pagx 默认值与 tgfx 一致,至少 secondColor 默认为白色:

Color secondColor = {1.0f, 1.0f, 1.0f, 1.0f};

NoiseFilter.h 同样问题。


/**
* The overall noise opacity for Multi mode, in [0, 1]. The default value is 0.15.
*/
float opacity = 0.15f;

NodeType nodeType() const override {
return NodeType::NoiseStyle;
}

private:
NoiseStyle() = default;

friend class PAGXDocument;
};

} // namespace pagx
2 changes: 1 addition & 1 deletion include/pagx/nodes/TextBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class TextBox : public Group {
return NodeType::TextBox;
}

protected:
protected:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[代码规范] 这一处 protected: 前导空格被去掉,与 PR 主题(noise)无关,是 stray 改动。且与项目其他兄弟类不一致——例如 include/pagx/nodes/Group.h:91 使用 protected:(1 空格)。建议还原此行,或在本地运行 ./codeformat.sh 重新格式化。

void onMeasure(LayoutContext* context) override;
void setLayoutSize(LayoutContext* context, float targetWidth, float targetHeight) override;
void updateLayout(LayoutContext* context) override;
Expand Down
41 changes: 41 additions & 0 deletions include/pagx/types/NoiseMode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// 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

namespace pagx {

/**
* Noise modes for the NoiseFilter.
*/
enum class NoiseMode {
/**
* Single-color noise. Noise pixels are filled with one color.
*/
Mono,
/**
* Dual-color noise. The noise source is split into two complementary regions.
*/
Duo,
/**
* Multi-color noise preserving original Perlin noise RGB with enhanced contrast.
*/
Multi
};

} // namespace pagx
Loading
Loading