Werner Lemberg pushed to branch wl/cplusplus-casts at FreeType / FreeType
Commits:
-
37987329
by Werner Lemberg at 2021-11-14T10:12:03+01:00
6 changed files:
- include/freetype/config/public-macros.h
- include/freetype/freetype.h
- include/freetype/ftimage.h
- include/freetype/ftmodapi.h
- include/freetype/fttypes.h
- src/smooth/ftgrays.c
Changes:
... | ... | @@ -103,6 +103,7 @@ FT_BEGIN_HEADER |
103 | 103 |
*/
|
104 | 104 |
#define FT_EXPORT( x ) FT_PUBLIC_FUNCTION_ATTRIBUTE extern x
|
105 | 105 |
|
106 |
+ |
|
106 | 107 |
/*
|
107 | 108 |
* `FT_UNUSED` indicates that a given parameter is not used -- this is
|
108 | 109 |
* only used to get rid of unpleasant compiler warnings.
|
... | ... | @@ -115,6 +116,18 @@ FT_BEGIN_HEADER |
115 | 116 |
#endif
|
116 | 117 |
|
117 | 118 |
|
119 |
+ /*
|
|
120 |
+ * Support for casts in both C and C++.
|
|
121 |
+ */
|
|
122 |
+#ifdef __cplusplus
|
|
123 |
+#define FT_STATIC_CAST( type ) static_cast<type>
|
|
124 |
+#define FT_REINTERPRET_CAST( type ) reinterpret_cast<type>
|
|
125 |
+#else
|
|
126 |
+#define FT_STATIC_CAST( type ) (type)
|
|
127 |
+#define FT_REINTERPRET_CAST( type ) (type)
|
|
128 |
+#endif
|
|
129 |
+ |
|
130 |
+ |
|
118 | 131 |
FT_END_HEADER
|
119 | 132 |
|
120 | 133 |
#endif /* FREETYPE_CONFIG_PUBLIC_MACROS_H_ */
|
... | ... | @@ -616,11 +616,12 @@ FT_BEGIN_HEADER |
616 | 616 |
*/
|
617 | 617 |
|
618 | 618 |
#ifndef FT_ENC_TAG
|
619 |
-#define FT_ENC_TAG( value, a, b, c, d ) \
|
|
620 |
- value = ( ( (FT_UInt32)(a) << 24 ) | \
|
|
621 |
- ( (FT_UInt32)(b) << 16 ) | \
|
|
622 |
- ( (FT_UInt32)(c) << 8 ) | \
|
|
623 |
- (FT_UInt32)(d) )
|
|
619 |
+ |
|
620 |
+#define FT_ENC_TAG( value, a, b, c, d ) \
|
|
621 |
+ value = ( ( FT_STATIC_CAST( FT_UInt32 )(a) << 24 ) | \
|
|
622 |
+ ( FT_STATIC_CAST( FT_UInt32 )(b) << 16 ) | \
|
|
623 |
+ ( FT_STATIC_CAST( FT_UInt32 )(c) << 8 ) | \
|
|
624 |
+ FT_STATIC_CAST( FT_UInt32 )(d) )
|
|
624 | 625 |
|
625 | 626 |
#endif /* FT_ENC_TAG */
|
626 | 627 |
|
... | ... | @@ -3181,7 +3182,7 @@ FT_BEGIN_HEADER |
3181 | 3182 |
* necessary to empty the cache after a mode switch to avoid false hits.
|
3182 | 3183 |
*
|
3183 | 3184 |
*/
|
3184 |
-#define FT_LOAD_TARGET_( x ) ( (FT_Int32)( (x) & 15 ) << 16 )
|
|
3185 |
+#define FT_LOAD_TARGET_( x ) ( FT_STATIC_CAST( FT_Int32 )( (x) & 15 ) << 16 )
|
|
3185 | 3186 |
|
3186 | 3187 |
#define FT_LOAD_TARGET_NORMAL FT_LOAD_TARGET_( FT_RENDER_MODE_NORMAL )
|
3187 | 3188 |
#define FT_LOAD_TARGET_LIGHT FT_LOAD_TARGET_( FT_RENDER_MODE_LIGHT )
|
... | ... | @@ -3200,7 +3201,8 @@ FT_BEGIN_HEADER |
3200 | 3201 |
* @FT_LOAD_TARGET_XXX value.
|
3201 | 3202 |
*
|
3202 | 3203 |
*/
|
3203 |
-#define FT_LOAD_TARGET_MODE( x ) ( (FT_Render_Mode)( ( (x) >> 16 ) & 15 ) )
|
|
3204 |
+#define FT_LOAD_TARGET_MODE( x ) \
|
|
3205 |
+ FT_STATIC_CAST( FT_Render_Mode )( ( (x) >> 16 ) & 15 )
|
|
3204 | 3206 |
|
3205 | 3207 |
|
3206 | 3208 |
/**************************************************************************
|
... | ... | @@ -28,11 +28,6 @@ |
28 | 28 |
#define FTIMAGE_H_
|
29 | 29 |
|
30 | 30 |
|
31 |
- /* STANDALONE_ is from ftgrays.c */
|
|
32 |
-#ifndef STANDALONE_
|
|
33 |
-#endif
|
|
34 |
- |
|
35 |
- |
|
36 | 31 |
FT_BEGIN_HEADER
|
37 | 32 |
|
38 | 33 |
|
... | ... | @@ -700,11 +695,13 @@ FT_BEGIN_HEADER |
700 | 695 |
* to get a simple enumeration without assigning special numbers.
|
701 | 696 |
*/
|
702 | 697 |
#ifndef FT_IMAGE_TAG
|
703 |
-#define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) \
|
|
704 |
- value = ( ( (unsigned long)_x1 << 24 ) | \
|
|
705 |
- ( (unsigned long)_x2 << 16 ) | \
|
|
706 |
- ( (unsigned long)_x3 << 8 ) | \
|
|
707 |
- (unsigned long)_x4 )
|
|
698 |
+ |
|
699 |
+#define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) \
|
|
700 |
+ value = ( ( FT_STATIC_CAST( unsigned long )( _x1 ) << 24 ) | \
|
|
701 |
+ ( FT_STATIC_CAST( unsigned long )( _x2 ) << 16 ) | \
|
|
702 |
+ ( FT_STATIC_CAST( unsigned long )( _x3 ) << 8 ) | \
|
|
703 |
+ FT_STATIC_CAST( unsigned long )( _x4 ) )
|
|
704 |
+ |
|
708 | 705 |
#endif /* FT_IMAGE_TAG */
|
709 | 706 |
|
710 | 707 |
|
... | ... | @@ -347,8 +347,9 @@ FT_BEGIN_HEADER |
347 | 347 |
* 2.11
|
348 | 348 |
*
|
349 | 349 |
*/
|
350 |
-#define FT_FACE_DRIVER_NAME( face ) \
|
|
351 |
- ( ( *(FT_Module_Class**)( ( face )->driver ) )->module_name )
|
|
350 |
+#define FT_FACE_DRIVER_NAME( face ) \
|
|
351 |
+ ( ( *FT_REINTERPRET_CAST( FT_Module_Class** ) \
|
|
352 |
+ ( ( face )->driver ) )->module_name )
|
|
352 | 353 |
|
353 | 354 |
|
354 | 355 |
/**************************************************************************
|
... | ... | @@ -485,12 +485,12 @@ FT_BEGIN_HEADER |
485 | 485 |
* The produced values **must** be 32-bit integers. Don't redefine this
|
486 | 486 |
* macro.
|
487 | 487 |
*/
|
488 |
-#define FT_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
|
|
489 |
- (FT_Tag) \
|
|
490 |
- ( ( (FT_ULong)_x1 << 24 ) | \
|
|
491 |
- ( (FT_ULong)_x2 << 16 ) | \
|
|
492 |
- ( (FT_ULong)_x3 << 8 ) | \
|
|
493 |
- (FT_ULong)_x4 )
|
|
488 |
+#define FT_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
|
|
489 |
+ FT_STATIC_CAST( FT_Tag ) \
|
|
490 |
+ ( ( FT_STATIC_CAST( FT_ULong )( _x1 ) << 24 ) | \
|
|
491 |
+ ( FT_STATIC_CAST( FT_ULong )( _x2 ) << 16 ) | \
|
|
492 |
+ ( FT_STATIC_CAST( FT_ULong )( _x3 ) << 8 ) | \
|
|
493 |
+ FT_STATIC_CAST( FT_ULong )( _x4 ) )
|
|
494 | 494 |
|
495 | 495 |
|
496 | 496 |
/*************************************************************************/
|
... | ... | @@ -588,7 +588,7 @@ FT_BEGIN_HEADER |
588 | 588 |
|
589 | 589 |
|
590 | 590 |
#define FT_IS_EMPTY( list ) ( (list).head == 0 )
|
591 |
-#define FT_BOOL( x ) ( (FT_Bool)( (x) != 0 ) )
|
|
591 |
+#define FT_BOOL( x ) FT_STATIC_CAST( FT_Bool )( (x) != 0 )
|
|
592 | 592 |
|
593 | 593 |
/* concatenate C tokens */
|
594 | 594 |
#define FT_ERR_XCAT( x, y ) x ## y
|
... | ... | @@ -152,6 +152,8 @@ |
152 | 152 |
#define ADD_INT( a, b ) \
|
153 | 153 |
(int)( (unsigned int)(a) + (unsigned int)(b) )
|
154 | 154 |
|
155 |
+#define FT_STATIC_CAST( type ) (type)
|
|
156 |
+ |
|
155 | 157 |
|
156 | 158 |
#define ft_memset memset
|
157 | 159 |
|
... | ... | @@ -273,6 +275,8 @@ typedef ptrdiff_t FT_PtrDist; |
273 | 275 |
#else /* !STANDALONE_ */
|
274 | 276 |
|
275 | 277 |
|
278 |
+#include <ft2build.h>
|
|
279 |
+#include FT_CONFIG_CONFIG_H
|
|
276 | 280 |
#include "ftgrays.h"
|
277 | 281 |
#include <freetype/internal/ftobjs.h>
|
278 | 282 |
#include <freetype/internal/ftdebug.h>
|