1 /***************************************************************************/ 2 /* */ 3 /* ftgloadr.c */ 4 /* */ 5 /* The FreeType glyph loader (body). */ 6 /* */ 7 /* Copyright 2002-2018 by */ 8 /* David Turner, Robert Wilhelm, and Werner Lemberg */ 9 /* */ 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 */ 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 /* this file you indicate that you have read the license and */ 14 /* understand and accept it fully. */ 15 /* */ 16 /***************************************************************************/ 17 18 19 #include <ft2build.h> 20 #include FT_INTERNAL_DEBUG_H 21 #include FT_INTERNAL_GLYPH_LOADER_H 22 #include FT_INTERNAL_MEMORY_H 23 #include FT_INTERNAL_OBJECTS_H 24 25 #undef FT_COMPONENT 26 #define FT_COMPONENT trace_gloader 27 28 29 /*************************************************************************/ 30 /*************************************************************************/ 31 /*************************************************************************/ 32 /***** *****/ 33 /***** *****/ 34 /***** G L Y P H L O A D E R *****/ 35 /***** *****/ 36 /***** *****/ 37 /*************************************************************************/ 38 /*************************************************************************/ 39 /*************************************************************************/ 40 41 /*************************************************************************/ 42 /* */ 43 /* The glyph loader is a simple object which is used to load a set of */ 44 /* glyphs easily. It is critical for the correct loading of composites. */ 45 /* */ 46 /* Ideally, one can see it as a stack of abstract `glyph' objects. */ 47 /* */ 48 /* loader.base Is really the bottom of the stack. It describes a */ 49 /* single glyph image made of the juxtaposition of */ 50 /* several glyphs (those `in the stack'). */ 51 /* */ 52 /* loader.current Describes the top of the stack, on which a new */ 53 /* glyph can be loaded. */ 54 /* */ 55 /* Rewind Clears the stack. */ 56 /* Prepare Set up `loader.current' for addition of a new glyph */ 57 /* image. */ 58 /* Add Add the `current' glyph image to the `base' one, */ 59 /* and prepare for another one. */ 60 /* */ 61 /* The glyph loader is now a base object. Each driver used to */ 62 /* re-implement it in one way or the other, which wasted code and */ 63 /* energy. */ 64 /* */ 65 /*************************************************************************/ 66 67 68 /* create a new glyph loader */ 69 FT_BASE_DEF( FT_Error ) 70 FT_GlyphLoader_New( FT_Memory memory, 71 FT_GlyphLoader *aloader ) 72 { 73 FT_GlyphLoader loader = NULL; 74 FT_Error error; 75 76 77 if ( !FT_NEW( loader ) ) 78 { 79 loader->memory = memory; 80 *aloader = loader; 81 } 82 return error; 83 } 84 85 86 /* rewind the glyph loader - reset counters to 0 */ 87 FT_BASE_DEF( void ) 88 FT_GlyphLoader_Rewind( FT_GlyphLoader loader ) 89 { 90 FT_GlyphLoad base = &loader->base; 91 FT_GlyphLoad current = &loader->current; 92 93 94 base->outline.n_points = 0; 95 base->outline.n_contours = 0; 96 base->num_subglyphs = 0; 97 98 *current = *base; 99 } 100 101 102 /* reset the glyph loader, frees all allocated tables */ 103 /* and starts from zero */ 104 FT_BASE_DEF( void ) 105 FT_GlyphLoader_Reset( FT_GlyphLoader loader ) 106 { 107 FT_Memory memory = loader->memory; 108 109 110 FT_FREE( loader->base.outline.points ); 111 FT_FREE( loader->base.outline.tags ); 112 FT_FREE( loader->base.outline.contours ); 113 FT_FREE( loader->base.extra_points ); 114 FT_FREE( loader->base.subglyphs ); 115 116 loader->base.extra_points2 = NULL; 117 118 loader->max_points = 0; 119 loader->max_contours = 0; 120 loader->max_subglyphs = 0; 121 122 FT_GlyphLoader_Rewind( loader ); 123 } 341 base = &loader->base; 342 current = &loader->current; 343 344 n_curr_contours = current->outline.n_contours; 345 n_base_points = base->outline.n_points; 346 347 base->outline.n_points = 348 (short)( base->outline.n_points + current->outline.n_points ); 349 base->outline.n_contours = 350 (short)( base->outline.n_contours + current->outline.n_contours ); 351 352 base->num_subglyphs += current->num_subglyphs; 353 354 /* adjust contours count in newest outline */ 355 for ( n = 0; n < n_curr_contours; n++ ) 356 current->outline.contours[n] = 357 (short)( current->outline.contours[n] + n_base_points ); 358 359 /* prepare for another new glyph image */ 360 FT_GlyphLoader_Prepare( loader ); 361 } 362 363 364 FT_BASE_DEF( FT_Error ) 365 FT_GlyphLoader_CopyPoints( FT_GlyphLoader target, 366 FT_GlyphLoader source ) 367 { 368 FT_Error error; 369 FT_UInt num_points = (FT_UInt)source->base.outline.n_points; 370 FT_UInt num_contours = (FT_UInt)source->base.outline.n_contours; 371 372 373 error = FT_GlyphLoader_CheckPoints( target, num_points, num_contours ); 374 if ( !error ) 375 { 376 FT_Outline* out = &target->base.outline; 377 FT_Outline* in = &source->base.outline; 378 379 380 FT_ARRAY_COPY( out->points, in->points, 381 num_points ); 382 FT_ARRAY_COPY( out->tags, in->tags, 383 num_points ); 384 FT_ARRAY_COPY( out->contours, in->contours, 385 num_contours ); 386 387 /* do we need to copy the extra points? */ 388 if ( target->use_extra && source->use_extra ) 389 { 390 FT_ARRAY_COPY( target->base.extra_points, source->base.extra_points, 391 num_points ); 392 FT_ARRAY_COPY( target->base.extra_points2, source->base.extra_points2, 393 num_points ); 394 } 395 396 out->n_points = (short)num_points; 397 out->n_contours = (short)num_contours; 398 399 FT_GlyphLoader_Adjust_Points( target ); 400 } 401 402 return error; 403 } 404 405 406 /* END */ | 1 /**************************************************************************** 2 * 3 * ftgloadr.c 4 * 5 * The FreeType glyph loader (body). 6 * 7 * Copyright (C) 2002-2019 by 8 * David Turner, Robert Wilhelm, and Werner Lemberg 9 * 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 12 * license, LICENSE.TXT. By continuing to use, modify, or distribute 13 * this file you indicate that you have read the license and 14 * understand and accept it fully. 15 * 16 */ 17 18 19 #include <ft2build.h> 20 #include FT_INTERNAL_DEBUG_H 21 #include FT_INTERNAL_GLYPH_LOADER_H 22 #include FT_INTERNAL_MEMORY_H 23 #include FT_INTERNAL_OBJECTS_H 24 25 #undef FT_COMPONENT 26 #define FT_COMPONENT gloader 27 28 29 /*************************************************************************/ 30 /*************************************************************************/ 31 /*************************************************************************/ 32 /***** *****/ 33 /***** *****/ 34 /***** G L Y P H L O A D E R *****/ 35 /***** *****/ 36 /***** *****/ 37 /*************************************************************************/ 38 /*************************************************************************/ 39 /*************************************************************************/ 40 41 /************************************************************************** 42 * 43 * The glyph loader is a simple object which is used to load a set of 44 * glyphs easily. It is critical for the correct loading of composites. 45 * 46 * Ideally, one can see it as a stack of abstract `glyph' objects. 47 * 48 * loader.base Is really the bottom of the stack. It describes a 49 * single glyph image made of the juxtaposition of 50 * several glyphs (those `in the stack'). 51 * 52 * loader.current Describes the top of the stack, on which a new 53 * glyph can be loaded. 54 * 55 * Rewind Clears the stack. 56 * Prepare Set up `loader.current' for addition of a new glyph 57 * image. 58 * Add Add the `current' glyph image to the `base' one, 59 * and prepare for another one. 60 * 61 * The glyph loader is now a base object. Each driver used to 62 * re-implement it in one way or the other, which wasted code and 63 * energy. 64 * 65 */ 66 67 68 /* create a new glyph loader */ 69 FT_BASE_DEF( FT_Error ) 70 FT_GlyphLoader_New( FT_Memory memory, 71 FT_GlyphLoader *aloader ) 72 { 73 FT_GlyphLoader loader = NULL; 74 FT_Error error; 75 76 77 if ( !FT_NEW( loader ) ) 78 { 79 loader->memory = memory; 80 *aloader = loader; 81 } 82 return error; 83 } 84 85 86 /* rewind the glyph loader - reset counters to 0 */ 87 FT_BASE_DEF( void ) 88 FT_GlyphLoader_Rewind( FT_GlyphLoader loader ) 89 { 90 FT_GlyphLoad base = &loader->base; 91 FT_GlyphLoad current = &loader->current; 92 93 94 base->outline.n_points = 0; 95 base->outline.n_contours = 0; 96 base->num_subglyphs = 0; 97 98 *current = *base; 99 } 100 101 102 /* reset glyph loader, free all allocated tables, */ 103 /* and start from zero */ 104 FT_BASE_DEF( void ) 105 FT_GlyphLoader_Reset( FT_GlyphLoader loader ) 106 { 107 FT_Memory memory = loader->memory; 108 109 110 FT_FREE( loader->base.outline.points ); 111 FT_FREE( loader->base.outline.tags ); 112 FT_FREE( loader->base.outline.contours ); 113 FT_FREE( loader->base.extra_points ); 114 FT_FREE( loader->base.subglyphs ); 115 116 loader->base.extra_points2 = NULL; 117 118 loader->max_points = 0; 119 loader->max_contours = 0; 120 loader->max_subglyphs = 0; 121 122 FT_GlyphLoader_Rewind( loader ); 123 } 341 base = &loader->base; 342 current = &loader->current; 343 344 n_curr_contours = current->outline.n_contours; 345 n_base_points = base->outline.n_points; 346 347 base->outline.n_points = 348 (short)( base->outline.n_points + current->outline.n_points ); 349 base->outline.n_contours = 350 (short)( base->outline.n_contours + current->outline.n_contours ); 351 352 base->num_subglyphs += current->num_subglyphs; 353 354 /* adjust contours count in newest outline */ 355 for ( n = 0; n < n_curr_contours; n++ ) 356 current->outline.contours[n] = 357 (short)( current->outline.contours[n] + n_base_points ); 358 359 /* prepare for another new glyph image */ 360 FT_GlyphLoader_Prepare( loader ); 361 } 362 363 364 /* END */ |