2002-04-20 07:38:33 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* pfrobjs.c */
|
|
|
|
/* */
|
|
|
|
/* FreeType PFR object methods (body). */
|
|
|
|
/* */
|
|
|
|
/* Copyright 2002 by */
|
|
|
|
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
|
|
|
/* */
|
|
|
|
/* This file is part of the FreeType project, and may only be used, */
|
|
|
|
/* modified, and distributed under the terms of the FreeType project */
|
|
|
|
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
|
|
|
/* this file you indicate that you have read the license and */
|
|
|
|
/* understand and accept it fully. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
|
2002-04-19 17:13:47 +02:00
|
|
|
#include "pfrobjs.h"
|
|
|
|
#include "pfrload.h"
|
|
|
|
#include "pfrgload.h"
|
|
|
|
#include "pfrcmap.h"
|
|
|
|
#include FT_OUTLINE_H
|
|
|
|
#include FT_INTERNAL_DEBUG_H
|
|
|
|
|
2002-04-28 12:25:55 +02:00
|
|
|
#include "pfrerror.h"
|
|
|
|
|
2002-04-19 17:13:47 +02:00
|
|
|
#undef FT_COMPONENT
|
|
|
|
#define FT_COMPONENT trace_pfr
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** FACE OBJECT METHODS *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
FT_LOCAL_DEF( void )
|
2002-04-20 07:38:33 +02:00
|
|
|
pfr_face_done( PFR_Face face )
|
2002-04-19 17:13:47 +02:00
|
|
|
{
|
|
|
|
/* finalize the physical font record */
|
2002-04-20 07:38:33 +02:00
|
|
|
pfr_phy_font_done( &face->phy_font, FT_FACE_MEMORY( face ) );
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
/* no need to finalize the logical font or the header */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_LOCAL_DEF( FT_Error )
|
|
|
|
pfr_face_init( FT_Stream stream,
|
|
|
|
PFR_Face face,
|
|
|
|
FT_Int face_index )
|
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
|
2002-04-19 17:13:47 +02:00
|
|
|
/* load the header and check it */
|
|
|
|
error = pfr_header_load( &face->header, stream );
|
2002-04-20 07:38:33 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
if ( !pfr_header_check( &face->header ) )
|
|
|
|
{
|
2002-04-20 07:38:33 +02:00
|
|
|
FT_TRACE4(( "pfr_face_init: not a valid PFR font\n" ));
|
2002-04-28 12:25:55 +02:00
|
|
|
error = PFR_Err_Unknown_File_Format;
|
2002-04-19 17:13:47 +02:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check face index */
|
|
|
|
{
|
|
|
|
FT_UInt num_faces;
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
|
2002-04-19 17:13:47 +02:00
|
|
|
error = pfr_log_font_count( stream,
|
|
|
|
face->header.log_dir_offset,
|
|
|
|
&num_faces );
|
2002-04-20 07:38:33 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
face->root.num_faces = num_faces;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( face_index < 0 )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
if ( face_index >= face->root.num_faces )
|
|
|
|
{
|
2002-04-20 07:38:33 +02:00
|
|
|
FT_ERROR(( "pfr_face_init: invalid face index\n" ));
|
2002-04-28 12:25:55 +02:00
|
|
|
error = PFR_Err_Invalid_Argument;
|
2002-04-19 17:13:47 +02:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load the face */
|
|
|
|
error = pfr_log_font_load(
|
|
|
|
&face->log_font, stream, face_index,
|
|
|
|
face->header.log_dir_offset,
|
|
|
|
FT_BOOL( face->header.phy_font_max_size_high != 0 ) );
|
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
/* now load the physical font descriptor */
|
|
|
|
error = pfr_phy_font_load( &face->phy_font, stream,
|
|
|
|
face->log_font.phys_offset,
|
|
|
|
face->log_font.phys_size );
|
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
/* now, set-up all root face fields */
|
|
|
|
{
|
2002-04-20 07:38:33 +02:00
|
|
|
FT_Face root = FT_FACE( face );
|
2002-04-19 17:13:47 +02:00
|
|
|
PFR_PhyFont phy_font = &face->phy_font;
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
|
2002-04-19 17:13:47 +02:00
|
|
|
root->face_index = face_index;
|
|
|
|
root->num_glyphs = phy_font->num_chars;
|
|
|
|
root->face_flags = FT_FACE_FLAG_SCALABLE;
|
|
|
|
|
|
|
|
if ( (phy_font->flags & PFR_PHY_PROPORTIONAL) == 0 )
|
|
|
|
root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
|
|
|
|
|
|
|
|
if ( phy_font->flags & PFR_PHY_VERTICAL )
|
|
|
|
root->face_flags |= FT_FACE_FLAG_VERTICAL;
|
2002-06-18 22:30:13 +02:00
|
|
|
else
|
|
|
|
root->face_flags |= FT_FACE_FLAG_HORIZONTAL;
|
2002-04-19 17:13:47 +02:00
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
/* XXX: kerning and embedded bitmap support isn't there yet */
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
root->family_name = phy_font->font_id;
|
|
|
|
root->style_name = NULL; /* no style name in font file */
|
|
|
|
|
|
|
|
root->num_fixed_sizes = 0;
|
|
|
|
root->available_sizes = 0;
|
|
|
|
|
|
|
|
root->bbox = phy_font->bbox;
|
2002-04-20 07:38:33 +02:00
|
|
|
root->units_per_EM = (FT_UShort)phy_font->outline_resolution;
|
|
|
|
root->ascender = (FT_Short) phy_font->bbox.yMax;
|
|
|
|
root->descender = (FT_Short) phy_font->bbox.yMin;
|
|
|
|
root->height = (FT_Short)
|
|
|
|
( ( ( root->ascender - root->descender ) * 12 )
|
|
|
|
/ 10 );
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
/* now compute maximum advance width */
|
2002-04-20 07:38:33 +02:00
|
|
|
if ( ( phy_font->flags & PFR_PHY_PROPORTIONAL ) == 0 )
|
|
|
|
root->max_advance_width = (FT_Short)phy_font->standard_advance;
|
2002-04-19 17:13:47 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FT_Int max = 0;
|
|
|
|
FT_UInt count = phy_font->num_chars;
|
|
|
|
PFR_Char gchar = phy_font->chars;
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
|
2002-04-19 17:13:47 +02:00
|
|
|
for ( ; count > 0; count--, gchar++ )
|
|
|
|
{
|
|
|
|
if ( max < gchar->advance )
|
|
|
|
max = gchar->advance;
|
|
|
|
}
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
root->max_advance_width = (FT_Short)max;
|
2002-04-19 17:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
root->max_advance_height = root->height;
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
root->underline_position = (FT_Short)( - root->units_per_EM / 10 );
|
|
|
|
root->underline_thickness = (FT_Short)( root->units_per_EM / 30 );
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
/* create charmap */
|
|
|
|
{
|
2002-04-20 07:38:33 +02:00
|
|
|
FT_CharMapRec charmap;
|
2002-04-19 17:13:47 +02:00
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
|
2002-04-19 17:13:47 +02:00
|
|
|
charmap.face = root;
|
|
|
|
charmap.platform_id = 3;
|
|
|
|
charmap.encoding_id = 1;
|
|
|
|
charmap.encoding = ft_encoding_unicode;
|
|
|
|
|
|
|
|
FT_CMap_New( &pfr_cmap_class_rec, NULL, &charmap, NULL );
|
2002-06-19 17:57:55 +02:00
|
|
|
|
|
|
|
/* Select default charmap */
|
|
|
|
if (root->num_charmaps)
|
|
|
|
root->charmap = root->charmaps[0];
|
2002-04-19 17:13:47 +02:00
|
|
|
}
|
2002-06-21 09:33:23 +02:00
|
|
|
|
|
|
|
/* check if we've loaded any kerning pairs */
|
|
|
|
if (phy_font->num_kern_pairs)
|
|
|
|
root->face_flags |= FT_FACE_FLAG_KERNING;
|
2002-04-19 17:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** SLOT OBJECT METHOD *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
FT_LOCAL_DEF( FT_Error )
|
|
|
|
pfr_slot_init( PFR_Slot slot )
|
|
|
|
{
|
2002-04-20 07:38:33 +02:00
|
|
|
FT_GlyphLoader loader = slot->root.internal->loader;
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
pfr_glyph_init( &slot->glyph, loader );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_LOCAL_DEF( void )
|
|
|
|
pfr_slot_done( PFR_Slot slot )
|
|
|
|
{
|
|
|
|
pfr_glyph_done( &slot->glyph );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_LOCAL_DEF( FT_Error )
|
|
|
|
pfr_slot_load( PFR_Slot slot,
|
|
|
|
PFR_Size size,
|
|
|
|
FT_UInt gindex,
|
|
|
|
FT_Int load_flags )
|
|
|
|
{
|
|
|
|
FT_Error error;
|
2002-04-20 07:38:33 +02:00
|
|
|
PFR_Face face = (PFR_Face)slot->root.face;
|
2002-06-17 10:01:32 +02:00
|
|
|
PFR_Char gchar;
|
2002-04-19 17:13:47 +02:00
|
|
|
FT_Outline* outline = &slot->root.outline;
|
|
|
|
FT_ULong gps_offset;
|
|
|
|
|
2002-06-17 10:01:32 +02:00
|
|
|
if (gindex > 0)
|
|
|
|
gindex--;
|
2002-04-20 07:38:33 +02:00
|
|
|
|
|
|
|
/* check that the glyph index is correct */
|
2002-04-19 17:13:47 +02:00
|
|
|
FT_ASSERT( gindex < face->phy_font.num_chars );
|
|
|
|
|
2002-06-17 10:01:32 +02:00
|
|
|
gchar = face->phy_font.chars + gindex;
|
2002-04-19 17:13:47 +02:00
|
|
|
slot->root.format = ft_glyph_format_outline;
|
|
|
|
outline->n_points = 0;
|
|
|
|
outline->n_contours = 0;
|
|
|
|
gps_offset = face->header.gps_section_offset;
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
/* load the glyph outline (FT_LOAD_NO_RECURSE isn't supported) */
|
2002-04-19 17:13:47 +02:00
|
|
|
error = pfr_glyph_load( &slot->glyph, face->root.stream,
|
|
|
|
gps_offset, gchar->gps_offset, gchar->gps_size );
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
if ( !error )
|
2002-04-19 17:13:47 +02:00
|
|
|
{
|
|
|
|
FT_BBox cbox;
|
|
|
|
FT_Glyph_Metrics* metrics = &slot->root.metrics;
|
|
|
|
FT_Pos advance;
|
|
|
|
FT_Int em_metrics, em_outline;
|
|
|
|
FT_Bool scaling;
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
|
|
|
|
scaling = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE ) == 0 );
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
/* copy outline data */
|
|
|
|
*outline = slot->glyph.loader->base.outline;
|
|
|
|
|
|
|
|
outline->flags &= ~ft_outline_owner;
|
|
|
|
outline->flags |= ft_outline_reverse_fill;
|
|
|
|
|
|
|
|
if ( size && size->root.metrics.y_ppem < 24 )
|
|
|
|
outline->flags |= ft_outline_high_precision;
|
|
|
|
|
|
|
|
/* compute the advance vector */
|
|
|
|
metrics->horiAdvance = 0;
|
|
|
|
metrics->vertAdvance = 0;
|
|
|
|
|
|
|
|
advance = gchar->advance;
|
|
|
|
em_metrics = face->phy_font.metrics_resolution;
|
|
|
|
em_outline = face->phy_font.outline_resolution;
|
|
|
|
|
|
|
|
if ( em_metrics != em_outline )
|
|
|
|
advance = FT_MulDiv( advance, em_outline, em_metrics );
|
|
|
|
|
|
|
|
if ( face->phy_font.flags & PFR_PHY_VERTICAL )
|
|
|
|
metrics->vertAdvance = gchar->advance;
|
|
|
|
else
|
|
|
|
metrics->horiAdvance = gchar->advance;
|
|
|
|
|
|
|
|
slot->root.linearHoriAdvance = metrics->horiAdvance;
|
|
|
|
slot->root.linearVertAdvance = metrics->vertAdvance;
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
/* make-up vertical metrics(?) */
|
2002-04-19 17:13:47 +02:00
|
|
|
metrics->vertBearingX = 0;
|
|
|
|
metrics->vertBearingY = 0;
|
|
|
|
|
|
|
|
/* scale when needed */
|
|
|
|
if ( scaling )
|
|
|
|
{
|
|
|
|
FT_Int n;
|
|
|
|
FT_Fixed x_scale = size->root.metrics.x_scale;
|
|
|
|
FT_Fixed y_scale = size->root.metrics.y_scale;
|
|
|
|
FT_Vector* vec = outline->points;
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
|
2002-04-19 17:13:47 +02:00
|
|
|
/* scale outline points */
|
|
|
|
for ( n = 0; n < outline->n_points; n++, vec++ )
|
|
|
|
{
|
|
|
|
vec->x = FT_MulFix( vec->x, x_scale );
|
|
|
|
vec->y = FT_MulFix( vec->y, y_scale );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* scale the advance */
|
|
|
|
metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, x_scale );
|
|
|
|
metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, y_scale );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compute the rest of the metrics */
|
|
|
|
FT_Outline_Get_CBox( outline, &cbox );
|
|
|
|
|
|
|
|
metrics->width = cbox.xMax - cbox.xMin;
|
|
|
|
metrics->height = cbox.yMax - cbox.yMin;
|
|
|
|
metrics->horiBearingX = cbox.xMin;
|
|
|
|
metrics->horiBearingY = cbox.yMax - metrics->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
2002-04-20 07:38:33 +02:00
|
|
|
|
|
|
|
|
2002-06-21 09:33:23 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** KERNING METHOD *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/* XXX: This relies on the font being spec-conformant, i.e. that the
|
|
|
|
kerning pairs are sorted. We might want to sort it just to make
|
|
|
|
sure */
|
|
|
|
|
|
|
|
#undef PFR_KERN_INDEX
|
|
|
|
#define PFR_KERN_INDEX( g1, g2 ) ( ( (FT_ULong)g1 << 16 ) | g2 )
|
|
|
|
|
|
|
|
/* find the kerning for a given glyph pair */
|
|
|
|
FT_LOCAL_DEF( FT_Error )
|
|
|
|
pfr_face_get_kerning( PFR_Face face,
|
|
|
|
FT_UInt glyph1,
|
|
|
|
FT_UInt glyph2,
|
|
|
|
FT_Vector* kerning )
|
|
|
|
{
|
|
|
|
PFR_PhyFont phy_font = &face->phy_font;
|
|
|
|
PFR_KernPair min, mid, max;
|
|
|
|
FT_ULong idx = PFR_KERN_INDEX( glyph1, glyph2 );
|
|
|
|
|
|
|
|
/* simple binary search */
|
|
|
|
min = phy_font->kern_pairs;
|
|
|
|
max = min + phy_font->num_kern_pairs;
|
|
|
|
|
|
|
|
while ( min < max )
|
|
|
|
{
|
|
|
|
FT_ULong midi;
|
|
|
|
|
|
|
|
mid = min + ( max - min ) / 2;
|
|
|
|
midi = PFR_KERN_INDEX( mid->glyph1, mid->glyph2 );
|
|
|
|
|
|
|
|
if ( midi == idx )
|
|
|
|
{
|
|
|
|
*kerning = mid->kerning;
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( midi < idx )
|
|
|
|
min = mid + 1;
|
|
|
|
else
|
|
|
|
max = mid;
|
|
|
|
}
|
|
|
|
|
|
|
|
kerning->x = 0;
|
|
|
|
kerning->y = 0;
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
/* END */
|