Code Search for Developers
 
 
  

FontDisplay.c from The Open2x Project at Krugle


Show FontDisplay.c syntax highlighted

/*              
 *  DIGNSYS Inc. < www.dignsys.com >
 *  	Created.
 *
 */

#include <iconv.h>
#include <string.h>
#include "FontDisplay.h"
#include "UnicodeFont.h"

int transcode(const char *from_code, const char *to_code, const char *src, char *target, int len)
{
	iconv_t cd 		= 0;
	char 	*from	= NULL;
	char 	*to		= NULL;
	int 	flen	= 0; 
	int 	tlen	= 0;
	size_t 	result 	= 0;
	
	
	const char 	*errhand = (char*)strchrnul(to_code, '/');
	int 		nslash 	 = 2;
	char 		*newp	 = NULL;
	char 		*cp		 = NULL;
	
	if(*errhand == '/')
	{
		--nslash;
		errhand = (char *)strchrnul(errhand, '/');
	
		if(*errhand == '/')
		{
			--nslash;
			++errhand;
		}
	}
	
	newp 	= (char *)alloca(errhand - to_code + nslash + 6 + 1);
	cp 		= (char *)mempcpy(newp, to_code, errhand - to_code);
	while(nslash-- > 0)
		*cp++ = '/';
	
	memcpy(cp, "IGNORE", sizeof ("IGNORE"));
	to_code = newp;
	
	from 	= (char *)src;
	to 		= target;
	
	
	cd 		= iconv_open(to_code, from_code);
	flen 	= len;
	tlen 	= len*2;


	
	result 	= iconv((void*)cd, &from, (size_t*)&flen, &to, (size_t*)&tlen);
	
	*to='\0';
	
	
	iconv_close(cd);
	
	return len-tlen;
}

void SetPixel(SDL_Surface *pScreen, int x, int y, Uint8 r, Uint8 g, Uint8 b)
{
	Uint8 *ubuff8;
	Uint16 *ubuff16; 
	Uint32 *ubuff32;
	Uint32 color;

	Uint8 c1;
	Uint8 c2;
	Uint8 c3;

	color = SDL_MapRGB(pScreen->format, r, g, b );

	
	switch(pScreen->format->BytesPerPixel) 
	{
		case 1: 
			ubuff8 = (Uint8*)pScreen->pixels;
			ubuff8 += (y * pScreen->pitch) + x; 
			*ubuff8 = (Uint8)color;
			break;

		case 2:
			ubuff8 = (Uint8*)pScreen->pixels;
			ubuff8 += (y * pScreen->pitch) + (x*2);
			ubuff16 = (Uint16*)ubuff8;
			*ubuff16 = (Uint16)color; 
			break;  

		case 3:
			ubuff8 = (Uint8*)pScreen->pixels;
			ubuff8 += (y * pScreen->pitch) + (x*3);


			if(SDL_BYTEORDER == SDL_LIL_ENDIAN) 
			{
				c1 = (color & 0xFF0000) >> 16;
				c2 = (color & 0x00FF00) >> 8;
				c3 = (color & 0x0000FF);
			} 
			else 
			{
				c3 = (color & 0xFF0000) >> 16;
				c2 = (color & 0x00FF00) >> 8;
				c1 = (color & 0x0000FF);	
			}

			ubuff8[0] = c3;
			ubuff8[1] = c2;
			ubuff8[2] = c1;
			break;

		case 4:
			ubuff8 = (Uint8*)pScreen->pixels;
			ubuff8 = (Uint8*)((y*pScreen->pitch) + (x*4));
			ubuff32 = (Uint32*)ubuff8;
			*ubuff32 = color;
			break;

		default:
			fprintf(stderr, "Error: Unknown bitdepth!\n");
	}
}

int DrawFont(SDL_Surface *pScreen, int x, int y, unsigned short code, Uint8 r, Uint8 g, Uint8 b)
{
	unsigned short fontdata[12];
	int height = 0, width = 0;
	int cx = 0;
	int cy = 0;

	GetFont(code, fontdata, &height, &width);
	
	for(cx=0; cx<width; cx++)
	{
		for(cy=0; cy<height; cy++)
		{
			if(fontdata[cy] & (0x8000 >> cx))	
			{
				SetPixel(pScreen, cx + x, cy + y, r, g, b);
			}
		}
	}
	
	return width;
}

void DrawText(SDL_Surface *pScreen, int x, int y, unsigned short *code, int lencode, Uint8 r, Uint8 g, Uint8 b)
{
	int i = 0;
	int pos = 0;
	
	
	if(lencode == -1)	
	{
		for(i=0; code[i]; i++)
			pos += DrawFont(pScreen, x+pos, y, code[i], r, g, b);
	}
	
	else
	{
		for(i=0; i<lencode; i++)
			pos += DrawFont(pScreen, x+pos, y, code[i], r, g, b);
	}
}

void DrawTextOut(SDL_Surface *pScreen, int x, int y, int scale, unsigned short *code, Uint8 r, Uint8 g, Uint8 b)
{
	int i 		= 0;
	int pos		= 0;
	int cnt 	= 0;
	int total 	= 0;
	int height 	= 0;
	int width 	= 0;
	unsigned short fontdata[12] = { 0, };

	
	for(i=0; code[i]; i++)
	{
		GetFont(code[i], fontdata, &height, &width);		
		total += width;
		if(total > scale-18)	
			if(cnt == 0)
				cnt = i-1;								
	}
	
	if(total < scale)
	{
		for(i=0; code[i]; i++)
			pos += DrawFont(pScreen, x+pos, y, code[i], r, g, b);
	}
	else
	{
		for(i=0; i<cnt; i++)
			pos += DrawFont(pScreen, x+pos, y, code[i], r, g, b);
		pos += DrawFont(pScreen, x+pos, y, '.', r, g, b);
		pos += DrawFont(pScreen, x+pos, y, '.', r, g, b);
		pos += DrawFont(pScreen, x+pos, y, '.', r, g, b);
	}
}


unsigned short* OnUTF8ToUnicode(const char *src, int last)
{
	int len = 0;	
	unsigned short *dest = NULL;

	
	len	= (strlen(src)+1)*2;
	dest = (unsigned short*)malloc(len);
	memset((char*)dest, 0, len);			
	
	
	transcode("UTF-8", "UNICODELITTLE", src, (char*)dest, strlen(src)-last);
	
	return dest;
}



See more files for this project here

The Open2x Project

The Open2x project exists to provide an open source resource for the GP2X handheld console based on the MagicEyes MMSP2 processing platform and MP2520F SoC. The project hosts Linux kernel source for the GP2X, boot loader (U-Boot) source and more.

Project homepage: http://www.distant-earth.com/open2x
Programming language(s): Assembly,C,C++
License: other

  default_skin/
    asf.png
    avi.png
    body.png
    dat.png
    downarrow.png
    error.png
    ext.png
    ext_on.png
    folder.png
    full.png
    loading.png
    mpg.png
    nand.png
    nand_on.png
    normal.png
    resume.png
    save.png
    sd.png
    sd_on.png
    selectbar.png
    uparrow.png
    wmv.png
  etc/
    codecs.conf
    dvb-menu.conf
    example.conf
    input.conf
    inttypes.h
    menu.conf
    mplayer.desktop
    mplayer.ico
  fbdisp/
    Makefile
    fblin16.c
    fblin24.c
    fblin32.c
    fbs.h
    fontdisp.h
    fontout.c
    gfxdev.h
    gfxfontext.c
    gfxfontload.c
    gfxfontout.c
    gfxtype.h
    gulim_96_10_eng.c
    gulim_96_10_han.c
    main.c
    scr_fb.c
  help/
    help_diff.sh
    help_mp-bg.h
    help_mp-cs.h
    help_mp-de.h
    help_mp-dk.h
    help_mp-el.h
    help_mp-en.h
    help_mp-es.h
    help_mp-fr.h
    help_mp-hu.h
    help_mp-it.h
    help_mp-ja.h
    help_mp-ko.h
    help_mp-mk.h
    help_mp-nl.h
    help_mp-no.h
    help_mp-pl.h
    help_mp-pt_BR.h
    help_mp-ro.h
    help_mp-ru.h
  libaf/
  libao2/
  libmpcodecs/
  libmpdemux/
  loader/
  osdep/
  AUTHORS
  DirDisplay.c
  DirDisplay.h
  DirList.c
  DirList.h
  FontDisplay.c
  FontDisplay.h
  LICENSE
  Makefile
  bswap.h
  codec-cfg.c
  codec-cfg.h
  config.h
  config.mak
  csource.lst
  cx25874.h
  drawcontrol.c
  drawcontrol.h
  dualcpu.h
  filelistview.c
  filelistview.h
  find_sub.c
  g2player.h
  get_path.c
  glock.c
  glock.h
  guictrl.c
  guictrl.h
  gv.c
  gvlib_export.h
  help_mp.h
  i2c.h
  imgNumber.h
  imgbinary.h
  m_config.c
  m_config.h
  m_option.c
  m_option.h
  m_struct.c
  m_struct.h
  mangle.h
  mixer.c
  mixer.h
  mmsp2_940_if.c
  mmsp2_if.h
  mp_msg.c
  mp_msg.h
  mplayer.c
  mplayer.h
  open2x-mplayer.sh
  rtc_1024_table.h
  subdisp.c
  subdisp.h
  subreader.c
  subreader.h
  typed.h
  version.h
  vpp.h
  vpts_q.c
  wincetype.h