Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SVG import and rendering features #419

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
af6427b
svg to dom,and svg render
YGaurora Nov 14, 2024
b1db872
commit before context structure refactor
YGaurora Nov 15, 2024
f44ade3
debug and unit test
YGaurora Nov 20, 2024
7ed7413
Merge remote-tracking branch 'origin/main' into feature/svg_parse_to_dom
YGaurora Nov 25, 2024
2d7b6ae
debug render
YGaurora Nov 25, 2024
ab8d893
Merge remote-tracking branch 'origin/main' into feature/svg_parse_to_dom
YGaurora Nov 28, 2024
e24c3e9
format
YGaurora Nov 28, 2024
ccbed6f
typo
YGaurora Nov 28, 2024
0634b65
modify SVGFeGaussianBlur sigma scale
YGaurora Dec 2, 2024
1c6d8f8
save
YGaurora Dec 2, 2024
77ae5bc
formate code
YGaurora Dec 5, 2024
89ad985
...
YGaurora Dec 6, 2024
b481e14
format
YGaurora Dec 12, 2024
6a5cd29
format code
YGaurora Dec 12, 2024
a482430
format
YGaurora Dec 17, 2024
fff9fa5
...
YGaurora Dec 18, 2024
348f70e
Merge remote-tracking branch 'origin/main' into feature/svg_parse_to_dom
YGaurora Dec 18, 2024
0d86fbb
...
YGaurora Dec 18, 2024
dc52e04
Merge remote-tracking branch 'origin/main' into feature/svg_parse_to_dom
YGaurora Dec 23, 2024
e4e18a8
save
YGaurora Dec 24, 2024
19c3c4a
Merge remote-tracking branch 'origin/main' into feature/svg_parse_to_dom
YGaurora Dec 26, 2024
de6c97f
...
YGaurora Dec 26, 2024
4061f68
Merge remote-tracking branch 'origin/main' into feature/svg_parse_to_dom
YGaurora Dec 27, 2024
e5160a5
...
YGaurora Dec 30, 2024
ac521d1
...
YGaurora Dec 30, 2024
13c0a7b
interface for user and base attribute class define
YGaurora Dec 30, 2024
966e60b
...
YGaurora Dec 30, 2024
0a88c2b
。。。
YGaurora Jan 2, 2025
a0083fc
Merge branch 'feature/SVG_parser_interface_base_attr' into feature/sv…
YGaurora Jan 3, 2025
ad18a8c
...
YGaurora Jan 3, 2025
cb1e492
...
YGaurora Jan 3, 2025
bccd2c7
typo
YGaurora Jan 3, 2025
9f60098
typo
YGaurora Jan 3, 2025
ba1c7c2
Merge remote-tracking branch 'origin/main' into feature/svg_parse_to_dom
YGaurora Jan 15, 2025
2beb3f7
SVG render
YGaurora Jan 22, 2025
b6f5bfc
。。。
YGaurora Jan 22, 2025
df5ce50
typo
YGaurora Jan 23, 2025
04e1c44
optimize
YGaurora Jan 24, 2025
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
Prev Previous commit
Next Next commit
...
  • Loading branch information
YGaurora committed Dec 6, 2024
commit 89ad98516ec69d1c712394e9ace6d1a6c897c19d
403 changes: 210 additions & 193 deletions include/tgfx/svg/SVGTypes.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion include/tgfx/svg/SVGValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ class SVGWrapperValue final : public SVGValue {
return &_wrappedValue;
}

private:
// Stack-only
void* operator new(size_t) = delete;
void* operator new(size_t, void*) = delete;

private:
const T& _wrappedValue;

using INHERITED = SVGValue;
Expand Down
2 changes: 1 addition & 1 deletion include/tgfx/svg/node/SVGClipPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SVGClipPath final : public SVGHiddenContainer {
}

SVG_ATTR(ClipPathUnits, SVGObjectBoundingBoxUnits,
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::kUserSpaceOnUse))
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::UserSpaceOnUse))

private:
friend class SVGRenderContext;
Expand Down
12 changes: 6 additions & 6 deletions include/tgfx/svg/node/SVGFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ class SkSVGFilter final : public SVGHiddenContainer {

std::shared_ptr<ImageFilter> buildFilterDAG(const SVGRenderContext&) const;

SVG_ATTR(X, SVGLength, SVGLength(-10, SVGLength::Unit::kPercentage))
SVG_ATTR(Y, SVGLength, SVGLength(-10, SVGLength::Unit::kPercentage))
SVG_ATTR(Width, SVGLength, SVGLength(120, SVGLength::Unit::kPercentage))
SVG_ATTR(Height, SVGLength, SVGLength(120, SVGLength::Unit::kPercentage))
SVG_ATTR(X, SVGLength, SVGLength(-10, SVGLength::Unit::Percentage))
SVG_ATTR(Y, SVGLength, SVGLength(-10, SVGLength::Unit::Percentage))
SVG_ATTR(Width, SVGLength, SVGLength(120, SVGLength::Unit::Percentage))
SVG_ATTR(Height, SVGLength, SVGLength(120, SVGLength::Unit::Percentage))
SVG_ATTR(FilterUnits, SVGObjectBoundingBoxUnits,
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::kObjectBoundingBox))
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::ObjectBoundingBox))
SVG_ATTR(PrimitiveUnits, SVGObjectBoundingBoxUnits,
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::kUserSpaceOnUse))
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::UserSpaceOnUse))

private:
SkSVGFilter() : INHERITED(SVGTag::Filter) {
Expand Down
4 changes: 2 additions & 2 deletions include/tgfx/svg/node/SVGGradient.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class SkSVGGradient : public SVGHiddenContainer {
public:
SVG_ATTR(Href, SVGIRI, SVGIRI())
SVG_ATTR(GradientTransform, SVGTransformType, SVGTransformType(Matrix::I()))
SVG_ATTR(SpreadMethod, SVGSpreadMethod, SVGSpreadMethod(SVGSpreadMethod::Type::kPad))
SVG_ATTR(SpreadMethod, SVGSpreadMethod, SVGSpreadMethod(SVGSpreadMethod::Type::Pad))
SVG_ATTR(GradientUnits, SVGObjectBoundingBoxUnits,
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::kObjectBoundingBox))
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::ObjectBoundingBox))

protected:
explicit SkSVGGradient(SVGTag t) : INHERITED(t) {
Expand Down
8 changes: 4 additions & 4 deletions include/tgfx/svg/node/SVGLinearGradient.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class SkSVGLinearGradient final : public SkSVGGradient {
return std::shared_ptr<SkSVGLinearGradient>(new SkSVGLinearGradient());
}

SVG_ATTR(X1, SVGLength, SVGLength(0, SVGLength::Unit::kPercentage))
SVG_ATTR(Y1, SVGLength, SVGLength(0, SVGLength::Unit::kPercentage))
SVG_ATTR(X2, SVGLength, SVGLength(100, SVGLength::Unit::kPercentage))
SVG_ATTR(Y2, SVGLength, SVGLength(0, SVGLength::Unit::kPercentage))
SVG_ATTR(X1, SVGLength, SVGLength(0, SVGLength::Unit::Percentage))
SVG_ATTR(Y1, SVGLength, SVGLength(0, SVGLength::Unit::Percentage))
SVG_ATTR(X2, SVGLength, SVGLength(100, SVGLength::Unit::Percentage))
SVG_ATTR(Y2, SVGLength, SVGLength(0, SVGLength::Unit::Percentage))

protected:
bool parseAndSetAttribute(const char*, const char*) override;
Expand Down
4 changes: 2 additions & 2 deletions include/tgfx/svg/node/SVGMask.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class SkSVGMask final : public SVGHiddenContainer {
SVG_OPTIONAL_ATTR(Height, SVGLength)

SVG_ATTR(MaskUnits, SVGObjectBoundingBoxUnits,
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::kObjectBoundingBox))
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::ObjectBoundingBox))
SVG_ATTR(MaskContentUnits, SVGObjectBoundingBoxUnits,
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::kUserSpaceOnUse))
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::UserSpaceOnUse))

private:
friend class SVGRenderContext;
Expand Down
4 changes: 2 additions & 2 deletions include/tgfx/svg/node/SVGPattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class SkSVGPattern final : public SVGHiddenContainer {
SVG_OPTIONAL_ATTR(Height, SVGLength)
SVG_OPTIONAL_ATTR(PatternTransform, SVGTransformType)
SVG_ATTR(PatternUnits, SVGObjectBoundingBoxUnits,
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::kObjectBoundingBox))
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::ObjectBoundingBox))
SVG_ATTR(ContentUnits, SVGObjectBoundingBoxUnits,
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::kUserSpaceOnUse))
SVGObjectBoundingBoxUnits(SVGObjectBoundingBoxUnits::Type::UserSpaceOnUse))

protected:
SkSVGPattern();
Expand Down
6 changes: 3 additions & 3 deletions include/tgfx/svg/node/SVGRadialGradient.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class SkSVGRadialGradient final : public SkSVGGradient {
return std::shared_ptr<SkSVGRadialGradient>(new SkSVGRadialGradient());
}

SVG_ATTR(Cx, SVGLength, SVGLength(50, SVGLength::Unit::kPercentage))
SVG_ATTR(Cy, SVGLength, SVGLength(50, SVGLength::Unit::kPercentage))
SVG_ATTR(R, SVGLength, SVGLength(50, SVGLength::Unit::kPercentage))
SVG_ATTR(Cx, SVGLength, SVGLength(50, SVGLength::Unit::Percentage))
SVG_ATTR(Cy, SVGLength, SVGLength(50, SVGLength::Unit::Percentage))
SVG_ATTR(R, SVGLength, SVGLength(50, SVGLength::Unit::Percentage))
SVG_OPTIONAL_ATTR(Fx, SVGLength)
SVG_OPTIONAL_ATTR(Fy, SVGLength)

Expand Down
4 changes: 2 additions & 2 deletions include/tgfx/svg/node/SVGSVG.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class SVGSVG : public SkSVGContainer {

SVG_ATTR(X, SVGLength, SVGLength(0))
SVG_ATTR(Y, SVGLength, SVGLength(0))
SVG_ATTR(Width, SVGLength, SVGLength(100, SVGLength::Unit::kPercentage))
SVG_ATTR(Height, SVGLength, SVGLength(100, SVGLength::Unit::kPercentage))
SVG_ATTR(Width, SVGLength, SVGLength(100, SVGLength::Unit::Percentage))
SVG_ATTR(Height, SVGLength, SVGLength(100, SVGLength::Unit::Percentage))
SVG_ATTR(PreserveAspectRatio, SVGPreserveAspectRatio, SVGPreserveAspectRatio())

SVG_OPTIONAL_ATTR(ViewBox, SVGViewBoxType)
Expand Down
2 changes: 1 addition & 1 deletion include/tgfx/svg/node/SVGStop.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SkSVGStop : public SVGHiddenContainer {
return std::shared_ptr<SkSVGStop>(new SkSVGStop());
}

SVG_ATTR(Offset, SVGLength, SVGLength(0, SVGLength::Unit::kPercentage))
SVG_ATTR(Offset, SVGLength, SVGLength(0, SVGLength::Unit::Percentage))

protected:
bool parseAndSetAttribute(const char*, const char*) override;
Expand Down
18 changes: 9 additions & 9 deletions src/svg/SVGAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ SVGPresentationAttributes SVGPresentationAttributes::MakeInitial() {

result.fFill.set(SVGPaint(SVGColor(Color::Black())));
result.fFillOpacity.set(static_cast<SVGNumberType>(1));
result.fFillRule.set(SVGFillRule(SVGFillRule::Type::kNonZero));
result.fClipRule.set(SVGFillRule(SVGFillRule::Type::kNonZero));
result.fFillRule.set(SVGFillRule(SVGFillRule::Type::NonZero));
result.fClipRule.set(SVGFillRule(SVGFillRule::Type::NonZero));

result.fStroke.set(SVGPaint(SVGPaint::Type::kNone));
result.fStrokeDashArray.set(SVGDashArray(SVGDashArray::Type::kNone));
result.fStroke.set(SVGPaint(SVGPaint::Type::None));
result.fStrokeDashArray.set(SVGDashArray(SVGDashArray::Type::None));
result.fStrokeDashOffset.set(SVGLength(0));
result.fStrokeLineCap.set(SVGLineCap::kButt);
result.fStrokeLineJoin.set(SVGLineJoin(SVGLineJoin::Type::kMiter));
result.fStrokeLineCap.set(SVGLineCap::Butt);
result.fStrokeLineJoin.set(SVGLineJoin(SVGLineJoin::Type::Miter));
result.fStrokeMiterLimit.set(static_cast<SVGNumberType>(4));
result.fStrokeOpacity.set(static_cast<SVGNumberType>(1));
result.fStrokeWidth.set(SVGLength(1));

result.fVisibility.set(SVGVisibility(SVGVisibility::Type::kVisible));
result.fVisibility.set(SVGVisibility(SVGVisibility::Type::Visible));

result.fColor.set(SVGColorType(Color::Black()));
result.fColorInterpolation.set(SVGColorspace::kSRGB);
result.fColorInterpolationFilters.set(SVGColorspace::kLinearRGB);

result.fFontFamily.init("default");
result.fFontStyle.init(SVGFontStyle::Type::kNormal);
result.fFontStyle.init(SVGFontStyle::Type::Normal);
result.fFontSize.init(SVGLength(24));
result.fFontWeight.init(SVGFontWeight::Type::kNormal);
result.fFontWeight.init(SVGFontWeight::Type::Normal);
result.fTextAnchor.init(SVGTextAnchor::Type::kStart);

result.fDisplay.init(SVGDisplay::kInline);
Expand Down
Loading