Better text resolution on texture
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 1 May 2020 22:58:03 +0000 (01:58 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 1 May 2020 22:58:03 +0000 (01:58 +0300)
src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/TextEditComponent.java
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/ForwardOrientedTextBlock.java
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/TexturedRectangle.java
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/CanvasCharacter.java
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java

index 651193d..a6987eb 100755 (executable)
@@ -42,8 +42,8 @@ public class TextEditComponent extends GuiComponent implements ClipboardOwner {
 
         // initialize visual panel
 
-        final int columns = (int) (size.x / TextCanvas.FONT_CHAR_WIDTH_PIXELS);
-        final int rows = (int) (size.y / TextCanvas.FONT_CHAR_HEIGHT_PIXELS);
+        final int columns = (int) (size.x / TextCanvas.FONT_CHAR_WIDTH);
+        final int rows = (int) (size.y / TextCanvas.FONT_CHAR_HEIGHT);
 
         textCanvas = new TextCanvas(new Transform(), new TextPointer(rows,
                 columns), Color.WHITE, colorConfig.normalBack);
index 7fac52d..30e92bc 100644 (file)
@@ -23,7 +23,7 @@ public class ForwardOrientedTextBlock extends ForwardOrientedTexture {
                                      final eu.svjatoslav.sixth.e3d.renderer.raster.Color textColor) {
 
         final Texture texture = new Texture(text.length()
-                * TextCanvas.FONT_CHAR_WIDTH_PIXELS, TextCanvas.FONT_CHAR_HEIGHT_PIXELS,
+                * TextCanvas.FONT_CHAR_WIDTH_TEXTURE_PIXELS, TextCanvas.FONT_CHAR_HEIGHT_TEXTURE_PIXELS,
                 maxUpscaleFactor);
 
         // texture.graphics.setColor(Color.BLUE);
@@ -35,8 +35,8 @@ public class ForwardOrientedTextBlock extends ForwardOrientedTexture {
 
         for (int c = 0; c < text.length(); c++)
             texture.graphics.drawChars(new char[]{text.charAt(c),}, 0, 1,
-                    (c * TextCanvas.FONT_CHAR_WIDTH_PIXELS) - 0,
-                    (0 * TextCanvas.FONT_CHAR_HEIGHT_PIXELS) + 11);
+                    (c * TextCanvas.FONT_CHAR_WIDTH_TEXTURE_PIXELS),
+                    (int) (TextCanvas.FONT_CHAR_HEIGHT_TEXTURE_PIXELS / 1.45));
 
         return texture;
     }
index 2894136..776c41d 100644 (file)
@@ -80,9 +80,9 @@ public class TexturedRectangle extends AbstractCompositeShape {
         addShape(texturedPolygon2);
     }
 
-    public void initialize(final int width, final int height,
-                           final int maxTextureUpscale) {
-        initialize(width, height, width, height, maxTextureUpscale);
-    }
+//    public void initialize(final int width, final int height,
+//                           final int maxTextureUpscale) {
+//        initialize(width, height, width, height, maxTextureUpscale);
+//    }
 
 }
index e15058a..c66d5b5 100644 (file)
@@ -39,8 +39,8 @@ public class CanvasCharacter extends AbstractCoordinateShape {
 
         // set corner coordinates (for drawing background)
         {
-            final double widthHalf = TextCanvas.FONT_CHAR_WIDTH_PIXELS / 2d;
-            final double heightHalf = TextCanvas.FONT_CHAR_HEIGHT_PIXELS / 2d;
+            final double widthHalf = TextCanvas.FONT_CHAR_WIDTH / 2d;
+            final double heightHalf = TextCanvas.FONT_CHAR_HEIGHT / 2d;
 
             // upper left
             coordinates[1].coordinate = point.clone().translateX(-widthHalf)
index ca06706..7945a54 100644 (file)
@@ -22,9 +22,16 @@ import static eu.svjatoslav.sixth.e3d.renderer.raster.Color.WHITE;
 
 public class TextCanvas extends TexturedRectangle {
 
-    public static final int FONT_CHAR_WIDTH_PIXELS = 8;
-    public static final int FONT_CHAR_HEIGHT_PIXELS = 16;
-    public static final Font FONT = CanvasCharacter.getFont(15);
+    // character size in world coordiates
+    public static final int FONT_CHAR_WIDTH = 8;
+    public static final int FONT_CHAR_HEIGHT = 16;
+
+    // character size on texture
+    public static final int FONT_CHAR_WIDTH_TEXTURE_PIXELS = 16;
+    public static final int FONT_CHAR_HEIGHT_TEXTURE_PIXELS = 32;
+
+
+    public static final Font FONT = CanvasCharacter.getFont((int)(FONT_CHAR_HEIGHT_TEXTURE_PIXELS / 1.066));
     private static final String GROUP_TEXTURE = "texture";
     private static final String GROUP_CHARACTERS = "characters";
     private final TextPointer size;
@@ -54,7 +61,12 @@ public class TextCanvas extends TexturedRectangle {
         this.foregroundColor = foregroundColor;
 
         // initialize underlying textured rectangle
-        initialize(columns * FONT_CHAR_WIDTH_PIXELS, rows * FONT_CHAR_HEIGHT_PIXELS, 0);
+        initialize(
+                columns * FONT_CHAR_WIDTH,
+                rows * FONT_CHAR_HEIGHT,
+                columns * FONT_CHAR_WIDTH_TEXTURE_PIXELS,
+                rows * FONT_CHAR_HEIGHT_TEXTURE_PIXELS,
+                0);
 
         getTexture().primaryBitmap.fillColor(backgroundColor);
         getTexture().resetResampledBitmapCache();
@@ -150,15 +162,19 @@ public class TextCanvas extends TexturedRectangle {
                                    final char character, final Color foreground) {
         final Graphics2D graphics = getTexture().graphics;
 
-        getTexture().primaryBitmap.drawRectangle(column * FONT_CHAR_WIDTH_PIXELS, row
-                        * FONT_CHAR_HEIGHT_PIXELS, (column * FONT_CHAR_WIDTH_PIXELS)
-                        + FONT_CHAR_WIDTH_PIXELS, (row * FONT_CHAR_HEIGHT_PIXELS) + FONT_CHAR_HEIGHT_PIXELS,
+        getTexture().primaryBitmap.drawRectangle(
+                column * FONT_CHAR_WIDTH_TEXTURE_PIXELS,
+                row * FONT_CHAR_HEIGHT_TEXTURE_PIXELS,
+                (column * FONT_CHAR_WIDTH_TEXTURE_PIXELS) + FONT_CHAR_WIDTH_TEXTURE_PIXELS,
+                (row * FONT_CHAR_HEIGHT_TEXTURE_PIXELS) + FONT_CHAR_HEIGHT_TEXTURE_PIXELS,
                 backgroundColor);
 
         graphics.setFont(FONT);
         graphics.setColor(foreground.toAwtColor());
-        graphics.drawChars(new char[]{character,}, 0, 1,
-                (column * FONT_CHAR_WIDTH_PIXELS) - 0, (row * FONT_CHAR_HEIGHT_PIXELS) + 13);
+        graphics.drawChars(
+                new char[]{character,}, 0, 1,
+                (column * FONT_CHAR_WIDTH_TEXTURE_PIXELS) - 0,
+                (row * FONT_CHAR_HEIGHT_TEXTURE_PIXELS) + (int)(FONT_CHAR_HEIGHT_TEXTURE_PIXELS / 1.23f));
 
         getTexture().resetResampledBitmapCache();
     }
@@ -166,11 +182,11 @@ public class TextCanvas extends TexturedRectangle {
     public Point3D getCharLocation(final int row, final int column) {
         final Point3D coordinate = topLeft.clone();
 
-        coordinate.translateY((row * FONT_CHAR_HEIGHT_PIXELS)
-                + ((FONT_CHAR_HEIGHT_PIXELS / 2) - 3));
+        coordinate.translateY((row * FONT_CHAR_HEIGHT)
+                + (FONT_CHAR_HEIGHT / 3.2));
 
-        coordinate.translateX((column * FONT_CHAR_WIDTH_PIXELS)
-                + (FONT_CHAR_WIDTH_PIXELS / 2));
+        coordinate.translateX((column * FONT_CHAR_WIDTH)
+                + (FONT_CHAR_WIDTH / 2));
 
         return coordinate;
     }