📄 ftobjs.c
字号:
} else internal->transform_matrix = *matrix; /* set transform_flags bit flag 0 if `matrix' isn't the identity */ if ( ( matrix->xy | matrix->yx ) || matrix->xx != 0x10000L || matrix->yy != 0x10000L ) internal->transform_flags |= 1; if ( !delta ) { internal->transform_delta.x = 0; internal->transform_delta.y = 0; delta = &internal->transform_delta; } else internal->transform_delta = *delta; /* set transform_flags bit flag 1 if `delta' isn't the null vector */ if ( delta->x | delta->y ) internal->transform_flags |= 2; } static FT_Renderer ft_lookup_glyph_renderer( FT_GlyphSlot slot );#ifdef GRID_FIT_METRICS static void ft_glyphslot_grid_fit_metrics( FT_GlyphSlot slot, FT_Bool vertical ) { FT_Glyph_Metrics* metrics = &slot->metrics; FT_Pos right, bottom; if ( vertical ) { metrics->horiBearingX = FT_PIX_FLOOR( metrics->horiBearingX ); metrics->horiBearingY = FT_PIX_CEIL ( metrics->horiBearingY ); right = FT_PIX_CEIL( metrics->vertBearingX + metrics->width ); bottom = FT_PIX_CEIL( metrics->vertBearingY + metrics->height ); metrics->vertBearingX = FT_PIX_FLOOR( metrics->vertBearingX ); metrics->vertBearingY = FT_PIX_FLOOR( metrics->vertBearingY ); metrics->width = right - metrics->vertBearingX; metrics->height = bottom - metrics->vertBearingY; } else { metrics->vertBearingX = FT_PIX_FLOOR( metrics->vertBearingX ); metrics->vertBearingY = FT_PIX_FLOOR( metrics->vertBearingY ); right = FT_PIX_CEIL ( metrics->horiBearingX + metrics->width ); bottom = FT_PIX_FLOOR( metrics->horiBearingY - metrics->height ); metrics->horiBearingX = FT_PIX_FLOOR( metrics->horiBearingX ); metrics->horiBearingY = FT_PIX_CEIL ( metrics->horiBearingY ); metrics->width = right - metrics->horiBearingX; metrics->height = metrics->horiBearingY - bottom; } metrics->horiAdvance = FT_PIX_ROUND( metrics->horiAdvance ); metrics->vertAdvance = FT_PIX_ROUND( metrics->vertAdvance ); }#endif /* GRID_FIT_METRICS */ /* documentation is in freetype.h */ FT_EXPORT_DEF( FT_Error ) FT_Load_Glyph( FT_Face face, FT_UInt glyph_index, FT_Int32 load_flags ) { FT_Error error; FT_Driver driver; FT_GlyphSlot slot; FT_Library library; FT_Bool autohint = 0; FT_Module hinter; if ( !face || !face->size || !face->glyph ) return FT_Err_Invalid_Face_Handle; /* The validity test for `glyph_index' is performed by the */ /* font drivers. */ slot = face->glyph; ft_glyphslot_clear( slot ); driver = face->driver; library = driver->root.library; hinter = library->auto_hinter; /* resolve load flags dependencies */ if ( load_flags & FT_LOAD_NO_RECURSE ) load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_TRANSFORM; if ( load_flags & FT_LOAD_NO_SCALE ) { load_flags |= FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP; load_flags &= ~FT_LOAD_RENDER; } /* * Determine whether we need to auto-hint or not. * The general rules are: * * - Do only auto-hinting if we have a hinter module, * a scalable font format dealing with outlines, * and no transforms except simple slants. * * - Then, autohint if FT_LOAD_FORCE_AUTOHINT is set * or if we don't have a native font hinter. * * - Otherwise, auto-hint for LIGHT hinting mode. * * - Exception: The font requires the unpatented * bytecode interpreter to load properly. */ autohint = 0; if ( hinter && ( load_flags & FT_LOAD_NO_HINTING ) == 0 && ( load_flags & FT_LOAD_NO_AUTOHINT ) == 0 && FT_DRIVER_IS_SCALABLE( driver ) && FT_DRIVER_USES_OUTLINES( driver ) && face->internal->transform_matrix.yy > 0 && face->internal->transform_matrix.yx == 0 ) { if ( ( load_flags & FT_LOAD_FORCE_AUTOHINT ) != 0 || !FT_DRIVER_HAS_HINTER( driver ) ) autohint = 1; else { FT_Render_Mode mode = FT_LOAD_TARGET_MODE( load_flags ); if ( mode == FT_RENDER_MODE_LIGHT || face->internal->ignore_unpatented_hinter ) autohint = 1; } } if ( autohint ) { FT_AutoHinter_Service hinting; /* try to load embedded bitmaps first if available */ /* */ /* XXX: This is really a temporary hack that should disappear */ /* promptly with FreeType 2.1! */ /* */ if ( FT_HAS_FIXED_SIZES( face ) && ( load_flags & FT_LOAD_NO_BITMAP ) == 0 ) { error = driver->clazz->load_glyph( slot, face->size, glyph_index, load_flags | FT_LOAD_SBITS_ONLY ); if ( !error && slot->format == FT_GLYPH_FORMAT_BITMAP ) goto Load_Ok; } /* load auto-hinted outline */ hinting = (FT_AutoHinter_Service)hinter->clazz->module_interface; error = hinting->load_glyph( (FT_AutoHinter)hinter, slot, face->size, glyph_index, load_flags ); } else { error = driver->clazz->load_glyph( slot, face->size, glyph_index, load_flags ); if ( error ) goto Exit; if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) { /* check that the loaded outline is correct */ error = FT_Outline_Check( &slot->outline ); if ( error ) goto Exit;#ifdef GRID_FIT_METRICS if ( !( load_flags & FT_LOAD_NO_HINTING ) ) ft_glyphslot_grid_fit_metrics( slot, FT_BOOL( load_flags & FT_LOAD_VERTICAL_LAYOUT ) );#endif } } Load_Ok: /* compute the advance */ if ( load_flags & FT_LOAD_VERTICAL_LAYOUT ) { slot->advance.x = 0; slot->advance.y = slot->metrics.vertAdvance; } else { slot->advance.x = slot->metrics.horiAdvance; slot->advance.y = 0; } /* compute the linear advance in 16.16 pixels */ if ( ( load_flags & FT_LOAD_LINEAR_DESIGN ) == 0 && ( face->face_flags & FT_FACE_FLAG_SCALABLE ) ) { FT_Size_Metrics* metrics = &face->size->metrics; /* it's tricky! */ slot->linearHoriAdvance = FT_MulDiv( slot->linearHoriAdvance, metrics->x_scale, 64 ); slot->linearVertAdvance = FT_MulDiv( slot->linearVertAdvance, metrics->y_scale, 64 ); } if ( ( load_flags & FT_LOAD_IGNORE_TRANSFORM ) == 0 ) { FT_Face_Internal internal = face->internal; /* now, transform the glyph image if needed */ if ( internal->transform_flags ) { /* get renderer */ FT_Renderer renderer = ft_lookup_glyph_renderer( slot ); if ( renderer ) error = renderer->clazz->transform_glyph( renderer, slot, &internal->transform_matrix, &internal->transform_delta ); /* transform advance */ FT_Vector_Transform( &slot->advance, &internal->transform_matrix ); } } /* do we need to render the image now? */ if ( !error && slot->format != FT_GLYPH_FORMAT_BITMAP && slot->format != FT_GLYPH_FORMAT_COMPOSITE && load_flags & FT_LOAD_RENDER ) { FT_Render_Mode mode = FT_LOAD_TARGET_MODE( load_flags ); if ( mode == FT_RENDER_MODE_NORMAL && (load_flags & FT_LOAD_MONOCHROME ) ) mode = FT_RENDER_MODE_MONO; error = FT_Render_Glyph( slot, mode ); } Exit: return error; } /* documentation is in freetype.h */ FT_EXPORT_DEF( FT_Error ) FT_Load_Char( FT_Face face, FT_ULong char_code, FT_Int32 load_flags ) { FT_UInt glyph_index; if ( !face ) return FT_Err_Invalid_Face_Handle; glyph_index = (FT_UInt)char_code; if ( face->charmap ) glyph_index = FT_Get_Char_Index( face, char_code ); return FT_Load_Glyph( face, glyph_index, load_flags ); } /* destructor for sizes list */ static void destroy_size( FT_Memory memory, FT_Size size, FT_Driver driver ) { /* finalize client-specific data */ if ( size->generic.finalizer ) size->generic.finalizer( size ); /* finalize format-specific stuff */ if ( driver->clazz->done_size ) driver->clazz->done_size( size ); FT_FREE( size->internal ); FT_FREE( size ); } static void ft_cmap_done_internal( FT_CMap cmap ); static void destroy_charmaps( FT_Face face, FT_Memory memory ) { FT_Int n; for ( n = 0; n < face->num_charmaps; n++ ) { FT_CMap cmap = FT_CMAP( face->charmaps[n] ); ft_cmap_done_internal( cmap ); face->charmaps[n] = NULL; } FT_FREE( face->charmaps ); face->num_charmaps = 0; } /* destructor for faces list */ static void destroy_face( FT_Memory memory, FT_Face face, FT_Driver driver ) { FT_Driver_Class clazz = driver->clazz; /* discard auto-hinting data */ if ( face->autohint.finalizer ) face->autohint.finalizer( face->autohint.data ); /* Discard glyph slots for this face. */ /* Beware! FT_Done_GlyphSlot() changes the field `face->glyph' */ while ( face->glyph ) FT_Done_GlyphSlot( face->glyph ); /* discard all sizes for this face */ FT_List_Finalize( &face->sizes_list, (FT_List_Destructor)destroy_size, memory, driver ); face->size = 0; /* now discard client data */ if ( face->generic.finalizer ) face->generic.finalizer( face ); /* discard charmaps */ destroy_charmaps( face, memory ); /* finalize format-specific stuff */ if ( clazz->done_face ) clazz->done_face( face ); /* close the stream for this face if needed */ FT_Stream_Free( face->stream, ( face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 ); face->stream = 0; /* get rid of it */ if ( face->internal ) { FT_FREE( face->internal ); } FT_FREE( face ); } static void Destroy_Driver( FT_Driver driver ) { FT_List_Finalize( &driver->faces_list, (FT_List_Destructor)destroy_face, driver->root.memory, driver ); /* check whether we need to drop the driver's glyph loader */ if ( FT_DRIVER_USES_OUTLINES( driver ) ) FT_GlyphLoader_Done( driver->glyph_loader ); } /*************************************************************************/ /* */ /* <Function> */ /* find_unicode_charmap */ /* */ /* <Description> */ /* This function finds a Unicode charmap, if there is one. */ /* And if there is more than one, it tries to favour the more */ /* extensive one, i.e., one that supports UCS-4 against those which */ /* are limited to the BMP (said UCS-2 encoding.) */ /* */ /* This function is called from open_face() (just below), and also */ /* from FT_Select_Charmap( ..., FT_ENCODING_UNICODE). */ /* */ static FT_Error find_unicode_charmap( FT_Face face ) { FT_CharMap* first; FT_CharMap* cur; FT_CharMap* unicmap = NULL; /* some UCS-2 map, if we found it */ /* caller should have already checked that `face' is valid */ FT_ASSERT( face ); first = face->charmaps; if ( !first ) return FT_Err_Invalid_CharMap_Handle; /* * The original TrueType specification(s) only specified charmap * formats that are capable of mapping 8 or 16 bit character codes to * glyph indices. * * However, recent updates to the Apple and OpenType specifications * introduced new formats that are capable of mapping 32-bit character * codes as well. And these are already used on some fonts, mainly to * map non-BMP Asian ideographs as defined in Unicode. * * For compatibility purposes, these fonts generally come with * *several* Unicode charmaps: * * - One of them in the "old" 16-bit format, that cannot access * all glyphs in the font. * * - Another one in the "new" 32-bit format, that can access all * the glyphs. * * This function has been written to always favor a 32-bit charmap
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -