Skip to content

Commit

Permalink
[util] Prefer Win32 version of VerifyTranscodedFont
Browse files Browse the repository at this point in the history
If FreeType and another platform backend is enabled, we want to prefer
the platform one.

Fixes #254
  • Loading branch information
khaledhosny committed Mar 7, 2023
1 parent 5366dc8 commit 28e4930
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions util/ots-idempotent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

#if defined(HAVE_CORETEXT)
#include <ApplicationServices/ApplicationServices.h>
#elif defined(HAVE_WIN32)
#define NOMINMAX
#include <Windows.h>
#elif defined(HAVE_FREETYPE)
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_OUTLINE_H
#elif defined(HAVE_WIN32)
#define NOMINMAX
#include <Windows.h>
#endif

#include <fstream>
Expand Down Expand Up @@ -70,6 +70,18 @@ bool VerifyTranscodedFont(uint8_t *result, const size_t len) {
return true;
}

#elif defined(HAVE_WIN32)
// Windows
bool VerifyTranscodedFont(uint8_t *result, const size_t len) {
DWORD num_fonts = 0;
HANDLE handle = AddFontMemResourceEx(result, len, 0, &num_fonts);
if (!handle) {
return false;
}
RemoveFontMemResourceEx(handle);
return true;
}

#elif defined(HAVE_FREETYPE)
bool VerifyTranscodedFont(uint8_t *result, const size_t len) {
FT_Library library;
Expand All @@ -87,18 +99,6 @@ bool VerifyTranscodedFont(uint8_t *result, const size_t len) {
return true;
}

#elif defined(HAVE_WIN32)
// Windows
bool VerifyTranscodedFont(uint8_t *result, const size_t len) {
DWORD num_fonts = 0;
HANDLE handle = AddFontMemResourceEx(result, len, 0, &num_fonts);
if (!handle) {
return false;
}
RemoveFontMemResourceEx(handle);
return true;
}

#else
bool VerifyTranscodedFont(uint8_t *result, const size_t len) {
std::fprintf(stderr, "Can't verify the transcoded font on this platform.\n");
Expand Down

0 comments on commit 28e4930

Please sign in to comment.