📄 pfrobjs.c
字号:
/***************************************************************************/
/* */
/* pfrobjs.c */
/* */
/* FreeType PFR object methods (body). */
/* */
/* Copyright 2002, 2003, 2004, 2005, 2006, 2007 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. */
/* */
/***************************************************************************/
#include "pfrobjs.h"
#include "pfrload.h"
#include "pfrgload.h"
#include "pfrcmap.h"
#include "pfrsbit.h"
#include FT_OUTLINE_H
#include FT_INTERNAL_DEBUG_H
#include "pfrerror.h"
#undef FT_COMPONENT
#define FT_COMPONENT trace_pfr
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** FACE OBJECT METHODS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
FT_LOCAL_DEF( void )
pfr_face_done( FT_Face pfrface ) /* PFR_Face */
{
PFR_Face face = (PFR_Face)pfrface;
FT_Memory memory = pfrface->driver->root.memory;
/* we don't want dangling pointers */
pfrface->family_name = NULL;
pfrface->style_name = NULL;
/* finalize the physical font record */
pfr_phy_font_done( &face->phy_font, FT_FACE_MEMORY( face ) );
/* no need to finalize the logical font or the header */
FT_FREE( pfrface->available_sizes );
}
FT_LOCAL_DEF( FT_Error )
pfr_face_init( FT_Stream stream,
FT_Face pfrface,
FT_Int face_index,
FT_Int num_params,
FT_Parameter* params )
{
PFR_Face face = (PFR_Face)pfrface;
FT_Error error;
FT_UNUSED( num_params );
FT_UNUSED( params );
/* load the header and check it */
error = pfr_header_load( &face->header, stream );
if ( error )
goto Exit;
if ( !pfr_header_check( &face->header ) )
{
FT_TRACE4(( "pfr_face_init: not a valid PFR font\n" ));
error = PFR_Err_Unknown_File_Format;
goto Exit;
}
/* check face index */
{
FT_UInt num_faces;
error = pfr_log_font_count( stream,
face->header.log_dir_offset,
&num_faces );
if ( error )
goto Exit;
pfrface->num_faces = num_faces;
}
if ( face_index < 0 )
goto Exit;
if ( face_index >= pfrface->num_faces )
{
FT_ERROR(( "pfr_face_init: invalid face index\n" ));
error = PFR_Err_Invalid_Argument;
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 */
{
PFR_PhyFont phy_font = &face->phy_font;
pfrface->face_index = face_index;
pfrface->num_glyphs = phy_font->num_chars + 1;
pfrface->face_flags = FT_FACE_FLAG_SCALABLE;
/* if all characters point to the same gps_offset 0, we */
/* assume that the font only contains bitmaps */
{
FT_UInt nn;
for ( nn = 0; nn < phy_font->num_chars; nn++ )
if ( phy_font->chars[nn].gps_offset != 0 )
break;
if ( nn == phy_font->num_chars )
pfrface->face_flags = 0; /* not scalable */
}
if ( (phy_font->flags & PFR_PHY_PROPORTIONAL) == 0 )
pfrface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
if ( phy_font->flags & PFR_PHY_VERTICAL )
pfrface->face_flags |= FT_FACE_FLAG_VERTICAL;
else
pfrface->face_flags |= FT_FACE_FLAG_HORIZONTAL;
if ( phy_font->num_strikes > 0 )
pfrface->face_flags |= FT_FACE_FLAG_FIXED_SIZES;
if ( phy_font->num_kern_pairs > 0 )
pfrface->face_flags |= FT_FACE_FLAG_KERNING;
/* If no family name was found in the "undocumented" auxiliary
* data, use the font ID instead. This sucks but is better than
* nothing.
*/
pfrface->family_name = phy_font->family_name;
if ( pfrface->family_name == NULL )
pfrface->family_name = phy_font->font_id;
/* note that the style name can be NULL in certain PFR fonts,
* probably meaning "Regular"
*/
pfrface->style_name = phy_font->style_name;
pfrface->num_fixed_sizes = 0;
pfrface->available_sizes = 0;
pfrface->bbox = phy_font->bbox;
pfrface->units_per_EM = (FT_UShort)phy_font->outline_resolution;
pfrface->ascender = (FT_Short) phy_font->bbox.yMax;
pfrface->descender = (FT_Short) phy_font->bbox.yMin;
pfrface->height = (FT_Short)( ( pfrface->units_per_EM * 12 ) / 10 );
if ( pfrface->height < pfrface->ascender - pfrface->descender )
pfrface->height = (FT_Short)(pfrface->ascender - pfrface->descender);
if ( phy_font->num_strikes > 0 )
{
FT_UInt n, count = phy_font->num_strikes;
FT_Bitmap_Size* size;
PFR_Strike strike;
FT_Memory memory = pfrface->stream->memory;
if ( FT_NEW_ARRAY( pfrface->available_sizes, count ) )
goto Exit;
size = pfrface->available_sizes;
strike = phy_font->strikes;
for ( n = 0; n < count; n++, size++, strike++ )
{
size->height = (FT_UShort)strike->y_ppm;
size->width = (FT_UShort)strike->x_ppm;
size->size = strike->y_ppm << 6;
size->x_ppem = strike->x_ppm << 6;
size->y_ppem = strike->y_ppm << 6;
}
pfrface->num_fixed_sizes = count;
}
/* now compute maximum advance width */
if ( ( phy_font->flags & PFR_PHY_PROPORTIONAL ) == 0 )
pfrface->max_advance_width = (FT_Short)phy_font->standard_advance;
else
{
FT_Int max = 0;
FT_UInt count = phy_font->num_chars;
PFR_Char gchar = phy_font->chars;
for ( ; count > 0; count--, gchar++ )
{
if ( max < gchar->advance )
max = gchar->advance;
}
pfrface->max_advance_width = (FT_Short)max;
}
pfrface->max_advance_height = pfrface->height;
pfrface->underline_position = (FT_Short)( -pfrface->units_per_EM / 10 );
pfrface->underline_thickness = (FT_Short)( pfrface->units_per_EM / 30 );
/* create charmap */
{
FT_CharMapRec charmap;
charmap.face = pfrface;
charmap.platform_id = 3;
charmap.encoding_id = 1;
charmap.encoding = FT_ENCODING_UNICODE;
FT_CMap_New( &pfr_cmap_class_rec, NULL, &charmap, NULL );
#if 0
/* Select default charmap */
if ( pfrface->num_charmaps )
pfrface->charmap = pfrface->charmaps[0];
#endif
}
/* check whether we've loaded any kerning pairs */
if ( phy_font->num_kern_pairs )
pfrface->face_flags |= FT_FACE_FLAG_KERNING;
}
Exit:
return error;
}
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** SLOT OBJECT METHOD *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
FT_LOCAL_DEF( FT_Error )
pfr_slot_init( FT_GlyphSlot pfrslot ) /* PFR_Slot */
{
PFR_Slot slot = (PFR_Slot)pfrslot;
FT_GlyphLoader loader = pfrslot->internal->loader;
pfr_glyph_init( &slot->glyph, loader );
return 0;
}
FT_LOCAL_DEF( void )
pfr_slot_done( FT_GlyphSlot pfrslot ) /* PFR_Slot */
{
PFR_Slot slot = (PFR_Slot)pfrslot;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -