Hide the symbols exported by the FreeType API
See https://github.com/flutter/flutter/issues/106118
Change-Id: Iceebe722e6c61c0e7b7af01e86c317ec2bda0f9f
Bug: 106118
Reviewed-on: https://flutter-review.googlesource.com/c/third_party/freetype2/+/31480
Reviewed-by: Chinmay Garde <chinmaygarde@google.com>
Commit-Queue: Jason Simmons <jsimmons@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 0af3417..8621775 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -28,6 +28,7 @@
config("freetype_config") {
include_dirs = [
+ "include/freetype-flutter-config",
"include",
]
@@ -40,14 +41,6 @@
]
}
}
-
-#TODO(mikejurka): Remove once we've migrated to the freetype2 target everywhere
-group("freetype") {
- public_deps = [
- ":freetype2",
- ]
-}
-
target(default_library_type, "freetype2") {
sources = [
"src/autofit/autofit.c",
@@ -84,18 +77,8 @@
# Long directory name to avoid accidentally using wrong headers.
"FT_CONFIG_MODULES_H=<freetype-flutter-config/ftmodule.h>",
"FT_CONFIG_OPTIONS_H=<freetype-flutter-config/ftoption.h>",
- # Reduce visibility of symbols.
- # "FT_PUBLIC_FUNCTION_ATTRIBUTE=",
]
- if (default_library_type == "shared_library") {
- defines += [
- "FT_EXPORT(x)=extern __attribute__(( visibility( \"default\" ) )) x",
- "FT_EXPORT_DEF(x)=extern __attribute__(( visibility( \"default\" ) )) x",
- "FT_EXPORT_VAR(x)=extern __attribute__(( visibility( \"default\" ) )) x",
- ]
- }
-
public_configs = [ ":freetype_config" ]
deps = [
diff --git a/include/freetype-flutter-config/freetype/config/public-macros.h b/include/freetype-flutter-config/freetype/config/public-macros.h
new file mode 100644
index 0000000..aba90ee
--- /dev/null
+++ b/include/freetype-flutter-config/freetype/config/public-macros.h
@@ -0,0 +1,105 @@
+/****************************************************************************
+ *
+ * config/public-macros.h
+ *
+ * Define a set of compiler macros used in public FreeType headers.
+ *
+ * Copyright (C) 2020-2022 by
+ * David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ * This file is part of the FreeType project, and may only be used,
+ * modified, and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT. By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ */
+
+ /*
+ * The definitions in this file are used by the public FreeType headers
+ * and thus should be considered part of the public API.
+ *
+ * Other compiler-specific macro definitions that are not exposed by the
+ * FreeType API should go into
+ * `include/freetype/internal/compiler-macros.h` instead.
+ */
+#ifndef FREETYPE_CONFIG_PUBLIC_MACROS_H_
+#define FREETYPE_CONFIG_PUBLIC_MACROS_H_
+
+ /*
+ * `FT_BEGIN_HEADER` and `FT_END_HEADER` might have already been defined
+ * by `freetype/config/ftheader.h`, but we don't want to include this
+ * header here, so redefine the macros here only when needed. Their
+ * definition is very stable, so keeping them in sync with the ones in the
+ * header should not be a maintenance issue.
+ */
+#ifndef FT_BEGIN_HEADER
+#ifdef __cplusplus
+#define FT_BEGIN_HEADER extern "C" {
+#else
+#define FT_BEGIN_HEADER /* empty */
+#endif
+#endif /* FT_BEGIN_HEADER */
+
+#ifndef FT_END_HEADER
+#ifdef __cplusplus
+#define FT_END_HEADER }
+#else
+#define FT_END_HEADER /* empty */
+#endif
+#endif /* FT_END_HEADER */
+
+// Do not export FreeType APIs when building Flutter.
+#define FT_PUBLIC_FUNCTION_ATTRIBUTE
+
+FT_BEGIN_HEADER
+
+ /*
+ * Define a public FreeType API function. This ensures it is properly
+ * exported or imported at build time. The macro parameter is the
+ * function's return type as in:
+ *
+ * FT_EXPORT( FT_Bool )
+ * FT_Object_Method( FT_Object obj,
+ * ... );
+ *
+ * NOTE: This requires that all `FT_EXPORT` uses are inside
+ * `FT_BEGIN_HEADER ... FT_END_HEADER` blocks. This guarantees that the
+ * functions are exported with C linkage, even when the header is included
+ * by a C++ source file.
+ */
+#define FT_EXPORT( x ) FT_PUBLIC_FUNCTION_ATTRIBUTE extern x
+
+
+ /*
+ * `FT_UNUSED` indicates that a given parameter is not used -- this is
+ * only used to get rid of unpleasant compiler warnings.
+ *
+ * Technically, this was not meant to be part of the public API, but some
+ * third-party code depends on it.
+ */
+#ifndef FT_UNUSED
+#define FT_UNUSED( arg ) ( (arg) = (arg) )
+#endif
+
+
+ /*
+ * Support for casts in both C and C++.
+ */
+#ifdef __cplusplus
+#define FT_STATIC_CAST( type, var ) static_cast<type>(var)
+#define FT_REINTERPRET_CAST( type, var ) reinterpret_cast<type>(var)
+
+#define FT_STATIC_BYTE_CAST( type, var ) \
+ static_cast<type>( static_cast<unsigned char>( var ) )
+#else
+#define FT_STATIC_CAST( type, var ) (type)(var)
+#define FT_REINTERPRET_CAST( type, var ) (type)(var)
+
+#define FT_STATIC_BYTE_CAST( type, var ) (type)(unsigned char)(var)
+#endif
+
+
+FT_END_HEADER
+
+#endif /* FREETYPE_CONFIG_PUBLIC_MACROS_H_ */