Exemplo n.º 1
0
/*
 * Function    : libaroma_font_release
 * Return Value: byte
 * Descriptions: release font instance
 */
byte libaroma_font_release() {
  _libaroma_font_lock(1);
  if (_libaroma_font_instance == NULL) {
    ALOGE("libaroma_font_release _libaroma_font_instance=NULL");
    _libaroma_font_lock(0);
    __libaroma_text_locker_init(1);
    return 0;
  }
  
  /* release harfbuzz callback functions */
#ifndef LIBAROMA_CONFIG_TEXT_NOHARFBUZZ
  _libaroma_font_hb_free_functions();
#endif
  
  /* release font face */
  int i;
  for (i = 0; i < _LIBAROMA_FONT_MAX_FACE; i++) {
    libaroma_font_free(i);
  }
  if (FT_Done_FreeType(_libaroma_font_instance) == 0) {
    _libaroma_font_instance = NULL;
    _libaroma_font_lock(0);
    __libaroma_text_locker_init(1);
    ALOGV("Fonts Resource Released");
    return 1;
  }
  ALOGE("libaroma_font_release FT_Done_FreeType Error");
  _libaroma_font_lock(0);
  __libaroma_text_locker_init(1);
  return 0;
} /* End of libaroma_font_release */
Exemplo n.º 2
0
/*
 * Function    : libaroma_font
 * Return Value: byte
 * Descriptions: load new font
 */
byte libaroma_font(
    byte fontid,
    LIBAROMA_STREAMP stream) {
  if (!stream) {
    ALOGW("libaroma_font stream not found");
    return 0;
  }
  
  if (fontid >= _LIBAROMA_FONT_MAX_FACE) {
    ALOGW("libaroma_font fontid(%i)>=%i",
      fontid, _LIBAROMA_FONT_MAX_FACE);
    return 0;
  }
  
  /* thread safe */
  _libaroma_font_lock(1);
  
  /* load face */
  FT_Face tmp_face;
  if (FT_New_Memory_Face(_libaroma_font_instance, 
      stream->data,
      stream->size,
      0,
      &tmp_face) == 0) {
    /* set default face size */
    int def_size = libaroma_font_size_px(2);
    
    if (FT_Set_Pixel_Sizes(tmp_face, 0, def_size) == 0) {
      /* save it */
      libaroma_font_free(fontid);
      _libaroma_font_faces[fontid].size   = def_size;
      _libaroma_font_faces[fontid].id     = fontid;
      _libaroma_font_faces[fontid].face   = tmp_face;
      _libaroma_font_faces[fontid].stream = stream;
      _libaroma_font_faces[fontid].cache  =
        libaroma_iarray(libaroma_font_freecache_cb);
      
      /* force ucs2 */
      libaroma_font_set_ucs2(_libaroma_font_faces[fontid].face);
      
      /* init harfbuzz */
      _libaroma_font_hb_init(fontid);
      
      /* unlock */
      _libaroma_font_lock(0);
      ALOGV("font loaded %ibytes (%s)", stream->size, stream->uri);
      return 1;
    }
    else {
      ALOGW("libaroma_font libaroma_font_set_size error");
      FT_Done_Face(tmp_face);
    }
  }
  else {
    ALOGW("libaroma_font FT_New_Memory_Face Error");
    libaroma_stream_close(stream);
  }
  _libaroma_font_lock(0);
  return 0;
} /* End of libaroma_font */