Skip to content

Commit

Permalink
Switched to freetype 2.6, started implementing subpixel hinting support
Browse files Browse the repository at this point in the history
  • Loading branch information
ivansafrin committed Jun 23, 2015
1 parent 216caf5 commit c1e78e7
Show file tree
Hide file tree
Showing 7 changed files with 922 additions and 88 deletions.
8 changes: 4 additions & 4 deletions CMake/ExternalFreetype.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ SET(freetype_CMAKE_ARGS
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
)

EXTERNALPROJECT_ADD(freetype
PREFIX ${freetype_PREFIX}

DOWNLOAD_DIR ${POLYCODE_DEPS_DOWNLOAD_DIR}
URL http://download.savannah.gnu.org/releases/freetype/freetype-2.4.5.tar.gz
URL_MD5 0e67460b312df905dc1cc1586690e7b2
URL http://download.savannah.gnu.org/releases/freetype/freetype-2.6.tar.gz
URL_MD5 1d733ea6c1b7b3df38169fbdbec47d2b

PATCH_COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PolycodeDependencies_SOURCE_DIR}/../CMake/freetype.cmake <SOURCE_DIR>/CMakeLists.txt
PATCH_COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PolycodeDependencies_SOURCE_DIR}/../CMake/freetype/ftoption.h <SOURCE_DIR>/include/config/ftoption.h

INSTALL_DIR ${POLYCODE_DEPS_CORE_PREFIX}
CMAKE_ARGS ${freetype_CMAKE_ARGS}
Expand Down
81 changes: 0 additions & 81 deletions CMake/freetype.cmake

This file was deleted.

886 changes: 886 additions & 0 deletions CMake/freetype/ftoption.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Core/Contents/Include/PolyLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ namespace Polycode {
static const int ANTIALIAS_FULL = 0;
static const int ANTIALIAS_NONE = 1;
static const int ANTIALIAS_STRONG = 2;

static const int ANTIALIAS_LCD = 3;
/**
* Returns the pixel distance from top of image to the baseline of the rendered text.
*/
Expand Down
29 changes: 27 additions & 2 deletions Core/Contents/Source/PolyLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ void Label::precacheGlyphs(String text, GlyphData *glyphData) {
glyphData->positions[glyphData->num_glyphs].y = pen_y;

switch(antiAliasMode) {
case ANTIALIAS_LCD:
error = FT_Load_Glyph( face, glyph_index, FT_LOAD_TARGET_LCD);
break;
case ANTIALIAS_FULL:
case ANTIALIAS_STRONG:
error = FT_Load_Glyph( face, glyph_index, FT_LOAD_TARGET_LIGHT);
Expand Down Expand Up @@ -315,6 +318,26 @@ void Label::drawGlyphBitmap(FT_Bitmap *bitmap, unsigned int x, unsigned int y, C
}

switch(antiAliasMode) {
case ANTIALIAS_LCD:
{
unsigned char *src = bitmap->buffer;
for(int j=0; j < bitmap->rows;j++) {
unsigned char b;
unsigned char *bptr = src;
for(int k=0; k < bitmap->width ; k+=3){
imageData[xoff+lineoffset] = *(bptr);
imageData[xoff+lineoffset+1] = *(bptr+1);
imageData[xoff+lineoffset+2] = *(bptr+2);
imageData[xoff+lineoffset+3] = 255; //((*(bptr)) + (*(bptr+1)) + (*(bptr+2))) / 3;
bptr += 3;
xoff += 4;
}
lineoffset -= ((width*4)+(bitmap->width * 4 / 3));
src += bitmap->pitch;
}

}
break;
case ANTIALIAS_FULL:
case ANTIALIAS_STRONG:
for(int j = 0; j < ((bitmap->width * bitmap->rows)); j++) {
Expand Down Expand Up @@ -386,7 +409,9 @@ void Label::renderGlyphs(GlyphData *glyphData) {
pen.x = (start_x + glyphData->positions[n].x) * 64;
pen.y = (start_y + glyphData->positions[n].y) * 64;

if(antiAliasMode == ANTIALIAS_FULL || antiAliasMode == ANTIALIAS_STRONG) {
if(antiAliasMode == ANTIALIAS_LCD) {
error = FT_Glyph_To_Bitmap( &image, FT_RENDER_MODE_LCD, &pen, 0 );
} else if(antiAliasMode == ANTIALIAS_FULL || antiAliasMode == ANTIALIAS_STRONG) {
error = FT_Glyph_To_Bitmap( &image, FT_RENDER_MODE_LIGHT, &pen, 0 );
} else {
error = FT_Glyph_To_Bitmap( &image, FT_RENDER_MODE_MONO, &pen, 0 );
Expand Down Expand Up @@ -417,7 +442,7 @@ void Label::setText(const String& text) {
return;
if(!font->isValid())
return;

this->text = text;

precacheGlyphs(text, &labelData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3982,6 +3982,7 @@
"\"$(SRCROOT)/../../Modules/Dependencies/include/bullet\"",
"\"$(SRCROOT)/Contents\"",
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/OpenAL.framework/Headers,
"\"$(SRCROOT)/../../Core/Dependencies/include/freetype2\"",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -4018,6 +4019,7 @@
"\"$(SRCROOT)/../../Modules/Dependencies/include/bullet\"",
"\"$(SRCROOT)/Contents\"",
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/OpenAL.framework/Headers,
"\"$(SRCROOT)/../../Core/Dependencies/include/freetype2\"",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
Expand Down
2 changes: 2 additions & 0 deletions IDE/Build/Mac OS X/Polycode.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@
"\"$(SRCROOT)/../../../Release/Darwin/Framework/Core/Dependencies/include\"",
"\"$(SRCROOT)/../../../Release/Darwin/Framework/Modules/include\"",
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/OpenAL.framework/Headers,
"\"$(SRCROOT)/../../../Release/Darwin/Framework/Core/Dependencies/include/freetype2\"",
);
INFOPLIST_FILE = "Polycode-Info.plist";
INSTALL_PATH = "$(HOME)/Applications";
Expand Down Expand Up @@ -608,6 +609,7 @@
"\"$(SRCROOT)/../../../Release/Darwin/Framework/Core/Dependencies/include\"",
"\"$(SRCROOT)/../../../Release/Darwin/Framework/Modules/include\"",
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/OpenAL.framework/Headers,
"\"$(SRCROOT)/../../../Release/Darwin/Framework/Core/Dependencies/include/freetype2\"",
);
INFOPLIST_FILE = "Polycode-Info.plist";
INSTALL_PATH = "$(HOME)/Applications";
Expand Down

0 comments on commit c1e78e7

Please sign in to comment.