📄 gview.c
字号:
? GHOST_HINT_COLOR : STEM_HINT_COLOR );
nv_pixmap_fill_rect( target, pshint_cpos, x2, 1, x1 + 1 - x2,
STEM_JOIN_COLOR );
}
#if 0
printf( "[%7.3f %7.3f] %c\n", hint->cur_pos/64.0, (hint->cur_pos+hint->cur_len)/64.0, vertical ? 'v' : 'h' );
#endif
pshint_cpos += 10;
}
static void
ps_draw_control_points( void )
{
if ( ps_debug_glyph )
{
PSH_Glyph glyph = ps_debug_glyph;
PSH_Point point = glyph->points;
FT_UInt count = glyph->num_points;
NV_Transform transform, *trans = &transform;
NV_Path vert_rect;
NV_Path horz_rect;
NV_Path dot, circle;
for ( ; count > 0; count--, point++ )
{
NV_Vector vec;
vec.x = point->cur_x;
vec.y = point->cur_y;
nv_vector_transform( &vec, &size_transform );
nv_transform_set_translate( trans, vec.x, vec.y );
if ( option_show_smooth && !psh_point_is_smooth(point) )
{
nv_painter_set_color( painter, SMOOTH_COLOR, 256 );
nv_painter_fill_path( painter, trans, 0, symbol_circle );
}
if ( option_show_horz_hints )
{
if ( point->flags_y & PSH_POINT_STRONG )
{
nv_painter_set_color( painter, STRONG_COLOR, 256 );
nv_painter_fill_path( painter, trans, 0, symbol_rect_h );
}
}
if ( option_show_vert_hints )
{
if ( point->flags_x & PSH_POINT_STRONG )
{
nv_painter_set_color( painter, STRONG_COLOR, 256 );
nv_painter_fill_path( painter, trans, 0, symbol_rect_v );
}
}
}
}
}
static void
ps_print_hints( void )
{
if ( ps_debug_hints )
{
FT_Int dimension;
for ( dimension = 1; dimension >= 0; dimension-- )
{
PS_Dimension dim = &ps_debug_hints->dimension[ dimension ];
PS_Mask mask = dim->masks.masks;
FT_UInt count = dim->masks.num_masks;
printf( "%s hints -------------------------\n",
dimension ? "vertical" : "horizontal" );
for ( ; count > 0; count--, mask++ )
{
FT_UInt index;
printf( "mask -> %d\n", mask->end_point );
for ( index = 0; index < mask->num_bits; index++ )
{
if ( mask->bytes[ index >> 3 ] & (0x80 >> (index & 7)) )
{
PS_Hint hint = dim->hints.hints + index;
printf( "%c [%3d %3d (%4d)]\n", dimension ? "v" : "h",
hint->pos, hint->pos + hint->len, hint->len );
}
}
}
}
}
}
/************************************************************************/
/************************************************************************/
/***** *****/
/***** AUTOHINTER DRAWING ROUTINES *****/
/***** *****/
/************************************************************************/
/************************************************************************/
static NV_Path
ah_link_path( NV_Vector* p1,
NV_Vector* p4,
NV_Bool vertical )
{
NV_PathWriter writer;
NV_Vector p2, p3;
NV_Path path, stroke;
if ( vertical )
{
p2.x = p4->x;
p2.y = p1->y;
p3.x = p1->x;
p3.y = p4->y;
}
else
{
p2.x = p1->x;
p2.y = p4->y;
p3.x = p4->x;
p3.y = p1->y;
}
nv_path_writer_new( renderer, &writer );
nv_path_writer_moveto( writer, p1 );
nv_path_writer_cubicto( writer, &p2, &p3, p4 );
nv_path_writer_end( writer );
path = nv_path_writer_get_path( writer );
nv_path_writer_destroy( writer );
nv_path_stroke( path, 1.,
nv_path_linecap_butt, nv_path_linejoin_round,
1., &stroke );
nv_path_destroy( path );
return stroke;
}
static void
ah_draw_smooth_points( void )
{
if ( ah_debug_hinter && option_show_smooth )
{
AH_Outline glyph = ah_debug_hinter->glyph;
FT_UInt count = glyph->num_points;
AH_Point point = glyph->points;
nv_painter_set_color( painter, SMOOTH_COLOR, 256 );
for ( ; count > 0; count--, point++ )
{
if ( !( point->flags & AH_FLAG_WEAK_INTERPOLATION ) )
{
NV_Transform transform, *trans = &transform;
NV_Vector vec;
vec.x = point->x - ah_debug_hinter->pp1.x;
vec.y = point->y;
nv_vector_transform( &vec, &size_transform );
nv_transform_set_translate( &transform, vec.x, vec.y );
nv_painter_fill_path( painter, trans, 0, symbol_circle );
}
}
}
}
static void
ah_draw_edges( void )
{
if ( ah_debug_hinter )
{
AH_Outline glyph = ah_debug_hinter->glyph;
FT_UInt count;
AH_Edge edge;
FT_Pos pp1 = ah_debug_hinter->pp1.x;
nv_painter_set_color( painter, EDGE_COLOR, 256 );
if ( option_show_edges )
{
/* draw vertical edges */
if ( option_show_vert_hints )
{
count = glyph->num_vedges;
edge = glyph->vert_edges;
for ( ; count > 0; count--, edge++ )
{
NV_Vector vec;
NV_Pos x;
vec.x = edge->pos - pp1;
vec.y = 0;
nv_vector_transform( &vec, &size_transform );
x = (FT_Pos)( vec.x + 0.5 );
nv_pixmap_fill_rect( target, x, 0, 1, target->height, EDGE_COLOR );
}
}
/* draw horizontal edges */
if ( option_show_horz_hints )
{
count = glyph->num_hedges;
edge = glyph->horz_edges;
for ( ; count > 0; count--, edge++ )
{
NV_Vector vec;
NV_Pos x;
vec.x = 0;
vec.y = edge->pos;
nv_vector_transform( &vec, &size_transform );
x = (FT_Pos)( vec.y + 0.5 );
nv_pixmap_fill_rect( target, 0, x, target->width, 1, EDGE_COLOR );
}
}
}
if ( option_show_segments )
{
/* draw vertical segments */
if ( option_show_vert_hints )
{
AH_Segment seg = glyph->vert_segments;
FT_UInt count = glyph->num_vsegments;
for ( ; count > 0; count--, seg++ )
{
AH_PointRec *first, *last;
NV_Vector v1, v2;
NV_Pos y1, y2, x;
first = seg->first;
last = seg->last;
v1.x = v2.x = first->x - pp1;
if ( first->y <= last->y )
{
v1.y = first->y;
v2.y = last->y;
}
else
{
v1.y = last->y;
v2.y = first->y;
}
nv_vector_transform( &v1, &size_transform );
nv_vector_transform( &v2, &size_transform );
y1 = (NV_Pos)( v1.y + 0.5 );
y2 = (NV_Pos)( v2.y + 0.5 );
x = (NV_Pos)( v1.x + 0.5 );
nv_pixmap_fill_rect( target, x - 1, y2, 3,
FT_ABS( y1 - y2 ) + 1, SEGMENT_COLOR );
}
}
/* draw horizontal segments */
if ( option_show_horz_hints )
{
AH_Segment seg = glyph->horz_segments;
FT_UInt count = glyph->num_hsegments;
for ( ; count > 0; count--, seg++ )
{
AH_PointRec *first, *last;
NV_Vector v1, v2;
NV_Pos y1, y2, x;
first = seg->first;
last = seg->last;
v1.y = v2.y = first->y;
if ( first->x <= last->x )
{
v1.x = first->x - pp1;
v2.x = last->x - pp1;
}
else
{
v1.x = last->x - pp1;
v2.x = first->x - pp1;
}
nv_vector_transform( &v1, &size_transform );
nv_vector_transform( &v2, &size_transform );
y1 = (NV_Pos)( v1.x + 0.5 );
y2 = (NV_Pos)( v2.x + 0.5 );
x = (NV_Pos)( v1.y + 0.5 );
nv_pixmap_fill_rect( target, y1, x - 1,
FT_ABS( y1 - y2 ) + 1, 3, SEGMENT_COLOR );
}
}
if ( option_show_vert_hints && option_show_links )
{
AH_Segment seg = glyph->vert_segments;
FT_UInt count = glyph->num_vsegments;
for ( ; count > 0; count--, seg++ )
{
AH_Segment seg2 = NULL;
NV_Path link;
NV_Vector v1, v2;
if ( seg->link )
{
if ( seg->link > seg )
seg2 = seg->link;
}
else if ( seg->serif )
seg2 = seg->serif;
if ( seg2 )
{
v1.x = seg->first->x - pp1;
v2.x = seg2->first->x - pp1;
v1.y = ( seg->first->y + seg->last->y ) / 2;
v2.y = ( seg2->first->y + seg2->last->y ) / 2;
link = ah_link_path( &v1, &v2, 1 );
nv_painter_set_color( painter,
seg->serif ? SERIF_LINK_COLOR : LINK_COLOR,
256 );
nv_painter_fill_path( painter, &size_transform, 0, link );
nv_path_destroy( link );
}
}
}
if ( option_show_horz_hints && option_show_links )
{
AH_Segment seg = glyph->horz_segments;
FT_UInt count = glyph->num_hsegments;
for ( ; count > 0; count--, seg++ )
{
AH_Segment seg2 = NULL;
NV_Path link;
NV_Vector v1, v2;
if ( seg->link )
{
if ( seg->link > seg )
seg2 = seg->link;
}
else if ( seg->serif )
seg2 = seg->serif;
if ( seg2 )
{
v1.y = seg->first->y;
v2.y = seg2->first->y;
v1.x = ( seg->first->x + seg->last->x ) / 2 - pp1;
v2.x = ( seg2->first->x + seg2->last->x ) / 2 - pp1;
link = ah_link_path( &v1, &v2, 0 );
nv_painter_set_color( painter,
seg->serif ? SERIF_LINK_COLOR : LINK_COLOR,
256 );
nv_painter_fill_path( painter, &size_transform, 0, link );
nv_path_destroy( link );
}
}
}
}
}
}
/************************************************************************/
/************************************************************************/
/***** *****/
/***** MAIN LOOP(S) *****/
/***** *****/
/************************************************************************/
/************************************************************************/
static void
draw_glyph( int glyph_index )
{
NV_Path path;
pshint_vertical = -1;
ps_debug_hint_func = option_show_ps_hints ? draw_ps_hint : 0;
ah_debug_hinter = NULL;
error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_BITMAP );
if ( error )
Panic( "could not load glyph" );
if ( face->glyph->format != FT_GLYPH_FORMAT_OUTLINE )
Panic( "could not load glyph outline" );
error = nv_path_new_from_outline( renderer,
(NV_Outline*)&face->glyph->outline,
&size_transform,
&path );
if ( error )
Panic( "could not create glyph path" );
/* trac
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -