mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2025-01-03 13:31:44 +00:00
Unified font display
This commit is contained in:
parent
314d86e36e
commit
895dc892a5
85
src/com/bytezone/diskbrowser/applefile/CharacterList.java
Normal file
85
src/com/bytezone/diskbrowser/applefile/CharacterList.java
Normal file
@ -0,0 +1,85 @@
|
||||
package com.bytezone.diskbrowser.applefile;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
abstract class CharacterList extends AbstractFile
|
||||
{
|
||||
static final int borderX = 3;
|
||||
static final int borderY = 3;
|
||||
static final int gapX = 3;
|
||||
static final int gapY = 3;
|
||||
|
||||
static final int sizeX = 7;
|
||||
static final int sizeY = 8;
|
||||
|
||||
List<Character> characters = new ArrayList<> ();
|
||||
|
||||
public CharacterList (String name, byte[] buffer, int charsX, int charsY)
|
||||
{
|
||||
this (name, buffer, charsX, charsY, 0);
|
||||
}
|
||||
|
||||
public CharacterList (String name, byte[] buffer, int charsX, int charsY, int offset)
|
||||
{
|
||||
super (name, buffer);
|
||||
|
||||
image = new BufferedImage ( //
|
||||
dimension (charsX, borderX, sizeX, gapX), //
|
||||
dimension (charsY, borderY, sizeY, gapY), //
|
||||
BufferedImage.TYPE_BYTE_GRAY);
|
||||
|
||||
Graphics2D g2d = image.createGraphics ();
|
||||
g2d.setComposite (AlphaComposite.getInstance (AlphaComposite.SRC_OVER, (float) 1.0));
|
||||
|
||||
if (false) // show gaps around the glyphs
|
||||
{
|
||||
g2d.setColor (new Color (245, 245, 245)); // match background
|
||||
g2d.fillRect (0, 0, image.getWidth (), image.getHeight ());
|
||||
}
|
||||
|
||||
int x = borderX;
|
||||
int y = borderY;
|
||||
int count = 0;
|
||||
int ptr = offset;
|
||||
|
||||
while (ptr < buffer.length)
|
||||
{
|
||||
Character c = createCharacter (buffer, ptr);
|
||||
characters.add (c);
|
||||
ptr += sizeY;
|
||||
|
||||
g2d.drawImage (c.image, x, y, null);
|
||||
if (++count % charsX == 0)
|
||||
{
|
||||
x = borderX;
|
||||
y += sizeY + gapY;
|
||||
}
|
||||
else
|
||||
x += sizeX + gapX;
|
||||
}
|
||||
|
||||
g2d.dispose ();
|
||||
}
|
||||
|
||||
abstract Character createCharacter (byte[] buffer, int ptr);
|
||||
|
||||
int dimension (int chars, int border, int size, int gap)
|
||||
{
|
||||
return border * 2 + chars * (size + gap) - gap;
|
||||
}
|
||||
|
||||
class Character
|
||||
{
|
||||
BufferedImage image;
|
||||
|
||||
public Character (byte[] buffer, int ptr)
|
||||
{
|
||||
image = new BufferedImage (sizeX, sizeY, BufferedImage.TYPE_BYTE_GRAY);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,99 +1,26 @@
|
||||
package com.bytezone.diskbrowser.applefile;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.bytezone.common.Platform;
|
||||
import com.bytezone.common.Platform.FontType;
|
||||
|
||||
// see graffidisk.v1.0.2mg
|
||||
public class CharacterRom extends AbstractFile
|
||||
public class CharacterRom extends CharacterList
|
||||
{
|
||||
private static final int charsX = 16;
|
||||
private static final int charsY = 6;
|
||||
|
||||
String description;
|
||||
List<Character> characters = new ArrayList<> ();
|
||||
|
||||
public CharacterRom (String name, byte[] buffer)
|
||||
{
|
||||
super (name, buffer);
|
||||
super (name, buffer, charsX, charsY, 256);
|
||||
|
||||
description = new String (buffer, 16, 16);
|
||||
|
||||
int sizeX = buffer[5] & 0xFF;
|
||||
int sizeY = buffer[6] & 0xFF;
|
||||
|
||||
int gapX = 2;
|
||||
int gapY = 2;
|
||||
int marginX = 2;
|
||||
int marginY = 2;
|
||||
int heading = 15;
|
||||
|
||||
image = new BufferedImage (16 * (sizeX + gapX) + 2 * marginX - gapX,
|
||||
6 * (sizeY + gapY) + 2 * marginY - gapY + heading, BufferedImage.TYPE_BYTE_GRAY);
|
||||
Graphics2D g2d = image.createGraphics ();
|
||||
g2d.setComposite (AlphaComposite.getInstance (AlphaComposite.SRC_OVER, (float) 1.0));
|
||||
|
||||
int x = marginX;
|
||||
int y = marginY + heading;
|
||||
int count = 0;
|
||||
int ptr = 256;
|
||||
|
||||
while (ptr < buffer.length)
|
||||
{
|
||||
Character character = new Character (buffer, ptr);
|
||||
characters.add (character);
|
||||
ptr += 8;
|
||||
|
||||
g2d.drawImage (character.image, x, y, null);
|
||||
x += sizeX + gapX;
|
||||
if (++count % 16 == 0)
|
||||
{
|
||||
x = marginX;
|
||||
y += sizeY + gapY;
|
||||
}
|
||||
}
|
||||
|
||||
y = marginY;
|
||||
x = marginX;
|
||||
Font font = Platform.getFont (FontType.SANS_SERIF, 10);
|
||||
g2d.setFont (font);
|
||||
|
||||
for (int i = 0; i < description.length (); i++)
|
||||
{
|
||||
int pos = description.charAt (i);
|
||||
if (pos == 0)
|
||||
break;
|
||||
Character character = characters.get (pos - 32);
|
||||
g2d.drawImage (character.image, x, y, null);
|
||||
x += sizeX;
|
||||
}
|
||||
|
||||
g2d.dispose ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText ()
|
||||
{
|
||||
StringBuilder text = new StringBuilder (description + "\n\n");
|
||||
for (int i = 256; i < buffer.length; i += 8)
|
||||
{
|
||||
for (int line = 0; line < 8; line++)
|
||||
{
|
||||
int value = buffer[i + line] & 0xFF;
|
||||
for (int bit = 0; bit < 8; bit++)
|
||||
{
|
||||
text.append ((value & 0x80) != 0 ? "X" : ".");
|
||||
value <<= 1;
|
||||
}
|
||||
text.append ("\n");
|
||||
}
|
||||
text.append ("\n");
|
||||
}
|
||||
return text.toString ();
|
||||
assert sizeX == (buffer[5] & 0xFF);
|
||||
assert sizeY == (buffer[6] & 0xFF);
|
||||
}
|
||||
|
||||
public static boolean isRom (byte[] buffer)
|
||||
@ -107,23 +34,50 @@ public class CharacterRom extends AbstractFile
|
||||
&& buffer[2] == (byte) 0x53 && buffer[3] == (byte) 0x10;
|
||||
}
|
||||
|
||||
class Character
|
||||
@Override
|
||||
public String getText ()
|
||||
{
|
||||
private final BufferedImage image;
|
||||
StringBuilder text = new StringBuilder (description + "\n\n");
|
||||
|
||||
public Character (byte[] buffer, int ptr)
|
||||
for (int i = 256; i < buffer.length; i += sizeY)
|
||||
{
|
||||
// draw the image
|
||||
image = new BufferedImage (7, 8, BufferedImage.TYPE_BYTE_GRAY);
|
||||
for (int line = 0; line < sizeY; line++)
|
||||
{
|
||||
int value = buffer[i + line] & 0xFF;
|
||||
for (int bit = 0; bit < sizeX; bit++)
|
||||
{
|
||||
text.append ((value & 0x80) == 0 ? "." : "X");
|
||||
value <<= 1;
|
||||
}
|
||||
text.append ("\n");
|
||||
}
|
||||
text.append ("\n");
|
||||
}
|
||||
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
@Override
|
||||
Character createCharacter (byte[] buffer, int ptr)
|
||||
{
|
||||
return new CharacterRomCharacter (buffer, ptr);
|
||||
}
|
||||
|
||||
class CharacterRomCharacter extends Character
|
||||
{
|
||||
public CharacterRomCharacter (byte[] buffer, int ptr)
|
||||
{
|
||||
super (buffer, ptr);
|
||||
|
||||
DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
|
||||
int element = 0;
|
||||
|
||||
for (int line = 0; line < 8; line++)
|
||||
for (int i = 0; i < sizeY; i++)
|
||||
{
|
||||
int value = buffer[ptr++] & 0xFF;
|
||||
for (int bit = 0; bit < 7; bit++)
|
||||
for (int j = 0; j < sizeX; j++)
|
||||
{
|
||||
dataBuffer.setElem (element++, (value & 0x80) != 0 ? 255 : 0);
|
||||
dataBuffer.setElem (element++, (value & 0x80) == 0 ? 0 : 0xFF);
|
||||
value <<= 1;
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,69 @@
|
||||
package com.bytezone.diskbrowser.applefile;
|
||||
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// Found on Pascal disks
|
||||
public class Charset extends AbstractFile
|
||||
public class Charset extends CharacterList
|
||||
{
|
||||
private static final int charsX = 16;
|
||||
private static final int charsY = 8;
|
||||
|
||||
List<Character> characters = new ArrayList<> ();
|
||||
|
||||
public Charset (String name, byte[] buffer)
|
||||
{
|
||||
super (name, buffer);
|
||||
super (name, buffer, charsX, charsY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText ()
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
for (int i = 0; i < buffer.length; i += 8)
|
||||
|
||||
for (int i = 0; i < buffer.length; i += sizeY)
|
||||
{
|
||||
for (int line = 7; line >= 0; line--)
|
||||
for (int line = sizeY - 1; line >= 0; line--)
|
||||
{
|
||||
int value = buffer[i + line] & 0xFF;
|
||||
for (int bit = 0; bit < 8; bit++)
|
||||
int value = buffer[line + i] & 0xFF;
|
||||
for (int bit = 0; bit < sizeX; bit++)
|
||||
{
|
||||
text.append ((value & 0x01) == 1 ? "X" : ".");
|
||||
value >>= 1;
|
||||
text.append ((value & 0x01) == 0 ? "." : "X");
|
||||
value >>>= 1;
|
||||
}
|
||||
text.append ("\n");
|
||||
}
|
||||
text.append ("\n");
|
||||
}
|
||||
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
@Override
|
||||
Character createCharacter (byte[] buffer, int ptr)
|
||||
{
|
||||
return new CharsetCharacter (buffer, ptr);
|
||||
}
|
||||
|
||||
class CharsetCharacter extends Character
|
||||
{
|
||||
public CharsetCharacter (byte[] buffer, int ptr)
|
||||
{
|
||||
super (buffer, ptr);
|
||||
|
||||
DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
|
||||
int element = 0;
|
||||
|
||||
for (int i = sizeY - 1; i >= 0; i--)
|
||||
{
|
||||
int value = buffer[ptr + i] & 0xFF;
|
||||
for (int j = 0; j < sizeX; j++)
|
||||
{
|
||||
dataBuffer.setElem (element++, (value & 0x01) == 0 ? 0 : 0xFF);
|
||||
value >>>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,99 +1,21 @@
|
||||
package com.bytezone.diskbrowser.applefile;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FontFile extends AbstractFile
|
||||
public class FontFile extends CharacterList
|
||||
{
|
||||
private static final int borderX = 3;
|
||||
private static final int borderY = 3;
|
||||
private static final int gapX = 3;
|
||||
private static final int gapY = 3;
|
||||
private static final int charsX = 8;
|
||||
private static final int charsY = 12;
|
||||
|
||||
private static final int sizeX = 7;
|
||||
private static final int sizeY = 8;
|
||||
private static final int charBytes = 8;
|
||||
private static final int charsX = 16;
|
||||
private static final int charsY = 6;
|
||||
|
||||
List<Character> characters = new ArrayList<Character> ();
|
||||
|
||||
public FontFile (String name, byte[] buffer, int address)
|
||||
{
|
||||
super (name, buffer);
|
||||
super (name, buffer, charsX, charsY);
|
||||
|
||||
loadAddress = address;
|
||||
|
||||
image = new BufferedImage ( //
|
||||
dimension (charsX, borderX, sizeX, gapX), //
|
||||
dimension (charsY, borderY, sizeY, gapY), //
|
||||
BufferedImage.TYPE_BYTE_GRAY);
|
||||
|
||||
Graphics2D g2d = image.createGraphics ();
|
||||
g2d.setComposite (AlphaComposite.getInstance (AlphaComposite.SRC_OVER, (float) 1.0));
|
||||
|
||||
if (false) // show gaps around the glyphs
|
||||
{
|
||||
g2d.setColor (new Color (245, 245, 245)); // match background
|
||||
g2d.fillRect (0, 0, image.getWidth (), image.getHeight ());
|
||||
}
|
||||
|
||||
int ptr = 0;
|
||||
int x = borderX;
|
||||
int y = borderY;
|
||||
int count = 0;
|
||||
|
||||
while (ptr < buffer.length)
|
||||
{
|
||||
Character c = new Character (buffer, ptr);
|
||||
characters.add (c);
|
||||
ptr += charBytes;
|
||||
|
||||
g2d.drawImage (c.image, x, y, null);
|
||||
if (++count % charBytes == 0)
|
||||
{
|
||||
x = borderX;
|
||||
y += sizeY + gapY;
|
||||
}
|
||||
else
|
||||
x += sizeX + gapX;
|
||||
}
|
||||
|
||||
g2d.dispose ();
|
||||
}
|
||||
|
||||
private int dimension (int chars, int border, int size, int gap)
|
||||
{
|
||||
return border * 2 + chars * (size + gap) - gap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText ()
|
||||
{
|
||||
StringBuilder text = new StringBuilder ("Name : " + name + "\n\n");
|
||||
|
||||
for (int i = 0; i < characters.size (); i += 8)
|
||||
{
|
||||
StringBuilder line = new StringBuilder ();
|
||||
for (int j = 0; j < 8; j++)
|
||||
{
|
||||
for (int k = 0; k < 8; k++)
|
||||
{
|
||||
line.append (characters.get (i + k).lines[j]);
|
||||
line.append (" ");
|
||||
}
|
||||
line.append ("\n");
|
||||
}
|
||||
|
||||
text.append (line.toString ());
|
||||
text.append ("\n");
|
||||
}
|
||||
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
public static boolean isFont (byte[] buffer)
|
||||
@ -106,42 +28,53 @@ public class FontFile extends AbstractFile
|
||||
return true;
|
||||
}
|
||||
|
||||
class Character
|
||||
@Override
|
||||
public String getText ()
|
||||
{
|
||||
String[] lines = new String[8];
|
||||
private final BufferedImage image;
|
||||
StringBuilder text = new StringBuilder ("Name : " + name + "\n\n");
|
||||
|
||||
public Character (byte[] buffer, int ptr)
|
||||
for (int i = 0; i < buffer.length; i += sizeY)
|
||||
{
|
||||
// draw the image
|
||||
image = new BufferedImage (sizeX, sizeY, BufferedImage.TYPE_BYTE_GRAY);
|
||||
for (int line = 0; line < sizeY; line++)
|
||||
{
|
||||
int value = buffer[i + line] & 0xFF;
|
||||
for (int bit = 0; bit < sizeX; bit++)
|
||||
{
|
||||
text.append ((value & 0x01) == 0 ? "." : "X");
|
||||
value >>>= 1;
|
||||
}
|
||||
text.append ("\n");
|
||||
}
|
||||
text.append ("\n");
|
||||
}
|
||||
|
||||
return text.toString ();
|
||||
}
|
||||
|
||||
@Override
|
||||
Character createCharacter (byte[] buffer, int ptr)
|
||||
{
|
||||
return new FontFileCharacter (buffer, ptr);
|
||||
}
|
||||
|
||||
class FontFileCharacter extends Character
|
||||
{
|
||||
public FontFileCharacter (byte[] buffer, int ptr)
|
||||
{
|
||||
super (buffer, ptr);
|
||||
|
||||
DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
|
||||
int element = 0;
|
||||
|
||||
for (int i = 0; i < charBytes; i++)
|
||||
for (int i = 0; i < sizeY; i++)
|
||||
{
|
||||
int b = buffer[ptr + i] & 0xFF;
|
||||
String s = "0000000" + Integer.toString (b, 2);
|
||||
s = s.substring (s.length () - 7);
|
||||
s = s.replace ('0', ' ');
|
||||
s = s.replace ('1', 'O');
|
||||
s = new StringBuilder (s).reverse ().toString ();
|
||||
for (byte ch : s.getBytes ())
|
||||
dataBuffer.setElem (element++, ch == ' ' ? 0 : 255);
|
||||
lines[i] = s;
|
||||
int value = buffer[ptr++] & 0xFF;
|
||||
for (int j = 0; j < sizeX; j++)
|
||||
{
|
||||
dataBuffer.setElem (element++, (value & 0x01) == 0 ? 0 : 0xFF);
|
||||
value >>>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
|
||||
for (String s : lines)
|
||||
text.append (s + "\n");
|
||||
text.deleteCharAt (text.length () - 1);
|
||||
|
||||
return text.toString ();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user