⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftglyph.c

📁 qt-embedded-2.3.8.tar.gz源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************//*                                                                         *//*  ftglyph.c                                                              *//*                                                                         *//*    FreeType convenience functions to handle glyphs (body).              *//*                                                                         *//*  Copyright 1996-2000 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.                                        *//*                                                                         *//***************************************************************************/  /*************************************************************************/  /*                                                                       */  /*  This file contains the definition of several convenience functions   */  /*  that can be used by client applications to easily retrieve glyph     */  /*  bitmaps and outlines from a given face.                              */  /*                                                                       */  /*  These functions should be optional if you are writing a font server  */  /*  or text layout engine on top of FreeType.  However, they are pretty  */  /*  handy for many other simple uses of the library.                     */  /*                                                                       */  /*************************************************************************/#include <freetype/ftglyph.h>#include <freetype/ftoutln.h>#include <freetype/internal/ftobjs.h>  /*************************************************************************/  /*                                                                       */  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */  /* messages during execution.                                            */  /*                                                                       */#undef  FT_COMPONENT#define FT_COMPONENT  trace_glyph  /*************************************************************************/  /*************************************************************************/  /****                                                                 ****/  /****   Convenience functions                                         ****/  /****                                                                 ****/  /*************************************************************************/  /*************************************************************************/  /* documentation is in ftglyph.h */  FT_EXPORT_DEF( void )  FT_Matrix_Multiply( FT_Matrix*  a,                                             FT_Matrix*  b )  {    FT_Fixed  xx, xy, yx, yy;    if ( !a || !b )      return;    xx = FT_MulFix( a->xx, b->xx ) + FT_MulFix( a->xy, b->yx );    xy = FT_MulFix( a->xx, b->xy ) + FT_MulFix( a->xy, b->yy );    yx = FT_MulFix( a->yx, b->xx ) + FT_MulFix( a->yy, b->yx );    yy = FT_MulFix( a->yx, b->xy ) + FT_MulFix( a->yy, b->yy );    b->xx = xx;  b->xy = xy;    b->yx = yx;  b->yy = yy;  }  /* documentation is in ftglyph.h */  FT_EXPORT_DEF( FT_Error )  FT_Matrix_Invert( FT_Matrix*  matrix )  {    FT_Pos  delta, xx, yy;    if ( !matrix )      return FT_Err_Invalid_Argument;    /* compute discriminant */    delta = FT_MulFix( matrix->xx, matrix->yy ) -            FT_MulFix( matrix->xy, matrix->yx );    if ( !delta )      return FT_Err_Invalid_Argument;  /* matrix can't be inverted */    matrix->xy = - FT_DivFix( matrix->xy, delta );    matrix->yx = - FT_DivFix( matrix->yx, delta );    xx = matrix->xx;    yy = matrix->yy;    matrix->xx = FT_DivFix( yy, delta );    matrix->yy = FT_DivFix( xx, delta );    return FT_Err_Ok;  }  /*************************************************************************/  /*************************************************************************/  /****                                                                 ****/  /****   FT_BitmapGlyph support                                        ****/  /****                                                                 ****/  /*************************************************************************/  /*************************************************************************/  static  FT_Error  ft_bitmap_copy( FT_Memory   memory,                            FT_Bitmap*  source,                            FT_Bitmap*  target )  {    FT_Error  error;    FT_Int    pitch = source->pitch;    FT_ULong  size;    *target = *source;    if ( pitch < 0 )      pitch = -pitch;    size = (FT_ULong)( pitch * source->rows );    if ( !ALLOC( target->buffer, size ) )      MEM_Copy( target->buffer, source->buffer, size );    return error;  }  static  FT_Error  ft_bitmap_glyph_init( FT_BitmapGlyph  glyph,                                  FT_GlyphSlot    slot )  {    FT_Error    error   = FT_Err_Ok;    FT_Library  library = FT_GLYPH(glyph)->library;    FT_Memory   memory  = library->memory;    if ( slot->format != ft_glyph_format_bitmap )    {      error = FT_Err_Invalid_Glyph_Format;      goto Exit;    }    /* grab the bitmap in the slot - do lazy copying whenever possible */    glyph->bitmap = slot->bitmap;    glyph->left   = slot->bitmap_left;    glyph->top    = slot->bitmap_top;    if ( slot->flags & ft_glyph_own_bitmap )      slot->flags &= ~ft_glyph_own_bitmap;    else    {      /* copy the bitmap into a new buffer */      error = ft_bitmap_copy( memory, &slot->bitmap, &glyph->bitmap );    }  Exit:    return error;  }  static  FT_Error  ft_bitmap_glyph_copy( FT_BitmapGlyph  source,                                  FT_BitmapGlyph  target )  {    FT_Memory  memory = source->root.library->memory;    target->left = source->left;    target->top  = source->top;    return ft_bitmap_copy( memory, &source->bitmap, &target->bitmap );  }  static  void  ft_bitmap_glyph_done( FT_BitmapGlyph  glyph )  {    FT_Memory  memory = FT_GLYPH(glyph)->library->memory;    FREE( glyph->bitmap.buffer );  }  static  void  ft_bitmap_glyph_bbox( FT_BitmapGlyph  glyph,                              FT_BBox*        cbox )  {    cbox->xMin = glyph->left << 6;    cbox->xMax = cbox->xMin + ( glyph->bitmap.width << 6 );    cbox->yMax = glyph->top << 6;    cbox->yMin = cbox->yMax - ( glyph->bitmap.rows << 6 );  }  const FT_Glyph_Class  ft_bitmap_glyph_class =  {    sizeof( FT_BitmapGlyphRec ),    ft_glyph_format_bitmap,    (FT_Glyph_Init_Func)     ft_bitmap_glyph_init,    (FT_Glyph_Done_Func)     ft_bitmap_glyph_done,    (FT_Glyph_Copy_Func)     ft_bitmap_glyph_copy,    (FT_Glyph_Transform_Func)0,    (FT_Glyph_BBox_Func)     ft_bitmap_glyph_bbox,    (FT_Glyph_Prepare_Func)  0  };  /*************************************************************************/  /*************************************************************************/  /****                                                                 ****/  /****   FT_OutlineGlyph support                                       ****/  /****                                                                 ****/  /*************************************************************************/  /*************************************************************************/  static  FT_Error  ft_outline_glyph_init( FT_OutlineGlyph  glyph,                                   FT_GlyphSlot     slot )  {    FT_Error     error   = FT_Err_Ok;    FT_Library   library = FT_GLYPH(glyph)->library;    FT_Outline*  source  = &slot->outline;    FT_Outline*  target  = &glyph->outline;    /* check format in glyph slot */    if ( slot->format != ft_glyph_format_outline )    {      error = FT_Err_Invalid_Glyph_Format;      goto Exit;    }    /* allocate new outline */    error = FT_Outline_New( library, source->n_points, source->n_contours,                            &glyph->outline );    if ( error )      goto Exit;    /* copy it */    MEM_Copy( target->points, source->points,              source->n_points * sizeof ( FT_Vector ) );    MEM_Copy( target->tags, source->tags,              source->n_points * sizeof ( FT_Byte ) );    MEM_Copy( target->contours, source->contours,              source->n_contours * sizeof ( FT_Short ) );    /* copy all flags, except the `ft_outline_owner' one */    target->flags = source->flags | ft_outline_owner;  Exit:    return error;  }  static  void  ft_outline_glyph_done( FT_OutlineGlyph  glyph )  {    FT_Outline_Done( FT_GLYPH( glyph )->library, &glyph->outline );  }  static  FT_Error  ft_outline_glyph_copy( FT_OutlineGlyph  source,                                   FT_OutlineGlyph  target )  {    FT_Error    error;    FT_Library  library = FT_GLYPH( source )->library;    error = FT_Outline_New( library, source->outline.n_points,                            source->outline.n_contours, &target->outline );    if ( !error )      FT_Outline_Copy( &source->outline, &target->outline );    return error;  }  static  void  ft_outline_glyph_transform( FT_OutlineGlyph  glyph,                                    FT_Matrix*       matrix,                                    FT_Vector*       delta )  {    if ( matrix )      FT_Outline_Transform( &glyph->outline, matrix );    if ( delta )      FT_Outline_Translate( &glyph->outline, delta->x, delta->y );  }  static  void  ft_outline_glyph_bbox( FT_OutlineGlyph  glyph,                               FT_BBox*         bbox )  {    FT_Outline_Get_CBox( &glyph->outline, bbox );  }  static  FT_Error  ft_outline_glyph_prepare( FT_OutlineGlyph  glyph,                                      FT_GlyphSlot     slot )  {    slot->format         = ft_glyph_format_outline;    slot->outline        = glyph->outline;    slot->outline.flags &= ~ft_outline_owner;    return FT_Err_Ok;  }  const FT_Glyph_Class  ft_outline_glyph_class =  {    sizeof( FT_OutlineGlyphRec ),    ft_glyph_format_outline,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -