diff --git a/OrangeX/build.gradle b/OrangeX/build.gradle index 9956130..43c82c0 100644 --- a/OrangeX/build.gradle +++ b/OrangeX/build.gradle @@ -24,6 +24,11 @@ dependencies { // Source: https://mvnrepository.com/artifact/org.greenrobot/eventbus implementation 'org.greenrobot:eventbus:3.2.0' + // Legacy OpenGL entry points for the 1.8.9 font backend. This is compile + // only: the 1.8.9 runtime provides its own LWJGL 2, and the 26.2 backend + // never loads these classes. + compileOnly files('../Minecraft1.8.8/runtime/libraries/org/lwjgl/lwjgl/lwjgl/2.9.4-nightly-20150209/lwjgl-2.9.4-nightly-20150209.jar') + // JuiceAgent is provided at runtime by the agent (see JuiceAgentBridge). // Do NOT bundle it: Fabric's KnotClassLoader would load a second copy of // the API whose native methods are not registered. diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/OrangeX.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/OrangeX.java index 231a0ed..7ea6005 100644 --- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/OrangeX.java +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/OrangeX.java @@ -3,6 +3,8 @@ package cn.xiaozhou233.orangex; import cn.xiaozhou233.orangex.event.impl.EventTickPre; import cn.xiaozhou233.orangex.hook.HookManager; import cn.xiaozhou233.orangex.mapping.MappingManager; +import cn.xiaozhou233.orangex.render.FontDebugOverlay; +import cn.xiaozhou233.orangex.render.Render2DManager; import cn.xiaozhou233.orangex.runtime.RuntimeDetector; import cn.xiaozhou233.orangex.runtime.RuntimeInfo; import cn.xiaozhou233.orangex.wrapper.MinecraftFactory; @@ -23,6 +25,8 @@ public class OrangeX { .build(); @Getter private RuntimeInfo runtimeInfo; + @Getter + private Render2DManager render2DManager; public OrangeX() { System.out.println("OrangeX start!"); @@ -39,8 +43,13 @@ public class OrangeX { Minecraft minecraft = MinecraftFactory.create(runtimeInfo, MappingManager.getResolver()); System.out.println(minecraft.getMinecraft()); - // DELETE THIS ON RELEASE: - eventBus.register(this); + render2DManager = new Render2DManager( + runtimeInfo, MappingManager.getResolver(), minecraft.getMinecraft()); + System.out.println("[OrangeX] Font backend: " + render2DManager.getBackendName()); + + if (Boolean.getBoolean("orangex.debugFont")) { + eventBus.register(new FontDebugOverlay()); + } HookManager.getINSTANCE().applyAll(); } @@ -48,9 +57,4 @@ public class OrangeX { public void stop() { System.out.println("OrangeX stop!"); } - - @Subscribe() - public void onTick(EventTickPre event) { - System.out.println("PRE EVENT!"); - } } diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/event/facade/Render2DEvents.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/event/facade/Render2DEvents.java new file mode 100644 index 0000000..00b0999 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/event/facade/Render2DEvents.java @@ -0,0 +1,31 @@ +package cn.xiaozhou233.orangex.event.facade; + +import cn.xiaozhou233.orangex.OrangeX; +import cn.xiaozhou233.orangex.render.Render2DManager; + +/** + * Entry point used by injected code. Always refer to this class by its simple + * name inside Javassist snippets (see docs/hooks.md). + */ +public final class Render2DEvents { + + private static boolean failureLogged; + + public static void fire(Object platformContext) { + try { + Render2DManager manager = OrangeX.getInstance().getRender2DManager(); + if (manager != null) { + manager.fire(platformContext); + } + } catch (Throwable throwable) { + if (!failureLogged) { + failureLogged = true; + System.err.println("[OrangeX] Render2D callback failed"); + throwable.printStackTrace(); + } + } + } + + private Render2DEvents() { + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/event/impl/EventRender2D.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/event/impl/EventRender2D.java new file mode 100644 index 0000000..bc43cc4 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/event/impl/EventRender2D.java @@ -0,0 +1,20 @@ +package cn.xiaozhou233.orangex.event.impl; + +import cn.xiaozhou233.orangex.render.api.Render2D; + +/** + * Fired once per frame while the game collects its GUI. Listeners can queue + * text through {@link #getRender2D()}. + */ +public class EventRender2D { + + private final Render2D render2D; + + public EventRender2D(Render2D render2D) { + this.render2D = render2D; + } + + public Render2D getRender2D() { + return render2D; + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/hook/HookManager.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/hook/HookManager.java index 1440f99..bf4950e 100644 --- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/hook/HookManager.java +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/hook/HookManager.java @@ -16,6 +16,7 @@ public final class HookManager { private HookManager() { register(new TickHook()); + register(new Render2DHook()); } public void register(ClassHook hook) { diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/hook/impl/Render2DHook.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/hook/impl/Render2DHook.java new file mode 100644 index 0000000..666a0a4 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/hook/impl/Render2DHook.java @@ -0,0 +1,105 @@ +package cn.xiaozhou233.orangex.hook.impl; + +import cn.xiaozhou233.orangex.OrangeX; +import cn.xiaozhou233.orangex.hook.ClassHook; +import cn.xiaozhou233.orangex.mapping.MappingManager; +import cn.xiaozhou233.orangex.mapping.MappingMethod; +import cn.xiaozhou233.orangex.mapping.MappingResolver; +import cn.xiaozhou233.orangex.runtime.RuntimeInfo; +import cn.xiaozhou233.orangex.runtime.loader.LoaderType; +import javassist.CtClass; +import javassist.CtMethod; + +/** + * Fires {@link cn.xiaozhou233.orangex.event.impl.EventRender2D} once per frame. + * + * + */ +public final class Render2DHook extends ClassHook { + + private static final RuntimeInfo runtimeInfo = + OrangeX.getInstance().getRuntimeInfo(); + private static final MappingResolver resolver = MappingManager.getResolver(); + + @Override + protected String[] getInjectedClassNames() { + return new String[]{ + "cn.xiaozhou233.orangex.event.facade.Render2DEvents" + }; + } + + @Override + protected String getTargetClass() { + switch (runtimeInfo.getMinecraftVersion()) { + case V1_8_9: + if (runtimeInfo.getLoaderType() == LoaderType.FORGE + && classPresent("net.minecraftforge.client.GuiIngameForge")) { + // Forge replaces the HUD renderer with its own subclass. + return "net.minecraftforge.client.GuiIngameForge"; + } + return resolver.mapClass("net/minecraft/client/gui/GuiIngame") + .getTargetName().replace("/", "."); + case V26_2: + return "net.minecraft.client.gui.Gui"; + default: + return null; + } + } + + private static boolean classPresent(String className) { + try { + Class.forName(className, false, Render2DHook.class.getClassLoader()); + return true; + } catch (Throwable ignored) { + return false; + } + } + + @Override + protected void transform(CtClass ctClass) throws Exception { + switch (runtimeInfo.getMinecraftVersion()) { + case V1_8_9: { + String methodName; + String methodDescriptor; + if (runtimeInfo.getLoaderType() == LoaderType.FORGE + && classPresent("net.minecraftforge.client.GuiIngameForge")) { + // Forge's GuiIngameForge is not obfuscated. + methodName = "renderGameOverlay"; + methodDescriptor = "(F)V"; + } else { + MappingMethod target = resolver.mapMethod( + "net/minecraft/client/gui/GuiIngame", + "renderGameOverlay", + "(F)V"); + methodName = target.getTargetName(); + methodDescriptor = target.getTargetDescriptor(); + } + CtMethod method = ctClass.getMethod(methodName, methodDescriptor); + method.insertAfter("Render2DEvents.fire(null);"); + System.out.println("[OrangeX] Render2DHook injected: " + + ctClass.getName() + "#" + methodName + methodDescriptor); + break; + } + case V26_2: { + MappingMethod target = resolver.mapMethod( + "net/minecraft/client/gui/Gui", + "extractRenderState", + "(Lnet/minecraft/client/DeltaTracker;ZZ)V"); + CtMethod method = ctClass.getMethod( + target.getTargetName(), target.getTargetDescriptor()); + method.insertAfter("Render2DEvents.fire($0);"); + System.out.println("[OrangeX] Render2DHook injected: " + + ctClass.getName() + "#" + target.getTargetName() + + target.getTargetDescriptor()); + break; + } + default: + break; + } + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/FontDebugOverlay.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/FontDebugOverlay.java new file mode 100644 index 0000000..26ad339 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/FontDebugOverlay.java @@ -0,0 +1,40 @@ +package cn.xiaozhou233.orangex.render; + +import cn.xiaozhou233.orangex.event.impl.EventRender2D; +import cn.xiaozhou233.orangex.render.api.FontRenderer; +import cn.xiaozhou233.orangex.render.api.Render2D; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +/** + * Optional debug overlay. Enable with {@code -Dorangex.debugFont=true}. + */ +public final class FontDebugOverlay { + + private static boolean logged; + + @Subscribe(threadMode = ThreadMode.POSTING) + public void onRender2D(EventRender2D event) { + Render2D render2D = event.getRender2D(); + if (!logged) { + logged = true; + System.out.println("[OrangeX] Render2D event: " + + render2D.getWidth() + "x" + render2D.getHeight() + + " scale=" + render2D.getGuiScale()); + } + FontRenderer title = render2D.getFont(14.0f, true); + FontRenderer body = render2D.getFont(10.0f, false); + + title.drawStringWithShadow("OrangeX", 8, 8, 0xFFFFFFFF); + body.drawString("Font backend: " + render2D.getClass().getSimpleName(), + 8, 26, 0xFF55FFFF); + body.drawString("ASCII 0123456789", 8, 40, 0xFFAAAAAA); + body.drawString("中文测试:钻石剑 / 迅捷", 8, 54, 0xFFFFAA00); + + // Large high-contrast marker: if this is invisible too, the problem is + // GL state/coordinates rather than the glyph atlas. + FontRenderer marker = render2D.getFont(28.0f, true); + marker.drawCenteredString("TEST", render2D.getWidth() / 2.0, + render2D.getHeight() / 2.0 - 24.0, 0xFFFF3030); + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/Render2DManager.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/Render2DManager.java new file mode 100644 index 0000000..9414d6e --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/Render2DManager.java @@ -0,0 +1,59 @@ +package cn.xiaozhou233.orangex.render; + +import cn.xiaozhou233.orangex.OrangeX; +import cn.xiaozhou233.orangex.event.impl.EventRender2D; +import cn.xiaozhou233.orangex.mapping.MappingResolver; +import cn.xiaozhou233.orangex.render.api.Render2D; +import cn.xiaozhou233.orangex.render.font.FontManager; +import cn.xiaozhou233.orangex.render.internal.FontBackend; +import cn.xiaozhou233.orangex.render.internal.FontBackendFactory; +import cn.xiaozhou233.orangex.runtime.RuntimeInfo; +import org.greenrobot.eventbus.EventBus; + +/** + * Owns the font cache and turns one platform render callback into an + * {@link EventRender2D}. + */ +public final class Render2DManager { + + private final FontBackend backend; + private final FontManager fonts; + private boolean hookLogged; + + public Render2DManager(RuntimeInfo runtimeInfo, + MappingResolver mappingResolver, + Object minecraft) { + this.backend = FontBackendFactory.create( + runtimeInfo, mappingResolver, minecraft); + this.fonts = new FontManager(backend); + } + + public void fire(Object platformContext) { + EventBus eventBus = OrangeX.getInstance().getEventBus(); + boolean hasSubscribers = eventBus.hasSubscriberForEvent(EventRender2D.class); + if (!hookLogged) { + hookLogged = true; + System.out.println("[OrangeX] Render2D hook fired; subscribers=" + + hasSubscribers + ", context=" + + (platformContext == null ? "null" : platformContext.getClass().getName())); + } + if (!hasSubscribers) { + return; + } + + Render2D context = backend.createRender2D(fonts, platformContext); + try { + eventBus.post(new EventRender2D(context)); + } finally { + context.flush(); + } + } + + public String getBackendName() { + return backend.getName(); + } + + public FontManager getFonts() { + return fonts; + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/api/FontRenderer.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/api/FontRenderer.java new file mode 100644 index 0000000..e1511f5 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/api/FontRenderer.java @@ -0,0 +1,22 @@ +package cn.xiaozhou233.orangex.render.api; + +/** + * A font face bound to the current 2D render pass. + * + *

Instances are created by {@link Render2D#getFont(float)} and must only be + * used during the frame that produced the {@code Render2D} instance.

+ */ +public interface FontRenderer { + + void drawString(String text, double x, double y, int argb); + + void drawStringWithShadow(String text, double x, double y, int argb); + + void drawCenteredString(String text, double centerX, double y, int argb); + + void drawCenteredStringWithShadow(String text, double centerX, double y, int argb); + + double getStringWidth(String text); + + double getStringHeight(); +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/api/Render2D.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/api/Render2D.java new file mode 100644 index 0000000..bd26adf --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/api/Render2D.java @@ -0,0 +1,28 @@ +package cn.xiaozhou233.orangex.render.api; + +/** + * The 2D drawing context for one frame. + * + *

Feature code receives this object through + * {@code cn.xiaozhou233.orangex.event.impl.EventRender2D}. Coordinates and + * sizes are expressed in Minecraft GUI pixels (the same space used by the + * vanilla HUD after {@code ScaledResolution}).

+ */ +public interface Render2D { + + int getWidth(); + + int getHeight(); + + double getGuiScale(); + + FontRenderer getFont(float size); + + FontRenderer getFont(float size, boolean bold); + + /** + * Framework-internal: restores any state the backend changed for this + * frame. Feature code should not call it. + */ + void flush(); +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/FontAtlas.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/FontAtlas.java new file mode 100644 index 0000000..18cd1e3 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/FontAtlas.java @@ -0,0 +1,97 @@ +package cn.xiaozhou233.orangex.render.font; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * A baked font atlas. + * + *

{@link #getPixels()} contains one 8-bit coverage value per texel. The + * backends decide how to upload that data (alpha-only on legacy OpenGL, RGBA + * on modern Minecraft).

+ */ +public final class FontAtlas { + + private final int width; + private final int height; + private byte[] pixels; + private final Map glyphs; + + /** Distance from the top of a line to the baseline, in atlas pixels. */ + private final float ascent; + /** Recommended line height, in atlas pixels. */ + private final float lineHeight; + + private final Glyph[] ascii = new Glyph[128]; + + public FontAtlas(int width, int height, byte[] pixels, + Map glyphs, + float ascent, float lineHeight) { + this.width = width; + this.height = height; + this.pixels = pixels; + this.glyphs = Collections.unmodifiableMap(new HashMap(glyphs)); + this.ascent = ascent; + this.lineHeight = lineHeight; + + for (Map.Entry entry : glyphs.entrySet()) { + int codePoint = entry.getKey(); + if (codePoint >= 0 && codePoint < ascii.length) { + ascii[codePoint] = entry.getValue(); + } + } + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public byte[] getPixels() { + if (pixels == null) { + throw new IllegalStateException("Atlas pixels have already been released"); + } + return pixels; + } + + /** + * Drops the CPU-side coverage bitmap after the texture has been uploaded. + */ + public void releasePixels() { + this.pixels = null; + } + + public float getAscent() { + return ascent; + } + + public float getLineHeight() { + return lineHeight; + } + + public Glyph getGlyph(int codePoint) { + if (codePoint >= 0 && codePoint < ascii.length) { + Glyph glyph = ascii[codePoint]; + if (glyph != null) { + return glyph; + } + } + return glyphs.get(codePoint); + } + + public Glyph getFallbackGlyph() { + Glyph space = getGlyph(' '); + if (space != null) { + return space; + } + return getGlyph('?'); + } + + public Map getGlyphs() { + return glyphs; + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/FontFace.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/FontFace.java new file mode 100644 index 0000000..80cde68 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/FontFace.java @@ -0,0 +1,61 @@ +package cn.xiaozhou233.orangex.render.font; + +import cn.xiaozhou233.orangex.render.internal.FontTexture; + +/** + * A baked atlas plus its GPU texture and the scale needed to draw it at the + * requested logical size. + */ +public final class FontFace { + + private final FontFamily family; + private final FontAtlas atlas; + private final FontTexture texture; + private final float logicalSize; + private final float drawScale; + + public FontFace(FontFamily family, FontAtlas atlas, FontTexture texture, + float logicalSize, float drawScale) { + this.family = family; + this.atlas = atlas; + this.texture = texture; + this.logicalSize = logicalSize; + this.drawScale = drawScale; + } + + public FontFamily getFamily() { + return family; + } + + public FontAtlas getAtlas() { + return atlas; + } + + public FontTexture getTexture() { + return texture; + } + + public float getLogicalSize() { + return logicalSize; + } + + public float getDrawScale() { + return drawScale; + } + + public Glyph getGlyph(int codePoint) { + return atlas.getGlyph(codePoint); + } + + public Glyph getFallbackGlyph() { + return atlas.getFallbackGlyph(); + } + + public float getAscent() { + return atlas.getAscent(); + } + + public float getLineHeight() { + return atlas.getLineHeight(); + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/FontFamily.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/FontFamily.java new file mode 100644 index 0000000..fc537d9 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/FontFamily.java @@ -0,0 +1,37 @@ +package cn.xiaozhou233.orangex.render.font; + +/** + * Bundled font families. + */ +public enum FontFamily { + + PROXIMA("assets/orangex/font/proxima.ttf", "assets/orangex/font/proximabd.ttf", false), + NOTO("assets/orangex/font/noto.ttf", "assets/orangex/font/noto.ttf", true), + POPPINS("assets/orangex/font/poppins_rg.ttf", "assets/orangex/font/poppins_rg.ttf", false); + + private final String regularResource; + private final String boldResource; + private final boolean cjkCapable; + + FontFamily(String regularResource, String boldResource, boolean cjkCapable) { + this.regularResource = regularResource; + this.boldResource = boldResource; + this.cjkCapable = cjkCapable; + } + + public String getRegularResource() { + return regularResource; + } + + public String getBoldResource() { + return boldResource; + } + + public String getResource(boolean bold) { + return bold ? boldResource : regularResource; + } + + public boolean isCjkCapable() { + return cjkCapable; + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/FontManager.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/FontManager.java new file mode 100644 index 0000000..d282385 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/FontManager.java @@ -0,0 +1,162 @@ +package cn.xiaozhou233.orangex.render.font; + +import cn.xiaozhou233.orangex.render.internal.FontBackend; +import cn.xiaozhou233.orangex.render.internal.FontTexture; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +/** + * Creates and caches {@link FontFace} instances. + * + *

One face exists per (family, bold, logical size, GUI scale) tuple. The + * atlas is rasterised at {@code size * guiScale} pixels so text stays crisp on + * high GUI scales, while {@link FontFace#getDrawScale()} converts atlas pixels + * back to GUI pixels.

+ */ +public final class FontManager { + + private static final int MAX_RASTER_HEIGHT = 64; + private static final int MAX_CJK_RASTER_HEIGHT = 36; + + private final FontBackend backend; + private final Map faces = new HashMap(); + private final Map fontData = new HashMap(); + + public FontManager(FontBackend backend) { + this.backend = backend; + } + + public synchronized FontFace getFace(FontFamily family, float logicalSize, + boolean bold, double guiScale) { + if (family == null) { + family = FontFamily.PROXIMA; + } + if (logicalSize <= 0.0f) { + throw new IllegalArgumentException("logicalSize must be positive"); + } + + int rasterHeight = (int) Math.round(logicalSize * Math.max(1.0, guiScale)); + int maxRasterHeight = family.isCjkCapable() + ? MAX_CJK_RASTER_HEIGHT + : MAX_RASTER_HEIGHT; + if (rasterHeight < 1) { + rasterHeight = 1; + } else if (rasterHeight > maxRasterHeight) { + rasterHeight = maxRasterHeight; + } + + Key key = new Key(family, bold, rasterHeight, logicalSize); + FontFace cached = faces.get(key); + if (cached != null) { + return cached; + } + + byte[] data = loadFont(family.getResource(bold)); + long start = System.currentTimeMillis(); + FontAtlas atlas = StbFontBaker.bake( + data, + rasterHeight, + family.isCjkCapable(), + !"false".equalsIgnoreCase( + System.getProperty("orangex.font.fullGbk", "true")) + ); + FontTexture texture = backend.createTexture(atlas); + atlas.releasePixels(); + float drawScale = logicalSize / (float) rasterHeight; + FontFace face = new FontFace(family, atlas, texture, logicalSize, drawScale); + faces.put(key, face); + + System.out.println("[OrangeX] Baked " + family.name().toLowerCase() + + (bold ? "-bold" : "") + " " + rasterHeight + "px (" + + atlas.getGlyphs().size() + " glyphs, " + + (System.currentTimeMillis() - start) + " ms)"); + return face; + } + + private byte[] loadFont(String resource) { + byte[] cached = fontData.get(resource); + if (cached != null) { + return cached; + } + + InputStream stream = FontManager.class.getClassLoader() + .getResourceAsStream(resource); + if (stream == null) { + throw new IllegalStateException("Missing font resource: " + resource); + } + + try { + ByteArrayOutputStream output = new ByteArrayOutputStream(64 * 1024); + byte[] buffer = new byte[8192]; + int read; + while ((read = stream.read(buffer)) != -1) { + output.write(buffer, 0, read); + } + byte[] data = output.toByteArray(); + fontData.put(resource, data); + return data; + } catch (IOException e) { + throw new IllegalStateException("Cannot read font resource: " + resource, e); + } finally { + try { + stream.close(); + } catch (IOException ignored) { + // Ignore close failures for a classpath resource. + } + } + } + + public String getBackendName() { + return backend.getName(); + } + + public void clear() { + for (FontFace face : faces.values()) { + face.getTexture().close(); + } + faces.clear(); + } + + private static final class Key { + private final FontFamily family; + private final boolean bold; + private final int rasterHeight; + private final float logicalSize; + + private Key(FontFamily family, boolean bold, int rasterHeight, + float logicalSize) { + this.family = family; + this.bold = bold; + this.rasterHeight = rasterHeight; + this.logicalSize = logicalSize; + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof Key)) { + return false; + } + Key key = (Key) other; + return bold == key.bold + && rasterHeight == key.rasterHeight + && Float.compare(logicalSize, key.logicalSize) == 0 + && family == key.family; + } + + @Override + public int hashCode() { + int result = family.hashCode(); + result = 31 * result + (bold ? 1 : 0); + result = 31 * result + rasterHeight; + result = 31 * result + Float.floatToIntBits(logicalSize); + return result; + } + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/Glyph.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/Glyph.java new file mode 100644 index 0000000..6df2462 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/Glyph.java @@ -0,0 +1,76 @@ +package cn.xiaozhou233.orangex.render.font; + +/** + * One glyph inside a {@link FontAtlas}. + * + *

All offsets are expressed in atlas pixels relative to the pen position on + * the baseline. UVs are normalised to {@code [0, 1]}.

+ */ +public final class Glyph { + + private final float x0; + private final float y0; + private final float x1; + private final float y1; + + private final float u0; + private final float v0; + private final float u1; + private final float v1; + + private final float advance; + + public Glyph(float x0, float y0, float x1, float y1, + float u0, float v0, float u1, float v1, + float advance) { + this.x0 = x0; + this.y0 = y0; + this.x1 = x1; + this.y1 = y1; + this.u0 = u0; + this.v0 = v0; + this.u1 = u1; + this.v1 = v1; + this.advance = advance; + } + + public float getX0() { + return x0; + } + + public float getY0() { + return y0; + } + + public float getX1() { + return x1; + } + + public float getY1() { + return y1; + } + + public float getU0() { + return u0; + } + + public float getV0() { + return v0; + } + + public float getU1() { + return u1; + } + + public float getV1() { + return v1; + } + + public float getAdvance() { + return advance; + } + + public boolean isBlank() { + return x0 == x1 || y0 == y1; + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/StbFontBaker.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/StbFontBaker.java new file mode 100644 index 0000000..caa86bf --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/StbFontBaker.java @@ -0,0 +1,215 @@ +package cn.xiaozhou233.orangex.render.font; + +import cn.xiaozhou233.orangex.render.font.stb.StbRasterizer; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypeFontInfo; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypePackContext; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypePackRange; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypePackedChar; + +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +/** + * Bakes a TrueType/OpenType font into a {@link FontAtlas}. + * + *

This is a thin adapter around the ported stb_truetype code in + * {@code render.font.stb}. The original Vape renderer used a single range and + * one fixed 4096x4096 sheet; here the character set is split into a Latin range + * and an optional CJK range so oversampling/atlas pressure can be controlled + * separately.

+ */ +public final class StbFontBaker { + + private static final int DEFAULT_ATLAS_SIZE = 4096; + private static final int LATIN_OVERSAMPLE = 2; + private static final int CJK_OVERSAMPLE = 1; + + private StbFontBaker() { + } + + public static FontAtlas bake(byte[] fontData, int pixelHeight, + boolean includeCjk, boolean fullGbk) { + if (fontData == null || fontData.length == 0) { + throw new IllegalArgumentException("fontData is empty"); + } + if (pixelHeight < 1) { + throw new IllegalArgumentException("pixelHeight must be positive"); + } + + StbTrueTypeFontInfo info = new StbTrueTypeFontInfo(); + if (StbRasterizer.z(info, fontData, 0) == 0) { + throw new IllegalArgumentException("Not a valid TrueType/OpenType font"); + } + + int[] ascent = new int[1]; + int[] descent = new int[1]; + int[] lineGap = new int[1]; + StbRasterizer.x(info, ascent, descent, lineGap); + + float fontScale = StbRasterizer.V(info, pixelHeight); + float ascentPx = ascent[0] * fontScale; + float lineHeightPx = (ascent[0] - descent[0] + lineGap[0]) * fontScale; + + int atlasSize = atlasSize(); + byte[] pixels = new byte[atlasSize * atlasSize]; + + StbTrueTypePackContext packContext = new StbTrueTypePackContext(); + if (StbRasterizer.C(packContext, pixels, atlasSize, atlasSize, 0, 1) == 0) { + throw new IllegalStateException("Unable to initialise the stb pack context"); + } + StbRasterizer.n(packContext, LATIN_OVERSAMPLE, LATIN_OVERSAMPLE); + + int[] latin = latinCodepoints(); + StbTrueTypePackRange latinRange = createRange(latin, pixelHeight, LATIN_OVERSAMPLE); + StbTrueTypePackRange[] ranges; + + int[] cjk = null; + StbTrueTypePackRange cjkRange = null; + if (includeCjk) { + cjk = cjkCodepoints(fullGbk); + if (cjk.length > 0) { + cjkRange = createRange(cjk, pixelHeight, CJK_OVERSAMPLE); + } + } + + if (cjkRange != null) { + ranges = new StbTrueTypePackRange[]{latinRange, cjkRange}; + } else { + ranges = new StbTrueTypePackRange[]{latinRange}; + } + + int packed = StbRasterizer.c(packContext, fontData, 0, ranges, ranges.length); + StbRasterizer.S(packContext); + + Map glyphs = new HashMap(); + collectGlyphs(glyphs, latinRange, latin, atlasSize, packed != 0); + if (cjkRange != null) { + collectGlyphs(glyphs, cjkRange, cjk, atlasSize, packed != 0); + } + + // Missing glyph: '?' or space. The renderer falls back to it for + // unsupported code points. + if (!glyphs.containsKey((int) '?')) { + Glyph space = glyphs.get((int) ' '); + if (space != null) { + glyphs.put((int) '?', space); + } + } + + return new FontAtlas(atlasSize, atlasSize, pixels, glyphs, + ascentPx, lineHeightPx); + } + + private static int atlasSize() { + int configured = Integer.getInteger("orangex.font.atlasSize", DEFAULT_ATLAS_SIZE); + if (configured < 512) { + configured = 512; + } else if (configured > 8192) { + configured = 8192; + } + return configured; + } + + private static StbTrueTypePackRange createRange(int[] codepoints, int pixelHeight, + int oversample) { + StbTrueTypePackedChar[] packedChars = new StbTrueTypePackedChar[codepoints.length]; + for (int i = 0; i < packedChars.length; i++) { + packedChars[i] = new StbTrueTypePackedChar(); + } + + StbTrueTypePackRange range = new StbTrueTypePackRange(); + range.E = pixelHeight; + range.R = 0; + range.N = codepoints; + range.b = codepoints.length; + range.M = packedChars; + range.i = (byte) oversample; + range.y = (byte) oversample; + return range; + } + + private static void collectGlyphs(Map out, + StbTrueTypePackRange range, + int[] codepoints, + int atlasSize, + boolean packedOk) { + float inverse = 1.0f / (float) atlasSize; + for (int i = 0; i < codepoints.length; i++) { + StbTrueTypePackedChar packedChar = range.M[i]; + if (packedChar.A == 0.0f && packedChar.q == 0 && packedChar.p == 0) { + // Glyph did not fit or has no advance; keep spaces (A > 0). + continue; + } + out.put(codepoints[i], new Glyph( + packedChar.s, + packedChar.G, + packedChar.t, + packedChar.R, + packedChar.b * inverse, + packedChar.k * inverse, + packedChar.q * inverse, + packedChar.p * inverse, + packedChar.A + )); + } + if (!packedOk) { + System.out.println("[OrangeX] Font pack reported overflow (atlas " + + atlasSize + "x" + atlasSize + ")"); + } + } + + private static int[] latinCodepoints() { + Set codepoints = new LinkedHashSet(); + for (int c = 32; c <= 126; c++) { + codepoints.add(c); + } + for (int c = 160; c <= 255; c++) { + codepoints.add(c); + } + return toArray(codepoints); + } + + /** + * Decodes GBK double-byte ranges. Level 1 (common simplified Chinese) is + * used by default; {@code fullGbk} widens it to the whole GBK range that + * Vape covered. + */ + private static int[] cjkCodepoints(boolean fullGbk) { + Set codepoints = new LinkedHashSet(); + int highStart = fullGbk ? 0xA1 : 0xB0; + int highEnd = fullGbk ? 0xF7 : 0xD7; + Charset gbk; + try { + gbk = Charset.forName("GBK"); + } catch (Exception ignored) { + return new int[0]; + } + + for (int high = highStart; high <= highEnd; high++) { + for (int low = 0xA1; low <= 0xFE; low++) { + String decoded = new String( + new byte[]{(byte) high, (byte) low}, gbk); + if (decoded.length() != 1) { + continue; + } + char c = decoded.charAt(0); + if (c >= '\u4e00' && c <= '\u9fff') { + codepoints.add((int) c); + } + } + } + return toArray(codepoints); + } + + private static int[] toArray(Set values) { + int[] result = new int[values.size()]; + int index = 0; + for (Integer value : values) { + result[index++] = value; + } + return result; + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/TrueTypeFontRenderer.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/TrueTypeFontRenderer.java new file mode 100644 index 0000000..db0b714 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/TrueTypeFontRenderer.java @@ -0,0 +1,238 @@ +package cn.xiaozhou233.orangex.render.font; + +import cn.xiaozhou233.orangex.render.api.FontRenderer; +import cn.xiaozhou233.orangex.render.internal.GlyphDrawer; + +import java.util.HashMap; +import java.util.Map; + +/** + * Draws UTF-16 text with a primary face and an optional CJK fallback face. + * + *

Supported formatting: Minecraft {@code §} colour codes ({@code 0-9}, + * {@code a-f}, {@code r}). Shadow text is drawn as MC does: a dimmed copy + * offset by one GUI pixel.

+ */ +public final class TrueTypeFontRenderer implements FontRenderer { + + private static final int[] COLORS = new int[]{ + 0xFF000000, 0xFF0000AA, 0xFF00AA00, 0xFF00AAAA, + 0xFFAA0000, 0xFFAA00AA, 0xFFFFAA00, 0xFFAAAAAA, + 0xFF555555, 0xFF5555FF, 0xFF55FF55, 0xFF55FFFF, + 0xFFFF5555, 0xFFFF55FF, 0xFFFFFF55, 0xFFFFFFFF + }; + + private final FontManager manager; + private final FontFace primary; + private final GlyphDrawer drawer; + private final boolean bold; + private final double guiScale; + + private final Map widthCache = new HashMap(); + private FontFace fallback; + + public TrueTypeFontRenderer(FontManager manager, FontFace primary, + boolean bold, double guiScale, + GlyphDrawer drawer) { + this.manager = manager; + this.primary = primary; + this.bold = bold; + this.guiScale = guiScale; + this.drawer = drawer; + } + + @Override + public void drawString(String text, double x, double y, int argb) { + draw(text, x, y, argb, false); + } + + @Override + public void drawStringWithShadow(String text, double x, double y, int argb) { + draw(text, x, y, argb, true); + } + + @Override + public void drawCenteredString(String text, double centerX, double y, int argb) { + drawString(text, centerX - getUncachedWidth(text) / 2.0, y, argb); + } + + @Override + public void drawCenteredStringWithShadow(String text, double centerX, + double y, int argb) { + drawStringWithShadow(text, centerX - getUncachedWidth(text) / 2.0, y, argb); + } + + @Override + public double getStringWidth(String text) { + if (text == null || text.isEmpty()) { + return 0.0; + } + Double cached = widthCache.get(text); + if (cached != null) { + return cached; + } + double width = getUncachedWidth(text); + if (widthCache.size() > 4096) { + widthCache.clear(); + } + widthCache.put(text, width); + return width; + } + + @Override + public double getStringHeight() { + float height = primary.getLineHeight() * primary.getDrawScale(); + return height > 0.0f ? height : primary.getLogicalSize(); + } + + private void draw(String text, double x, double y, int argb, boolean shadow) { + if (text == null || text.isEmpty()) { + return; + } + int color = normalizeAlpha(argb); + if (shadow) { + drawPass(text, x + 1.0, y + 1.0, color, true); + } + drawPass(text, x, y, color, false); + } + + private void drawPass(String text, double x, double y, + int baseColor, boolean shadow) { + int color = baseColor; + double penX = x; + + for (int i = 0; i < text.length(); ) { + char ch = text.charAt(i); + + if (ch == '\u00a7' && i + 1 < text.length()) { + char code = text.charAt(i + 1); + color = colorFor(code, baseColor); + i += 2; + continue; + } + + int codePoint; + if (Character.isHighSurrogate(ch) && i + 1 < text.length()) { + codePoint = Character.toCodePoint(ch, text.charAt(i + 1)); + i += 2; + } else { + codePoint = ch; + i++; + } + + ResolvedGlyph resolved = resolve(codePoint); + if (resolved == null) { + continue; + } + + float scale = resolved.face.getDrawScale(); + double baseline = y + resolved.face.getAscent() * scale; + int drawColor = shadow ? shadowColor(color) : color; + + if (!resolved.glyph.isBlank()) { + drawer.drawGlyph(resolved.face.getTexture(), resolved.glyph, + penX, baseline, scale, drawColor); + } + penX += resolved.glyph.getAdvance() * scale; + } + } + + private double getUncachedWidth(String text) { + double width = 0.0; + for (int i = 0; i < text.length(); ) { + char ch = text.charAt(i); + + if (ch == '\u00a7' && i + 1 < text.length()) { + i += 2; + continue; + } + + int codePoint; + if (Character.isHighSurrogate(ch) && i + 1 < text.length()) { + codePoint = Character.toCodePoint(ch, text.charAt(i + 1)); + i += 2; + } else { + codePoint = ch; + i++; + } + + ResolvedGlyph resolved = resolve(codePoint); + if (resolved == null) { + continue; + } + width += resolved.glyph.getAdvance() * resolved.face.getDrawScale(); + } + return width; + } + + private ResolvedGlyph resolve(int codePoint) { + Glyph glyph = primary.getGlyph(codePoint); + if (glyph != null) { + return new ResolvedGlyph(primary, glyph); + } + + // ASCII/Latin faces do not contain CJK. Lazy-load Noto only when a + // missing code point is actually encountered. + if (!primary.getFamily().isCjkCapable()) { + if (fallback == null) { + fallback = manager.getFace(FontFamily.NOTO, + primary.getLogicalSize(), bold, guiScale); + } + glyph = fallback.getGlyph(codePoint); + if (glyph != null) { + return new ResolvedGlyph(fallback, glyph); + } + } + + glyph = primary.getFallbackGlyph(); + return glyph != null ? new ResolvedGlyph(primary, glyph) : null; + } + + private static int normalizeAlpha(int argb) { + if ((argb >>> 24) == 0) { + return 0xFF000000 | (argb & 0x00FFFFFF); + } + return argb; + } + + private static int colorFor(char code, int baseColor) { + if (code == 'r' || code == 'R') { + return baseColor; + } + if (code >= '0' && code <= '9') { + return applyAlpha(COLORS[code - '0'], baseColor); + } + if (code >= 'a' && code <= 'f') { + return applyAlpha(COLORS[10 + code - 'a'], baseColor); + } + if (code >= 'A' && code <= 'F') { + return applyAlpha(COLORS[10 + code - 'A'], baseColor); + } + return baseColor; + } + + private static int applyAlpha(int rgb, int baseColor) { + return (baseColor & 0xFF000000) | (rgb & 0x00FFFFFF); + } + + private static int shadowColor(int color) { + int alpha = color & 0xFF000000; + int red = (color >> 16) & 0xFF; + int green = (color >> 8) & 0xFF; + int blue = color & 0xFF; + return alpha + | ((red / 4) << 16) + | ((green / 4) << 8) + | (blue / 4); + } + + private static final class ResolvedGlyph { + private final FontFace face; + private final Glyph glyph; + + private ResolvedGlyph(FontFace face, Glyph glyph) { + this.face = face; + this.glyph = glyph; + } + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbByteBufferView.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbByteBufferView.java new file mode 100644 index 0000000..f0ca60f --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbByteBufferView.java @@ -0,0 +1,33 @@ +/* + * Recovered from the sample class that collided with Javassist's + * javassist.bytecode.analysis.Frame. + */ +package cn.xiaozhou233.orangex.render.font.stb; + +/** A lightweight cursor over a byte-array slice used by the STB parser. */ +public final class StbByteBufferView { + public byte[] f; + public int y; + public int C; + public int h; + + public StbByteBufferView() { + this(null, 0, 0); + } + + public StbByteBufferView(byte[] data, int offset, int length) { + this.f = data; + this.C = offset; + this.h = 0; + this.y = length; + } + + public StbByteBufferView k() { + StbByteBufferView copy = new StbByteBufferView(); + copy.f = this.f; + copy.C = this.C; + copy.h = this.h; + copy.y = this.y; + return copy; + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbRasterizer.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbRasterizer.java new file mode 100644 index 0000000..bff1c34 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbRasterizer.java @@ -0,0 +1,3405 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypeActiveEdge; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypeAlignedQuad; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypeBakedChar; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypeBitmap; +import cn.xiaozhou233.orangex.render.font.stb.StbByteBufferView; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypeCharStringContext; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypeEdge; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypeFontInfo; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypeGlyphPackNode; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypeKerningEntry; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypePackAtlasState; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypePackContext; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypePackRange; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypePackRectangle; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypePackedChar; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypePoint; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypeVertex; +import java.util.Arrays; + +public class StbRasterizer { + public static final int d = 0; + public static final int x; + public static final int O; + public static final int n; + public static final int M; + public static final int b = 1; + static final /* synthetic */ boolean G; + public static final int z; + public static final int m; + public static final int Fc; + public static final int P; + public static final int q; + public static final int J = 1; + public static final int j; + public static final int W; + public static final int R; + public static final int T; + public static final int e; + public static final int B; + public static final int u = 0; + public static final int i; + public static final int I; + public static final int k = 0; + public static final int Q; + public static final int h; + public static final int FM = 1; + public static final int a; + public static final int F1; + public static final int g; + public static final int Fb; + public static final int s = 0; + public static final int y = 1; + public static final int V; + public static final int FC; + private static final int c; + public static final int v; + public static final int E; + public static final int w = 1; + public static final int N; + public static final int p = 1; + public static final int D; + public static final int U; + public static final int Ff; + public static final int K = 0; + public static final int F; + public static final int L; + public static final int l = 0; + public static final int t; + public static final int f; + public static final int o; + public static final int A; + public static final int Z; + public static final int C; + public static final int X = 1; + public static final int S; + public static final int r; + public static final int H; + public static final int Fy; + public static final int Y; + + public static int F(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, int[] nArray, int[] nArray2, int[] nArray3, int[] nArray4) { + if (stbTrueTypeFontInfo.g.y != 0) { + StbRasterizer.m(stbTrueTypeFontInfo, n, nArray, nArray2, nArray3, nArray4); + } else { + int n2 = StbRasterizer.G(stbTrueTypeFontInfo, n); + if (n2 < 0) { + return 0; + } + if (nArray != null) { + nArray[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, n2 + 2); + } + if (nArray2 != null) { + nArray2[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, n2 + 4); + } + if (nArray3 != null) { + nArray3[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, n2 + 6); + } + if (nArray4 != null) { + nArray4[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, n2 + 8); + } + } + return 1; + } + + static StbByteBufferView e(StbByteBufferView frame, int n) { + StbByteBufferView frame2 = frame.k(); + StbRasterizer.i(frame2, 0); + int n2 = StbRasterizer.p(frame2); + int n3 = StbRasterizer.Q(frame2); + if (!(G || n >= 0 && n < n2)) { + throw new AssertionError(); + } + if (!(G || n3 >= 1 && n3 <= 4)) { + throw new AssertionError(); + } + StbRasterizer.K(frame2, n * n3); + int n4 = (int)StbRasterizer.u(frame2, n3); + int n5 = (int)StbRasterizer.u(frame2, n3); + return StbRasterizer.E(frame2, 2 + (n2 + 1) * n3 + n4, n5 - n4); + } + + public static int y(byte[] byArray, String string, int n) { + return StbRasterizer.h(byArray, string.getBytes(), n); + } + + static int a(StbTrueTypeVertex[] stbTrueTypeVertexArray, int n, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int n9) { + if (n3 != 0) { + if (n2 != 0) { + StbRasterizer.d(stbTrueTypeVertexArray[n++], 3, n8 + n6 >> 1, n9 + n7 >> 1, n8, n9); + } + StbRasterizer.d(stbTrueTypeVertexArray[n++], 3, n4, n5, n6, n7); + } else if (n2 != 0) { + StbRasterizer.d(stbTrueTypeVertexArray[n++], 3, n4, n5, n8, n9); + } else { + StbRasterizer.d(stbTrueTypeVertexArray[n++], 2, n4, n5, 0, 0); + } + return n; + } + + static void p(byte[] byArray, int n, int n2, int n3, int n4, int n5) { + byte[] byArray2 = new byte[8]; + int n6 = n3 - n5; + Arrays.fill(byArray2, (byte)0); + for (int i = 0; i < n2; ++i) { + int n7; + Arrays.fill(byArray2, 0, n5, (byte)0); + int n8 = 0; + switch (n5) { + case 2: { + for (n7 = 0; n7 <= n6; ++n7) { + byArray2[n7 + n5 & 7] = byArray[n + n7 * n4]; + byArray[n + n7 * n4] = (byte)((n8 += (byArray[n + n7 * n4] & 0xFF) - (byArray2[n7 & 7] & 0xFF)) / 2); + } + break; + } + case 3: { + for (n7 = 0; n7 <= n6; ++n7) { + byArray2[n7 + n5 & 7] = byArray[n + n7 * n4]; + byArray[n + n7 * n4] = (byte)((n8 += (byArray[n + n7 * n4] & 0xFF) - (byArray2[n7 & 7] & 0xFF)) / 3); + } + break; + } + case 4: { + for (n7 = 0; n7 <= n6; ++n7) { + byArray2[n7 + n5 & 7] = byArray[n + n7 * n4]; + byArray[n + n7 * n4] = (byte)((n8 += (byArray[n + n7 * n4] & 0xFF) - (byArray2[n7 & 7] & 0xFF)) / 4); + } + break; + } + case 5: { + for (n7 = 0; n7 <= n6; ++n7) { + byArray2[n7 + n5 & 7] = byArray[n + n7 * n4]; + byArray[n + n7 * n4] = (byte)((n8 += (byArray[n + n7 * n4] & 0xFF) - (byArray2[n7 & 7] & 0xFF)) / 5); + } + break; + } + default: { + for (n7 = 0; n7 <= n6; ++n7) { + byArray2[n7 + n5 & 7] = byArray[n + n7 * n4]; + byArray[n + n7 * n4] = (byte)((n8 += (byArray[n + n7 * n4] & 0xFF) - (byArray2[n7 & 7] & 0xFF)) / n5); + } + } + } + while (n7 < n3) { + byArray[n + n7 * n4] = (byte)((n8 -= byArray2[n7 & 7] & 0xFF) / n5); + ++n7; + } + ++n; + } + } + + static int B(byte[] byArray, int n) { + return ((byArray[n] & 0xFF) << 24) + ((byArray[n + 1] & 0xFF) << 16) + ((byArray[n + 2] & 0xFF) << 8) + (byArray[n + 3] & 0xFF); + } + + static float A(float f, float f2, float f3) { + return (f2 + f3) / 2.0f * f; + } + + static void V(StbTrueTypeCharStringContext stbTrueTypeCharStringContext, int n, int n2) { + if (n > stbTrueTypeCharStringContext.c || stbTrueTypeCharStringContext.v == 0) { + stbTrueTypeCharStringContext.c = n; + } + if (n2 > stbTrueTypeCharStringContext.f || stbTrueTypeCharStringContext.v == 0) { + stbTrueTypeCharStringContext.f = n2; + } + if (n < stbTrueTypeCharStringContext.y || stbTrueTypeCharStringContext.v == 0) { + stbTrueTypeCharStringContext.y = n; + } + if (n2 < stbTrueTypeCharStringContext.Z || stbTrueTypeCharStringContext.v == 0) { + stbTrueTypeCharStringContext.Z = n2; + } + stbTrueTypeCharStringContext.v = 1; + } + + public static void m(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, float f, float f2, int[] nArray, int[] nArray2, int[] nArray3, int[] nArray4) { + StbRasterizer.p(stbTrueTypeFontInfo, n, f, f2, 0.0f, 0.0f, nArray, nArray2, nArray3, nArray4); + } + + public static void o(StbTrueTypeFontInfo stbTrueTypeFontInfo, byte[] byArray, int n, int n2, int n3, int n4, float f, float f2, float f3, float f4, int n5, int n6, float[] fArray, float[] fArray2, int n7) { + StbRasterizer.H(stbTrueTypeFontInfo, byArray, n, n2, n3, n4, f, f2, f3, f4, n5, n6, fArray, fArray2, StbRasterizer.T(stbTrueTypeFontInfo, n7)); + } + + static StbByteBufferView x(byte[] byArray, int n, int n2) { + if (!G && n2 >= 0x40000000) { + throw new AssertionError(); + } + StbByteBufferView frame = new StbByteBufferView(); + frame.f = byArray; + frame.C = n; + frame.y = n2; + frame.h = 0; + return frame; + } + + public static int d(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, int n2) { + int n3 = 0; + if (stbTrueTypeFontInfo.G != 0) { + n3 += StbRasterizer.c(stbTrueTypeFontInfo, n, n2); + } else if (stbTrueTypeFontInfo.L != 0) { + n3 += StbRasterizer.v(stbTrueTypeFontInfo, n, n2); + } + return n3; + } + + static void b(StbTrueTypePackAtlasState stbTrueTypePackAtlasState, int n, int n2, StbTrueTypeGlyphPackNode[] stbTrueTypeGlyphPackNodeArray, int n3) { + stbTrueTypePackAtlasState.f = n; + stbTrueTypePackAtlasState.F = n2; + stbTrueTypePackAtlasState.n = 0; + stbTrueTypePackAtlasState.a = 0; + stbTrueTypePackAtlasState.t = 0; + } + + public static String j(StbTrueTypeFontInfo stbTrueTypeFontInfo, int[] nArray, int n, int n2, int n3, int n4) { + byte[] byArray = stbTrueTypeFontInfo.S; + int n5 = stbTrueTypeFontInfo.U; + long l = StbRasterizer.v(byArray, n5, "name"); + if (l == 0L) { + return null; + } + int n6 = StbRasterizer.x(byArray, (int)l + 2); + int n7 = (int)l + StbRasterizer.x(byArray, (int)l + 4); + for (int i = 0; i < n6; ++i) { + int n8 = (int)l + 6 + 12 * i; + if (n != StbRasterizer.x(byArray, n8 + 0) || n2 != StbRasterizer.x(byArray, n8 + 2) || n3 != StbRasterizer.x(byArray, n8 + 4) || n4 != StbRasterizer.x(byArray, n8 + 6)) continue; + nArray[0] = StbRasterizer.x(byArray, n8 + 8); + int n9 = n7 + StbRasterizer.x(byArray, n8 + 10); + byte[] byArray2 = new byte[nArray[0]]; + System.arraycopy(byArray, n9, byArray2, 0, nArray[0]); + return new String(byArray2); + } + return null; + } + + public static int c(byte[] byArray, int n) { + return StbRasterizer.E(byArray, n); + } + + public static byte[] F(StbTrueTypeFontInfo stbTrueTypeFontInfo, float f, float f2, float f3, float f4, int n, int[] nArray, int[] nArray2, int[] nArray3, int[] nArray4) { + int n2; + int[] nArray5 = new int[1]; + int[] nArray6 = new int[1]; + int[] nArray7 = new int[1]; + int[] nArray8 = new int[1]; + StbTrueTypeBitmap stbTrueTypeBitmap = new StbTrueTypeBitmap(); + StbTrueTypeVertex[] stbTrueTypeVertexArray = StbRasterizer.m(stbTrueTypeFontInfo, n); + int n3 = n2 = stbTrueTypeVertexArray != null ? stbTrueTypeVertexArray.length : 0; + if (f == 0.0f) { + f = f2; + } + if (f2 == 0.0f) { + if (f == 0.0f) { + return null; + } + f2 = f; + } + StbRasterizer.G(stbTrueTypeFontInfo, n, f, f2, f3, f4, nArray5, nArray6, nArray7, nArray8); + stbTrueTypeBitmap.K = nArray7[0] - nArray5[0]; + stbTrueTypeBitmap.c = nArray8[0] - nArray6[0]; + stbTrueTypeBitmap.E = null; + if (nArray != null) { + nArray[0] = stbTrueTypeBitmap.K; + } + if (nArray2 != null) { + nArray2[0] = stbTrueTypeBitmap.c; + } + if (nArray3 != null) { + nArray3[0] = nArray5[0]; + } + if (nArray4 != null) { + nArray4[0] = nArray6[0]; + } + if (stbTrueTypeBitmap.K != 0 && stbTrueTypeBitmap.c != 0) { + stbTrueTypeBitmap.E = new byte[stbTrueTypeBitmap.K * stbTrueTypeBitmap.c]; + stbTrueTypeBitmap.h = 0; + if (stbTrueTypeBitmap.E != null) { + stbTrueTypeBitmap.A = stbTrueTypeBitmap.K; + StbRasterizer.b(stbTrueTypeBitmap, 0.35f, stbTrueTypeVertexArray, n2, f, f2, f3, f4, nArray5[0], nArray6[0], 1); + } + } + return stbTrueTypeBitmap.E; + } + + static void Q(StbTrueTypeCharStringContext stbTrueTypeCharStringContext, float f, float f2) { + StbRasterizer.d(stbTrueTypeCharStringContext); + stbTrueTypeCharStringContext.s = stbTrueTypeCharStringContext.C += f; + stbTrueTypeCharStringContext.p = stbTrueTypeCharStringContext.o += f2; + StbRasterizer.A(stbTrueTypeCharStringContext, 1, (int)stbTrueTypeCharStringContext.C, (int)stbTrueTypeCharStringContext.o, 0, 0, 0, 0); + } + + static void K(StbByteBufferView frame, int n) { + StbRasterizer.i(frame, frame.h + n); + } + + static long v(byte[] byArray, int n, String string) { + int n2 = StbRasterizer.x(byArray, n + 4); + long l = n + 12; + for (int i = 0; i < n2; ++i) { + long l2 = l + (long)(16 * i); + if (!StbRasterizer.f(byArray, (int)l2, string)) continue; + return StbRasterizer.c$src$J$1nktx4p(byArray, (int)l2 + 8); + } + return 0L; + } + + static StbTrueTypeVertex[] o(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n) { + int n2; + byte[] byArray = stbTrueTypeFontInfo.S; + StbTrueTypeVertex[] stbTrueTypeVertexArray = null; + int n3 = 0; + int n4 = StbRasterizer.G(stbTrueTypeFontInfo, n); + if (n4 < 0) { + return null; + } + short s = StbRasterizer.E$src$S$1b9gd7y(byArray, n4); + if (s > 0) { + int n5; + int n6; + n2 = 0; + int n7 = 0; + int n8 = 0; + int n9 = 0; + int n10 = n4 + 10; + int n11 = StbRasterizer.x(byArray, n4 + 10 + s * 2); + int n12 = n4 + 10 + s * 2 + 2 + n11; + int n13 = 1 + StbRasterizer.x(byArray, n10 + s * 2 - 2); + int n14 = n13 + 2 * s; + stbTrueTypeVertexArray = new StbTrueTypeVertex[n14]; + for (n6 = 0; n6 < n14; ++n6) { + stbTrueTypeVertexArray[n6] = new StbTrueTypeVertex(); + } + int n15 = 0; + int n16 = 0; + int n17 = n14 - n13; + int n18 = n12; + for (n6 = 0; n6 < n13; ++n6) { + if (n16 == 0) { + if (((n2 = byArray[n18++] & 0xFF) & 8) != 0) { + n16 = byArray[n18++] & 0xFF; + } + } else { + --n16; + } + stbTrueTypeVertexArray[n17 + n6].O = n2; + } + int n19 = 0; + for (n6 = 0; n6 < n13; ++n6) { + n2 = stbTrueTypeVertexArray[n17 + n6].O; + if ((n2 & 2) != 0) { + n5 = byArray[n18++] & 0xFF; + n19 += (n2 & 0x10) != 0 ? n5 : -n5; + } else if ((n2 & 0x10) == 0) { + n19 += (short)((byArray[n18] & 0xFF) * 256 + (byArray[n18 + 1] & 0xFF)); + n18 += 2; + } + stbTrueTypeVertexArray[n17 + n6].f = (short)n19; + } + int n20 = 0; + for (n6 = 0; n6 < n13; ++n6) { + n2 = stbTrueTypeVertexArray[n17 + n6].O; + if ((n2 & 4) != 0) { + n5 = byArray[n18++] & 0xFF; + n20 += (n2 & 0x20) != 0 ? n5 : -n5; + } else if ((n2 & 0x20) == 0) { + n20 += (short)((byArray[n18] & 0xFF) * 256 + (byArray[n18 + 1] & 0xFF)); + n18 += 2; + } + stbTrueTypeVertexArray[n17 + n6].H = (short)n20; + } + n3 = 0; + int n21 = 0; + int n22 = 0; + int n23 = 0; + int n24 = 0; + int n25 = 0; + int n26 = 0; + for (n6 = 0; n6 < n13; ++n6) { + n2 = stbTrueTypeVertexArray[n17 + n6].O; + n19 = stbTrueTypeVertexArray[n17 + n6].f; + n20 = stbTrueTypeVertexArray[n17 + n6].H; + if (n15 == n6) { + if (n6 != 0) { + n3 = StbRasterizer.a(stbTrueTypeVertexArray, n3, n8, n9, n26, n25, n22, n21, n24, n23); + } + int n27 = n9 = (n2 & 1) == 0 ? 1 : 0; + if (n9 != 0) { + n22 = n19; + n21 = n20; + if ((stbTrueTypeVertexArray[n17 + n6 + 1].O & 1) == 0) { + n26 = n19 + stbTrueTypeVertexArray[n17 + n6 + 1].f >> 1; + n25 = n20 + stbTrueTypeVertexArray[n17 + n6 + 1].H >> 1; + } else { + n26 = stbTrueTypeVertexArray[n17 + n6 + 1].f; + n25 = stbTrueTypeVertexArray[n17 + n6 + 1].H; + ++n6; + } + } else { + n26 = n19; + n25 = n20; + } + StbRasterizer.d(stbTrueTypeVertexArray[n3++], 1, n26, n25, 0, 0); + n8 = 0; + n15 = 1 + StbRasterizer.x(byArray, n10 + n7 * 2); + ++n7; + continue; + } + if ((n2 & 1) == 0) { + if (n8 != 0) { + StbRasterizer.d(stbTrueTypeVertexArray[n3++], 3, n24 + n19 >> 1, n23 + n20 >> 1, n24, n23); + } + n24 = n19; + n23 = n20; + n8 = 1; + continue; + } + if (n8 != 0) { + StbRasterizer.d(stbTrueTypeVertexArray[n3++], 3, n19, n20, n24, n23); + } else { + StbRasterizer.d(stbTrueTypeVertexArray[n3++], 2, n19, n20, 0, 0); + } + n8 = 0; + } + n3 = StbRasterizer.a(stbTrueTypeVertexArray, n3, n8, n9, n26, n25, n22, n21, n24, n23); + } else if (s < 0) { + n2 = 1; + int n28 = n4 + 10; + n3 = 0; + stbTrueTypeVertexArray = null; + while (n2 != 0) { + int n29 = 0; + StbTrueTypeVertex[] stbTrueTypeVertexArray2 = null; + StbTrueTypeVertex[] stbTrueTypeVertexArray3 = null; + float[] fArray = new float[]{1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f}; + int n30 = StbRasterizer.x(byArray, n28); + int n31 = StbRasterizer.x(byArray, n28 += 2); + n28 += 2; + if ((n30 & 2) != 0) { + if ((n30 & 1) != 0) { + fArray[4] = StbRasterizer.E$src$S$1b9gd7y(byArray, n28); + fArray[5] = StbRasterizer.E$src$S$1b9gd7y(byArray, n28 += 2); + n28 += 2; + } else { + fArray[4] = StbRasterizer.u(byArray, n28); + fArray[5] = StbRasterizer.u(byArray, ++n28); + ++n28; + } + } else if (!G) { + throw new AssertionError(); + } + if ((n30 & 8) != 0) { + fArray[0] = fArray[3] = (float)StbRasterizer.E$src$S$1b9gd7y(byArray, n28) / 16384.0f; + n28 += 2; + fArray[2] = 0.0f; + fArray[1] = 0.0f; + } else if ((n30 & 0x40) != 0) { + fArray[0] = (float)StbRasterizer.E$src$S$1b9gd7y(byArray, n28) / 16384.0f; + fArray[2] = 0.0f; + fArray[1] = 0.0f; + fArray[3] = (float)StbRasterizer.E$src$S$1b9gd7y(byArray, n28 += 2) / 16384.0f; + n28 += 2; + } else if ((n30 & 0x80) != 0) { + fArray[0] = (float)StbRasterizer.E$src$S$1b9gd7y(byArray, n28) / 16384.0f; + fArray[1] = (float)StbRasterizer.E$src$S$1b9gd7y(byArray, n28 += 2) / 16384.0f; + fArray[2] = (float)StbRasterizer.E$src$S$1b9gd7y(byArray, n28 += 2) / 16384.0f; + fArray[3] = (float)StbRasterizer.E$src$S$1b9gd7y(byArray, n28 += 2) / 16384.0f; + n28 += 2; + } + float f = (float)Math.sqrt(fArray[0] * fArray[0] + fArray[1] * fArray[1]); + float f2 = (float)Math.sqrt(fArray[2] * fArray[2] + fArray[3] * fArray[3]); + stbTrueTypeVertexArray2 = StbRasterizer.m(stbTrueTypeFontInfo, n31); + if (stbTrueTypeVertexArray2 != null) { + n29 = stbTrueTypeVertexArray2.length; + } + if (n29 > 0) { + for (int i = 0; i < n29; ++i) { + StbTrueTypeVertex stbTrueTypeVertex = stbTrueTypeVertexArray2[i]; + short s2 = stbTrueTypeVertex.f; + short s3 = stbTrueTypeVertex.H; + stbTrueTypeVertex.f = (short)(f * (fArray[0] * (float)s2 + fArray[2] * (float)s3 + fArray[4])); + stbTrueTypeVertex.H = (short)(f2 * (fArray[1] * (float)s2 + fArray[3] * (float)s3 + fArray[5])); + s2 = stbTrueTypeVertex.h; + s3 = stbTrueTypeVertex.D; + stbTrueTypeVertex.h = (short)(f * (fArray[0] * (float)s2 + fArray[2] * (float)s3 + fArray[4])); + stbTrueTypeVertex.D = (short)(f2 * (fArray[1] * (float)s2 + fArray[3] * (float)s3 + fArray[5])); + } + stbTrueTypeVertexArray3 = new StbTrueTypeVertex[n3 + n29]; + if (n3 > 0 && stbTrueTypeVertexArray != null) { + System.arraycopy(stbTrueTypeVertexArray, 0, stbTrueTypeVertexArray3, 0, n3); + } + System.arraycopy(stbTrueTypeVertexArray2, 0, stbTrueTypeVertexArray3, n3, n29); + stbTrueTypeVertexArray = stbTrueTypeVertexArray3; + n3 += n29; + } + n2 = n30 & 0x20; + } + } + if (stbTrueTypeVertexArray != null && n3 < stbTrueTypeVertexArray.length) { + StbTrueTypeVertex[] stbTrueTypeVertexArray4 = new StbTrueTypeVertex[n3]; + System.arraycopy(stbTrueTypeVertexArray, 0, stbTrueTypeVertexArray4, 0, n3); + return stbTrueTypeVertexArray4; + } + return stbTrueTypeVertexArray; + } + + public static void w(StbTrueTypePackContext stbTrueTypePackContext, int n) { + stbTrueTypePackContext.h = n; + } + + public static void S(StbTrueTypePackContext stbTrueTypePackContext) { + } + + static int x(byte[] byArray, int n) { + return (byArray[n] & 0xFF) * 256 + (byArray[n + 1] & 0xFF); + } + + static boolean d(float[] fArray, float[] fArray2) { + return fArray[0] == fArray2[0] && fArray[1] == fArray2[1]; + } + + static StbByteBufferView B(StbByteBufferView frame) { + int n = frame.h; + int n2 = StbRasterizer.p(frame); + if (n2 != 0) { + int n3 = StbRasterizer.Q(frame); + if (!(G || n3 >= 1 && n3 <= 4)) { + throw new AssertionError(); + } + StbRasterizer.K(frame, n3 * n2); + StbRasterizer.K(frame, (int)StbRasterizer.u(frame, n3) - 1); + } + return StbRasterizer.E(frame, n, frame.h - n); + } + + public static byte[] Y(StbTrueTypeFontInfo stbTrueTypeFontInfo, float f, float f2, int n, int[] nArray, int[] nArray2, int[] nArray3, int[] nArray4) { + return StbRasterizer.q(stbTrueTypeFontInfo, f, f2, 0.0f, 0.0f, n, nArray, nArray2, nArray3, nArray4); + } + + static void c(float[] fArray, int n, float[] fArray2, int n2, int n3, StbTrueTypeActiveEdge stbTrueTypeActiveEdge, float f) { + float f2 = f + 1.0f; + while (stbTrueTypeActiveEdge != null) { + float f3; + if (!G && !(stbTrueTypeActiveEdge.m >= f)) { + throw new AssertionError(); + } + if (stbTrueTypeActiveEdge.L == 0.0f) { + f3 = stbTrueTypeActiveEdge.e; + if (f3 < (float)n3) { + if (f3 >= 0.0f) { + StbRasterizer.A(fArray, n, (int)f3, stbTrueTypeActiveEdge, f3, f, f3, f2); + StbRasterizer.A(fArray2, n2, (int)f3 + 1, stbTrueTypeActiveEdge, f3, f, f3, f2); + } else { + StbRasterizer.A(fArray2, n2, 0, stbTrueTypeActiveEdge, f3, f, f3, f2); + } + } + } else { + float f4; + float f5; + float f6; + float f7; + float f8; + float f9; + float f10; + float f11; + float f12; + f3 = stbTrueTypeActiveEdge.e; + float f13 = stbTrueTypeActiveEdge.L; + float f14 = f3 + f13; + float f15 = stbTrueTypeActiveEdge.N; + if (!(G || stbTrueTypeActiveEdge.j <= f2 && stbTrueTypeActiveEdge.m >= f)) { + throw new AssertionError(); + } + if (stbTrueTypeActiveEdge.j > f) { + f12 = f3 + f13 * (stbTrueTypeActiveEdge.j - f); + f11 = stbTrueTypeActiveEdge.j; + } else { + f12 = f3; + f11 = f; + } + if (stbTrueTypeActiveEdge.m < f2) { + f10 = f3 + f13 * (stbTrueTypeActiveEdge.m - f); + f9 = stbTrueTypeActiveEdge.m; + } else { + f10 = f14; + f9 = f2; + } + if (f12 >= 0.0f && f10 >= 0.0f && f12 < (float)n3 && f10 < (float)n3) { + int n4; + if ((int)f12 == (int)f10) { + n4 = (int)f12; + float f16 = (f9 - f11) * stbTrueTypeActiveEdge.T; + int n5 = n + n4; + fArray[n5] = fArray[n5] + StbRasterizer.E(f16, f12, (float)n4 + 1.0f, f10, (float)n4 + 1.0f); + int n6 = n2 + n4 + 1; + fArray2[n6] = fArray2[n6] + f16; + } else { + if (f12 > f10) { + f11 = f2 - (f11 - f); + f9 = f2 - (f9 - f); + float f17 = f11; + f11 = f9; + f9 = f17; + f17 = f10; + f10 = f12; + f12 = f17; + f13 = -f13; + f15 = -f15; + f17 = f3; + f3 = f14; + f14 = f17; + } + n4 = (int)f12; + int n7 = (int)f10; + f8 = f + f15 * ((float)(n4 + 1) - f3); + f7 = f + f15 * ((float)n7 - f3); + if (f8 > f2) { + f8 = f2; + } + f6 = stbTrueTypeActiveEdge.T; + f5 = f6 * (f8 - f11); + int n8 = n + n4; + fArray[n8] = fArray[n8] + StbRasterizer.S(f5, (float)(n4 + 1) - f12); + if (f7 > f2) { + f7 = f2; + f15 = (f7 - f8) / (float)(n7 - (n4 + 1)); + } + f4 = f6 * f15 * 1.0f; + for (int i = n4 + 1; i < n7; ++i) { + int n9 = n + i; + fArray[n9] = fArray[n9] + (f5 + f4 / 2.0f); + f5 += f4; + } + int n10 = n + n7; + fArray[n10] = fArray[n10] + (f5 + f6 * StbRasterizer.E(f9 - f7, n7, (float)n7 + 1.0f, f10, (float)n7 + 1.0f)); + int n11 = n2 + n7 + 1; + fArray2[n11] = fArray2[n11] + f6 * (f9 - f11); + } + } else { + for (int i = 0; i < n3; ++i) { + float f18 = f; + float f19 = i; + f8 = i + 1; + f7 = f14; + f4 = f2; + f6 = ((float)i - f3) / f13 + f; + f5 = ((float)(i + 1) - f3) / f13 + f; + if (f3 < f19 && f7 > f8) { + StbRasterizer.A(fArray, n, i, stbTrueTypeActiveEdge, f3, f18, f19, f6); + StbRasterizer.A(fArray, n, i, stbTrueTypeActiveEdge, f19, f6, f8, f5); + StbRasterizer.A(fArray, n, i, stbTrueTypeActiveEdge, f8, f5, f7, f4); + continue; + } + if (f7 < f19 && f3 > f8) { + StbRasterizer.A(fArray, n, i, stbTrueTypeActiveEdge, f3, f18, f8, f5); + StbRasterizer.A(fArray, n, i, stbTrueTypeActiveEdge, f8, f5, f19, f6); + StbRasterizer.A(fArray, n, i, stbTrueTypeActiveEdge, f19, f6, f7, f4); + continue; + } + if (f3 < f19 && f7 > f19) { + StbRasterizer.A(fArray, n, i, stbTrueTypeActiveEdge, f3, f18, f19, f6); + StbRasterizer.A(fArray, n, i, stbTrueTypeActiveEdge, f19, f6, f7, f4); + continue; + } + if (f7 < f19 && f3 > f19) { + StbRasterizer.A(fArray, n, i, stbTrueTypeActiveEdge, f3, f18, f19, f6); + StbRasterizer.A(fArray, n, i, stbTrueTypeActiveEdge, f19, f6, f7, f4); + continue; + } + if (f3 < f8 && f7 > f8) { + StbRasterizer.A(fArray, n, i, stbTrueTypeActiveEdge, f3, f18, f8, f5); + StbRasterizer.A(fArray, n, i, stbTrueTypeActiveEdge, f8, f5, f7, f4); + continue; + } + if (f7 < f8 && f3 > f8) { + StbRasterizer.A(fArray, n, i, stbTrueTypeActiveEdge, f3, f18, f8, f5); + StbRasterizer.A(fArray, n, i, stbTrueTypeActiveEdge, f8, f5, f7, f4); + continue; + } + StbRasterizer.A(fArray, n, i, stbTrueTypeActiveEdge, f3, f18, f7, f4); + } + } + } + stbTrueTypeActiveEdge = stbTrueTypeActiveEdge.l; + } + } + + static StbTrueTypeActiveEdge O(StbTrueTypeEdge stbTrueTypeEdge, int n, float f) { + float f2; + StbTrueTypeActiveEdge stbTrueTypeActiveEdge = new StbTrueTypeActiveEdge(); + stbTrueTypeActiveEdge.L = f2 = (stbTrueTypeEdge.i - stbTrueTypeEdge.d) / (stbTrueTypeEdge.u - stbTrueTypeEdge.X); + stbTrueTypeActiveEdge.N = f2 != 0.0f ? 1.0f / f2 : 0.0f; + stbTrueTypeActiveEdge.e = stbTrueTypeEdge.d + f2 * (f - stbTrueTypeEdge.X); + stbTrueTypeActiveEdge.e -= (float)n; + stbTrueTypeActiveEdge.T = stbTrueTypeEdge.W != 0 ? 1.0f : -1.0f; + stbTrueTypeActiveEdge.j = stbTrueTypeEdge.X; + stbTrueTypeActiveEdge.m = stbTrueTypeEdge.u; + stbTrueTypeActiveEdge.l = null; + return stbTrueTypeActiveEdge; + } + + public static int c(StbTrueTypePackContext stbTrueTypePackContext, byte[] byArray, int n, StbTrueTypePackRange[] stbTrueTypePackRangeArray, int n2) { + int n3; + StbTrueTypeFontInfo stbTrueTypeFontInfo = new StbTrueTypeFontInfo(); + int n4 = 1; + for (n3 = 0; n3 < n2; ++n3) { + for (int i = 0; i < stbTrueTypePackRangeArray[n3].b; ++i) { + stbTrueTypePackRangeArray[n3].M[i].p = 0; + stbTrueTypePackRangeArray[n3].M[i].q = 0; + stbTrueTypePackRangeArray[n3].M[i].k = 0; + stbTrueTypePackRangeArray[n3].M[i].b = 0; + } + } + int n5 = 0; + for (n3 = 0; n3 < n2; ++n3) { + n5 += stbTrueTypePackRangeArray[n3].b; + } + StbTrueTypePackRectangle[] stbTrueTypePackRectangleArray = new StbTrueTypePackRectangle[n5]; + for (n3 = 0; n3 < n5; ++n3) { + stbTrueTypePackRectangleArray[n3] = new StbTrueTypePackRectangle(); + } + StbRasterizer.z(stbTrueTypeFontInfo, byArray, StbRasterizer.c(byArray, n)); + n5 = StbRasterizer.G(stbTrueTypePackContext, stbTrueTypeFontInfo, stbTrueTypePackRangeArray, n2, stbTrueTypePackRectangleArray); + StbRasterizer.H(stbTrueTypePackContext, stbTrueTypePackRectangleArray, n5); + n4 = StbRasterizer.E(stbTrueTypePackContext, stbTrueTypeFontInfo, stbTrueTypePackRangeArray, n2, stbTrueTypePackRectangleArray); + return n4; + } + + static int p(StbByteBufferView frame) { + return (int)StbRasterizer.u(frame, 2); + } + + static short E$src$S$1b9gd7y(byte[] byArray, int n) { + return (short)((byArray[n] & 0xFF) * 256 + (byArray[n + 1] & 0xFF)); + } + + public static void N(byte[] byArray, int n, float f, float[] fArray, float[] fArray2, float[] fArray3) { + int[] nArray = new int[1]; + int[] nArray2 = new int[1]; + int[] nArray3 = new int[1]; + StbTrueTypeFontInfo stbTrueTypeFontInfo = new StbTrueTypeFontInfo(); + StbRasterizer.z(stbTrueTypeFontInfo, byArray, StbRasterizer.c(byArray, n)); + float f2 = f > 0.0f ? StbRasterizer.V(stbTrueTypeFontInfo, f) : StbRasterizer.b(stbTrueTypeFontInfo, -f); + StbRasterizer.x(stbTrueTypeFontInfo, nArray, nArray2, nArray3); + fArray[0] = (float)nArray[0] * f2; + fArray2[0] = (float)nArray2[0] * f2; + fArray3[0] = (float)nArray3[0] * f2; + } + + public static StbTrueTypeVertex[] t(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n) { + return StbRasterizer.m(stbTrueTypeFontInfo, StbRasterizer.T(stbTrueTypeFontInfo, n)); + } + + static long c$src$J$1nktx4p(byte[] byArray, int n) { + return ((long)(byArray[n] & 0xFF) << 24) + ((long)(byArray[n + 1] & 0xFF) << 16) + ((long)(byArray[n + 2] & 0xFF) << 8) + (long)(byArray[n + 3] & 0xFF); + } + + static int q(byte[] byArray, int n, int n2) { + int n3 = StbRasterizer.x(byArray, n); + switch (n3) { + case 1: { + int n4 = StbRasterizer.x(byArray, n + 2); + int n5 = StbRasterizer.x(byArray, n + 4); + int n6 = n + 6; + if (n2 < n4 || n2 >= n4 + n5) break; + return StbRasterizer.x(byArray, n6 + 2 * (n2 - n4)); + } + case 2: { + int n7 = StbRasterizer.x(byArray, n + 2); + int n8 = n + 4; + int n9 = 0; + int n10 = n7 - 1; + int n11 = n2; + while (n9 <= n10) { + int n12 = n9 + n10 >> 1; + int n13 = n8 + 6 * n12; + int n14 = StbRasterizer.x(byArray, n13); + int n15 = StbRasterizer.x(byArray, n13 + 2); + if (n11 < n14) { + n10 = n12 - 1; + continue; + } + if (n11 > n15) { + n9 = n12 + 1; + continue; + } + return StbRasterizer.x(byArray, n13 + 4); + } + break; + } + default: { + return -1; + } + } + return 0; + } + + static void M(StbByteBufferView frame) { + int n = StbRasterizer.K(frame); + if (!G && n < 28) { + throw new AssertionError(); + } + if (n == 30) { + int n2; + StbRasterizer.K(frame, 1); + while (frame.h < frame.y && ((n2 = StbRasterizer.Q(frame)) & 0xF) != 15 && n2 >> 4 != 15) { + } + } else { + StbRasterizer.v(frame); + } + } + + public static int J(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, int n2) { + if (stbTrueTypeFontInfo.L == 0 && stbTrueTypeFontInfo.G == 0) { + return 0; + } + return StbRasterizer.d(stbTrueTypeFontInfo, StbRasterizer.T(stbTrueTypeFontInfo, n), StbRasterizer.T(stbTrueTypeFontInfo, n2)); + } + + static StbTrueTypeVertex[] a$src$ALgg_vape_ui_font_stb_StbTrueTypeVertex_$1sz52d4(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n) { + StbTrueTypeCharStringContext stbTrueTypeCharStringContext = new StbTrueTypeCharStringContext(1); + StbTrueTypeCharStringContext stbTrueTypeCharStringContext2 = new StbTrueTypeCharStringContext(0); + if (StbRasterizer.V(stbTrueTypeFontInfo, n, stbTrueTypeCharStringContext) != 0) { + StbTrueTypeVertex[] stbTrueTypeVertexArray = new StbTrueTypeVertex[stbTrueTypeCharStringContext.q]; + for (int i = 0; i < stbTrueTypeVertexArray.length; ++i) { + stbTrueTypeVertexArray[i] = new StbTrueTypeVertex(); + } + stbTrueTypeCharStringContext2.V = stbTrueTypeVertexArray; + if (StbRasterizer.V(stbTrueTypeFontInfo, n, stbTrueTypeCharStringContext2) != 0) { + if (!G && stbTrueTypeCharStringContext2.q != stbTrueTypeCharStringContext.q) { + throw new AssertionError(); + } + return stbTrueTypeVertexArray; + } + } + return null; + } + + static int J(StbTrueTypeFontInfo stbTrueTypeFontInfo) { + if (stbTrueTypeFontInfo.Q < 0) { + long l = StbRasterizer.v(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.U, "SVG "); + if (l != 0L) { + long l2 = StbRasterizer.c$src$J$1nktx4p(stbTrueTypeFontInfo.S, (int)(l + 2L)); + stbTrueTypeFontInfo.Q = (int)(l + l2); + } else { + stbTrueTypeFontInfo.Q = 0; + } + } + return stbTrueTypeFontInfo.Q; + } + + static void b(StbTrueTypeBitmap stbTrueTypeBitmap, StbTrueTypeEdge[] stbTrueTypeEdgeArray, int n, int n2, int n3, int n4) { + StbTrueTypeActiveEdge stbTrueTypeActiveEdge = null; + float[] fArray = new float[129]; + float[] fArray2 = stbTrueTypeBitmap.K > 64 ? new float[stbTrueTypeBitmap.K * 2 + 1] : fArray; + int n5 = 0; + int n6 = stbTrueTypeBitmap.K; + int n7 = n4; + stbTrueTypeEdgeArray[n].X = (float)(n4 + stbTrueTypeBitmap.c) + 1.0f; + int n8 = 0; + for (int i = 0; i < stbTrueTypeBitmap.c; ++i) { + float f = (float)n7 + 0.0f; + float f2 = (float)n7 + 1.0f; + Arrays.fill(fArray2, n5, n5 + stbTrueTypeBitmap.K, 0.0f); + Arrays.fill(fArray2, n6, n6 + stbTrueTypeBitmap.K + 1, 0.0f); + StbTrueTypeActiveEdge stbTrueTypeActiveEdge2 = null; + StbTrueTypeActiveEdge stbTrueTypeActiveEdge3 = stbTrueTypeActiveEdge; + while (stbTrueTypeActiveEdge3 != null) { + if (stbTrueTypeActiveEdge3.m <= f) { + if (stbTrueTypeActiveEdge2 != null) { + stbTrueTypeActiveEdge2.l = stbTrueTypeActiveEdge3.l; + } else { + stbTrueTypeActiveEdge = stbTrueTypeActiveEdge3.l; + } + stbTrueTypeActiveEdge3 = stbTrueTypeActiveEdge2 != null ? stbTrueTypeActiveEdge2.l : stbTrueTypeActiveEdge; + continue; + } + stbTrueTypeActiveEdge2 = stbTrueTypeActiveEdge3; + stbTrueTypeActiveEdge3 = stbTrueTypeActiveEdge3.l; + } + while (n8 < n && stbTrueTypeEdgeArray[n8].X <= f2) { + if (stbTrueTypeEdgeArray[n8].X != stbTrueTypeEdgeArray[n8].u) { + StbTrueTypeActiveEdge stbTrueTypeActiveEdge4 = StbRasterizer.O(stbTrueTypeEdgeArray[n8], n3, f); + if (i == 0 && n4 != 0 && stbTrueTypeActiveEdge4.m < f) { + stbTrueTypeActiveEdge4.m = f; + } + stbTrueTypeActiveEdge4.l = stbTrueTypeActiveEdge; + stbTrueTypeActiveEdge = stbTrueTypeActiveEdge4; + } + ++n8; + } + if (stbTrueTypeActiveEdge != null) { + StbRasterizer.c(fArray2, n5, fArray2, n6, stbTrueTypeBitmap.K, stbTrueTypeActiveEdge, f); + } + float f3 = 0.0f; + for (int j = 0; j < stbTrueTypeBitmap.K; ++j) { + float f4 = fArray2[n5 + j] + (f3 += fArray2[n6 + j]); + int n9 = (int)(f4 = Math.abs(f4) * 255.0f + 0.5f); + if (n9 > 255) { + n9 = 255; + } + stbTrueTypeBitmap.E[stbTrueTypeBitmap.h + i * stbTrueTypeBitmap.A + j] = (byte)n9; + } + stbTrueTypeActiveEdge3 = stbTrueTypeActiveEdge; + while (stbTrueTypeActiveEdge3 != null) { + stbTrueTypeActiveEdge3.e += stbTrueTypeActiveEdge3.L; + stbTrueTypeActiveEdge3 = stbTrueTypeActiveEdge3.l; + } + ++n7; + } + } + + public static void K(StbTrueTypePackedChar[] stbTrueTypePackedCharArray, int n, int n2, int n3, float[] fArray, float[] fArray2, StbTrueTypeAlignedQuad stbTrueTypeAlignedQuad, int n4) { + float f = 1.0f / (float)n; + float f2 = 1.0f / (float)n2; + StbTrueTypePackedChar stbTrueTypePackedChar = stbTrueTypePackedCharArray[n3]; + if (n4 != 0) { + float f3 = (int)Math.floor(fArray[0] + stbTrueTypePackedChar.s + 0.5f); + float f4 = (int)Math.floor(fArray2[0] + stbTrueTypePackedChar.G + 0.5f); + stbTrueTypeAlignedQuad.v = f3; + stbTrueTypeAlignedQuad.x = f4; + stbTrueTypeAlignedQuad.K = f3 + stbTrueTypePackedChar.t - stbTrueTypePackedChar.s; + stbTrueTypeAlignedQuad.M = f4 + stbTrueTypePackedChar.R - stbTrueTypePackedChar.G; + } else { + stbTrueTypeAlignedQuad.v = fArray[0] + stbTrueTypePackedChar.s; + stbTrueTypeAlignedQuad.x = fArray2[0] + stbTrueTypePackedChar.G; + stbTrueTypeAlignedQuad.K = fArray[0] + stbTrueTypePackedChar.t; + stbTrueTypeAlignedQuad.M = fArray2[0] + stbTrueTypePackedChar.R; + } + stbTrueTypeAlignedQuad.G = (float)stbTrueTypePackedChar.b * f; + stbTrueTypeAlignedQuad.O = (float)stbTrueTypePackedChar.k * f2; + stbTrueTypeAlignedQuad.S = (float)stbTrueTypePackedChar.q * f; + stbTrueTypeAlignedQuad.C = (float)stbTrueTypePackedChar.p * f2; + fArray[0] = fArray[0] + stbTrueTypePackedChar.A; + } + + static int K(StbByteBufferView frame) { + if (frame.h >= frame.y) { + return 0; + } + return frame.f[frame.C + frame.h] & 0xFF; + } + + static StbByteBufferView W(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n) { + StbByteBufferView frame = stbTrueTypeFontInfo.N.k(); + int n2 = -1; + StbRasterizer.i(frame, 0); + int n3 = StbRasterizer.Q(frame); + if (n3 == 0) { + StbRasterizer.K(frame, n); + n2 = StbRasterizer.Q(frame); + } else if (n3 == 3) { + int n4 = StbRasterizer.p(frame); + int n5 = StbRasterizer.p(frame); + for (int i = 0; i < n4; ++i) { + int n6 = StbRasterizer.Q(frame); + int n7 = StbRasterizer.p(frame); + if (n >= n5 && n < n7) { + n2 = n6; + break; + } + n5 = n7; + } + } + if (n2 == -1) { + return StbRasterizer.x(null, 0, 0); + } + return StbRasterizer.u(stbTrueTypeFontInfo.g, StbRasterizer.e(stbTrueTypeFontInfo.H, n2)); + } + + public static int E(StbTrueTypePackContext stbTrueTypePackContext, StbTrueTypeFontInfo stbTrueTypeFontInfo, StbTrueTypePackRange[] stbTrueTypePackRangeArray, int n, StbTrueTypePackRectangle[] stbTrueTypePackRectangleArray) { + int n2 = -1; + int n3 = 1; + int n4 = stbTrueTypePackContext.c; + int n5 = stbTrueTypePackContext.m; + int n6 = 0; + for (int i = 0; i < n; ++i) { + float f = stbTrueTypePackRangeArray[i].E; + float f2 = f > 0.0f ? StbRasterizer.V(stbTrueTypeFontInfo, f) : StbRasterizer.b(stbTrueTypeFontInfo, -f); + stbTrueTypePackContext.c = stbTrueTypePackRangeArray[i].i; + stbTrueTypePackContext.m = stbTrueTypePackRangeArray[i].y; + float f3 = 1.0f / (float)stbTrueTypePackContext.c; + float f4 = 1.0f / (float)stbTrueTypePackContext.m; + float f5 = StbRasterizer.U(stbTrueTypePackContext.c); + float f6 = StbRasterizer.U(stbTrueTypePackContext.m); + for (int j = 0; j < stbTrueTypePackRangeArray[i].b; ++j) { + StbTrueTypePackRectangle stbTrueTypePackRectangle = stbTrueTypePackRectangleArray[n6]; + if (stbTrueTypePackRectangle.M != 0 && stbTrueTypePackRectangle.N != 0 && stbTrueTypePackRectangle.e != 0) { + StbTrueTypePackedChar stbTrueTypePackedChar = stbTrueTypePackRangeArray[i].M[j]; + int[] nArray = new int[1]; + int[] nArray2 = new int[1]; + int[] nArray3 = new int[1]; + int[] nArray4 = new int[1]; + int[] nArray5 = new int[1]; + int[] nArray6 = new int[1]; + int n7 = stbTrueTypePackRangeArray[i].N == null ? stbTrueTypePackRangeArray[i].R + j : stbTrueTypePackRangeArray[i].N[j]; + int n8 = StbRasterizer.T(stbTrueTypeFontInfo, n7); + int n9 = stbTrueTypePackContext.G; + stbTrueTypePackRectangle.P += n9; + stbTrueTypePackRectangle.J += n9; + stbTrueTypePackRectangle.N -= n9; + stbTrueTypePackRectangle.e -= n9; + StbRasterizer.q(stbTrueTypeFontInfo, n8, nArray, nArray2); + StbRasterizer.Z(stbTrueTypeFontInfo, n8, f2 * (float)stbTrueTypePackContext.c, f2 * (float)stbTrueTypePackContext.m, nArray3, nArray4, nArray5, nArray6); + StbRasterizer.j(stbTrueTypeFontInfo, stbTrueTypePackContext.X, stbTrueTypePackRectangle.P + stbTrueTypePackRectangle.J * stbTrueTypePackContext.b, stbTrueTypePackRectangle.N - stbTrueTypePackContext.c + 1, stbTrueTypePackRectangle.e - stbTrueTypePackContext.m + 1, stbTrueTypePackContext.b, f2 * (float)stbTrueTypePackContext.c, f2 * (float)stbTrueTypePackContext.m, 0.0f, 0.0f, n8); + if (stbTrueTypePackContext.c > 1) { + StbRasterizer.H(stbTrueTypePackContext.X, stbTrueTypePackRectangle.P + stbTrueTypePackRectangle.J * stbTrueTypePackContext.b, stbTrueTypePackRectangle.N, stbTrueTypePackRectangle.e, stbTrueTypePackContext.b, stbTrueTypePackContext.c); + } + if (stbTrueTypePackContext.m > 1) { + StbRasterizer.p(stbTrueTypePackContext.X, stbTrueTypePackRectangle.P + stbTrueTypePackRectangle.J * stbTrueTypePackContext.b, stbTrueTypePackRectangle.N, stbTrueTypePackRectangle.e, stbTrueTypePackContext.b, stbTrueTypePackContext.m); + } + stbTrueTypePackedChar.b = (short)stbTrueTypePackRectangle.P; + stbTrueTypePackedChar.k = (short)stbTrueTypePackRectangle.J; + stbTrueTypePackedChar.q = (short)(stbTrueTypePackRectangle.P + stbTrueTypePackRectangle.N); + stbTrueTypePackedChar.p = (short)(stbTrueTypePackRectangle.J + stbTrueTypePackRectangle.e); + stbTrueTypePackedChar.A = f2 * (float)nArray[0]; + stbTrueTypePackedChar.s = (float)nArray3[0] * f3 + f5; + stbTrueTypePackedChar.G = (float)nArray4[0] * f4 + f6; + stbTrueTypePackedChar.t = (float)(nArray3[0] + stbTrueTypePackRectangle.N) * f3 + f5; + stbTrueTypePackedChar.R = (float)(nArray4[0] + stbTrueTypePackRectangle.e) * f4 + f6; + if (n8 == 0) { + n2 = j; + } + } else if (stbTrueTypePackContext.h != 0) { + n3 = 0; + } else if (stbTrueTypePackRectangle.M != 0 && stbTrueTypePackRectangle.N == 0 && stbTrueTypePackRectangle.e == 0 && n2 >= 0) { + stbTrueTypePackRangeArray[i].M[j] = stbTrueTypePackRangeArray[i].M[n2]; + } else { + n3 = 0; + } + ++n6; + } + } + stbTrueTypePackContext.c = n4; + stbTrueTypePackContext.m = n5; + return n3; + } + + static boolean d(byte[] byArray, int n, int n2, int n3, int n4, int n5) { + return (byArray[n] & 0xFF) == n2 && (byArray[n + 1] & 0xFF) == n3 && (byArray[n + 2] & 0xFF) == n4 && (byArray[n + 3] & 0xFF) == n5; + } + + static int s(byte[] byArray) { + if (StbRasterizer.c$src$Z$1nktxih(byArray, 0)) { + return 1; + } + if (StbRasterizer.f(byArray, 0, "ttcf") && (StbRasterizer.c$src$J$1nktx4p(byArray, 4) == 65536L || StbRasterizer.c$src$J$1nktx4p(byArray, 4) == 131072L)) { + return StbRasterizer.B(byArray, 8); + } + return 0; + } + + static void A(StbTrueTypeCharStringContext stbTrueTypeCharStringContext, int n, int n2, int n3, int n4, int n5, int n6, int n7) { + if (stbTrueTypeCharStringContext.J != 0) { + StbRasterizer.V(stbTrueTypeCharStringContext, n2, n3); + if (n == 4) { + StbRasterizer.V(stbTrueTypeCharStringContext, n4, n5); + StbRasterizer.V(stbTrueTypeCharStringContext, n6, n7); + } + } else { + StbRasterizer.d(stbTrueTypeCharStringContext.V[stbTrueTypeCharStringContext.q], n, n2, n3, n4, n5); + stbTrueTypeCharStringContext.V[stbTrueTypeCharStringContext.q].a = (short)n6; + stbTrueTypeCharStringContext.V[stbTrueTypeCharStringContext.q].s = (short)n7; + } + ++stbTrueTypeCharStringContext.q; + } + + static int Q(StbByteBufferView frame) { + if (frame.h >= frame.y) { + return 0; + } + return frame.f[frame.C + frame.h++] & 0xFF; + } + + static int E(byte[] byArray, int n, byte[] byArray2, int n2, int n3, int n4, int n5) { + int n6 = StbRasterizer.x(byArray, n + 2); + int n7 = n + StbRasterizer.x(byArray, n + 4); + for (int i = 0; i < n6; ++i) { + int n8 = n + 6 + 12 * i; + int n9 = StbRasterizer.x(byArray, n8 + 6); + if (n9 != n4) continue; + int n10 = StbRasterizer.x(byArray, n8 + 0); + int n11 = StbRasterizer.x(byArray, n8 + 2); + int n12 = StbRasterizer.x(byArray, n8 + 4); + if (n10 != 0 && (n10 != 3 || n11 != 1) && (n10 != 3 || n11 != 10)) continue; + int n13 = StbRasterizer.x(byArray, n8 + 8); + int n14 = StbRasterizer.x(byArray, n8 + 10); + int n15 = StbRasterizer.Y(byArray2, n2, n3, byArray, n7 + n14, n13); + if (n15 < 0) continue; + if (i + 1 < n6 && StbRasterizer.x(byArray, n8 + 12 + 6) == n5 && StbRasterizer.x(byArray, n8 + 12) == n10 && StbRasterizer.x(byArray, n8 + 12 + 2) == n11 && StbRasterizer.x(byArray, n8 + 12 + 4) == n12) { + n13 = StbRasterizer.x(byArray, n8 + 12 + 8); + n14 = StbRasterizer.x(byArray, n8 + 12 + 10); + if (!(n13 == 0 ? n15 == n3 : n15 < n3 && (byArray2[n2 + n15] & 0xFF) == 32 && StbRasterizer.d(byArray2, n2 + ++n15, n3 - n15, byArray, n7 + n14, n13))) continue; + return 1; + } + if (n15 != n3) continue; + return 1; + } + return 0; + } + + static int Y(byte[] byArray, int n, int n2, byte[] byArray2, int n3, int n4) { + int n5 = 0; + while (n4 > 0) { + int n6 = (byArray2[n3] & 0xFF) * 256 + (byArray2[n3 + 1] & 0xFF); + if (n6 < 128) { + if (n5 >= n2) { + return -1; + } + if ((byArray[n + n5++] & 0xFF) != n6) { + return -1; + } + } else if (n6 < 2048) { + if (n5 + 1 >= n2) { + return -1; + } + if ((byArray[n + n5++] & 0xFF) != 192 + (n6 >> 6)) { + return -1; + } + if ((byArray[n + n5++] & 0xFF) != 128 + (n6 & 0x3F)) { + return -1; + } + } else if (n6 >= 55296 && n6 < 56320) { + int n7 = (byArray2[n3 + 2] & 0xFF) * 256 + (byArray2[n3 + 3] & 0xFF); + if (n5 + 3 >= n2) { + return -1; + } + int n8 = (n6 - 55296 << 10) + (n7 - 56320) + 65536; + if ((byArray[n + n5++] & 0xFF) != 240 + (n8 >> 18)) { + return -1; + } + if ((byArray[n + n5++] & 0xFF) != 128 + (n8 >> 12 & 0x3F)) { + return -1; + } + if ((byArray[n + n5++] & 0xFF) != 128 + (n8 >> 6 & 0x3F)) { + return -1; + } + if ((byArray[n + n5++] & 0xFF) != 128 + (n8 & 0x3F)) { + return -1; + } + n3 += 2; + n4 -= 2; + } else { + if (n6 >= 56320 && n6 < 57344) { + return -1; + } + if (n5 + 2 >= n2) { + return -1; + } + if ((byArray[n + n5++] & 0xFF) != 224 + (n6 >> 12)) { + return -1; + } + if ((byArray[n + n5++] & 0xFF) != 128 + (n6 >> 6 & 0x3F)) { + return -1; + } + if ((byArray[n + n5++] & 0xFF) != 128 + (n6 & 0x3F)) { + return -1; + } + } + n3 += 2; + n4 -= 2; + } + return n5; + } + + public static void j(StbTrueTypeFontInfo stbTrueTypeFontInfo, byte[] byArray, int n, int n2, int n3, int n4, float f, float f2, float f3, float f4, int n5) { + int[] nArray = new int[1]; + int[] nArray2 = new int[1]; + StbTrueTypeVertex[] stbTrueTypeVertexArray = StbRasterizer.m(stbTrueTypeFontInfo, n5); + int n6 = stbTrueTypeVertexArray != null ? stbTrueTypeVertexArray.length : 0; + StbTrueTypeBitmap stbTrueTypeBitmap = new StbTrueTypeBitmap(); + StbRasterizer.G(stbTrueTypeFontInfo, n5, f, f2, f3, f4, nArray, nArray2, null, null); + stbTrueTypeBitmap.E = byArray; + stbTrueTypeBitmap.h = n; + stbTrueTypeBitmap.K = n2; + stbTrueTypeBitmap.c = n3; + stbTrueTypeBitmap.A = n4; + if (stbTrueTypeBitmap.K != 0 && stbTrueTypeBitmap.c != 0) { + StbRasterizer.b(stbTrueTypeBitmap, 0.35f, stbTrueTypeVertexArray, n6, f, f2, f3, f4, nArray[0], nArray2[0], 1); + } + } + + public static float b(StbTrueTypeFontInfo stbTrueTypeFontInfo, float f) { + int n = StbRasterizer.x(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.c + 18); + return f / (float)n; + } + + public static byte[] q(StbTrueTypeFontInfo stbTrueTypeFontInfo, float f, float f2, float f3, float f4, int n, int[] nArray, int[] nArray2, int[] nArray3, int[] nArray4) { + return StbRasterizer.F(stbTrueTypeFontInfo, f, f2, f3, f4, StbRasterizer.T(stbTrueTypeFontInfo, n), nArray, nArray2, nArray3, nArray4); + } + + public static void Y(StbTrueTypeFontInfo stbTrueTypeFontInfo, int[] nArray, int[] nArray2, int[] nArray3, int[] nArray4) { + nArray[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.c + 36); + nArray2[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.c + 38); + nArray3[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.c + 40); + nArray4[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.c + 42); + } + + static StbTrueTypePoint[] P(StbTrueTypeVertex[] stbTrueTypeVertexArray, int n, float f, int[][] nArray, int[] nArray2) { + int n2; + StbTrueTypePoint[] stbTrueTypePointArray = null; + int[] nArray3 = new int[]{0}; + float f2 = f * f; + int n3 = 0; + int n4 = 0; + for (n2 = 0; n2 < n; ++n2) { + if (stbTrueTypeVertexArray[n2].O != 1) continue; + ++n3; + } + nArray2[0] = n3; + if (n3 == 0) { + return null; + } + nArray[0] = new int[n3]; + for (int i = 0; i < 2; ++i) { + float f3 = 0.0f; + float f4 = 0.0f; + if (i == 1) { + stbTrueTypePointArray = new StbTrueTypePoint[nArray3[0]]; + for (n2 = 0; n2 < stbTrueTypePointArray.length; ++n2) { + stbTrueTypePointArray[n2] = new StbTrueTypePoint(); + } + } + nArray3[0] = 0; + n3 = -1; + block9: for (n2 = 0; n2 < n; ++n2) { + switch (stbTrueTypeVertexArray[n2].O) { + case 1: { + if (n3 >= 0) { + nArray[0][n3] = nArray3[0] - n4; + } + ++n3; + n4 = nArray3[0]; + f3 = stbTrueTypeVertexArray[n2].f; + f4 = stbTrueTypeVertexArray[n2].H; + int n5 = nArray3[0]; + nArray3[0] = n5 + 1; + StbRasterizer.r(stbTrueTypePointArray, n5, f3, f4); + continue block9; + } + case 2: { + f3 = stbTrueTypeVertexArray[n2].f; + f4 = stbTrueTypeVertexArray[n2].H; + int n6 = nArray3[0]; + nArray3[0] = n6 + 1; + StbRasterizer.r(stbTrueTypePointArray, n6, f3, f4); + continue block9; + } + case 3: { + StbRasterizer.y(stbTrueTypePointArray, nArray3, f3, f4, stbTrueTypeVertexArray[n2].h, stbTrueTypeVertexArray[n2].D, stbTrueTypeVertexArray[n2].f, stbTrueTypeVertexArray[n2].H, f2, 0); + f3 = stbTrueTypeVertexArray[n2].f; + f4 = stbTrueTypeVertexArray[n2].H; + continue block9; + } + case 4: { + StbRasterizer.w(stbTrueTypePointArray, nArray3, f3, f4, stbTrueTypeVertexArray[n2].h, stbTrueTypeVertexArray[n2].D, stbTrueTypeVertexArray[n2].a, stbTrueTypeVertexArray[n2].s, stbTrueTypeVertexArray[n2].f, stbTrueTypeVertexArray[n2].H, f2, 0); + f3 = stbTrueTypeVertexArray[n2].f; + f4 = stbTrueTypeVertexArray[n2].H; + } + } + } + nArray[0][n3] = nArray3[0] - n4; + } + return stbTrueTypePointArray; + } + + static int i(float f, float f2, int n, StbTrueTypeVertex[] stbTrueTypeVertexArray) { + float[] fArray = new float[2]; + float[] fArray2 = new float[]{1.0f, 0.0f}; + int n2 = 0; + float f3 = f2 % 1.0f; + if (f3 < 0.01f) { + f2 += 0.01f; + } else if (f3 > 0.99f) { + f2 -= 0.01f; + } + fArray[0] = f; + fArray[1] = f2; + for (int i = 0; i < n; ++i) { + short s; + short s2; + short s3; + short s4; + if (stbTrueTypeVertexArray[i].O == 2) { + float f4; + s4 = stbTrueTypeVertexArray[i - 1].f; + s3 = stbTrueTypeVertexArray[i - 1].H; + s2 = stbTrueTypeVertexArray[i].f; + s = stbTrueTypeVertexArray[i].H; + if (f2 > (float)Math.min(s3, s) && f2 < (float)Math.max(s3, s) && f > (float)Math.min(s4, s2) && (f4 = (f2 - (float)s3) / (float)(s - s3) * (float)(s2 - s4) + (float)s4) < f) { + n2 += s3 < s ? 1 : -1; + } + } + if (stbTrueTypeVertexArray[i].O != 3) continue; + s4 = stbTrueTypeVertexArray[i - 1].f; + s3 = stbTrueTypeVertexArray[i - 1].H; + s2 = stbTrueTypeVertexArray[i].h; + s = stbTrueTypeVertexArray[i].D; + short s5 = stbTrueTypeVertexArray[i].f; + short s6 = stbTrueTypeVertexArray[i].H; + int n3 = Math.min(s4, Math.min(s2, s5)); + int n4 = Math.min(s3, Math.min(s, s6)); + int n5 = Math.max(s3, Math.max(s, s6)); + if (!(f2 > (float)n4) || !(f2 < (float)n5) || !(f > (float)n3)) continue; + float[] fArray3 = new float[2]; + float[] fArray4 = new float[2]; + float[] fArray5 = new float[2]; + float[][] fArray6 = new float[2][2]; + fArray3[0] = s4; + fArray3[1] = s3; + fArray4[0] = s2; + fArray4[1] = s; + fArray5[0] = s5; + fArray5[1] = s6; + if (StbRasterizer.d(fArray3, fArray4) || StbRasterizer.d(fArray4, fArray5)) { + float f5; + s4 = stbTrueTypeVertexArray[i - 1].f; + s3 = stbTrueTypeVertexArray[i - 1].H; + s2 = stbTrueTypeVertexArray[i].f; + s = stbTrueTypeVertexArray[i].H; + if (!(f2 > (float)Math.min(s3, s)) || !(f2 < (float)Math.max(s3, s)) || !(f > (float)Math.min(s4, s2)) || !((f5 = (f2 - (float)s3) / (float)(s - s3) * (float)(s2 - s4) + (float)s4) < f)) continue; + n2 += s3 < s ? 1 : -1; + continue; + } + int n6 = StbRasterizer.J(fArray, fArray2, fArray3, fArray4, fArray5, fArray6); + if (n6 >= 1 && fArray6[0][0] < 0.0f) { + n2 += fArray6[0][1] < 0.0f ? -1 : 1; + } + if (n6 < 2 || !(fArray6[1][0] < 0.0f)) continue; + n2 += fArray6[1][1] < 0.0f ? -1 : 1; + } + return n2; + } + + static boolean S(byte[] byArray, int n, byte[] byArray2, int n2, int n3, int n4) { + long l; + if (!StbRasterizer.c$src$Z$1nktxih(byArray, n)) { + return false; + } + if (n4 != 0 && (StbRasterizer.x(byArray, (int)(l = StbRasterizer.v(byArray, n, "head")) + 44) & 7) != (n4 & 7)) { + return false; + } + l = StbRasterizer.v(byArray, n, "name"); + if (l == 0L) { + return false; + } + if (n4 != 0) { + if (StbRasterizer.E(byArray, (int)l, byArray2, n2, n3, 16, -1) != 0) { + return true; + } + if (StbRasterizer.E(byArray, (int)l, byArray2, n2, n3, 1, -1) != 0) { + return true; + } + if (StbRasterizer.E(byArray, (int)l, byArray2, n2, n3, 3, -1) != 0) { + return true; + } + } else { + if (StbRasterizer.E(byArray, (int)l, byArray2, n2, n3, 16, 17) != 0) { + return true; + } + if (StbRasterizer.E(byArray, (int)l, byArray2, n2, n3, 1, 2) != 0) { + return true; + } + if (StbRasterizer.E(byArray, (int)l, byArray2, n2, n3, 3, -1) != 0) { + return true; + } + } + return false; + } + + static void A(float[] fArray, int n, int n2, StbTrueTypeActiveEdge stbTrueTypeActiveEdge, float f, float f2, float f3, float f4) { + if (f2 == f4) { + return; + } + if (!G && !(f2 < f4)) { + throw new AssertionError(); + } + if (!G && !(stbTrueTypeActiveEdge.j <= stbTrueTypeActiveEdge.m)) { + throw new AssertionError(); + } + if (f2 > stbTrueTypeActiveEdge.m) { + return; + } + if (f4 < stbTrueTypeActiveEdge.j) { + return; + } + if (f2 < stbTrueTypeActiveEdge.j) { + f += (f3 - f) * (stbTrueTypeActiveEdge.j - f2) / (f4 - f2); + f2 = stbTrueTypeActiveEdge.j; + } + if (f4 > stbTrueTypeActiveEdge.m) { + f3 += (f3 - f) * (stbTrueTypeActiveEdge.m - f4) / (f4 - f2); + f4 = stbTrueTypeActiveEdge.m; + } + if (f <= (float)n2 && f3 <= (float)n2) { + int n3 = n + n2; + fArray[n3] = fArray[n3] + stbTrueTypeActiveEdge.T * (f4 - f2); + } else if (!(f >= (float)(n2 + 1)) || !(f3 >= (float)(n2 + 1))) { + int n4 = n + n2; + fArray[n4] = fArray[n4] + stbTrueTypeActiveEdge.T * (f4 - f2) * (1.0f - (f - (float)n2 + (f3 - (float)n2)) / 2.0f); + } + } + + static int y(StbTrueTypePoint[] stbTrueTypePointArray, int[] nArray, float f, float f2, float f3, float f4, float f5, float f6, float f7, int n) { + float f8 = (f + 2.0f * f3 + f5) / 4.0f; + float f9 = (f2 + 2.0f * f4 + f6) / 4.0f; + float f10 = (f + f5) / 2.0f - f8; + float f11 = (f2 + f6) / 2.0f - f9; + if (n > 16) { + return 1; + } + if (f10 * f10 + f11 * f11 > f7) { + StbRasterizer.y(stbTrueTypePointArray, nArray, f, f2, (f + f3) / 2.0f, (f2 + f4) / 2.0f, f8, f9, f7, n + 1); + StbRasterizer.y(stbTrueTypePointArray, nArray, f8, f9, (f3 + f5) / 2.0f, (f4 + f6) / 2.0f, f5, f6, f7, n + 1); + } else { + StbRasterizer.r(stbTrueTypePointArray, nArray[0], f5, f6); + nArray[0] = nArray[0] + 1; + } + return 1; + } + + public static void n(StbTrueTypePackContext stbTrueTypePackContext, int n, int n2) { + if (!G && n > 8) { + throw new AssertionError(); + } + if (!G && n2 > 8) { + throw new AssertionError(); + } + if (n <= 8) { + stbTrueTypePackContext.c = n; + } + if (n2 <= 8) { + stbTrueTypePackContext.m = n2; + } + } + + static int L(StbTrueTypeFontInfo stbTrueTypeFontInfo, byte[] byArray, int n) { + long l; + stbTrueTypeFontInfo.S = byArray; + stbTrueTypeFontInfo.U = n; + stbTrueTypeFontInfo.g = StbRasterizer.x(null, 0, 0); + long l2 = StbRasterizer.v(byArray, n, "cmap"); + stbTrueTypeFontInfo.v = (int)StbRasterizer.v(byArray, n, "loca"); + stbTrueTypeFontInfo.c = (int)StbRasterizer.v(byArray, n, "head"); + stbTrueTypeFontInfo.p = (int)StbRasterizer.v(byArray, n, "glyf"); + stbTrueTypeFontInfo.w = (int)StbRasterizer.v(byArray, n, "hhea"); + stbTrueTypeFontInfo.d = (int)StbRasterizer.v(byArray, n, "hmtx"); + stbTrueTypeFontInfo.L = (int)StbRasterizer.v(byArray, n, "kern"); + stbTrueTypeFontInfo.G = (int)StbRasterizer.v(byArray, n, "GPOS"); + if (l2 == 0L || stbTrueTypeFontInfo.c == 0 || stbTrueTypeFontInfo.w == 0 || stbTrueTypeFontInfo.d == 0) { + return 0; + } + if (stbTrueTypeFontInfo.p != 0) { + if (stbTrueTypeFontInfo.v == 0) { + return 0; + } + } else { + long l3 = 2L; + long l4 = 0L; + long l5 = 0L; + long l6 = 0L; + long l7 = StbRasterizer.v(byArray, n, "CFF "); + if (l7 == 0L) { + return 0; + } + stbTrueTypeFontInfo.H = StbRasterizer.x(null, 0, 0); + stbTrueTypeFontInfo.N = StbRasterizer.x(null, 0, 0); + stbTrueTypeFontInfo.g = StbRasterizer.x(byArray, (int)l7, 0x20000000); + StbByteBufferView frame = stbTrueTypeFontInfo.g.k(); + StbRasterizer.K(frame, 2); + StbRasterizer.i(frame, StbRasterizer.Q(frame)); + StbRasterizer.B(frame); + StbByteBufferView frame2 = StbRasterizer.B(frame); + StbByteBufferView frame3 = StbRasterizer.e(frame2, 0); + StbRasterizer.B(frame); + stbTrueTypeFontInfo.j = StbRasterizer.B(frame); + long[] lArray = new long[]{l4}; + StbRasterizer.X(frame3, 17, 1, lArray); + l4 = lArray[0]; + long[] lArray2 = new long[]{l3}; + StbRasterizer.X(frame3, 262, 1, lArray2); + l3 = lArray2[0]; + long[] lArray3 = new long[]{l5}; + StbRasterizer.X(frame3, 292, 1, lArray3); + l5 = lArray3[0]; + long[] lArray4 = new long[]{l6}; + StbRasterizer.X(frame3, 293, 1, lArray4); + l6 = lArray4[0]; + stbTrueTypeFontInfo.J = StbRasterizer.u(frame, frame3); + if (l3 != 2L) { + return 0; + } + if (l4 == 0L) { + return 0; + } + if (l5 != 0L) { + if (l6 == 0L) { + return 0; + } + StbRasterizer.i(frame, (int)l5); + stbTrueTypeFontInfo.H = StbRasterizer.B(frame); + stbTrueTypeFontInfo.N = StbRasterizer.E(frame, (int)l6, frame.y - (int)l6); + } + StbRasterizer.i(frame, (int)l4); + stbTrueTypeFontInfo.z = StbRasterizer.B(frame); + } + stbTrueTypeFontInfo.h = (l = StbRasterizer.v(byArray, n, "maxp")) != 0L ? StbRasterizer.x(byArray, (int)(l + 4L)) : 65535; + stbTrueTypeFontInfo.Q = -1; + int n2 = StbRasterizer.x(byArray, (int)(l2 + 2L)); + stbTrueTypeFontInfo.Y = 0; + block7: for (int i = 0; i < n2; ++i) { + long l8 = l2 + 4L + (long)(8 * i); + switch (StbRasterizer.x(byArray, (int)l8)) { + case 3: { + switch (StbRasterizer.x(byArray, (int)l8 + 2)) { + case 1: + case 10: { + stbTrueTypeFontInfo.Y = (int)(l2 + StbRasterizer.c$src$J$1nktx4p(byArray, (int)l8 + 4)); + } + } + continue block7; + } + case 0: { + stbTrueTypeFontInfo.Y = (int)(l2 + StbRasterizer.c$src$J$1nktx4p(byArray, (int)l8 + 4)); + } + } + } + if (stbTrueTypeFontInfo.Y == 0) { + return 0; + } + stbTrueTypeFontInfo.T = StbRasterizer.x(byArray, stbTrueTypeFontInfo.c + 50); + return 1; + } + + public static int v(StbTrueTypeFontInfo stbTrueTypeFontInfo) { + byte[] byArray = stbTrueTypeFontInfo.S; + int n = stbTrueTypeFontInfo.L; + if (n == 0) { + return 0; + } + if (StbRasterizer.x(byArray, n + 2) < 1) { + return 0; + } + if (StbRasterizer.x(byArray, n + 8) != 1) { + return 0; + } + return StbRasterizer.x(byArray, n + 10); + } + + public static int z(StbTrueTypeFontInfo stbTrueTypeFontInfo, byte[] byArray, int n) { + return StbRasterizer.L(stbTrueTypeFontInfo, byArray, n); + } + + static int E(byte[] byArray, int n) { + if (StbRasterizer.c$src$Z$1nktxih(byArray, 0)) { + return n == 0 ? 0 : -1; + } + if (StbRasterizer.f(byArray, 0, "ttcf") && (StbRasterizer.c$src$J$1nktx4p(byArray, 4) == 65536L || StbRasterizer.c$src$J$1nktx4p(byArray, 4) == 131072L)) { + int n2 = StbRasterizer.B(byArray, 8); + if (n >= n2) { + return -1; + } + return (int)StbRasterizer.c$src$J$1nktx4p(byArray, 12 + n * 4); + } + return -1; + } + + static void d(StbTrueTypeCharStringContext stbTrueTypeCharStringContext) { + if (stbTrueTypeCharStringContext.s != stbTrueTypeCharStringContext.C || stbTrueTypeCharStringContext.p != stbTrueTypeCharStringContext.o) { + StbRasterizer.A(stbTrueTypeCharStringContext, 2, (int)stbTrueTypeCharStringContext.s, (int)stbTrueTypeCharStringContext.p, 0, 0, 0, 0); + } + } + + static void H(byte[] byArray, int n, int n2, int n3, int n4, int n5) { + byte[] byArray2 = new byte[8]; + int n6 = n2 - n5; + Arrays.fill(byArray2, (byte)0); + for (int i = 0; i < n3; ++i) { + int n7; + Arrays.fill(byArray2, 0, n5, (byte)0); + int n8 = 0; + switch (n5) { + case 2: { + for (n7 = 0; n7 <= n6; ++n7) { + byArray2[n7 + n5 & 7] = byArray[n + n7]; + byArray[n + n7] = (byte)((n8 += (byArray[n + n7] & 0xFF) - (byArray2[n7 & 7] & 0xFF)) / 2); + } + break; + } + case 3: { + for (n7 = 0; n7 <= n6; ++n7) { + byArray2[n7 + n5 & 7] = byArray[n + n7]; + byArray[n + n7] = (byte)((n8 += (byArray[n + n7] & 0xFF) - (byArray2[n7 & 7] & 0xFF)) / 3); + } + break; + } + case 4: { + for (n7 = 0; n7 <= n6; ++n7) { + byArray2[n7 + n5 & 7] = byArray[n + n7]; + byArray[n + n7] = (byte)((n8 += (byArray[n + n7] & 0xFF) - (byArray2[n7 & 7] & 0xFF)) / 4); + } + break; + } + case 5: { + for (n7 = 0; n7 <= n6; ++n7) { + byArray2[n7 + n5 & 7] = byArray[n + n7]; + byArray[n + n7] = (byte)((n8 += (byArray[n + n7] & 0xFF) - (byArray2[n7 & 7] & 0xFF)) / 5); + } + break; + } + default: { + for (n7 = 0; n7 <= n6; ++n7) { + byArray2[n7 + n5 & 7] = byArray[n + n7]; + byArray[n + n7] = (byte)((n8 += (byArray[n + n7] & 0xFF) - (byArray2[n7 & 7] & 0xFF)) / n5); + } + } + } + while (n7 < n2) { + byArray[n + n7] = (byte)((n8 -= byArray2[n7 & 7] & 0xFF) / n5); + ++n7; + } + n += n4; + } + } + + public static StbTrueTypeVertex[] m(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n) { + if (stbTrueTypeFontInfo.g.y == 0) { + return StbRasterizer.o(stbTrueTypeFontInfo, n); + } + return StbRasterizer.a$src$ALgg_vape_ui_font_stb_StbTrueTypeVertex_$1sz52d4(stbTrueTypeFontInfo, n); + } + + public static void u(StbTrueTypeFontInfo stbTrueTypeFontInfo, byte[] byArray, int n, int n2, int n3, int n4, float f, float f2, float f3, float f4, int n5) { + StbRasterizer.j(stbTrueTypeFontInfo, byArray, n, n2, n3, n4, f, f2, f3, f4, StbRasterizer.T(stbTrueTypeFontInfo, n5)); + } + + public static void F(StbTrueTypeFontInfo stbTrueTypeFontInfo, byte[] byArray, int n, int n2, int n3, int n4, float f, float f2, int n5) { + StbRasterizer.u(stbTrueTypeFontInfo, byArray, n, n2, n3, n4, f, f2, 0.0f, 0.0f, n5); + } + + static int L(byte[] byArray, int n, int n2) { + int n3 = StbRasterizer.x(byArray, n); + switch (n3) { + case 1: { + int n4 = StbRasterizer.x(byArray, n + 2); + int n5 = 0; + int n6 = n4 - 1; + int n7 = n2; + while (n5 <= n6) { + int n8 = n + 4; + int n9 = n5 + n6 >> 1; + int n10 = StbRasterizer.x(byArray, n8 + 2 * n9); + int n11 = n10; + if (n7 < n11) { + n6 = n9 - 1; + continue; + } + if (n7 > n11) { + n5 = n9 + 1; + continue; + } + return n9; + } + break; + } + case 2: { + int n12 = StbRasterizer.x(byArray, n + 2); + int n13 = n + 4; + int n14 = 0; + int n15 = n12 - 1; + int n16 = n2; + while (n14 <= n15) { + int n17 = n14 + n15 >> 1; + int n18 = n13 + 6 * n17; + int n19 = StbRasterizer.x(byArray, n18); + int n20 = StbRasterizer.x(byArray, n18 + 2); + if (n16 < n19) { + n15 = n17 - 1; + continue; + } + if (n16 > n20) { + n14 = n17 + 1; + continue; + } + int n21 = StbRasterizer.x(byArray, n18 + 4); + return n21 + n2 - n19; + } + break; + } + default: { + return -1; + } + } + return -1; + } + + public static int g(String string, String string2) { + byte[] byArray; + byte[] byArray2 = string.getBytes(); + return StbRasterizer.d(byArray2, 0, byArray2.length, byArray = string2.getBytes(), 0, byArray.length) ? 1 : 0; + } + + static int X(float f, float f2, float f3, float[] fArray) { + float f4 = -f / 3.0f; + float f5 = f * (2.0f * f * f - 9.0f * f2) / 27.0f + f3; + float f6 = f2 - f * f / 3.0f; + float f7 = f6 * f6 * f6; + float f8 = f5 * f5 + 4.0f * f7 / 27.0f; + if (f8 >= 0.0f) { + float f9 = (float)Math.sqrt(f8); + float f10 = (-f5 + f9) / 2.0f; + float f11 = (-f5 - f9) / 2.0f; + f10 = StbRasterizer.w(f10); + f11 = StbRasterizer.w(f11); + fArray[0] = f4 + f10 + f11; + return 1; + } + float f12 = (float)Math.sqrt(-f6 / 3.0f); + float f13 = (float)Math.acos(-Math.sqrt(-27.0f / f7) * (double)f5 / 2.0) / 3.0f; + float f14 = (float)Math.cos(f13); + float f15 = (float)Math.cos((double)f13 - 1.570796) * 1.7320508f; + fArray[0] = f4 + f12 * 2.0f * f14; + fArray[1] = f4 - f12 * (f14 + f15); + fArray[2] = f4 - f12 * (f14 - f15); + return 3; + } + + static long u(StbByteBufferView frame, int n) { + long l = 0L; + if (!(G || n >= 1 && n <= 4)) { + throw new AssertionError(); + } + for (int i = 0; i < n; ++i) { + l = l << 8 | (long)StbRasterizer.Q(frame); + } + return l; + } + + public static int U(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, int[] nArray) { + return StbRasterizer.B(stbTrueTypeFontInfo, StbRasterizer.T(stbTrueTypeFontInfo, n), nArray); + } + + public static int A(StbTrueTypeFontInfo stbTrueTypeFontInfo, StbTrueTypeKerningEntry[] stbTrueTypeKerningEntryArray, int n) { + byte[] byArray = stbTrueTypeFontInfo.S; + int n2 = stbTrueTypeFontInfo.L; + if (n2 == 0) { + return 0; + } + if (StbRasterizer.x(byArray, n2 + 2) < 1) { + return 0; + } + if (StbRasterizer.x(byArray, n2 + 8) != 1) { + return 0; + } + int n3 = StbRasterizer.x(byArray, n2 + 10); + if (n < n3) { + n3 = n; + } + for (int i = 0; i < n3; ++i) { + stbTrueTypeKerningEntryArray[i].q = StbRasterizer.x(byArray, n2 + 18 + i * 6); + stbTrueTypeKerningEntryArray[i].o = StbRasterizer.x(byArray, n2 + 20 + i * 6); + stbTrueTypeKerningEntryArray[i].y = StbRasterizer.E$src$S$1b9gd7y(byArray, n2 + 22 + i * 6); + } + return n3; + } + + public static int G(StbTrueTypePackContext stbTrueTypePackContext, StbTrueTypeFontInfo stbTrueTypeFontInfo, StbTrueTypePackRange[] stbTrueTypePackRangeArray, int n, StbTrueTypePackRectangle[] stbTrueTypePackRectangleArray) { + boolean bl = false; + int n2 = 0; + for (int i = 0; i < n; ++i) { + float f = stbTrueTypePackRangeArray[i].E; + float f2 = f > 0.0f ? StbRasterizer.V(stbTrueTypeFontInfo, f) : StbRasterizer.b(stbTrueTypeFontInfo, -f); + stbTrueTypePackRangeArray[i].i = stbTrueTypePackContext.c; + stbTrueTypePackRangeArray[i].y = stbTrueTypePackContext.m; + for (int j = 0; j < stbTrueTypePackRangeArray[i].b; ++j) { + int[] nArray = new int[1]; + int[] nArray2 = new int[1]; + int[] nArray3 = new int[1]; + int[] nArray4 = new int[1]; + int n3 = stbTrueTypePackRangeArray[i].N == null ? stbTrueTypePackRangeArray[i].R + j : stbTrueTypePackRangeArray[i].N[j]; + int n4 = StbRasterizer.T(stbTrueTypeFontInfo, n3); + if (n4 == 0 && (stbTrueTypePackContext.h != 0 || bl)) { + stbTrueTypePackRectangleArray[n2].e = 0; + stbTrueTypePackRectangleArray[n2].N = 0; + } else { + StbRasterizer.G(stbTrueTypeFontInfo, n4, f2 * (float)stbTrueTypePackContext.c, f2 * (float)stbTrueTypePackContext.m, 0.0f, 0.0f, nArray, nArray2, nArray3, nArray4); + stbTrueTypePackRectangleArray[n2].N = nArray3[0] - nArray[0] + stbTrueTypePackContext.G + stbTrueTypePackContext.c - 1; + stbTrueTypePackRectangleArray[n2].e = nArray4[0] - nArray2[0] + stbTrueTypePackContext.G + stbTrueTypePackContext.m - 1; + if (n4 == 0) { + bl = true; + } + } + ++n2; + } + } + return n2; + } + + static StbByteBufferView p(StbByteBufferView frame, int n) { + int n2 = StbRasterizer.q(frame); + int n3 = 107; + if (n2 >= 33900) { + n3 = 32768; + } else if (n2 >= 1240) { + n3 = 1131; + } + if ((n += n3) < 0 || n >= n2) { + return StbRasterizer.x(null, 0, 0); + } + return StbRasterizer.e(frame, n); + } + + static float E(float f, float f2, float f3, float f4, float f5) { + return StbRasterizer.A(f, f3 - f2, f5 - f4); + } + + static int V(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, StbTrueTypeCharStringContext stbTrueTypeCharStringContext) { + boolean bl = true; + int n2 = 0; + int n3 = 0; + int n4 = 0; + boolean bl2 = false; + float[] fArray = new float[48]; + StbByteBufferView[] frameArray = new StbByteBufferView[10]; + StbByteBufferView frame = stbTrueTypeFontInfo.J.k(); + StbByteBufferView frame2 = StbRasterizer.e(stbTrueTypeFontInfo.z, n); + while (frame2.h < frame2.y) { + boolean bl3 = true; + int n5 = StbRasterizer.Q(frame2); + block0 : switch (n5) { + case 19: + case 20: { + if (bl) { + n2 += n4 / 2; + } + bl = false; + StbRasterizer.K(frame2, (n2 + 7) / 8); + break; + } + case 1: + case 3: + case 18: + case 23: { + n2 += n4 / 2; + break; + } + case 21: { + bl = false; + if (n4 < 2) { + return 0; + } + StbRasterizer.Q(stbTrueTypeCharStringContext, fArray[n4 - 2], fArray[n4 - 1]); + break; + } + case 4: { + bl = false; + if (n4 < 1) { + return 0; + } + StbRasterizer.Q(stbTrueTypeCharStringContext, 0.0f, fArray[n4 - 1]); + break; + } + case 22: { + bl = false; + if (n4 < 1) { + return 0; + } + StbRasterizer.Q(stbTrueTypeCharStringContext, fArray[n4 - 1], 0.0f); + break; + } + case 5: { + int n6 = 0; + if (n4 < 2) { + return 0; + } + while (n6 + 1 < n4) { + StbRasterizer.z(stbTrueTypeCharStringContext, fArray[n6], fArray[n6 + 1]); + n6 += 2; + } + break; + } + case 7: { + int n6 = 0; + if (n4 < 1) { + return 0; + } + for (n6 = 0; n6 < n4; ++n6) { + StbRasterizer.z(stbTrueTypeCharStringContext, 0.0f, fArray[n6]); + if (++n6 >= n4) break block0; + StbRasterizer.z(stbTrueTypeCharStringContext, fArray[n6], 0.0f); + } + break; + } + case 6: { + int n6 = 0; + if (n4 < 1) { + return 0; + } + while (n6 < n4) { + StbRasterizer.z(stbTrueTypeCharStringContext, fArray[n6], 0.0f); + if (++n6 >= n4) break block0; + StbRasterizer.z(stbTrueTypeCharStringContext, 0.0f, fArray[n6]); + ++n6; + } + break; + } + case 31: { + int n6 = 0; + if (n4 < 4) { + return 0; + } + while (n6 + 3 < n4) { + StbRasterizer.s(stbTrueTypeCharStringContext, fArray[n6], 0.0f, fArray[n6 + 1], fArray[n6 + 2], n4 - n6 == 5 ? fArray[n6 + 4] : 0.0f, fArray[n6 + 3]); + if ((n6 += 4) + 3 >= n4) break block0; + StbRasterizer.s(stbTrueTypeCharStringContext, 0.0f, fArray[n6], fArray[n6 + 1], fArray[n6 + 2], fArray[n6 + 3], n4 - n6 == 5 ? fArray[n6 + 4] : 0.0f); + n6 += 4; + } + break; + } + case 30: { + int n6 = 0; + if (n4 < 4) { + return 0; + } + while (n6 + 3 < n4) { + StbRasterizer.s(stbTrueTypeCharStringContext, 0.0f, fArray[n6], fArray[n6 + 1], fArray[n6 + 2], fArray[n6 + 3], n4 - n6 == 5 ? fArray[n6 + 4] : 0.0f); + if ((n6 += 4) + 3 >= n4) break block0; + StbRasterizer.s(stbTrueTypeCharStringContext, fArray[n6], 0.0f, fArray[n6 + 1], fArray[n6 + 2], n4 - n6 == 5 ? fArray[n6 + 4] : 0.0f, fArray[n6 + 3]); + n6 += 4; + } + break; + } + case 8: { + int n6 = 0; + if (n4 < 6) { + return 0; + } + while (n6 + 5 < n4) { + StbRasterizer.s(stbTrueTypeCharStringContext, fArray[n6], fArray[n6 + 1], fArray[n6 + 2], fArray[n6 + 3], fArray[n6 + 4], fArray[n6 + 5]); + n6 += 6; + } + break; + } + case 24: { + int n6 = 0; + if (n4 < 8) { + return 0; + } + while (n6 + 5 < n4 - 2) { + StbRasterizer.s(stbTrueTypeCharStringContext, fArray[n6], fArray[n6 + 1], fArray[n6 + 2], fArray[n6 + 3], fArray[n6 + 4], fArray[n6 + 5]); + n6 += 6; + } + if (n6 + 1 >= n4) { + return 0; + } + StbRasterizer.z(stbTrueTypeCharStringContext, fArray[n6], fArray[n6 + 1]); + break; + } + case 25: { + int n6 = 0; + if (n4 < 8) { + return 0; + } + while (n6 + 1 < n4 - 6) { + StbRasterizer.z(stbTrueTypeCharStringContext, fArray[n6], fArray[n6 + 1]); + n6 += 2; + } + if (n6 + 5 >= n4) { + return 0; + } + StbRasterizer.s(stbTrueTypeCharStringContext, fArray[n6], fArray[n6 + 1], fArray[n6 + 2], fArray[n6 + 3], fArray[n6 + 4], fArray[n6 + 5]); + break; + } + case 26: + case 27: { + int n6 = 0; + if (n4 < 4) { + return 0; + } + float f = 0.0f; + if ((n4 & 1) != 0) { + f = fArray[n6]; + ++n6; + } + while (n6 + 3 < n4) { + if (n5 == 27) { + StbRasterizer.s(stbTrueTypeCharStringContext, fArray[n6], f, fArray[n6 + 1], fArray[n6 + 2], fArray[n6 + 3], 0.0f); + } else { + StbRasterizer.s(stbTrueTypeCharStringContext, f, fArray[n6], fArray[n6 + 1], fArray[n6 + 2], 0.0f, fArray[n6 + 3]); + } + f = 0.0f; + n6 += 4; + } + break; + } + case 10: { + if (!bl2) { + if (stbTrueTypeFontInfo.N.y != 0) { + frame = StbRasterizer.W(stbTrueTypeFontInfo, n); + } + bl2 = true; + } + } + case 29: { + if (n4 < 1) { + return 0; + } + int n7 = (int)fArray[--n4]; + if (n3 >= 10) { + return 0; + } + frameArray[n3++] = frame2.k(); + frame2 = StbRasterizer.p(n5 == 10 ? frame : stbTrueTypeFontInfo.j, n7); + if (frame2.y == 0) { + return 0; + } + frame2.h = 0; + bl3 = false; + break; + } + case 11: { + if (n3 <= 0) { + return 0; + } + frame2 = frameArray[--n3]; + bl3 = false; + break; + } + case 14: { + StbRasterizer.d(stbTrueTypeCharStringContext); + return 1; + } + case 12: { + int n8 = StbRasterizer.Q(frame2); + switch (n8) { + case 34: { + if (n4 < 7) { + return 0; + } + float f = fArray[0]; + float f2 = fArray[1]; + float f3 = fArray[2]; + float f4 = fArray[3]; + float f5 = fArray[4]; + float f6 = fArray[5]; + float f7 = fArray[6]; + StbRasterizer.s(stbTrueTypeCharStringContext, f, 0.0f, f2, f3, f4, 0.0f); + StbRasterizer.s(stbTrueTypeCharStringContext, f5, 0.0f, f6, -f3, f7, 0.0f); + break block0; + } + case 35: { + if (n4 < 13) { + return 0; + } + float f = fArray[0]; + float f8 = fArray[1]; + float f2 = fArray[2]; + float f3 = fArray[3]; + float f4 = fArray[4]; + float f9 = fArray[5]; + float f5 = fArray[6]; + float f10 = fArray[7]; + float f6 = fArray[8]; + float f11 = fArray[9]; + float f7 = fArray[10]; + float f12 = fArray[11]; + StbRasterizer.s(stbTrueTypeCharStringContext, f, f8, f2, f3, f4, f9); + StbRasterizer.s(stbTrueTypeCharStringContext, f5, f10, f6, f11, f7, f12); + break block0; + } + case 36: { + if (n4 < 9) { + return 0; + } + float f = fArray[0]; + float f8 = fArray[1]; + float f2 = fArray[2]; + float f3 = fArray[3]; + float f4 = fArray[4]; + float f5 = fArray[5]; + float f6 = fArray[6]; + float f11 = fArray[7]; + float f7 = fArray[8]; + StbRasterizer.s(stbTrueTypeCharStringContext, f, f8, f2, f3, f4, 0.0f); + StbRasterizer.s(stbTrueTypeCharStringContext, f5, 0.0f, f6, f11, f7, -(f8 + f3 + f11)); + break block0; + } + case 37: { + float f12; + if (n4 < 11) { + return 0; + } + float f = fArray[0]; + float f8 = fArray[1]; + float f2 = fArray[2]; + float f3 = fArray[3]; + float f4 = fArray[4]; + float f9 = fArray[5]; + float f5 = fArray[6]; + float f10 = fArray[7]; + float f6 = fArray[8]; + float f11 = fArray[9]; + float f7 = f12 = fArray[10]; + float f13 = f + f2 + f4 + f5 + f6; + float f14 = f8 + f3 + f9 + f10 + f11; + if (Math.abs(f13) > Math.abs(f14)) { + f12 = -f14; + } else { + f7 = -f13; + } + StbRasterizer.s(stbTrueTypeCharStringContext, f, f8, f2, f3, f4, f9); + StbRasterizer.s(stbTrueTypeCharStringContext, f5, f10, f6, f11, f7, f12); + break block0; + } + } + return 0; + } + default: { + float f; + if (n5 != 255 && n5 != 28 && n5 < 32) { + return 0; + } + if (n5 == 255) { + f = (float)((int)StbRasterizer.g(frame2)) / 65536.0f; + } else { + StbRasterizer.K(frame2, -1); + f = (short)StbRasterizer.v(frame2); + } + if (n4 >= 48) { + return 0; + } + fArray[n4++] = f; + bl3 = false; + } + } + if (!bl3) continue; + n4 = 0; + } + return 0; + } + + public static void b(StbTrueTypeBitmap stbTrueTypeBitmap, float f, StbTrueTypeVertex[] stbTrueTypeVertexArray, int n, float f2, float f3, float f4, float f5, int n2, int n3, int n4) { + int[] nArray; + int[][] nArrayArray; + float f6 = f2 > f3 ? f3 : f2; + StbTrueTypePoint[] stbTrueTypePointArray = StbRasterizer.P(stbTrueTypeVertexArray, n, f / f6, nArrayArray = new int[][]{null}, nArray = new int[]{0}); + if (stbTrueTypePointArray != null) { + StbRasterizer.b(stbTrueTypeBitmap, stbTrueTypePointArray, nArrayArray[0], nArray[0], f2, f3, f4, f5, n2, n3, n4); + } + } + + static int h(byte[] byArray, byte[] byArray2, int n) { + int n2 = 0; + int n3; + while ((n3 = StbRasterizer.c(byArray, n2)) >= 0) { + if (StbRasterizer.S(byArray, n3, byArray2, 0, byArray2.length, n)) { + return n3; + } + ++n2; + } + return n3; + } + + public static int C(StbTrueTypePackContext stbTrueTypePackContext, byte[] byArray, int n, int n2, int n3, int n4) { + StbTrueTypePackAtlasState stbTrueTypePackAtlasState = new StbTrueTypePackAtlasState(); + int n5 = n - n4; + StbTrueTypeGlyphPackNode[] stbTrueTypeGlyphPackNodeArray = new StbTrueTypeGlyphPackNode[n5]; + for (int i = 0; i < n5; ++i) { + stbTrueTypeGlyphPackNodeArray[i] = new StbTrueTypeGlyphPackNode(); + } + stbTrueTypePackContext.w = n; + stbTrueTypePackContext.d = n2; + stbTrueTypePackContext.X = byArray; + stbTrueTypePackContext.J = stbTrueTypePackAtlasState; + stbTrueTypePackContext.j = stbTrueTypeGlyphPackNodeArray; + stbTrueTypePackContext.G = n4; + stbTrueTypePackContext.b = n3 != 0 ? n3 : n; + stbTrueTypePackContext.c = 1; + stbTrueTypePackContext.m = 1; + stbTrueTypePackContext.h = 0; + StbRasterizer.b(stbTrueTypePackAtlasState, n - n4, n2 - n4, stbTrueTypeGlyphPackNodeArray, n5); + if (byArray != null) { + Arrays.fill(byArray, 0, n * n2, (byte)0); + } + return 1; + } + + static int N(byte[] byArray, int n) { + return byArray[n] & 0xFF; + } + + static void w(StbTrueTypePoint[] stbTrueTypePointArray, int[] nArray, float f, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, int n) { + float f10 = f3 - f; + float f11 = f4 - f2; + float f12 = f5 - f3; + float f13 = f6 - f4; + float f14 = f7 - f5; + float f15 = f8 - f6; + float f16 = f7 - f; + float f17 = f8 - f2; + float f18 = (float)(Math.sqrt(f10 * f10 + f11 * f11) + Math.sqrt(f12 * f12 + f13 * f13) + Math.sqrt(f14 * f14 + f15 * f15)); + float f19 = (float)Math.sqrt(f16 * f16 + f17 * f17); + float f20 = f18 * f18 - f19 * f19; + if (n > 16) { + return; + } + if (f20 > f9) { + float f21 = (f + f3) / 2.0f; + float f22 = (f2 + f4) / 2.0f; + float f23 = (f3 + f5) / 2.0f; + float f24 = (f4 + f6) / 2.0f; + float f25 = (f5 + f7) / 2.0f; + float f26 = (f6 + f8) / 2.0f; + float f27 = (f21 + f23) / 2.0f; + float f28 = (f22 + f24) / 2.0f; + float f29 = (f23 + f25) / 2.0f; + float f30 = (f24 + f26) / 2.0f; + float f31 = (f27 + f29) / 2.0f; + float f32 = (f28 + f30) / 2.0f; + StbRasterizer.w(stbTrueTypePointArray, nArray, f, f2, f21, f22, f27, f28, f31, f32, f9, n + 1); + StbRasterizer.w(stbTrueTypePointArray, nArray, f31, f32, f29, f30, f25, f26, f7, f8, f9, n + 1); + } else { + StbRasterizer.r(stbTrueTypePointArray, nArray[0], f7, f8); + nArray[0] = nArray[0] + 1; + } + } + + static int J(float[] fArray, float[] fArray2, float[] fArray3, float[] fArray4, float[] fArray5, float[][] fArray6) { + float f; + float f2; + float f3; + float f4 = fArray3[1] * fArray2[0] - fArray3[0] * fArray2[1]; + float f5 = fArray4[1] * fArray2[0] - fArray4[0] * fArray2[1]; + float f6 = fArray5[1] * fArray2[0] - fArray5[0] * fArray2[1]; + float f7 = fArray[1] * fArray2[0] - fArray[0] * fArray2[1]; + float f8 = f4 - 2.0f * f5 + f6; + float f9 = f5 - f4; + float f10 = f4 - f7; + float f11 = 0.0f; + float f12 = 0.0f; + int n = 0; + if ((double)f8 != 0.0) { + f3 = f9 * f9 - f8 * f10; + if ((double)f3 > 0.0) { + f2 = -1.0f / f8; + f = (float)Math.sqrt(f3); + f11 = (f9 + f) * f2; + f12 = (f9 - f) * f2; + if ((double)f11 >= 0.0 && (double)f11 <= 1.0) { + n = 1; + } + if ((double)f > 0.0 && (double)f12 >= 0.0 && (double)f12 <= 1.0) { + if (n == 0) { + f11 = f12; + } + ++n; + } + } + } else { + f11 = f10 / (-2.0f * f9); + if ((double)f11 >= 0.0 && (double)f11 <= 1.0) { + n = 1; + } + } + if (n == 0) { + return 0; + } + f3 = 1.0f / (fArray2[0] * fArray2[0] + fArray2[1] * fArray2[1]); + f2 = fArray2[0] * f3; + f = fArray2[1] * f3; + float f13 = fArray3[0] * f2 + fArray3[1] * f; + float f14 = fArray4[0] * f2 + fArray4[1] * f; + float f15 = fArray5[0] * f2 + fArray5[1] * f; + float f16 = fArray[0] * f2 + fArray[1] * f; + float f17 = f14 - f13; + float f18 = f15 - f13; + float f19 = f13 - f16; + fArray6[0][0] = f19 + f11 * (2.0f - 2.0f * f11) * f17 + f11 * f11 * f18; + fArray6[0][1] = f8 * f11 + f9; + if (n > 1) { + fArray6[1][0] = f19 + f12 * (2.0f - 2.0f * f12) * f17 + f12 * f12 * f18; + fArray6[1][1] = f8 * f12 + f9; + return 2; + } + return 1; + } + + static int i(byte[] byArray, int n, float f, byte[] byArray2, int n2, int n3, int n4, int n5, StbTrueTypeBakedChar[] stbTrueTypeBakedCharArray) { + StbTrueTypeFontInfo stbTrueTypeFontInfo = new StbTrueTypeFontInfo(); + if (StbRasterizer.L(stbTrueTypeFontInfo, byArray, n) == 0) { + return -1; + } + Arrays.fill(byArray2, 0, n2 * n3, (byte)0); + int n6 = 1; + int n7 = 1; + int n8 = 1; + float f2 = StbRasterizer.V(stbTrueTypeFontInfo, f); + for (int i = 0; i < n5; ++i) { + int[] nArray = new int[1]; + int[] nArray2 = new int[1]; + int[] nArray3 = new int[1]; + int[] nArray4 = new int[1]; + int[] nArray5 = new int[1]; + int[] nArray6 = new int[1]; + int n9 = StbRasterizer.T(stbTrueTypeFontInfo, n4 + i); + StbRasterizer.q(stbTrueTypeFontInfo, n9, nArray, nArray2); + StbRasterizer.Z(stbTrueTypeFontInfo, n9, f2, f2, nArray3, nArray4, nArray5, nArray6); + int n10 = nArray5[0] - nArray3[0]; + int n11 = nArray6[0] - nArray4[0]; + if (n7 + n10 + 1 >= n2) { + n6 = n8; + n7 = 1; + } + if (n6 + n11 + 1 >= n3) { + return -i; + } + StbRasterizer.I(stbTrueTypeFontInfo, byArray2, n7 + n6 * n2, n10, n11, n2, f2, f2, n9); + stbTrueTypeBakedCharArray[i].V = (short)n7; + stbTrueTypeBakedCharArray[i].Q = (short)n6; + stbTrueTypeBakedCharArray[i].U = (short)(n7 + n10); + stbTrueTypeBakedCharArray[i].D = (short)(n6 + n11); + stbTrueTypeBakedCharArray[i].l = f2 * (float)nArray[0]; + stbTrueTypeBakedCharArray[i].B = nArray3[0]; + stbTrueTypeBakedCharArray[i].k = nArray4[0]; + n7 = n7 + n10 + 1; + if (n6 + n11 + 1 <= n8) continue; + n8 = n6 + n11 + 1; + } + return n8; + } + + static int m(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, int[] nArray, int[] nArray2, int[] nArray3, int[] nArray4) { + StbTrueTypeCharStringContext stbTrueTypeCharStringContext = new StbTrueTypeCharStringContext(1); + int n2 = StbRasterizer.V(stbTrueTypeFontInfo, n, stbTrueTypeCharStringContext); + if (n2 != 0) { + if (nArray != null) { + int n3 = 0; + int[] nArray5 = nArray; + nArray5[n3] = stbTrueTypeCharStringContext.y; + } + if (nArray2 != null) { + int n4 = 0; + int[] nArray6 = nArray2; + nArray6[n4] = stbTrueTypeCharStringContext.Z; + } + if (nArray3 != null) { + int n5 = 0; + int[] nArray7 = nArray3; + nArray7[n5] = stbTrueTypeCharStringContext.c; + } + if (nArray4 != null) { + int n6 = 0; + int[] nArray8 = nArray4; + nArray8[n6] = stbTrueTypeCharStringContext.f; + } + return stbTrueTypeCharStringContext.q; + } + if (nArray != null) { + int n7 = 0; + int[] nArray9 = nArray; + nArray9[n7] = 0; + } + if (nArray2 != null) { + int n8 = 0; + int[] nArray10 = nArray2; + nArray10[n8] = 0; + } + if (nArray3 != null) { + int n9 = 0; + int[] nArray11 = nArray3; + nArray11[n9] = 0; + } + if (nArray4 != null) { + int n10 = 0; + int[] nArray12 = nArray4; + nArray12[n10] = 0; + } + return 0; + } + + static void i(StbByteBufferView frame, int n) { + if (!(G || n <= frame.y && n >= 0)) { + throw new AssertionError(); + } + frame.h = n > frame.y || n < 0 ? frame.y : n; + } + + public static byte[] N(StbTrueTypeFontInfo stbTrueTypeFontInfo, float f, float f2, int n, int[] nArray, int[] nArray2, int[] nArray3, int[] nArray4) { + return StbRasterizer.F(stbTrueTypeFontInfo, f, f2, 0.0f, 0.0f, n, nArray, nArray2, nArray3, nArray4); + } + + public static void G(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, float f, float f2, float f3, float f4, int[] nArray, int[] nArray2, int[] nArray3, int[] nArray4) { + int[] nArray5 = new int[]{0}; + int[] nArray6 = new int[]{0}; + int[] nArray7 = new int[]{0}; + int[] nArray8 = new int[]{0}; + if (StbRasterizer.F(stbTrueTypeFontInfo, n, nArray5, nArray6, nArray7, nArray8) == 0) { + if (nArray != null) { + nArray[0] = 0; + } + if (nArray2 != null) { + nArray2[0] = 0; + } + if (nArray3 != null) { + nArray3[0] = 0; + } + if (nArray4 != null) { + nArray4[0] = 0; + } + } else { + if (nArray != null) { + nArray[0] = (int)Math.floor((float)nArray5[0] * f + f3); + } + if (nArray2 != null) { + nArray2[0] = (int)Math.floor((float)(-nArray8[0]) * f2 + f4); + } + if (nArray3 != null) { + nArray3[0] = (int)Math.ceil((float)nArray7[0] * f + f3); + } + if (nArray4 != null) { + nArray4[0] = (int)Math.ceil((float)(-nArray6[0]) * f2 + f4); + } + } + } + + static long v(StbByteBufferView frame) { + int n = StbRasterizer.Q(frame); + if (n >= 32 && n <= 246) { + return n - 139; + } + if (n >= 247 && n <= 250) { + return (n - 247) * 256 + StbRasterizer.Q(frame) + 108; + } + if (n >= 251 && n <= 254) { + return -(n - 251) * 256 - StbRasterizer.Q(frame) - 108; + } + if (n == 28) { + return StbRasterizer.p(frame); + } + if (n == 29) { + return StbRasterizer.g(frame); + } + if (!G) { + throw new AssertionError(); + } + return 0L; + } + + static void G(StbTrueTypeEdge[] stbTrueTypeEdgeArray, int n, int n2) { + while (n2 > 12) { + StbTrueTypeEdge stbTrueTypeEdge; + boolean bl; + int n3 = n2 >> 1; + boolean bl2 = stbTrueTypeEdgeArray[n].X < stbTrueTypeEdgeArray[n + n3].X; + boolean bl3 = bl = stbTrueTypeEdgeArray[n + n3].X < stbTrueTypeEdgeArray[n + n2 - 1].X; + if (bl2 != bl) { + boolean bl4 = stbTrueTypeEdgeArray[n].X < stbTrueTypeEdgeArray[n + n2 - 1].X; + int n4 = bl4 == bl ? 0 : n2 - 1; + stbTrueTypeEdge = stbTrueTypeEdgeArray[n + n4]; + stbTrueTypeEdgeArray[n + n4] = stbTrueTypeEdgeArray[n + n3]; + stbTrueTypeEdgeArray[n + n3] = stbTrueTypeEdge; + } + stbTrueTypeEdge = stbTrueTypeEdgeArray[n]; + stbTrueTypeEdgeArray[n] = stbTrueTypeEdgeArray[n + n3]; + stbTrueTypeEdgeArray[n + n3] = stbTrueTypeEdge; + int n5 = 1; + int n6 = n2 - 1; + while (true) { + if (stbTrueTypeEdgeArray[n + n5].X < stbTrueTypeEdgeArray[n].X) { + ++n5; + continue; + } + while (stbTrueTypeEdgeArray[n].X < stbTrueTypeEdgeArray[n + n6].X) { + --n6; + } + if (n5 >= n6) break; + stbTrueTypeEdge = stbTrueTypeEdgeArray[n + n5]; + stbTrueTypeEdgeArray[n + n5] = stbTrueTypeEdgeArray[n + n6]; + stbTrueTypeEdgeArray[n + n6] = stbTrueTypeEdge; + ++n5; + --n6; + } + if (n6 < n2 - n5) { + StbRasterizer.G(stbTrueTypeEdgeArray, n, n6); + n += n5; + n2 -= n5; + continue; + } + StbRasterizer.G(stbTrueTypeEdgeArray, n + n5, n2 - n5); + n2 = n6; + } + } + + public static byte[] a(StbTrueTypeFontInfo stbTrueTypeFontInfo, float f, int n, int n2, int n3, float f2, int[] nArray, int[] nArray2, int[] nArray3, int[] nArray4) { + return StbRasterizer.A(stbTrueTypeFontInfo, f, StbRasterizer.T(stbTrueTypeFontInfo, n), n2, n3, f2, nArray, nArray2, nArray3, nArray4); + } + + public static int P(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n) { + if (stbTrueTypeFontInfo.g.y != 0) { + return StbRasterizer.m(stbTrueTypeFontInfo, n, null, null, null, null) == 0 ? 1 : 0; + } + int n2 = StbRasterizer.G(stbTrueTypeFontInfo, n); + if (n2 < 0) { + return 1; + } + short s = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, n2); + return s == 0 ? 1 : 0; + } + + public static void q(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, int[] nArray, int[] nArray2) { + int n2 = StbRasterizer.x(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.w + 34); + if (n < n2) { + if (nArray != null) { + nArray[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.d + 4 * n); + } + if (nArray2 != null) { + nArray2[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.d + 4 * n + 2); + } + } else { + if (nArray != null) { + nArray[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.d + 4 * (n2 - 1)); + } + if (nArray2 != null) { + nArray2[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.d + 4 * n2 + 2 * (n - n2)); + } + } + } + + static int c(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, int n2) { + if (stbTrueTypeFontInfo.G == 0) { + return 0; + } + byte[] byArray = stbTrueTypeFontInfo.S; + int n3 = stbTrueTypeFontInfo.G; + if (StbRasterizer.x(byArray, n3 + 0) != 1) { + return 0; + } + if (StbRasterizer.x(byArray, n3 + 2) != 0) { + return 0; + } + int n4 = StbRasterizer.x(byArray, n3 + 8); + int n5 = n3 + n4; + int n6 = StbRasterizer.x(byArray, n5); + for (int i = 0; i < n6; ++i) { + int n7 = StbRasterizer.x(byArray, n5 + 2 + 2 * i); + int n8 = n5 + n7; + int n9 = StbRasterizer.x(byArray, n8); + int n10 = StbRasterizer.x(byArray, n8 + 4); + int n11 = n8 + 6; + if (n9 != 2) continue; + block5: for (int j = 0; j < n10; ++j) { + int n12 = StbRasterizer.x(byArray, n11 + 2 * j); + int n13 = n8 + n12; + int n14 = StbRasterizer.x(byArray, n13); + int n15 = StbRasterizer.x(byArray, n13 + 2); + int n16 = StbRasterizer.L(byArray, n13 + n15, n); + if (n16 == -1) continue; + switch (n14) { + case 1: { + int n17; + int n18; + int n19; + int n20; + int n21; + int n22; + int n23; + int n24; + int n25; + int n26 = StbRasterizer.x(byArray, n13 + 4); + int n27 = StbRasterizer.x(byArray, n13 + 6); + if (n26 == 4 && n27 == 0) { + n25 = 2; + n24 = StbRasterizer.x(byArray, n13 + 8); + n23 = StbRasterizer.x(byArray, n13 + 10 + 2 * n16); + n22 = n13 + n23; + int n28 = StbRasterizer.x(byArray, n22); + int n29 = n22 + 2; + if (n16 >= n24) { + return 0; + } + n21 = n2; + n20 = n28 - 1; + n19 = 0; + while (n19 <= n20) { + n18 = n19 + n20 >> 1; + int n30 = n29 + (2 + n25) * n18; + int n31 = StbRasterizer.x(byArray, n30); + n17 = n31; + if (n21 < n17) { + n20 = n18 - 1; + continue; + } + if (n21 > n17) { + n19 = n18 + 1; + continue; + } + short s = StbRasterizer.E$src$S$1b9gd7y(byArray, n30 + 2); + return s; + } + continue block5; + } + return 0; + } + case 2: { + int n17; + int n18; + int n21; + int n22; + int n23; + int n24; + int n25; + int n27; + int n26; + int n19 = StbRasterizer.x(byArray, n13 + 4); + int n20 = StbRasterizer.x(byArray, n13 + 6); + if (n19 == 4 && n20 == 0) { + n18 = StbRasterizer.x(byArray, n13 + 8); + n17 = StbRasterizer.x(byArray, n13 + 10); + n21 = StbRasterizer.q(byArray, n13 + n18, n); + n26 = StbRasterizer.q(byArray, n13 + n17, n2); + n27 = StbRasterizer.x(byArray, n13 + 12); + n25 = StbRasterizer.x(byArray, n13 + 14); + if (n21 < 0 || n21 >= n27) { + return 0; + } + if (n26 < 0 || n26 >= n25) { + return 0; + } + n23 = n13 + 16; + n22 = n23 + 2 * (n21 * n25); + n24 = StbRasterizer.E$src$S$1b9gd7y(byArray, n22 + 2 * n26); + return n24; + } + return 0; + } + default: { + return 0; + } + } + } + } + return 0; + } + + static int G(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n) { + int n2; + int n3; + if (!G && stbTrueTypeFontInfo.g.y != 0) { + throw new AssertionError(); + } + if (n >= stbTrueTypeFontInfo.h) { + return -1; + } + if (stbTrueTypeFontInfo.T >= 2) { + return -1; + } + if (stbTrueTypeFontInfo.T == 0) { + n3 = stbTrueTypeFontInfo.p + StbRasterizer.x(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.v + n * 2) * 2; + n2 = stbTrueTypeFontInfo.p + StbRasterizer.x(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.v + n * 2 + 2) * 2; + } else { + n3 = (int)((long)stbTrueTypeFontInfo.p + StbRasterizer.c$src$J$1nktx4p(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.v + n * 4)); + n2 = (int)((long)stbTrueTypeFontInfo.p + StbRasterizer.c$src$J$1nktx4p(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.v + n * 4 + 4)); + } + return n3 == n2 ? -1 : n3; + } + + static boolean c$src$Z$1nktxih(byte[] byArray, int n) { + if (StbRasterizer.d(byArray, n, 49, 0, 0, 0)) { + return true; + } + if (StbRasterizer.f(byArray, n, "typ1")) { + return true; + } + if (StbRasterizer.f(byArray, n, "OTTO")) { + return true; + } + if (StbRasterizer.d(byArray, n, 0, 1, 0, 0)) { + return true; + } + return StbRasterizer.f(byArray, n, "true"); + } + + public static int X(byte[] byArray, int n, float f, byte[] byArray2, int n2, int n3, int n4, int n5, StbTrueTypeBakedChar[] stbTrueTypeBakedCharArray) { + return StbRasterizer.i(byArray, n, f, byArray2, n2, n3, n4, n5, stbTrueTypeBakedCharArray); + } + + static void r(StbTrueTypePoint[] stbTrueTypePointArray, int n, float f, float f2) { + if (stbTrueTypePointArray == null) { + return; + } + stbTrueTypePointArray[n].M = f; + stbTrueTypePointArray[n].E = f2; + } + + public static int a(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n) { + byte[] byArray = stbTrueTypeFontInfo.S; + int n2 = StbRasterizer.J(stbTrueTypeFontInfo); + if (n2 == 0) { + return -1; + } + int n3 = StbRasterizer.x(byArray, n2); + int n4 = n2 + 2; + for (int i = 0; i < n3; ++i) { + int n5 = n4 + 12 * i; + if (n < StbRasterizer.x(byArray, n5) || n > StbRasterizer.x(byArray, n5 + 2)) continue; + return n5; + } + return -1; + } + + public static void Z(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, float f, float f2, int[] nArray, int[] nArray2, int[] nArray3, int[] nArray4) { + StbRasterizer.G(stbTrueTypeFontInfo, n, f, f2, 0.0f, 0.0f, nArray, nArray2, nArray3, nArray4); + } + + public static int B(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, int[] nArray) { + byte[] byArray = stbTrueTypeFontInfo.S; + if (stbTrueTypeFontInfo.Q == 0) { + return 0; + } + int n2 = StbRasterizer.a(stbTrueTypeFontInfo, n); + if (n2 >= 0) { + if (nArray != null) { + nArray[0] = stbTrueTypeFontInfo.Q + (int)StbRasterizer.c$src$J$1nktx4p(byArray, n2 + 4); + } + return (int)StbRasterizer.c$src$J$1nktx4p(byArray, n2 + 8); + } + return 0; + } + + public static int s(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, int[] nArray, int[] nArray2, int[] nArray3, int[] nArray4) { + return StbRasterizer.F(stbTrueTypeFontInfo, StbRasterizer.T(stbTrueTypeFontInfo, n), nArray, nArray2, nArray3, nArray4); + } + + static float U(int n) { + if (n == 0) { + return 0.0f; + } + return (float)(-(n - 1)) / (2.0f * (float)n); + } + + static int v(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, int n2) { + byte[] byArray = stbTrueTypeFontInfo.S; + int n3 = stbTrueTypeFontInfo.L; + if (n3 == 0) { + return 0; + } + if (StbRasterizer.x(byArray, n3 + 2) < 1) { + return 0; + } + if (StbRasterizer.x(byArray, n3 + 8) != 1) { + return 0; + } + int n4 = 0; + int n5 = StbRasterizer.x(byArray, n3 + 10) - 1; + long l = (long)n << 16 | (long)n2; + while (n4 <= n5) { + int n6 = n4 + n5 >> 1; + long l2 = StbRasterizer.c$src$J$1nktx4p(byArray, n3 + 18 + n6 * 6); + if (l < l2) { + n5 = n6 - 1; + continue; + } + if (l > l2) { + n4 = n6 + 1; + continue; + } + return StbRasterizer.E$src$S$1b9gd7y(byArray, n3 + 22 + n6 * 6); + } + return 0; + } + + public static void V(StbTrueTypeBakedChar[] stbTrueTypeBakedCharArray, int n, int n2, int n3, float[] fArray, float[] fArray2, StbTrueTypeAlignedQuad stbTrueTypeAlignedQuad, int n4) { + float f = n4 != 0 ? 0.0f : -0.5f; + float f2 = 1.0f / (float)n; + float f3 = 1.0f / (float)n2; + StbTrueTypeBakedChar stbTrueTypeBakedChar = stbTrueTypeBakedCharArray[n3]; + int n5 = (int)Math.floor(fArray[0] + stbTrueTypeBakedChar.B + 0.5f); + int n6 = (int)Math.floor(fArray2[0] + stbTrueTypeBakedChar.k + 0.5f); + stbTrueTypeAlignedQuad.v = (float)n5 + f; + stbTrueTypeAlignedQuad.x = (float)n6 + f; + stbTrueTypeAlignedQuad.K = (float)(n5 + stbTrueTypeBakedChar.U - stbTrueTypeBakedChar.V) + f; + stbTrueTypeAlignedQuad.M = (float)(n6 + stbTrueTypeBakedChar.D - stbTrueTypeBakedChar.Q) + f; + stbTrueTypeAlignedQuad.G = (float)stbTrueTypeBakedChar.V * f2; + stbTrueTypeAlignedQuad.O = (float)stbTrueTypeBakedChar.Q * f3; + stbTrueTypeAlignedQuad.S = (float)stbTrueTypeBakedChar.U * f2; + stbTrueTypeAlignedQuad.C = (float)stbTrueTypeBakedChar.D * f3; + fArray[0] = fArray[0] + stbTrueTypeBakedChar.l; + } + + static void s(StbTrueTypeEdge[] stbTrueTypeEdgeArray, int n) { + StbRasterizer.G(stbTrueTypeEdgeArray, 0, n); + StbRasterizer.N(stbTrueTypeEdgeArray, 0, n); + } + + static void d(StbTrueTypeVertex stbTrueTypeVertex, int n, int n2, int n3, int n4, int n5) { + stbTrueTypeVertex.O = n; + stbTrueTypeVertex.f = (short)n2; + stbTrueTypeVertex.H = (short)n3; + stbTrueTypeVertex.h = (short)n4; + stbTrueTypeVertex.D = (short)n5; + } + + static boolean d(byte[] byArray, int n, int n2, byte[] byArray2, int n3, int n4) { + return n2 == StbRasterizer.Y(byArray, n, n2, byArray2, n3, n4); + } + + static void t(StbTrueTypePackAtlasState stbTrueTypePackAtlasState, StbTrueTypePackRectangle[] stbTrueTypePackRectangleArray, int n) { + int n2; + for (n2 = 0; n2 < n; ++n2) { + if (stbTrueTypePackAtlasState.n + stbTrueTypePackRectangleArray[n2].N > stbTrueTypePackAtlasState.f) { + stbTrueTypePackAtlasState.n = 0; + stbTrueTypePackAtlasState.a = stbTrueTypePackAtlasState.t; + } + if (stbTrueTypePackAtlasState.a + stbTrueTypePackRectangleArray[n2].e > stbTrueTypePackAtlasState.F) break; + stbTrueTypePackRectangleArray[n2].P = stbTrueTypePackAtlasState.n; + stbTrueTypePackRectangleArray[n2].J = stbTrueTypePackAtlasState.a; + stbTrueTypePackRectangleArray[n2].M = 1; + stbTrueTypePackAtlasState.n += stbTrueTypePackRectangleArray[n2].N; + if (stbTrueTypePackAtlasState.a + stbTrueTypePackRectangleArray[n2].e <= stbTrueTypePackAtlasState.t) continue; + stbTrueTypePackAtlasState.t = stbTrueTypePackAtlasState.a + stbTrueTypePackRectangleArray[n2].e; + } + while (n2 < n) { + stbTrueTypePackRectangleArray[n2].M = 0; + ++n2; + } + } + + + public static float N(float f) { + return -f; + } + + public static void x(StbTrueTypeFontInfo stbTrueTypeFontInfo, int[] nArray, int[] nArray2, int[] nArray3) { + if (nArray != null) { + nArray[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.w + 4); + } + if (nArray2 != null) { + nArray2[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.w + 6); + } + if (nArray3 != null) { + nArray3[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.w + 8); + } + } + + static void s(StbTrueTypeCharStringContext stbTrueTypeCharStringContext, float f, float f2, float f3, float f4, float f5, float f6) { + float f7 = stbTrueTypeCharStringContext.C + f; + float f8 = stbTrueTypeCharStringContext.o + f2; + float f9 = f7 + f3; + float f10 = f8 + f4; + stbTrueTypeCharStringContext.C = f9 + f5; + stbTrueTypeCharStringContext.o = f10 + f6; + StbRasterizer.A(stbTrueTypeCharStringContext, 4, (int)stbTrueTypeCharStringContext.C, (int)stbTrueTypeCharStringContext.o, (int)f7, (int)f8, (int)f9, (int)f10); + } + + public static void I(StbTrueTypeFontInfo stbTrueTypeFontInfo, byte[] byArray, int n, int n2, int n3, int n4, float f, float f2, int n5) { + StbRasterizer.j(stbTrueTypeFontInfo, byArray, n, n2, n3, n4, f, f2, 0.0f, 0.0f, n5); + } + + public static void c(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, int[] nArray, int[] nArray2) { + StbRasterizer.q(stbTrueTypeFontInfo, StbRasterizer.T(stbTrueTypeFontInfo, n), nArray, nArray2); + } + + static StbByteBufferView E(StbByteBufferView frame, int n, int n2) { + StbByteBufferView frame2 = StbRasterizer.x(null, 0, 0); + if (n < 0 || n2 < 0 || n > frame.y || n2 > frame.y - n) { + return frame2; + } + frame2.f = frame.f; + frame2.C = frame.C + n; + frame2.y = n2; + return frame2; + } + + static int q(StbByteBufferView frame) { + StbRasterizer.i(frame, 0); + return StbRasterizer.p(frame); + } + + public static int J(StbTrueTypeFontInfo stbTrueTypeFontInfo, int[] nArray, int[] nArray2, int[] nArray3) { + int n = (int)StbRasterizer.v(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.U, "OS/2"); + if (n == 0) { + return 0; + } + if (nArray != null) { + nArray[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, n + 68); + } + if (nArray2 != null) { + nArray2[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, n + 70); + } + if (nArray3 != null) { + nArray3[0] = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, n + 72); + } + return 1; + } + + static StbByteBufferView u(StbByteBufferView frame, StbByteBufferView frame2) { + long[] lArray = new long[]{0L}; + long[] lArray2 = new long[]{0L, 0L}; + StbRasterizer.X(frame2, 18, 2, lArray2); + if (lArray2[1] == 0L || lArray2[0] == 0L) { + return StbRasterizer.x(null, 0, 0); + } + StbByteBufferView frame3 = StbRasterizer.E(frame, (int)lArray2[1], (int)lArray2[0]); + StbRasterizer.X(frame3, 19, 1, lArray); + if (lArray[0] == 0L) { + return StbRasterizer.x(null, 0, 0); + } + StbRasterizer.i(frame, (int)(lArray2[1] + lArray[0])); + return StbRasterizer.B(frame); + } + + public static void H(StbTrueTypePackContext stbTrueTypePackContext, StbTrueTypePackRectangle[] stbTrueTypePackRectangleArray, int n) { + StbRasterizer.t(stbTrueTypePackContext.J, stbTrueTypePackRectangleArray, n); + } + + static void X(StbByteBufferView frame, int n, int n2, long[] lArray) { + StbByteBufferView frame2 = StbRasterizer.C(frame, n); + for (int i = 0; i < n2 && frame2.h < frame2.y; ++i) { + lArray[i] = StbRasterizer.v(frame2); + } + } + + public static void p(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n, float f, float f2, float f3, float f4, int[] nArray, int[] nArray2, int[] nArray3, int[] nArray4) { + StbRasterizer.G(stbTrueTypeFontInfo, StbRasterizer.T(stbTrueTypeFontInfo, n), f, f2, f3, f4, nArray, nArray2, nArray3, nArray4); + } + + static void z(StbTrueTypeCharStringContext stbTrueTypeCharStringContext, float f, float f2) { + stbTrueTypeCharStringContext.C += f; + stbTrueTypeCharStringContext.o += f2; + StbRasterizer.A(stbTrueTypeCharStringContext, 2, (int)stbTrueTypeCharStringContext.C, (int)stbTrueTypeCharStringContext.o, 0, 0, 0, 0); + } + + static float S(float f, float f2) { + return f * f2 / 2.0f; + } + + public static int T(StbTrueTypeFontInfo stbTrueTypeFontInfo, int n) { + byte[] byArray = stbTrueTypeFontInfo.S; + int n2 = stbTrueTypeFontInfo.Y; + int n3 = StbRasterizer.x(byArray, n2 + 0); + if (n3 == 0) { + int n4 = StbRasterizer.x(byArray, n2 + 2); + if (n < n4 - 6) { + return StbRasterizer.N(byArray, n2 + 6 + n); + } + return 0; + } + if (n3 == 6) { + long l = StbRasterizer.x(byArray, n2 + 6); + long l2 = StbRasterizer.x(byArray, n2 + 8); + if ((long)n >= l && (long)n < l + l2) { + return StbRasterizer.x(byArray, n2 + 10 + (n - (int)l) * 2); + } + return 0; + } + if (n3 == 2) { + if (!G) { + throw new AssertionError(); + } + return 0; + } + if (n3 == 4) { + int n5; + int n6; + int n7 = StbRasterizer.x(byArray, n2 + 6) >> 1; + int n8 = StbRasterizer.x(byArray, n2 + 8) >> 1; + int n9 = StbRasterizer.x(byArray, n2 + 10); + int n10 = StbRasterizer.x(byArray, n2 + 12) >> 1; + int n11 = n6 = n2 + 14; + if (n > 65535) { + return 0; + } + if (n >= StbRasterizer.x(byArray, n11 + n10 * 2)) { + n11 += n10 * 2; + } + n11 -= 2; + while (n9 != 0) { + n5 = StbRasterizer.x(byArray, n11 + (n8 >>= 1) * 2); + if (n > n5) { + n11 += n8 * 2; + } + --n9; + } + int n12 = (n11 += 2) - n6 >> 1; + int n13 = StbRasterizer.x(byArray, n2 + 14 + n7 * 2 + 2 + 2 * n12); + int n14 = StbRasterizer.x(byArray, n6 + 2 * n12); + if (n < n13 || n > n14) { + return 0; + } + n5 = StbRasterizer.x(byArray, n2 + 14 + n7 * 6 + 2 + 2 * n12); + if (n5 == 0) { + return n + StbRasterizer.E$src$S$1b9gd7y(byArray, n2 + 14 + n7 * 4 + 2 + 2 * n12) & 0xFFFF; + } + return StbRasterizer.x(byArray, n5 + (n - n13) * 2 + n2 + 14 + n7 * 6 + 2 + 2 * n12); + } + if (n3 == 12 || n3 == 13) { + long l = StbRasterizer.c$src$J$1nktx4p(byArray, n2 + 12); + int n15 = 0; + int n16 = (int)l; + while (n15 < n16) { + int n17 = n15 + (n16 - n15 >> 1); + long l3 = StbRasterizer.c$src$J$1nktx4p(byArray, n2 + 16 + n17 * 12); + long l4 = StbRasterizer.c$src$J$1nktx4p(byArray, n2 + 16 + n17 * 12 + 4); + if ((long)n < l3) { + n16 = n17; + continue; + } + if ((long)n > l4) { + n15 = n17 + 1; + continue; + } + long l5 = StbRasterizer.c$src$J$1nktx4p(byArray, n2 + 16 + n17 * 12 + 8); + if (n3 == 12) { + return (int)(l5 + (long)n - l3); + } + return (int)l5; + } + return 0; + } + if (!G) { + throw new AssertionError(); + } + return 0; + } + + public static void H(StbTrueTypeFontInfo stbTrueTypeFontInfo, byte[] byArray, int n, int n2, int n3, int n4, float f, float f2, float f3, float f4, int n5, int n6, float[] fArray, float[] fArray2, int n7) { + StbRasterizer.j(stbTrueTypeFontInfo, byArray, n, n2 - (n5 - 1), n3 - (n6 - 1), n4, f, f2, f3, f4, n7); + if (n5 > 1) { + StbRasterizer.H(byArray, n, n2, n3, n4, n5); + } + if (n6 > 1) { + StbRasterizer.p(byArray, n, n2, n3, n4, n6); + } + fArray[0] = StbRasterizer.U(n5); + fArray2[0] = StbRasterizer.U(n6); + } + + static { + j = 23; + S = 19; + L = 4; + q = 4; + o = 3; + C = 2; + B = 1053; + T = 11; + a = 6; + x = 2; + Fb = 1041; + i = 2; + E = 7; + R = 1042; + r = 10; + M = 1036; + Ff = 8; + z = 5; + I = 2; + A = 4; + n = 3; + f = 1049; + O = 6; + g = 1043; + Y = 10; + v = 2; + H = 12; + P = 1033; + F = 2052; + V = 2; + U = 1037; + c = 7; + m = 3; + Fc = 1033; + t = 3; + D = 5; + W = 32; + N = 1031; + FC = 3; + Fy = 2; + Q = 8; + F1 = 4; + h = 4; + Z = 1040; + e = 33; + boolean bl = StbRasterizer.class.desiredAssertionStatus(); + boolean bl2 = true; + G = false; + } + + static void N(StbTrueTypeEdge[] stbTrueTypeEdgeArray, int n, int n2) { + for (int i = 1; i < n2; ++i) { + int n3; + StbTrueTypeEdge stbTrueTypeEdge = stbTrueTypeEdgeArray[n + i]; + for (n3 = i; n3 > 0; --n3) { + boolean bl; + StbTrueTypeEdge stbTrueTypeEdge2 = stbTrueTypeEdgeArray[n + n3 - 1]; + boolean bl2 = bl = stbTrueTypeEdge.X < stbTrueTypeEdge2.X; + if (!bl) break; + stbTrueTypeEdgeArray[n + n3] = stbTrueTypeEdgeArray[n + n3 - 1]; + } + if (i == n3) continue; + stbTrueTypeEdgeArray[n + n3] = stbTrueTypeEdge; + } + } + + static StbByteBufferView C(StbByteBufferView frame, int n) { + StbRasterizer.i(frame, 0); + while (frame.h < frame.y) { + int n2 = frame.h; + while (StbRasterizer.K(frame) >= 28) { + StbRasterizer.M(frame); + } + int n3 = frame.h; + int n4 = StbRasterizer.Q(frame); + if (n4 == 12) { + n4 = StbRasterizer.Q(frame) | 0x100; + } + if (n4 != n) continue; + return StbRasterizer.E(frame, n2, n3 - n2); + } + return StbRasterizer.E(frame, 0, 0); + } + + static long g(StbByteBufferView frame) { + return StbRasterizer.u(frame, 4); + } + + public static float V(StbTrueTypeFontInfo stbTrueTypeFontInfo, float f) { + int n = StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.w + 4) - StbRasterizer.E$src$S$1b9gd7y(stbTrueTypeFontInfo.S, stbTrueTypeFontInfo.w + 6); + return f / (float)n; + } + + static void b(StbTrueTypeBitmap stbTrueTypeBitmap, StbTrueTypePoint[] stbTrueTypePointArray, int[] nArray, int n, float f, float f2, float f3, float f4, int n2, int n3, int n4) { + int n5; + float f5 = n4 != 0 ? -f2 : f2; + int n6 = 1; + int n7 = 0; + for (n5 = 0; n5 < n; ++n5) { + n7 += nArray[n5]; + } + StbTrueTypeEdge[] stbTrueTypeEdgeArray = new StbTrueTypeEdge[n7 + 1]; + for (n5 = 0; n5 <= n7; ++n5) { + stbTrueTypeEdgeArray[n5] = new StbTrueTypeEdge(); + } + n7 = 0; + int n8 = 0; + for (n5 = 0; n5 < n; ++n5) { + int n9 = n8; + n8 += nArray[n5]; + int n10 = nArray[n5] - 1; + int n11 = 0; + while (n11 < nArray[n5]) { + int n12 = n11; + int n13 = n10; + if (stbTrueTypePointArray[n9 + n10].E != stbTrueTypePointArray[n9 + n11].E) { + stbTrueTypeEdgeArray[n7].W = 0; + if (n4 != 0 ? stbTrueTypePointArray[n9 + n10].E > stbTrueTypePointArray[n9 + n11].E : stbTrueTypePointArray[n9 + n10].E < stbTrueTypePointArray[n9 + n11].E) { + stbTrueTypeEdgeArray[n7].W = 1; + n12 = n10; + n13 = n11; + } + stbTrueTypeEdgeArray[n7].d = stbTrueTypePointArray[n9 + n12].M * f + f3; + stbTrueTypeEdgeArray[n7].X = (stbTrueTypePointArray[n9 + n12].E * f5 + f4) * (float)n6; + stbTrueTypeEdgeArray[n7].i = stbTrueTypePointArray[n9 + n13].M * f + f3; + stbTrueTypeEdgeArray[n7].u = (stbTrueTypePointArray[n9 + n13].E * f5 + f4) * (float)n6; + ++n7; + } + n10 = n11++; + } + } + StbRasterizer.s(stbTrueTypeEdgeArray, n7); + StbRasterizer.b(stbTrueTypeBitmap, stbTrueTypeEdgeArray, n7, n6, n2, n3); + } + + public static int G(StbTrueTypePackContext stbTrueTypePackContext, byte[] byArray, int n, float f, int n2, int n3, StbTrueTypePackedChar[] stbTrueTypePackedCharArray) { + StbTrueTypePackRange stbTrueTypePackRange = new StbTrueTypePackRange(); + stbTrueTypePackRange.R = n2; + stbTrueTypePackRange.N = null; + stbTrueTypePackRange.b = n3; + stbTrueTypePackRange.M = stbTrueTypePackedCharArray; + stbTrueTypePackRange.E = f; + return StbRasterizer.c(stbTrueTypePackContext, byArray, n, new StbTrueTypePackRange[]{stbTrueTypePackRange}, 1); + } + + public static byte[] A(StbTrueTypeFontInfo stbTrueTypeFontInfo, float f, int n, int n2, int n3, float f2, int[] nArray, int[] nArray2, int[] nArray3, int[] nArray4) { + float f3; + float f4; + float f5; + float f6; + float f7; + float f8; + float f9; + float f10; + float f11 = f; + float f12 = f; + int[] nArray5 = new int[1]; + int[] nArray6 = new int[1]; + int[] nArray7 = new int[1]; + int[] nArray8 = new int[1]; + if (f == 0.0f) { + return null; + } + StbRasterizer.G(stbTrueTypeFontInfo, n, f, f, 0.0f, 0.0f, nArray5, nArray6, nArray7, nArray8); + if (nArray5[0] == nArray7[0] || nArray6[0] == nArray8[0]) { + return null; + } + nArray5[0] = nArray5[0] - n2; + nArray6[0] = nArray6[0] - n2; + nArray7[0] = nArray7[0] + n2; + nArray8[0] = nArray8[0] + n2; + int n4 = nArray7[0] - nArray5[0]; + int n5 = nArray8[0] - nArray6[0]; + if (nArray != null) { + nArray[0] = n4; + } + if (nArray2 != null) { + nArray2[0] = n5; + } + if (nArray3 != null) { + nArray3[0] = nArray5[0]; + } + if (nArray4 != null) { + nArray4[0] = nArray6[0]; + } + f12 = -f12; + float f13 = 9.765625E-4f; + float f14 = 9.536743E-7f; + StbTrueTypeVertex[] stbTrueTypeVertexArray = StbRasterizer.m(stbTrueTypeFontInfo, n); + int n6 = stbTrueTypeVertexArray != null ? stbTrueTypeVertexArray.length : 0; + byte[] byArray = new byte[n4 * n5]; + float[] fArray = new float[n6]; + int n7 = 0; + int n8 = n6 - 1; + while (n7 < n6) { + float f15; + fArray[n7] = stbTrueTypeVertexArray[n7].O == 2 ? ((f10 = (float)Math.sqrt(((f9 = (float)stbTrueTypeVertexArray[n8].f * f11) - (f8 = (float)stbTrueTypeVertexArray[n7].f * f11)) * (f9 - f8) + ((f7 = (float)stbTrueTypeVertexArray[n8].H * f12) - (f6 = (float)stbTrueTypeVertexArray[n7].H * f12)) * (f7 - f6))) < 9.765625E-4f ? 0.0f : 1.0f / f10) : (stbTrueTypeVertexArray[n7].O == 3 ? ((f5 = (f15 = (f10 = (float)stbTrueTypeVertexArray[n7].f * f11) - 2.0f * (f9 = (float)stbTrueTypeVertexArray[n7].h * f11) + (f8 = (float)stbTrueTypeVertexArray[n8].f * f11)) * f15 + (f4 = (f3 = (float)stbTrueTypeVertexArray[n7].H * f12) - 2.0f * (f7 = (float)stbTrueTypeVertexArray[n7].D * f12) + (f6 = (float)stbTrueTypeVertexArray[n8].H * f12)) * f4) >= 9.536743E-7f ? 1.0f / f5 : 0.0f) : 0.0f); + n8 = n7++; + } + for (int i = nArray6[0]; i < nArray8[0]; ++i) { + for (int j = nArray5[0]; j < nArray7[0]; ++j) { + f6 = 999999.0f; + f9 = (float)j + 0.5f; + f7 = (float)i + 0.5f; + f10 = f9 / f11; + f3 = f7 / f12; + int n9 = StbRasterizer.i(f10, f3, n6, stbTrueTypeVertexArray); + for (n7 = 0; n7 < n6; ++n7) { + float f16; + float f17; + float f18; + float f19; + float f20; + float f21; + float f22; + float f23; + float f24; + float f25; + float f26; + float f27; + float f28; + float f29; + float f30; + f4 = (float)stbTrueTypeVertexArray[n7].f * f11; + f5 = (float)stbTrueTypeVertexArray[n7].H * f12; + if (stbTrueTypeVertexArray[n7].O == 2 && fArray[n7] != 0.0f) { + float f31; + f30 = (float)stbTrueTypeVertexArray[n7 - 1].f * f11; + f29 = (float)stbTrueTypeVertexArray[n7 - 1].H * f12; + f28 = (f4 - f9) * (f4 - f9) + (f5 - f7) * (f5 - f7); + if (f28 < f6 * f6) { + f6 = (float)Math.sqrt(f28); + } + if (!((f27 = Math.abs((f30 - f4) * (f5 - f7) - (f29 - f5) * (f4 - f9)) * fArray[n7]) < f6) || !((f31 = -((f26 = f4 - f9) * (f25 = f30 - f4) + (f24 = f5 - f7) * (f23 = f29 - f5)) / (f25 * f25 + f23 * f23)) >= 0.0f) || !(f31 <= 1.0f)) continue; + f6 = f27; + continue; + } + if (stbTrueTypeVertexArray[n7].O != 3) continue; + f30 = (float)stbTrueTypeVertexArray[n7 - 1].f * f11; + f29 = (float)stbTrueTypeVertexArray[n7 - 1].H * f12; + f27 = (float)stbTrueTypeVertexArray[n7].h * f11; + f28 = (float)stbTrueTypeVertexArray[n7].D * f12; + f25 = Math.min(Math.min(f4, f27), f30); + f23 = Math.min(Math.min(f5, f28), f29); + f26 = Math.max(Math.max(f4, f27), f30); + f24 = Math.max(Math.max(f5, f28), f29); + if (!(f9 > f25 - f6) || !(f9 < f26 + f6) || !(f7 > f23 - f6) || !(f7 < f24 + f6)) continue; + int n10 = 0; + float f32 = f27 - f4; + float f33 = f28 - f5; + float f34 = f4 - 2.0f * f27 + f30; + float f35 = f5 - 2.0f * f28 + f29; + float f36 = f4 - f9; + float f37 = f5 - f7; + float[] fArray2 = new float[]{0.0f, 0.0f, 0.0f}; + float f38 = fArray[n7]; + if ((double)f38 == 0.0) { + f22 = 3.0f * (f32 * f34 + f33 * f35); + f21 = 2.0f * (f32 * f32 + f33 * f33) + (f36 * f34 + f37 * f35); + f20 = f36 * f32 + f37 * f33; + if (Math.abs(f22) < 9.536743E-7f) { + if (Math.abs(f21) >= 9.536743E-7f) { + fArray2[n10++] = -f20 / f21; + } + } else { + float f39 = f21 * f21 - 4.0f * f22 * f20; + if (f39 < 0.0f) { + n10 = 0; + } else { + float f40 = (float)Math.sqrt(f39); + fArray2[0] = (-f21 - f40) / (2.0f * f22); + fArray2[1] = (-f21 + f40) / (2.0f * f22); + n10 = 2; + } + } + } else { + f22 = 3.0f * (f32 * f34 + f33 * f35) * f38; + f21 = (2.0f * (f32 * f32 + f33 * f33) + (f36 * f34 + f37 * f35)) * f38; + f20 = (f36 * f32 + f37 * f33) * f38; + n10 = StbRasterizer.X(f22, f21, f20, fArray2); + } + float f41 = (f4 - f9) * (f4 - f9) + (f5 - f7) * (f5 - f7); + if (f41 < f6 * f6) { + f6 = (float)Math.sqrt(f41); + } + if (n10 >= 1 && fArray2[0] >= 0.0f && fArray2[0] <= 1.0f && (f41 = ((f19 = (f18 = 1.0f - (f17 = fArray2[0])) * f18 * f4 + 2.0f * f17 * f18 * f27 + f17 * f17 * f30) - f9) * (f19 - f9) + ((f16 = f18 * f18 * f5 + 2.0f * f17 * f18 * f28 + f17 * f17 * f29) - f7) * (f16 - f7)) < f6 * f6) { + f6 = (float)Math.sqrt(f41); + } + if (n10 >= 2 && fArray2[1] >= 0.0f && fArray2[1] <= 1.0f && (f41 = ((f19 = (f18 = 1.0f - (f17 = fArray2[1])) * f18 * f4 + 2.0f * f17 * f18 * f27 + f17 * f17 * f30) - f9) * (f19 - f9) + ((f16 = f18 * f18 * f5 + 2.0f * f17 * f18 * f28 + f17 * f17 * f29) - f7) * (f16 - f7)) < f6 * f6) { + f6 = (float)Math.sqrt(f41); + } + if (n10 < 3 || !(fArray2[2] >= 0.0f) || !(fArray2[2] <= 1.0f) || !((f41 = ((f19 = (f18 = 1.0f - (f17 = fArray2[2])) * f18 * f4 + 2.0f * f17 * f18 * f27 + f17 * f17 * f30) - f9) * (f19 - f9) + ((f16 = f18 * f18 * f5 + 2.0f * f17 * f18 * f28 + f17 * f17 * f29) - f7) * (f16 - f7)) < f6 * f6)) continue; + f6 = (float)Math.sqrt(f41); + } + if (n9 == 0) { + f6 = -f6; + } + if ((f8 = (float)n3 + f2 * f6) < 0.0f) { + f8 = 0.0f; + } else if (f8 > 255.0f) { + f8 = 255.0f; + } + byArray[(i - nArray6[0]) * n4 + (j - nArray5[0])] = (byte)f8; + } + } + return byArray; + } + + static float w(float f) { + if (f < 0.0f) { + return -((float)Math.pow(-f, 0.3333333432674408)); + } + return (float)Math.pow(f, 0.3333333432674408); + } + + static int u(byte[] byArray, int n) { + return byArray[n]; + } + + static boolean f(byte[] byArray, int n, String string) { + return StbRasterizer.d(byArray, n, (int)string.charAt(0), (int)string.charAt(1), (int)string.charAt(2), (int)string.charAt(3)); + } + + public static int p(byte[] byArray) { + return StbRasterizer.s(byArray); + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeActiveEdge.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeActiveEdge.java new file mode 100644 index 0000000..51486f4 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeActiveEdge.java @@ -0,0 +1,12 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +public class StbTrueTypeActiveEdge { + public float j; + public float e; + public float N; + public float m; + public StbTrueTypeActiveEdge l; + public float T; + public float L; +} + diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeAlignedQuad.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeAlignedQuad.java new file mode 100644 index 0000000..3c7827b --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeAlignedQuad.java @@ -0,0 +1,13 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +public class StbTrueTypeAlignedQuad { + public float K; + public float G; + public float C; + public float x; + public float v; + public float M; + public float O; + public float S; +} + diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeBakedChar.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeBakedChar.java new file mode 100644 index 0000000..859c1eb --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeBakedChar.java @@ -0,0 +1,12 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +public class StbTrueTypeBakedChar { + public int V; + public float k; + public float l; + public int D; + public float B; + public int U; + public int Q; +} + diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeBitmap.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeBitmap.java new file mode 100644 index 0000000..8c41ffd --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeBitmap.java @@ -0,0 +1,10 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +public class StbTrueTypeBitmap { + public byte[] E; + public int c; + public int K; + public int h; + public int A; +} + diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeCharStringContext.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeCharStringContext.java new file mode 100644 index 0000000..ee46c42 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeCharStringContext.java @@ -0,0 +1,34 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypeVertex; + +public class StbTrueTypeCharStringContext { + public int Z; + public int c; + public int q; + public float p; + public int v; + public float o; + public float s; + public float C; + public int J; + public int y; + public int f; + public StbTrueTypeVertex[] V; + + public StbTrueTypeCharStringContext(int n) { + this.J = n; + this.v = 0; + this.s = 0.0f; + this.p = 0.0f; + this.C = 0.0f; + this.o = 0.0f; + this.y = 0; + this.c = 0; + this.Z = 0; + this.f = 0; + this.V = null; + this.q = 0; + } +} + diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeEdge.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeEdge.java new file mode 100644 index 0000000..05b70eb --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeEdge.java @@ -0,0 +1,10 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +public class StbTrueTypeEdge { + public float u; + public float d; + public int W; + public float X; + public float i; +} + diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeFontInfo.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeFontInfo.java new file mode 100644 index 0000000..86931b5 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeFontInfo.java @@ -0,0 +1,30 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +public class StbTrueTypeFontInfo { + public int h; + public int G; + public StbByteBufferView H; + public int Y; + public int L; + public int Q; + public int U; + public StbByteBufferView g = new StbByteBufferView(); + public int c; + public StbByteBufferView j; + public byte[] S; + public StbByteBufferView z = new StbByteBufferView(); + public StbByteBufferView J; + public int d; + public int T; + public int w; + public StbByteBufferView N; + public int v; + public int p; + + public StbTrueTypeFontInfo() { + this.j = new StbByteBufferView(); + this.J = new StbByteBufferView(); + this.H = new StbByteBufferView(); + this.N = new StbByteBufferView(); + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeGlyphPackNode.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeGlyphPackNode.java new file mode 100644 index 0000000..c64e855 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeGlyphPackNode.java @@ -0,0 +1,6 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +public class StbTrueTypeGlyphPackNode { + public int z; +} + diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeKerningEntry.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeKerningEntry.java new file mode 100644 index 0000000..3f890b8 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeKerningEntry.java @@ -0,0 +1,8 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +public class StbTrueTypeKerningEntry { + public int y; + public int q; + public int o; +} + diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePackAtlasState.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePackAtlasState.java new file mode 100644 index 0000000..dc85d00 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePackAtlasState.java @@ -0,0 +1,10 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +public class StbTrueTypePackAtlasState { + public int F; + public int a; + public int n; + public int f; + public int t; +} + diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePackContext.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePackContext.java new file mode 100644 index 0000000..8c9aef8 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePackContext.java @@ -0,0 +1,18 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypeGlyphPackNode; +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypePackAtlasState; + +public class StbTrueTypePackContext { + public int d; + public StbTrueTypeGlyphPackNode[] j; + public int m; + public int h; + public int G; + public int b; + public StbTrueTypePackAtlasState J; + public int c; + public int w; + public byte[] X; +} + diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePackRange.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePackRange.java new file mode 100644 index 0000000..ea72c5b --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePackRange.java @@ -0,0 +1,29 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +import cn.xiaozhou233.orangex.render.font.stb.StbTrueTypePackedChar; + +public class StbTrueTypePackRange { + public int y; + public int R; + public int[] N; + public StbTrueTypePackedChar[] M; + public int i; + public float E; + private static String[] j; + public int b; + + public static void t(String[] stringArray) { + j = stringArray; + } + + public static String[] x() { + return j; + } + + static { + if (StbTrueTypePackRange.x() != null) { + StbTrueTypePackRange.t(new String[1]); + } + } +} + diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePackRectangle.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePackRectangle.java new file mode 100644 index 0000000..88196ff --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePackRectangle.java @@ -0,0 +1,11 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +public class StbTrueTypePackRectangle { + public int e; + public int J; + public int P; + public int M; + public int N; + public int q; +} + diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePackedChar.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePackedChar.java new file mode 100644 index 0000000..afe8e59 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePackedChar.java @@ -0,0 +1,14 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +public class StbTrueTypePackedChar { + public int p; + public int q; + public float R; + public int k; + public float A; + public int b; + public float G; + public float t; + public float s; +} + diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePoint.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePoint.java new file mode 100644 index 0000000..ca3adfb --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypePoint.java @@ -0,0 +1,7 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +public class StbTrueTypePoint { + public float E; + public float M; +} + diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeVertex.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeVertex.java new file mode 100644 index 0000000..2295182 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/font/stb/StbTrueTypeVertex.java @@ -0,0 +1,13 @@ +package cn.xiaozhou233.orangex.render.font.stb; + +public class StbTrueTypeVertex { + public short h; + public int O; + public short H; + public short a; + public short D; + public short s; + public int v; + public short f; +} + diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/FontBackend.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/FontBackend.java new file mode 100644 index 0000000..c1de6c5 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/FontBackend.java @@ -0,0 +1,17 @@ +package cn.xiaozhou233.orangex.render.internal; + +import cn.xiaozhou233.orangex.render.api.Render2D; +import cn.xiaozhou233.orangex.render.font.FontAtlas; +import cn.xiaozhou233.orangex.render.font.FontManager; + +/** + * Version-specific GPU operations for the font renderer. + */ +public interface FontBackend { + + FontTexture createTexture(FontAtlas atlas); + + Render2D createRender2D(FontManager fonts, Object platformContext); + + String getName(); +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/FontBackendFactory.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/FontBackendFactory.java new file mode 100644 index 0000000..10c3bc7 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/FontBackendFactory.java @@ -0,0 +1,29 @@ +package cn.xiaozhou233.orangex.render.internal; + +import cn.xiaozhou233.orangex.mapping.MappingResolver; +import cn.xiaozhou233.orangex.render.internal.v1_8_9.V1_8_9FontBackend; +import cn.xiaozhou233.orangex.render.internal.v26_2.V26_2FontBackend; +import cn.xiaozhou233.orangex.runtime.RuntimeInfo; + +/** + * Selects the font backend for the detected Minecraft version. + */ +public final class FontBackendFactory { + + public static FontBackend create(RuntimeInfo runtimeInfo, + MappingResolver mappingResolver, + Object minecraft) { + switch (runtimeInfo.getMinecraftVersion()) { + case V1_8_9: + return new V1_8_9FontBackend(runtimeInfo, mappingResolver, minecraft); + case V26_2: + return new V26_2FontBackend(runtimeInfo); + default: + throw new IllegalStateException( + "No font backend for " + runtimeInfo.getMinecraftVersion()); + } + } + + private FontBackendFactory() { + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/FontTexture.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/FontTexture.java new file mode 100644 index 0000000..4221d41 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/FontTexture.java @@ -0,0 +1,14 @@ +package cn.xiaozhou233.orangex.render.internal; + +/** + * Opaque GPU texture owned by one {@link cn.xiaozhou233.orangex.render.font.FontAtlas}. + * The concrete type depends on the Minecraft version. + */ +public interface FontTexture { + + int getWidth(); + + int getHeight(); + + void close(); +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/GlyphDrawer.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/GlyphDrawer.java new file mode 100644 index 0000000..e5b03a4 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/GlyphDrawer.java @@ -0,0 +1,13 @@ +package cn.xiaozhou233.orangex.render.internal; + +import cn.xiaozhou233.orangex.render.font.Glyph; + +/** + * Draws one glyph for the current frame. A drawer is created per frame because + * modern Minecraft renders the GUI through a deferred render-state object. + */ +public interface GlyphDrawer { + + void drawGlyph(FontTexture texture, Glyph glyph, + double x, double y, double scale, int argb); +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v1_8_9/V1_8_9FontBackend.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v1_8_9/V1_8_9FontBackend.java new file mode 100644 index 0000000..3668037 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v1_8_9/V1_8_9FontBackend.java @@ -0,0 +1,94 @@ +package cn.xiaozhou233.orangex.render.internal.v1_8_9; + +import cn.xiaozhou233.orangex.mapping.MappingResolver; +import cn.xiaozhou233.orangex.render.api.Render2D; +import cn.xiaozhou233.orangex.render.font.FontAtlas; +import cn.xiaozhou233.orangex.render.font.FontManager; +import cn.xiaozhou233.orangex.render.internal.FontBackend; +import cn.xiaozhou233.orangex.render.internal.FontTexture; +import cn.xiaozhou233.orangex.runtime.RuntimeInfo; +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import org.lwjgl.opengl.GL13; + +import java.nio.ByteBuffer; + +/** + * Legacy OpenGL backend used by Minecraft 1.8.9. + * + *

The atlas is uploaded as {@code GL_ALPHA}; the fixed-function pipeline + * modulates the current colour with the glyph coverage, which is exactly what + * the old Minecraft font renderer does.

+ */ +public final class V1_8_9FontBackend implements FontBackend { + + private final RuntimeInfo runtimeInfo; + private final MappingResolver resolver; + private final Object minecraft; + + public V1_8_9FontBackend(RuntimeInfo runtimeInfo, + MappingResolver resolver, + Object minecraft) { + this.runtimeInfo = runtimeInfo; + this.resolver = resolver; + this.minecraft = minecraft; + } + + @Override + public FontTexture createTexture(FontAtlas atlas) { + int previousTexture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); + int previousAlignment = GL11.glGetInteger(GL11.GL_UNPACK_ALIGNMENT); + int previousActiveTexture = GL11.glGetInteger(GL13.GL_ACTIVE_TEXTURE); + GL13.glActiveTexture(GL13.GL_TEXTURE0); + int textureId = GL11.glGenTextures(); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); + + GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, + GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, + GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, + GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, + GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); + + ByteBuffer buffer = BufferUtils.createByteBuffer( + atlas.getWidth() * atlas.getHeight() * 4); + byte[] coverage = atlas.getPixels(); + for (int i = 0; i < coverage.length; i++) { + // RGBA is the most compatible fixed-function format: white RGB + // keeps the vertex colour, alpha carries the glyph coverage. + buffer.put((byte) 0xFF); + buffer.put((byte) 0xFF); + buffer.put((byte) 0xFF); + buffer.put(coverage[i]); + } + buffer.flip(); + + GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, + atlas.getWidth(), atlas.getHeight(), 0, + GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); + + int glError = GL11.glGetError(); + System.out.println("[OrangeX] Font texture uploaded: id=" + textureId + + " size=" + atlas.getWidth() + "x" + atlas.getHeight() + + " glError=" + glError); + + GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, previousAlignment); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, previousTexture); + GL13.glActiveTexture(previousActiveTexture); + return new V1_8_9FontTexture(textureId, atlas.getWidth(), atlas.getHeight()); + } + + @Override + public Render2D createRender2D(FontManager fonts, Object platformContext) { + return new V1_8_9Render2D(fonts, runtimeInfo, resolver, minecraft); + } + + @Override + public String getName() { + return "1.8.9/GL11"; + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v1_8_9/V1_8_9FontTexture.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v1_8_9/V1_8_9FontTexture.java new file mode 100644 index 0000000..bb664c2 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v1_8_9/V1_8_9FontTexture.java @@ -0,0 +1,35 @@ +package cn.xiaozhou233.orangex.render.internal.v1_8_9; + +import cn.xiaozhou233.orangex.render.internal.FontTexture; + +public final class V1_8_9FontTexture implements FontTexture { + + private final int textureId; + private final int width; + private final int height; + + V1_8_9FontTexture(int textureId, int width, int height) { + this.textureId = textureId; + this.width = width; + this.height = height; + } + + int getTextureId() { + return textureId; + } + + @Override + public int getWidth() { + return width; + } + + @Override + public int getHeight() { + return height; + } + + @Override + public void close() { + org.lwjgl.opengl.GL11.glDeleteTextures(textureId); + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v1_8_9/V1_8_9GlyphDrawer.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v1_8_9/V1_8_9GlyphDrawer.java new file mode 100644 index 0000000..cd2c440 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v1_8_9/V1_8_9GlyphDrawer.java @@ -0,0 +1,142 @@ +package cn.xiaozhou233.orangex.render.internal.v1_8_9; + +import cn.xiaozhou233.orangex.render.font.Glyph; +import cn.xiaozhou233.orangex.render.internal.FontTexture; +import cn.xiaozhou233.orangex.render.internal.GlyphDrawer; +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.GL11; + +import java.nio.FloatBuffer; + +/** + * Immediate-mode glyph drawer for the legacy (1.8.9) OpenGL pipeline. + */ +final class V1_8_9GlyphDrawer implements GlyphDrawer { + + private int boundTexture = -1; + private static boolean firstDrawLogged; + + private boolean initialized; + private boolean previousBlend; + private boolean previousTexture2D; + private boolean previousAlphaTest; + private boolean previousDepthTest; + private boolean previousCullFace; + private boolean previousLighting; + private boolean previousScissorTest; + private boolean previousFog; + private int previousTexture; + private int previousTextureEnvMode; + private int previousActiveTexture; + private final FloatBuffer previousColor = BufferUtils.createFloatBuffer(16); + + @Override + public void drawGlyph(FontTexture texture, Glyph glyph, + double penX, double baseline, double scale, int argb) { + if (!(texture instanceof V1_8_9FontTexture)) { + return; + } + initialize(); + + int textureId = ((V1_8_9FontTexture) texture).getTextureId(); + if (textureId != boundTexture) { + GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); + boundTexture = textureId; + } + + if (!firstDrawLogged) { + firstDrawLogged = true; + System.out.println("[OrangeX] Font first glyph draw: tex=" + textureId + + " penX=" + penX + " baseline=" + baseline + + " scale=" + scale + " glError=" + GL11.glGetError()); + } + + float red = ((argb >> 16) & 0xFF) / 255.0f; + float green = ((argb >> 8) & 0xFF) / 255.0f; + float blue = (argb & 0xFF) / 255.0f; + float alpha = ((argb >>> 24) & 0xFF) / 255.0f; + GL11.glColor4f(red, green, blue, alpha); + + double left = penX + glyph.getX0() * scale; + double right = penX + glyph.getX1() * scale; + double top = baseline + glyph.getY0() * scale; + double bottom = baseline + glyph.getY1() * scale; + + GL11.glBegin(GL11.GL_QUADS); + GL11.glTexCoord2f(glyph.getU0(), glyph.getV0()); + GL11.glVertex2d(left, top); + GL11.glTexCoord2f(glyph.getU0(), glyph.getV1()); + GL11.glVertex2d(left, bottom); + GL11.glTexCoord2f(glyph.getU1(), glyph.getV1()); + GL11.glVertex2d(right, bottom); + GL11.glTexCoord2f(glyph.getU1(), glyph.getV0()); + GL11.glVertex2d(right, top); + GL11.glEnd(); + } + + void flush() { + if (!initialized) { + return; + } + GL11.glBindTexture(GL11.GL_TEXTURE_2D, previousTexture); + GL11.glColor4f(previousColor.get(0), previousColor.get(1), + previousColor.get(2), previousColor.get(3)); + setEnabled(GL11.GL_BLEND, previousBlend); + setEnabled(GL11.GL_TEXTURE_2D, previousTexture2D); + setEnabled(GL11.GL_ALPHA_TEST, previousAlphaTest); + setEnabled(GL11.GL_DEPTH_TEST, previousDepthTest); + setEnabled(GL11.GL_CULL_FACE, previousCullFace); + setEnabled(GL11.GL_LIGHTING, previousLighting); + setEnabled(GL11.GL_SCISSOR_TEST, previousScissorTest); + setEnabled(GL11.GL_FOG, previousFog); + GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, + GL11.GL_TEXTURE_ENV_MODE, previousTextureEnvMode); + org.lwjgl.opengl.GL13.glActiveTexture(previousActiveTexture); + initialized = false; + boundTexture = -1; + } + + private void initialize() { + if (initialized) { + return; + } + initialized = true; + + previousTexture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); + previousBlend = GL11.glIsEnabled(GL11.GL_BLEND); + previousTexture2D = GL11.glIsEnabled(GL11.GL_TEXTURE_2D); + previousAlphaTest = GL11.glIsEnabled(GL11.GL_ALPHA_TEST); + previousDepthTest = GL11.glIsEnabled(GL11.GL_DEPTH_TEST); + previousCullFace = GL11.glIsEnabled(GL11.GL_CULL_FACE); + previousLighting = GL11.glIsEnabled(GL11.GL_LIGHTING); + previousScissorTest = GL11.glIsEnabled(GL11.GL_SCISSOR_TEST); + previousFog = GL11.glIsEnabled(GL11.GL_FOG); + previousTextureEnvMode = GL11.glGetTexEnvi(GL11.GL_TEXTURE_ENV, + GL11.GL_TEXTURE_ENV_MODE); + previousActiveTexture = GL11.glGetInteger(org.lwjgl.opengl.GL13.GL_ACTIVE_TEXTURE); + org.lwjgl.opengl.GL13.glActiveTexture(org.lwjgl.opengl.GL13.GL_TEXTURE0); + + previousColor.clear(); + GL11.glGetFloat(GL11.GL_CURRENT_COLOR, previousColor); + + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glDisable(GL11.GL_CULL_FACE); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_SCISSOR_TEST); + GL11.glDisable(GL11.GL_FOG); + GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, + GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); + } + + private static void setEnabled(int capability, boolean enabled) { + if (enabled) { + GL11.glEnable(capability); + } else { + GL11.glDisable(capability); + } + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v1_8_9/V1_8_9Render2D.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v1_8_9/V1_8_9Render2D.java new file mode 100644 index 0000000..7f1a985 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v1_8_9/V1_8_9Render2D.java @@ -0,0 +1,106 @@ +package cn.xiaozhou233.orangex.render.internal.v1_8_9; + +import cn.xiaozhou233.orangex.mapping.MappingClass; +import cn.xiaozhou233.orangex.mapping.MappingMethod; +import cn.xiaozhou233.orangex.mapping.MappingResolver; +import cn.xiaozhou233.orangex.render.api.FontRenderer; +import cn.xiaozhou233.orangex.render.api.Render2D; +import cn.xiaozhou233.orangex.render.font.FontFace; +import cn.xiaozhou233.orangex.render.font.FontFamily; +import cn.xiaozhou233.orangex.render.font.FontManager; +import cn.xiaozhou233.orangex.render.font.TrueTypeFontRenderer; +import cn.xiaozhou233.orangex.runtime.RuntimeInfo; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +/** + * 1.8.9 2D context. Coordinates are the vanilla {@code ScaledResolution} + * pixels, which matches the ortho set up by {@code GuiIngame#renderGameOverlay}. + */ +final class V1_8_9Render2D implements Render2D { + + private static final String SCALED_RESOLUTION = + "net/minecraft/client/gui/ScaledResolution"; + + private final FontManager fonts; + private final double guiScale; + private final V1_8_9GlyphDrawer drawer = new V1_8_9GlyphDrawer(); + private final int width; + private final int height; + + V1_8_9Render2D(FontManager fonts, RuntimeInfo runtimeInfo, + MappingResolver resolver, Object minecraft) { + this.fonts = fonts; + + int resolvedWidth = 854; + int resolvedHeight = 480; + int resolvedScale = 1; + + try { + MappingClass mappingClass = resolver.mapClass(SCALED_RESOLUTION); + Class scaledClass = Class.forName( + mappingClass.getTargetName().replace('/', '.'), + false, runtimeInfo.getMinecraftClassLoader()); + Constructor constructor = scaledClass.getDeclaredConstructor( + minecraft.getClass()); + constructor.setAccessible(true); + Object scaled = constructor.newInstance(minecraft); + + Method widthMethod = method(scaledClass, resolver, "getScaledWidth", "()I"); + Method heightMethod = method(scaledClass, resolver, "getScaledHeight", "()I"); + Method scaleMethod = method(scaledClass, resolver, "getScaleFactor", "()I"); + + resolvedWidth = (Integer) widthMethod.invoke(scaled); + resolvedHeight = (Integer) heightMethod.invoke(scaled); + resolvedScale = (Integer) scaleMethod.invoke(scaled); + } catch (Throwable throwable) { + System.err.println("[OrangeX] Failed to resolve ScaledResolution for 1.8.9: " + + throwable); + } + + this.width = resolvedWidth; + this.height = resolvedHeight; + this.guiScale = Math.max(1, resolvedScale); + } + + private static Method method(Class owner, MappingResolver resolver, + String name, String descriptor) throws Exception { + MappingMethod mapping = resolver.mapMethod( + SCALED_RESOLUTION, name, descriptor); + Method method = owner.getDeclaredMethod(mapping.getTargetName()); + method.setAccessible(true); + return method; + } + + @Override + public int getWidth() { + return width; + } + + @Override + public int getHeight() { + return height; + } + + @Override + public double getGuiScale() { + return guiScale; + } + + @Override + public FontRenderer getFont(float size) { + return getFont(size, false); + } + + @Override + public FontRenderer getFont(float size, boolean bold) { + FontFace face = fonts.getFace(FontFamily.PROXIMA, size, bold, guiScale); + return new TrueTypeFontRenderer(fonts, face, bold, guiScale, drawer); + } + + @Override + public void flush() { + drawer.flush(); + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v26_2/V26_2FontBackend.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v26_2/V26_2FontBackend.java new file mode 100644 index 0000000..96ec8de --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v26_2/V26_2FontBackend.java @@ -0,0 +1,90 @@ +package cn.xiaozhou233.orangex.render.internal.v26_2; + +import cn.xiaozhou233.orangex.render.api.Render2D; +import cn.xiaozhou233.orangex.render.font.FontAtlas; +import cn.xiaozhou233.orangex.render.font.FontManager; +import cn.xiaozhou233.orangex.render.internal.FontBackend; +import cn.xiaozhou233.orangex.render.internal.FontTexture; +import cn.xiaozhou233.orangex.runtime.RuntimeInfo; + +import java.lang.reflect.Constructor; +import java.nio.ByteBuffer; +import java.util.function.Supplier; + +/** + * 26.x backend. + * + *

The atlas is expanded to RGBA (white RGB + coverage alpha) and wrapped in + * a {@code DynamicTexture}. Glyph drawing is deferred through + * {@code GuiRenderState}, so no raw OpenGL calls are made here.

+ */ +public final class V26_2FontBackend implements FontBackend { + + private final ClassLoader loader; + + public V26_2FontBackend(RuntimeInfo runtimeInfo) { + this.loader = runtimeInfo.getMinecraftClassLoader(); + } + + @Override + public FontTexture createTexture(FontAtlas atlas) { + try { + int width = atlas.getWidth(); + int height = atlas.getHeight(); + byte[] coverage = atlas.getPixels(); + + byte[] rgba = new byte[coverage.length * 4]; + for (int i = 0, j = 0; i < coverage.length; i++, j += 4) { + rgba[j] = (byte) 0xFF; + rgba[j + 1] = (byte) 0xFF; + rgba[j + 2] = (byte) 0xFF; + rgba[j + 3] = coverage[i]; + } + + Class nativeImageClass = Class.forName( + "com.mojang.blaze3d.platform.NativeImage", false, loader); + Constructor nativeImageConstructor = nativeImageClass + .getDeclaredConstructor(int.class, int.class, boolean.class); + Object image = nativeImageConstructor.newInstance(width, height, false); + ByteBuffer buffer = (ByteBuffer) nativeImageClass + .getMethod("getPixelBytes").invoke(image); + buffer.put(rgba); + + Class dynamicTextureClass = Class.forName( + "net.minecraft.client.renderer.texture.DynamicTexture", false, loader); + Constructor dynamicTextureConstructor = dynamicTextureClass + .getDeclaredConstructor(Supplier.class, nativeImageClass); + Object dynamicTexture = dynamicTextureConstructor.newInstance( + new Supplier() { + @Override + public String get() { + return "OrangeX font atlas"; + } + }, + image); + + Object textureView = dynamicTextureClass.getMethod("getTextureView") + .invoke(dynamicTexture); + Object sampler = dynamicTextureClass.getMethod("getSampler") + .invoke(dynamicTexture); + + System.out.println("[OrangeX] 26.2 font texture created: " + + width + "x" + height); + return new V26_2FontTexture(dynamicTexture, textureView, sampler, + width, height); + } catch (Throwable throwable) { + throw new IllegalStateException("Cannot upload the 26.2 font atlas", + throwable); + } + } + + @Override + public Render2D createRender2D(FontManager fonts, Object platformContext) { + return new V26_2Render2D(fonts, platformContext, loader); + } + + @Override + public String getName() { + return "26.2/GuiRenderState"; + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v26_2/V26_2FontTexture.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v26_2/V26_2FontTexture.java new file mode 100644 index 0000000..187d72b --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v26_2/V26_2FontTexture.java @@ -0,0 +1,58 @@ +package cn.xiaozhou233.orangex.render.internal.v26_2; + +import cn.xiaozhou233.orangex.render.internal.FontTexture; + +/** + * Wraps a 26.x {@code DynamicTexture}. All fields are kept as {@link Object} + * because OrangeX is compiled against Java 8 without Mojang/LWJGL3 on the + * compile classpath. + */ +public final class V26_2FontTexture implements FontTexture { + + private final Object texture; + private final Object textureView; + private final Object sampler; + private final int width; + private final int height; + + V26_2FontTexture(Object texture, Object textureView, Object sampler, + int width, int height) { + this.texture = texture; + this.textureView = textureView; + this.sampler = sampler; + this.width = width; + this.height = height; + } + + Object getTexture() { + return texture; + } + + Object getTextureView() { + return textureView; + } + + Object getSampler() { + return sampler; + } + + @Override + public int getWidth() { + return width; + } + + @Override + public int getHeight() { + return height; + } + + @Override + public void close() { + try { + texture.getClass().getMethod("close").invoke(texture); + } catch (Throwable throwable) { + System.err.println("[OrangeX] Failed to close a 26.2 font texture: " + + throwable); + } + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v26_2/V26_2GlyphDrawer.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v26_2/V26_2GlyphDrawer.java new file mode 100644 index 0000000..9e2de19 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v26_2/V26_2GlyphDrawer.java @@ -0,0 +1,59 @@ +package cn.xiaozhou233.orangex.render.internal.v26_2; + +import cn.xiaozhou233.orangex.render.font.Glyph; +import cn.xiaozhou233.orangex.render.internal.FontTexture; +import cn.xiaozhou233.orangex.render.internal.GlyphDrawer; + +import java.lang.reflect.Method; + +/** + * Adds one deferred blit per glyph to the 26.x {@code GuiRenderState}. + */ +final class V26_2GlyphDrawer implements GlyphDrawer { + + private static boolean firstDrawLogged; + + private final Object extractor; + private final Method innerBlit; + private final Object guiPipeline; + + V26_2GlyphDrawer(Object extractor, Method innerBlit, Object guiPipeline) { + this.extractor = extractor; + this.innerBlit = innerBlit; + this.guiPipeline = guiPipeline; + } + + @Override + public void drawGlyph(FontTexture texture, Glyph glyph, + double penX, double baseline, double scale, int argb) { + if (!(texture instanceof V26_2FontTexture)) { + return; + } + + int x0 = (int) Math.round(penX + glyph.getX0() * scale); + int y0 = (int) Math.round(baseline + glyph.getY0() * scale); + int x1 = (int) Math.round(penX + glyph.getX1() * scale); + int y1 = (int) Math.round(baseline + glyph.getY1() * scale); + if (x1 <= x0 || y1 <= y0) { + return; + } + + V26_2FontTexture fontTexture = (V26_2FontTexture) texture; + try { + innerBlit.invoke(extractor, guiPipeline, + fontTexture.getTextureView(), fontTexture.getSampler(), + x0, y0, x1, y1, + glyph.getU0(), glyph.getU1(), + glyph.getV0(), glyph.getV1(), + argb); + if (!firstDrawLogged) { + firstDrawLogged = true; + System.out.println("[OrangeX] 26.2 first glyph blit: " + + x0 + "," + y0 + " -> " + x1 + "," + y1 + + " tex=" + fontTexture.getTextureView()); + } + } catch (Throwable throwable) { + throw new IllegalStateException("Failed to submit a GUI glyph", throwable); + } + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v26_2/V26_2Render2D.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v26_2/V26_2Render2D.java new file mode 100644 index 0000000..74c4d88 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/render/internal/v26_2/V26_2Render2D.java @@ -0,0 +1,138 @@ +package cn.xiaozhou233.orangex.render.internal.v26_2; + +import cn.xiaozhou233.orangex.render.api.FontRenderer; +import cn.xiaozhou233.orangex.render.api.Render2D; +import cn.xiaozhou233.orangex.render.font.FontFace; +import cn.xiaozhou233.orangex.render.font.FontFamily; +import cn.xiaozhou233.orangex.render.font.FontManager; +import cn.xiaozhou233.orangex.render.font.TrueTypeFontRenderer; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +/** + * 26.x 2D context. + * + *

26.x no longer exposes {@code GuiGraphics}; the GUI is collected into a + * {@code GuiRenderState} by {@code Gui#extractRenderState}. The render hook + * passes that {@code Gui} instance in, and this class creates a private + * {@code GuiGraphicsExtractor} over the same render state to queue glyph + * blits.

+ */ +final class V26_2Render2D implements Render2D { + + private static boolean contextLogged; + + private final FontManager fonts; + private final V26_2GlyphDrawer drawer; + private final int width; + private final int height; + private final double guiScale; + + V26_2Render2D(FontManager fonts, Object gui, ClassLoader loader) { + this.fonts = fonts; + + try { + Field minecraftField = field(gui.getClass(), "minecraft"); + Object minecraft = minecraftField.get(gui); + + Field renderStateField = field(gui.getClass(), "guiRenderState"); + Object guiRenderState = renderStateField.get(gui); + + Class renderStateClass = Class.forName( + "net.minecraft.client.renderer.state.gui.GuiRenderState", + false, loader); + Class extractorClass = Class.forName( + "net.minecraft.client.gui.GuiGraphicsExtractor", + false, loader); + + Constructor extractorConstructor = extractorClass.getDeclaredConstructor( + minecraft.getClass(), renderStateClass, int.class, int.class); + extractorConstructor.setAccessible(true); + Object extractor = extractorConstructor.newInstance( + minecraft, guiRenderState, 0, 0); + + Object window = minecraft.getClass().getMethod("getWindow").invoke(minecraft); + this.width = (Integer) window.getClass().getMethod("getGuiScaledWidth") + .invoke(window); + this.height = (Integer) window.getClass().getMethod("getGuiScaledHeight") + .invoke(window); + this.guiScale = Math.max(1, (Integer) window.getClass() + .getMethod("getGuiScale").invoke(window)); + + if (!contextLogged) { + contextLogged = true; + System.out.println("[OrangeX] 26.2 Render2D: " + + width + "x" + height + " scale=" + guiScale); + } + + Class pipelineClass = Class.forName( + "com.mojang.blaze3d.pipeline.RenderPipeline", false, loader); + Class textureViewClass = Class.forName( + "com.mojang.blaze3d.textures.GpuTextureView", false, loader); + Class samplerClass = Class.forName( + "com.mojang.blaze3d.textures.GpuSampler", false, loader); + + Object guiPipeline = Class.forName( + "net.minecraft.client.renderer.RenderPipelines", false, loader) + .getField("GUI_TEXTURED").get(null); + + Method innerBlit = extractorClass.getDeclaredMethod("innerBlit", + pipelineClass, textureViewClass, samplerClass, + int.class, int.class, int.class, int.class, + float.class, float.class, float.class, float.class, + int.class); + innerBlit.setAccessible(true); + + this.drawer = new V26_2GlyphDrawer(extractor, innerBlit, guiPipeline); + } catch (Throwable throwable) { + throw new IllegalStateException( + "Cannot initialise the 26.2 GUI font context", throwable); + } + } + + private static Field field(Class owner, String name) throws Exception { + for (Class current = owner; current != null; current = current.getSuperclass()) { + try { + Field field = current.getDeclaredField(name); + field.setAccessible(true); + return field; + } catch (NoSuchFieldException ignored) { + // Continue with the superclass. + } + } + throw new NoSuchFieldException(name + " on " + owner.getName()); + } + + @Override + public int getWidth() { + return width; + } + + @Override + public int getHeight() { + return height; + } + + @Override + public double getGuiScale() { + return guiScale; + } + + @Override + public FontRenderer getFont(float size) { + return getFont(size, false); + } + + @Override + public FontRenderer getFont(float size, boolean bold) { + FontFace face = fonts.getFace(FontFamily.PROXIMA, size, bold, guiScale); + return new TrueTypeFontRenderer(fonts, face, bold, guiScale, drawer); + } + + @Override + public void flush() { + // Everything was submitted to the GuiRenderState; nothing to restore. + } +} diff --git a/OrangeX/src/main/resources/assets/orangex/font/noto.ttf b/OrangeX/src/main/resources/assets/orangex/font/noto.ttf new file mode 100644 index 0000000..04cd8e8 Binary files /dev/null and b/OrangeX/src/main/resources/assets/orangex/font/noto.ttf differ diff --git a/OrangeX/src/main/resources/assets/orangex/font/poppins_rg.ttf b/OrangeX/src/main/resources/assets/orangex/font/poppins_rg.ttf new file mode 100644 index 0000000..094a8ab Binary files /dev/null and b/OrangeX/src/main/resources/assets/orangex/font/poppins_rg.ttf differ diff --git a/OrangeX/src/main/resources/assets/orangex/font/proxima.ttf b/OrangeX/src/main/resources/assets/orangex/font/proxima.ttf new file mode 100644 index 0000000..6eba754 Binary files /dev/null and b/OrangeX/src/main/resources/assets/orangex/font/proxima.ttf differ diff --git a/OrangeX/src/main/resources/assets/orangex/font/proximabd.ttf b/OrangeX/src/main/resources/assets/orangex/font/proximabd.ttf new file mode 100644 index 0000000..b82d2eb Binary files /dev/null and b/OrangeX/src/main/resources/assets/orangex/font/proximabd.ttf differ diff --git a/docs/render/README.md b/docs/render/README.md new file mode 100644 index 0000000..9d80cf7 --- /dev/null +++ b/docs/render/README.md @@ -0,0 +1,31 @@ +# 渲染相关文档 + +本目录记录客户端字体、GUI 与跨版本渲染实现的分析与设计参考。 + +## 文档索引 + +| 文档 | 内容 | +| --- | --- | +| [vape-font-gui-rendering.md](vape-font-gui-rendering.md) | Vape 4.21 的字体光栅化、文本排版、GUI 组件树、双渲染后端与 1.7.10–26.2 跨版本路径分析 | +| [font-port.md](font-port.md) | OrangeX 的字体移植实现:TTF 烘焙、Render2D API、1.8.9 / 26.2 接入、调试参数与限制 | + +## 快速导航 + +- 字体资源与语言选择 → 主文档 §2.1 +- stb_truetype 字形图集 → 主文档 §2.2 +- Buffered / Legacy 字体渲染器 → 主文档 §2.3 +- Minecraft 原生 `FontSet` 字体桥 → 主文档 §2.4 +- § 颜色码、阴影、宽度缓存、GUI Scale → 主文档 §2.5 +- 中文覆盖与构建期校验 → 主文档 §2.6 +- ClickGUI 生命周期与输入 → 主文档 §3.1 +- 坐标系统与缩放 → 主文档 §3.2 +- 组件树与布局 → 主文档 §3.3 +- `GuiRenderPrimitives` 双后端 → 主文档 §3.4 +- Universal Shader 批次渲染 → 主文档 §3.5 +- 1.21.6+ / 26.x 兼容 → 主文档 §3.7 +- 版本矩阵 → 主文档 §4 + +## 阅读前提 + +主文档以 `E:\Vape-v4.21` 为源码根,涉及的文件路径均相对于该目录。 +文中结论来自静态源码阅读,运行时行为仍需结合实际客户端验证。 diff --git a/docs/render/font-port.md b/docs/render/font-port.md new file mode 100644 index 0000000..33025d2 --- /dev/null +++ b/docs/render/font-port.md @@ -0,0 +1,194 @@ +# 字体移植(Vape 4.21 → OrangeX) + +本文说明从 `E:\Vape-v4.21` 移植过来的 TTF 字体子系统,以及它在 1.8.9 / 26.2 两个版本上的接入方式。 + +> 设计目标:字体光栅化、排版、缓存全部与 Minecraft 版本无关;只有“把图集交给 GPU”和“每帧从哪拿绘制上下文”是版本相关的。 + +## 1. 目录结构 + +```text +OrangeX/src/main/java/cn/xiaozhou233/orangex/ +├── render/ +│ ├── api/ +│ │ ├── FontRenderer.java # 业务代码使用的字体接口 +│ │ └── Render2D.java # 每帧 2D 上下文 +│ ├── font/ +│ │ ├── FontFamily.java # 内置字体族 +│ │ ├── FontManager.java # 按 (family,size,bold,scale) 缓存 +│ │ ├── FontFace.java # 图集 + 纹理 + drawScale +│ │ ├── FontAtlas.java # 烘焙结果 +│ │ ├── Glyph.java # 单字形度量 / UV +│ │ ├── StbFontBaker.java # stb 打包适配 +│ │ ├── TrueTypeFontRenderer.java # 排版、§ 颜色、阴影、CJK 回退 +│ │ └── stb/ # 移植的 stb_truetype +│ ├── internal/ +│ │ ├── FontBackend.java # 版本相关 GPU 操作 +│ │ ├── FontTexture.java +│ │ ├── GlyphDrawer.java +│ │ ├── FontBackendFactory.java +│ │ ├── v1_8_9/ # GL11 立即模式 +│ │ └── v26_2/ # GuiRenderState 延迟绘制 +│ ├── Render2DManager.java +│ └── FontDebugOverlay.java +├── event/ +│ ├── facade/Render2DEvents.java # 注入代码唯一引用 +│ └── impl/EventRender2D.java +└── hook/impl/Render2DHook.java # 每帧 2D 回调 +``` + +## 2. 使用方式 + +```java +@Subscribe(threadMode = ThreadMode.POSTING) +public void onRender2D(EventRender2D event) { + Render2D render2D = event.getRender2D(); + + FontRenderer title = render2D.getFont(14.0f, true); + FontRenderer body = render2D.getFont(10.0f, false); + + title.drawStringWithShadow("OrangeX", 8, 8, 0xFFFFFFFF); + body.drawString("中文测试:钻石剑", 8, 30, 0xFFFFAA00); +} +``` + +约定: + +- 坐标和字号都是 **Minecraft GUI 像素**(`ScaledResolution` / `getGuiScaledWidth` 空间)。 +- `FontRenderer` 只在当前帧有效,不要缓存到字段里跨帧使用。 +- `getFont(size, bold)` 返回的对象可以在一帧内重复使用。 +- 英文默认使用 Proxima;遇到 CJK 字符时自动懒加载 Noto 回退。 + +## 3. 光栅化流程 + +1. `StbFontBaker` 用 stb_truetype 读取 TTF 的 hhea/ascent/descent。 +2. 字符集: + - ASCII `32..126` + - Latin-1 `160..255` + - Noto 额外解码 GBK 双字节区间(默认全 GBK,`noto.ttf` 子集实际约 6900 个汉字) +3. 在 `4096 × 4096` 的 8 位覆盖度位图上打包: + - Latin 使用 `2×2` oversampling + - CJK 使用 `1×1` oversampling +4. 每个字形记录 `x0/y0/x1/y1`(相对基线)、`u0/v0/u1/v1`、`advance`。 +5. 纹理上传: + - 1.8.9:`GL_ALPHA` + 固定管线 `GL_MODULATE` + - 26.2:扩展为 RGBA(白色 RGB + 覆盖度 alpha),包装成 `DynamicTexture` + +字号策略: + +```text +rasterHeight = round(logicalSize * guiScale) +drawScale = logicalSize / rasterHeight +``` + +因此 GUI Scale 只提高烘焙分辨率,不改变逻辑排版宽度。为避免 4096 图集溢出: + +| 字体 | 最大 rasterHeight | +| --- | --- | +| 非 CJK(Proxima/Poppins) | 64 | +| CJK(Noto) | 36 | + +## 4. 版本接入 + +### 4.1 1.8.9 + +- Hook:`GuiIngame#renderGameOverlay(F)V` 的末尾。 +- Forge:改为 `net.minecraftforge.client.GuiIngameForge#renderGameOverlay(F)V`。 +- `V1_8_9Render2D` 通过 `MappingResolver` 反射 `ScaledResolution`,拿到 `scaledWidth/scaledHeight/scaleFactor`。 +- `V1_8_9GlyphDrawer` 使用 `GL11` 立即模式绘制四边形;首次绘制时保存并在 `flush()` 中恢复: + - 纹理绑定 / 激活纹理单元 + - `GL_BLEND` / `GL_TEXTURE_2D` / `GL_ALPHA_TEST` / `GL_DEPTH_TEST` + - `GL_CULL_FACE` / `GL_LIGHTING` / `GL_FOG` / `GL_SCISSOR_TEST` + - `GL_TEXTURE_ENV_MODE` + - 当前 `glColor` +- 图集使用 `GL_RGBA`(白色 RGB + 覆盖度 alpha),避免 `GL_ALPHA` 在固定管线中 RGB 为 0 导致文字发黑。 + +> 坑:LWJGL2 的 `glGetFloat(GL_CURRENT_COLOR, buffer)` 有 +> `BufferChecks` 限制,缓冲区至少要有 **16** 个元素;只分配 4 个会在首个字形 +> 抛出 `IllegalArgumentException`,表现为“字体烘焙成功但屏幕无反应”。 + +### 4.2 26.2 + +- Hook:`net.minecraft.client.gui.Gui#extractRenderState(DeltaTracker, boolean, boolean)` 的末尾。 +- 把 `Gui` 实例传给 `Render2DEvents`。 +- `V26_2Render2D` 反射: + - `Gui.minecraft` + - `Gui.guiRenderState` + - 构造 `GuiGraphicsExtractor` + - `Window#getGuiScale/getGuiScaledWidth/getGuiScaledHeight` +- 每个字形调用 `GuiGraphicsExtractor#innerBlit(...)`,把 `BlitRenderState` 加入 `GuiRenderState`,由 `GuiRenderer` 统一排序、合批、绘制。 +- 不直接调用任何 OpenGL。 + +## 5. 调试 + +构建: + +```bash +./gradlew :OrangeX:shadowJar +# 或完整注入包 +./gradlew packageAll +``` + +> 部署注意:MCP 开发环境通常直接读取 +> `E:\OrangeX-Client\out\tmp\OrangeX.jar`,而 Vanilla/Forge/NeoForge/Fabric +> 启动器会读取 `%USERPROFILE%\.orangex\OrangeX.jar`。改完代码后必须把新 +> jar 同步过去,否则会出现“MCP 正常、其他版本没反应”。 + +```text +-Dorangex.debugFont=true +``` + +会在屏幕左上角绘制: + +```text +OrangeX +Font backend: V1_8_9Render2D / V26_2Render2D +ASCII 0123456789 +中文测试:钻石剑 / 迅捷 +``` + +其他属性: + +| 属性 | 默认 | 说明 | +| --- | --- | --- | +| `-Dorangex.font.fullGbk` | `true` | `false` 时只烘焙 GB2312 一级汉字(约 3755 个) | +| `-Dorangex.font.atlasSize` | `4096` | 图集边长,允许 `512..8192`。26.2 使用 RGBA 纹理,8192 约占用 256 MB 显存 | + +启动日志会输出: + +```text +[OrangeX] Font backend: 1.8.9/GL11 +[OrangeX] Baked proxima 20px (191 glyphs, 33 ms) +[OrangeX] Baked noto 28px (... glyphs, ... ms) +``` + +## 6. 添加新版本 + +1. 在 `render/internal/vX_Y_Z/` 新建: + - `VX_Y_ZFontBackend implements FontBackend` + - `VX_Y_ZFontTexture implements FontTexture` + - `VX_Y_ZRender2D implements Render2D` + - `VX_Y_ZGlyphDrawer implements GlyphDrawer` +2. 在 `FontBackendFactory` 的 `switch` 中注册。 +3. 在 `Render2DHook` 的 `getTargetClass/transform` 中增加该版本的每帧 2D 入口。 +4. 如果该版本使用新的 GUI 渲染架构,只需要改 `Render2D`/`GlyphDrawer`,字体光栅化与排版代码不用动。 + +## 7. 当前限制 + +- 没有移植 Vape 的 `StbSmoothFontRenderer`(直接读游戏 `FontSet`),因此没有“MC 原版字体”选项。 +- 没有多页图集;CJK 在超大字号下会被限制到 36px 烘焙高度。 +- 只支持 `§0-9/a-f/r`,没有 italic / underline / obfuscated。 +- 粗体只对内置了 bold 文件的字体生效(Proxima);Noto 使用同一文件。 +- `FontManager` 目前不会在 GUI Scale 变化时主动释放旧纹理,需要时可调用 `clear()`。 +- 26.2 使用 RGBA 图集,4096² 单张约 67 MB 显存;不同字号会各自持有一张。若要做大量字号,建议后续改成 R8 + 自定义画字管线或做字号分桶。 + +## 8. 已验证环境 + +| 环境 | 结果 | +| --- | --- | +| 1.8.9 MCP | 正常渲染 | +| 1.8.9 Vanilla(`avo#a(F)V`) | 正常渲染 | +| 1.8.9 Forge(`GuiIngameForge`) | 走同一注入逻辑,待实机验证 | +| 26.2 Vanilla(`Gui#extractRenderState`) | 正常渲染 | + +在真实 LWJGL2 窗口上下文中的离屏冒烟测试也通过:绘制字母 `A` 得到 +`nonBlack=160, max=255, glError=0`。 diff --git a/docs/render/vape-font-gui-rendering.md b/docs/render/vape-font-gui-rendering.md new file mode 100644 index 0000000..d7e05a1 --- /dev/null +++ b/docs/render/vape-font-gui-rendering.md @@ -0,0 +1,642 @@ +# Vape 4.21 字体与 GUI 渲染(含跨版本) + +> 分析对象:`E:\Vape-v4.21`(Vape 4.21 恢复工程)。 +> 本文所有相对路径均以该目录为根,例如 `src/main/java/gg/vape/ui/font/FontManager.java`。 +> 结论来自源码静态阅读,未做运行时验证。 + +## 0. 一句话总结 + +Vape **不依赖某个 Minecraft 版本的 `FontRenderer` / `Screen` 实现**: + +- 字体:内嵌 TTF,用移植版 stb_truetype 烘成字形图集,再用自建 shader 画四边形;1.21.10+ 额外提供“直接读取游戏 `FontSet`”的桥。 +- GUI:不是 `GuiScreen`,而是每帧在 HUD / PostRender 阶段画的自绘 Overlay,输入由原生层回调。 +- 跨版本:`ForgeVersion` 版本谓词 + `MappedClasses`/`Mapping*` 名字映射 + `GuiRenderPrimitives` 双渲染后端(立即模式 / 自建批次)。 + +--- + +## 1. 分层架构 + +```text +注入 DLL → Java payload + │ + ├─ Runtime.NativeBridge / wrapper.impl.ForgeVersion 版本探测 + ├─ mapping.MappedClasses / Mapper / Mapping* 运行时类与成员解析 + ├─ wrapper.impl.* 对 MC 的薄封装 + ├─ utils.render.GuiRenderPrimitives 绘制门面(双后端) + └─ ui.font / ui.click 字体、组件、布局 +``` + +### 1.1 版本探测 + +入口:`src/main/java/gg/vape/runtime/NativeBridge.java` 的 `gmv()`。 + +1. 优先读 Forge / NeoForge 的版本号: + - `net.minecraftforge.common.ForgeVersion.minorVersion` + - `net.minecraftforge.fml.loading.FMLLoader.forgeVersion` + - `FMLLoader.versionInfo().forgeVersion()` +2. 失败则调用 `detectVanillaMappingVersion()`,用锚点类逐个探测: + - `Vanilla1710Mappings` / `Vanilla189Mappings` / `Badlion189Mappings` + - `Vanilla1122Mappings` / `Vanilla1165Mappings` + - `Vanilla1201Mappings` / `Vanilla1206Mappings` / `Vanilla1211Mappings` / `Vanilla12111Mappings` + - `NeoForge1201Mappings` / `NeoForge1211Mappings` + - `Vanilla262Mappings` / `Fabric262Mappings` +3. 结果写入 `ForgeVersion.gameVersion`,对应枚举协议号: + +```text +13 1.7.10 +15 1.8.9 +23 1.12.2 +35 1.16.4 +36 1.16.5 +37 1.17 +47 1.20.1 +50 1.20.6 +51 1.21.0 +52 1.21.1 +54 1.21.4 +55 1.21.5 +56 1.21.6 +60 1.21.10 +61 1.21.11 +100 26.1 +110 26.2 +``` + +之后全代码通过 `ForgeVersion.MC_1_20_1.d()` 这类“大于等于”谓词分支: + +- `d()` = `>=` +- `v()` = `>` +- `L()` = `<=` +- `Y()` = `<` +- `B()` = `!=` + +### 1.2 跨版本名字映射 + +#### 类名 + +`src/main/java/gg/vape/mapping/MappedClasses.java` 里大量静态 `Class` 字段由 `src/main/java/gg/vape/mapping/runtime/` 下的表初始化: + +| 表 | 用途 | +| --- | --- | +| `ClassNameRemapTableV23/V35V36/V37/V50/V51/V54/V55/V56/V60/V61/V100/V110` | 各版本“源码类名 → 运行时类名” | +| `MemberNameRemapTableV*` | MCP/mojmap/SRG → 混淆成员名 | +| `NeoForgeClassMap` / `NeoForgeFieldMap` / `NeoForgeObfMap` | NeoForge / 纯原版 1.20.1、1.21.1 的特殊转换 | +| `VanillaSrgMappings` / `NeoForge*Mappings` / `Fabric*Mappings` | classpath 探测 + `joined.srg` 解析 | + +`MappedClasses` 还区分运行时形态: + +- `Vape.INSTANCE.isForgeAbsent()`:纯原版 / Fabric / NeoForge 无 Forge remap +- `Vape.INSTANCE.isForgeRemapActive()`:Forge 的 SRG remap 路径 +- `Vape.INSTANCE.isVanillaMinecraftPresent()`:纯原版 + +#### 成员访问 + +`src/main/java/gg/vape/mapping/Mapping.java` + `MappingMethod` / `MappingField`: + +```java +// 声明式注册(MFontRenderer 片段) +this.P = this.Y("drawInBatch", true, Void.TYPE, + String.class, Float.TYPE, Float.TYPE, Integer.TYPE, Boolean.TYPE, + MappedClasses.ZA, MappedClasses.ZK, MappedClasses.Y8, + Integer.TYPE, Integer.TYPE); +``` + +运行时解析链: + +```text +MappingMethod.invoke* + ├─ generatedInvoker (GeneratedAccessorFactory 生成的字节码访问器) + ├─ reflectedMethod (Forge remap 未激活时直接反射) + └─ NativeMappedMemberInvoker + └─ Reflections + └─ MappingRegistry.matches() + ├─ resources/mappings/forgeXXXX/methods.csv + ├─ resources/mappings/forgeXXXX/fields.csv + └─ Vanilla*Mappings 的 SRG 表兜底 +``` + +所以同一份 Java 代码可以匹配: + +- 1.8.9 的 `func_78276_b` +- 1.16.5 的 SRG 名 +- 1.17+ 的 `m_xxxxx_` +- 1.20.1+ 的 mojmap 名 +- 26.x 的 mojmap 名 + +--- + +## 2. 字体系统 + +### 2.1 字体资源与语言选择 + +`src/main/java/gg/vape/ui/font/FontManager.java`: + +| `FontFamily` | 资源 | 说明 | +| --- | --- | --- | +| `PROXIMA`(默认) | `resources/proxima.ttf`、`proximabd.ttf` | `FontManager.e()` 读入 | +| `NOTO`(中文) | `resources/noto.ttf` | 约 1.1 MB 的子集字体 | +| `POPPINS` | `resources/poppins_rg.ttf` | | +| `ARIAL` | 系统 `arial.ttf` / `arialbd.ttf` | 扫描 `%LOCALAPPDATA%\Microsoft\Windows\Fonts` 与 `%SystemRoot%\Fonts` | +| `MINECRAFT` | 游戏自身 `FontSet` | 见 2.4 | + +语言选择在 `src/main/java/gg/vape/ui/font/FontSelector.java`: + +- English → `IdentityFontOption`(Proxima,不翻译) +- Chinese → `NotoFontOption`(`FontFamily.NOTO`,`noto.ttf`) +- Spanish / French / Portuguese → `FontOptionVariant*`(Proxima + 翻译表) + +翻译表为 `resources/{english,chinese,french,spanish,portuguese}.properties.txt`,由 `FontOption` 用 `Properties` 载入。`FontOption.s(String)` 做整串查表,未命中返回原文。 + +### 2.2 字形光栅化:移植版 stb_truetype + +`src/main/java/gg/vape/ui/font/stb/` 是一份完整的 stb_truetype Java 移植: + +- `StbTrueTypeFontInfo` +- `StbTrueTypePackContext` / `StbTrueTypePackRange` / `StbTrueTypePackedChar` +- `StbTrueTypeGlyphPackNode` / `StbTrueTypeBakeContext`(在 `SmoothFontRasterState` 内) +- `StbGlyphCache`(MC 字体桥专用,见 2.4) + +核心入口在 `src/main/java/gg/vape/ui/font/SmoothFontRasterState.java`(约 3400 行)。 + +`BufferedSmoothFontRenderer.w(byte[], int, String)` 的流程: + +1. **收集字符集** + - ASCII `32..126` + - Latin-1 `160..255` + - `chinese.properties.txt` 中出现的所有字符 + - 额外用 GBK 双字节区间(`0xA1..0xF7` × `0xA1..0xFE`)解出全部 CJK 汉字,保证游戏内中文物品/实体名不空白 +2. **初始化字体** + - `SmoothFontRasterState.z(info, bytes, 0)` + - 取全局 ascent/descent,计算 `f5 = size * (0.6 / aspect)` +3. **打包图集** + - `4096 × 4096` 单通道位图 + - `stbtt_PackBegin/PackFontRange` + - 得到每个字的 `x0,y0,x1,y1,xadvance` 与 UV + - 存入 `Map` +4. **创建 GL 纹理** + ```java + GlImageTexture.create(4096, 4096, buffer, GL_RED /*6403*/, + GL_LINEAR /*9729*/, GL_REPEAT /*10497*/); + ``` + 通过 `RenderThreadTaskQueue.enqueue(...)` 回到渲染线程执行。 + +> 注意:**每个字号、每个字体族都各自持有一张 4096² 图集**。 +> 默认还会烘入全部 GBK 汉字,单张 R8 约 16 MB,加 mipmap 约 22 MB,多字号叠加后显存开销明显。 + +### 2.3 两个字体渲染器实现 + +`FontManager` 的缓存值是抽象类 `SmoothFontRenderer`,具体类型由后端决定: + +```java +GuiRenderPrimitives.d() + ? new BufferedSmoothFontRenderer(...) + : new LegacySmoothFontRenderer(...); +``` + +| 实现 | 版本 | 绘制方式 | +| --- | --- | --- | +| `BufferedSmoothFontRenderer` | 1.16.5+ | 每字 4 顶点 → `RenderBatchBuilder` → universal shader | +| `LegacySmoothFontRenderer` | 1.7.10 / 1.8.9 / 1.12.2 | `glBegin(GL_QUADS)` 立即模式 + 独立 GLSL | + +`BufferedSmoothFontRenderer` 的字体 shader 在 `resources/shader/universal_frag.frag`(`shaderMode = 11`): + +```glsl +void fontShader() { + float alpha = texture(imgTexture, f_TexCoords).x; + alpha = max(0.0, alpha + 0.25 * (1.0 - alpha)); + float smoothenAlpha = smoothstep(0.2, 0.8, alpha); + alpha = mix(alpha, 0.0, 1.0 - smoothenAlpha); + FragColor = vec4(f_VertexColor.rgb, alpha * f_VertexColor.a); +} +``` + +“先加 0.25 再 smoothstep”是为了让小字号不发虚。 + +`LegacySmoothFontRenderer` 同样用 stb 建图集,但绘制走: + +```java +GL11.glBegin(GL_QUADS); +GL11.glTexCoord2f(...); +GL11.glVertex2d(...); +GL11.glEnd(); +``` + +并用 `glPushMatrix/glScalef` 做缩放;必要时回退 `Minecraft.getFontRenderer()` 画字。 + +### 2.4 Minecraft 原生字体桥:`StbSmoothFontRenderer` + +当用户选择 `FontFamily.MINECRAFT` 时,`FontManager.x(int)` 返回 `StbSmoothFontRenderer`。它不读 TTF,而是读取游戏自己的字体: + +1. `Minecraft.q()` 取 MC 的 `FontManager` +2. `h()` 取默认 `FontSet` +3. `StbGlyphCache` 对每个 code point 调 `FontSet.getGlyphInfo(char)`,取出: + - 纹理 id + - UV(`u0/v0/u1/v1`) + - advance + - ascent / descent + - glyph 尺寸 +4. 缓存为 `StbGlyphCacheEntry` +5. 绘制时: + +```java +// 彩色位图字体 +BufferedGuiRenderPrimitives.drawMinecraftColorFontGlyph(...); +// R8 强度字体 +BufferedGuiRenderPrimitives.drawMinecraftIntensityFontGlyph(...); +``` + +对应 universal shader 的两个分支: + +| shaderMode | 函数 | 适用纹理 | +| --- | --- | --- | +| 16 | `minecraftFontColorShader()` | RGBA8 彩色位图字体 | +| 17 | `minecraftFontIntensityShader()` | R8 强度字体(`.r` 当 alpha) | + +纹理格式通过 `glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT)` 探测: + +```java +bl2 = n3 != GL_R8; // 33321 +``` + +桥不可用时回退到 wrapper 的 `Minecraft.getFontRenderer()`: + +- `StbGlyphCache.l()` 明确要求 **1.21.10+** +- `StbSmoothFontRenderer.y(...)` 用 `MatrixStack.S(f,f,f)` 后调 `FontRenderer.E/V` +- 1.21.6+ 走 `RenderItemTextBridge`(新的 `Font.drawInBatch` 签名) +- 26.2 对空格单独处理(`StbGlyphCache.H(char)` 调 `getStringWidth(" ")`) + +### 2.5 文本排版细节 + +`src/main/java/gg/vape/ui/font/SmoothFontRenderer.java` 统一了 API: + +| 方法 | 含义 | +| --- | --- | +| `g/O` | 普通绘制;`O(..., boolean shadow)` | +| `v/I` | 带阴影;`I()` 先剥掉 `§` | +| `d/R/N/Y` | 宽度 / 高度测量 | +| `t/T` | 双色(渐变)文本 | +| `f` | 清空字符串/宽度缓存 | + +具体行为: + +- **§ 颜色码** + - 逐字符解析 `§x` + - `o(char, float[3])` 是 16 色表 + - `§r` 恢复基础色 +- **阴影** + - Buffered 非 Stb:`Integer.MIN_VALUE`(ARGB `0x80000000`,半透明黑)偏移 `+0.5,+0.5` 画一遍 + - Stb:颜色乘 `0.25`,偏移 `+1,+1` 画一遍 +- **宽度缓存** + - `SmoothFontRendererWidthCache`:`LinkedHashMap`,最多 5120 项 + - 剥离 `§` 后的字符串也有缓存 +- **字号 / GUI Scale 关系** + + ```java + n = (int)(16 * size * guiScaleFactor); // 烘焙字号 + advance *= 0.6f / guiScaleFactor; // 逻辑宽度 + ``` + + 即:**GUI Scale 只提高字形烘焙分辨率(超采样),不改变逻辑排版宽度**;实际屏幕尺寸由外层矩阵的 `2 * guiScale` 放大。 + +- **截断 / 自适应** + - `TextLabelFitScaleCache`:从最大字号往下降,直到宽度放得下 + - `TruncatedTextComponent` / `FadingTruncatedTextComponent` + - `MarqueeTextRendererComponent`:跑马灯 +- **翻译时机** + - `BufferedSmoothFontRenderer.b()` / `StbSmoothFontRenderer.Z()` 在绘制和测宽前都会执行: + + ```java + string = Vape.INSTANCE.getFontSelector().W().s(string); + ``` + + - 因此翻译后的文本宽度也正确。 +- **限制** + - 按 UTF-16 `char` 遍历,不处理代理对(emoji / 扩展 B 区汉字) + - CJK 覆盖到 GBK 范围为止 + +### 2.6 中文覆盖的构建期校验 + +`build.gradle` 注册了 `verifyFontCoverage`: + +- 用 `tools/FontCoverageCheck.java` 直接解析 `noto.ttf` 的 cmap(format 0/4/6/12) +- 对照 `chinese.properties.txt` 中出现的每个字符 +- 有缺字则构建失败 + +所以中文翻译新增字符时,必须同步裁剪或替换 `noto.ttf`。 + +--- + +## 3. GUI 系统 + +### 3.1 生命周期:不是一个 Minecraft `Screen` + +Vape 的 ClickGUI 不继承 `GuiScreen`,而是画在游戏画面上的自绘 Overlay: + +```text +HUD 打开(inputEnabled = true) + └─ 游戏 HUD 钩子 EventRender2D.create() + ├─ GuiRenderPrimitives.o(displayWidth, displayHeight) + ├─ ClientSettings.renderHudOverlay()/renderHudFrames() + ├─ EventRender2D.fire() + └─ GuiRenderPrimitives.L(...) + +ClickGUI 打开(inputEnabled = false) + └─ EventPostRenderTick.fire() + └─ GuiScreenNativeCallbackBridge.drawScreen(null, 0, 0, 0.0f) + └─ ClientSettings.renderGui() + └─ RenderBatchManager.flushGuiBatches(...) +``` + +- 输入不走 MC 的 `mouseClicked`: + - 原生层回调 `GuiScreenNativeCallbackBridge.mouseClicked / handleMouseInput` + - 再进入 `InputEventDispatcher` / `MouseInputState` +- 打开 / 关闭:`ClientSettings.toggle()` + - `Minecraft.R()` 释放鼠标 + - `gameSettings.P(false)` + - `inputEnabled = false` +- 26.x 专门注入: + - `GuiRendererRenderTickMappingTask` 在 `GuiRenderer.render()` 前后插: + - `EventRender2DHudCallback` → 只画 HUD(在游戏 HUD 下) + - `EventRender2DGuiCallback` → 画通知和 ClickGUI(在游戏 HUD 上) + +这样做最大的好处:**完全绕开各版本 `Screen` / `GuiScreen` / `AbstractGui` 的 API 差异**。 + +### 3.2 坐标系与缩放 + +每帧开始: + +```java +GuiRenderPrimitives.o(displayWidth, displayHeight); +// legacy: NativeBridge.rs(0, w, h) → glOrtho(0, w, h, 0, 1000, 3000) +// 然后 backend.scale(2, 2, 2) + +OpenGlBackendHolder.backend.scale(guiScale, guiScale, guiScale); +``` + +- `Minecraft.J()/h()` 返回 **framebuffer 物理像素** +- 正交投影覆盖 `0..framebufferWidth` +- 先固定 `scale(2,2,2)`,再乘 Vape 自己的 GUI Scale: + - `0.5 / 0.8 / 1.0 / 1.2 / 1.5` + - Auto 按高度选:`>= 2000 → 1.5`,`>= 1000 → 1.2`,否则 `1.0` +- 因此 **1 个 UI 逻辑单位 ≈ `2 * guiScale` 物理像素** +- Scissor 按同一比例换算: + + ```java + double d5 = 2.0 * Vape.INSTANCE.getClientSettings().getGuiScaleFactor(); + ``` + +- 字体烘焙尺寸同样乘 `guiScale`,但逻辑宽度除回去,保证改 GUI Scale 时布局不跳、只是更清晰 + +### 3.3 组件树与布局 + +核心目录 `src/main/java/gg/vape/ui/click/`: + +| 类 / 目录 | 职责 | +| --- | --- | +| `GuiComponent` | 位置/尺寸、可见性、父子关系、鼠标/键盘监听、Tooltip、绑定 `Value` | +| `FrameComponent extends GuiComponent` | 可滚动 Frame 的基类 | +| `Frame` | 可拖动/可缩放的窗口 | +| `FrameStackManager` / `ClickGuiFrameManager` | 窗口栈、置顶、Popup | +| `PopupFrame` / `AnchoredPopupFrame` / `DimmedCenteredPopupFrame` | 弹窗 | +| `layout/ComponentLayout` | 布局约束与排版 | +| `layout/WrappingFlowLayout` / `BottomUpFlowLayout` | 流式布局 | +| `module.none.ClientSettings` | 每帧调度、GUI Scale、Frame 注册 | + +`FrameComponent` 的两个核心方法: + +- `c()`:**渲染** + - 背景 / 圆角 / 阴影 + - 滚动条 + - `scissor` 裁剪 + - 递归子组件 `child.c()` +- `J()`:**更新 / 交互** + - hover + - 点击、滚动 + - tooltip + - 递归子组件 + +文本组件最终都落到: + +```java +SmoothFontRenderer fr = getFontRenderer(scale); +// 或 getAlternateFontRenderer(scale) (bold) + +fr.d(text, x, y, color); // 无阴影 +fr.v(text, x, y, color); // 有阴影 +``` + +`GuiComponent.getFontRenderer(double scale)`: + +```java +return this.fontOption != null + ? this.fontOption.k((float) scale, false) + : Vape.INSTANCE.getFontManager().Y(scale); +``` + +### 3.4 绘制门面:`GuiRenderPrimitives` + 双后端 + +`src/main/java/gg/vape/utils/render/GuiRenderPrimitives.java` 是所有 UI 绘制的统一入口。每个方法内部都做同一个判断: + +```java +if (GuiRenderPrimitives.d()) { // 1.16.5+ + // BufferedGuiRenderPrimitives / RenderBatchBuilder +} else { + // GL11 立即模式 + 自带 GLSL +} +``` + +`d()` 的实现: + +```java +public static boolean d() { + return ForgeVersion.MC_1_16_5.d(); +} +``` + +后端由 `OpenGlBackendHolder` 选择: + +```java +public static OpenGlBackend backend = GuiRenderPrimitives.d() + ? new BufferedOpenGlBackend() + : new LegacyOpenGlBackend(); +``` + +| 后端 | 矩阵 | 顶点 | +| --- | --- | --- | +| `LegacyOpenGlBackend` | `glPushMatrix/glTranslatef/glScalef` | `glBegin/glVertex` | +| `BufferedOpenGlBackend` | 软件 `RenderMatrixStack` | 只记录 capability,不直接画 | + +### 3.5 现代路径:自建批次 + Universal Shader + +这是跨版本 GUI 的核心设计。 + +1. **每个绘制调用产出一个 `RenderBatchBuilder`** + - `addSolidRect` / `addRoundedRect` / `addCircle` / `addFontGlyph` + - `addTexturedRect` / `addBlurPass` / `addCompositeRoundedRect` … +2. **固定 15 个顶点属性**(与 `universal_vert.vert` 的 `layout(location=0..14)` 对应) + + ```text + shaderMode, position, uv, color, + inner, feather, center, middleAngle, sweepAngle, + screenDimensions, origin, innerRect, radius3, spread, corners + ``` + + `shaderMode` 就是“这个顶点走哪段片元逻辑”的编号。 + +3. **`RenderBatchManager.queueGuiBatch(builder)`** + - 按纹理、拓扑、模型矩阵、GL capability、scissor 是否相同尝试合并 + - 每个 batch 最多合并 4500 个 builder +4. **`flushGuiBatches()`** + - 保存并接管 GL 状态(VAO / VBO / program / texture / framebuffer) + - `RenderBatchBuffer.stageBatch()` → 上传顶点/索引 + - `glDrawElements` + - 恢复状态 +5. **Universal Shader** + - `resources/shader/universal_vert.vert` + - `resources/shader/universal_frag.frag` + + 顶点着色器: + + ```glsl + gl_Position = u_Projection * u_View * u_Model * vec4(aPos, 1.0); + ``` + + 片元着色器按 `shaderMode` 分发: + + | mode | 功能 | + | --- | --- | + | 0 | `arcStroke` | + | 1 | `blur` | + | 2 / 3 | 圆 / 圆环描边 | + | 4 | 纹理圆 | + | 5 / 6 | 圆角矩形 / 圆角描边 | + | 7 | 圆角纹理矩形 | + | 8 | 阴影 | + | 9 | 纯色 | + | 10 | 纹理 | + | 11 | 自定义字体 | + | 12 | 反向圆角 | + | 13 / 14 | 胶囊 / 渐变 | + | 16 / 17 | MC 彩色字体 / MC 强度字体 | + + 所有圆角、描边、圆、弧、模糊、字体、阴影、渐变都在一个 shader 里完成。 + **GL 侧只依赖最基础的 VAO / VBO / 纹理 / 混合**,与 MC 的 `RenderType` / `BufferBuilder` / `VertexConsumer` API 解耦,因此 1.17 / 1.20 / 1.21.6 / 26.x 的渲染管线重写基本影响不到它。 + +### 3.6 旧版路径:立即模式 + 独立 shader + +1.8.9 / 1.12.2 等版本: + +- `NativeBridge.rs()` 用 `glOrtho` 设置 2D 投影 +- `GL11.glBegin/glVertex/glTexCoord/glColor` 立即模式 +- 圆角 / 圆 / 阴影等用 `src/main/java/gg/vape/utils/render/shader/*ShaderProgram` 单独编译的 GLSL + - 如 `LegacyFontShaderProgram`:`#version 430 compatibility` + `gl_ModelViewProjectionMatrix` +- 每个绘制函数显式 `glPushMatrix/glPopMatrix`、`glEnable/glDisable` +- `GlStateManager` 包装层负责不同版本的混合、纹理、alpha test 状态 + +### 3.7 1.21.6+ / 26.x 的特殊处理 + +- **1.21.6+** + - MC 的 `Font.drawInBatch` 改成新签名(`Matrix4f` / `MultiBufferSource` / `DisplayMode`) + - `MFontRenderer` 针对 `MC_26_1` 与 `MC_26_2` 分别注册不同的 `drawInBatch` / `text` / `drawString` 映射 +- **1.21.10+** + - `Minecraft.getMainRenderTarget()` 可取主 RT + - `RenderBatchManager.refreshTargetFramebuffer()` 会解析颜色/深度纹理,并包一个自己的 FBO,保证 GUI 画到参与最终合成的目标上 +- **26.2** + - `GuiRenderer.render()` 前/后分别插 HUD / GUI 回调 + - 通知从 HUD pass 移到 GUI pass: + + ```java + if (!ForgeVersion.MC_26_2.d()) { + notificationManager.renderNotifications(); + } + ``` + + - 字体桥对空格、纹理格式、`FontSet` 初始化都有专门分支 + +### 3.8 模糊、物品与实体预览 + +- **背景模糊** + - 旧版:`ShaderGroupRenderStateManager` 使用 MC 自己的 post-processing `ShaderGroup` + - 1.16.5+:`BlurRegionRenderer` + `RenderBatchBuilder.addBlurPass()`,走 universal shader 的 `blur()` +- **物品图标** + - `ItemIconRenderer` / `ItemStackRenderUtils` + - 1.21.6+ 用 `RenderItemTextBridge` / `Matrix4fHandle` +- **实体预览** + - `EntityModelFramebufferRenderer` + - `Post117EntityModelFramebufferRenderer` + - 按版本选择“直接画”或“渲染到 FBO 再当纹理贴” +- **纹理图集** + - `TextureAtlasRegistry` / `TextureAtlas` / `TextureAtlasRegion` + - `ImageRenderer` 负责 PNG 解码与图集区域查找 + +--- + +## 4. 跨版本路径一览 + +| 版本 | GUI 后端 | 字体渲染 | 备注 | +| --- | --- | --- | --- | +| 1.7.10 | Legacy | `LegacySmoothFontRenderer` + MC 字体回退 | `glOrtho` + 立即模式 | +| 1.8.9(含 Badlion) | Legacy | 同上 | Badlion 有独立按键队列 / 渲染回调 | +| 1.12.2 | Legacy | 同上 | | +| 1.16.5 | **Buffered** | `BufferedSmoothFontRenderer` | 第一批切到自建 VAO/VBO + shader | +| 1.17–1.20.5 | Buffered | Buffered | `drawInBatch(MatrixStack...)` 系 | +| 1.20.6–1.21.5 | Buffered | Buffered / MC 字体桥 | `drawInBatch(Matrix4f, MultiBufferSource, DisplayMode...)` | +| 1.21.6–1.21.11 | Buffered | Buffered / MC 字体桥 | 新 RenderPass / GPU 管线,Vape 仍用自建 shader | +| 26.1 / 26.2 | Buffered | Buffered / MC 字体桥 | `GuiRenderer.render` 前后双回调;自建 FBO 包装主 RT | + +--- + +## 5. 关键结论与坑 + +1. **字体不是“用 MC 的 FontRenderer 改个 TTF”** + - 内嵌 stb_truetype 把 TTF 烘成图集 + - 自建 shader 画四边形 + - 中文完整覆盖 GBK 汉字 + - 构建期还有 cmap 覆盖校验 + +2. **GUI 不是 `GuiScreen`** + - 每帧在 HUD / PostRender 阶段画自绘 Overlay + - 输入靠原生回调 + - 天然规避各版本 `Screen` API 差异 + +3. **跨版本的核心是“两条渲染路径 + 一套映射层”** + - 1.16.5+:自建批次 + universal shader(GL 基础 API) + - 旧版:立即模式 + 独立 shader + `glOrtho` + - 所有 MC 类/字段/方法通过 `MappedClasses` / `MappingMethod` / `Reflections` 按版本解析 + +4. **缩放策略** + - 逻辑坐标固定 + - `size * guiScale` 只影响烘焙分辨率 + - 屏幕尺寸由 `2 * guiScale` 统一缩放决定 + - scissor 同步换算 + +5. **主要代价 / 坑** + - 每个字号一张 4096² R8 图集(含全 GBK),显存占用高 + - 系统字体依赖 Windows 路径(Arial / Bahnschrift) + - `StbSmoothFontRenderer` 的 MC 字体桥只有 1.21.10+ 可用,低版本回退 MC 原版字体 + - UTF-16 `char` 遍历不支持代理对(emoji / 扩展汉字) + - 旧版 shader 依赖 `#version 430 compatibility`,对驱动/上下文有隐含要求 + - 1.21.6+ / 26.x 的 framebuffer 与 GUI pass 需要单独的兼容处理 + +--- + +## 6. 建议阅读顺序 + +如果要继续修改字体或 GUI,建议从这几个入口按顺序看: + +1. `src/main/java/gg/vape/ui/font/FontManager.java` + - 字体选择、字号缓存、GUI Scale 参与方式 +2. `src/main/java/gg/vape/ui/font/BufferedSmoothFontRenderer.java` + - TTF → 字形图集 → 顶点 +3. `src/main/java/gg/vape/ui/font/StbSmoothFontRenderer.java` + - MC 原生 `FontSet` 桥 +4. `src/main/java/gg/vape/utils/render/RenderBatchBuilder.java` + - 图形/字体的顶点语义 +5. `src/main/resources/resources/shader/universal_frag.frag` + - 所有 shaderMode 的实际像素逻辑 +6. `src/main/java/gg/vape/utils/render/GuiRenderPrimitives.java` + - 双后端分界与所有绘制原语 +7. `src/main/java/gg/vape/module/none/ClientSettings.java` 的 `renderGui()` / `renderHudFrames()` + - 每帧顺序、缩放、Frame 调度 +8. `src/main/java/gg/vape/ui/click/frame/FrameComponent.java` + - 组件树渲染 `c()` 与交互 `J()`