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

📄 bbf_font.h

📁 这是法国Kaleido公司提供了一个手机mmi设计平台
💻 H
字号:
/*
 * Created on 07 jul 2005
 *
 * @author DigitalAirways (c) 2004-2005
 * 
 * This software is the confidential and proprietary information of
 * DigitalAirways, sarl. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DigitalAirways.
 * A copy of this license is included in the licence.txt file included
 * in this software package.
 *
 *
 */

#ifndef __BBF_Font__h_
#define __BBF_Font__h_

#include "EB_Utils.h"

class Graphics;
class GContext;

/* the name of the key used to find the font instance in the global context */
#define BBF_FONT_CONTEXT_KEY "_BBDF_CURRENT_FONT"
 /* this buffer will contain the current char data. Max width = 63 (=4 bytes), max height= 63 (max line number in 111 is 31 + 1 line to save the previous line)*/
#define TMP_LINES_BUFFER_SIZE 252
/* the number of bufferized glyphs */
#define CHAR_BUFFER_LEN 100
/* the number of font which could be declared */
#define MAX_FONT_NUMBER 30

/************************************ struct used  to decompress the font ************************************/
typedef struct 
 {
	unsigned int firstCharCode;	
	unsigned int pageData; // index from the fontData pointer
	unsigned short pageDataSize;	
	unsigned char nbCharacters;
	unsigned char characterWidth;
	unsigned char characterHeight;
	signed char characterXOff;
	signed char characterYOff;
	unsigned char headerInChars;
	unsigned char nbBitsToGetCharsDataLen;
	unsigned char isProportional;

} BBF_page; 


typedef struct 
{
	unsigned int code;
	unsigned int charData; // index from the fontData pointer
	signed char declaredFontIdx; // the char is supposed to be used with this font
	signed char actualFontIdx; // this char actually belongs this font
	unsigned char width;
	unsigned char height;
	signed char xOff;
	signed char yOff;
	signed char nextCharXOff; // from where the next char should 
	unsigned char bitCount;
} BBF_char;


typedef struct 
{
	unsigned char* fontName;
	unsigned char* fontData;
	unsigned int  fontLen; // the len (in bytes) of the current font
	unsigned char isFontDataToBeFreed;
	unsigned char fontSize; // if 0 the font can be used with all other size
	unsigned char fontStyle;
} declaredFont ; 


/* this struct is used to store the last string requested */
typedef struct
{
	int stringHash; // the ID of the string
	unsigned int stringCodesLen ; // the number of chars in the string ( the number of characters is NOT equals the size in byte)
	unsigned int* stringCodes; // malloced. stringCodes and stringSortedCodes share the same buffer 
	unsigned int stringSortedCodesLen; // the number of different glyphs used
	unsigned int* stringSortedCodes; // list of codes in the string, sorted ascendant
	signed int fontIndex;
	unsigned int height;
	unsigned int width;
	unsigned int maxHeight;
	unsigned int bufferSize; // the number of elements in the int[]. actual size of the malloced array is bufferLen*sizeof(int)
} stringContent;


/* BBF FONT manager  */
class KREBDLIBS_API BBF_Font
{
	private:

		/* this buffer is used to store tmp line data during drawString */
		unsigned char* fLinesBuffer;
		
		
		/*********** manage fonts ***********/
		signed char fCurrentFontIdx;	// the idx of the current font in the fDeclaredFonts array
		declaredFont fDeclaredFonts[MAX_FONT_NUMBER];  // to keep the list of all declared fonts 
		GContext* fContext;
		/* used to access the current font */
		declaredFont* getCurrentFont();
		/* load the current font (= fCurrentFontIdx in fDeclaredFonts) from the resource Manager */
		unsigned char* loadCurrentFont(); 	


		/* internal methods to acces pages and chars */
		BBF_page loadPage(unsigned char* pageData, unsigned int byteParsed);
		BBF_page getPage(unsigned char* loadedFont, unsigned int characterCode);
		BBF_char getChar(unsigned int characterCode, unsigned char* fontData);  // fontData should be the data of the fCurrentFontIdx 

		/* to save time when we get the data from the font file, last string is stored */
		stringContent* fLastStringUsed;
		unsigned char* updateStringContent(unsigned char* string);
		unsigned char* loadStringChars();
		int updateStringSize(unsigned char* currentFontData);
		
		/* to save time, we try to keep a cache on some already loaded characters */
		BBF_char fCharBuffer[CHAR_BUFFER_LEN];
		unsigned int fEmptyBufferIdx;
		int putCharInBuffer(BBF_char character); 
		BBF_char getCharInBuffer(unsigned int charCode);
		int clearCharBuffer();

	public : 
		
		DEFINE_NEW(BBF_Font);
		DEFINE_DELETE(BBF_Font);
	
		BBF_Font(GContext* context);
		~BBF_Font();


		/* free all the buffurized datas */
		void packDatas(); 
	
		/* add to the list a new font. 
	       The font will be used and only afer a setCurrentFont 
		   BBF class duplicate fontName to keep a local copy of the string
		   The string fontName is NOT free'd */
		int addFont(unsigned char* fontName, int size, int style=0);

		/* remove a font from the list of declared fonts . */
		int removeFont(unsigned char* fontName, int size, int style=0);

		/* draw a string using the current font.The property is not transferred.
		   BBF class DOESN'T free the given string*/
		void drawString(Graphics* graphics, unsigned char* s, int x, int y, unsigned char r=0, unsigned char g=0, unsigned char b=0, unsigned char a=0xff);
		
		/* set  the current font to be used. Assign only the index in the list of fonts
		   BBF class duplicate fontName to keep a local copy of the string
		   The string fontName is NOT free'd */
		int setCurrentFont(unsigned char* fontName, int size, int style=0);
		
		/* get the name of the current font used. The property is not transferred. 
		   The caller should NOT free the returned name */
		unsigned char* getCurrentFontName();

		/* get the height (in pixels) of the string using the current font*/
		int getHeight(unsigned char* s);

		/* get the width (in pixels) of the string using the current font*/
		int getWidth(unsigned char* s);

		
};

#endif 

⌨️ 快捷键说明

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