
Building 32-bit FreeType libraries for OpenJDK 7 on Windows
The majority of fonts used in modern software are encoded in vector format for proper scaling support. There are multiple standards for vector fonts, for example Metafont from Professor Donald E. Knuth, Type1 from Adobe, TrueType from Apple and Microsoft, and OpenType from Adobe and Microsoft.
Rasterization of vector fonts is a remarkably complex task and most desktop software (such as web browsers or text processors) use third-party libraries to work with fonts.
Sun Microsystems licensed a third-party closed source font library for use in Sun Java implementation. The sources for this library could not be released to the public along with the initial release of OpenJDK. The Font Scaler Replacement Project was launched in the early days of OpenJDK to adopt the open source font library instead.
FreeType is a free and open source (under permissive license) font rasterization library. It is widely used in open source desktop software. FreeType was chosen by the OpenJDK team as a replacement for the closed source font library and is now used by OpenJDK on all supported platforms. Prebuilt static and dynamic FreeType libraries are required for OpenJDK builds on Windows.
FreeType may be built for OpenJDK 7 using the same Microsoft Windows SDK for Windows 7 and .NET Framework 4 (Version 7.1) that we will use for both i586 and amd64 OpenJDK builds. We will use the freely available Visual Studio 2010 Express Edition to configure the build settings for the FreeType project.
Getting ready
For this recipe, we should have Windows 7 SP1 i586 running.
How to do it...
The following procedure will help us to build FreeType:
- Download Microsoft .NET Framework 4 from the Microsoft website and install it.
- Download Microsoft Windows SDK for Windows 7 and .NET Framework 4 (Version 7.1) from the Microsoft website and install it to the default location with image filename
GRMSDK_EN_DVD.iso
. - Download Visual Studio 2010 Express Edition from the Microsoft website and install it to the default location. Only the Visual C++ component is required.
- Download the FreeType 2.5.2 sources tarball from http://freetype.org/ and decompress it.
- Open the file
include\config\ftoption.h
and uncomment line 95:#define FT_CONFIG_OPTION_SUBPIXEL_RENDERING
- Change lines 269 and 271 from
/* #define FT_EXPORT(x) extern x */
and/* #define FT_EXPORT_DEF(x) x */
to#define FT_EXPORT(x) __declspec(dllexport) x
and#define FT_EXPORT_DEF(x) __declspec(dllexport) x
. - Open the solution
builds\windows\vc2010\freetype.sln
in Visual Studio. - In the main menu, go to Project | Properties | Configuration Properties and choose Windows7.1 SDK in the Platform Toolset field.
- On the main screen choose Release Multithreaded as the Solution Configuration.
- Run build, and the
freetype252MT.lib
library will be placed into thefreetype\objs\win32\vc2010
directory; rename it tofreetype.lib
, and save it for later use. - In the main menu, go to Project | Properties | Configuration Properties, change Configuration Type to Dynamic Library (.dll), and build the solution. The
freetype252MT.dll
andfreetype252MT.exp
files will be placed into theobjs\release_mt
directory. Rename these filesfreetype.dll
andfreetype.exp
and use them with the previously generatedfreetype.lib
during the OpenJDK build.
How it works...
FreeType for i586 may be built using Visual Studio's own toolset, but we used the Windows SDK7.1 toolset to ensure compatibility with the OpenJDK build that uses the same toolset.
The FT_CONFIG_OPTION_SUBPIXEL_RENDERING
macro enables subpixel rendering functionality in FreeType implementation.
The FT_EXPORT
and FT_EXPORT_DEF
macros should be adjusted with the calling conventions for the current platform. We changed them to use Windows-specific calling conventions.
See also
- The Building 64-bit FreeType libraries for OpenJDK 7 on Windows recipe
- The FreeType official website at http://freetype.org/
- Professor Donald E. Knuth's interview covering Metafont and TrueType at http://www.advogato.org/article/28.html
- The OpenJDK: Font Scaler Replacement Project page at http://openjdk.java.net/projects/font-scaler/