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

📄 bbf_utils.h

📁 这是法国Kaleido公司提供了一个手机mmi设计平台
💻 H
字号:
/*
 * Created on 07 jul 2005
 *
 * @author DigitalAirways (c) 2005-2006
 * 
 * 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_DEFINE__H
#define __BBF_FONT_DEFINE__H

#include "KR_KRuntime.h"
#include "EB_CharCodes.h"

/* the font file must start with this number*/
#define CURRENT_FONT_VERSION 14

/* the max idx of a bit in a byte */
#define CHAR_MAX_INDEX 7

/* the max number of characters in a font page */
#define MAX_PAGE_SIZE 255

/* the max value for the glyph width,height */
#define MAX_CHAR_SIZE 63

/* the max value for the glyph xOff,yOff */
#define MAX_CHAR_XY_OFFSET 31

#define CHAR_NOT_FOUND_SIZE 7
		
/* These methods are used by both the kompress tool and the target engine to
 * acess bits
 */
inline unsigned char getMask(unsigned char i);
inline unsigned char getMultiBitsMask(unsigned char number);
inline unsigned char getCurrentBitInCurrentByte(unsigned char theByte, unsigned int count);
inline unsigned char putBitInCurrentBuffer(unsigned char** buffer, unsigned int* count);
inline unsigned char getCurrentBitInCurrentBuffer(unsigned char**  buffer, unsigned int* count);
inline unsigned int getCharacterCode (unsigned char** buffer);
inline unsigned char  getBitsAsByteInCurrentBuffer(unsigned char**  buffer, unsigned int* count, unsigned int numberOfBitNeeded);
inline unsigned char jumpInBuffer(unsigned char**  buffer, unsigned int* count, unsigned int numberOfBits);

/* get a hash (ID) from a string*/
inline int hashString(char* string);

/* sort method using the bubble sort algorithm */
inline int bubbleSort(unsigned int* tab, unsigned int elementNumber) ; 
/* sort method using the quickSort algorithm */
inline void quickSort(unsigned int* t, int beg, int end);


/* get the mask to get the bit of idx i in a byte*/
inline  unsigned char getMask(unsigned char i)
{
	switch (i) 
	{
		case 0 : 
			return 0x80;
		case 1: 
			return 0x40;
		case 2: 
			return 0x20;
		case 3: 
			return 0x10;
		case 4: 
			return 0x08;
		case 5: 
			return 0x04;
		case 6: 
			return 0x02;
		case 7: 
			return 0x01;
	}
	return 0;
}



/* get the mask to get the bit of idx i in a byte*/
inline  unsigned char getMultiBitsMask(unsigned char number)
{
	switch (number) 
	{
		case 1: 
			return	0x80;
		case 2: 
			return	0xC0;
		case 3: 
			return	0xE0;
		case 4: 
			return	0xF0;
		case 5: 
			return	0xF8;
		case 6: 
			return	0xFC;
		case 7: 
			return	0xFE;
		case 8: 
			return	0xFF;
	}
	return 0;
}



/* get the bit at index count in the byte 
 * return value is 0x0001 or 0x0000 */
inline unsigned char getCurrentBitInCurrentByte(unsigned char theByte, unsigned int count)
{
	return  (((theByte) & getMask(count)) >> (CHAR_MAX_INDEX-count)); 
}
		


/* put a bit in a char* buffer BUFFER is supposed to be memseted with 0
 * the char* can be ++'d */
inline unsigned char putBitInCurrentBuffer(unsigned char**  buffer, unsigned int* count, unsigned char bit)
{
	unsigned char* offset=*buffer;
	*offset=  (*offset | (bit <<(CHAR_MAX_INDEX-*count)));
	if (*count==CHAR_MAX_INDEX) 
	{ 
		*count=0;
		(*buffer)++;
	}
	else
	 (*count)++;
	return TRUE;	
}


	
/* return the next 8 bits in the currentBuffer */
inline unsigned char getCurrentByteInCurrentBuffer(unsigned char**  buffer, unsigned int* count)
{
	return getBitsAsByteInCurrentBuffer(buffer, count, 8); 
}
	

	
/* get the bit at idx count in the char* buffer.
 * the char* and the bitcount can be ++'d */
inline unsigned char  getCurrentBitInCurrentBuffer(unsigned char**  buffer, unsigned int* count)
{
	unsigned char tmp= getCurrentBitInCurrentByte((*(*buffer)), *count);
	if (*count>=CHAR_MAX_INDEX) 
	{
		*count=0;
		(*buffer)++;
	}
	 else
	 	(*count)++;
	 return tmp;		
}


/* get the bit at idx count in the char* buffer.
 * the char* and the bitcount can be ++'d */
inline void  getCurrentBitInCurrentBuffer(unsigned char**  buffer, unsigned int* count, unsigned char* bitValue)
{
	*bitValue = getCurrentBitInCurrentByte((*(*buffer)), *count);
	if (*count>=CHAR_MAX_INDEX) 
	{
		*count=0;
		(*buffer)++;
	}
	 else
	 	(*count)++;
}


	
/* NUMBER OF BIT NEEDED SHOULD BE <9 and > 0 . NUMBER OF BIT NEEDED IS NOT CHECKED !!! */
inline unsigned char  getBitsAsByteInCurrentBuffer(unsigned char**  buffer, unsigned int* count, unsigned int numberOfBitNeeded)
{
	unsigned char returnValue= 0;
	unsigned char numberOfBitLeftInCurrentByte= 8 - *count;

	if (numberOfBitNeeded >numberOfBitLeftInCurrentByte) 
	{
		/* first, get the bits in current byte */
		returnValue =  ((((unsigned char)(*(*buffer)))<<*count) & getMultiBitsMask(numberOfBitLeftInCurrentByte)) >> (8-numberOfBitNeeded);
		/* now that we have each bits in the current byte, go to the next byte */
		*count=0;
		(*buffer)++;
		/* get the bits in the second byte */
		numberOfBitLeftInCurrentByte = numberOfBitNeeded - numberOfBitLeftInCurrentByte; // get the number of bits left 
		returnValue |= (((unsigned char)(*(*buffer)) & getMultiBitsMask(numberOfBitLeftInCurrentByte)) >> (8 - numberOfBitLeftInCurrentByte)) ;	
		 /* reassign the new count */
		*count = numberOfBitLeftInCurrentByte ; 
	}
	else /* easier way : just get the bits in the current byte */
	{	
		returnValue = ((((unsigned char)(*(*buffer)))<<*count) &getMultiBitsMask(numberOfBitNeeded)) >> (8 - numberOfBitNeeded);
		*count = *count + numberOfBitNeeded;
	}

	if (*count>CHAR_MAX_INDEX) 
	{
		*count=0;
		(*buffer)++;
	}
	return returnValue;		
}


/* NUMBER OF BIT NEEDED SHOULD BE <9 and > 0 . NUMBER OF BIT NEEDED IS NOT CHECKED !!! 
	BEWARE !!! BYTE ORDER MANAGEMENT NOT TESTED YET 
*/
inline unsigned int getBitsAsIntInCurrentBuffer(unsigned char**  buffer, unsigned int* count, unsigned int numberOfBitNeeded)
{
	unsigned int returnValue= 0;
	signed char nbBytesNeeded=(signed char)((unsigned char)(numberOfBitNeeded>>3)) ; 
	unsigned char remainingBits = numberOfBitNeeded & 0x00000007;
#if defined (__BYTE_ORDER) &&  ( __BYTE_ORDER == __BIG_ENDIAN )
	
		int i=0;
	for ( i = 0 ; i< nbBytesNeeded; i++)
		returnValue |= (getBitsAsByteInCurrentBuffer(buffer, count, 8)) << ((i<<3)+remainingBits);

	if (remainingBits)
		returnValue |= ((unsigned int) getBitsAsByteInCurrentBuffer(buffer, count, remainingBits));
	
#else 
	for ( nbBytesNeeded=nbBytesNeeded-1; nbBytesNeeded >= 0; nbBytesNeeded--)
		returnValue |= (getBitsAsByteInCurrentBuffer(buffer, count, 8)) << ((nbBytesNeeded<<3)+remainingBits);

	if (remainingBits)
		returnValue |=getBitsAsByteInCurrentBuffer(buffer, count, remainingBits);

#endif 
	return returnValue;
}



inline unsigned char jumpInBuffer(unsigned char**  buffer, unsigned int* count, unsigned int numberOfBits)
{			
	numberOfBits+=*count;
	*buffer+=(numberOfBits>>3);
	*count=numberOfBits & 0x00000007;	
	return TRUE;
}



/* manage only 0xFFFF characters 
 *
 * This method is supposed to return a Unicode (16bits) char from
 *. the current string.
 */
inline unsigned int getCharacterCode (unsigned char** buffer)
{
	unsigned int characterBuffer=0;
	characterBuffer = getUTF16fromUTF8(buffer, strictConversion);
	if (!characterBuffer) // cause if the char is not a valid UTF8 the buffer is NOT ++'d
		(*buffer) ++ ; 
	return characterBuffer;
}



inline int quickSortStep(unsigned int* t, int min, int max) 
{
	unsigned int temp = t[max];
    while(max > min) 
	{
         while(max > min && t[min] <= temp) 
			min++;
         if(max > min) 
		 {
            t[max--] = t[min];
            while(max > min && t[max] >= temp) 
				max--;
            if(max > min) 
                t[min++] = t[max];
        }
   }
   t[max] = temp;
   return max;
}



inline void quickSort(unsigned int* t, int beg, int end) 
{
	unsigned int mil;
    if(beg < end) 
	{
		mil = quickSortStep(t,beg,end);
        if(mil - beg > end - mil) 
		{
			quickSort(t,mil+1,end);
            quickSort(t,beg,mil-1);
        }
        else 
		{
            quickSort(t,beg,mil-1);
            quickSort(t,mil+1,end);
        }
    }
}





inline int bubbleSort(unsigned int* tab, unsigned int elementNumber) 
{	
	unsigned int i, k; 
    unsigned int tmp; 
   for (i= elementNumber-1; i>0;  i--) 
     for (k=0 ; k < i; k++ ) 
         if (tab[k] > tab[k+1]) 
		 {
            tmp = tab[k]; 
            tab[k] = tab[k+1]; 
            tab[k+1] = tmp; 
         }
		return 0;
}


inline int hashString(char* string)
{
	int rslt = 147;
	if(!string || !*string)
		return 0;
	while(*string)
	{
		rslt = ((rslt ^ *string) << 8) | ((rslt & 0xff000000)>>24) ;
		string++;
	}
	return rslt ;
}



#endif

⌨️ 快捷键说明

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