Debian Codegraph @

src/com/github/weisj/jsvg/renderer/output/Output.java

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 /*
2 * MIT License
3 *
4 * Copyright (c) 2024-2026 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.renderer.output;
23
24 import java.awt.*;
25 import java.awt.geom.AffineTransform;
26 import java.awt.geom.Rectangle2D;
27 import java.awt.image.BufferedImage;
28 import java.awt.image.ImageObserver;
29 import java.util.Optional;
30 import java.util.function.Consumer;
31 import java.util.function.Supplier;
32
33 import org.jetbrains.annotations.NotNull;
34 import org.jetbrains.annotations.Nullable;
35
36 import com.github.weisj.jsvg.nodes.text.NullTextOutput;
37 import com.github.weisj.jsvg.renderer.SVGRenderingHints;
38 import com.github.weisj.jsvg.renderer.output.impl.Graphics2DOutput;
39 import com.github.weisj.jsvg.renderer.output.impl.RenderingHintsUtil;
40
41 public interface Output {
42
43 /**
44 * Create a new output for the given graphics context. The output needs to be disposed after use.
45 *
46 * @see #dispose()
47 * @param g The graphics context to create the output for.
48 * @return The output for the given graphics context.
49 */
50 static @NotNull Output createForGraphics(@NotNull Graphics2D g) {
51 Graphics2D g2 = (Graphics2D) g.create();
52 RenderingHintsUtil.setupSVGRenderingHints(g2);
53 return new Graphics2DOutput(g2);
54 }
55
56 void fillShape(@NotNull Shape shape);
57
58 void drawShape(@NotNull Shape shape);
59
60 void drawImage(@NotNull BufferedImage image);
61
62 void drawImage(@NotNull Image image, @Nullable ImageObserver observer);
63
64 void drawImage(@NotNull Image image, @NotNull AffineTransform at, @Nullable ImageObserver observer);
65
66 void setPaint(@NotNull Paint paint);
67
68 /**
69 * Set the paint used for the output. Use this version if computing the paint is expensive.
70 * Outputs which don't support paints can avoid the computation.
71 *
72 * @param paintProvider The paint provider.
73 */
74 void setPaint(@NotNull Supplier<Paint> paintProvider);
75
76 void setStroke(@NotNull Stroke stroke);
77
78 @NotNull
79 Stroke stroke();
80
81 void applyClip(@NotNull Shape clipShape);
82
83 /**
84 * Use {@link #applyClip(Shape)} instead
85 */
86 @Deprecated
87 default void setClip(@Nullable Shape shape) {}
88
89 Optional<Float> contextFontSize();
90
91 @NotNull
92 Output createChild();
93
94 void dispose();
95
96 void debugPaint(@NotNull Consumer<Graphics2D> painter);
97
98 @NotNull
99 Rectangle2D clipBounds();
100
101 @Nullable
102 RenderingHints renderingHints();
103
104 @Nullable
105 Object renderingHint(@NotNull RenderingHints.Key key);
106
107 void setRenderingHint(@NotNull RenderingHints.Key key, @Nullable Object value);
108
109 @NotNull
110 AffineTransform transform();
111
112 void setTransform(@NotNull AffineTransform affineTransform);
113
114 void applyTransform(@NotNull AffineTransform transform);
115
116 void rotate(double angle);
117
118 void scale(double sx, double sy);
119
120 void translate(double dx, double dy);
121
122 float currentOpacity();
123
124 void applyOpacity(float opacity);
125
126 @NotNull
127 SafeState safeState();
128
129 default @NotNull TextOutput textOutput() {
130 return NullTextOutput.INSTANCE;
131 }
132
133 boolean supportsFilters();
134
135 boolean supportsColors();
136
137 default boolean isSoftClippingEnabled() {
138 return renderingHint(SVGRenderingHints.KEY_SOFT_CLIPPING) == SVGRenderingHints.VALUE_SOFT_CLIPPING_ON;
139 }
140
141 default boolean hasMaskedPaint() {
142 return false;
143 }
144
145 interface SafeState {
146 void restore();
147 }
148 }