Debian Codegraph @

src/com/github/weisj/jsvg/nodes/animation/BaseAnimationNode.java

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 /*
2 * MIT License
3 *
4 * Copyright (c) 2024-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.nodes.animation;
23
24 import org.jetbrains.annotations.NotNull;
25 import org.jetbrains.annotations.Nullable;
26
27 import com.github.weisj.jsvg.animation.Additive;
28 import com.github.weisj.jsvg.animation.AnimationValuesType;
29 import com.github.weisj.jsvg.animation.Track;
30 import com.github.weisj.jsvg.nodes.AbstractSVGNode;
31 import com.github.weisj.jsvg.parser.impl.AttributeNode;
32 import com.github.weisj.jsvg.parser.impl.SeparatorMode;
33
34 public abstract class BaseAnimationNode extends AbstractSVGNode {
35
36 // Note: Needs to be replaced by the additive neutral element of the type.
37 private static final @NotNull String INITIAL_PLACEHOLDER = "<<initial>>";
38
39 protected String[] values;
40 protected @Nullable Track track;
41
42 BaseAnimationNode() {}
43
44 public static @Nullable String attributeName(@NotNull AttributeNode attributeNode) {
45 return attributeNode.getValue("attributeName");
46 }
47
48 @SuppressWarnings("ReferenceEquality")
49 protected static boolean isPlaceholder(@NotNull String value) {
50 return value == INITIAL_PLACEHOLDER;
51 }
52
53 @Override
54 public void build(@NotNull AttributeNode attributeNode) {
55 super.build(attributeNode);
56
57 String from = attributeNode.getValue("from");
58 String to = attributeNode.getValue("to");
59 String by = attributeNode.getValue("by");
60
61 if (to != null) by = null;
62
63 AnimationValuesType valuesType = null;
64 if (attributeNode.getValue("values") != null) {
65 values = attributeNode.getStringList("values", SeparatorMode.SEMICOLON_ONLY);
66 valuesType = AnimationValuesType.VALUES;
67 } else {
68 if (from != null && to != null) {
69 values = new String[] {from, to};
70 valuesType = AnimationValuesType.FROM_TO;
71 } else if (from != null && by != null) {
72 values = new String[] {from, by};
73 valuesType = AnimationValuesType.FROM_BY;
74 } else if (by != null) {
75 values = new String[] {INITIAL_PLACEHOLDER, by};
76 valuesType = AnimationValuesType.BY;
77 } else if (to != null) {
78 values = new String[] {INITIAL_PLACEHOLDER, to};
79 valuesType = AnimationValuesType.TO;
80 }
81 }
82
83 if (valuesType != null) {
84 Additive additive = valuesType.endIsBy()
85 ? Additive.SUM
86 : attributeNode.getEnum("additive", Additive.REPLACE);
87 track = Track.parse(attributeNode, valuesType, additive);
88 }
89 }
90
91 public @Nullable Track track() {
92 return track;
93 }
94 }