Skip to content

Commit

Permalink
Update Print Shop font converter
Browse files Browse the repository at this point in the history
We now allow the conversion to be a sample string or a glyph grid,
using the same approach as the IIgs bitmap font converter.
  • Loading branch information
fadden committed Sep 2, 2024
1 parent a12b0f0 commit bba1f73
Show file tree
Hide file tree
Showing 7 changed files with 308 additions and 119 deletions.
23 changes: 22 additions & 1 deletion FileConv/ConvUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ internal static void CheckByte(int val, string name) {
}


// Strings used in import/export specs.
//
// Text conversion option handling. This is used in more than one place, so we want to
// have a single implementation here to ensure consistency.
//

public const string CHAR_MODE_ASCII = "ascii";
public const string CHAR_MODE_CP1252 = "1252";
public const string CHAR_MODE_HIGH_ASCII = "hiascii";
Expand Down Expand Up @@ -187,6 +191,23 @@ public static bool TryParseImportCharDst(string modeStr, out ImportCharDst mode)
return (mode != ImportCharDst.Unknown);
}

//
// Font conversion option handling.
//

public const string FONT_MODE_SAMPLE = "sample";
public const string FONT_MODE_GRID = "grid";
public static readonly string[] FontModeTags = new string[] {
FONT_MODE_SAMPLE, FONT_MODE_GRID
};
public static readonly string[] FontModeDescrs = new string[] {
"Sample string", "Grid of glyphs"
};
public enum FontConvMode {
Unknown = 0, Sample, Grid
}


#if false
/// <summary>
/// Determines the best value for the ProDOS file type from the available data. If no
Expand Down
26 changes: 8 additions & 18 deletions FileConv/Gfx/BitmapFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,11 @@ public class BitmapFont : Converter {

public const string OPT_MODE = "mode";

public const string MODE_GRID = "grid";
public const string MODE_SAMPLE = "sample";
public static readonly string[] ModeTags = new string[] {
MODE_SAMPLE, MODE_GRID
};
public static readonly string[] ModeDescrs = new string[] {
"Sample string", "Grid of glyphs"
};
internal enum ConvMode {
Unknown = 0, Sample, Grid
}

public override List<OptionDefinition> OptionDefs { get; protected set; } =
new List<OptionDefinition>() {
new OptionDefinition(OPT_MODE, "Conversion Mode",
OptionDefinition.OptType.Multi, MODE_SAMPLE, ModeTags, ModeDescrs),
OptionDefinition.OptType.Multi, ConvUtil.FONT_MODE_SAMPLE,
ConvUtil.FontModeTags, ConvUtil.FontModeDescrs),
};

/// <summary>
Expand All @@ -73,7 +62,7 @@ internal enum ConvMode {
ConvUtil.MakeRGB(0x80, 0x80, 0x80), // 1=dark gray (frame around cells)
ConvUtil.MakeRGB(0xff, 0xff, 0xff), // 2=white (glyph background)
ConvUtil.MakeRGB(0x00, 0x00, 0x00), // 3=black (glyph foreground)
ConvUtil.MakeRGB(0x30, 0x30, 0xe0), // 4=blue (hex labels)
ConvUtil.MakeRGB(0x30, 0x30, 0xe0), // 4=blue (labels)
ConvUtil.MakeRGB(0xb0, 0x30, 0x30), // 5=red (char not in font)
});
private const int COLOR_CELL_BG = 0;
Expand Down Expand Up @@ -394,11 +383,11 @@ public override IConvOutput ConvertFile(Dictionary<string, string> options) {
//DrawFontStrike(output, macHeader);
//return output;

string modeStr = GetStringOption(options, OPT_MODE, MODE_SAMPLE);
string modeStr = GetStringOption(options, OPT_MODE, ConvUtil.FONT_MODE_SAMPLE);
switch (modeStr) {
case MODE_GRID:
case ConvUtil.FONT_MODE_GRID:
return RenderFontGrid(gsHeader, macHeader, cellWidth, tmpNotes);
case MODE_SAMPLE:
case ConvUtil.FONT_MODE_SAMPLE:
default:
return RenderFontSample(gsHeader, macHeader, tmpNotes);
}
Expand Down Expand Up @@ -700,8 +689,9 @@ private static IConvOutput RenderFontSample(GSFontHeader gsHeader, MacFontHeader

/// <summary>
/// Draws a string with the current font. If "bitmap" is null, the string's length
/// is computed.
/// is computed without drawing anything.
/// </summary>
/// <returns>Line length, in pixels.</returns>
private static int DrawString(MacFontHeader macHeader, string str, Bitmap8? bitmap) {
SetPixelFunc setPixel = delegate (int xc, int yc, byte color) {
bitmap!.SetPixelIndex(xc, yc, COLOR_GLYPH_FG);
Expand Down
11 changes: 10 additions & 1 deletion FileConv/Gfx/PrintShop-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
File types:
- BIN / $4800/5800/6800/7800, length 572 or 576: Print Shop 88x52 Monochrome Clip Art
- BIN / $4800/5800/6800/7800, length 144 or 148: Print Shop 12x12 Monochrome Border
- BIN / $6000/5FF4, length > 576: Print Shop Font
- $f8 / $c311: Print Shop GS ?x? Monochrome Pattern
- $f8 / $c312: Print Shop GS ?x? Monochrome Border
- $f8 / $c313: Print Shop GS 88x52 Monochrome Clip Art
Expand Down Expand Up @@ -61,7 +62,7 @@ In Print Shop, offset 32 points to the current graphic selected, which is not co
file itself.

The Space character is at offset 0, and in all the examples I've seen, has a height of 0 pixels.
The data is calculated in the PSC font editor based off of an average of all other character
The width is calculated in the PSC font editor based off of an average of all other character
widths.

Character data is stored one bit per pixel, where 0 indicated background and 1 is foreground. LSB
Expand Down Expand Up @@ -93,3 +94,11 @@ but some characters are out of the expected sizes, then the acceptability should
ProbablyYes.

Like the Print Shop graphic data, fonts are expanded 2x3 in usage.

The characters map directly to ASCII $20-3a; the special entry 32 replaces '@':
``` 0 1 2 3 4 5 6 7 8 9 A B C D E F
$00 spc ! " # $ % & ' ( ) * + , - . /
$10 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
$20 img A B C D E F G H I J K L M N O
$30 P Q R S T U V W X Y Z
```
4 changes: 2 additions & 2 deletions FileConv/Gfx/PrintShopClip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class PrintShopClip : Converter {
public const string LABEL = "Print Shop Clip Art";
public const string DESCRIPTION =
"Converts a Print Shop or Print Shop GS clip art graphic file to an 88x52 bitmap. " +
"These can optionally be pixel-multiplied x2/x3 to 176x156. Monochrome and color " +
"formats are supported.";
"These can optionally be pixel-multiplied x2/x3 to 176x156, as they would when " +
"printed. Monochrome and color formats are supported.";
public const string DISCRIMINATOR =
"ProDOS $f8 / $c313 and $c323, DOS B / $x800, length 572/576 or 1716 " +
" (length may vary slightly).";
Expand Down
Loading

0 comments on commit bba1f73

Please sign in to comment.