Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ let package = Package(
// QuickDraw's C functions over Graphite2D, one `@c @implementation` each.
.target(
name: "GraphiteQuickDrawABI",
dependencies: ["CQuickDraw", "GraphiteCore", "Graphite2D"]
dependencies: ["CQuickDraw", "GraphiteCore", "Graphite2D", "GraphiteText"]
),
.target(
name: "GraphiteText",
Expand Down Expand Up @@ -249,6 +249,6 @@ let package = Package(
.testTarget(name: "GraphiteEventsTests", dependencies: ["GraphiteEvents"]),
.testTarget(name: "GraphiteMemoryTests", dependencies: ["GraphiteMemory"]),
.testTarget(name: "GraphiteMixedModeTests", dependencies: ["GraphiteMixedMode", "GraphiteMemory"]),
.testTarget(name: "GraphiteQuickDrawABITests", dependencies: ["GraphiteQuickDrawABI", "CQuickDraw"])
.testTarget(name: "GraphiteQuickDrawABITests", dependencies: ["GraphiteQuickDrawABI", "CQuickDraw", "GraphiteCore", "GraphiteText"])
]
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Any UI it shows will be drawn with [Cacao](https://github.com/PureSwift/Cacao).
| `GraphiteResources` | The Resource Manager: resource maps read with every offset checked and written back, resource files changed in memory and updated, the chain of open files with `Get` and `Get1` searches, and `STR#`, `STR ` and `vers` resources. |
| `GraphiteAutomation` | The Apple Event Manager: descriptors, lists, records and Apple events as values; coercions between text, numbers, booleans, codes, lists, records and file types (`furl`, `fss `, `alis`, and the host's), with installed handlers; the application's handlers by class and ID with wildcards; events sent to itself, and the required events. |
| `Graphite2D` | QuickDraw's pixels (1 to 8 bits indexed, 16 and 32 bits direct, big-endian on every CPU, in memory of its own or a program's), colors and the system's color tables, regions as real regions with QuickDraw's region records, patterns, transfer modes, ports, devices and offscreen worlds; drawing rectangles, ovals, round rectangles, arcs, polygons, regions and lines with the pen, and CopyBits, CopyMask and ScrollRect between any depths; PICT pictures, version 1 and 2, with PackBits and QuickTime-compressed images through a decoder the host gives. |
| `GraphiteText` | Fonts: faces and their metrics, the Font Manager's family numbers and names with the classic fonts' and their substitutes, a built-in bitmap system font (from Pomme), and QuickDraw's text in a port's font, face, size and mode, with the styles a face hasn't drawn from its plain glyphs; ATSUI-style layouts with styled runs, line breaking, measuring, hit testing and drawing, and the text in PICT pictures; and, with the `FreeType` trait (on by default), faces from TrueType, OpenType and other outline fonts, found by family name in the system's font folders. |
| `GraphiteText` | Fonts: faces and their metrics, the Font Manager's family numbers and names with the classic fonts' and their substitutes, a built-in bitmap system font (from Pomme) and `NFNT` bitmap fonts, and QuickDraw's text in a port's font, face, size and mode, with the styles a face hasn't drawn from its plain glyphs as Mac OS 9.2.2 drew them; ATSUI-style layouts with styled runs, line breaking, measuring, hit testing and drawing, and the text in PICT pictures; and, with the `FreeType` trait (on by default), faces from TrueType, OpenType and other outline fonts, found by family name in the system's font folders. |
| `GraphiteSound` | The Sound Manager: sampled sounds from `'snd '` resources (formats 1 and 2, with the standard, compressed and extended headers) and AIFF and AIFF-C files, read to 16-bit PCM; the µ-law, A-law and IMA4 codecs (MACE is recognized but not decoded yet); sound channels with queued commands (`SndDoCommand`) including `callBackCmd`, `waitCmd` and `syncCmd`, immediate ones, volume, pan, pitch, loops and completion; a mixer that renders them to stereo float frames, for an audio device the host provides; and the frequencies of MIDI notes. |
| `GraphiteWindows` | The Window Manager: windows of every class, from documents, dialogs and alerts to palettes, sheets and drawers, each with the standard Mac OS 8 and 9 frame or a window definition the host brings (the WDEF); the window list ordered by layer, `FrontWindow`, and the active document and the active palette; `FindWindow` and every part of a frame; showing, hiding, selecting, zooming between the user and standard states, collapsing; `MoveWindow`, `SizeWindow` and `SetWindowBounds`, with centering, cascading and the alert position; each window's content in an offscreen buffer with its visible region — what no window in front covers — its update region with `BeginUpdate` and `EndUpdate`, and the part of it the host is told to flush. |
| `GraphiteMenus` | The Menu Manager: menus and their items — text in MacRoman, marks (the check mark and the diamond), icons, styles, keyboard equivalents with their modifiers, submenus by menu ID, command IDs — built with `AppendMenu`'s metacharacter strings or item by item; checked, enabled and disabled; the menu bar with `InsertMenu`'s order and its hierarchical list, `GetMenuHandle`, `MenuKey` and `EnableMenuCommand`; menu definitions (the MDEF) with the standard definition's sizes and item geometry; and `'MENU'` resources read with every field as the classic kept it, enable flags and submenus included. |
Expand Down
1 change: 1 addition & 0 deletions ReferenceTests/Retro68/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ add_application(AppleEventParamsCapture AppleEventParamsCapture.c)
add_application(QuickDrawDrawingCapture QuickDrawDrawingCapture.c)
add_application(PolygonCapture PolygonCapture.c)
add_application(CopyBitsCapture CopyBitsCapture.c)
add_application(TextCapture TextCapture.c TextCapture.r)
37 changes: 37 additions & 0 deletions ReferenceTests/Retro68/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -668,3 +668,40 @@ Mac OS 9.2.2 in UTM. It writes `CopyBits.txt`, kept here as
`CopyBitsCaptureTests` makes the probe's calls through libQuickDraw and
compares every line. The two with a source outside its bitmap differ: Graphite
leaves the destination there.

## Text

`TextCapture.c` records `GetFontInfo`, `CharWidth`, `StringWidth`, `TextWidth`
and `MeasureText`, and what `DrawChar`, `DrawString` and `DrawText` draw: every
style, the text modes, `SpaceExtra`, `CharExtra` and sizes the font has not. It
draws in a font of its own, `GraphiteProbe`, a `FOND` and a 12 point `NFNT` in
`TextCapture.r`, so none of Apple's fonts is needed to draw the same again. It
ran from the Finder on Mac OS 9.2.2 in UTM. It writes `Text.txt`, kept here as
`Text-macos-9.2.2-ppc.txt` (CR line endings).

- Bold drew the glyphs twice a pixel apart; italic moved a row a pixel right
for every two above the baseline, rounding down below it. Bold, extend and
outline widened a character by a pixel, shadow by two, outline with shadow by
three, and condense narrowed it by one. Italic and underline widened nothing,
and `GetFontInfo`'s `widMax` followed the same sums.
- Underline was a row below the baseline, left out beside the pixels of
descenders, before and after the italic slant; with outline or shadow it
started a pixel left of the pen.
- Outline and shadow surrounded the glyphs by one pixel up and left and one,
two or three down and right, and left the glyphs themselves white.
- A character the font lacks drew its missing symbol; a carriage return had no
width.
- `srcCopy` and the `not` modes drew the whole cell, from the pen over the
advance, or as far as the last glyph reached past it.
- `SpaceExtra` was summed in fixed point: widths dropped the fraction, and
drawing started from half a pixel. `CharExtra` did nothing in a `GrafPort`.
- A size the font lacked was the 12 point strike, styled first, stretched by
the ratio of the sizes in 16.16 fixed point, as `CopyBits` stretches.
Metrics rounded halves up; widths dropped the fraction.
- The pen's pattern, mode and size and the background pattern did nothing; a
hidden pen drew nothing and moved all the same; an open region recorded
nothing.

`TextCaptureTests` makes the probe's calls through libQuickDraw and compares
every line. Three differ: a pixel at the right edge of bold condensed text, and
a few pixels of the two pictures shrunk to 9 points.
1 change: 1 addition & 0 deletions ReferenceTests/Retro68/Text-macos-9.2.2-ppc.txt

Large diffs are not rendered by default.

282 changes: 282 additions & 0 deletions ReferenceTests/Retro68/TextCapture.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
/*
* Captures QuickDraw's text: what GetFontInfo, CharWidth, StringWidth,
* TextWidth and MeasureText give, and what DrawChar, DrawString and DrawText
* draw, in every style, in the text modes, with SpaceExtra and CharExtra, and
* at sizes the font has not. The font is the probe's own, in TextCapture.r.
* It writes "Text.txt" next to itself and refuses to run if that file is
* already there. The file is flushed after every line, so a call that crashes
* leaves the lines before it.
*
* Everything is drawn in a port of the probe's own over its own 96 by 32
* bitmap, never the screen. A picture's line gives the bitmap's 32 rows, each
* 24 hex digits, the high bit leftmost. The pen starts at h 8, v 16.
*/
#include <Quickdraw.h>
#include <Fonts.h>
#include <MacMemory.h>
#include <Files.h>
#include <stdio.h>
#include <string.h>

#define ROW 12

static short out;
static short family;
static GrafPort port;
static unsigned char pixels[ROW * 32];

static const Pattern half = { { 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55 } };

static void line(const char *text)
{
long count = strlen(text);
FSWrite(out, &count, text);
count = 1;
FSWrite(out, &count, "\r");
FlushVol(0, 0);
}

static void plain(void)
{
Rect box = { 0, 0, 32, 96 };
BitMap bits;
memset(pixels, 0, sizeof pixels);
InitPort(&port);
bits.baseAddr = (Ptr)pixels;
bits.rowBytes = ROW;
bits.bounds = box;
SetPortBits(&bits);
port.portRect = box;
RectRgn(port.visRgn, &box);
TextFont(family);
TextSize(12);
MoveTo(8, 16);
}

/* The picture, and where the pen ended. */
static void picture(const char *label)
{
char text[1000];
int used, row, i;
used = sprintf(text, "%s -> pen (%d,%d)", label, port.pnLoc.v, port.pnLoc.h);
for (row = 0; row < 32; row++) {
used += sprintf(text + used, " ");
for (i = 0; i < ROW; i++)
used += sprintf(text + used, "%02X", pixels[row * ROW + i]);
}
line(text);
}

static void number(const char *label, long value)
{
char text[200];
sprintf(text, "%s -> %ld", label, value);
line(text);
}

static void info(const char *label)
{
FontInfo f;
char text[200];
GetFontInfo(&f);
sprintf(text, "%s -> ascent %d, descent %d, widMax %d, leading %d",
label, f.ascent, f.descent, f.widMax, f.leading);
line(text);
}

static const struct { const char *name; short face; } faces[] = {
{ "plain", 0 }, { "bold", 1 }, { "italic", 2 }, { "underline", 4 },
{ "outline", 8 }, { "shadow", 16 }, { "condense", 32 }, { "extend", 64 },
{ "bold italic", 3 }, { "bold underline", 5 }, { "bold outline", 9 },
{ "outline shadow", 24 }, { "italic shadow", 18 }, { "italic underline", 6 },
{ "underline shadow", 20 }, { "bold condense", 33 }, { "condense extend", 96 },
{ "all", 127 },
};
#define FACES ((int)(sizeof faces / sizeof faces[0]))

static const unsigned char sample[] = "\pAfgj Wai.";
static const unsigned char pair[] = "\pgaf";

static void measures(const char *label)
{
char text[400];
short locations[16];
int used, i;
sprintf(text, "StringWidth, %s", label);
number(text, StringWidth(sample));
memset(locations, 0, sizeof locations);
MeasureText(sample[0], (Ptr)(sample + 1), (Ptr)locations);
used = sprintf(text, "MeasureText, %s ->", label);
for (i = 0; i <= sample[0]; i++) used += sprintf(text + used, " %d", locations[i]);
line(text);
}

static void metrics(void)
{
static const char codes[] = { ' ', '.', 'A', 'B', 'W', 'a', 'f', 'g', 'i', 'j', 'Z', '~', '\r', '\t', 0 };
static const short sizes[] = { 12, 24, 18, 9, 6, 36, 13, 0 };
char label[80];
int i, f;

plain();
number("GetFNum", family);
for (f = 0; f < FACES; f++) {
plain(); TextFace(faces[f].face);
sprintf(label, "GetFontInfo, %s", faces[f].name); info(label);
measures(faces[f].name);
sprintf(label, "CharWidth of A, %s", faces[f].name); number(label, CharWidth('A'));
sprintf(label, "CharWidth of space, %s", faces[f].name); number(label, CharWidth(' '));
}

plain();
for (i = 0; i < (int)sizeof codes; i++) {
sprintf(label, "CharWidth %d", (unsigned char)codes[i]);
number(label, CharWidth((unsigned char)codes[i]));
}
number("CharWidth 200", CharWidth(200));
number("TextWidth from 0 for 0", TextWidth((Ptr)(sample + 1), 0, 0));
number("TextWidth from 2 for 4", TextWidth((Ptr)(sample + 1), 2, 4));

for (i = 0; i < (int)(sizeof sizes / sizeof sizes[0]); i++) {
plain(); TextSize(sizes[i]);
sprintf(label, "GetFontInfo at %d", sizes[i]); info(label);
sprintf(label, "at %d", sizes[i]); measures(label);
TextFace(1);
sprintf(label, "bold at %d", sizes[i]); measures(label);
}

plain(); SpaceExtra(0x00028000);
number("StringWidth of one space, spExtra 2.5", StringWidth("\p "));
number("StringWidth of two spaces, spExtra 2.5", StringWidth("\p "));
number("StringWidth of three spaces, spExtra 2.5", StringWidth("\p "));
measures("spExtra 2.5");
plain(); SpaceExtra(0x00004000);
number("StringWidth of A space A space A, spExtra 0.25", StringWidth("\pA A A"));
number("StringWidth of five spaces, spExtra 0.25", StringWidth("\p "));
plain(); SpaceExtra(-0x00018000);
number("StringWidth of three spaces, spExtra -1.5", StringWidth("\p "));
plain(); CharExtra(0x00030000);
number("StringWidth with CharExtra 3 in a GrafPort", StringWidth(sample));
}

static void pen(void)
{
plain(); DrawChar('A'); picture("DrawChar A");
plain(); DrawChar('Z'); picture("DrawChar of a missing character");
plain(); DrawString(sample); picture("DrawString");
plain(); DrawString("\pBZ~a"); picture("DrawString with missing characters");
plain(); DrawText((Ptr)(sample + 1), 2, 4); picture("DrawText from 2 for 4");
plain(); DrawString("\p"); picture("DrawString of nothing");
plain(); MoveTo(0, 16); DrawString("\pjfA"); picture("DrawString overhanging the left edge");
plain(); MoveTo(90, 16); DrawString("\pAW"); picture("DrawString past the right edge");
}

static void styles(void)
{
char label[80];
int f;
for (f = 0; f < FACES; f++) {
plain(); TextFace(faces[f].face); DrawString(sample);
sprintf(label, "style %s", faces[f].name); picture(label);
plain(); TextFace(faces[f].face); DrawString(pair);
sprintf(label, "style %s, short", faces[f].name); picture(label);
}
}

/* Vertical stripes four pixels wide, to see what a mode does over ink. */
static void stripes(void)
{
int row, i;
for (row = 0; row < 32; row++)
for (i = 0; i < ROW; i++) pixels[row * ROW + i] = 0xF0;
}

static void modes(void)
{
static const struct { const char *name; short mode; } list[] = {
{ "srcCopy", srcCopy }, { "srcOr", srcOr }, { "srcXor", srcXor }, { "srcBic", srcBic },
{ "notSrcCopy", notSrcCopy }, { "notSrcOr", notSrcOr }, { "notSrcXor", notSrcXor }, { "notSrcBic", notSrcBic },
};
char label[80];
int m;
for (m = 0; m < 8; m++) {
plain(); stripes(); TextMode(list[m].mode); DrawString(pair);
sprintf(label, "mode %s", list[m].name); picture(label);
plain(); stripes(); TextMode(list[m].mode); TextFace(4); DrawString(pair);
sprintf(label, "mode %s, underline", list[m].name); picture(label);
}
plain(); stripes(); TextMode(srcCopy); TextFace(2); DrawString(pair); picture("mode srcCopy, italic");
plain(); stripes(); TextMode(srcCopy); TextFace(16); DrawString(pair); picture("mode srcCopy, shadow");
plain(); stripes(); TextMode(srcXor); TextFace(8); DrawString(pair); picture("mode srcXor, outline");
}

static void state(void)
{
plain(); ForeColor(whiteColor); stripes(); DrawString(pair); picture("fore color white");
plain(); ForeColor(redColor); DrawString(pair); picture("fore color red");
plain(); BackColor(blackColor); TextMode(srcCopy); DrawString(pair); picture("back color black, srcCopy");
plain(); BackPat(&half); TextMode(srcCopy); DrawString(pair); picture("back pattern, srcCopy");
plain(); PenPat(&half); PenMode(patXor); PenSize(3, 3); DrawString(pair); picture("pen pattern, mode and size");
plain(); HidePen(); DrawString(pair); ShowPen(); picture("pen hidden");
plain();
{
Rect clip = { 10, 10, 18, 18 };
ClipRect(&clip);
DrawString(sample);
}
picture("clipped");
plain(); SetOrigin(4, 2); MoveTo(12, 18); DrawString(pair); picture("origin 4,2");
plain(); SpaceExtra(0x00028000); DrawString("\pa a a"); picture("spExtra 2.5");
plain(); SpaceExtra(0x00028000); TextFace(4); DrawString("\pa a a"); picture("spExtra 2.5, underline");
plain(); SpaceExtra(0x00004000); DrawString("\p. . . . ."); picture("spExtra 0.25");
plain(); TextFace(4); DrawString("\pA g j"); picture("underline over spaces and descenders");
plain(); TextFace(4); DrawChar('g'); DrawChar('a'); picture("underline, two DrawChars");
plain(); TextFace(2); DrawChar('A'); DrawChar('W'); picture("italic, two DrawChars");
plain();
{
RgnHandle rgn = NewRgn();
OpenRgn();
DrawString(pair);
CloseRgn(rgn);
number("size of the region of a DrawString", (**rgn).rgnSize);
picture("DrawString in an open region");
DisposeRgn(rgn);
}
}

static void scaled(void)
{
static const short sizes[] = { 24, 18, 9, 6 };
char label[80];
int i;
for (i = 0; i < 4; i++) {
plain(); TextSize(sizes[i]); MoveTo(8, 22); DrawString(pair);
sprintf(label, "size %d", sizes[i]); picture(label);
plain(); TextSize(sizes[i]); TextFace(1); MoveTo(8, 22); DrawString(pair);
sprintf(label, "size %d, bold", sizes[i]); picture(label);
}
}

int main(void)
{
static const unsigned char name[] = "\pText.txt";

InitGraf(&qd.thePort);
InitFonts();
if (Create(name, 0, 'Grph', 'TEXT') != noErr) return 1;
if (FSOpen(name, 0, &out) != noErr) return 2;
OpenPort(&port);
GetFNum("\pGraphiteProbe", &family);

metrics();
pen();
styles();
modes();
state();
scaled();

line("done");
FSClose(out);
FlushVol(0, 0);
return 0;
}
Loading
Loading