Ejemplo n.º 1
0
int zaFont::initFont(char * path)
{
    FT_Library library;
    FT_Face face;

    if(FT_Init_FreeType(&library)) {
        fprintf(stderr, "Error loading Freetype library\n");
        return NULL;
    }

    if (FT_New_Face(library,path,0,&face)) {
        fprintf(stderr, "Error loading font %s\n", path);
        return NULL;
    }

	int iCharMapCnt = face->num_charmaps;
	FT_CharMap* pCharMaps = face->charmaps;
	// FT_ULong lang= FT_Get_CMap_Language_ID(*pCharMaps);
	 int ic;
	 for ( ic = 0; ic < iCharMapCnt; ic ++)
	 {
		 if (ic == 0 )
		 {
			 FT_CharMapRec aCharMap = *(pCharMaps[ic]);
			 FT_Encoding enconding = aCharMap.encoding;
			 int platform_id = aCharMap.platform_id;
			 int encoding_id = aCharMap.encoding_id;
//			 this->m_max_x = face->max_advance_width;
//			 this->m_max_y = face->max_advance_height;
			 fprintf(stderr,
					 "initFont "
					 "platform_id %d, "
					 "encoding_id %d "
					 "width %d height %d\n",
					 platform_id,encoding_id,m_max_x,m_max_y);
		 }
	 }
    FT_Done_Face(face);
    FT_Done_FreeType(library);
}
Ejemplo n.º 2
0
  static void
  ExecuteTest( char*  testfont )
  {
    FT_Library  context;
    FT_Face     face;


    if ( FT_Init_FreeType( &context ) )
    {
      fprintf( stderr, "Can't initialize FreeType.\n" );
      exit( 1 );
    }

    if ( FT_New_Face( context, testfont, 0, &face ) )
    {
      /* The font is erroneous, so if this fails that's ok. */
      exit( 0 );
    }

    if ( face->num_faces == 1 )
      TestFace( face );
    else
    {
      long  i, num;


      num = face->num_faces;
      FT_Done_Face( face );

      for ( i = 0; i < num; i++ )
      {
        if ( !FT_New_Face( context, testfont, i, &face ) )
          TestFace( face );
      }
    }

    FT_Done_FreeType( context );

    exit( 0 );
  }
Ejemplo n.º 3
0
Archivo: main.cpp Proyecto: lihw/glf
int main(int argc, const char* argv[])
{
    // Create And Initilize A FreeType Font Library.
    FT_Library library;
    if (FT_Init_FreeType(&library))
    {
        fprintf(stderr, "FT_Init_FreeType failed");
        return EXIT_FAILURE;
    }
 
    // The Object In Which FreeType Holds Information On A Given
    // Font Is Called A "face".
    FT_Face face;
 
    // This Is Where We Load In The Font Information From The File.
    // Of All The Places Where The Code Might Die, This Is The Most Likely,
    // As FT_New_Face Will Fail If The Font File Does Not Exist Or Is Somehow Broken.
    if (FT_New_Face(library, "arial.TTF", 0, &face))
    {
        fprintf(stderr, "FT_New_Face failed (there is probably a problem with your font file)");
        return EXIT_FAILURE;
    }
 
    // For Some Twisted Reason, FreeType Measures Font Size
    // In Terms Of 1/64ths Of Pixels.  Thus, To Make A Font
    // h Pixels High, We Need To Request A Size Of h*64.
    // (h << 6 Is Just A Prettier Way Of Writing h*64)
    FT_Set_Char_Size(face, fontHeight << 6, fontHeight << 6, 96, 96);
 
    createFontFile(face, "font.cpp");
 
    // We Don't Need The Face Information Now That The Display
    // Lists Have Been Created, So We Free The Assosiated Resources.
    FT_Done_Face(face);
 
    // Ditto For The Font Library.
    FT_Done_FreeType(library);
    
    return 0;
}
Ejemplo n.º 4
0
// Close fonts and glyphs
void tAt5MapText::Close()
{
    if ( m_pGlyphcache != NULL )
    {
        delete m_pGlyphcache;
        m_pGlyphcache = NULL;
    }

    if ( m_pFtLib != NULL )
    {
        FT_Done_FreeType( m_pFtLib );
        m_pFtLib = NULL;
    }

    if ( m_pFtFace != NULL )
    {
        FT_Done_Face( m_pFtFace );
        m_pFtFace = NULL;
    }

    m_Directory = "";
}
Ejemplo n.º 5
0
static av_cold void uninit(AVFilterContext *ctx)
{
    DrawTextContext *s = ctx->priv;

    av_expr_free(s->x_pexpr);
    av_expr_free(s->y_pexpr);
    s->x_pexpr = s->y_pexpr = NULL;
    av_freep(&s->positions);
    s->nb_positions = 0;


    av_tree_enumerate(s->glyphs, NULL, NULL, glyph_enu_free);
    av_tree_destroy(s->glyphs);
    s->glyphs = NULL;

    FT_Done_Face(s->face);
    FT_Stroker_Done(s->stroker);
    FT_Done_FreeType(s->library);

    av_bprint_finalize(&s->expanded_text, NULL);
    av_bprint_finalize(&s->expanded_fontcolor, NULL);
}
Ejemplo n.º 6
0
//-------------------------------------------------------------------------------------------------------
StringManager::~StringManager()
{
    if( m_isLoad )
    {
        FT_Done_Face(m_FT_Face);
        FT_Done_FreeType(m_FT2Lib);
        for ( BStringList::iterator it = m_StringList.begin(); //释放全部的字体
                it != m_StringList.end();
                it++)
        {
            this->DestroyString( *it );
        }
        for ( RendBufferList::iterator it = m_FreeBufferList.begin();
                it != m_FreeBufferList.end();
                it++ )
        {
            delete (*it)->GetVertexBuffer();
            delete (*it)->GetIndicesBuffer();
            SAFE_DELETE( *it );
        }
    }
}
Ejemplo n.º 7
0
void SkFontHost::FilterRec(SkScalerContext::Rec* rec) {
    if (!gLCDSupportValid) {
      InitFreetype();
      FT_Done_FreeType(gFTLibrary);
    }

    if (!gLCDSupport && rec->isLCD()) {
      // If the runtime Freetype library doesn't support LCD mode, we disable
      // it here.
      rec->fMaskFormat = SkMask::kA8_Format;
    }

    SkPaint::Hinting h = rec->getHinting();
    if (SkPaint::kFull_Hinting == h && !rec->isLCD()) {
        // collapse full->normal hinting if we're not doing LCD
        h = SkPaint::kNormal_Hinting;
    } else if (rec->fSubpixelPositioning && SkPaint::kNo_Hinting != h) {
        // to do subpixel, we must have at most slight hinting
        h = SkPaint::kSlight_Hinting;
    }
    rec->setHinting(h);
}
Ejemplo n.º 8
0
void gkCleanupFonts()
{
	gkFontRcRef* ref = gkFontResources, *p;
	gkFontFaceEx* face;
	int i;
	while (ref) {
		p = ref;
		for (i = 0; i < p->resource->numFaces; i++) {
			face = (gkFontFaceEx*)p->resource->faces[i];
			FT_Done_Face(face->ftface);
			free(face);
		}
		free(p->resource->faces);
		free(p->resource);
		ref = ref->next;
		free(p);
	}
	gkFontResources = gkFontResourcesTop = 0;
	FT_Done_FreeType(ftlib);
	ftlib = 0;
	cleanupBatch();
}
Ejemplo n.º 9
0
int BLI_vfontchar_from_freetypefont(VFont *vfont, unsigned long character)
{
	int success = FALSE;

	if (!vfont) return FALSE;

	/* Init Freetype */
	err = FT_Init_FreeType(&library);
	if (err) {
		/* XXX error("Failed to load the Freetype font library"); */
		return 0;
	}

	/* Load the character */
	success = objchr_to_ftvfontdata(vfont, character);
	if (success == FALSE) return FALSE;

	/* Free Freetype */
	FT_Done_FreeType(library);

	/* Ahh everything ok */
	return TRUE;
}
Ejemplo n.º 10
0
static av_cold void uninit(AVFilterContext *ctx)
{
    DrawTextContext *s = ctx->priv;
    int i;

    av_expr_free(s->x_pexpr);
    av_expr_free(s->y_pexpr);
    av_expr_free(s->d_pexpr);
    s->x_pexpr = s->y_pexpr = s->d_pexpr = NULL;
    av_freep(&s->expanded_text);
    av_freep(&s->positions);
    av_tree_enumerate(s->glyphs, NULL, NULL, glyph_enu_free);
    av_tree_destroy(s->glyphs);
    s->glyphs = 0;
    FT_Done_Face(s->face);
    FT_Done_FreeType(s->library);

    for (i = 0; i < 4; i++) {
        av_freep(&s->box_line[i]);
        s->pixel_step[i] = 0;
    }

}
Ejemplo n.º 11
0
static void
sushi_font_widget_finalize (GObject *object)
{
  SushiFontWidget *self = SUSHI_FONT_WIDGET (object);

  g_free (self->priv->uri);

  if (self->priv->face != NULL) {
    FT_Done_Face (self->priv->face);
    self->priv->face = NULL;
  }

  g_free (self->priv->font_name);
  g_free (self->priv->sample_string);
  g_free (self->priv->face_contents);

  if (self->priv->library != NULL) {
    FT_Done_FreeType (self->priv->library);
    self->priv->library = NULL;
  }

  G_OBJECT_CLASS (sushi_font_widget_parent_class)->finalize (object);
}
Ejemplo n.º 12
0
/**
 * Construct a new VFontData structure from
 * Freetype font data in a PackedFile.
 *
 * \param pf The font data.
 * \retval A new VFontData structure, or NULL
 * if unable to load.
 */
VFontData *BLI_vfontdata_from_freetypefont(PackedFile *pf)
{
	VFontData *vfd = NULL;
	int success = 0;

	/* init Freetype */
	err = FT_Init_FreeType(&library);
	if (err) {
		/* XXX error("Failed to load the Freetype font library"); */
		return NULL;
	}

	success = check_freetypefont(pf);
	
	if (success) {
		vfd = objfnt_to_ftvfontdata(pf);
	}

	/* free Freetype */
	FT_Done_FreeType(library);
	
	return vfd;
}
Ejemplo n.º 13
0
void SFFontRelease(SFFontRef sfFont) {
    if (!sfFont)
        return;
    
    sfFont->_retainCount--;
    
    if (sfFont->_retainCount == 0) {
        if (sfFont->_parent)
    		SFFontRelease(sfFont->_parent);
    	else {
            
#ifdef SF_IOS_CG
    		CGFontRelease(sfFont->_cgFont);
#else
    		if (sfFont->_ftFace)
    			FT_Done_Face(sfFont->_ftFace);
            
    		if (sfFont->_ftLib)
    			FT_Done_FreeType(sfFont->_ftLib);
#endif
            
    		if (sfFont->_availableFontTables & itCMAP)
    			SFFreeCMAP(&sfFont->_cmap);
            
    		if (sfFont->_availableFontTables & itGDEF)
    			SFFreeGDEF(&sfFont->_gdef);
            
    		if (sfFont->_availableFontTables & itGSUB)
    			SFFreeGSUB(&sfFont->_gsub);
            
    		if (sfFont->_availableFontTables & itGPOS)
    			SFFreeGPOS(&sfFont->_gpos);
    	}
        
        free(sfFont);
    }
}
Ejemplo n.º 14
0
bool FreeType::destroy()
{
	if (_activeTex)
	{
		_activeTex = 0;
	}
	if (_fx)
	{
		_fx->destroy();
//			delete _fx;
		_fx = 0;
	}
	for (size_t i = 0; i != _textures.size(); ++i)
	{
		Texture* t = _textures[i];
		if (t)
		{
			t->destroy();
			delete t;
		}
	}
	_textures.clear();
	CodeTexMap::iterator it = _codeTex.begin();
	for (; it != _codeTex.end(); ++it)
	{
		FTex* t = it->second;
		if (t)
		{
			delete t;
			t = NULL;
		}
	}
	_codeTex.clear();
	FT_Done_Face(_face);
	FT_Done_FreeType(_library);
	return true;
}	
  void
  FTDemo_Done( FTDemo_Handle*  handle )
  {
    int  i;


    if ( !handle )
      return;

    for ( i = 0; i < handle->max_fonts; i++ )
    {
      if ( handle->fonts[i] )
      {
        if ( handle->fonts[i]->filepathname )
          free( (void*)handle->fonts[i]->filepathname );
        free( handle->fonts[i] );
      }
    }
    free( handle->fonts );

    /* string_done */
    for ( i = 0; i < MAX_GLYPHS; i++ )
    {
      PGlyph  glyph = handle->string + i;


      if ( glyph->image )
        FT_Done_Glyph( glyph->image );
    }

    FT_Stroker_Done( handle->stroker );
    FT_Bitmap_Done( handle->library, &handle->bitmap );
    FTC_Manager_Done( handle->cache_manager );
    FT_Done_FreeType( handle->library );

    free( handle );
  }
Ejemplo n.º 16
0
/// @brief Closes the renderer used by the editor
/// @return 0 on failure, non-0 for success
/// @note Tested
int CloseGraphics (void)
{
	Graphics::Main & g = Graphics::Main::Get();

	// Unload all pictures; doing so unloads images, as well.
	while (!g.mPictures.empty())
	{
		UnloadPicture(*g.mPictures.begin());
	}

	// Unload all text images and fonts.
	while (!g.mTextImages.empty())
	{
		UnloadTextImage(*g.mTextImages.begin());
	}

	while (!g.mFaces.empty())
	{
		Graphics::Face * pFace = g.mFaces.begin()->second;

		while (!pFace->mSizes.empty())
		{
			UnloadFont(pFace->mSizes.begin()->second);
		}
	}

	// Close TrueType font support.
	FT_Done_FreeType(g.mFreeType);

	// Close the video subsystem.
	if (SDL_WasInit(SDL_INIT_VIDEO)) SDL_QuitSubSystem(SDL_INIT_VIDEO);

	// Flag the termination
	g.mInit = false;

	return 1;
}
Ejemplo n.º 17
0
Archivo: gui.cpp Proyecto: EQ4/genesis
Gui::~Gui() {
    while (render_jobs.length()) {
        RenderJob *rj = render_jobs.pop();
        destroy_render_job(rj);
    }


    os_mutex_unlock(gui_mutex);

    glfwDestroyCursor(cursor_default);
    glfwDestroyCursor(cursor_ibeam);

    auto it = _font_size_cache.entry_iterator();
    for (;;) {
        auto *entry = it.next();
        if (!entry)
            break;
        FontSize *font_size_object = entry->value;
        destroy(font_size_object, 1);
    }

    FT_Done_Face(_default_font_face);
    FT_Done_FreeType(_ft_library);
}
Ejemplo n.º 18
0
void Font::cleanup()
{
    // Check if we must destroy the FreeType pointers
    if (m_refCount)
    {
        // Decrease the reference counter
        (*m_refCount)--;

        // Free the resources only if we are the last owner
        if (*m_refCount == 0)
        {
            // Delete the reference counter
            delete m_refCount;

            // Destroy the font face
            if (m_face)
                FT_Done_Face(static_cast<FT_Face>(m_face));

            // Destroy the stream rec instance, if any (must be done after FT_Done_Face!)
            if (m_streamRec)
                delete static_cast<FT_StreamRec*>(m_streamRec);

            // Close the library
            if (m_library)
                FT_Done_FreeType(static_cast<FT_Library>(m_library));
        }
    }

    // Reset members
    m_library   = NULL;
    m_face      = NULL;
    m_streamRec = NULL;
    m_refCount  = NULL;
    m_pages.clear();
    m_pixelBuffer.clear();
}
Ejemplo n.º 19
0
void ft_Font_Destroy(void)
{
    if (ft_MEM.pmem)
    {
        free(ft_MEM.pmem);
    }

    if (ft_MEM_SLV.pmem)
    {
        free(ft_MEM_SLV.pmem);
    }

    if(ft_Font_FtFace)
    {
        FT_Done_Face(ft_Font_FtFace);
    }

    if(ft_Font_FTLibrary)
    {
        FT_Done_FreeType(ft_Font_FTLibrary);
    }

    return;
}
Ejemplo n.º 20
0
int cleanupCairo(void *cache) {
    cairoCacheData *ccache = (cairoCacheData*)cache;
    
    if(ccache->dummycr) {
        cairo_destroy(ccache->dummycr);
    }
    if(ccache->dummysurface) {
        cairo_surface_destroy(ccache->dummysurface);
    }
    if(ccache->facecache) {
        faceCacheObj *next,*cur;
        cur = ccache->facecache;
        do {
            next = cur->next;
            freeFaceCache(cur);
            free(cur);
            cur=next;
        } while(cur);
    }
    if(ccache->library)
        FT_Done_FreeType(ccache->library);
    free(ccache);
    return MS_SUCCESS;
}
Ejemplo n.º 21
0
static void
fz_keep_freetype(fz_context *ctx)
{
	int fterr;
	int maj, min, pat;
	fz_font_context *fct = ctx->font;

	fz_lock(ctx, FZ_LOCK_FREETYPE);
	if (fct->ftlib)
	{
		fct->ftlib_refs++;
		fz_unlock(ctx, FZ_LOCK_FREETYPE);
		return;
	}

	fterr = FT_Init_FreeType(&fct->ftlib);
	if (fterr)
	{
		char *mess = ft_error_string(fterr);
		fz_unlock(ctx, FZ_LOCK_FREETYPE);
		fz_throw(ctx, FZ_ERROR_GENERIC, "cannot init freetype: %s", mess);
	}

	FT_Library_Version(fct->ftlib, &maj, &min, &pat);
	if (maj == 2 && min == 1 && pat < 7)
	{
		fterr = FT_Done_FreeType(fct->ftlib);
		if (fterr)
			fz_warn(ctx, "freetype finalizing: %s", ft_error_string(fterr));
		fz_unlock(ctx, FZ_LOCK_FREETYPE);
		fz_throw(ctx, FZ_ERROR_GENERIC, "freetype version too old: %d.%d.%d", maj, min, pat);
	}

	fct->ftlib_refs++;
	fz_unlock(ctx, FZ_LOCK_FREETYPE);
}
Ejemplo n.º 22
0
void blf_font_exit(void)
{
	FT_Done_FreeType(ft_lib);
	BLI_spin_end(&ft_lib_mutex);
}
Ejemplo n.º 23
0
Archivo: library.cpp Proyecto: det/Twil
Library::~Library() noexcept
{
	FT_Done_FreeType(id_);
}
Ejemplo n.º 24
0
// ----------------------------------------------- texture_font_load_glyphs ---
size_t
texture_font_load_glyphs( texture_font_t * self,
                          const wchar_t * charcodes )
{
    assert( self );
    assert( charcodes );

    size_t i, x, y, width, height, depth, w, h;
    FT_Library library;
    FT_Error error;
    FT_Face face;
    FT_Glyph ft_glyph;
    FT_GlyphSlot slot;
    FT_Bitmap ft_bitmap;

    FT_UInt glyph_index;
    texture_glyph_t *glyph;
    ivec4 region;
    size_t missed = 0;
    width  = self->atlas->width;
    height = self->atlas->height;
    depth  = self->atlas->depth;

    region.x=1;
    region.y=1;

#ifdef RENDERSTRING
    stringwidth=0;
    stringheight=0;
    stringshift=0;
#endif

    if( !texture_font_load_face( &library, self->filename, self->size, &face ) )
    {
        return wcslen(charcodes);
    }

    /* Load each glyph */
    for( i=0; i<wcslen(charcodes); ++i )
    {
        glyph_index = FT_Get_Char_Index( face, charcodes[i] );
        // WARNING: We use texture-atlas depth to guess if user wants
        //          LCD subpixel rendering
        FT_Int32 flags = 0;

        if( self->outline_type > 0 )
        {
            flags |= FT_LOAD_NO_BITMAP;
        }
        else
        {
            flags |= FT_LOAD_RENDER;
        }

        if( !self->hinting )
        {
            flags |= FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT;
        }
        else
        {
            flags |= FT_LOAD_FORCE_AUTOHINT;
        }


        if( depth == 3 )
        {
            FT_Library_SetLcdFilter( library, FT_LCD_FILTER_LIGHT );
            flags |= FT_LOAD_TARGET_LCD;
            if( self->filtering )
            {
//                FT_Library_SetLcdFilterWeights( library, self->lcd_weights );
            }
        }
        error = FT_Load_Glyph( face, glyph_index, flags );

        if( error )
        {
            fprintf( stderr, "FT_Error (line %d, code 0x%02x) : %s\n",
                     __LINE__, FT_Errors[error].code, FT_Errors[error].message );
            FT_Done_FreeType( library );
            return wcslen(charcodes)-i;
        }

        int ft_bitmap_width = 0;
        int ft_bitmap_rows = 0;
        int ft_bitmap_pitch = 0;
        int ft_glyph_top = 0;
        int ft_glyph_left = 0;
        if( self->outline_type == 0 )
        {
            slot            = face->glyph;
            ft_bitmap       = slot->bitmap;
            ft_bitmap_width = slot->bitmap.width;
            ft_bitmap_rows  = slot->bitmap.rows;
            ft_bitmap_pitch = slot->bitmap.pitch;
            ft_glyph_top    = slot->bitmap_top;
            ft_glyph_left   = slot->bitmap_left;
        }
        else
        {
            FT_Stroker stroker;
            error = FT_Stroker_New( library, &stroker );
            if( error )
            {
                fprintf(stderr, "FT_Error (0x%02x) : %s\n",
                        FT_Errors[error].code, FT_Errors[error].message);
                return 0;
            }
            FT_Stroker_Set( stroker,
                            (int)(self->outline_thickness *64),
                            FT_STROKER_LINECAP_ROUND,
                            FT_STROKER_LINEJOIN_ROUND,
                            0);
            error = FT_Get_Glyph( face->glyph, &ft_glyph);
            if( error )
            {
                fprintf(stderr, "FT_Error (0x%02x) : %s\n",
                        FT_Errors[error].code, FT_Errors[error].message);
                return 0;
            }

            if( self->outline_type == 1 )
            {
                error = FT_Glyph_Stroke( &ft_glyph, stroker, 1 );
            }
            else if ( self->outline_type == 2 )
            {
                error = FT_Glyph_StrokeBorder( &ft_glyph, stroker, 0, 1 );
            }
            else if ( self->outline_type == 3 )
            {
                error = FT_Glyph_StrokeBorder( &ft_glyph, stroker, 1, 1 );
            }
            if( error )
            {
                fprintf(stderr, "FT_Error (0x%02x) : %s\n",
                        FT_Errors[error].code, FT_Errors[error].message);
                return 0;
            }
          
            if( depth == 1)
            {
                error = FT_Glyph_To_Bitmap( &ft_glyph, FT_RENDER_MODE_NORMAL, 0, 1);
                if( error )
                {
                    fprintf(stderr, "FT_Error (0x%02x) : %s\n",
                            FT_Errors[error].code, FT_Errors[error].message);
                    return 0;
                }
            }
            else
            {
                error = FT_Glyph_To_Bitmap( &ft_glyph, FT_RENDER_MODE_LCD, 0, 1);
                if( error )
                {
                    fprintf(stderr, "FT_Error (0x%02x) : %s\n",
                            FT_Errors[error].code, FT_Errors[error].message);
                    return 0;
                }
            }
            FT_BitmapGlyph ft_bitmap_glyph = (FT_BitmapGlyph) ft_glyph;
            ft_bitmap       = ft_bitmap_glyph->bitmap;
            ft_bitmap_width = ft_bitmap.width;
            ft_bitmap_rows  = ft_bitmap.rows;
            ft_bitmap_pitch = ft_bitmap.pitch;
            ft_glyph_top    = ft_bitmap_glyph->top;
            ft_glyph_left   = ft_bitmap_glyph->left;
            FT_Stroker_Done(stroker);
        }


        // We want each glyph to be separated by at least one black pixel
        // (for example for shader used in demo-subpixel.c)
        w = ft_bitmap_width/depth + 1;
        h = ft_bitmap_rows + 1;

#ifdef RENDERSTRING
        static size_t maxh=0;
        if (charcodes[i]==13) { stringshift+=maxh+1; region.x=1; }
        if (h>maxh) maxh=h;
        //region.y=stringshift+maxh-h+1+(h-ft_glyph_top);
        region.y=stringshift+maxh-ft_glyph_top+1;
       // if (stringshift+h+h-ft_glyph_top+1>stringheight) stringheight=stringshift+h+h-ft_glyph_top+1;
        if (region.y+h>stringheight) stringheight=region.y+h;
        if (region.x+w>stringwidth) stringwidth=region.x+w;
//        if (region.y>=height) { missed++; continue; }
//        if (region.x+w>=width) {missed++; continue; }
       // if (h+h-ft_glyph_top+1>=height) { missed++; continue; }
       // if (h+h-ft_glyph_top+2>=height) { missed++; continue; }
//        if (region.y+maxh>=height) { missed++; continue; }
#else
        region = texture_atlas_get_region( self->atlas, w, h );
        if ( region.x < 0 )
        {
            missed++;
        //    fprintf( stderr, "Texture atlas is full (line %d)\n",  __LINE__ );
            continue;
        }
#endif
        w = w - 1;
        h = h - 1;
        x = region.x;
        y = region.y;
        if (charcodes[i]!=13) {

#ifdef RENDERSTRING
     if (!(x<width)||!((x+w)<=width)||!(y<height)||!((y+h)<=height)) { missed++; continue; }
#endif

          texture_atlas_set_region( self->atlas, x, y, w, h,
                                  ft_bitmap.buffer, ft_bitmap.pitch );
}
        glyph = texture_glyph_new( );
        glyph->charcode = charcodes[i];
        glyph->width    = w;
        glyph->height   = h;
        glyph->outline_type = self->outline_type;
        glyph->outline_thickness = self->outline_thickness;
        glyph->offset_x = ft_glyph_left;
        glyph->offset_y = ft_glyph_top;
        glyph->s0       = x/(float)width;
        glyph->t0       = y/(float)height;
        glyph->s1       = (x + glyph->width)/(float)width;
        glyph->t1       = (y + glyph->height)/(float)height;

        // Discard hinting to get advance
        FT_Load_Glyph( face, glyph_index, FT_LOAD_RENDER | FT_LOAD_NO_HINTING);
        slot = face->glyph;
        glyph->advance_x = slot->advance.x/64.0;
        glyph->advance_y = slot->advance.y/64.0;

#ifdef RENDERSTRING
        if (charcodes[i]!=13) region.x+=(int)glyph->advance_x;
#endif

        vector_push_back( self->glyphs, &glyph );
    }
    if( self->outline_type > 0 )
    {
        FT_Done_Glyph( ft_glyph );
    }
    FT_Done_Face( face );
    FT_Done_FreeType( library );
 //   texture_atlas_upload( self->atlas );
    texture_font_generate_kerning( self );
    return missed;
}
Ejemplo n.º 25
0
// ------------------------------------------------- texture_font_load_face ---
int
texture_font_load_face( FT_Library * library,
                        const char * filename,
                        const float size,
                        FT_Face * face )
{
    assert( library );
    assert( filename );
    assert( size );

    size_t hres = 64;
    FT_Error error;
    FT_Matrix matrix = { (int)((1.0/hres) * 0x10000L),
                         (int)((0.0)      * 0x10000L),
                         (int)((0.0)      * 0x10000L),
                         (int)((1.0)      * 0x10000L) };

    /* Initialize library */
    error = FT_Init_FreeType( library );
    if( error )
    {
        fprintf(stderr, "FT_Error (0x%02x) : %s\n",
                FT_Errors[error].code, FT_Errors[error].message);
        return 0;
    }

    /* Load face */
    error = FT_New_Face( *library, filename, 0, face );
    if( error )
    {
        fprintf( stderr, "FT_Error (line %d, code 0x%02x) : %s\n",
                 __LINE__, FT_Errors[error].code, FT_Errors[error].message);
        FT_Done_FreeType( *library );
        return 0;
    }

    /* Select charmap */
    error = FT_Select_Charmap( *face, FT_ENCODING_UNICODE );
    if( error )
    {
        fprintf( stderr, "FT_Error (line %d, code 0x%02x) : %s\n",
                 __LINE__, FT_Errors[error].code, FT_Errors[error].message );
        FT_Done_Face( *face );
        FT_Done_FreeType( *library );
        return 0;
    }

    /* Set char size */
    error = FT_Set_Char_Size( *face, (int)(size*64), 0, 72*hres, 72 );
    if( error )
    {
        fprintf( stderr, "FT_Error (line %d, code 0x%02x) : %s\n",
                 __LINE__, FT_Errors[error].code, FT_Errors[error].message );
        FT_Done_Face( *face );
        FT_Done_FreeType( *library );
        return 0;
    }

    /* Set transform matrix */
    FT_Set_Transform( *face, &matrix, NULL );

    return 1;
}
Ejemplo n.º 26
0
// ------------------------------------------------------- texture_font_new ---
texture_font_t *
texture_font_new( texture_atlas_t * atlas,
                  const char * filename,
                  const float size)
{
    assert( filename );
    assert( size );

    texture_font_t *self = (texture_font_t *) malloc( sizeof(texture_font_t) );
    if( self == NULL)
    {
        fprintf( stderr,
                 "line %d: No more memory for allocating data\n", __LINE__ );
        exit( EXIT_FAILURE );
    }
    self->glyphs = vector_new( sizeof(texture_glyph_t *) );
    self->atlas = atlas;
    self->height = 0;
    self->ascender = 0;
    self->descender = 0;
    self->filename = strdup( filename );
    self->size = size;
    self->outline_type = 0;
    self->outline_thickness = 0.0;
    self->hinting = 1;
    self->filtering = 1;
    // FT_LCD_FILTER_LIGHT   is (0x00, 0x55, 0x56, 0x55, 0x00)
    // FT_LCD_FILTER_DEFAULT is (0x10, 0x40, 0x70, 0x40, 0x10)
    self->lcd_weights[0] = 0x10;
    self->lcd_weights[1] = 0x40;
    self->lcd_weights[2] = 0x70;
    self->lcd_weights[3] = 0x40;
    self->lcd_weights[4] = 0x10;

    /* Get font metrics at high resolution */
    FT_Library library;
    FT_Face face;
    if( !texture_font_load_face( &library, self->filename, self->size*100, &face ) )
    {
        return self;
    }

    // 64 * 64 because of 26.6 encoding AND the transform matrix used
    // in texture_font_load_face (hres = 64)
    self->underline_position = face->underline_position / (float)(64.0f*64.0f) * self->size;
    self->underline_position = round( self->underline_position );
    if( self->underline_position > -2 )
    {
        self->underline_position = -2.0;
    }

    self->underline_thickness = face->underline_thickness / (float)(64.0f*64.0f) * self->size;
    self->underline_thickness = round( self->underline_thickness );
    if( self->underline_thickness < 1 )
    {
        self->underline_thickness = 1.0;
    }

    FT_Size_Metrics metrics = face->size->metrics; 
    self->ascender = (metrics.ascender >> 6) / 100.0;
    self->descender = (metrics.descender >> 6) / 100.0;
    self->height = (metrics.height >> 6) / 100.0;
    self->linegap = self->height - self->ascender + self->descender;
    FT_Done_Face( face );
    FT_Done_FreeType( library );

    /* -1 is a special glyph */
    texture_font_get_glyph( self, -1 );

    return self;
}
Ejemplo n.º 27
0
int main (int argc, char **argv)
{
	int tv,index,i,j,cmct=CMCT,cmc=CMC,trnspi=TRANSP,trnsp=0,found,loop=1,first=1,x0,x1,x2,x3,x4,x5,x6,x7;
	int xdir=1, ydir=1;
	double xstep=1, ystep=1; 
	double csx, cex, csy, cey;
	time_t atim;
	struct tm *ltim;
	char *aptr,*rptr;
	char dstr[2]={0,0};

		printf("SSaver Version %s\n",CL_VERSION);
		
		ReadConf();
	
		for(i=1; i<argc; i++)
		{
			aptr=argv[i];
			if((rptr=strchr(aptr,'='))!=NULL)
			{
				rptr++;
				if(strstr(aptr,"DATE=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						sdat=j;
					}
				}
				if(strstr(aptr,"BIG=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						big=(j)?1:0;
					}
				}
				if(strstr(aptr,"SEC=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						secs=j;
					}
				}
				if(strstr(aptr,"SLOW=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						if(!j)
						{
							j=1;
						}
						slow=j;
					}
				}
				if(strstr(aptr,"FCOL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						fcol=j;
					}
				}
				if(strstr(aptr,"BCOL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						bcol=j;
					}
				}
			}
		}
		if((sx=Read_Neutrino_Cfg("screen_StartX"))<0)
			sx=80;
		
		if((ex=Read_Neutrino_Cfg("screen_EndX"))<0)
			ex=620;

		if((sy=Read_Neutrino_Cfg("screen_StartY"))<0)
			sy=80;

		if((ey=Read_Neutrino_Cfg("screen_EndY"))<0)
			ey=505;
		
		if(!slow)
		{
			slow=1;
		}	
		if(slow>10)
		{
			slow=10;
		}
		
		xpos=ex/2;
		ypos=ey/2;	
		for(index=CMCST; index<=CMH; index++)
		{
			sprintf(tstr,"menu_%s_alpha",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				tr[index-1]=(tv<<8);

			sprintf(tstr,"menu_%s_blue",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				bl[index-1]=(tv+(tv<<8));

			sprintf(tstr,"menu_%s_green",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				gn[index-1]=(tv+(tv<<8));

			sprintf(tstr,"menu_%s_red",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				rd[index-1]=(tv+(tv<<8));
		}
		
		fb = open(FB_DEVICE, O_RDWR);

		if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1)
		{
			printf("Clock <FBIOGET_FSCREENINFO failed>\n");
			return -1;
		}
		if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1)
		{
			printf("Clock <FBIOGET_VSCREENINFO failed>\n");
			return -1;
		}
		
		if(ioctl(fb, FBIOGETCMAP, &colormap) == -1)
		{
			printf("Clock <FBIOGETCMAP failed>\n");
			return -1;
		}

		if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0)))
		{
			printf("Clock <mapping of Framebuffer failed>\n");
			return -1;
		}

	//init fontlibrary

		if((error = FT_Init_FreeType(&library)))
		{
			printf("Clock <FT_Init_FreeType failed with Errorcode 0x%.2X>", error);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager)))
		{
			printf("Clock <FTC_Manager_New failed with Errorcode 0x%.2X>\n", error);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_SBitCache_New(manager, &cache)))
		{
			printf("Clock <FTC_SBitCache_New failed with Errorcode 0x%.2X>\n", error);
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_Manager_Lookup_Face(manager, FONT, &face)))
		{
			printf("Clock <FTC_Manager_Lookup_Face failed with Errorcode 0x%.2X>\n", error);
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		use_kerning = FT_HAS_KERNING(face);

#ifdef FT_NEW_CACHE_API
		desc.face_id = FONT;
		desc.flags = FT_LOAD_MONOCHROME;
#else
		desc.font.face_id = FONT;
		desc.image_type = ftc_image_mono;
#endif
		if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres)))
		{
			printf("Clock <allocating of Backbuffer failed>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		memset(lbb, 0, var_screeninfo.xres*var_screeninfo.yres);

		startx = sx;
		starty = sy;
		xstep/=(double)slow;
		ystep/=(double)slow;
		
		InitRC();

	while(loop)
	{
		usleep(15000L);
		ioctl(fb, FBIOGETCMAP, &colormap);
		found=0;
		trnsp=0;
		for(i=colormap.start;i<colormap.len && found!=7;i++)
		{
			if(!colormap.red[i] && !colormap.green[i] && !colormap.blue[i] && !colormap.transp[i])
			{
				cmc=i;
				found|=1;
			}
			if(colormap.red[i]>=0xF000 && colormap.green[i]>=0xF000  && colormap.blue[i]>=0xF000 && !colormap.transp[i])
			{
				cmct=i;
				found|=2;
			}
			if(colormap.transp[i]>trnsp)
			{
				trnspi=i;
				trnsp=colormap.transp[i];
				found|=4;
			}
		}
		if(first)
		{
			first=0;
			memset(lbb, (bcol==0)?trnspi:((bcol==1)?cmc:cmct), var_screeninfo.xres*var_screeninfo.yres);
			memset(lfb, (bcol==0)?trnspi:((bcol==1)?cmc:cmct), var_screeninfo.xres*var_screeninfo.yres);
		}
		if(big)
		{
			x0=3;
			x1=14;
			x2=26;
			x3=BIG;
			x4=30;
			x5=60;
		}
		else
		{
			x0=7;
			x1=12;
			x2=18;
			x3=MED;
			x4=18;
			x5=40;
		}
		x6=0;
		x7=0;
		time(&atim);
		ltim=localtime(&atim);
		if(secs)
		{
			sprintf(tstr,"%02d:%02d:%02d",ltim->tm_hour,ltim->tm_min,ltim->tm_sec);
		}
		else
		{
			sprintf(tstr,"   %02d%c%02d",ltim->tm_hour,(ltim->tm_sec & 1)?':':' ',ltim->tm_min);
			if(!sdat)
			{
				x6=3;
				x7=36+4*big;
			}
		}

		xpos+=xstep*(double)xdir;
		ypos+=ystep*(double)ydir;

		csx=xpos+x7;
		csy=ypos;
		cex=xpos+x7+100+20*big;
		cey=ypos+x2+2*(1+big)+sdat*x4;
		if(csx<0 || (sx+cex)>=ex)
		{
			xdir*=-1;
			xpos+=xstep*(double)xdir;
			csx=xpos+x7;
			cex=xpos+x7+100+20*big;
			xstep=rand()&3;
			if(!xstep)
			{
				xstep=1;
			}
			xstep/=(double)slow;
		}
		if(csy<0 || (sy+cey)>=ey)
		{
			ydir*=-1;
			ypos+=ystep*(double)ydir;
			csy=ypos;
			cey=ypos+x2+2*(1+big)+sdat*x4;
			ystep=rand()&3;
			if(!ystep || (ystep==3 && ydir==1))
			{
				ystep=1;
			}
			ystep/=(double)slow;
		}

		for(i=x6; i<strlen(tstr); i++)
		{
			*dstr=tstr[i];
			RenderString(dstr, xpos-x0+(i*x1), ypos+x2, 30, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc));
		}

		if(sdat)
		{
			sprintf(tstr,"%02d.%02d.%02d",ltim->tm_mday,ltim->tm_mon+1,ltim->tm_year-100);
			for(i=0; i<strlen(tstr); i++)
			{
				*dstr=tstr[i];
				RenderString(dstr, xpos-x0+(i*x1), ypos+x5-2-2*big, 30, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc));
			}
		}

		for(i=0;i<=((sdat)?40:20)*(1+big);i++)
		{
			j=(starty+ypos+i)*var_screeninfo.xres+xpos+startx;
			if((j+100+20*big)<var_screeninfo.xres*var_screeninfo.yres)
			{
				memcpy(lfb+j, lbb+j, 100+20*big);
			}
		}
		
		RenderBox(csx, csy, cex, cey, FILL, (bcol==0)?trnspi:((bcol==1)?cmc:cmct));

		if(++loop>10)
		{
			if(RCKeyPressed()||ExistFile("/tmp/.ssaver_kill"))
			{
				loop=0;
			}
		}	
	}	

	cmct=0;
	cmc=0;
	for(i=colormap.start;i<colormap.len;i++)
	{
		if(colormap.transp[i]>cmct)
		{
			cmc=i;
			cmct=colormap.transp[i];
		}
	}
	memset(lfb, cmc, var_screeninfo.xres*var_screeninfo.yres);
	FTC_Manager_Done(manager);
	FT_Done_FreeType(library);

	free(lbb);
	munmap(lfb, fix_screeninfo.smem_len);

	close(fb);
	CloseRC();
	remove("/tmp/.ssaver_kill");
	return 0;
}
Ejemplo n.º 28
0
n2dFontImpl::~n2dFontImpl()
{
	FT_Done_Face(m_pFTFace);
	FT_Done_FreeType(m_pFTLib);
}
Ejemplo n.º 29
0
 void tearDownFreetype()
 {
     FT_Done_Face( face);
     FT_Done_FreeType( library);
 }
void TextRenderer::initRenderData()
{
	// FreeType
	FT_Library ft;

	// All functions return a value different than 0 whenever an error occurred
	if (FT_Init_FreeType(&ft))
		std::cout << "ERROR::FREETYPE: Could not init FreeType Library" << std::endl;

	// Load font as face
	FT_Face face;
	if (FT_New_Face(ft, Constants::fontFilePath.c_str(), 0, &face))
		std::cout << "ERROR::FREETYPE: Failed to load font" << std::endl;

	// Set size to load glyphs as
	FT_Set_Pixel_Sizes(face, 0, 48);

	// Disable byte-alignment restriction
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	// Load first 128 characters of ASCII set
	for (GLubyte c = 0; c < 128; c++)
	{
		// Load character glyph 
		if (FT_Load_Char(face, c, FT_LOAD_RENDER))
		{
			std::cout << "ERROR::FREETYTPE: Failed to load Glyph" << std::endl;
			continue;
		}
		// Generate texture
		GLuint texture;
		glGenTextures(1, &texture);
		glBindTexture(GL_TEXTURE_2D, texture);
		glTexImage2D(
			GL_TEXTURE_2D,
			0,
			GL_RED,
			face->glyph->bitmap.width,
			face->glyph->bitmap.rows,
			0,
			GL_RED,
			GL_UNSIGNED_BYTE,
			face->glyph->bitmap.buffer
			);
		// Set texture options
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		// Now store character for later use
		Character character = {
			texture,
			glm::ivec2(face->glyph->bitmap.width, face->glyph->bitmap.rows),
			glm::ivec2(face->glyph->bitmap_left, face->glyph->bitmap_top),
			face->glyph->advance.x
		};
		Characters.insert(std::pair<GLchar, Character>(c, character));
	}
	glBindTexture(GL_TEXTURE_2D, 0);
	// Destroy FreeType once we're finished
	FT_Done_Face(face);
	FT_Done_FreeType(ft);


	// Configure VAO/VBO for texture quads
	glGenVertexArrays(1, &VAO);
	glGenBuffers(1, &VBO);
	glBindVertexArray(VAO);
	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 6 * 4, NULL, GL_DYNAMIC_DRAW);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), 0);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindVertexArray(0);
}