Skip to content

Commit

Permalink
Font: Force smoothing in all cases, and improve fps counter
Browse files Browse the repository at this point in the history
Using the GASP hint makes it font-dependent, whereas ON should
force AA regardless of the font. Might help with #59.
  • Loading branch information
AShiningRay committed Feb 21, 2025
1 parent 3cef9e2 commit 2a79e44
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/javax/microedition/lcdui/Font.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public final class Font
private static final int[] fontSizes =
{
10, 12, 14, // < 128 minimum px dimension
12, 14, 15, // < 176 minimum px dimension
12, 14, 16, // < 176 minimum px dimension
14, 16, 18, // < 220 minimum px dimension
16, 18, 20, // >= 220 minimum px dimension
};
Expand Down
17 changes: 8 additions & 9 deletions src/org/recompile/mobile/MobilePlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class MobilePlatform
private long sleepTime = 0;

// Whether the user has toggled the ShowFPS option
private final int OVERLAY_WIDTH = 80;
private final int OVERLAY_WIDTH = 100;
private final int OVERLAY_HEIGHT = 20;
private String showFPS = "Off";
private int frameCount = 0;
Expand Down Expand Up @@ -376,8 +376,7 @@ private final void showFPS()
BufferedImage overlayImage = new BufferedImage(OVERLAY_WIDTH, OVERLAY_HEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics2D overlayGraphics = overlayImage.createGraphics();

// Enable font AA for better text quality (GASP uses font resource information to apply AA when appropriate)
gc.getGraphics2D().setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
gc.getGraphics2D().setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
gc.getGraphics2D().setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

// Set the overlay background
Expand All @@ -399,12 +398,12 @@ private final void showFPS()
double scale = Math.min(lcdWidth, lcdHeight);

int scaledWidth = 0;
if(scale < 100) { scaledWidth = (int) (lcdWidth / 2.5);}
if(scale > 100) { scaledWidth = (int) (lcdWidth / 3);}
if(scale > 200) { scaledWidth = (int) (lcdWidth / 4);}
if(scale > 300) { scaledWidth = (int) (lcdWidth / 5);}
if(scale > 400) { scaledWidth = (int) (lcdWidth / 6);}
int scaledHeight = (int) (scaledWidth / 4);
if(scale < 100) { scaledWidth = (int) (lcdWidth / 2);}
if(scale > 100) { scaledWidth = (int) (lcdWidth / 2.5);}
if(scale > 200) { scaledWidth = (int) (lcdWidth / 3);}
if(scale > 300) { scaledWidth = (int) (lcdWidth / 4);}
if(scale > 400) { scaledWidth = (int) (lcdWidth / 5);}
int scaledHeight = (int) (scaledWidth / 5);

// Draw the scaled overlay image onto the jar's main screen.
if(showFPS.equals("TopLeft")) { gc.getGraphics2D().drawImage(overlayImage, 2, 2, scaledWidth, scaledHeight, null); }
Expand Down
2 changes: 1 addition & 1 deletion src/org/recompile/mobile/PlatformGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public PlatformGraphics(PlatformImage image)
setStrokeStyle(SOLID);
gc.setBackground(new Color(0, 0, 0, 0));
gc.setFont(font.platformFont.awtFont);
gc.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
gc.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}

public void reset() //Internal use method, resets the Graphics object to its inital values
Expand Down

0 comments on commit 2a79e44

Please sign in to comment.