diff options
Diffstat (limited to 'demos/src/ftview.c')
-rw-r--r-- | demos/src/ftview.c | 121 |
1 files changed, 27 insertions, 94 deletions
diff --git a/demos/src/ftview.c b/demos/src/ftview.c index 43f4dfe89..8b1e8bfce 100644 --- a/demos/src/ftview.c +++ b/demos/src/ftview.c @@ -17,7 +17,6 @@ #include <freetype/freetype.h> -#include <freetype/ftrender.h> /* the following header shouldn't be used in normal programs */ #include <freetype/internal/ftdebug.h> @@ -64,7 +63,7 @@ int ptsize; /* current point size */ int hinted = 1; /* is glyph hinting active? */ - int antialias = 0; /* is anti-aliasing active? */ + int antialias = 1; /* is anti-aliasing active? */ int use_sbits = 1; /* do we use embedded bitmaps? */ int low_prec = 0; /* force low precision */ int Num; /* current first glyph index */ @@ -78,14 +77,9 @@ int graph_init = 0; int render_mode = 1; - int use_grays = 1; int debug = 0; int trace_level = 0; - /* the standard raster's interface */ - FT_Renderer std_renderer; - FT_Renderer smooth_renderer; - #define RASTER_BUFF_SIZE 32768 char raster_buff[RASTER_BUFF_SIZE]; @@ -152,79 +146,44 @@ #define CEIL( x ) ( ( (x) + 63 ) & -64 ) #define TRUNC( x ) ( (x) >> 6 ) - static - char bit_buffer[MAX_BUFFER]; - /* Render a single glyph with the `grays' component */ static FT_Error Render_Glyph( int x_offset, int y_offset ) { - /* first, render the glyph into an intermediate buffer */ - FT_Bitmap bit2; - grBitmap bit3; - int width, height, pitch, size; - int left, right, top, bottom; - int x_top, y_top; - - - left = FLOOR( glyph->metrics.horiBearingX ); - right = CEIL( glyph->metrics.horiBearingX + glyph->metrics.width ); - width = TRUNC( right - left ); - - top = CEIL( glyph->metrics.horiBearingY ); - bottom = FLOOR( glyph->metrics.horiBearingY - glyph->metrics.height ); - height = TRUNC( top - bottom ); - - if ( glyph->format == ft_glyph_format_outline ) + grBitmap bit3; + FT_Pos x_top, y_top; + + /* first, render the glyph image into a bitmap */ + if (glyph->format != ft_glyph_format_bitmap) { - pitch = antialias ? ( width + 3 ) & -4 - : ( width + 7 ) >> 3; - size = pitch * height; - - if ( size > MAX_BUFFER ) - return FT_Err_Out_Of_Memory; - - bit2.width = width; - bit2.rows = height; - bit2.pitch = pitch; - bit2.pixel_mode = antialias ? ft_pixel_mode_grays : ft_pixel_mode_mono; - bit2.buffer = bit_buffer; - - bit3.rows = bit2.rows; - bit3.width = bit2.width; - bit3.pitch = bit2.pitch; - bit3.mode = antialias ? bit.mode : gr_pixel_mode_mono; - bit3.buffer = bit_buffer; - bit3.grays = 256; - - FT_Outline_Translate( &glyph->outline, -left, -bottom ); - memset( bit_buffer, 0, size ); - - if ( low_prec ) - glyph->outline.flags &= ~ft_outline_high_precision; - - error = FT_Outline_Get_Bitmap( library, &glyph->outline, &bit2 ); + error = FT_Render_Glyph( glyph, antialias ? 1 : 0 ); + if (error) return error; + } - else + + /* now blit it to our display screen */ + bit3.rows = glyph->bitmap.rows; + bit3.width = glyph->bitmap.width; + bit3.pitch = glyph->bitmap.pitch; + bit3.buffer = glyph->bitmap.buffer; + + switch (glyph->bitmap.pixel_mode) { - bit3.rows = glyph->bitmap.rows; - bit3.width = glyph->bitmap.width; - bit3.pitch = glyph->bitmap.pitch; - bit3.mode = gr_pixel_mode_mono; - bit3.buffer = glyph->bitmap.buffer; - bit3.grays = 0; + case ft_pixel_mode_mono: + bit3.mode = gr_pixel_mode_mono; + bit3.grays = 0; + break; + + case ft_pixel_mode_grays: + bit3.mode = gr_pixel_mode_gray; + bit3.grays = glyph->bitmap.num_grays; } /* Then, blit the image to the target surface */ - x_top = x_offset + TRUNC( left ); - y_top = y_offset - TRUNC( top ); - -#if 0 - if ( bit.pitch < 0 ) - y_top = bit.rows - y_top; -#endif + x_top = x_offset + glyph->bitmap_left; + y_top = y_offset - glyph->bitmap_top; grBlitGlyphToBitmap( &bit, &bit3, x_top, y_top, fore_color ); @@ -431,7 +390,6 @@ grWriteln(" h : toggle outline hinting" ); grWriteln(" b : toggle embedded bitmaps" ); grWriteln(" l : toggle low precision rendering" ); - grWriteln(" g : toggle between `smooth' and `standard' anti-aliaser" ); grWriteln(" space : toggle rendering mode" ); grLn(); grWriteln(" Up : increase pointsize by 1 unit" ); @@ -456,15 +414,6 @@ } - static - void reset_raster( void ) - { - if ( antialias && use_grays && smooth_renderer ) - FT_Set_Renderer( library, smooth_renderer, 0, 0 ); - else - FT_Set_Renderer( library, std_renderer, 0, 0 ); - } - static int Process_Event( grEvent* event ) @@ -482,7 +431,6 @@ antialias = !antialias; new_header = antialias ? "anti-aliasing is now on" : "anti-aliasing is now off"; - reset_raster(); return 1; case grKEY( 'b' ): @@ -496,14 +444,6 @@ case grKEY( 'p' ): return (int)event->key; - case grKEY( 'g' ): - use_grays = !use_grays; - new_header = use_grays - ? "now using the smooth anti-aliaser" - : "now using the standard anti-aliaser"; - reset_raster(); - break; - case grKEY( 'l' ): low_prec = !low_prec; new_header = low_prec @@ -672,13 +612,6 @@ if ( error ) PanicZ( "Could not initialize FreeType library" ); - /* retrieve the standard raster's interface */ - std_renderer = (FT_Renderer)FT_Get_Module( library, "standard renderer" ); - if (!std_renderer) - PanicZ( "Could not retrieve standard renderer" ); - - smooth_renderer = (FT_Renderer)FT_Get_Module( library, "smooth renderer" ); - NewFile: ptsize = orig_ptsize; hinted = 1; |