|
1 | 1 | package io.github.chrimle.fontmeter.fonts; |
2 | 2 |
|
3 | 3 | import java.util.Map; |
| 4 | +import java.util.Optional; |
4 | 5 |
|
5 | 6 | /** |
6 | 7 | * Just an abstraction-layer for {@link FontMetrics}. Contains the interfaces for the {@link |
@@ -47,6 +48,46 @@ default Double getNullableCharacterWidth(final Character character, final int fo |
47 | 48 | Double getNullableCharacterWidth(final char character, final int fontSize) |
48 | 49 | throws IllegalArgumentException; |
49 | 50 |
|
| 51 | + /** |
| 52 | + * Gets the <strong>width</strong> of the given {@code character} and {@code fontSize}. If the |
| 53 | + * {@code character} is not supported, {@link Optional#empty()} is returned. if the |
| 54 | + * <strong>width</strong> cannot be determined, by not having it pre-calculated, or if <em>this |
| 55 | + * instance</em> does not support "on-demand" calculations, then {@link Optional#empty()} is |
| 56 | + * returned. |
| 57 | + * |
| 58 | + * @param character to get the <strong>width</strong> of. <strong>MUST NOT</strong> be {@code |
| 59 | + * null}. |
| 60 | + * @param fontSize of the {@code character}. <strong>MUST</strong> be positive. |
| 61 | + * @return the width of the {@code character}, in <em>points (pt)</em>. <strong>MAY</strong> be |
| 62 | + * {@link Optional#empty()} if the {@code width} cannot be determined. |
| 63 | + * @throws NullPointerException if {@code character} is {@code null}. |
| 64 | + * @throws IllegalArgumentException if {@code fontSize} is negative, or zero. |
| 65 | + * @since 0.1.0 |
| 66 | + */ |
| 67 | + default Optional<Double> getOptionalCharacterWidth( |
| 68 | + final Character character, final int fontSize) { |
| 69 | + return getOptionalCharacterWidth(character.charValue(), fontSize); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Gets the <strong>width</strong> of the given {@code character} and {@code fontSize}. If the |
| 74 | + * {@code character} is not supported, {@link Optional#empty()} is returned. if the |
| 75 | + * <strong>width</strong> cannot be determined, by not having it pre-calculated, or if <em>this |
| 76 | + * instance</em> does not support "on-demand" calculations, then {@link Optional#empty()} is |
| 77 | + * returned. |
| 78 | + * |
| 79 | + * @param character to get the <strong>width</strong> of. <strong>MUST NOT</strong> be {@code |
| 80 | + * null}. |
| 81 | + * @param fontSize of the {@code character}. <strong>MUST</strong> be positive. |
| 82 | + * @return the width of the {@code character}, in <em>points (pt)</em>. <strong>MAY</strong> be |
| 83 | + * {@link Optional#empty()} if the {@code width} cannot be determined. |
| 84 | + * @throws IllegalArgumentException if {@code fontSize} is negative, or zero. |
| 85 | + * @since 0.1.0 |
| 86 | + */ |
| 87 | + default Optional<Double> getOptionalCharacterWidth(final char character, final int fontSize) { |
| 88 | + return Optional.ofNullable(getNullableCharacterWidth(character, fontSize)); |
| 89 | + } |
| 90 | + |
50 | 91 | /** |
51 | 92 | * The <em>Builder</em>-step for configuring the <em>baseline</em> for {@link IFontMetrics}. The |
52 | 93 | * <em>baseline</em> is a {@link Map} of supported {@link Character}s and their respective |
|
0 commit comments