Debian Codegraph @

src/com/github/weisj/jsvg/parser/resources/impl/MissingImageResource.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.resources.impl;
23
24 import java.awt.geom.AffineTransform;
25 import java.io.ByteArrayInputStream;
26 import java.nio.charset.StandardCharsets;
27
28 import org.jetbrains.annotations.NotNull;
29
30 import com.github.weisj.jsvg.SVGDocument;
31 import com.github.weisj.jsvg.parser.LoaderContext;
32 import com.github.weisj.jsvg.parser.SVGLoader;
33 import com.github.weisj.jsvg.parser.resources.RenderableResource;
34 import com.github.weisj.jsvg.renderer.RenderContext;
35 import com.github.weisj.jsvg.renderer.output.Output;
36 import com.github.weisj.jsvg.util.supplier.LazySupplier;
37 import com.github.weisj.jsvg.view.FloatSize;
38 import com.github.weisj.jsvg.view.ViewBox;
39
40 public final class MissingImageResource implements RenderableResource {
41 private static final int SIZE = 100;
42 private static final LazySupplier<SVGDocument> missingImage = new LazySupplier<>(() -> {
43 SVGLoader loader = new SVGLoader();
44 return loader.load(new ByteArrayInputStream(
45 ("<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" x=\"0px\"\n" +
46 " y=\"0px\" viewBox=\"0 0 16 16\">\n" +
47 " <g fill=\"#9AA7B0\">\n" +
48 " <rect x=\"1\" y=\"1\" width=\"1\" height=\"11.3\"/>\n" +
49 " <rect x=\"2\" y=\"1\" width=\"12\" height=\"1\"/>\n" +
50 " <path d=\"M7,12.5c0-0.1,0-0.1,0-0.2H1v1h6.1C7,13,7,12.8,7,12.5z\"/>\n" +
51 " <path d=\"M15,9.7V1h-1v7.8C14.4,9,14.7,9.3,15,9.7z\"/>\n" +
52 " </g>\n" +
53 " <path fill=\"#40B6E0\"\n" +
54 " d=\"M11.2,8c0.1,0,0.2,0,0.3,0c0.5,0,1,0.1,1.5,0.3V3H3v4.2c0,0,2.9-2.8,4.3-1.4C8.5,6.8,9.8,7.5,11.2,8z M10.5,4.7\n"
55 +
56 "\tc0.6,0,0.8,0.4,0.8,0.9s-0.2,0.8-0.8,0.8c-0.5,0-0.8-0.3-0.8-0.9C9.7,5,9.9,4.7,10.5,4.7z\"/>\n"
57 +
58 " <path fill=\"#62B543\"\n" +
59 " d=\"M9.3,8.6c-0.7-0.4-1.4-0.9-2-1.4C6,5.9,3,8.6,3,8.6v2.8h4.1C7.5,10.2,8.2,9.2,9.3,8.6z\"/>\n"
60 +
61 " <path fill=\"#DB5860\"\n" +
62 " d=\"M15,12.5c0,1.9-1.6,3.5-3.5,3.5S8,14.4,8,12.5S9.6,9,11.5,9S15,10.6,15,12.5\"/>\n"
63 +
64 " <polygon fill=\"#231F20\" opacity=\"0.8\" points=\"13.6,11.1 12.9,10.4 11.5,11.8 10.1,10.4 9.4,11.1 10.8,12.5 9.4,13.9 10.1,14.6 11.5,13.2 12.9,14.6\n"
65 +
66 "\t 13.6,13.9 12.2,12.5 \"/>\n" +
67 "</svg>\n").getBytes(StandardCharsets.UTF_8)),
68 null, LoaderContext.createDefault());
69 });
70
71 @Override
72 public @NotNull FloatSize intrinsicSize(@NotNull RenderContext context) {
73 return new FloatSize(SIZE, SIZE);
74 }
75
76 @Override
77 public void render(@NotNull Output output, @NotNull RenderContext context, @NotNull AffineTransform transform) {
78 output.applyTransform(transform);
79 synchronized (missingImage) {
80 missingImage.get().renderWithPlatform(context.platformSupport(), output, new ViewBox(0, 0, SIZE, SIZE));
81 }
82 }
83 }