1 /****************************************************************************
3 * config/public-macros.h
5 * Define a set of compiler macros used in public FreeType headers.
7 * Copyright (C) 2020-2023 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
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.
19 * The definitions in this file are used by the public FreeType headers
20 * and thus should be considered part of the public API.
22 * Other compiler-specific macro definitions that are not exposed by the
23 * FreeType API should go into
24 * `include/freetype/internal/compiler-macros.h` instead.
26 #ifndef FREETYPE_CONFIG_PUBLIC_MACROS_H_
27 #define FREETYPE_CONFIG_PUBLIC_MACROS_H_
30 * `FT_BEGIN_HEADER` and `FT_END_HEADER` might have already been defined
31 * by `freetype/config/ftheader.h`, but we don't want to include this
32 * header here, so redefine the macros here only when needed. Their
33 * definition is very stable, so keeping them in sync with the ones in the
34 * header should not be a maintenance issue.
36 #ifndef FT_BEGIN_HEADER
38 #define FT_BEGIN_HEADER extern "C" {
40 #define FT_BEGIN_HEADER /* empty */
42 #endif /* FT_BEGIN_HEADER */
46 #define FT_END_HEADER }
48 #define FT_END_HEADER /* empty */
50 #endif /* FT_END_HEADER */
56 * Mark a function declaration as public. This ensures it will be
57 * properly exported to client code. Place this before a function
60 * NOTE: This macro should be considered an internal implementation
61 * detail, and not part of the FreeType API. It is only defined here
62 * because it is needed by `FT_EXPORT`.
68 #if defined( FT2_BUILD_LIBRARY ) && defined( DLL_EXPORT )
69 #define FT_PUBLIC_FUNCTION_ATTRIBUTE __declspec( dllexport )
70 #elif defined( DLL_IMPORT )
71 #define FT_PUBLIC_FUNCTION_ATTRIBUTE __declspec( dllimport )
75 #elif ( defined( __GNUC__ ) && __GNUC__ >= 4 ) || defined( __clang__ )
76 #define FT_PUBLIC_FUNCTION_ATTRIBUTE \
77 __attribute__(( visibility( "default" ) ))
80 #elif defined( __SUNPRO_C ) && __SUNPRO_C >= 0x550
81 #define FT_PUBLIC_FUNCTION_ATTRIBUTE __global
85 #ifndef FT_PUBLIC_FUNCTION_ATTRIBUTE
86 #define FT_PUBLIC_FUNCTION_ATTRIBUTE /* empty */
91 * Define a public FreeType API function. This ensures it is properly
92 * exported or imported at build time. The macro parameter is the
93 * function's return type as in:
95 * FT_EXPORT( FT_Bool )
96 * FT_Object_Method( FT_Object obj,
99 * NOTE: This requires that all `FT_EXPORT` uses are inside
100 * `FT_BEGIN_HEADER ... FT_END_HEADER` blocks. This guarantees that the
101 * functions are exported with C linkage, even when the header is included
102 * by a C++ source file.
104 #define FT_EXPORT( x ) FT_PUBLIC_FUNCTION_ATTRIBUTE extern x
108 * `FT_UNUSED` indicates that a given parameter is not used -- this is
109 * only used to get rid of unpleasant compiler warnings.
111 * Technically, this was not meant to be part of the public API, but some
112 * third-party code depends on it.
115 #define FT_UNUSED( arg ) ( (arg) = (arg) )
120 * Support for casts in both C and C++.
123 #define FT_STATIC_CAST( type, var ) static_cast<type>(var)
124 #define FT_REINTERPRET_CAST( type, var ) reinterpret_cast<type>(var)
126 #define FT_STATIC_BYTE_CAST( type, var ) \
127 static_cast<type>( static_cast<unsigned char>( var ) )
129 #define FT_STATIC_CAST( type, var ) (type)(var)
130 #define FT_REINTERPRET_CAST( type, var ) (type)(var)
132 #define FT_STATIC_BYTE_CAST( type, var ) (type)(unsigned char)(var)
138 #endif /* FREETYPE_CONFIG_PUBLIC_MACROS_H_ */