Пример #1
0
void wxMGLFontLibrary::IncRef()
{
    wxLogTrace("mgl_font", "incRef(%u) '%s'", m_refs, m_fileName.c_str());
    if ( m_refs++ == 0 )
    {
        wxLogTrace("mgl_font", "opening library '%s'", m_fileName.mb_str());
        m_fontLib = MGL_openFontLib(m_fileName.mb_str());
    }
}
Пример #2
0
void wxFontFace::Acquire()
{
    wxFontFaceBase::Acquire();

    if ( m_refCnt == 1 )
    {
        wxCHECK_RET( m_fontLib == NULL, wxT("font lib already created") );

        wxLogTrace("mgl_font", "opening library '%s'", m_fileName.mb_str());
        m_fontLib = MGL_openFontLib(m_fileName.fn_str());
    }
}
Пример #3
0
ibool textLibDump(MGLDC *dc)
/****************************************************************************
*
* Function:     textDump
* Parameters:   dc  - Device context
*
* Description:  Displays all the characters in each of the fonts in
*               the distribution.
*
****************************************************************************/
{
	int         i,j,maxx,pointSize = 18;
	font_t      *font;
	font_lib_t  *fontLib;
	char        buf[80];

	mainWindow(dc,"Loading font...");
	maxx = MGL_maxx();
	for (i = 0; i < NUM_FontLibS; i++) {   /* For each available font      */
		/* Attempt to load the font file from disk. If it cannot be
		 * found, then go onto the next one.
		 */
		strcpy(buf,FontLibname[i]);
		if ((fontLib = MGL_openFontLib(buf)) == NULL)
			continue;
		if ((font = MGL_loadFontInstance(fontLib,pointSize,0,0,false)) == NULL) {
			MGL_closeFontLib(fontLib);
			continue;
			}
		switch (fontLib->fontLibType) {
			case MGL_BITMAPFONT_LIB:
				sprintf(buf,"Bitmap Font Library: %s - %d Point", fontLib->name, font->pointSize);
				break;
			case MGL_TRUETYPEFONT_LIB:
				sprintf(buf,"TrueType Font Library: %s - %d Point", fontLib->name, font->pointSize);
				break;
			case MGL_TYPE1FONT_LIB:
				sprintf(buf,"Type1 Font Library: %s - %d Point", fontLib->name, font->pointSize);
				break;
			}
		mainWindow(dc,buf);

		/* Display all characters on the screen */
		MGL_useFont(font);
		buf[1] = '\0';
		for (j = ' '; j < 256; j++) {
			buf[0] = j;
			MGL_drawStr(buf);
			if (MGL_getX() + MGL_maxCharWidth() > maxx) {
				MGL_moveToCoord(0,MGL_getY() + MGL_textHeight());
				}
			}

		/* Unload the font from memory */
		MGL_useFont(defFont);
		MGL_unloadFont(font);
		MGL_closeFontLib(fontLib);
		if (!pause())
			return false;
		mainWindow(dc,"Loading font...");
		}
	defaultAttributes(dc);
	return true;
}
Пример #4
0
ibool textDir(MGLDC *dc)
/****************************************************************************
*
* Function:     textDir
* Parameters:   dc  - Device context
*
* Description:  Display text in varying directions on the screen.
*
****************************************************************************/
{
	int         maxx,maxy;
	int         horiz,vert;
	char        *str;
	font_t      *font = NULL;
	font_lib_t  *fontLib;
	char        buf[80];

	maxx = MGL_maxx();
	maxy = MGL_maxy();

	strcpy(buf,FontLibname[0]);
	if ((fontLib = MGL_openFontLib(buf)) == NULL)
		return FALSE;
	if ((font = MGL_loadFontInstance(fontLib,40,0,0,false)) == NULL) {
		MGL_closeFontLib(fontLib);
		return FALSE;
		}

	sprintf(buf,"Character set (%s)", font->name);
	mainWindow(dc,buf);

	MGL_useFont(font);
	for (horiz = MGL_LEFT_TEXT; horiz <= MGL_RIGHT_TEXT; horiz++)
		for (vert = MGL_TOP_TEXT; vert <= MGL_BASELINE_TEXT; vert++) {
			MGL_clearDevice();
			MGL_setColor(MGL_RED);
			MGL_lineCoord(0,maxy/2,maxx,maxy/2);
			MGL_lineCoord(maxx/2,0,maxx/2,maxy);
			MGL_setTextJustify(MGL_LEFT_TEXT,MGL_TOP_TEXT);
			MGL_setTextDirection(MGL_RIGHT_DIR);
			MGL_setColor(MGL_GREEN);
			MGL_moveToCoord(0,0);
			MGL_drawStr("horiz: ");
			switch (horiz) {
				case MGL_LEFT_TEXT:
					str = "LEFT";
					break;
				case MGL_CENTER_TEXT:
					str = "CENTER";
					break;
				case MGL_RIGHT_TEXT:
					str = "RIGHT";
					break;
				default:
					str = "UNKNOWN";
				}
			MGL_drawStr(str);
			MGL_moveToCoord(0,MGL_textHeight());
			MGL_drawStr("vert:  ");
			switch (vert) {
				case MGL_TOP_TEXT:
					str = "TOP";
					break;
				case MGL_CENTER_TEXT:
					str = "CENTER";
					break;
				case MGL_BOTTOM_TEXT:
					str = "BOTTOM";
					break;
				case MGL_BASELINE_TEXT:
					str = "BASELINE";
					break;
				default:
					str = "UNKNOWN";
				}
			MGL_drawStr(str);
			MGL_makeCurrentDC(dc);

			MGL_setTextJustify(horiz,vert);
			MGL_useFont(font);

			MGL_setColor(MGL_BLUE);
			MGL_lineCoord(0,maxy/2+MGL_textHeight()-1,maxx,maxy/2+MGL_textHeight()-1);
			MGL_lineCoord(maxx/2+MGL_textHeight()-1,0,maxx/2+MGL_textHeight()-1,maxy);

			MGL_setColor(MGL_WHITE);
			MGL_setTextDirection(MGL_LEFT_DIR);
			MGL_drawStrXY(maxx/2,maxy/2,"This text goes left");

			MGL_setTextDirection(MGL_DOWN_DIR);
			MGL_drawStrXY(maxx/2,maxy/2,"This text goes down");

			MGL_setTextDirection(MGL_UP_DIR);
			MGL_drawStrXY(maxx/2,maxy/2,"This text goes up");

			MGL_setTextDirection(MGL_RIGHT_DIR);
			MGL_drawStrXY(maxx/2,maxy/2,"This text goes right");
			if (!pause())
				break;
			}

	/* Unload the font from memory */
	MGL_useFont(defFont);
	MGL_unloadFont(font);
	MGL_closeFontLib(fontLib);
	defaultAttributes(dc);
	return true;
}
Пример #5
0
/****************************************************************************
PARAMETERS:
path        - directory with font file
filename    - filename of the font file
cache       - local cache for one directory

REMARKS:
Updates cache entry for given font file. If such file is not in the
cache, loads it with MGL_openFontLib and extracts information about font
library type, family and face from it.

A font is marked as bold if its name ends with " Bold", as italic if it ends
with " Italic". Suffixes are cumulative. Family name is face name with
recognized suffixes stripped off. For example, cache entry for font
"Arial Bold Italic" will read "family is Arial, face is bold and italic".
{secret}
****************************************************************************/
static void enumFontFile(
    const char *path,
    const char *filename,
    dirCache *cache)
{
    char          fullname[PM_MAX_PATH];
    font_lib_t    *fontLib;
    fileCache     *entry;
    ibool         isNewer;
    ibool         foundSuffix;
#if 0 // TODO: missing PM_getFileTime under Unix and DOS
    PM_time       time;
    long          ytimef, ytimec;
#endif
    char          *buf;
    size_t        buflen;

    strcpy(fullname, path);
    PM_backslash(fullname);
    strcat(fullname, filename);

    /* Try to find entry in cache: */
    entry = (fileCache*) bsearch(filename, cache->files, cache->filesCnt,
                                    sizeof(fileCache), searchFileCache);

    isNewer = (entry == NULL);

#if 0 // TODO: missing PM_getFileTime under Unix and DOS
    if (!isNewer && PM_getFileTime(fullname, true, &time)) {
        ytimef = time.sec + 60 * (time.min + 60 * (time.hour + 24 * (time.day +
                    31 * time.mon)));
        ytimec = cache->timestamp.sec + 60 * (cache->timestamp.min + 60 * (
                    cache->timestamp.hour + 24 * (cache->timestamp.day +
                    31 * cache->timestamp.mon)));
        isNewer = time.year > cache->timestamp.year ||
                    (time.year == cache->timestamp.year && ytimef > ytimec);
        }
#endif

    if (!isNewer) {
        cache->validCnt++;
        entry->exists = true;
        return;
        }

    /* Nothing in cache, we have to open the font: */
    fontLib = MGL_openFontLib(fullname);
    if (fontLib == NULL)
        return;

    if (entry == NULL) {
        if (cache->filesCnt % CACHE_BLOCK_SIZE == 0) {
            cache->filesBlocks++;
            cache->files = PM_realloc(cache->files,
                    sizeof(fileCache) * cache->filesBlocks * CACHE_BLOCK_SIZE);
            }
        entry = cache->files + cache->filesCnt;
        cache->filesCnt++;
        }
    else {
        PM_free(entry->fileName);
        PM_free(entry->familyName);
        }

    /* Try to determine family name and face type from facename: */
    if ((entry->fileName = PM_malloc(strlen(filename) + 1)) == NULL)
        FATALERROR(grNoMem);
    strcpy(entry->fileName, filename);
    entry->fontLibType = fontLib->fontLibType;
    buflen = strlen(fontLib->name);
    if ((buf = PM_malloc(buflen + 1)) == NULL)
        FATALERROR(grNoMem);
    strcpy(buf, fontLib->name);
    entry->isBold = entry->isItalic = false;
    do {
        foundSuffix = false;
        if (buflen >= 5 && strcmp(buf + buflen - 5, " Bold") == 0) {
            foundSuffix = true;
            entry->isBold = true;
            buf[buflen - 5] = '\0';
            buflen -= 5;
            }
        if (buflen >= 7 && strcmp(buf + buflen - 7, " Italic") == 0) {
            foundSuffix = true;
            entry->isItalic = true;
            buf[buflen - 7] = '\0';
            buflen -= 7;
            }
        } while (buflen > 0 && foundSuffix);
    if (buflen == 0) {
        if ((entry->familyName = PM_malloc(strlen(filename) + 1)) == NULL)
            FATALERROR(grNoMem);
        strcpy(entry->familyName, filename);
        }
    else {
        if ((entry->familyName = PM_malloc(strlen(buf) + 1)) == NULL)
            FATALERROR(grNoMem);
        strcpy(entry->familyName, buf);
        }
    PM_free(buf);

    /* Check if the font is fixed width or proportional. In absence of better
       method, we do it by comparing average and maximum character width: */
    entry->isFixed = fontIsFixed(fontLib);

    MGL_closeFontLib(fontLib);

    cache->validCnt++;
    entry->exists = true;
}