-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
api/src/main/java/net/kyori/adventure/text/format/Font.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* This file is part of adventure, licensed under the MIT License. | ||
* | ||
* Copyright (c) 2017-2021 KyoriPowered | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package net.kyori.adventure.text.format; | ||
|
||
import java.util.Objects; | ||
import java.util.stream.Stream; | ||
import net.kyori.adventure.key.Key; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.examination.Examinable; | ||
import net.kyori.examination.ExaminableProperty; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* A container around a {@link Component}'s {@link Component#font() font}. | ||
* | ||
* @since 4.10.0 | ||
*/ | ||
public interface Font extends Examinable, StyleBuilderApplicable { | ||
/** | ||
* Creates a {@code Font}. | ||
* | ||
* @param font the font | ||
* @return a {@code Font} | ||
* @since 4.10.0 | ||
*/ | ||
static @NotNull Font font(final @NotNull Key font) { | ||
Objects.requireNonNull(font, "font"); | ||
return new FontImpl(font); | ||
} | ||
|
||
/** | ||
* Gets the font. | ||
* | ||
* @return the font | ||
* @since 4.10.0 | ||
*/ | ||
@NotNull Key font(); | ||
|
||
@Override | ||
default void styleApply(final Style.@NotNull Builder style) { | ||
style.font(this.font()); | ||
} | ||
|
||
@Override | ||
default @NotNull Stream<? extends ExaminableProperty> examinableProperties() { | ||
return Stream.of(ExaminableProperty.of("font", this.font())); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
api/src/main/java/net/kyori/adventure/text/format/FontImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* This file is part of adventure, licensed under the MIT License. | ||
* | ||
* Copyright (c) 2017-2021 KyoriPowered | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package net.kyori.adventure.text.format; | ||
|
||
import java.util.Objects; | ||
import net.kyori.adventure.key.Key; | ||
import net.kyori.adventure.util.internal.Internals; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
final class FontImpl implements Font { | ||
private final Key font; | ||
|
||
FontImpl(final Key font) { | ||
this.font = font; | ||
} | ||
|
||
@Override | ||
public @NotNull Key font() { | ||
return this.font; | ||
} | ||
|
||
@Override | ||
public boolean equals(final @Nullable Object other) { | ||
if (this == other) return true; | ||
if (!(other instanceof Font)) return false; | ||
final Font that = (Font) other; | ||
return this.font.equals(that.font()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.font); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Internals.toString(this); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
api/src/main/java/net/kyori/adventure/util/internal/Internals.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* This file is part of adventure, licensed under the MIT License. | ||
* | ||
* Copyright (c) 2017-2021 KyoriPowered | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package net.kyori.adventure.util.internal; | ||
|
||
import net.kyori.examination.Examinable; | ||
import net.kyori.examination.string.StringExaminer; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Utilities internal to Adventure. | ||
* | ||
* @since 4.10.0 | ||
*/ | ||
@ApiStatus.Internal | ||
public final class Internals { | ||
private Internals() { | ||
} | ||
|
||
/** | ||
* Generates a string representation of an {@link Examinable}. | ||
* | ||
* @param examinable the examinable | ||
* @return the string representation | ||
* @since 4.10.0 | ||
*/ | ||
public static @NotNull String toString(final @NotNull Examinable examinable) { | ||
return examinable.examine(StringExaminer.simpleEscaping()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
api/src/main/java/net/kyori/adventure/util/internal/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* This file is part of adventure, licensed under the MIT License. | ||
* | ||
* Copyright (c) 2017-2021 KyoriPowered | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
/** | ||
* Internal utilities. | ||
*/ | ||
@org.jetbrains.annotations.ApiStatus.Internal | ||
package net.kyori.adventure.util.internal; |