2001-11-27 20:44:08 +03:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
2001-11-27 20:44:08 +03:00
|
|
|
//
|
|
|
|
// MacOS font utilities for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2011-03-02 17:17:34 +03:00
|
|
|
// Copyright 1998-2011 by Bill Spitzak and others.
|
2001-11-27 20:44:08 +03:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/COPYING.php
|
2001-11-27 20:44:08 +03:00
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
2001-11-27 20:44:08 +03:00
|
|
|
//
|
|
|
|
|
2004-08-25 04:20:27 +04:00
|
|
|
#include <config.h>
|
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
// #inclde <SFNTTypes.h>
|
|
|
|
|
2001-11-27 20:44:08 +03:00
|
|
|
// This function fills in the fltk font table with all the fonts that
|
|
|
|
// are found on the X server. It tries to place the fonts into families
|
|
|
|
// and to sort them so the first 4 in a family are normal, bold, italic,
|
|
|
|
// and bold italic.
|
|
|
|
|
2003-03-09 03:22:20 +03:00
|
|
|
// Bug: older versions calculated the value for *ap as a side effect of
|
|
|
|
// making the name, and then forgot about it. To avoid having to change
|
|
|
|
// the header files I decided to store this value in the last character
|
|
|
|
// of the font name array.
|
|
|
|
#define ENDOFBUFFER 127 // sizeof(Fl_Font.fontname)-1
|
|
|
|
|
2001-11-27 20:44:08 +03:00
|
|
|
// turn a stored font name into a pretty name:
|
|
|
|
const char* Fl::get_font_name(Fl_Font fnum, int* ap) {
|
2004-09-09 04:55:41 +04:00
|
|
|
Fl_Fontdesc *f = fl_fonts + fnum;
|
|
|
|
if (!f->fontname[0]) {
|
|
|
|
const char* p = f->name;
|
|
|
|
if (!p || !*p) {if (ap) *ap = 0; return "";}
|
|
|
|
strlcpy(f->fontname, p, ENDOFBUFFER);
|
|
|
|
int type = 0;
|
|
|
|
if (strstr(f->name, "Bold")) type |= FL_BOLD;
|
|
|
|
if (strstr(f->name, "Italic")) type |= FL_ITALIC;
|
|
|
|
f->fontname[ENDOFBUFFER] = (char)type;
|
|
|
|
}
|
|
|
|
if (ap) *ap = f->fontname[ENDOFBUFFER];
|
|
|
|
return f->fontname;
|
2001-11-27 20:44:08 +03:00
|
|
|
}
|
|
|
|
|
2011-02-20 01:29:39 +03:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
|
|
|
static int name_compare(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
return strcmp(*(char**)a, *(char**)b);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-11-27 20:44:08 +03:00
|
|
|
static int fl_free_font = FL_FREE_FONT;
|
2001-12-18 07:58:43 +03:00
|
|
|
|
2001-11-27 20:44:08 +03:00
|
|
|
Fl_Font Fl::set_fonts(const char* xstarname) {
|
|
|
|
#pragma unused ( xstarname )
|
2010-08-20 17:07:13 +04:00
|
|
|
if (fl_free_font > FL_FREE_FONT) return (Fl_Font)fl_free_font; // if already called
|
|
|
|
|
2010-03-29 14:35:00 +04:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
2011-03-04 19:48:10 +03:00
|
|
|
if(fl_mac_os_version >= 100500) {
|
2010-01-24 11:48:35 +03:00
|
|
|
//if(CTFontCreateWithFontDescriptor != NULL) {// CTFontCreateWithFontDescriptor != NULL on 10.4 also!
|
2009-12-07 01:21:55 +03:00
|
|
|
int value[1] = {1};
|
2010-01-24 11:48:35 +03:00
|
|
|
CFDictionaryRef dict = CFDictionaryCreate(NULL,
|
|
|
|
(const void **)kCTFontCollectionRemoveDuplicatesOption,
|
|
|
|
(const void **)&value, 1, NULL, NULL);
|
2009-12-07 01:21:55 +03:00
|
|
|
CTFontCollectionRef fcref = CTFontCollectionCreateFromAvailableFonts(dict);
|
|
|
|
CFRelease(dict);
|
|
|
|
CFArrayRef arrayref = CTFontCollectionCreateMatchingFontDescriptors(fcref);
|
|
|
|
CFRelease(fcref);
|
|
|
|
CFIndex count = CFArrayGetCount(arrayref);
|
|
|
|
CFIndex i;
|
2011-02-20 11:02:50 +03:00
|
|
|
char **tabfontnames = new char*[count];
|
2009-12-07 01:21:55 +03:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
CTFontDescriptorRef fdesc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(arrayref, i);
|
|
|
|
CTFontRef font = CTFontCreateWithFontDescriptor(fdesc, 0., NULL);
|
2011-02-20 11:25:26 +03:00
|
|
|
CFStringRef cfname = CTFontCopyFullName(font);
|
2009-12-07 01:21:55 +03:00
|
|
|
CFRelease(font);
|
|
|
|
static char fname[100];
|
|
|
|
CFStringGetCString(cfname, fname, sizeof(fname), kCFStringEncodingUTF8);
|
2011-02-20 01:29:39 +03:00
|
|
|
tabfontnames[i] = strdup(fname); // never free'ed
|
2009-12-07 01:21:55 +03:00
|
|
|
CFRelease(cfname);
|
|
|
|
}
|
|
|
|
CFRelease(arrayref);
|
2011-02-20 01:29:39 +03:00
|
|
|
qsort(tabfontnames, count, sizeof(char*), name_compare);
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
Fl::set_font((Fl_Font)(fl_free_font++), tabfontnames[i]);
|
|
|
|
}
|
2011-02-20 11:02:50 +03:00
|
|
|
delete[] tabfontnames;
|
2009-12-07 01:21:55 +03:00
|
|
|
return (Fl_Font)fl_free_font;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#endif
|
|
|
|
#if ! __LP64__
|
2008-09-11 03:56:49 +04:00
|
|
|
ItemCount oFontCount, oCountAgain;
|
|
|
|
ATSUFontID *oFontIDs;
|
|
|
|
// How many fonts?
|
|
|
|
ATSUFontCount (&oFontCount);
|
|
|
|
// now allocate space for them...
|
|
|
|
oFontIDs = (ATSUFontID *)malloc((oFontCount+1) * sizeof(ATSUFontID));
|
|
|
|
ATSUGetFontIDs (oFontIDs, oFontCount, &oCountAgain);
|
|
|
|
// Now oFontIDs should contain a list of all the available Unicode fonts
|
|
|
|
// Iterate through the list to get each font name
|
|
|
|
for (ItemCount idx = 0; idx < oFontCount; idx++)
|
|
|
|
{
|
|
|
|
// ByteCount actualLength = 0;
|
|
|
|
// Ptr oName;
|
|
|
|
// How to get the name - Apples docs say call this twice, once to get the length, then again
|
|
|
|
// to get the actual name...
|
|
|
|
// ATSUFindFontName (oFontIDs[idx], kFontFullName, kFontMacintoshPlatform, kFontRomanScript, kFontEnglishLanguage,
|
|
|
|
// 0, NULL, &actualLength, NULL);
|
|
|
|
// Now actualLength tells us the length of buffer we need
|
|
|
|
// oName = (Ptr)malloc(actualLength + 8);
|
|
|
|
// But who's got time for that nonsense? Let's just hard code a fixed buffer (urgh!)
|
|
|
|
ByteCount actualLength = 511;
|
|
|
|
char oName[512];
|
|
|
|
ATSUFindFontName (oFontIDs[idx], kFontFullName, kFontMacintoshPlatform, kFontRomanScript, kFontEnglishLanguage,
|
|
|
|
actualLength, oName, &actualLength, &oCountAgain);
|
|
|
|
// bounds check and terminate the returned name
|
|
|
|
if(actualLength > 511)
|
|
|
|
oName[511] = 0;
|
|
|
|
else
|
|
|
|
oName[actualLength] = 0;
|
|
|
|
Fl::set_font((Fl_Font)(fl_free_font++), strdup(oName));
|
|
|
|
// free(oName);
|
|
|
|
}
|
|
|
|
free(oFontIDs);
|
|
|
|
return (Fl_Font)fl_free_font;
|
2009-12-07 01:21:55 +03:00
|
|
|
#endif //__LP64__
|
2010-03-29 14:35:00 +04:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
2009-12-07 01:21:55 +03:00
|
|
|
}
|
2004-09-09 04:55:41 +04:00
|
|
|
#endif
|
2010-11-25 21:21:21 +03:00
|
|
|
return 0;
|
2001-11-27 20:44:08 +03:00
|
|
|
}
|
|
|
|
|
2001-12-18 07:58:43 +03:00
|
|
|
static int array[128];
|
2001-11-27 20:44:08 +03:00
|
|
|
int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) {
|
2001-12-18 07:58:43 +03:00
|
|
|
Fl_Fontdesc *s = fl_fonts+fnum;
|
|
|
|
if (!s->name) s = fl_fonts; // empty slot in table, use entry 0
|
2004-09-09 04:55:41 +04:00
|
|
|
int cnt = 0;
|
2001-12-18 07:58:43 +03:00
|
|
|
|
2004-09-09 04:55:41 +04:00
|
|
|
// ATS supports all font size
|
|
|
|
array[0] = 0;
|
|
|
|
sizep = array;
|
|
|
|
cnt = 1;
|
2001-12-18 07:58:43 +03:00
|
|
|
|
|
|
|
return cnt;
|
2001-11-27 20:44:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
2001-11-27 20:44:08 +03:00
|
|
|
//
|