[comp.sys.mac.programmer] menu font list appearing as font

dc4d+@andrew.cmu.edu (Darius Clynes) (11/10/89)

Does anyone have a sample of code which will add all the
available font resource names to a menu displayed in the font itself.
Would this require writing your own MDEF?

-Darius Clynes, Dept of Psychology, Carnegie Mellon University

oster@dewey.soe.berkeley.edu (David Phillip Oster) (11/12/89)

To have a list of font names, each name in its own font (for example the
string "New York" in the New york font.) you need your own MDEF. It isn't
worth writing though, since there are at least two commercial products
that do this for you, uniformly, at INIT time. MenuFont 2, and Font/DA
Juggler, I think, are their names.  It is much better to do this at INIT
time, since it is very slow to read in the font data, and create the
bitmaps. An INIT can pre-render all the fonts, and save them off to disk,
and only build new ones when there are changes.  If the INIT is also a
control panel device, it can gice the user a place to say that he wants to
turn the mechanism off for unusual fonts that don't contain legible
characters for their own name. Symbol is one such font, but any upper case
only font with a mixed-case name would qualify.

I've written this feature into at least two prototype products that never
saw the light of day.  If you must do it, do it as an INIT, make it work
everywhere, and compete with the other guys.

--- According to the Constitution, the Constitution is unconstitutional:
--- David Phillip Oster            --U.S.Constitution I.10.1: "No State shall
Arpa: oster@dewey.soe.berkeley.edu --enter into any treaty, alliance, or
Uucp: {uwvax,decvax}!ucbvax!oster%dewey.soe.berkeley.edu -- confederation..."

tim@hoptoad.uucp (Tim Maroney) (11/13/89)

In article <32498@ucbvax.BERKELEY.EDU> oster@dewey.soe.berkeley.edu.UUCP
(David Phillip Oster) writes:
>To have a list of font names, each name in its own font (for example the
>string "New York" in the New york font.) you need your own MDEF. It isn't
>worth writing though, since there are at least two commercial products
>that do this for you, uniformly, at INIT time. MenuFont 2, and Font/DA
>Juggler, I think, are their names.  It is much better to do this at INIT
>time, since it is very slow to read in the font data, and create the
>bitmaps. An INIT can pre-render all the fonts, and save them off to disk,
>and only build new ones when there are changes.

This is a good idea; it can't be stressed enough that you should only
do the menu rebuilding when there are changes in the available fonts,
though.  I'd hate to have to wait for an INIT to do this every time I
restarted.

I think Claris has the right idea.  All their programs with Font menus
save them in a common data structure and a common file in the system
folder, and each application comes with the necessary code to check the
font list stored in that file against the current font list, rebuild
the menu if necessary, and display and track the menu.  It would be
nice if someone would put code to do this in the public domain, or if
Apple were to include it in system software.  Probably the best way to
do it would be to use the Resource Manager to store the data
structures.  The menu itself could be stored in a PICT, and the
rectangles for each font name would be stored in an 'nrct'; a 'STR#'
would hold the alphabetized list of font names.

Here's an old PICT MDEF I wrote.  The extension to variable-sized
elements should be pretty easy.  Anyone else have useful code they
can contribute to this cause?

#define ItemHeight 16

pascal void
mdef(message, menuid, r, p, which)
short message;
short **menuid;
Rect *r;
long p;
short *which;
{
	PicHandle pic = GetPicture(**menuid);
	short new;
	Rect invert;
	Point pt;

	switch (message) {
	case 0:
		/* draw the menu */
		DrawPicture(pic, r);
		break;
	case 1:
		/* choose and hilight */
		BlockMove((Ptr)&p, (Ptr)&pt, 4);
		if (PtInRect(pt, r)) {
			/* find the item */
			new = ((pt.v - r->top) / ItemHeight) + 1;
			if (*which != new) {
				if (*which != 0) {
					/* unhighlight which */
					SetRect(&invert, r->left,
						r->top + ((*which - 1) * ItemHeight),
						r->right, r->top + (*which * ItemHeight));
					InvertRect(&invert);
				}
				/* highlight the item */
				SetRect(&invert, r->left, r->top + ((new - 1) * ItemHeight),
					r->right, r->top + (new * ItemHeight));
				InvertRect(&invert);
				*which = new;
			}
		}
		else if (*which != 0) {
			/* unhighlight which */
			SetRect(&invert, r->left, r->top + ((*which - 1) * ItemHeight),
				r->right, r->top + (*which * ItemHeight));
			InvertRect(&invert);
			*which = 0;
		}
		break;
	case 2:
		/* calculate size */
		(*menuid)[1] = (*pic)->picFrame.right - (*pic)->picFrame.left;
		(*menuid)[2] = (*pic)->picFrame.bottom - (*pic)->picFrame.top;
		break;
	}
}

>If the INIT is also a
>control panel device, it can gice the user a place to say that he wants to
>turn the mechanism off for unusual fonts that don't contain legible
>characters for their own name. Symbol is one such font, but any upper case
>only font with a mixed-case name would qualify.

Hmm.  I don't know that this rule is correct.  Might there not be symbol
fonts that were not upper-case-only?  And I confess that I'm mystified
by what the mixed-case font name has to do with it.

Also, there are some Script Manager compatibility issues here that aren't
clear to me.  Perhaps some nice person at Claris could tell us how their
applications deal with Symbol font and others of like kind, and how they
deal with the international environment.

>I've written this feature into at least two prototype products that never
>saw the light of day.  If you must do it, do it as an INIT, make it work
>everywhere, and compete with the other guys.

Yeah, well, I think the last thing we need is more INITs.  Especially
more overpriced single-function INITs.  I'd rather have someone give me
a code resource or two that I can just plug into my program and fly with.
-- 
Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com

"Now hear a plain fact: Swedenborg has not written one new truth: Now hear
  another: he has written all the old falshoods.
 And now hear the reason.  He conversed with Angels who are all religious, &
  conversed not with Devils who all hate religion..."
    - Blake, "The Marriage of Heaven and Hell"

pete@cavevax.ucsb.edu (GurgleKat) (11/13/89)

In article <32498@ucbvax.BERKELEY.EDU> oster@dewey.soe.berkeley.edu.UUCP
(David Phillip Oster) writes:
] To have a list of font names, each name in its own font (for example the
] string "New York" in the New york font.)... there are at least two
] commercial products that do this for you, uniformly, at INIT time.
] MenuFont 2, and Font/DA Juggler, I think, are their names.

Suitcase II does this, too.
--
Pete Gontier   : pete@cavevax.ucsb.edu; outgoing .UUCP cause me grief
Editor, Macker : Online Macintosh Programming Journal; mail for subscription
Hire this kid  : Mac, DOS, C, Pascal, asm, excellent communication skills

"This was it. This was what he was, who he was, his being. He forgot to eat.
 Sometimes he'd resent having to leave the deck to use the toilet..."
                                              -- William Gibson, _Neuromancer_