Debian Codegraph @

src/com/github/weisj/jsvg/nodes/animation/Animate.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.nodes.animation;
23
24 import java.awt.*;
25
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
28
29 import com.github.weisj.jsvg.animation.value.*;
30 import com.github.weisj.jsvg.attributes.value.*;
31 import com.github.weisj.jsvg.geometry.size.Length;
32 import com.github.weisj.jsvg.geometry.size.Percentage;
33 import com.github.weisj.jsvg.nodes.prototype.spec.Category;
34 import com.github.weisj.jsvg.nodes.prototype.spec.ElementCategories;
35 import com.github.weisj.jsvg.nodes.prototype.spec.PermittedContent;
36 import com.github.weisj.jsvg.paint.SVGPaint;
37 import com.github.weisj.jsvg.paint.impl.PredefinedPaints;
38 import com.github.weisj.jsvg.paint.impl.RGBColor;
39 import com.github.weisj.jsvg.parser.PaintParser;
40 import com.github.weisj.jsvg.parser.impl.AttributeNode;
41
42 @ElementCategories(Category.Animation)
43 @PermittedContent(categories = {Category.Descriptive})
44 public final class Animate extends BaseAnimationNode {
45 public static final String TAG = "animate";
46
47 @Override
48 public @NotNull String tagName() {
49 return TAG;
50 }
51
52
53 public @Nullable AnimatedLength animatedLength(
54 @NotNull LengthValue initial,
55 PercentageDimension dimension,
56 @NotNull AttributeNode attributeNode) {
57 if (track == null) return null;
58
59 Length[] lengths = new Length[values.length];
60 for (int i = 0; i < values.length; i++) {
61 if (isPlaceholder(values[i])) {
62 lengths[i] = Length.ZERO;
63 } else {
64 lengths[i] = attributeNode.parser().parseLength(values[i], null, dimension);
65 }
66 if (lengths[i] == null) return null;
67 }
68 return new AnimatedLength(track, initial, lengths);
69 }
70
71 public @Nullable AnimatedFloatList animatedFloatList(@NotNull FloatListValue initial,
72 @NotNull AttributeNode attributeNode) {
73 if (track == null) return null;
74
75 float[][] lists = new float[values.length][];
76 for (int i = 0; i < values.length; i++) {
77 if (isPlaceholder(values[i])) {
78 lists[i] = new float[0];
79 } else {
80 lists[i] = attributeNode.parser().parseFloatList(values[i]);
81 }
82 }
83 return new AnimatedFloatList(track, initial, lists);
84 }
85
86 public @Nullable AnimatedPercentage animatedPercentage(@NotNull PercentageValue initial,
87 @NotNull AttributeNode attributeNode) {
88 if (track == null) return null;
89 float[] percentages = new float[this.values.length];
90 for (int i = 0; i < this.values.length; i++) {
91 if (isPlaceholder(values[i])) {
92 percentages[i] = Percentage.ZERO.value();
93 } else {
94 Percentage p = attributeNode.parser().parsePercentage(this.values[i], null);
95 if (p == null) return null;
96 percentages[i] = p.value();
97 }
98 }
99 return new AnimatedPercentage(track, initial, percentages, Percentage.ONE);
100 }
101
102 public @Nullable AnimatedPaint animatedPaint(@NotNull SVGPaint initial, @NotNull AttributeNode attributeNode) {
103 if (track == null) return null;
104 SVGPaint[] paints = new SVGPaint[this.values.length];
105 for (int i = 0; i < this.values.length; i++) {
106 if (isPlaceholder(values[i])) {
107 paints[i] = PredefinedPaints.NONE;
108 } else {
109 SVGPaint p = attributeNode.parsePaint(this.values[i]);
110 if (p == null) return null;
111 paints[i] = p;
112 }
113 }
114 return new AnimatedPaint(track, initial, paints);
115 }
116
117 public @Nullable AnimatedColor animatedColor(@NotNull ColorValue initial, @NotNull AttributeNode attributeNode) {
118 if (track == null) return null;
119 RGBColor[] paints = new RGBColor[this.values.length];
120 for (int i = 0; i < this.values.length; i++) {
121 if (isPlaceholder(values[i])) {
122 paints[i] = new RGBColor(PaintParser.DEFAULT_COLOR);
123 } else {
124 Color c = attributeNode.parser().paintParser().parseColor(this.values[i]);
125 if (c == null) return null;
126 paints[i] = new RGBColor(c);
127 }
128 }
129 return new AnimatedColor(track, initial, paints);
130 }
131 }