forked from minhngoc25a/freetype2
Trying to get it to work attempt #1
This commit is contained in:
parent
e66db7ec5c
commit
43a66f774c
|
@ -9,6 +9,7 @@
|
||||||
#include <freetype/internal/ftdebug.h>
|
#include <freetype/internal/ftdebug.h>
|
||||||
#include <freetype/internal/ftobjs.h>
|
#include <freetype/internal/ftobjs.h>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
#include "ftdenseerrs.h"
|
#include "ftdenseerrs.h"
|
||||||
|
|
||||||
typedef struct dense_TRaster_
|
typedef struct dense_TRaster_
|
||||||
|
@ -30,7 +31,6 @@ static int
|
||||||
dense_move_to( const FT_Vector* to, RasterFP* aRasterFP )
|
dense_move_to( const FT_Vector* to, RasterFP* aRasterFP )
|
||||||
{
|
{
|
||||||
RasterFP_Point lp = { to->x, to->y };
|
RasterFP_Point lp = { to->x, to->y };
|
||||||
|
|
||||||
aRasterFP->last_point = lp;
|
aRasterFP->last_point = lp;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,8 @@ dense_line_to( const FT_Vector* to, RasterFP* aRasterFP )
|
||||||
void
|
void
|
||||||
RasterFP_DrawLine( RasterFP* aRasterFP, RasterFP_Point aP0, RasterFP_Point aP1 )
|
RasterFP_DrawLine( RasterFP* aRasterFP, RasterFP_Point aP0, RasterFP_Point aP1 )
|
||||||
{
|
{
|
||||||
|
// printf( "\n%f\n", aRasterFP->m_w );
|
||||||
|
// printf( "\n%f\n", aRasterFP->m_h );
|
||||||
// assert( aRasterFP );
|
// assert( aRasterFP );
|
||||||
if ( aP0.m_y == aP1.m_y )
|
if ( aP0.m_y == aP1.m_y )
|
||||||
return;
|
return;
|
||||||
|
@ -139,6 +141,13 @@ RasterFP_DrawLine( RasterFP* aRasterFP, RasterFP_Point aP0, RasterFP_Point aP1 )
|
||||||
int y0 = (int)aP0.m_y;
|
int y0 = (int)aP0.m_y;
|
||||||
int y_limit = (int)ceil( aP1.m_y );
|
int y_limit = (int)ceil( aP1.m_y );
|
||||||
float* m_a = aRasterFP->m_a;
|
float* m_a = aRasterFP->m_a;
|
||||||
|
|
||||||
|
// printf( "%f\n", x );
|
||||||
|
// printf( "%d\n", y0 );
|
||||||
|
// printf( "%d\n", y_limit );
|
||||||
|
// printf( "%p\n", m_a );
|
||||||
|
|
||||||
|
|
||||||
for ( int y = y0; y < y_limit; y++ )
|
for ( int y = y0; y < y_limit; y++ )
|
||||||
{
|
{
|
||||||
int linestart = y * aRasterFP->m_w;
|
int linestart = y * aRasterFP->m_w;
|
||||||
|
@ -197,6 +206,7 @@ RasterFP_DrawLine( RasterFP* aRasterFP, RasterFP_Point aP0, RasterFP_Point aP1 )
|
||||||
}
|
}
|
||||||
x = xnext;
|
x = xnext;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -341,7 +351,6 @@ dense_raster_new( FT_Memory memory, dense_PRaster* araster )
|
||||||
raster->memory = memory;
|
raster->memory = memory;
|
||||||
|
|
||||||
*araster = raster;
|
*araster = raster;
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,9 +394,9 @@ FT_DEFINE_OUTLINE_FUNCS( dense_decompose_funcs,
|
||||||
)
|
)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dense_render_glyph( RasterFP* aRasterFP, FT_Bitmap* target )
|
dense_render_glyph( RasterFP* aRasterFP, const FT_Bitmap* target )
|
||||||
{
|
{
|
||||||
FT_Error error = FT_Outline_Decompose( aRasterFP->outline,
|
FT_Error error = FT_Outline_Decompose( &(aRasterFP->outline),
|
||||||
&dense_decompose_funcs, aRasterFP );
|
&dense_decompose_funcs, aRasterFP );
|
||||||
|
|
||||||
// Render into bitmap
|
// Render into bitmap
|
||||||
|
@ -418,6 +427,8 @@ dense_raster_render( FT_Raster raster, const FT_Raster_Params* params )
|
||||||
const FT_Outline* outline = (const FT_Outline*)params->source;
|
const FT_Outline* outline = (const FT_Outline*)params->source;
|
||||||
const FT_Bitmap* target_map = params->target;
|
const FT_Bitmap* target_map = params->target;
|
||||||
|
|
||||||
|
printf( "Rasterizing glyph" );
|
||||||
|
|
||||||
RasterFP* aRasterFP = malloc( sizeof( RasterFP ) );
|
RasterFP* aRasterFP = malloc( sizeof( RasterFP ) );
|
||||||
|
|
||||||
if ( !raster )
|
if ( !raster )
|
||||||
|
@ -426,7 +437,7 @@ dense_raster_render( FT_Raster raster, const FT_Raster_Params* params )
|
||||||
if ( !outline )
|
if ( !outline )
|
||||||
return FT_THROW( Invalid_Outline );
|
return FT_THROW( Invalid_Outline );
|
||||||
|
|
||||||
aRasterFP->outline = outline;
|
aRasterFP->outline = *outline;
|
||||||
|
|
||||||
if ( !target_map )
|
if ( !target_map )
|
||||||
return FT_THROW( Invalid_Argument );
|
return FT_THROW( Invalid_Argument );
|
||||||
|
@ -438,16 +449,27 @@ dense_raster_render( FT_Raster raster, const FT_Raster_Params* params )
|
||||||
if ( !target_map->buffer )
|
if ( !target_map->buffer )
|
||||||
return FT_THROW( Invalid_Argument );
|
return FT_THROW( Invalid_Argument );
|
||||||
|
|
||||||
|
|
||||||
aRasterFP->m_origin_x = 0;
|
aRasterFP->m_origin_x = 0;
|
||||||
aRasterFP->m_origin_y = 0;
|
aRasterFP->m_origin_y = 0;
|
||||||
aRasterFP->m_w = (float)target_map->width;
|
aRasterFP->m_w = target_map->pitch;
|
||||||
aRasterFP->m_h = (float)target_map->rows;
|
aRasterFP->m_h = target_map->rows;
|
||||||
|
|
||||||
|
int size = aRasterFP->m_w * aRasterFP->m_h + 4;
|
||||||
|
|
||||||
|
aRasterFP->m_a = realloc(aRasterFP, sizeof(float) * size);
|
||||||
|
if ( aRasterFP->m_a == NULL )
|
||||||
|
{
|
||||||
|
memset( aRasterFP, 0, sizeof( RasterFP ) );
|
||||||
|
}
|
||||||
|
aRasterFP->m_a_size = size;
|
||||||
|
|
||||||
|
memset( aRasterFP->m_a, 0, sizeof( float ) * size );
|
||||||
|
|
||||||
/* exit if nothing to do */
|
/* exit if nothing to do */
|
||||||
if ( aRasterFP->m_w <= aRasterFP->m_origin_x ||
|
if ( aRasterFP->m_w <= aRasterFP->m_origin_x ||
|
||||||
aRasterFP->m_h <= aRasterFP->m_origin_y )
|
aRasterFP->m_h <= aRasterFP->m_origin_y )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return dense_render_glyph( aRasterFP, target_map );
|
return dense_render_glyph( aRasterFP, target_map );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,15 +108,10 @@ extern "C"
|
||||||
|
|
||||||
RasterFP_Point last_point;
|
RasterFP_Point last_point;
|
||||||
|
|
||||||
FT_Outline *outline;
|
FT_Outline outline;
|
||||||
} RasterFP;
|
} RasterFP;
|
||||||
|
|
||||||
void RasterFP_Create( RasterFP* aRasterFP );
|
void RasterFP_Create( RasterFP* aRasterFP );
|
||||||
void RasterFP_StartRasterizing( RasterFP* aRasterFP,
|
|
||||||
int aOriginX,
|
|
||||||
int aOriginY,
|
|
||||||
int aWidth,
|
|
||||||
int aHeight );
|
|
||||||
void RasterFP_Destroy( RasterFP* aRasterFP );
|
void RasterFP_Destroy( RasterFP* aRasterFP );
|
||||||
void RasterFP_DrawLine( RasterFP* aRasterFP,
|
void RasterFP_DrawLine( RasterFP* aRasterFP,
|
||||||
RasterFP_Point aP0,
|
RasterFP_Point aP0,
|
||||||
|
|
|
@ -30,13 +30,11 @@
|
||||||
static FT_Error
|
static FT_Error
|
||||||
ft_dense_init( FT_Renderer render )
|
ft_dense_init( FT_Renderer render )
|
||||||
{
|
{
|
||||||
FT_Renderer dense_render = render;
|
|
||||||
|
|
||||||
// dense_render->spread = 0;
|
// dense_render->spread = 0;
|
||||||
// dense_render->flip_sign = 0;
|
// dense_render->flip_sign = 0;
|
||||||
// dense_render->flip_y = 0;
|
// dense_render->flip_y = 0;
|
||||||
// dense_render->overlaps = 0;
|
// dense_render->overlaps = 0;
|
||||||
|
|
||||||
return FT_Err_Ok;
|
return FT_Err_Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,33 +86,34 @@ ft_dense_render( FT_Renderer render,
|
||||||
if ( !bitmap->rows || !bitmap->pitch )
|
if ( !bitmap->rows || !bitmap->pitch )
|
||||||
goto Exit;
|
goto Exit;
|
||||||
|
|
||||||
/* ignore the pitch, pixel mode and set custom */
|
|
||||||
bitmap->pixel_mode = FT_PIXEL_MODE_GRAY;
|
|
||||||
bitmap->pitch = bitmap->width;
|
|
||||||
bitmap->num_grays = 255;
|
|
||||||
|
|
||||||
|
|
||||||
/* allocate new one */
|
/* allocate new one */
|
||||||
if ( FT_ALLOC_MULT( bitmap->buffer, bitmap->rows, bitmap->pitch ) )
|
|
||||||
goto Exit;
|
|
||||||
/* the padding will simply be equal to the `spread' */
|
|
||||||
x_shift = 64 * -slot->bitmap_left;
|
|
||||||
y_shift = 64 * -slot->bitmap_top;
|
|
||||||
|
|
||||||
|
// if ( FT_ALLOC_MULT( bitmap->buffer, bitmap->rows, bitmap->pitch ) )
|
||||||
|
// goto Exit;
|
||||||
|
|
||||||
|
// For whatever reason, it segfaults if the above is used for allocation
|
||||||
|
bitmap->buffer = realloc(bitmap->buffer, sizeof(int) * bitmap->rows * bitmap->pitch);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* the padding will simply be equal to the `spread' */
|
||||||
|
// x_shift = 64 * -slot->bitmap_left;
|
||||||
|
// y_shift = 64 * -slot->bitmap_top;
|
||||||
|
|
||||||
|
|
||||||
slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
|
slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
|
||||||
y_shift += 64 * (FT_Int)bitmap->rows;
|
// y_shift += 64 * (FT_Int)bitmap->rows;
|
||||||
|
|
||||||
if ( origin )
|
// if ( origin )
|
||||||
{
|
// {
|
||||||
x_shift += origin->x;
|
// x_shift += origin->x;
|
||||||
y_shift += origin->y;
|
// y_shift += origin->y;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/* translate outline to render it into the bitmap */
|
// /* translate outline to render it into the bitmap */
|
||||||
if ( x_shift || y_shift )
|
// if ( x_shift || y_shift )
|
||||||
FT_Outline_Translate( outline, x_shift, y_shift );
|
// FT_Outline_Translate( outline, x_shift, y_shift );
|
||||||
|
|
||||||
/* set up parameters */
|
/* set up parameters */
|
||||||
params.target = bitmap;
|
params.target = bitmap;
|
||||||
|
|
Loading…
Reference in New Issue