forked from minhngoc25a/freetype2
Integration prototype successful
This commit is contained in:
parent
43a66f774c
commit
44892f8212
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"ftoutln.h": "c",
|
"ftoutln.h": "c",
|
||||||
"svprop.h": "c"
|
"svprop.h": "c",
|
||||||
|
"ftdebug.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -97,6 +97,8 @@ RASTER_MODULES += dense
|
||||||
# Anti-aliasing rasterizer.
|
# Anti-aliasing rasterizer.
|
||||||
RASTER_MODULES += smooth
|
RASTER_MODULES += smooth
|
||||||
|
|
||||||
|
# RASTER_MODULES += dense
|
||||||
|
|
||||||
# Monochrome rasterizer.
|
# Monochrome rasterizer.
|
||||||
RASTER_MODULES += raster
|
RASTER_MODULES += raster
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,16 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "ftdenseerrs.h"
|
#include "ftdenseerrs.h"
|
||||||
|
|
||||||
|
#define PIXEL_BITS 8
|
||||||
|
|
||||||
|
#define ONE_PIXEL ( 1 << PIXEL_BITS )
|
||||||
|
#define TRUNC( x ) ( int )( ( x ) >> PIXEL_BITS )
|
||||||
|
#define FRACT( x ) ( int )( ( x ) & ( ONE_PIXEL - 1 ) )
|
||||||
|
|
||||||
|
#define UPSCALE( x ) ( ( x ) * ( ONE_PIXEL >> 6 ) )
|
||||||
|
#define DOWNSCALE( x ) ( ( x ) >> ( PIXEL_BITS - 6 ) )
|
||||||
|
|
||||||
|
|
||||||
typedef struct dense_TRaster_
|
typedef struct dense_TRaster_
|
||||||
{
|
{
|
||||||
void* memory;
|
void* memory;
|
||||||
|
@ -30,19 +40,23 @@ Lerp( float aT, RasterFP_Point aP0, RasterFP_Point aP1 )
|
||||||
static int
|
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 };
|
FT_Pos x, y;
|
||||||
aRasterFP->last_point = lp;
|
|
||||||
|
x = UPSCALE( to->x );
|
||||||
|
y = UPSCALE( to->y );
|
||||||
|
aRasterFP->prev_x = x;
|
||||||
|
aRasterFP->prev_y = y;
|
||||||
|
//printf( "last point is {%f, %f}", lp.m_x, lp.m_y );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dense_line_to( const FT_Vector* to, RasterFP* aRasterFP )
|
dense_line_to( const FT_Vector* to, RasterFP* aRasterFP )
|
||||||
{
|
{
|
||||||
RasterFP_Point tp = { to->x, to->y };
|
RasterFP_Point tp = {UPSCALE(to->x), UPSCALE(to->y)};
|
||||||
RasterFP_DrawLine( aRasterFP, aRasterFP->last_point, tp );
|
RasterFP_Point lp = {aRasterFP->prev_x, aRasterFP->prev_y};
|
||||||
|
RasterFP_DrawLine( aRasterFP, lp, tp );
|
||||||
|
dense_move_to( to, aRasterFP );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,11 +68,18 @@ RasterFP_DrawLine( RasterFP* aRasterFP, RasterFP_Point aP0, RasterFP_Point aP1 )
|
||||||
// assert( aRasterFP );
|
// assert( aRasterFP );
|
||||||
if ( aP0.m_y == aP1.m_y )
|
if ( aP0.m_y == aP1.m_y )
|
||||||
return;
|
return;
|
||||||
|
// aP0.m_x -= aRasterFP->m_origin_x;
|
||||||
|
// aP0.m_y -= aRasterFP->m_origin_y;
|
||||||
|
// aP1.m_x -= aRasterFP->m_origin_x;
|
||||||
|
// aP1.m_y -= aRasterFP->m_origin_y;
|
||||||
|
|
||||||
aP0.m_x -= aRasterFP->m_origin_x;
|
aP0.m_x = TRUNC((int)aP0.m_x );
|
||||||
aP0.m_y -= aRasterFP->m_origin_y;
|
aP0.m_y = TRUNC((int)aP0.m_y );
|
||||||
aP1.m_x -= aRasterFP->m_origin_x;
|
aP1.m_x = TRUNC((int)aP1.m_x );
|
||||||
aP1.m_y -= aRasterFP->m_origin_y;
|
aP1.m_y = TRUNC((int)aP1.m_y );
|
||||||
|
|
||||||
|
// printf( "Drawing a line from {%f, %f} to {%f, %f}\n", aP0.m_x, aP0.m_y,
|
||||||
|
// aP1.m_x, aP1.m_y );
|
||||||
|
|
||||||
float dir;
|
float dir;
|
||||||
if ( aP0.m_y < aP1.m_y )
|
if ( aP0.m_y < aP1.m_y )
|
||||||
|
@ -146,8 +167,8 @@ RasterFP_DrawLine( RasterFP* aRasterFP, RasterFP_Point aP0, RasterFP_Point aP1 )
|
||||||
// printf( "%d\n", y0 );
|
// printf( "%d\n", y0 );
|
||||||
// printf( "%d\n", y_limit );
|
// printf( "%d\n", y_limit );
|
||||||
// printf( "%p\n", m_a );
|
// printf( "%p\n", m_a );
|
||||||
|
// printf( "Drawing line from {%f, %f} to {%f, %f}\n", aP0.m_x, aP0.m_y, aP1.m_x,
|
||||||
|
// aP1.m_y );
|
||||||
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;
|
||||||
|
@ -206,22 +227,17 @@ RasterFP_DrawLine( RasterFP* aRasterFP, RasterFP_Point aP0, RasterFP_Point aP1 )
|
||||||
}
|
}
|
||||||
x = xnext;
|
x = xnext;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dense_conic_to( const FT_Vector* control,
|
dense_conic_to( const FT_Vector* control,
|
||||||
const FT_Vector* to,
|
const FT_Vector* to,
|
||||||
RasterFP* aRasterFP )
|
RasterFP* aRasterFP )
|
||||||
{
|
{
|
||||||
RasterFP_Point controlP = { control->x, control->y };
|
RasterFP_Point controlP = { UPSCALE(control->x), UPSCALE(control->y) };
|
||||||
RasterFP_Point toP = { to->x, to->y };
|
RasterFP_Point toP = { UPSCALE(to->x), UPSCALE(to->y) };
|
||||||
RasterFP_DrawQuadratic( aRasterFP, aRasterFP->last_point, controlP, toP );
|
RasterFP_Point lP = { aRasterFP->prev_x, aRasterFP->prev_y };
|
||||||
|
RasterFP_DrawQuadratic( aRasterFP, lP, controlP, toP );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,23 +296,19 @@ RasterFP_DrawQuadratic( RasterFP* aRasterFP,
|
||||||
RasterFP_DrawLine( aRasterFP, p, aP2 );
|
RasterFP_DrawLine( aRasterFP, p, aP2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dense_cubic_to( const FT_Vector* control1,
|
dense_cubic_to( const FT_Vector* control1,
|
||||||
const FT_Vector* control2,
|
const FT_Vector* control2,
|
||||||
const FT_Vector* to,
|
const FT_Vector* to,
|
||||||
RasterFP* aRasterFP )
|
RasterFP* aRasterFP )
|
||||||
{
|
{
|
||||||
RasterFP_Point ap1 = { control1->x, control1->y };
|
RasterFP_Point ap1 = { UPSCALE(control1->x), UPSCALE(control1->y) };
|
||||||
RasterFP_Point ap2 = { control2->x, control2->y };
|
RasterFP_Point ap2 = { UPSCALE(control2->x), UPSCALE(control2->y) };
|
||||||
RasterFP_Point ap3 = { to->x, to->y };
|
RasterFP_Point ap3 = { UPSCALE(to->x), UPSCALE(to->y) };
|
||||||
|
|
||||||
RasterFP_DrawCubic( aRasterFP, aRasterFP->last_point, ap1, ap2, ap3 );
|
RasterFP_Point lP = {aRasterFP->prev_x, aRasterFP->prev_y};
|
||||||
|
|
||||||
|
RasterFP_DrawCubic( aRasterFP, lP, ap1, ap2, ap3 );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,11 +408,49 @@ FT_DEFINE_OUTLINE_FUNCS( dense_decompose_funcs,
|
||||||
static int
|
static int
|
||||||
dense_render_glyph( RasterFP* aRasterFP, const 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
|
||||||
const float* source = aRasterFP->m_a;
|
const float* source = aRasterFP->m_a;
|
||||||
|
|
||||||
|
|
||||||
|
// for (int i = 0; i < aRasterFP->m_h; i++)
|
||||||
|
// {
|
||||||
|
// printf("%f\n", *(source+i));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// printf("pulu %d\n", aRasterFP->m_h);
|
||||||
|
printf( "Outputting bitmap\n" );
|
||||||
|
for ( int i = 0; i < aRasterFP->m_h; i++ )
|
||||||
|
{
|
||||||
|
printf( "\n" );
|
||||||
|
for ( int j = 0; j < aRasterFP->m_w; j++ )
|
||||||
|
{
|
||||||
|
float strength = *( source + ( i * aRasterFP->m_w + j ) );
|
||||||
|
if ( strength > 0.90 )
|
||||||
|
{
|
||||||
|
printf( "@|" );
|
||||||
|
}
|
||||||
|
else if ( strength > 0.70 )
|
||||||
|
{
|
||||||
|
printf( "#|" );
|
||||||
|
}
|
||||||
|
else if ( strength > 0.45 )
|
||||||
|
{
|
||||||
|
printf( "+|" );
|
||||||
|
}
|
||||||
|
else if ( strength > 0.20 )
|
||||||
|
{
|
||||||
|
printf( "*|" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf( ".|" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf( "\n" );
|
||||||
|
|
||||||
unsigned char* dest = target->buffer;
|
unsigned char* dest = target->buffer;
|
||||||
unsigned char* dest_end = target->buffer + aRasterFP->m_w * aRasterFP->m_h;
|
unsigned char* dest_end = target->buffer + aRasterFP->m_w * aRasterFP->m_h;
|
||||||
float value = 0.0f;
|
float value = 0.0f;
|
||||||
|
@ -427,8 +477,6 @@ 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 )
|
||||||
|
@ -449,7 +497,6 @@ 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 = target_map->pitch;
|
aRasterFP->m_w = target_map->pitch;
|
||||||
|
@ -457,19 +504,16 @@ dense_raster_render( FT_Raster raster, const FT_Raster_Params* params )
|
||||||
|
|
||||||
int size = aRasterFP->m_w * aRasterFP->m_h + 4;
|
int size = aRasterFP->m_w * aRasterFP->m_h + 4;
|
||||||
|
|
||||||
aRasterFP->m_a = realloc(aRasterFP, sizeof(float) * size);
|
aRasterFP->m_a = malloc( sizeof( float ) * size );
|
||||||
if ( aRasterFP->m_a == NULL )
|
|
||||||
{
|
|
||||||
memset( aRasterFP, 0, sizeof( RasterFP ) );
|
|
||||||
}
|
|
||||||
aRasterFP->m_a_size = size;
|
aRasterFP->m_a_size = size;
|
||||||
|
|
||||||
memset( aRasterFP->m_a, 0, sizeof( float ) * 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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ extern "C"
|
||||||
/** The y origin of the raster. */
|
/** The y origin of the raster. */
|
||||||
int m_origin_y;
|
int m_origin_y;
|
||||||
|
|
||||||
RasterFP_Point last_point;
|
FT_Pos prev_x, prev_y;
|
||||||
|
|
||||||
FT_Outline outline;
|
FT_Outline outline;
|
||||||
} RasterFP;
|
} RasterFP;
|
||||||
|
|
|
@ -98,22 +98,22 @@ ft_dense_render( FT_Renderer render,
|
||||||
|
|
||||||
|
|
||||||
/* the padding will simply be equal to the `spread' */
|
/* the padding will simply be equal to the `spread' */
|
||||||
// x_shift = 64 * -slot->bitmap_left;
|
x_shift = 64 * -slot->bitmap_left;
|
||||||
// y_shift = 64 * -slot->bitmap_top;
|
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;
|
||||||
|
|
|
@ -876,10 +876,13 @@ typedef ptrdiff_t FT_PtrDist;
|
||||||
TCoord fx1, fy1, fx2, fy2;
|
TCoord fx1, fy1, fx2, fy2;
|
||||||
TCoord ex1, ey1, ex2, ey2;
|
TCoord ex1, ey1, ex2, ey2;
|
||||||
|
|
||||||
|
printf( "Line from {%li, %li} to {%li, %li}, with a maximum dimensions of %d by %d\n", ras.x, ras.y, to_x,
|
||||||
|
to_y, ras.max_ex, ras.max_ey );
|
||||||
ey1 = TRUNC( ras.y );
|
ey1 = TRUNC( ras.y );
|
||||||
ey2 = TRUNC( to_y );
|
ey2 = TRUNC( to_y );
|
||||||
|
|
||||||
|
printf("Truncation reduced prev y from %ld to %d\n", ras.y, ey1);
|
||||||
|
|
||||||
/* perform vertical clipping */
|
/* perform vertical clipping */
|
||||||
if ( ( ey1 >= ras.max_ey && ey2 >= ras.max_ey ) ||
|
if ( ( ey1 >= ras.max_ey && ey2 >= ras.max_ey ) ||
|
||||||
( ey1 < ras.min_ey && ey2 < ras.min_ey ) )
|
( ey1 < ras.min_ey && ey2 < ras.min_ey ) )
|
||||||
|
|
|
@ -493,6 +493,8 @@
|
||||||
/* 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 );
|
||||||
|
printf( "x_shift is %li\n", x_shift );
|
||||||
|
printf( "y_shift is %li\n", y_shift );
|
||||||
|
|
||||||
if ( mode == FT_RENDER_MODE_NORMAL ||
|
if ( mode == FT_RENDER_MODE_NORMAL ||
|
||||||
mode == FT_RENDER_MODE_LIGHT )
|
mode == FT_RENDER_MODE_LIGHT )
|
||||||
|
|
Loading…
Reference in New Issue