From 4546025b6462608a703ea3dd87571b280796630c Mon Sep 17 00:00:00 2001 From: squid233 <60126026+squid233@users.noreply.github.com> Date: Fri, 3 Mar 2023 22:36:31 +0800 Subject: [PATCH] v15.0.01.1 --- README.md | 15 +++ gradle.properties | 2 +- .../org/overrun/unifont/UnifontConst.java | 58 ------------ .../java/org/overrun/unifont/UnifontUtil.java | 94 +++++++++++++++++++ 4 files changed, 110 insertions(+), 59 deletions(-) create mode 100644 README.md delete mode 100644 src/main/java/org/overrun/unifont/UnifontConst.java create mode 100644 src/main/java/org/overrun/unifont/UnifontUtil.java diff --git a/README.md b/README.md new file mode 100644 index 0000000..98f38f6 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Unifont + +This “library” binds the baked bitmap of Unifont, so we don't need to add them for each project. + +## Import + +```groovy +dependencies { + implementation "io.github.over-run:unifont:15.0.01.1" +} +``` + +## Technical Information + +The constants are stored in `UnifontUtil`. diff --git a/gradle.properties b/gradle.properties index 4730dc1..27e93b2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Dfile.encoding=UTF-8 projGroupId=io.github.over-run projArtifactId=unifont projName=unifont -projVersion=15.0.01 +projVersion=15.0.01.1 projDesc=Java Unifont binding projVcs=Over-Run/unifont projBranch=0.x diff --git a/src/main/java/org/overrun/unifont/UnifontConst.java b/src/main/java/org/overrun/unifont/UnifontConst.java deleted file mode 100644 index e9526e0..0000000 --- a/src/main/java/org/overrun/unifont/UnifontConst.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.overrun.unifont; - -/** - * The constants of Unifont. - * - * @author squid233 - * @since 0.1.0 - */ -public final class UnifontConst { - /** - * The path of Plane 0 image. - */ - public static final String PLANE0 = "assets/_overrun/fonts/unifont.png"; - /** - * The path of Plane 0 image for Japanese glyphs. - */ - public static final String PLANE0_JP = "assets/_overrun/fonts/unifont_jp.png"; - /** - * The path of Plane 1 image. - */ - public static final String PLANE1 = "assets/_overrun/fonts/unifont_plane1.png"; - /** - * The width and height of the image. - */ - public static final int IMAGE_SIZE = 4096; - private static final float INV_IMAGE_SIZE = 1.0f / IMAGE_SIZE; - - /** - * Gets the x advance for the given codepoint. - * - * @param codePoint the codepoint. - * @return the x advance. - */ - public static int xAdvance(int codePoint) { - if (codePoint >= ' ' && codePoint <= '~') return 8; - if (codePoint == 0x200C) return 0; - return 16; - } - - /** - * Gets the y advance. - * - * @return the y advance. - */ - public static int yAdvance() { - return 16; - } - - /** - * Normalizes the given UV offset. - * - * @param uv the offset of the image. - * @return the normalized UV. - */ - public static float uv(int uv) { - return (float) uv * INV_IMAGE_SIZE; - } -} diff --git a/src/main/java/org/overrun/unifont/UnifontUtil.java b/src/main/java/org/overrun/unifont/UnifontUtil.java new file mode 100644 index 0000000..77748ae --- /dev/null +++ b/src/main/java/org/overrun/unifont/UnifontUtil.java @@ -0,0 +1,94 @@ +/* + * MIT License + * + * Copyright (c) 2023 Overrun Organization + * + * 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. + */ + +package org.overrun.unifont; + +/** + * The utilities of Unifont. + * + * @author squid233 + * @since 0.1.0 + */ +public final class UnifontUtil { + /** + * The path of Plane 0 image. + */ + public static final String PLANE0 = "assets/_overrun/fonts/unifont.png"; + /** + * The path of Plane 0 image for Japanese glyphs. + */ + public static final String PLANE0_JP = "assets/_overrun/fonts/unifont_jp.png"; + /** + * The path of Plane 1 image. + */ + public static final String PLANE1 = "assets/_overrun/fonts/unifont_plane1.png"; + /** + * The width and height of the image. + */ + public static final int IMAGE_SIZE = 4096; + private static final float INV_IMAGE_SIZE = 1.0f / IMAGE_SIZE; + + /** + * Gets the x advance for the given codepoint. + * + * @param codePoint the codepoint. + * @return the x advance. + */ + public static int xAdvance(int codePoint) { + if (codePoint >= ' ' && codePoint <= '~') return 8; + if (codePoint == 0x200C) return 0; + return 16; + } + + /** + * Gets the y advance. + * + * @return the y advance. + */ + public static int yAdvance() { + return 16; + } + + /** + * Gets the x offset of the given codepoint. + * + * @param codePoint the codepoint. + * @return the x offset. + */ + public static int xOffset(int codePoint) { + return (codePoint % 0x10000 % 0x100) * 16; + } + + /** + * Gets the y offset of the given codepoint. + * + * @param codePoint the codepoint. + * @return the y offset. + */ + public static int yOffset(int codePoint) { + return (codePoint % 0x10000) / 0x100 * 16; + } + + /** + * Normalizes the given UV offset. + * + * @param offset the offset of the image. + * @return the normalized UV. + */ + public static float uv(int offset) { + return (float) offset * INV_IMAGE_SIZE; + } +}