Commit 9d636b6d authored by David Turner's avatar David Turner
Browse files

various cleanups to reduce compiler warnings

+ support for CID-keyed fonts in the CFF driver
(still some unexpected bugs though..)
parent 74abee8e
LATEST CHANGES
- added support for CID-keyed fonts to the CFF driver. There are still
some unexplained bugs though... ???
- cleaned up source code in order to avoid two functions with the
same name. Also changed the names of the files in "type1z" from
"t1XXXX" to "z1XXXX" in order to avoid any conflicts.
"make multi" now works well :-)
- CHANGES TO THE RENDERER MODULES
the monochrome and smooth renderers are now in two distinct directories,
namely "src/raster1" and "src/smooth". Note that the old "src/renderer"
is now gone..
I ditched the 5-gray-levels renderers. Basically, it involved a simple
#define toggle in 'src/raster1/ftraster.c'
FT_Render_Glyph, FT_Outline_Render & FT_Outline_Get_Bitmap now select
the best renderer available, depending on render mode. If the current
renderer for a given glyph image format isn't capable of supporting
the render mode, another one will be found in the library's list.
This means that client applications do not need to switch or set the
renderers themselves (as in the latest change), they'll get what they
want automatically... At last..
Changed the demo programs accordingly..
- MAJOR INTERNAL REDESIGN:
A lot of internal modifications have been performed lately on the
......
......@@ -98,7 +98,7 @@ T := -o # Don't remove this comment line! We need the space after `-o'.
# ANSI compliance.
#
ifndef CFLAGS
CFLAGS := -c -g -O0 -Wall
CFLAGS := -c -g -O0 -Wall -W
endif
# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant.
......
......@@ -13,7 +13,6 @@
/****************************************************************************/
#include <freetype/freetype.h>
#include <freetype/ftrender.h>
#include <freetype/ftmm.h>
#include "common.h"
......@@ -74,10 +73,6 @@
int render_mode = 1;
int use_grays = 1;
/* the standard raster's interface */
FT_Renderer std_renderer;
FT_Renderer smooth_renderer;
FT_Multi_Master multimaster;
FT_Long design_pos[T1_MAX_MM_AXIS];
......@@ -432,7 +427,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" );
......@@ -457,15 +451,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 )
......@@ -489,7 +474,6 @@
antialias = !antialias;
new_header = antialias ? "anti-aliasing is now on"
: "anti-aliasing is now off";
reset_raster();
return 1;
case grKEY( 'b' ):
......@@ -502,13 +486,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 ? "rendering precision is now forced to low"
......@@ -714,13 +691,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;
......
......@@ -11,7 +11,6 @@
/****************************************************************************/
#include <freetype/freetype.h>
#include <freetype/ftrender.h>
#include <freetype/ftglyph.h>
#include "common.h"
......@@ -60,11 +59,6 @@
static int graph_init = 0;
static int render_mode = 1;
static int use_grays = 1;
/* the standard raster's interface */
FT_Renderer std_renderer;
FT_Renderer smooth_renderer;
static FT_Matrix trans_matrix;
static int transform = 0;
......@@ -449,7 +443,6 @@
grWriteln(" a : toggle anti-aliasing" );
grWriteln(" h : toggle outline hinting" );
grWriteln(" k : toggle kerning" );
grWriteln(" g : toggle between 'smooth' and 'standard' anti-aliaser" );
grLn();
grWriteln(" Up : increase pointsize by 1 unit" );
grWriteln(" Down : decrease pointsize by 1 unit" );
......@@ -468,15 +461,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 )
{
int i;
......@@ -499,7 +483,6 @@
new_header = ( antialias
? "anti-aliasing is now on"
: "anti-aliasing is now off" );
reset_raster();
return 1;
case grKEY('b'):
......@@ -513,14 +496,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('h'):
hinted = !hinted;
new_header = ( hinted
......@@ -668,13 +643,6 @@
error = FT_Init_FreeType( &library );
if (error) PanicZ( "Could not initialise 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;
......
......@@ -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;
......
FT_USE_MODULE(cff_driver_class)
FT_USE_MODULE(t1cid_driver_class)
FT_USE_MODULE(psnames_module_class)
FT_USE_MODULE(ft_standard_renderer_class)
FT_USE_MODULE(ft_smooth_renderer_class)
FT_USE_MODULE(ft_raster1_renderer_class)
FT_USE_MODULE(sfnt_module_class)
FT_USE_MODULE(ft_smooth_renderer_class)
FT_USE_MODULE(tt_driver_class)
FT_USE_MODULE(t1_driver_class)
FT_USE_MODULE(t1z_driver_class)
......@@ -55,6 +55,7 @@ FT_ERROR_START_LIST
FT_ERRORDEF( FT_Err_Unimplemented_Feature, 0x0020, "unimplemented feature" )
FT_ERRORDEF( FT_Err_Invalid_Glyph_Format, 0x0021, "invalid glyph image format" )
FT_ERRORDEF( FT_Err_Cannot_Render_Glyph, 0x0022, "cannot render this glyph format" )
FT_ERRORDEF( FT_Err_Invalid_Library_Handle, 0x0030, "invalid library handle" )
FT_ERRORDEF( FT_Err_Invalid_Driver_Handle, 0x0031, "invalid module handle" )
......
......@@ -49,7 +49,8 @@
typedef FT_Error (*FTRenderer_render)( FT_Renderer renderer,
FT_GlyphSlot slot,
FT_UInt mode );
FT_UInt mode,
FT_Vector* origin );
typedef FT_Error (*FTRenderer_transform)( FT_Renderer renderer,
FT_GlyphSlot slot,
......
......@@ -384,14 +384,14 @@
FT_Generic generic;
FT_Int num_modules;
FT_UInt num_modules;
FT_Module modules[ FT_MAX_MODULES ]; /* module objects */
FT_ListRec renderers; /* list of renderers */
FT_Renderer cur_renderer; /* current outline renderer */
void* raster_pool; /* scan-line conversion render pool */
long raster_pool_size; /* size of render pool in bytes */
unsigned long raster_pool_size; /* size of render pool in bytes */
FT_DebugHook_Func debug_hooks[4];
......@@ -411,6 +411,14 @@
FT_DebugHook_Func debug_hook );
BASE_DEF(FT_Renderer) FT_Lookup_Renderer( FT_Library library,
FT_Glyph_Format format,
FT_ListNode *node );
BASE_DEF(FT_Error) FT_Render_Glyph_Internal( FT_Library library,
FT_GlyphSlot slot,
FT_UInt render_mode );
#ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM
......
......@@ -62,7 +62,7 @@
} CFF_Index;
typedef struct CFF_Top_Dict_
typedef struct CFF_Font_Dict_
{
FT_UInt version;
FT_UInt notice;
......@@ -90,6 +90,7 @@
FT_UInt base_font_name;
FT_UInt postscript;
/* these should only be used for the top-level font dict */
FT_UInt cid_registry;
FT_UInt cid_ordering;
FT_ULong cid_supplement;
......@@ -103,7 +104,9 @@
FT_ULong cid_fd_select_offset;
FT_UInt cid_font_name;
} CFF_Top_Dict;
} CFF_Font_Dict;
typedef struct CFF_Private_
{
......@@ -138,12 +141,49 @@
FT_Pos nominal_width;
} CFF_Private;
typedef struct CFF_FD_Select_
{
FT_Byte format;
FT_UInt range_count;
/* that's the table, taken from the file 'as is' */
FT_Byte* data;
FT_UInt data_size;
/* small cache for format 3 only */
FT_UInt cache_first;
FT_UInt cache_count;
FT_Byte cache_fd;
} CFF_FD_Select;
/* a SubFont packs a font dict and a private dict together. They're */
/* needed to support CID-keyde CFF fonts.. */
typedef struct CFF_SubFont_
{
CFF_Font_Dict font_dict;
CFF_Private private_dict;
CFF_Index local_subrs_index;
FT_UInt num_local_subrs;
FT_Byte** local_subrs;
} CFF_SubFont;
/* maximum number of sub-fonts in a CID-keyed file */
#define CFF_MAX_CID_FONTS 16
typedef struct CFF_Font_
{
FT_Stream stream;
FT_Memory memory;
FT_UInt num_faces;
FT_UInt num_glyphs;
FT_Byte version_major;
FT_Byte version_minor;
......@@ -164,13 +204,14 @@
CFF_Index local_subrs_index;
FT_String* font_name;
CFF_Top_Dict top_dict;
CFF_Private private_dict;
FT_UInt num_global_subrs;
FT_UInt num_local_subrs;
FT_Byte** global_subrs;
FT_Byte** local_subrs;
CFF_SubFont top_font;
FT_UInt num_subfonts;
CFF_SubFont* subfonts[ CFF_MAX_CID_FONTS ];
CFF_FD_Select fd_select;
} CFF_Font;
......
......@@ -345,18 +345,37 @@
T2_Init_Builder( &decoder->builder, face, size, slot );
/* initialize Type2 decoder */
decoder->num_locals = cff->num_local_subrs;
decoder->num_globals = cff->num_global_subrs;
decoder->locals = cff->local_subrs;
decoder->globals = cff->global_subrs;
decoder->locals_bias = t2_compute_bias( decoder->num_locals );
decoder->globals_bias = t2_compute_bias( decoder->num_globals );
decoder->glyph_width = cff->private_dict.default_width;
decoder->nominal_width = cff->private_dict.nominal_width;
}
/* this function is used to select the locals subrs array */
LOCAL_DEF
void T2_Prepare_Decoder( T2_Decoder* decoder,
FT_UInt glyph_index )
{
CFF_Font* cff = (CFF_Font*)decoder->builder.face->extra.data;
CFF_SubFont* sub = &cff->top_font;
/* manage CID fonts */
if (cff->num_subfonts >= 1)
{
FT_Byte fd_index = CFF_Get_FD( &cff->fd_select, glyph_index );
sub = cff->subfonts[fd_index];
}
decoder->num_locals = sub->num_local_subrs;
decoder->locals = sub->local_subrs;
decoder->locals_bias = t2_compute_bias( decoder->num_locals );
decoder->glyph_width = sub->private_dict.default_width;
decoder->nominal_width = sub->private_dict.nominal_width;
}
/* check that there is enough room for `count' more points */
static
FT_Error check_points( T2_Builder* builder,
......@@ -509,7 +528,6 @@
FT_Fixed seed;
FT_Fixed* stack;
/* set default width */
decoder->num_hints = 0;
decoder->read_width = 1;
......@@ -1572,6 +1590,7 @@
&charstring, &charstring_len );
if ( !error )
{
T2_Prepare_Decoder( &decoder, glyph_index );
error = T2_Parse_CharStrings( &decoder, charstring, charstring_len );
T2_Forget_Element( &cff->charstrings_index, &charstring );
......@@ -1648,6 +1667,7 @@
&charstring, &charstring_len );
if ( !error )
{
T2_Prepare_Decoder( &decoder, glyph_index );
error = T2_Parse_CharStrings( &decoder, charstring, charstring_len );
T2_Forget_Element( &cff->charstrings_index, &charstring );
......
......@@ -166,6 +166,9 @@
T2_Size size,
T2_GlyphSlot slot );