PageRenderTime 62ms CodeModel.GetById 40ms app.highlight 7ms RepoModel.GetById 13ms app.codeStats 0ms

/src/canvas/default/ftk_font_default.c

http://ftk.googlecode.com/
C | 115 lines | 68 code | 18 blank | 29 comment | 10 complexity | 6ac39c1e141f6582d20564e401d80e6a MD5 | raw file
  1/*
  2 * File: ftk_font_default.c    
  3 * Author:  Li XianJing <xianjimli@hotmail.com>
  4 * Brief:   default font.  
  5 *
  6 * Copyright (c) 2009 - 2010  Li XianJing <xianjimli@hotmail.com>
  7 *
  8 * Licensed under the Academic Free License version 2.1
  9 *
 10 * This program is free software; you can redistribute it and/or modify
 11 * it under the terms of the GNU General Public License as published by
 12 * the Free Software Foundation; either version 2 of the License, or
 13 * (at your option) any later version.
 14 *
 15 * This program is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 * GNU General Public License for more details.
 19 *
 20 * You should have received a copy of the GNU General Public License
 21 * along with this program; if not, write to the Free Software
 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 23 */
 24
 25/*
 26 * History:
 27 * ================================================================
 28 * 2009-10-03 Li XianJing <xianjimli@hotmail.com> created
 29 *
 30 */
 31
 32#include "ftk_log.h"
 33#include "fontdata.h"
 34#include "ftk_util.h"
 35#include "ftk_font.h"
 36
 37typedef struct _FontDefaultPrivInfo
 38{
 39	size_t size;
 40	char* filename;
 41	FontData* fontdata;
 42}PrivInfo;
 43
 44static Ret ftk_font_default_load(FtkFont* thiz, const char* filename)
 45{
 46	DECL_PRIV(thiz, priv);
 47
 48	priv->fontdata = font_data_load_file(filename);
 49	ftk_logd("%s: filename=%s\n", __func__, filename);
 50	ftk_logd("%s: author=%s\n", __func__, font_data_get_author(priv->fontdata));
 51	ftk_logd("%s: family=%s\n", __func__, font_data_get_family(priv->fontdata));
 52	ftk_logd("%s: style =%s\n", __func__, font_data_get_style(priv->fontdata));
 53	ftk_logd("%s: w=%d h=%d\n", __func__, font_data_get_width(priv->fontdata), font_data_get_height(priv->fontdata));
 54	
 55	return priv->fontdata != NULL ? RET_OK : RET_FAIL;
 56}
 57
 58static int      ftk_font_default_height(FtkFont* thiz)
 59{
 60	DECL_PRIV(thiz, priv);
 61	return_val_if_fail(thiz != NULL, 0);
 62
 63	return font_data_get_height(priv->fontdata);
 64}
 65
 66static Ret ftk_font_default_lookup (FtkFont* thiz, unsigned short code, FtkGlyph* glyph)
 67{
 68	DECL_PRIV(thiz, priv);
 69	return_val_if_fail(thiz != NULL, RET_FAIL);
 70
 71	return font_data_get_glyph(priv->fontdata, code, (Glyph*)glyph);
 72}
 73
 74void      ftk_font_default_destroy(FtkFont* thiz)
 75{
 76	if(thiz != NULL)
 77	{
 78		DECL_PRIV(thiz, priv);
 79		FTK_FREE(priv->filename);
 80		font_data_destroy(priv->fontdata);
 81		FTK_ZFREE(thiz, sizeof(*thiz) + sizeof(PrivInfo));
 82	}
 83
 84	return;
 85}
 86
 87FtkFont* ftk_font_create (const char* filename, FtkFontDesc* font_desc)
 88{
 89	FtkFont* thiz = NULL;
 90	return_val_if_fail(filename != NULL, NULL);
 91
 92	thiz = FTK_NEW_PRIV(FtkFont); 
 93	if(thiz != NULL)
 94	{
 95		DECL_PRIV(thiz, priv);
 96		
 97		thiz->ref = 1;
 98		thiz->height = ftk_font_default_height;
 99		thiz->lookup = ftk_font_default_lookup;
100		thiz->destroy= ftk_font_default_destroy;
101
102		priv->size = ftk_font_desc_get_size(font_desc);
103		if(ftk_font_default_load(thiz, filename) != RET_OK)
104		{
105			FTK_ZFREE(thiz, sizeof(FtkFont) + sizeof(PrivInfo));
106		}
107		else
108		{
109			priv->filename = FTK_STRDUP(filename);
110		}
111	}
112
113	return thiz;
114}
115