| OLD | NEW |
| 1 /***************************************************************************/ | 1 /***************************************************************************/ |
| 2 /* */ | 2 /* */ |
| 3 /* ftadvanc.c */ | 3 /* ftadvanc.c */ |
| 4 /* */ | 4 /* */ |
| 5 /* Quick computation of advance widths (body). */ | 5 /* Quick computation of advance widths (body). */ |
| 6 /* */ | 6 /* */ |
| 7 /* Copyright 2008, 2009, 2011 by */ | 7 /* Copyright 2008, 2009, 2011, 2013 by */ |
| 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ | 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 9 /* */ | 9 /* */ |
| 10 /* This file is part of the FreeType project, and may only be used, */ | 10 /* This file is part of the FreeType project, and may only be used, */ |
| 11 /* modified, and distributed under the terms of the FreeType project */ | 11 /* modified, and distributed under the terms of the FreeType project */ |
| 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
| 13 /* this file you indicate that you have read the license and */ | 13 /* this file you indicate that you have read the license and */ |
| 14 /* understand and accept it fully. */ | 14 /* understand and accept it fully. */ |
| 15 /* */ | 15 /* */ |
| 16 /***************************************************************************/ | 16 /***************************************************************************/ |
| 17 | 17 |
| 18 | 18 |
| 19 #include <ft2build.h> | 19 #include <ft2build.h> |
| 20 #include FT_INTERNAL_DEBUG_H |
| 21 |
| 20 #include FT_ADVANCES_H | 22 #include FT_ADVANCES_H |
| 21 #include FT_INTERNAL_OBJECTS_H | 23 #include FT_INTERNAL_OBJECTS_H |
| 22 | 24 |
| 23 | 25 |
| 24 static FT_Error | 26 static FT_Error |
| 25 _ft_face_scale_advances( FT_Face face, | 27 _ft_face_scale_advances( FT_Face face, |
| 26 FT_Fixed* advances, | 28 FT_Fixed* advances, |
| 27 FT_UInt count, | 29 FT_UInt count, |
| 28 FT_Int32 flags ) | 30 FT_Int32 flags ) |
| 29 { | 31 { |
| 30 FT_Fixed scale; | 32 FT_Fixed scale; |
| 31 FT_UInt nn; | 33 FT_UInt nn; |
| 32 | 34 |
| 33 | 35 |
| 34 if ( flags & FT_LOAD_NO_SCALE ) | 36 if ( flags & FT_LOAD_NO_SCALE ) |
| 35 return FT_Err_Ok; | 37 return FT_Err_Ok; |
| 36 | 38 |
| 37 if ( face->size == NULL ) | 39 if ( face->size == NULL ) |
| 38 return FT_Err_Invalid_Size_Handle; | 40 return FT_THROW( Invalid_Size_Handle ); |
| 39 | 41 |
| 40 if ( flags & FT_LOAD_VERTICAL_LAYOUT ) | 42 if ( flags & FT_LOAD_VERTICAL_LAYOUT ) |
| 41 scale = face->size->metrics.y_scale; | 43 scale = face->size->metrics.y_scale; |
| 42 else | 44 else |
| 43 scale = face->size->metrics.x_scale; | 45 scale = face->size->metrics.x_scale; |
| 44 | 46 |
| 45 /* this must be the same scaling as to get linear{Hori,Vert}Advance */ | 47 /* this must be the same scaling as to get linear{Hori,Vert}Advance */ |
| 46 /* (see `FT_Load_Glyph' implementation in src/base/ftobjs.c) */ | 48 /* (see `FT_Load_Glyph' implementation in src/base/ftobjs.c) */ |
| 47 | 49 |
| 48 for ( nn = 0; nn < count; nn++ ) | 50 for ( nn = 0; nn < count; nn++ ) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 69 FT_EXPORT_DEF( FT_Error ) | 71 FT_EXPORT_DEF( FT_Error ) |
| 70 FT_Get_Advance( FT_Face face, | 72 FT_Get_Advance( FT_Face face, |
| 71 FT_UInt gindex, | 73 FT_UInt gindex, |
| 72 FT_Int32 flags, | 74 FT_Int32 flags, |
| 73 FT_Fixed *padvance ) | 75 FT_Fixed *padvance ) |
| 74 { | 76 { |
| 75 FT_Face_GetAdvancesFunc func; | 77 FT_Face_GetAdvancesFunc func; |
| 76 | 78 |
| 77 | 79 |
| 78 if ( !face ) | 80 if ( !face ) |
| 79 return FT_Err_Invalid_Face_Handle; | 81 return FT_THROW( Invalid_Face_Handle ); |
| 80 | 82 |
| 81 if ( gindex >= (FT_UInt)face->num_glyphs ) | 83 if ( gindex >= (FT_UInt)face->num_glyphs ) |
| 82 return FT_Err_Invalid_Glyph_Index; | 84 return FT_THROW( Invalid_Glyph_Index ); |
| 83 | 85 |
| 84 func = face->driver->clazz->get_advances; | 86 func = face->driver->clazz->get_advances; |
| 85 if ( func && LOAD_ADVANCE_FAST_CHECK( flags ) ) | 87 if ( func && LOAD_ADVANCE_FAST_CHECK( flags ) ) |
| 86 { | 88 { |
| 87 FT_Error error; | 89 FT_Error error; |
| 88 | 90 |
| 89 | 91 |
| 90 error = func( face, gindex, 1, flags, padvance ); | 92 error = func( face, gindex, 1, flags, padvance ); |
| 91 if ( !error ) | 93 if ( !error ) |
| 92 return _ft_face_scale_advances( face, padvance, 1, flags ); | 94 return _ft_face_scale_advances( face, padvance, 1, flags ); |
| 93 | 95 |
| 94 if ( error != FT_ERROR_BASE( FT_Err_Unimplemented_Feature ) ) | 96 if ( FT_ERR_NEQ( error, Unimplemented_Feature ) ) |
| 95 return error; | 97 return error; |
| 96 } | 98 } |
| 97 | 99 |
| 98 return FT_Get_Advances( face, gindex, 1, flags, padvance ); | 100 return FT_Get_Advances( face, gindex, 1, flags, padvance ); |
| 99 } | 101 } |
| 100 | 102 |
| 101 | 103 |
| 102 /* documentation is in ftadvanc.h */ | 104 /* documentation is in ftadvanc.h */ |
| 103 | 105 |
| 104 FT_EXPORT_DEF( FT_Error ) | 106 FT_EXPORT_DEF( FT_Error ) |
| 105 FT_Get_Advances( FT_Face face, | 107 FT_Get_Advances( FT_Face face, |
| 106 FT_UInt start, | 108 FT_UInt start, |
| 107 FT_UInt count, | 109 FT_UInt count, |
| 108 FT_Int32 flags, | 110 FT_Int32 flags, |
| 109 FT_Fixed *padvances ) | 111 FT_Fixed *padvances ) |
| 110 { | 112 { |
| 111 FT_Face_GetAdvancesFunc func; | 113 FT_Face_GetAdvancesFunc func; |
| 112 FT_UInt num, end, nn; | 114 FT_UInt num, end, nn; |
| 113 FT_Error error = FT_Err_Ok; | 115 FT_Error error = FT_Err_Ok; |
| 114 | 116 |
| 115 | 117 |
| 116 if ( !face ) | 118 if ( !face ) |
| 117 return FT_Err_Invalid_Face_Handle; | 119 return FT_THROW( Invalid_Face_Handle ); |
| 118 | 120 |
| 119 num = (FT_UInt)face->num_glyphs; | 121 num = (FT_UInt)face->num_glyphs; |
| 120 end = start + count; | 122 end = start + count; |
| 121 if ( start >= num || end < start || end > num ) | 123 if ( start >= num || end < start || end > num ) |
| 122 return FT_Err_Invalid_Glyph_Index; | 124 return FT_THROW( Invalid_Glyph_Index ); |
| 123 | 125 |
| 124 if ( count == 0 ) | 126 if ( count == 0 ) |
| 125 return FT_Err_Ok; | 127 return FT_Err_Ok; |
| 126 | 128 |
| 127 func = face->driver->clazz->get_advances; | 129 func = face->driver->clazz->get_advances; |
| 128 if ( func && LOAD_ADVANCE_FAST_CHECK( flags ) ) | 130 if ( func && LOAD_ADVANCE_FAST_CHECK( flags ) ) |
| 129 { | 131 { |
| 130 error = func( face, start, count, flags, padvances ); | 132 error = func( face, start, count, flags, padvances ); |
| 131 if ( !error ) | 133 if ( !error ) |
| 132 return _ft_face_scale_advances( face, padvances, count, flags ); | 134 return _ft_face_scale_advances( face, padvances, count, flags ); |
| 133 | 135 |
| 134 if ( error != FT_ERROR_BASE( FT_Err_Unimplemented_Feature ) ) | 136 if ( FT_ERR_NEQ( error, Unimplemented_Feature ) ) |
| 135 return error; | 137 return error; |
| 136 } | 138 } |
| 137 | 139 |
| 138 error = FT_Err_Ok; | 140 error = FT_Err_Ok; |
| 139 | 141 |
| 140 if ( flags & FT_ADVANCE_FLAG_FAST_ONLY ) | 142 if ( flags & FT_ADVANCE_FLAG_FAST_ONLY ) |
| 141 return FT_Err_Unimplemented_Feature; | 143 return FT_THROW( Unimplemented_Feature ); |
| 142 | 144 |
| 143 flags |= (FT_UInt32)FT_LOAD_ADVANCE_ONLY; | 145 flags |= (FT_UInt32)FT_LOAD_ADVANCE_ONLY; |
| 144 for ( nn = 0; nn < count; nn++ ) | 146 for ( nn = 0; nn < count; nn++ ) |
| 145 { | 147 { |
| 146 error = FT_Load_Glyph( face, start + nn, flags ); | 148 error = FT_Load_Glyph( face, start + nn, flags ); |
| 147 if ( error ) | 149 if ( error ) |
| 148 break; | 150 break; |
| 149 | 151 |
| 150 /* scale from 26.6 to 16.16 */ | 152 /* scale from 26.6 to 16.16 */ |
| 151 padvances[nn] = ( flags & FT_LOAD_VERTICAL_LAYOUT ) | 153 padvances[nn] = ( flags & FT_LOAD_VERTICAL_LAYOUT ) |
| 152 ? face->glyph->advance.y << 10 | 154 ? face->glyph->advance.y << 10 |
| 153 : face->glyph->advance.x << 10; | 155 : face->glyph->advance.x << 10; |
| 154 } | 156 } |
| 155 | 157 |
| 156 return error; | 158 return error; |
| 157 } | 159 } |
| 158 | 160 |
| 159 | 161 |
| 160 /* END */ | 162 /* END */ |
| OLD | NEW |