Debian Codegraph @

src/com/github/weisj/jsvg/parser/impl/NodeSupplier.java

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 /*
2 * MIT License
3 *
4 * Copyright (c) 2023-2025 Jannis Weis
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
7 * associated documentation files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all copies or
13 * substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
16 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 *
21 */
22 package com.github.weisj.jsvg.parser.impl;
23
24 import java.util.Map;
25 import java.util.TreeMap;
26 import java.util.function.Supplier;
27
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
30
31 import com.github.weisj.jsvg.nodes.*;
32 import com.github.weisj.jsvg.nodes.animation.Animate;
33 import com.github.weisj.jsvg.nodes.animation.AnimateTransform;
34 import com.github.weisj.jsvg.nodes.animation.Set;
35 import com.github.weisj.jsvg.nodes.filter.*;
36 import com.github.weisj.jsvg.nodes.mesh.MeshGradient;
37 import com.github.weisj.jsvg.nodes.mesh.MeshPatch;
38 import com.github.weisj.jsvg.nodes.mesh.MeshRow;
39 import com.github.weisj.jsvg.nodes.text.Text;
40 import com.github.weisj.jsvg.nodes.text.TextPath;
41 import com.github.weisj.jsvg.nodes.text.TextSpan;
42
43 @SuppressWarnings("Convert2MethodRef")
44 public final class NodeSupplier {
45
46 private final Map<String, Supplier<SVGNode>> constructorMap;
47
48 public NodeSupplier() {
49 this(new TreeMap<>(String.CASE_INSENSITIVE_ORDER));
50 }
51
52
53 public NodeSupplier(final @NotNull Map<@NotNull String, @NotNull Supplier<@NotNull SVGNode>> mapImpl) {
54 mapImpl.clear();
55 constructorMap = mapImpl;
56
57 constructorMap.put(Anchor.TAG, () -> new Anchor());
58 constructorMap.put(ClipPath.TAG, () -> new ClipPath());
59 constructorMap.put(Defs.TAG, () -> new Defs());
60 constructorMap.put(Group.TAG, () -> new Group());
61 constructorMap.put(Image.TAG, () -> new Image());
62 constructorMap.put(Marker.TAG, () -> new Marker());
63 constructorMap.put(Mask.TAG, () -> new Mask());
64 constructorMap.put(SVG.TAG, () -> new SVG());
65 constructorMap.put(Style.TAG, () -> new Style());
66 constructorMap.put(Symbol.TAG, () -> new Symbol());
67 constructorMap.put(Use.TAG, () -> new Use());
68 constructorMap.put(View.TAG, () -> new View());
69
70 populateShapeNodeConstructors();
71 populatePaintNodeConstructors();
72 populateTextNodeConstructors();
73 populateFilterNodeConstructors();
74 populateAnimationNodeConstructors();
75 populateMetaNodeConstructors();
76 populateDummyNodeConstructors();
77 }
78
79 public @Nullable SVGNode create(@NotNull String tagName) {
80 @Nullable Supplier<SVGNode> supplier = constructorMap.get(tagName);
81 if (supplier == null) return null;
82 return supplier.get();
83 }
84
85 private void populateShapeNodeConstructors() {
86 constructorMap.put(Circle.TAG, () -> new Circle());
87 constructorMap.put(Ellipse.TAG, () -> new Ellipse());
88 constructorMap.put(Line.TAG, () -> new Line());
89 constructorMap.put(Path.TAG, () -> new Path());
90 constructorMap.put(Polygon.TAG, () -> new Polygon());
91 constructorMap.put(Polyline.TAG, () -> new Polyline());
92 constructorMap.put(Rect.TAG, () -> new Rect());
93 }
94
95 private void populatePaintNodeConstructors() {
96 constructorMap.put(LinearGradient.TAG, () -> new LinearGradient());
97 constructorMap.put(MeshGradient.TAG, () -> new MeshGradient());
98 constructorMap.put(MeshPatch.TAG, () -> new MeshPatch());
99 constructorMap.put(MeshRow.TAG, () -> new MeshRow());
100 constructorMap.put(Pattern.TAG, () -> new Pattern());
101 constructorMap.put(RadialGradient.TAG, () -> new RadialGradient());
102 constructorMap.put(SolidColor.TAG, () -> new SolidColor());
103 constructorMap.put(Stop.TAG, () -> new Stop());
104 }
105
106 private void populateTextNodeConstructors() {
107 constructorMap.put(Text.TAG, () -> new Text());
108 constructorMap.put(TextPath.TAG, () -> new TextPath());
109 constructorMap.put(TextSpan.TAG, () -> new TextSpan());
110 }
111
112 private void populateFilterNodeConstructors() {
113 constructorMap.put(Filter.TAG, () -> new Filter());
114 constructorMap.put(FeBlend.TAG, () -> new FeBlend());
115 constructorMap.put(FeColorMatrix.TAG, () -> new FeColorMatrix());
116 constructorMap.put(FeComposite.TAG, () -> new FeComposite());
117 constructorMap.put(FeDisplacementMap.TAG, () -> new FeDisplacementMap());
118 constructorMap.put(FeDropShadow.TAG, () -> new FeDropShadow());
119 constructorMap.put(FeFlood.TAG, () -> new FeFlood());
120 constructorMap.put(FeGaussianBlur.TAG, () -> new FeGaussianBlur());
121 constructorMap.put(FeMerge.TAG, () -> new FeMerge());
122 constructorMap.put(FeMergeNode.TAG, () -> new FeMergeNode());
123 constructorMap.put(FeTurbulence.TAG, () -> new FeTurbulence());
124 constructorMap.put(FeOffset.TAG, () -> new FeOffset());
125 constructorMap.put(FeComponentTransfer.TAG, () -> new FeComponentTransfer());
126 constructorMap.put(TransferFunctionElement.FeFuncB.TAG, () -> new TransferFunctionElement.FeFuncB());
127 constructorMap.put(TransferFunctionElement.FeFuncG.TAG, () -> new TransferFunctionElement.FeFuncG());
128 constructorMap.put(TransferFunctionElement.FeFuncR.TAG, () -> new TransferFunctionElement.FeFuncR());
129 constructorMap.put(TransferFunctionElement.FeFuncA.TAG, () -> new TransferFunctionElement.FeFuncA());
130 }
131
132 private void populateAnimationNodeConstructors() {
133 constructorMap.put(Animate.TAG, () -> new Animate());
134 constructorMap.put(AnimateTransform.TAG, () -> new AnimateTransform());
135 constructorMap.put(Set.TAG, () -> new Set());
136 }
137
138 private void populateMetaNodeConstructors() {
139 constructorMap.put(Desc.TAG, () -> new Desc());
140 constructorMap.put(Metadata.TAG, () -> new Metadata());
141 constructorMap.put(Title.TAG, () -> new Title());
142 }
143
144 private void populateDummyNodeConstructors() {
145 constructorMap.put("feConvolveMatrix", () -> new DummyFilterPrimitive("feConvolveMatrix"));
146 constructorMap.put("feDiffuseLightning", () -> new DummyFilterPrimitive("feDiffuseLightning"));
147 constructorMap.put("feImage", () -> new DummyFilterPrimitive("feImage"));
148 constructorMap.put("feMorphology", () -> new DummyFilterPrimitive("feMorphology"));
149 constructorMap.put("feSpecularLighting", () -> new DummyFilterPrimitive("feSpecularLighting"));
150 constructorMap.put("feTile", () -> new DummyFilterPrimitive("feTile"));
151 }
152
153 }