Skip to content

Commit c1e78e7

Browse files
committed
Switched to freetype 2.6, started implementing subpixel hinting support
1 parent 216caf5 commit c1e78e7

File tree

7 files changed

+922
-88
lines changed

7 files changed

+922
-88
lines changed

CMake/ExternalFreetype.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ SET(freetype_CMAKE_ARGS
77
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
88
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
99
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
10-
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
10+
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
1111
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
1212
)
1313

1414
EXTERNALPROJECT_ADD(freetype
1515
PREFIX ${freetype_PREFIX}
1616

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

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

2323
INSTALL_DIR ${POLYCODE_DEPS_CORE_PREFIX}
2424
CMAKE_ARGS ${freetype_CMAKE_ARGS}

CMake/freetype.cmake

Lines changed: 0 additions & 81 deletions
This file was deleted.

CMake/freetype/ftoption.h

Lines changed: 886 additions & 0 deletions
Large diffs are not rendered by default.

Core/Contents/Include/PolyLabel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ namespace Polycode {
178178
static const int ANTIALIAS_FULL = 0;
179179
static const int ANTIALIAS_NONE = 1;
180180
static const int ANTIALIAS_STRONG = 2;
181-
181+
static const int ANTIALIAS_LCD = 3;
182182
/**
183183
* Returns the pixel distance from top of image to the baseline of the rendered text.
184184
*/

Core/Contents/Source/PolyLabel.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ void Label::precacheGlyphs(String text, GlyphData *glyphData) {
271271
glyphData->positions[glyphData->num_glyphs].y = pen_y;
272272

273273
switch(antiAliasMode) {
274+
case ANTIALIAS_LCD:
275+
error = FT_Load_Glyph( face, glyph_index, FT_LOAD_TARGET_LCD);
276+
break;
274277
case ANTIALIAS_FULL:
275278
case ANTIALIAS_STRONG:
276279
error = FT_Load_Glyph( face, glyph_index, FT_LOAD_TARGET_LIGHT);
@@ -315,6 +318,26 @@ void Label::drawGlyphBitmap(FT_Bitmap *bitmap, unsigned int x, unsigned int y, C
315318
}
316319

317320
switch(antiAliasMode) {
321+
case ANTIALIAS_LCD:
322+
{
323+
unsigned char *src = bitmap->buffer;
324+
for(int j=0; j < bitmap->rows;j++) {
325+
unsigned char b;
326+
unsigned char *bptr = src;
327+
for(int k=0; k < bitmap->width ; k+=3){
328+
imageData[xoff+lineoffset] = *(bptr);
329+
imageData[xoff+lineoffset+1] = *(bptr+1);
330+
imageData[xoff+lineoffset+2] = *(bptr+2);
331+
imageData[xoff+lineoffset+3] = 255; //((*(bptr)) + (*(bptr+1)) + (*(bptr+2))) / 3;
332+
bptr += 3;
333+
xoff += 4;
334+
}
335+
lineoffset -= ((width*4)+(bitmap->width * 4 / 3));
336+
src += bitmap->pitch;
337+
}
338+
339+
}
340+
break;
318341
case ANTIALIAS_FULL:
319342
case ANTIALIAS_STRONG:
320343
for(int j = 0; j < ((bitmap->width * bitmap->rows)); j++) {
@@ -386,7 +409,9 @@ void Label::renderGlyphs(GlyphData *glyphData) {
386409
pen.x = (start_x + glyphData->positions[n].x) * 64;
387410
pen.y = (start_y + glyphData->positions[n].y) * 64;
388411

389-
if(antiAliasMode == ANTIALIAS_FULL || antiAliasMode == ANTIALIAS_STRONG) {
412+
if(antiAliasMode == ANTIALIAS_LCD) {
413+
error = FT_Glyph_To_Bitmap( &image, FT_RENDER_MODE_LCD, &pen, 0 );
414+
} else if(antiAliasMode == ANTIALIAS_FULL || antiAliasMode == ANTIALIAS_STRONG) {
390415
error = FT_Glyph_To_Bitmap( &image, FT_RENDER_MODE_LIGHT, &pen, 0 );
391416
} else {
392417
error = FT_Glyph_To_Bitmap( &image, FT_RENDER_MODE_MONO, &pen, 0 );
@@ -417,7 +442,7 @@ void Label::setText(const String& text) {
417442
return;
418443
if(!font->isValid())
419444
return;
420-
445+
421446
this->text = text;
422447

423448
precacheGlyphs(text, &labelData);

Examples/C++/Build/Darwin/PolycodeExample.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3982,6 +3982,7 @@
39823982
"\"$(SRCROOT)/../../Modules/Dependencies/include/bullet\"",
39833983
"\"$(SRCROOT)/Contents\"",
39843984
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/OpenAL.framework/Headers,
3985+
"\"$(SRCROOT)/../../Core/Dependencies/include/freetype2\"",
39853986
);
39863987
LIBRARY_SEARCH_PATHS = (
39873988
"$(inherited)",
@@ -4018,6 +4019,7 @@
40184019
"\"$(SRCROOT)/../../Modules/Dependencies/include/bullet\"",
40194020
"\"$(SRCROOT)/Contents\"",
40204021
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/OpenAL.framework/Headers,
4022+
"\"$(SRCROOT)/../../Core/Dependencies/include/freetype2\"",
40214023
);
40224024
LIBRARY_SEARCH_PATHS = (
40234025
"$(inherited)",

IDE/Build/Mac OS X/Polycode.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@
576576
"\"$(SRCROOT)/../../../Release/Darwin/Framework/Core/Dependencies/include\"",
577577
"\"$(SRCROOT)/../../../Release/Darwin/Framework/Modules/include\"",
578578
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/OpenAL.framework/Headers,
579+
"\"$(SRCROOT)/../../../Release/Darwin/Framework/Core/Dependencies/include/freetype2\"",
579580
);
580581
INFOPLIST_FILE = "Polycode-Info.plist";
581582
INSTALL_PATH = "$(HOME)/Applications";
@@ -608,6 +609,7 @@
608609
"\"$(SRCROOT)/../../../Release/Darwin/Framework/Core/Dependencies/include\"",
609610
"\"$(SRCROOT)/../../../Release/Darwin/Framework/Modules/include\"",
610611
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/OpenAL.framework/Headers,
612+
"\"$(SRCROOT)/../../../Release/Darwin/Framework/Core/Dependencies/include/freetype2\"",
611613
);
612614
INFOPLIST_FILE = "Polycode-Info.plist";
613615
INSTALL_PATH = "$(HOME)/Applications";

0 commit comments

Comments
 (0)