Mac demo support stuff.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
diff --git a/demos/mac/README b/demos/mac/README
new file mode 100644
index 0000000..9674240
--- /dev/null
+++ b/demos/mac/README
@@ -0,0 +1,22 @@
+This folder contains supporting code and CodeWarrior Pro 4 project
+files to build the FreeType demo programs ftlint and ftview for MacOS.
+
+Building
+To build these apps, you'll first need to build the FreeType library
+(see config/mac). The applications get built in the demos/bin folder.
+
+Notes
+Since the Mac doesn't have the notion of argc/argv, we'll emulate
+this: each file dropped onto the application will be translated
+to a command line argument. Both ftlint and ftview take a ppem
+value as their first command line argument: for the Mac version
+this has been hard-coded into the source. Also: the additional
+options for ftview cannot be set.
+
+Have fun with FreeType on the Mac!
+
+Just van Rossum, <just@letterror.com>
+
+DISCLAIMER: this subdirectory is *not* being maintained by the
+FreeType team, but by Just van Rossum. It's being released under
+the same terms as FreeType (see license.txt).
diff --git a/demos/mac/codewarrior/ftlint.prj b/demos/mac/codewarrior/ftlint.prj
new file mode 100644
index 0000000..a76742e
Binary files /dev/null and b/demos/mac/codewarrior/ftlint.prj differ
diff --git a/demos/mac/codewarrior/ftview.prj b/demos/mac/codewarrior/ftview.prj
new file mode 100644
index 0000000..3eedd83
Binary files /dev/null and b/demos/mac/codewarrior/ftview.prj differ
diff --git a/demos/mac/ftlint_m.c b/demos/mac/ftlint_m.c
new file mode 100644
index 0000000..258b028
--- /dev/null
+++ b/demos/mac/ftlint_m.c
@@ -0,0 +1,59 @@
+/* minimal Mac wrapper for the ftlint.c program */
+
+
+int original_main( int argc, char** argv );
+
+/* We rename the original main() program to original_main,
+ so we can provide a wrapper around it */
+#define main original_main
+#include "ftlint.c"
+#undef main
+
+
+#define PPEM "24" /* hard-code the ppem size */
+
+
+#include <SIOUX.h>
+#include "getargv.h"
+#include <Windows.h>
+#include <Dialogs.h>
+#include <Fonts.h>
+#include <TextEdit.h>
+
+static void
+init_toolbox()
+{
+ InitGraf(&qd.thePort);
+ InitFonts();
+ InitWindows();
+ TEInit();
+ InitDialogs((long)0);
+ InitMenus();
+ InitCursor();
+ SIOUXSettings.asktosaveonclose = 0;
+}
+
+int main()
+{
+ int argc, i;
+ char** argv;
+
+ init_toolbox();
+
+ /* put paths of all files dropped onto the app into argv */
+ argc = FTMac_GetArgv(&argv);
+ if (argc < 2)
+ {
+ printf("Please drop one or more font files onto the app (but quit first!)\n");
+ exit(1);
+ }
+ /* move argv[1:] to argv[2:] and fill in the ppem arg */
+ for (i = argc; i > 1; i--)
+ {
+ argv[i] = argv[i-1];
+ }
+ argc++;
+ argv[1] = PPEM;
+ /* call the original main() program */
+ original_main(argc, argv);
+}
diff --git a/demos/mac/ftview_m.c b/demos/mac/ftview_m.c
new file mode 100644
index 0000000..c4edc7e
--- /dev/null
+++ b/demos/mac/ftview_m.c
@@ -0,0 +1,59 @@
+/* minimal Mac wrapper for the ftview.c program */
+
+
+int original_main( int argc, char** argv );
+
+/* We rename the original main() program to original_main,
+ so we can provide a wrapper around it */
+#define main original_main
+#include "ftview.c"
+#undef main
+
+
+#define PPEM "24" /* hard-code the ppem size */
+
+
+#include <SIOUX.h>
+#include "getargv.h"
+#include <Windows.h>
+#include <Dialogs.h>
+#include <Fonts.h>
+#include <TextEdit.h>
+
+static void
+init_toolbox()
+{
+ InitGraf(&qd.thePort);
+ InitFonts();
+ InitWindows();
+ TEInit();
+ InitDialogs((long)0);
+ InitMenus();
+ InitCursor();
+ SIOUXSettings.asktosaveonclose = 0;
+}
+
+int main()
+{
+ int argc, i;
+ char** argv;
+
+ init_toolbox();
+
+ /* put paths of all files dropped onto the app into argv */
+ argc = FTMac_GetArgv(&argv);
+ if (argc < 2)
+ {
+ printf("Please drop one or more font files onto the app (but quit first!)\n");
+ exit(1);
+ }
+ /* move argv[1:] to argv[2:] and fill in the ppem arg */
+ for (i = argc; i > 1; i--)
+ {
+ argv[i] = argv[i-1];
+ }
+ argc++;
+ argv[1] = PPEM;
+ /* call the original main() program */
+ original_main(argc, argv);
+}
diff --git a/demos/mac/getargv.c b/demos/mac/getargv.c
new file mode 100644
index 0000000..7ff18e0
--- /dev/null
+++ b/demos/mac/getargv.c
@@ -0,0 +1,312 @@
+/***********************************************************
+Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
+The Netherlands.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the names of Stichting Mathematisch
+Centrum or CWI not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+
+STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
+THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
+FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+******************************************************************/
+
+/* Construct argc and argv for main() by using Apple Events */
+/* From Jack's implementation for STDWIN */
+
+/* Modified for use with FreeType from MacPython's macgetargv.c
+ by Just van Rossum <just@letterror.com> */
+
+#include <stdlib.h>
+#include <string.h>
+#include "getargv.h"
+
+#include <Types.h>
+#include <Files.h>
+#include <Events.h>
+#include <Processes.h>
+#include <Errors.h>
+#include <AppleEvents.h>
+#include <AEObjects.h>
+
+#ifdef GENERATINGCFM /* Defined to 0 or 1 in Universal headers */
+#define HAVE_UNIVERSAL_HEADERS
+#endif
+
+#ifndef HAVE_UNIVERSAL_HEADERS
+#define NewAEEventHandlerProc(x) (x)
+#define AEEventHandlerUPP EventHandlerProcPtr
+#endif
+
+static int arg_count;
+static char *arg_vector[256];
+static char app_name[256];
+static int app_name_inited;
+
+
+/* Duplicate a string to the heap. */
+
+static char *
+strdup(char *src)
+{
+ char *dst = malloc(strlen(src) + 1);
+ if (dst)
+ strcpy(dst, src);
+ return dst;
+}
+
+
+/* Given an FSSpec, return the FSSpec of the parent folder */
+
+static OSErr
+get_folder_parent (FSSpec * fss, FSSpec * parent)
+{
+ CInfoPBRec rec;
+ short err;
+
+ * parent = * fss;
+ rec.hFileInfo.ioNamePtr = parent->name;
+ rec.hFileInfo.ioVRefNum = parent->vRefNum;
+ rec.hFileInfo.ioDirID = parent->parID;
+ rec.hFileInfo.ioFDirIndex = -1;
+ rec.hFileInfo.ioFVersNum = 0;
+ if (err = PBGetCatInfoSync (& rec))
+ return err;
+ parent->parID = rec.dirInfo.ioDrParID;
+/* parent->name[0] = 0; */
+ return 0;
+}
+
+
+/* Given an FSSpec return a full, colon-separated pathname */
+
+static OSErr
+FTMac_GetFullPath (FSSpec *fss, char *buf)
+{
+ short err;
+ FSSpec fss_parent, fss_current;
+ char tmpbuf[256];
+ int plen;
+
+ fss_current = *fss;
+ plen = fss_current.name[0];
+ memcpy(buf, &fss_current.name[1], plen);
+ buf[plen] = 0;
+ /* Special case for disk names */
+ if ( fss_current.parID <= 1 ) {
+ buf[plen++] = ':';
+ buf[plen] = 0;
+ return 0;
+ }
+ while (fss_current.parID > 1) {
+ /* Get parent folder name */
+ if (err = get_folder_parent(&fss_current, &fss_parent))
+ return err;
+ fss_current = fss_parent;
+ /* Prepend path component just found to buf */
+ plen = fss_current.name[0];
+ if (strlen(buf) + plen + 1 > 256) {
+ /* Oops... Not enough space (shouldn't happen) */
+ *buf = 0;
+ return -1;
+ }
+ memcpy(tmpbuf, &fss_current.name[1], plen);
+ tmpbuf[plen] = ':';
+ strcpy(&tmpbuf[plen+1], buf);
+ strcpy(buf, tmpbuf);
+ }
+ return 0;
+}
+
+
+/* Initialize name of current application */
+
+static OSErr
+init_app_name()
+{
+ ProcessSerialNumber currentPSN;
+ ProcessInfoRec info;
+ OSErr err;
+ FSSpec appSpec;
+
+ if ( app_name_inited ) return 0;
+ currentPSN.highLongOfPSN = 0;
+ currentPSN.lowLongOfPSN = kCurrentProcess;
+ info.processInfoLength = sizeof(ProcessInfoRec);
+ info.processName = NULL;
+ info.processAppSpec = &appSpec;
+ if ( err=GetProcessInformation(¤tPSN, &info))
+ return err;
+ strncpy(app_name, (char*)appSpec.name + 1, appSpec.name[0]);
+ app_name[appSpec.name[0]] = '\0';
+ app_name_inited = 1;
+ return 0;
+}
+
+
+/* Check that there aren't any args remaining in the event */
+
+static OSErr
+get_missing_params(AppleEvent *theAppleEvent)
+{
+ DescType theType;
+ Size actualSize;
+ OSErr err;
+
+ err = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
+ &theType, nil, 0, &actualSize);
+ if (err == errAEDescNotFound)
+ return noErr;
+ else
+ return errAEEventNotHandled;
+}
+
+static int got_one; /* Flag that we can stop getting events */
+
+
+/* Handle the Print or Quit events (by failing) */
+
+static pascal OSErr
+handle_not(AppleEvent *theAppleEvent, AppleEvent *reply, long refCon)
+{
+ #pragma unused (reply, refCon)
+ got_one = 1;
+ return errAEEventNotHandled;
+}
+
+
+/* Handle the Open Application event (by ignoring it) */
+
+static pascal OSErr
+handle_open_app(AppleEvent *theAppleEvent, AppleEvent *reply, long refCon)
+{
+ #pragma unused (reply, refCon)
+#if 0
+ /* Test by Jack: would removing this facilitate debugging? */
+ got_one = 1;
+#endif
+ return get_missing_params(theAppleEvent);
+}
+
+
+/* Handle the Open Document event, by adding an argument */
+
+static pascal OSErr
+handle_open_doc(AppleEvent *theAppleEvent, AppleEvent *reply, long refCon)
+{
+ #pragma unused (reply, refCon)
+ OSErr err;
+ AEDescList doclist;
+ AEKeyword keywd;
+ DescType rttype;
+ long i, ndocs, size;
+ FSSpec fss;
+ char path[256];
+
+ got_one = 1;
+ if (err = AEGetParamDesc(theAppleEvent,
+ keyDirectObject, typeAEList, &doclist))
+ return err;
+ if (err = get_missing_params(theAppleEvent))
+ return err;
+ if (err = AECountItems(&doclist, &ndocs))
+ return err;
+ for(i = 1; i <= ndocs; i++) {
+ err = AEGetNthPtr(&doclist, i, typeFSS,
+ &keywd, &rttype, &fss, sizeof(fss), &size);
+ if (err)
+ break;
+ FTMac_GetFullPath(&fss, path);
+ arg_vector[arg_count++] = strdup(path);
+ }
+ return err;
+}
+
+
+/* Install standard core event handlers */
+static AEEventHandlerUPP open_doc_upp;
+static AEEventHandlerUPP open_app_upp;
+static AEEventHandlerUPP not_upp;
+
+static void
+set_ae_handlers()
+{
+ open_doc_upp = NewAEEventHandlerProc(handle_open_doc);
+ open_app_upp = NewAEEventHandlerProc(handle_open_app);
+ not_upp = NewAEEventHandlerProc(handle_not);
+
+ AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
+ open_app_upp, 0L, false);
+ AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
+ open_doc_upp, 0L, false);
+ AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
+ not_upp, 0L, false);
+ AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
+ not_upp, 0L, false);
+}
+
+/* Uninstall standard core event handlers */
+
+static void
+reset_ae_handlers()
+{
+ AERemoveEventHandler(kCoreEventClass, kAEOpenApplication,
+ open_app_upp, false);
+ AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments,
+ open_doc_upp, false);
+ AERemoveEventHandler(kCoreEventClass, kAEPrintDocuments,
+ not_upp, false);
+ AERemoveEventHandler(kCoreEventClass, kAEQuitApplication,
+ not_upp, false);
+}
+
+/* Wait for events until a core event has been handled */
+
+static void
+event_loop()
+{
+ EventRecord event;
+ int n;
+ int ok;
+
+ got_one = 0;
+ for (n = 0; n < 100 && !got_one; n++) {
+ SystemTask();
+ ok = GetNextEvent(everyEvent, &event);
+ if (ok && event.what == kHighLevelEvent) {
+ AEProcessAppleEvent(&event);
+ }
+ }
+}
+
+/* Get the argv vector, return argc. See macgetargv.h for more doco. */
+
+int
+FTMac_GetArgv(pargv)
+ char ***pargv;
+{
+
+ arg_count = 0;
+ (void)init_app_name();
+ arg_vector[arg_count++] = strdup(app_name);
+
+ set_ae_handlers();
+ event_loop();
+ reset_ae_handlers();
+
+ arg_vector[arg_count] = NULL;
+
+ *pargv = arg_vector;
+ return arg_count;
+}
diff --git a/demos/mac/getargv.h b/demos/mac/getargv.h
new file mode 100644
index 0000000..a13289d
--- /dev/null
+++ b/demos/mac/getargv.h
@@ -0,0 +1,19 @@
+/*
+ <Function>
+ FTMac_GetArgv
+
+ <Description>
+ argc/argv emulation for the Mac. Converts files dropped
+ onto the application to full paths, and stuff them into
+ argv.
+
+ <Output>
+ pargv :: a pointer to an argv array. The array doesn't need to
+ exist before calling this function.
+
+ <Return>
+ The number of files dropped onto the app (ie. argc)
+*/
+
+int FTMac_GetArgv(char ***pargv);
+
diff --git a/demos/mac/resource.hqx b/demos/mac/resource.hqx
new file mode 100644
index 0000000..cde902d
--- /dev/null
+++ b/demos/mac/resource.hqx
@@ -0,0 +1,38 @@
+(This file must be converted with BinHex 4.0)
+:$(*PFfpeFQ0P,R0TG!"6594%8dP8)3%!!!!'[!!!!!!REP0*9#%!!J!!"Vab6'&
+e!RX!!!!@EhX0!!YQG'aTER3ZFR0bB`K"ST!!!%9qHJ!!!)!!!!!!#%PXcPl2#BB
+!!!!!!!!!!!!!!!!!!!!!!!!"R`!!!!$rrrrrFR0bBe*6483"!,6HlZHdhZmk!!!
+"Q3!!!!!!!!%C!!!!!"2I!!!!!!!!!!#2I4%!#"`XG3MLeZTM1d$2c[ec0aXql5S
+ShPIL[&U,h14S@fT@KjEj-dK+IjNHBG)R-N9+9!`J2MP%TSHT%#Nd-qT*elC3-#N
+4JA)Hkc6qlRVSqDHb&A*3a9&1cdmjhEbBUHN9ad&X+`E&1ceI!Y68j0ki6qFA)(r
+b,FRGeI4f6k%5&4RNVXbJ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