⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guidevfont.c

📁 The combined demo is dedicated for S1C33L05, so DMT33L05 should be used to load and run the demo. F
💻 C
字号:
/* $id: guiDevfont.c V1.0 2001/11/1 */
/***************************************************************************
 *    This source code has been made available to you by EPSON on an AS-IS
 *    basis. Anyone receiving this source is licensed under EPSON
 *    copyrights to use it in any way he or she deems fit, including
 *    copying it, modifying it, compiling it, and redistributing it either
 *    with or without modifications.
 *
 *    Any person who transfers this source code or any derivative work
 *    must include the EPSON copyright notice, this paragraph, and the
 *    preceding two paragraphs in the transferred software.
 *
 *    COPYRIGHT   EPSON  CORPORATION 2001
 *    LICENSED MATERIAL  -  PROGRAM PROPERTY OF EPSON
 **************************************************************************/


/***************************************************************************
 * FILE: guiDevfont.c
 * MODULE: FONT
 *
 * PURPOSE: The management of device font .
 *
 *
 * AUTHOR(S): ZhaoJZ
 * GROUP: GUI Group
 * DATE CREATED: 2001/11/1
 * REFERENCE DOCUMENT ID:
 * MODIFICATIONS:
 *    Date           userName          Description
 *    2001/11/1     ZhaoJZ            Create this file
 **************************************************************************/#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "sysGUI.h"

//#include "guiTotal.h"
#include "guiFont.h"

#include "guiSysfont.h"
#include "guiCharset.h"
#include "guiDevfont.h"
#include "guiFontname.h"
#include "guiRawbitmap.h"
#include "guiVarbitmap.h"
T_MODULE T_GUI_DevFont *sb_dev_font_head = NULL;
T_MODULE T_GUI_DevFont *mb_dev_font_head = NULL;
T_MODULE T_WORD nr_sb_dev_fonts=0;
T_MODULE T_WORD nr_mb_dev_fonts=0;

#define devfontAddSBCDevFont(head, new)         \
{                                               \
    if (head == NULL)                           \
        head = new;                             \
    else                                        \
	{                                      \
        T_GUI_DevFont *tail=NULL;                          \
        tail = head;                            \
        while (tail->sbc_next) tail = tail->sbc_next;   \
        tail->sbc_next = new;                       \
    }                                           \
    new->sbc_next = NULL;                           \
}

#define devfontAddMBCDevFont(head, new)         \
{                                               \
    if (head == NULL)                           \
        head = new;                             \
    else                                        \
	{                                      \
        T_GUI_DevFont *tail=NULL;                          \
        tail = head;                            \
        while (tail->mbc_next) tail = tail->mbc_next;   \
        tail->mbc_next = new;                       \
    }                                           \
    new->mbc_next = NULL;                           \
}

/* add the single byte font */
T_VOID AddSBDevFont(T_GUI_DevFont* dev_font)
{
    devfontAddSBCDevFont(sb_dev_font_head, dev_font);
    dev_font->style = fontGetStyleFromName(dev_font->name);
    nr_sb_dev_fonts ++;
}

/* add the double bytes font */
T_VOID AddMBDevFont(T_GUI_DevFont* dev_font)
{
    devfontAddMBCDevFont(mb_dev_font_head, dev_font);
    dev_font->style = fontGetStyleFromName(dev_font->name);
    nr_mb_dev_fonts ++;
}

/******************************************************************
 * FUNCTION: fnFNT_ResetDevFont
 *
 * PURPOSE:
 *    Reset the device font
 *
 * PARAMETERS
 *    Input:
 *    Output:
 *    InOut:
 * Return value:
 * Reentrant : No
 *****************************************************************/T_VOID  fnFNT_ResetDevFont(T_VOID){
    sb_dev_font_head = mb_dev_font_head = NULL;
    nr_sb_dev_fonts = 0;
    nr_mb_dev_fonts = 0;}

#define MATCHED_TYPE        0x01
#define MATCHED_FAMILY      0x02
#define MATCHED_CHARSET     0x04
/******************************************************************
 * FUNCTION: fnFNT_GetMatchedSBDevFont
 *
 * PURPOSE:
 *           get the single byte device font matched with logfont
 *
 * PARAMETERS
 *    Input: T_GUI_LogFont* --- the logic font
 *    Output:
 *    InOut:
 * Return value:T_GUI_DevFont* --- the single bytes device font
 * Reentrant : No
 *****************************************************************/
T_GUI_DevFont *fnFNT_GetMatchedSBDevFont(T_GUI_LogFont *log_font)
{
    T_GUI_DevFont *dev_font;
    T_WORD i;
    T_UBYTE* match_bits = malloc(nr_sb_dev_fonts);
    T_BYTE charset_req[LEN_FONT_NAME + 1];
    T_WORD min_error;
    T_GUI_DevFont *matched_font=NULL;

	if(!match_bits) return NULL;
/* is charset requested  a single byte charset? */
    if(fnFNT_GetCharsetOps(log_font->charset)->bytes_maxlen_char > 1)
	{
        fontGetCharsetFromName(tFNT_SysLogFont.sbc_devfont->name, charset_req);
    }
    else
        strcpy(charset_req, log_font->charset);

    i = 0;
    dev_font = sb_dev_font_head;
    while(dev_font)
	{
        T_WORD type_req;
        T_BYTE family[LEN_FONT_NAME + 1];
        T_BYTE charset[LEN_FONT_NAME + 1];

/* clear match_bits first */
        match_bits[i] = 0;

/* does match this font type? */
        type_req = fontConvertFontType(log_font->type);
        if (type_req == FONT_TYPE_ALL)
            match_bits[i] |= MATCHED_TYPE;
        else if (type_req == fontGetFontTypeFromName(dev_font->name))
            match_bits[i] |= MATCHED_TYPE;

/*  match this family? */
        fnFNT_GetFamilyFromName(dev_font->name, family);
        if (strcmp(family, log_font->family) == 0)
		{
            match_bits[i] |= MATCHED_FAMILY;
        }

/*  match this charset? */
        fontGetCharsetFromName(dev_font->name, charset);
        if (fnFNT_GetCharsetOps(charset) == fnFNT_GetCharsetOps(charset_req))
		{
            match_bits[i] |= MATCHED_CHARSET;
        }
        else
		{
            if (fontGetCompatibleCharsetFromName(dev_font->name, charset)
				  && fnFNT_GetCharsetOps(charset) == fnFNT_GetCharsetOps(charset_req))
                match_bits[i] |= MATCHED_CHARSET;
        }

        /* ignore style */

        dev_font = dev_font->sbc_next;
        i ++;
    }

    /* get the matched devfont according to the size of font */
    min_error = FONT_MAX_SIZE;
    matched_font = NULL;
    dev_font = sb_dev_font_head;
    for(i = 0; i < nr_sb_dev_fonts; i++)
	{
        T_WORD error;
        if((match_bits[i] & MATCHED_TYPE)
                && (match_bits[i] & MATCHED_FAMILY)
                && (match_bits[i] & MATCHED_CHARSET))
		{
            error = abs(log_font->size -
                    (*dev_font->font_ops->get_font_size)(log_font, dev_font,
                                                          log_font->size));
            if (min_error > error)
			{
                min_error = error;
                matched_font = dev_font;
            }
        }
        dev_font = dev_font->sbc_next;
    }

    if(matched_font)
	{
        return matched_font;
    }

    /*  if not ,get the most matched device font according to character's height */
    min_error = FONT_MAX_SIZE;
    dev_font = sb_dev_font_head;
    for(i = 0; i < nr_sb_dev_fonts; i++)
	{
        T_WORD error;
        if(match_bits[i] & MATCHED_CHARSET)
		{
            error = abs(log_font->size -
                    (*dev_font->font_ops->get_font_size)(log_font, dev_font, log_font->size));
            if(min_error > error)
			{
                min_error = error;
                matched_font = dev_font;
            }
        }
        dev_font = dev_font->sbc_next;
    }

    free(match_bits);
    return matched_font;
}


/******************************************************************
 * FUNCTION: fnFNT_GetMatchedMBDevFont
 *
 * PURPOSE:
 *           get the multiple bytes device font matched with logfont
 *
 * PARAMETERS
 *    Input: T_GUI_LogFont * --- the logic font
 *    Output:
 *    InOut:
 * Return value:T_GUI_DevFont* --- the double bytes device font
 * Reentrant : No
 *****************************************************************/
T_GUI_DevFont *fnFNT_GetMatchedMBDevFont(T_GUI_LogFont *log_font){
    T_GUI_DevFont* dev_font;
    T_WORD i;
    T_UBYTE* match_bits = malloc(nr_mb_dev_fonts);
    T_BYTE charset_req[LEN_FONT_NAME + 1];
    T_WORD min_error;
    T_GUI_DevFont *matched_font=NULL;
	
	if(!match_bits) return NULL;
    /* is charset requested  a multiple-byte charset? */
    if(fnFNT_GetCharsetOps(log_font->charset)->bytes_maxlen_char < 2)
        return NULL;

    strcpy(charset_req, log_font->charset);

    i = 0;
    dev_font = mb_dev_font_head;
    while(dev_font)
	{
        T_WORD type_req;
        T_BYTE family[LEN_FONT_NAME + 1];
        T_BYTE charset[LEN_FONT_NAME + 1];

        /* clear match_bits first.*/
        match_bits[i] = 0;

        /*  match this font type? */
        type_req = fontConvertFontType(log_font->type);
        if(type_req == FONT_TYPE_ALL)
            match_bits[i] |= MATCHED_TYPE;
        else if(type_req == fontGetFontTypeFromName(dev_font->name))
            match_bits[i] |= MATCHED_TYPE;

        /*  match this family? */
        fnFNT_GetFamilyFromName(dev_font->name, family);
        if(strcmp(family, log_font->family) == 0)
		{
            match_bits[i] |= MATCHED_FAMILY;
        }

        /*  match this charset */
        fontGetCharsetFromName(dev_font->name, charset);
        if(fnFNT_GetCharsetOps(charset) == fnFNT_GetCharsetOps(charset_req))
		{
            match_bits[i] |= MATCHED_CHARSET;
        }

        /* ignore style */

        dev_font = dev_font->mbc_next;
        i ++;
    }

    matched_font = NULL;
    min_error = FONT_MAX_SIZE;
    dev_font = mb_dev_font_head;
    for(i = 0; i < nr_mb_dev_fonts; i++)
	{
        T_WORD error;
        if((match_bits[i] & MATCHED_TYPE)
                && (match_bits[i] & MATCHED_FAMILY)
                && (match_bits[i] & MATCHED_CHARSET))
		{
            error = abs(log_font->size -
                    (*dev_font->font_ops->get_font_size)(log_font, dev_font,
                                                          log_font->size));
            if(min_error > error)
			{
                min_error = error;
                matched_font = dev_font;
            }
        }
        dev_font = dev_font->mbc_next;
    }

    if(matched_font)
	{
        return matched_font;
    }

    min_error = FONT_MAX_SIZE;
    dev_font = mb_dev_font_head;
    for(i = 0; i < nr_mb_dev_fonts; i++)
	{
        T_WORD error;
        if(match_bits[i] & MATCHED_CHARSET)
		{
            error = abs (log_font->size -
                    (*dev_font->font_ops->get_font_size)(log_font, dev_font,
                                                          log_font->size));
            if(min_error > error)
			{
                min_error = error;
                matched_font = dev_font;
            }
        }
        dev_font = dev_font->mbc_next;
    }

    free(match_bits);
    return matched_font;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -