/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. * History:
  26. * ================================================================
  27. * 2009-10-03 Li XianJing <xianjimli@hotmail.com> created
  28. *
  29. */
  30. #include "ftk_log.h"
  31. #include "fontdata.h"
  32. #include "ftk_util.h"
  33. #include "ftk_font.h"
  34. typedef struct _FontDefaultPrivInfo
  35. {
  36. size_t size;
  37. char* filename;
  38. FontData* fontdata;
  39. }PrivInfo;
  40. static Ret ftk_font_default_load(FtkFont* thiz, const char* filename)
  41. {
  42. DECL_PRIV(thiz, priv);
  43. priv->fontdata = font_data_load_file(filename);
  44. ftk_logd("%s: filename=%s\n", __func__, filename);
  45. ftk_logd("%s: author=%s\n", __func__, font_data_get_author(priv->fontdata));
  46. ftk_logd("%s: family=%s\n", __func__, font_data_get_family(priv->fontdata));
  47. ftk_logd("%s: style =%s\n", __func__, font_data_get_style(priv->fontdata));
  48. ftk_logd("%s: w=%d h=%d\n", __func__, font_data_get_width(priv->fontdata), font_data_get_height(priv->fontdata));
  49. return priv->fontdata != NULL ? RET_OK : RET_FAIL;
  50. }
  51. static int ftk_font_default_height(FtkFont* thiz)
  52. {
  53. DECL_PRIV(thiz, priv);
  54. return_val_if_fail(thiz != NULL, 0);
  55. return font_data_get_height(priv->fontdata);
  56. }
  57. static Ret ftk_font_default_lookup (FtkFont* thiz, unsigned short code, FtkGlyph* glyph)
  58. {
  59. DECL_PRIV(thiz, priv);
  60. return_val_if_fail(thiz != NULL, RET_FAIL);
  61. return font_data_get_glyph(priv->fontdata, code, (Glyph*)glyph);
  62. }
  63. void ftk_font_default_destroy(FtkFont* thiz)
  64. {
  65. if(thiz != NULL)
  66. {
  67. DECL_PRIV(thiz, priv);
  68. FTK_FREE(priv->filename);
  69. font_data_destroy(priv->fontdata);
  70. FTK_ZFREE(thiz, sizeof(*thiz) + sizeof(PrivInfo));
  71. }
  72. return;
  73. }
  74. FtkFont* ftk_font_create (const char* filename, FtkFontDesc* font_desc)
  75. {
  76. FtkFont* thiz = NULL;
  77. return_val_if_fail(filename != NULL, NULL);
  78. thiz = FTK_NEW_PRIV(FtkFont);
  79. if(thiz != NULL)
  80. {
  81. DECL_PRIV(thiz, priv);
  82. thiz->ref = 1;
  83. thiz->height = ftk_font_default_height;
  84. thiz->lookup = ftk_font_default_lookup;
  85. thiz->destroy= ftk_font_default_destroy;
  86. priv->size = ftk_font_desc_get_size(font_desc);
  87. if(ftk_font_default_load(thiz, filename) != RET_OK)
  88. {
  89. FTK_ZFREE(thiz, sizeof(FtkFont) + sizeof(PrivInfo));
  90. }
  91. else
  92. {
  93. priv->filename = FTK_STRDUP(filename);
  94. }
  95. }
  96. return thiz;
  97. }