Skip to content

Commit

Permalink
Fixes font rendering issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltasarq committed Apr 27, 2022
1 parent 3be156f commit 8adec3a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/com/devbaltasarq/pooi/core/AppInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class AppInfo {
public static final String Name = "Pooi";
public static final String Email = "jbgarcia@uvigo.es";
public static final String Author = "Baltasar García Perez-Schofield";
public static final String Version = "2.2.1 20181203";
public static final String Version = "2.2.2 20220427";
public static final String License = "MIT License: https://opensource.org/licenses/MIT";
public static final String SessionFileExt = ".txt";
public static final String ScriptFileExt = ".poi";
Expand Down
5 changes: 5 additions & 0 deletions src/com/devbaltasarq/pooi/ui/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import com.devbaltasarq.pooi.core.Interpreter;
import com.devbaltasarq.pooi.core.Interpreter.InterpretError;
import com.devbaltasarq.pooi.core.InterpreterCfg;
import sun.awt.resources.awt;

import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.util.Map;
import java.util.Scanner;

/**
Expand Down Expand Up @@ -85,6 +88,8 @@ private static void guiApp(Interpreter interpreter, String msg)
{
// Prepare look & feel, if possible
try {
System.setProperty( "swing.aatext", "true" );
System.setProperty( "awt.useSystemAAFontSettings", "on" );
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
} catch(Exception ignored) {
}
Expand Down
29 changes: 22 additions & 7 deletions src/com/devbaltasarq/pooi/ui/Canvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Map;

/**
* Created by baltasarq on 27/04/16.
Expand All @@ -18,7 +19,7 @@ public Canvas(int width, int height)
{
this.setMinimumSize( new Dimension( width, height ) );

canvas = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB);
canvas = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB );
JLabel canvasFrame = new JLabel( new ImageIcon( canvas ) );
canvasFrame.setPreferredSize( new Dimension( width, height ) );
canvasFrame.setMinimumSize( new Dimension( width, height ) );
Expand Down Expand Up @@ -58,7 +59,8 @@ public void setBackgroundColor(Color c) {
}

/** Clears the drawing area */
public void cls() {
public void cls()
{
final Graphics grfs = this.canvas.getGraphics();

grfs.setColor( this.getBackgroundColor() );
Expand Down Expand Up @@ -134,6 +136,14 @@ public void circle(int x, int y, int r, boolean filled)
}
}

/** Gets the hints for antialiasing. */
private Map getDesktopHints()
{
final Toolkit TK = Toolkit.getDefaultToolkit();

return (Map)( TK.getDesktopProperty("awt.font.desktophints") );
}

/**
* Draws a string in the graphic window
* @param x the x coordinate of the starting point
Expand All @@ -154,16 +164,21 @@ public void print(int x, int y, String str)
public void print(int x, int y, String str, boolean isBold)
{
if ( str != null ) {
final Graphics grfs = canvas.getGraphics();
final Graphics2D GRFS = (Graphics2D) canvas.getGraphics();
final Map HINTS = this.getDesktopHints();
Font font = this.getFont();

if ( isBold ) {
font = font.deriveFont( Font.BOLD );
font = font.deriveFont( Font.BOLD );
}

if ( HINTS != null ) {
GRFS.addRenderingHints( HINTS );
}

grfs.setFont( font );
grfs.setColor( this.getColor() );
grfs.drawChars( str.toCharArray(), 0, str.length(), x, y );
GRFS.setFont( font );
GRFS.setColor( this.getColor() );
GRFS.drawChars( str.toCharArray(), 0, str.length(), x, y );
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/com/devbaltasarq/pooi/ui/VisualEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,6 @@ private void build()

// Split view
this.spPanel = new JSplitPane();
this.spPanel.setDividerLocation( 150 );
spMain.setDividerLocation( (int) ( this.getHeight() - ( this.getHeight() * 0.15 ) ) );

// Build components
this.buildMenuBar();
Expand Down Expand Up @@ -548,8 +546,10 @@ public void mouseExited(MouseEvent e) {
}
} );

// Center on screen
// Center on screen & polish
this.setLocationRelativeTo( null );
this.spPanel.setDividerLocation( (int) ( this.getWidth() * .15 ) );
spMain.setDividerLocation( (int) ( this.getHeight() - ( this.getHeight() * .33 ) ) );
}

private void onLoadSession()
Expand Down

0 comments on commit 8adec3a

Please sign in to comment.