Debian Codegraph @

src/com/github/weisj/jsvg/attributes/font/FontStyle.java

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 /*
2 * MIT License
3 *
4 * Copyright (c) 2021-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.attributes.font;
23
24 import java.awt.geom.AffineTransform;
25 import java.util.Objects;
26
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
29
30 import com.github.weisj.jsvg.annotations.Sealed;
31 import com.github.weisj.jsvg.geometry.size.Angle;
32 import com.github.weisj.jsvg.geometry.size.AngleUnit;
33
34 /**
35 * This abstract class shouldn't be extended besides those constants.
36 */
37 @Sealed(permits = {FontStyle.Normal.class, FontStyle.Italic.class, FontStyle.Oblique.class})
38 abstract class FontStyle {
39
40 private FontStyle() {}
41
42 public @Nullable AffineTransform transform() {
43 return null;
44 }
45
46 public static @NotNull FontStyle normal() {
47 return Normal.INSTANCE;
48 }
49
50 public static @NotNull FontStyle italic() {
51 return Italic.INSTANCE;
52 }
53
54 public static @NotNull FontStyle oblique() {
55 return Oblique.DEFAULT;
56 }
57
58 public static @NotNull FontStyle oblique(@NotNull Angle angle) {
59 return new Oblique(angle);
60 }
61
62 static final class Normal extends FontStyle {
63 private static final @NotNull FontStyle.Normal INSTANCE = new Normal();
64
65 @Override
66 public String toString() {
67 return "Normal";
68 }
69
70 @Override
71 public boolean equals(Object obj) {
72 return obj instanceof Normal;
73 }
74
75 @Override
76 public int hashCode() {
77 return Normal.class.hashCode();
78 }
79 }
80
81 static final class Italic extends FontStyle {
82 private static final @NotNull FontStyle.Italic INSTANCE = new Italic();
83
84 @Override
85 public String toString() {
86 return "Italic";
87 }
88
89 @Override
90 public boolean equals(Object obj) {
91 return obj instanceof Italic;
92 }
93
94 @Override
95 public int hashCode() {
96 return Italic.class.hashCode();
97 }
98 }
99
100 static final class Oblique extends FontStyle {
101 public static final @NotNull Angle DEFAULT_ANGLE = new Angle(AngleUnit.Deg, 14);
102 public static final @NotNull FontStyle.Oblique DEFAULT = new Oblique(DEFAULT_ANGLE);
103
104 private final @NotNull Angle angle;
105
106 public Oblique(@NotNull Angle angle) {
107 this.angle = angle;
108 }
109
110 @Override
111 public @NotNull AffineTransform transform() {
112 return AffineTransform.getShearInstance(-angle.radians(), 0);
113 }
114
115 @Override
116 public String toString() {
117 return "Oblique{" + angle + '}';
118 }
119
120 @Override
121 public boolean equals(Object o) {
122 if (this == o) return true;
123 if (!(o instanceof Oblique)) return false;
124 Oblique that = (Oblique) o;
125 return angle.equals(that.angle);
126 }
127
128 @Override
129 public int hashCode() {
130 return Objects.hashCode(angle);
131 }
132 }
133 }