Commit 197e2501 authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

Map characters to SQF's encoding better.

parent 18fb9d46
......@@ -51,6 +51,9 @@ More detailed changes:
to specify arguments, system properties, and console output alternatives
to launched tasks.
* `midp-lcdui`
* Corrected mapping of characters since SQFs are ISO-8859-1 and most games
may be ISO-8859-1, since some characters may be missing in the font
use similar graphics for them.
* Fully added `cc.squirreljme.runtime.lcdui.gfx.SerializedGraphics`, This
allows all of the graphics drawing functions to be forwarded when
graphics acceleration is used, previously only a subset of methods were
......
......@@ -377,5 +377,46 @@ public final class SQFFont
return new SQFFont(pixelheight, ascent, descent, bytesperscan,
charwidths, isvalidchar, charbmp);
}
/**
* This maps the given character to the SQF character map.
*
* Since SQFs are ISO-8859-15, they do not map exactly to ISO-8859-1
* which may be the default encoding.
*
* @param __c The character to map.
* @return The mapped character.
* @since 2019/04/29
*/
public static final char mapChar(char __c)
{
switch (__c)
{
// Convert
case 0x20AC: return (char)0x00A4;
case 0x0160: return (char)0x00A6;
case 0x0161: return (char)0x00A8;
case 0x017D: return (char)0x00B4;
case 0x017E: return (char)0x00B8;
case 0x0152: return (char)0x00BC;
case 0x0153: return (char)0x00BD;
case 0x0178: return (char)0x00BE;
// Map similar characters to others
case 0x00A4: return (char)0x20AC;
case 0x00B4: return '\'';
case 0x00A6: return '|';
case 0x00A8: return '"';
// Cannot be mapped
case 0x00B8:
case 0x00BC:
case 0x00BD:
case 0x00BE: return (char)0xFFFD;
}
// Mapped the same
return __c;
}
}
......@@ -1484,9 +1484,12 @@ public class AdvancedGraphics
dsy >= clipey || dey <= 0)
continue;
// Map character index to the SQF
char mc = SQFFont.mapChar(c);
// Base scan offsets and such
int scanoff = 0,
scanlen = sqf.charWidth(c),
scanlen = sqf.charWidth(mc),
lineoff = 0,
linelen = pixelheight;
......@@ -1521,7 +1524,7 @@ public class AdvancedGraphics
linelen -= (dey - clipey);
// Draw the bitmap for the character
int bps = sqf.loadCharBitmap(c, bmp);
int bps = sqf.loadCharBitmap(mc, bmp);
this.funccharbmp.function(this,
new int[]{color, dsx, dsy, bps, scanoff, scanlen,
lineoff, linelen},
......
......@@ -151,7 +151,7 @@ public final class Font
*/
public int charWidth(char __c)
{
return this._sqf.charWidth(__c);
return this._sqf.charWidth(SQFFont.mapChar(__c));
}
public int charsWidth(char[] __a, int __b, int __c)
......@@ -454,7 +454,7 @@ public final class Font
}
// Add the character's width
curwidth += sqf.charWidth(c);
curwidth += sqf.charWidth(SQFFont.mapChar(c));
}
// Use the greater width
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment