OLD | NEW |
1 /***************************************************************************/ | 1 /***************************************************************************/ |
2 /* */ | 2 /* */ |
3 /* ftglyph.c */ | 3 /* ftglyph.c */ |
4 /* */ | 4 /* */ |
5 /* FreeType convenience functions to handle glyphs (body). */ | 5 /* FreeType convenience functions to handle glyphs (body). */ |
6 /* */ | 6 /* */ |
7 /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2007, 2008, 2010 by */ | 7 /* Copyright 1996-2005, 2007, 2008, 2010, 2012, 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 /* */ | 19 /* */ |
20 /* This file contains the definition of several convenience functions */ | 20 /* This file contains the definition of several convenience functions */ |
21 /* that can be used by client applications to easily retrieve glyph */ | 21 /* that can be used by client applications to easily retrieve glyph */ |
22 /* bitmaps and outlines from a given face. */ | 22 /* bitmaps and outlines from a given face. */ |
23 /* */ | 23 /* */ |
24 /* These functions should be optional if you are writing a font server */ | 24 /* These functions should be optional if you are writing a font server */ |
25 /* or text layout engine on top of FreeType. However, they are pretty */ | 25 /* or text layout engine on top of FreeType. However, they are pretty */ |
26 /* handy for many other simple uses of the library. */ | 26 /* handy for many other simple uses of the library. */ |
27 /* */ | 27 /* */ |
28 /*************************************************************************/ | 28 /*************************************************************************/ |
29 | 29 |
30 | 30 |
31 #include <ft2build.h> | 31 #include <ft2build.h> |
| 32 #include FT_INTERNAL_DEBUG_H |
| 33 |
32 #include FT_GLYPH_H | 34 #include FT_GLYPH_H |
33 #include FT_OUTLINE_H | 35 #include FT_OUTLINE_H |
34 #include FT_BITMAP_H | 36 #include FT_BITMAP_H |
35 #include FT_INTERNAL_OBJECTS_H | 37 #include FT_INTERNAL_OBJECTS_H |
36 | 38 |
37 #include "basepic.h" | 39 #include "basepic.h" |
38 | 40 |
39 /*************************************************************************/ | 41 /*************************************************************************/ |
40 /* */ | 42 /* */ |
41 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ | 43 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
(...skipping 16 matching lines...) Expand all Loading... |
58 ft_bitmap_glyph_init( FT_Glyph bitmap_glyph, | 60 ft_bitmap_glyph_init( FT_Glyph bitmap_glyph, |
59 FT_GlyphSlot slot ) | 61 FT_GlyphSlot slot ) |
60 { | 62 { |
61 FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph; | 63 FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph; |
62 FT_Error error = FT_Err_Ok; | 64 FT_Error error = FT_Err_Ok; |
63 FT_Library library = FT_GLYPH( glyph )->library; | 65 FT_Library library = FT_GLYPH( glyph )->library; |
64 | 66 |
65 | 67 |
66 if ( slot->format != FT_GLYPH_FORMAT_BITMAP ) | 68 if ( slot->format != FT_GLYPH_FORMAT_BITMAP ) |
67 { | 69 { |
68 error = FT_Err_Invalid_Glyph_Format; | 70 error = FT_THROW( Invalid_Glyph_Format ); |
69 goto Exit; | 71 goto Exit; |
70 } | 72 } |
71 | 73 |
72 glyph->left = slot->bitmap_left; | 74 glyph->left = slot->bitmap_left; |
73 glyph->top = slot->bitmap_top; | 75 glyph->top = slot->bitmap_top; |
74 | 76 |
75 /* do lazy copying whenever possible */ | 77 /* do lazy copying whenever possible */ |
76 if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) | 78 if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) |
77 { | 79 { |
78 glyph->bitmap = slot->bitmap; | 80 glyph->bitmap = slot->bitmap; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph; | 161 FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph; |
160 FT_Error error = FT_Err_Ok; | 162 FT_Error error = FT_Err_Ok; |
161 FT_Library library = FT_GLYPH( glyph )->library; | 163 FT_Library library = FT_GLYPH( glyph )->library; |
162 FT_Outline* source = &slot->outline; | 164 FT_Outline* source = &slot->outline; |
163 FT_Outline* target = &glyph->outline; | 165 FT_Outline* target = &glyph->outline; |
164 | 166 |
165 | 167 |
166 /* check format in glyph slot */ | 168 /* check format in glyph slot */ |
167 if ( slot->format != FT_GLYPH_FORMAT_OUTLINE ) | 169 if ( slot->format != FT_GLYPH_FORMAT_OUTLINE ) |
168 { | 170 { |
169 error = FT_Err_Invalid_Glyph_Format; | 171 error = FT_THROW( Invalid_Glyph_Format ); |
170 goto Exit; | 172 goto Exit; |
171 } | 173 } |
172 | 174 |
173 /* allocate new outline */ | 175 /* allocate new outline */ |
174 error = FT_Outline_New( library, source->n_points, source->n_contours, | 176 error = FT_Outline_New( library, source->n_points, source->n_contours, |
175 &glyph->outline ); | 177 &glyph->outline ); |
176 if ( error ) | 178 if ( error ) |
177 goto Exit; | 179 goto Exit; |
178 | 180 |
179 FT_Outline_Copy( source, target ); | 181 FT_Outline_Copy( source, target ); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 FT_Glyph *target ) | 309 FT_Glyph *target ) |
308 { | 310 { |
309 FT_Glyph copy; | 311 FT_Glyph copy; |
310 FT_Error error; | 312 FT_Error error; |
311 const FT_Glyph_Class* clazz; | 313 const FT_Glyph_Class* clazz; |
312 | 314 |
313 | 315 |
314 /* check arguments */ | 316 /* check arguments */ |
315 if ( !target ) | 317 if ( !target ) |
316 { | 318 { |
317 error = FT_Err_Invalid_Argument; | 319 error = FT_THROW( Invalid_Argument ); |
318 goto Exit; | 320 goto Exit; |
319 } | 321 } |
320 | 322 |
321 *target = 0; | 323 *target = 0; |
322 | 324 |
323 if ( !source || !source->clazz ) | 325 if ( !source || !source->clazz ) |
324 { | 326 { |
325 error = FT_Err_Invalid_Argument; | 327 error = FT_THROW( Invalid_Argument ); |
326 goto Exit; | 328 goto Exit; |
327 } | 329 } |
328 | 330 |
329 clazz = source->clazz; | 331 clazz = source->clazz; |
330 error = ft_new_glyph( source->library, clazz, © ); | 332 error = ft_new_glyph( source->library, clazz, © ); |
331 if ( error ) | 333 if ( error ) |
332 goto Exit; | 334 goto Exit; |
333 | 335 |
334 copy->advance = source->advance; | 336 copy->advance = source->advance; |
335 copy->format = source->format; | 337 copy->format = source->format; |
(...skipping 18 matching lines...) Expand all Loading... |
354 FT_Glyph *aglyph ) | 356 FT_Glyph *aglyph ) |
355 { | 357 { |
356 FT_Library library; | 358 FT_Library library; |
357 FT_Error error; | 359 FT_Error error; |
358 FT_Glyph glyph; | 360 FT_Glyph glyph; |
359 | 361 |
360 const FT_Glyph_Class* clazz = 0; | 362 const FT_Glyph_Class* clazz = 0; |
361 | 363 |
362 | 364 |
363 if ( !slot ) | 365 if ( !slot ) |
364 return FT_Err_Invalid_Slot_Handle; | 366 return FT_THROW( Invalid_Slot_Handle ); |
365 | 367 |
366 library = slot->library; | 368 library = slot->library; |
367 | 369 |
368 if ( !aglyph ) | 370 if ( !aglyph ) |
369 return FT_Err_Invalid_Argument; | 371 return FT_THROW( Invalid_Argument ); |
370 | 372 |
371 /* if it is a bitmap, that's easy :-) */ | 373 /* if it is a bitmap, that's easy :-) */ |
372 if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) | 374 if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) |
373 clazz = FT_BITMAP_GLYPH_CLASS_GET; | 375 clazz = FT_BITMAP_GLYPH_CLASS_GET; |
374 | 376 |
375 /* if it is an outline */ | 377 /* if it is an outline */ |
376 else if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) | 378 else if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) |
377 clazz = FT_OUTLINE_GLYPH_CLASS_GET; | 379 clazz = FT_OUTLINE_GLYPH_CLASS_GET; |
378 | 380 |
379 else | 381 else |
380 { | 382 { |
381 /* try to find a renderer that supports the glyph image format */ | 383 /* try to find a renderer that supports the glyph image format */ |
382 FT_Renderer render = FT_Lookup_Renderer( library, slot->format, 0 ); | 384 FT_Renderer render = FT_Lookup_Renderer( library, slot->format, 0 ); |
383 | 385 |
384 | 386 |
385 if ( render ) | 387 if ( render ) |
386 clazz = &render->glyph_class; | 388 clazz = &render->glyph_class; |
387 } | 389 } |
388 | 390 |
389 if ( !clazz ) | 391 if ( !clazz ) |
390 { | 392 { |
391 error = FT_Err_Invalid_Glyph_Format; | 393 error = FT_THROW( Invalid_Glyph_Format ); |
392 goto Exit; | 394 goto Exit; |
393 } | 395 } |
394 | 396 |
395 /* create FT_Glyph object */ | 397 /* create FT_Glyph object */ |
396 error = ft_new_glyph( library, clazz, &glyph ); | 398 error = ft_new_glyph( library, clazz, &glyph ); |
397 if ( error ) | 399 if ( error ) |
398 goto Exit; | 400 goto Exit; |
399 | 401 |
400 /* copy advance while converting it to 16.16 format */ | 402 /* copy advance while converting it to 16.16 format */ |
401 glyph->advance.x = slot->advance.x << 10; | 403 glyph->advance.x = slot->advance.x << 10; |
(...skipping 18 matching lines...) Expand all Loading... |
420 FT_EXPORT_DEF( FT_Error ) | 422 FT_EXPORT_DEF( FT_Error ) |
421 FT_Glyph_Transform( FT_Glyph glyph, | 423 FT_Glyph_Transform( FT_Glyph glyph, |
422 FT_Matrix* matrix, | 424 FT_Matrix* matrix, |
423 FT_Vector* delta ) | 425 FT_Vector* delta ) |
424 { | 426 { |
425 const FT_Glyph_Class* clazz; | 427 const FT_Glyph_Class* clazz; |
426 FT_Error error = FT_Err_Ok; | 428 FT_Error error = FT_Err_Ok; |
427 | 429 |
428 | 430 |
429 if ( !glyph || !glyph->clazz ) | 431 if ( !glyph || !glyph->clazz ) |
430 error = FT_Err_Invalid_Argument; | 432 error = FT_THROW( Invalid_Argument ); |
431 else | 433 else |
432 { | 434 { |
433 clazz = glyph->clazz; | 435 clazz = glyph->clazz; |
434 if ( clazz->glyph_transform ) | 436 if ( clazz->glyph_transform ) |
435 { | 437 { |
436 /* transform glyph image */ | 438 /* transform glyph image */ |
437 clazz->glyph_transform( glyph, matrix, delta ); | 439 clazz->glyph_transform( glyph, matrix, delta ); |
438 | 440 |
439 /* transform advance vector */ | 441 /* transform advance vector */ |
440 if ( matrix ) | 442 if ( matrix ) |
441 FT_Vector_Transform( &glyph->advance, matrix ); | 443 FT_Vector_Transform( &glyph->advance, matrix ); |
442 } | 444 } |
443 else | 445 else |
444 error = FT_Err_Invalid_Glyph_Format; | 446 error = FT_THROW( Invalid_Glyph_Format ); |
445 } | 447 } |
446 return error; | 448 return error; |
447 } | 449 } |
448 | 450 |
449 | 451 |
450 /* documentation is in ftglyph.h */ | 452 /* documentation is in ftglyph.h */ |
451 | 453 |
452 FT_EXPORT_DEF( void ) | 454 FT_EXPORT_DEF( void ) |
453 FT_Glyph_Get_CBox( FT_Glyph glyph, | 455 FT_Glyph_Get_CBox( FT_Glyph glyph, |
454 FT_UInt bbox_mode, | 456 FT_UInt bbox_mode, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 | 505 |
504 FT_EXPORT_DEF( FT_Error ) | 506 FT_EXPORT_DEF( FT_Error ) |
505 FT_Glyph_To_Bitmap( FT_Glyph* the_glyph, | 507 FT_Glyph_To_Bitmap( FT_Glyph* the_glyph, |
506 FT_Render_Mode render_mode, | 508 FT_Render_Mode render_mode, |
507 FT_Vector* origin, | 509 FT_Vector* origin, |
508 FT_Bool destroy ) | 510 FT_Bool destroy ) |
509 { | 511 { |
510 FT_GlyphSlotRec dummy; | 512 FT_GlyphSlotRec dummy; |
511 FT_GlyphSlot_InternalRec dummy_internal; | 513 FT_GlyphSlot_InternalRec dummy_internal; |
512 FT_Error error = FT_Err_Ok; | 514 FT_Error error = FT_Err_Ok; |
513 FT_Glyph glyph; | 515 FT_Glyph b, glyph; |
514 FT_BitmapGlyph bitmap = NULL; | 516 FT_BitmapGlyph bitmap = NULL; |
515 const FT_Glyph_Class* clazz; | 517 const FT_Glyph_Class* clazz; |
516 | 518 |
517 /* FT_BITMAP_GLYPH_CLASS_GET derefers `library' in PIC mode */ | 519 /* FT_BITMAP_GLYPH_CLASS_GET derefers `library' in PIC mode */ |
518 FT_Library library; | 520 FT_Library library; |
519 | 521 |
520 | 522 |
521 /* check argument */ | 523 /* check argument */ |
522 if ( !the_glyph ) | 524 if ( !the_glyph ) |
523 goto Bad; | 525 goto Bad; |
(...skipping 16 matching lines...) Expand all Loading... |
540 /* we render the glyph into a glyph bitmap using a `dummy' glyph slot */ | 542 /* we render the glyph into a glyph bitmap using a `dummy' glyph slot */ |
541 /* then calling FT_Render_Glyph_Internal() */ | 543 /* then calling FT_Render_Glyph_Internal() */ |
542 | 544 |
543 FT_MEM_ZERO( &dummy, sizeof ( dummy ) ); | 545 FT_MEM_ZERO( &dummy, sizeof ( dummy ) ); |
544 FT_MEM_ZERO( &dummy_internal, sizeof ( dummy_internal ) ); | 546 FT_MEM_ZERO( &dummy_internal, sizeof ( dummy_internal ) ); |
545 dummy.internal = &dummy_internal; | 547 dummy.internal = &dummy_internal; |
546 dummy.library = library; | 548 dummy.library = library; |
547 dummy.format = clazz->glyph_format; | 549 dummy.format = clazz->glyph_format; |
548 | 550 |
549 /* create result bitmap glyph */ | 551 /* create result bitmap glyph */ |
550 error = ft_new_glyph( library, FT_BITMAP_GLYPH_CLASS_GET, | 552 error = ft_new_glyph( library, FT_BITMAP_GLYPH_CLASS_GET, &b ); |
551 (FT_Glyph*)(void*)&bitmap ); | |
552 if ( error ) | 553 if ( error ) |
553 goto Exit; | 554 goto Exit; |
| 555 bitmap = (FT_BitmapGlyph)b; |
554 | 556 |
555 #if 1 | 557 #if 1 |
556 /* if `origin' is set, translate the glyph image */ | 558 /* if `origin' is set, translate the glyph image */ |
557 if ( origin ) | 559 if ( origin ) |
558 FT_Glyph_Transform( glyph, 0, origin ); | 560 FT_Glyph_Transform( glyph, 0, origin ); |
559 #else | 561 #else |
560 FT_UNUSED( origin ); | 562 FT_UNUSED( origin ); |
561 #endif | 563 #endif |
562 | 564 |
563 /* prepare dummy slot for rendering */ | 565 /* prepare dummy slot for rendering */ |
(...skipping 29 matching lines...) Expand all Loading... |
593 | 595 |
594 *the_glyph = FT_GLYPH( bitmap ); | 596 *the_glyph = FT_GLYPH( bitmap ); |
595 | 597 |
596 Exit: | 598 Exit: |
597 if ( error && bitmap ) | 599 if ( error && bitmap ) |
598 FT_Done_Glyph( FT_GLYPH( bitmap ) ); | 600 FT_Done_Glyph( FT_GLYPH( bitmap ) ); |
599 | 601 |
600 return error; | 602 return error; |
601 | 603 |
602 Bad: | 604 Bad: |
603 error = FT_Err_Invalid_Argument; | 605 error = FT_THROW( Invalid_Argument ); |
604 goto Exit; | 606 goto Exit; |
605 } | 607 } |
606 | 608 |
607 | 609 |
608 /* documentation is in ftglyph.h */ | 610 /* documentation is in ftglyph.h */ |
609 | 611 |
610 FT_EXPORT_DEF( void ) | 612 FT_EXPORT_DEF( void ) |
611 FT_Done_Glyph( FT_Glyph glyph ) | 613 FT_Done_Glyph( FT_Glyph glyph ) |
612 { | 614 { |
613 if ( glyph ) | 615 if ( glyph ) |
614 { | 616 { |
615 FT_Memory memory = glyph->library->memory; | 617 FT_Memory memory = glyph->library->memory; |
616 const FT_Glyph_Class* clazz = glyph->clazz; | 618 const FT_Glyph_Class* clazz = glyph->clazz; |
617 | 619 |
618 | 620 |
619 if ( clazz->glyph_done ) | 621 if ( clazz->glyph_done ) |
620 clazz->glyph_done( glyph ); | 622 clazz->glyph_done( glyph ); |
621 | 623 |
622 FT_FREE( glyph ); | 624 FT_FREE( glyph ); |
623 } | 625 } |
624 } | 626 } |
625 | 627 |
626 | 628 |
627 /* END */ | 629 /* END */ |
OLD | NEW |