Commit 7b96f5ad authored by Nicolas.Rougier's avatar Nicolas.Rougier

Added the outline feature (see demo-outline)

parent dbb35d5e
......@@ -55,7 +55,12 @@
* Updated in 2011 to avoid a corner case infinite loop.
*
*/
#ifndef __EDTAA3FUNC_H__
#define __EDTAA3FUNC_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <math.h>
......@@ -86,3 +91,10 @@ double distaa3(double *img, double *gximg, double *gyimg, int w, int c, int xc,
#define DISTAA(c,xc,yc,xi,yi) (distaa3(img, gx, gy, w, c, xc, yc, xi, yi))
void edtaa3(double *img, double *gx, double *gy, int w, int h, short *distx, short *disty, double *dist);
#ifdef __cplusplus
}
#endif
#endif // __EDTAA3FUNC_H__
......@@ -88,6 +88,33 @@ font_manager_delete( font_manager_t * self )
free( self );
}
// ----------------------------------------------- font_manager_delete_font ---
void
font_manager_delete_font( font_manager_t * self,
texture_font_t * font)
{
size_t i;
assert( self );
assert( font );
texture_font_t *other;
for( i=0; i<self->fonts->size;++i )
{
other = (texture_font_t *) vector_get( self->fonts, i );
if ( (strcmp(font->filename, other->filename) == 0)
&& ( font->size == other->size) )
{
vector_erase( self->fonts, i);
break;
}
}
texture_font_delete( font );
}
// ----------------------------------------- font_manager_get_from_filename ---
texture_font_t *
font_manager_get_from_filename( font_manager_t *self,
......
......@@ -33,12 +33,18 @@
*/
#ifndef __FONT_MANAGER_H__
#define __FONT_MANAGER_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "vector.h"
#include "markup.h"
#include "texture-font.h"
#include "texture-atlas.h"
/**
*
*/
......@@ -76,6 +82,14 @@ typedef struct {
font_manager_delete( font_manager_t *self );
/**
*
*/
void
font_manager_delete_font( font_manager_t * self,
texture_font_t * font );
/**
*
*/
......@@ -129,5 +143,9 @@ typedef struct {
font_manager_set_cache( font_manager_t * self,
const wchar_t * cache );
#ifdef __cplusplus
}
#endif // ifdef __cplusplus
#endif /* __FONT_MANAGER_H__ */
......@@ -33,6 +33,10 @@
#ifndef __MARKUP_H__
#define __MARKUP_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "texture-font.h"
#include "vec234.h"
......@@ -209,4 +213,8 @@ vec4 markup_get_strikethrough_color( const markup_t *self );
void markup_set_strikethrough_color( markup_t *self,
const vec4 * color );
#ifdef __cplusplus
}
#endif
#endif /* __MARKUP_H__ */
......@@ -43,6 +43,11 @@
*/
#ifndef __TEXTURE_ATLAS_H__
#define __TEXTURE_ATLAS_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "vector.h"
#include "vec234.h"
......@@ -149,4 +154,9 @@ typedef struct
void
texture_atlas_clear( texture_atlas_t * self );
#ifdef __cplusplus
}
#endif
#endif /* __TEXTURE_ATLAS_H__ */
......@@ -137,6 +137,8 @@ texture_glyph_new( void )
self->id = 0;
self->width = 0;
self->height = 0;
self->outline_type = 0;
self->outline_thickness = 0.0;
self->offset_x = 0;
self->offset_y = 0;
self->advance_x = 0.0;
......@@ -238,8 +240,6 @@ texture_font_new( texture_atlas_t * atlas,
assert( filename );
assert( size );
const float thickness = .2;
texture_font_t *self = (texture_font_t *) malloc( sizeof(texture_font_t) );
if( self == NULL)
{
......@@ -254,7 +254,8 @@ texture_font_new( texture_atlas_t * atlas,
self->descender = 0;
self->filename = strdup( filename );
self->size = size;
self->thickness = thickness;
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)
......@@ -356,7 +357,7 @@ texture_font_load_glyphs( texture_font_t * self,
// LCD subpixel rendering
FT_Int32 flags = 0;
if( self->thickness > 0 )
if( self->outline_type > 0 )
{
flags |= FT_LOAD_NO_BITMAP;
}
......@@ -399,7 +400,7 @@ texture_font_load_glyphs( texture_font_t * self,
int ft_bitmap_pitch = 0;
int ft_glyph_top = 0;
int ft_glyph_left = 0;
if( self->thickness == 0 )
if( self->outline_type == 0 )
{
slot = face->glyph;
ft_bitmap = slot->bitmap;
......@@ -420,7 +421,7 @@ texture_font_load_glyphs( texture_font_t * self,
return 0;
}
FT_Stroker_Set( stroker,
(int)(self->thickness *64),
(int)(self->outline_thickness *64),
FT_STROKER_LINECAP_ROUND,
FT_STROKER_LINEJOIN_ROUND,
0);
......@@ -432,9 +433,19 @@ texture_font_load_glyphs( texture_font_t * self,
return 0;
}
//FT_Glyph_StrokeBorder( &ft_glyph, stroker, 0, 1 );
FT_Glyph_Stroke( &ft_glyph, stroker, 1 );
if( self->outline_type == 1 )
{
FT_Glyph_Stroke( &ft_glyph, stroker, 1 );
}
else if ( self->outline_type == 2 )
{
FT_Glyph_StrokeBorder( &ft_glyph, stroker, 0, 1 );
}
else if ( self->outline_type == 3 )
{
FT_Glyph_StrokeBorder( &ft_glyph, stroker, 1, 1 );
}
if( depth == 1)
{
error = FT_Glyph_To_Bitmap( &ft_glyph, FT_RENDER_MODE_NORMAL, 0, 1);
......@@ -488,6 +499,8 @@ texture_font_load_glyphs( texture_font_t * self,
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;
......@@ -508,8 +521,8 @@ texture_font_load_glyphs( texture_font_t * self,
free( glyph );
}
// FT_Done_Glyph(ft_glyph);
// if( self->outline_thickness )
// FT_Done_Glyph( ft_glyph );
FT_Done_Face( face );
FT_Done_FreeType( library );
texture_atlas_upload( self->atlas );
......@@ -537,7 +550,9 @@ texture_font_get_glyph( texture_font_t * self,
for( i=0; i<self->glyphs->size; ++i )
{
glyph = (texture_glyph_t *) vector_get( self->glyphs, i );
if( glyph->charcode == charcode )
if( (glyph->charcode == charcode) &&
(glyph->outline_type == self->outline_type) &&
(glyph->outline_thickness == self->outline_thickness) )
{
return glyph;
}
......@@ -550,10 +565,12 @@ texture_font_get_glyph( texture_font_t * self,
{
size_t width = self->atlas->width;
size_t height = self->atlas->height;
ivec4 region = texture_atlas_get_region( self->atlas, 4, 4 );
ivec4 region = texture_atlas_get_region( self->atlas, 5, 5 );
texture_glyph_t * glyph = texture_glyph_new( );
static unsigned char data[4*3] = {-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1};
static unsigned char data[4*4*3] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
if ( region.x < 0 )
{
fprintf( stderr, "Texture atlas is full (line %d)\n", __LINE__ );
......
......@@ -33,6 +33,11 @@
*/
#ifndef __TEXTURE_FONT_H__
#define __TEXTURE_FONT_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "vector.h"
#include "texture-atlas.h"
......@@ -170,6 +175,16 @@ typedef struct
*/
vector_t * kerning;
/**
* Glyph outline type (0 = None, 1 = line, 2 = inner, 3 = outer)
*/
int outline_type;
/**
* Glyph outline thickness
*/
float outline_thickness;
} texture_glyph_t;
......@@ -204,10 +219,15 @@ typedef struct
*/
int hinting;
/**
* Outline type (0 = None, 1 = line, 2 = inner, 3 = outer)
*/
int outline_type;
/**
* Outline thickness
*/
float thickness;
float outline_thickness;
/**
* Whether to use our own lcd filter.
......@@ -273,6 +293,17 @@ typedef struct
/**
* This function creates a new texture font from given filename and size. The
* texture atlas is used to store glyph on demand. Note the depth of the atlas
* will determine if the font is rendered as alpha channel only (depth = 1) or
* RGB (depth = 3) that correspond to subpixel rendering (if available on your
* freetype implementation).
*
* @param atlas A texture atlas
* @param filename A font filename
* @param size Size of font to be created (in points)
*
* @return A new empty font (no glyph inside yet)
*
*/
texture_font_t *
......@@ -282,13 +313,24 @@ typedef struct
/**
* Delete a texture font. Note that this does not delete the glyph from the
* texture atlas.
*
* @param self a valid texture font
*/
void
texture_font_delete( texture_font_t * self );
/**
* Request a new glyph from the font. If it has not been created yet, it will
* be.
*
* @param self A valid texture font
* @param charcode Character codepoint to be loaded.
*
* @return A pointer on the new glyph or 0 if the texture atlas is not big
* enough
*
*/
texture_glyph_t *
......@@ -297,20 +339,34 @@ typedef struct
/**
* Request the loading of several glyphs at once.
*
* @param self A valid texture font
* @param charcode Character codepoints to be loaded.
*
* @return Number of missed glyph if the texture is not big enough to hold
* every glyphs.
*/
size_t
texture_font_load_glyphs( texture_font_t * self,
const wchar_t * charcodes );
/**
* Get the kerning between two horizontal glyphs.
*
* @param self a valid texture glyph
* @param charcode codepoint of the peceding glyph
*
* @return x kerning value
*/
float
texture_glyph_get_kerning( const texture_glyph_t * self,
const wchar_t charcode );
#ifdef __cplusplus
}
#endif
#endif /* __TEXTURE_FONT_H__ */
......@@ -30,10 +30,15 @@
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of Nicolas P. Rougier.
* ========================================================================= */
#pragma once
#ifndef __VEC234_H__
#define __VEC234_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* Tuple of 4 floats
*/
......@@ -121,4 +126,9 @@ typedef union
struct { int luminance; int alpha; };
} ivec2;
#ifdef __cplusplus
}
#endif
#endif /* __VEC234_H__ */
......@@ -33,6 +33,9 @@
#ifndef __VECTOR_H__
#define __VECTOR_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
......@@ -279,4 +282,8 @@ typedef struct
vector_sort( vector_t *self,
int (*cmp)(const void *, const void *) );
#ifdef __cplusplus
}
#endif
#endif /* __VECTOR_H__ */
......@@ -32,6 +32,11 @@
* ========================================================================= */
#ifndef __VERTEX_BUFFER_H__
#define __VERTEX_BUFFER_H__
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#else
......@@ -467,5 +472,8 @@ vertex_attribute_new( GLenum target,
char *
GL_TYPE_STRING( GLenum gtype );
#ifdef __cplusplus
}
#endif
#endif /* __VERTEX_BUFFER_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment