Skip to content

Commit 6f3b0b3

Browse files
committed
feat(api): #453 Introduce Font
1 parent dc7e0f0 commit 6f3b0b3

File tree

4 files changed

+208
-0
lines changed

4 files changed

+208
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* This file is part of adventure, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2017-2021 KyoriPowered
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package net.kyori.adventure.text.format;
25+
26+
import java.util.Objects;
27+
import java.util.stream.Stream;
28+
import net.kyori.adventure.key.Key;
29+
import net.kyori.examination.Examinable;
30+
import net.kyori.examination.ExaminableProperty;
31+
import org.jetbrains.annotations.NotNull;
32+
33+
/**
34+
* Font.
35+
*
36+
* @since 4.10.0
37+
*/
38+
public interface Font extends Examinable, StyleBuilderApplicable {
39+
/**
40+
* Creates a {@code Font}.
41+
*
42+
* @param font the font
43+
* @return a {@code Font}
44+
* @since 4.10.0
45+
*/
46+
static @NotNull Font font(final @NotNull Key font) {
47+
Objects.requireNonNull(font, "font");
48+
return new FontImpl(font);
49+
}
50+
51+
/**
52+
* Gets the font.
53+
*
54+
* @return the font
55+
* @since 4.10.0
56+
*/
57+
@NotNull Key font();
58+
59+
@Override
60+
default void styleApply(final Style.@NotNull Builder style) {
61+
style.font(this.font());
62+
}
63+
64+
@Override
65+
default @NotNull Stream<? extends ExaminableProperty> examinableProperties() {
66+
return Stream.of(ExaminableProperty.of("font", this.font()));
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* This file is part of adventure, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2017-2021 KyoriPowered
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package net.kyori.adventure.text.format;
25+
26+
import java.util.Objects;
27+
import net.kyori.adventure.key.Key;
28+
import net.kyori.adventure.util.internal.Internals;
29+
import org.jetbrains.annotations.NotNull;
30+
import org.jetbrains.annotations.Nullable;
31+
32+
final class FontImpl implements Font {
33+
private final Key font;
34+
35+
FontImpl(final Key font) {
36+
this.font = font;
37+
}
38+
39+
@Override
40+
public @NotNull Key font() {
41+
return this.font;
42+
}
43+
44+
@Override
45+
public boolean equals(final @Nullable Object other) {
46+
if (this == other) return true;
47+
if (!(other instanceof Font)) return false;
48+
final Font that = (Font) other;
49+
return this.font.equals(that.font());
50+
}
51+
52+
@Override
53+
public int hashCode() {
54+
return Objects.hash(this.font);
55+
}
56+
57+
@Override
58+
public String toString() {
59+
return Internals.toString(this);
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* This file is part of adventure, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2017-2021 KyoriPowered
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package net.kyori.adventure.util.internal;
25+
26+
import net.kyori.examination.Examinable;
27+
import net.kyori.examination.string.StringExaminer;
28+
import org.jetbrains.annotations.ApiStatus;
29+
import org.jetbrains.annotations.NotNull;
30+
31+
/**
32+
* Utilities internal to Adventure.
33+
*
34+
* @since 4.10.0
35+
*/
36+
@ApiStatus.Internal
37+
public final class Internals {
38+
private Internals() {
39+
}
40+
41+
/**
42+
* Generates a string representation of an {@link Examinable}.
43+
*
44+
* @param examinable the examinable
45+
* @return the string representation
46+
* @since 4.10.0
47+
*/
48+
public static @NotNull String toString(final @NotNull Examinable examinable) {
49+
return examinable.examine(StringExaminer.simpleEscaping());
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* This file is part of adventure, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2017-2021 KyoriPowered
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
/**
25+
* Internal utilities.
26+
*/
27+
@org.jetbrains.annotations.ApiStatus.Internal
28+
package net.kyori.adventure.util.internal;

0 commit comments

Comments
 (0)