Example #1
0
int
test_cmap_cache( btimer_t*  timer,
                 FT_Face    face,
                 void*      user_data )
{
  bcharset_t*  charset = (bcharset_t*)user_data;
  int          i, done = 0;


  FT_UNUSED( face );

  if ( !cmap_cache )
  {
    if ( FTC_CMapCache_New(cache_man, &cmap_cache) )
      return 0;
  }

  TIMER_START( timer );

  for ( i = 0; i < charset->size; i++ )
  {
    if ( FTC_CMapCache_Lookup( cmap_cache, font_type.face_id, 0, charset->code[i] ) )
      done++;
  }

  TIMER_STOP( timer );

  return done;
}
  FTDemo_Handle*
  FTDemo_New( void )
  {
    FTDemo_Handle*  handle;


    handle = (FTDemo_Handle *)malloc( sizeof ( FTDemo_Handle ) );
    if ( !handle )
      return NULL;

    memset( handle, 0, sizeof ( FTDemo_Handle ) );

    error = FT_Init_FreeType( &handle->library );
    if ( error )
      PanicZ( "could not initialize FreeType" );

    error = FTC_Manager_New( handle->library, 0, 0, 0,
                             my_face_requester, 0, &handle->cache_manager );
    if ( error )
      PanicZ( "could not initialize cache manager" );

    error = FTC_SBitCache_New( handle->cache_manager, &handle->sbits_cache );
    if ( error )
      PanicZ( "could not initialize small bitmaps cache" );

    error = FTC_ImageCache_New( handle->cache_manager, &handle->image_cache );
    if ( error )
      PanicZ( "could not initialize glyph image cache" );

    error = FTC_CMapCache_New( handle->cache_manager, &handle->cmap_cache );
    if ( error )
      PanicZ( "could not initialize charmap cache" );

    FT_Bitmap_New( &handle->bitmap );

    FT_Stroker_New( handle->library, &handle->stroker );

    handle->encoding = FT_ENCODING_NONE;

    handle->hinted    = 1;
    handle->antialias = 1;
    handle->use_sbits = 1;
    handle->autohint  = 0;
    handle->lcd_mode  = 0;
    handle->color     = 1;

    handle->use_sbits_cache = 1;

    /* string_init */
    memset( handle->string, 0, sizeof ( TGlyph ) * MAX_GLYPHS );
    handle->string_length = 0;
    handle->string_reload = 1;

    return handle;
  }
Example #3
0
TMODENTRY TUINT tek_init_display_rawfb(struct TTask *task, 
	struct TModule *vis, TUINT16 version, TTAGITEM *tags)
{
	RFBDISPLAY *mod = (RFBDISPLAY *) vis;

	if (mod == TNULL)
	{
		if (version == 0xffff)
			return sizeof(TAPTR) * RFB_DISPLAY_NUMVECTORS;

		if (version <= RFB_DISPLAY_VERSION)
			return sizeof(RFBDISPLAY);

		return 0;
	}

	for (;;)
	{
		TAPTR TExecBase = TGetExecBase(mod);
		
		if (FT_Init_FreeType(&mod->rfb_FTLibrary) != 0)
			break;
		if (FTC_Manager_New(mod->rfb_FTLibrary, 0, 0, 0, rfb_fontrequester, 
				NULL, &mod->rfb_FTCManager) != 0)
			break;
		if (FTC_CMapCache_New(mod->rfb_FTCManager, &mod->rfb_FTCCMapCache) 
			!= 0)
			break;
		if (FTC_SBitCache_New(mod->rfb_FTCManager, &mod->rfb_FTCSBitCache)
			!= 0)
			break;
		
		mod->rfb_ExecBase = TExecBase;
		mod->rfb_Lock = TCreateLock(TNULL);
		if (mod->rfb_Lock == TNULL)
			break;
		
		mod->rfb_Module.tmd_Version = RFB_DISPLAY_VERSION;
		mod->rfb_Module.tmd_Revision = RFB_DISPLAY_REVISION;
		mod->rfb_Module.tmd_Handle.thn_Hook.thk_Entry = rfb_dispatch;
		mod->rfb_Module.tmd_Flags = TMODF_VECTORTABLE | TMODF_OPENCLOSE;
		TInitVectors(&mod->rfb_Module, rfb_vectors, RFB_DISPLAY_NUMVECTORS);
		return TTRUE;
	}
	
	rfb_destroy(mod);
	return TFALSE;
}
Example #4
0
/*********************************************************
 *
 * Library (de)initialization
 *
 *********************************************************/
int
_PGFT_Init(FreeTypeInstance **_instance, int cache_size)
{
    FreeTypeInstance *inst = 0;
    int error;

    inst = _PGFT_malloc(sizeof(FreeTypeInstance));

    if (!inst) {
        PyErr_NoMemory();
        goto error_cleanup;
    }

    memset(inst, 0, sizeof(FreeTypeInstance));
    inst->cache_size = cache_size;

    error = FT_Init_FreeType(&inst->library);
    if (error) {
        RAISE(PyExc_RuntimeError,
              "pygame (_PGFT_Init): failed to initialize FreeType library");
        goto error_cleanup;
    }

    if (FTC_Manager_New(inst->library, 0, 0, 0,
            &_PGFT_face_request, 0,
            &inst->cache_manager) != 0) {
        RAISE(PyExc_RuntimeError,
              "pygame (_PGFT_Init): failed to create new FreeType manager");
        goto error_cleanup;
    }

    if (FTC_CMapCache_New(inst->cache_manager,
            &inst->cache_charmap) != 0) {
        RAISE(PyExc_RuntimeError,
              "pygame (_PGFT_Init): failed to create new FreeType cache");
        goto error_cleanup;
    }

    *_instance = inst;
    return 0;

error_cleanup:
    _PGFT_Quit(inst);
    *_instance = 0;

    return -1;
}
Example #5
0
vita2d_font *vita2d_load_font_file(const char *filename)
{
	FT_Error error;

	vita2d_font *font = malloc(sizeof(*font));
	if (!font)
		return NULL;

	error = FT_Init_FreeType(&font->ftlibrary);
	if (error != FT_Err_Ok) {
		free(font);
		return NULL;
	}

	error = FTC_Manager_New(
		font->ftlibrary,
		0,  /* use default */
		0,  /* use default */
		0,  /* use default */
		&ftc_face_requester,  /* use our requester */
		NULL,                 /* user data  */
		&font->ftcmanager);

	if (error != FT_Err_Ok) {
		free(font);
		FT_Done_FreeType(font->ftlibrary);
		return NULL;
	}

	size_t len = strlen(filename);
	font->filename = malloc(len + 1);
	strcpy(font->filename, filename);

	FTC_CMapCache_New(font->ftcmanager, &font->cmapcache);
	FTC_ImageCache_New(font->ftcmanager, &font->imagecache);

	font->load_from = VITA2D_LOAD_FROM_FILE;

	font->tex_atlas = texture_atlas_create(ATLAS_DEFAULT_W, ATLAS_DEFAULT_H,
		SCE_GXM_TEXTURE_FORMAT_U8_R111);

	return font;
}
Example #6
0
vita2d_font *vita2d_load_font_mem(const void *buffer, unsigned int size)
{
	FT_Error error;

	vita2d_font *font = malloc(sizeof(*font));
	if (!font)
		return NULL;

	error = FT_Init_FreeType(&font->ftlibrary);
	if (error != FT_Err_Ok) {
		free(font);
		return NULL;
	}

	error = FTC_Manager_New(
		font->ftlibrary,
		0,  /* use default */
		0,  /* use default */
		0,  /* use default */
		&ftc_face_requester,  /* use our requester */
		NULL,                 /* user data  */
		&font->ftcmanager);

	if (error != FT_Err_Ok) {
		free(font);
		FT_Done_FreeType(font->ftlibrary);
		return NULL;
	}

	font->font_buffer = buffer;
	font->buffer_size = size;

	FTC_CMapCache_New(font->ftcmanager, &font->cmapcache);
	FTC_ImageCache_New(font->ftcmanager, &font->imagecache);

	font->load_from = VITA2D_LOAD_FROM_MEM;

	font->tex_atlas = texture_atlas_create(ATLAS_DEFAULT_W, ATLAS_DEFAULT_H,
		SCE_GXM_TEXTURE_FORMAT_U8_R111);

	return font;
}
Example #7
0
FreeType::FreeType()
:library_(nullptr)
,cache_(nullptr)
,cmap_(nullptr)
,image_(nullptr)
{
	if(FT_Init_FreeType(&this->library_) != 0){
		CINAMO_EXCEPTION(Exception, "[BUG] Failed to init Freetype.");
	}
	if(FTC_Manager_New(this->library_, 16, 0, 1024*1024*10, face_requester, nullptr, &this->cache_ )){
		FT_Done_FreeType(this->library_);
		CINAMO_EXCEPTION(Exception, "[BUG] Failed to init cache manager.");
	}
	if(FTC_CMapCache_New(this->cache_, &this->cmap_)) {
		FTC_Manager_Done(this->cache_);
		FT_Done_FreeType(this->library_);
		CINAMO_EXCEPTION(Exception, "[BUG] Failed to init cmap cache.");
	}
	if(FTC_ImageCache_New(this->cache_, &this->image_)) {
		FTC_Manager_Done(this->cache_);
		FT_Done_FreeType(this->library_);
		CINAMO_EXCEPTION(Exception, "[BUG] Failed to init image cache.");
	}
}
/* initialise font handling */
bool fb_font_init(void)
{
        FT_Error error;
        FT_ULong max_cache_size;
        FT_UInt max_faces = 6;
	fb_faceid_t *fb_face;

LOG(("Freetype init..."));

	nsoptions.fb_font_monochrome = false;			
	nsoptions.fb_font_cachesize = 2048;			
	nsoptions.fb_face_sans_serif = NULL;			
	nsoptions.fb_face_sans_serif_bold = NULL;		
	nsoptions.fb_face_sans_serif_italic = NULL;		
	nsoptions.fb_face_sans_serif_italic_bold = NULL;		
	nsoptions.fb_face_serif = NULL;				
	nsoptions.fb_face_serif_bold = NULL;			
	nsoptions.fb_face_monospace = NULL;			
	nsoptions.fb_face_monospace_bold = NULL;			
	nsoptions.fb_face_cursive = NULL;			
	nsoptions.fb_face_fantasy = NULL;		


        /* freetype library initialise */
        error = FT_Init_FreeType( &library ); 
        if (error) {
                LOG(("Freetype could not initialised (code %d)\n", error));
                return false;
        }

        /* set the Glyph cache size up */
        max_cache_size = nsoption_int(fb_font_cachesize) * 1024; 

	if (max_cache_size < CACHE_MIN_SIZE) {
		max_cache_size = CACHE_MIN_SIZE;
	}

LOG(("Freetype cache..."));
DBG("Ft cache\n");
        /* cache manager initialise */
        error = FTC_Manager_New(library, 
                                max_faces, 
                                0, 
                                max_cache_size, 
                                ft_face_requester, 
                                NULL, 
                                &ft_cmanager);
        if (error) {
                LOG(("Freetype could not initialise cache manager (code %d)\n", error));
                FT_Done_FreeType(library);
                return false;
        }


LOG(("Freetype map cache..."));
DBG("Ft map cache\n");
        error = FTC_CMapCache_New(ft_cmanager, &ft_cmap_cache);

        error = FTC_ImageCache_New(ft_cmanager, &ft_image_cache);

	/* need to obtain the generic font faces */


LOG(("Freetype load fonts..."));
DBG("Ft load fonts\n");

	/* Start with the sans serif font */
	fb_face = fb_new_face(nsoption_charp(fb_face_sans_serif),
			      "sans_serif.ttf",
			      NETSURF_FB_FONT_SANS_SERIF);
	if (fb_face == NULL) {
		
LOG(("Freetype load fonts failed due SANS unavailable :(..."));
DBG("Ft Z:(((\n");
		/* The sans serif font is the default and must be found. */
                LOG(("Could not find the default font\n"));
                FTC_Manager_Done(ft_cmanager);
                FT_Done_FreeType(library);
                return false;
        } else {
		fb_faces[FB_FACE_SANS_SERIF] = fb_face;
	}

LOG(("Freetype loaded sans.."));
DBG("Ft sans loaded:)\n");

	/* Bold sans serif face */
	fb_face = fb_new_face(nsoption_charp(fb_face_sans_serif_bold),
                            "sans_serif_bold.ttf",
                            NETSURF_FB_FONT_SANS_SERIF_BOLD);
	if (fb_face == NULL) {
		/* seperate bold face unavailabe use the normal weight version */
		fb_faces[FB_FACE_SANS_SERIF_BOLD] = fb_faces[FB_FACE_SANS_SERIF];
	} else {
		fb_faces[FB_FACE_SANS_SERIF_BOLD] = fb_face;
	}

	/* Italic sans serif face */
	fb_face = fb_new_face(nsoption_charp(fb_face_sans_serif_italic),
			      "sans_serif_italic.ttf",
			      NETSURF_FB_FONT_SANS_SERIF_ITALIC);
	if (fb_face == NULL) {
		/* seperate italic face unavailabe use the normal weight version */
		fb_faces[FB_FACE_SANS_SERIF_ITALIC] = fb_faces[FB_FACE_SANS_SERIF];
	} else {
		fb_faces[FB_FACE_SANS_SERIF_ITALIC] = fb_face;
	}

	/* Bold italic sans serif face */
	fb_face = fb_new_face(nsoption_charp(fb_face_sans_serif_italic_bold), 
			      "sans_serif_italic_bold.ttf",
			      NETSURF_FB_FONT_SANS_SERIF_ITALIC_BOLD);
	if (fb_face == NULL) {
		/* seperate italic face unavailabe use the normal weight version */
		fb_faces[FB_FACE_SANS_SERIF_ITALIC_BOLD] = fb_faces[FB_FACE_SANS_SERIF];
	} else {
		fb_faces[FB_FACE_SANS_SERIF_ITALIC_BOLD] = fb_face;
	}

	/* serif face */
	fb_face = fb_new_face(nsoption_charp(fb_face_serif),
                            "serif.ttf",
			      NETSURF_FB_FONT_SERIF);
	if (fb_face == NULL) {
		/* serif face unavailabe use the default */
		fb_faces[FB_FACE_SERIF] = fb_faces[FB_FACE_SANS_SERIF];
	} else {
		fb_faces[FB_FACE_SERIF] = fb_face;
	}

	/* bold serif face*/
	fb_face = fb_new_face(nsoption_charp(fb_face_serif_bold),
			      "serif_bold.ttf",
			      NETSURF_FB_FONT_SERIF_BOLD);
	if (fb_face == NULL) {
		/* bold serif face unavailabe use the normal weight */
		fb_faces[FB_FACE_SERIF_BOLD] = fb_faces[FB_FACE_SERIF];
	} else {
		fb_faces[FB_FACE_SERIF_BOLD] = fb_face;
	}


	/* monospace face */
	fb_face = fb_new_face(nsoption_charp(fb_face_monospace),
			      "monospace.ttf",
			      NETSURF_FB_FONT_MONOSPACE);
	if (fb_face == NULL) {
		/* serif face unavailabe use the default */
		fb_faces[FB_FACE_MONOSPACE] = fb_faces[FB_FACE_SANS_SERIF];
	} else {
		fb_faces[FB_FACE_MONOSPACE] = fb_face;
	}

	/* bold monospace face*/
	fb_face = fb_new_face(nsoption_charp(fb_face_monospace_bold),
			      "monospace_bold.ttf",
			      NETSURF_FB_FONT_MONOSPACE_BOLD);
	if (fb_face == NULL) {
		/* bold serif face unavailabe use the normal weight */
		fb_faces[FB_FACE_MONOSPACE_BOLD] = fb_faces[FB_FACE_MONOSPACE];
	} else {
		fb_faces[FB_FACE_MONOSPACE_BOLD] = fb_face;
	}

	/* cursive face */
	fb_face = fb_new_face(nsoption_charp(fb_face_cursive),
			      "cursive.ttf",
			      NETSURF_FB_FONT_CURSIVE);
	if (fb_face == NULL) {
		/* cursive face unavailabe use the default */
		fb_faces[FB_FACE_CURSIVE] = fb_faces[FB_FACE_SANS_SERIF];
	} else {
		fb_faces[FB_FACE_CURSIVE] = fb_face;
	}

	/* fantasy face */
	fb_face = fb_new_face(nsoption_charp(fb_face_fantasy),
			      "fantasy.ttf",
			      NETSURF_FB_FONT_FANTASY);
	if (fb_face == NULL) {
		/* fantasy face unavailabe use the default */
		fb_faces[FB_FACE_FANTASY] = fb_faces[FB_FACE_SANS_SERIF];
	} else {
		fb_faces[FB_FACE_FANTASY] = fb_face;
	}

LOG(("Freetype fonts ready..."));
DBG("Ft ready :)\n");
        
        /* set the default render mode */
        if (nsoption_bool(fb_font_monochrome) == true)
                ft_load_type = FT_LOAD_MONOCHROME; /* faster but less pretty */
        else
                ft_load_type = 0;
        
        return true;
}