1
0
forked from 0ad/0ad

Run-time selection of FreeType DLL, to let the user decide whether to enable glyph hinting

This was SVN commit r953.
This commit is contained in:
Ykkrosh 2004-08-10 15:51:06 +00:00
parent 9aa3be9ae3
commit 982b0ffc25
13 changed files with 158 additions and 57 deletions

View File

@ -21,7 +21,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;E:\wx\wxWindows-2.4.2\include&quot;;&quot;E:\wx\wxWindows-2.4.2\lib\mswud&quot;;&quot;E:\freetype\freetype-2.1.8\include&quot;;E:\wx\pretends"
AdditionalIncludeDirectories="&quot;E:\wx\wxWindows-2.4.2\include&quot;;&quot;E:\wx\wxWindows-2.4.2\lib\mswud&quot;;&quot;E:\freetype\freetype-2.1.8\include&quot;;E:\wx\pretends;."
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;__WXDEBUG__;_UNICODE;UNICODE;wxUSE_UNICODE=1"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
@ -37,7 +37,7 @@
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="wxmswud.lib freetype218MT_D.lib comctl32.lib ws2_32.lib rpcrt4.lib"
AdditionalDependencies="wxmswud.lib comctl32.lib ws2_32.lib rpcrt4.lib"
OutputFile="$(OutDir)/FontBuilder.exe"
LinkIncremental="2"
SuppressStartupBanner="TRUE"
@ -86,7 +86,7 @@
EnableFiberSafeOptimizations="FALSE"
OptimizeForProcessor="2"
OptimizeForWindowsApplication="FALSE"
AdditionalIncludeDirectories="E:\wx\wxWindows-2.4.2\include;E:\wx\wxWindows-2.4.2\lib\mswu;E:\freetype\freetype-2.1.8\include"
AdditionalIncludeDirectories="&quot;E:\wx\wxWindows-2.4.2\include&quot;;&quot;E:\wx\wxWindows-2.4.2\lib\mswud&quot;;&quot;E:\freetype\freetype-2.1.8\include&quot;;E:\wx\pretends;."
PreprocessorDefinitions="_STATIC_CPPLIB;WIN32;NDEBUG;_WINDOWS;_UNICODE;UNICODE;wxUSE_UNICODE=1"
StringPooling="TRUE"
RuntimeLibrary="2"
@ -112,6 +112,7 @@
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
OptimizeForWindows98="0"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
@ -149,6 +150,9 @@
<File
RelativePath=".\font.cpp">
</File>
<File
RelativePath=".\freetypedll.cpp">
</File>
<File
RelativePath=".\imagemanip.cpp">
</File>
@ -232,6 +236,12 @@
<File
RelativePath=".\font.h">
</File>
<File
RelativePath=".\freetypedll.h">
</File>
<File
RelativePath=".\freetypedll_funcs.h">
</File>
<File
RelativePath=".\imagemanip.h">
</File>

View File

@ -1,4 +1,4 @@
// $Id: font.cpp,v 1.3 2004/07/16 15:32:34 philip Exp $
// $Id: font.cpp,v 1.4 2004/08/10 15:51:06 philip Exp $
#include "stdafx.h"
@ -8,20 +8,27 @@
#include "freetype/ttunpat.h"
#include <math.h>
FontRenderer::FontRenderer(const char* filename0, const char* filename1, int ptsize, bool unpatented_hinting)
#include "freetypedll.h"
FontRenderer::FontRenderer(const char* filename0, const char* filename1, int ptsize, bool unpatented_hinting, bool hinting)
{
if (SelectDLL(hinting ? 0 : 1))
{
throw "Error loading FreeType DLL (freetype(a|b).dll)";
}
int error;
error = FT_Init_FreeType(&FontLibrary0);
error = DLLFT_Init_FreeType(&FontLibrary0);
if (error)
{
throw "Error initialising FreeType";
}
error = FT_Init_FreeType(&FontLibrary1);
error = DLLFT_Init_FreeType(&FontLibrary1);
if (error)
{
FT_Done_FreeType(FontLibrary0);
DLLFT_Done_FreeType(FontLibrary0);
throw "Error initialising FreeType";
}
@ -49,7 +56,7 @@ FontRenderer::FontRenderer(const char* filename0, const char* filename1, int pts
&FontFace0
);
*/
error = FT_Open_Face(
error = DLLFT_Open_Face(
FontLibrary0,
&args0,
0, // index of face inside font file
@ -57,8 +64,8 @@ FontRenderer::FontRenderer(const char* filename0, const char* filename1, int pts
);
if (error)
{
FT_Done_FreeType(FontLibrary0);
FT_Done_FreeType(FontLibrary1);
DLLFT_Done_FreeType(FontLibrary0);
DLLFT_Done_FreeType(FontLibrary1);
throw "Error loading primary font";
}
@ -70,7 +77,7 @@ FontRenderer::FontRenderer(const char* filename0, const char* filename1, int pts
&FontFace1
);
*/
error = FT_Open_Face(
error = DLLFT_Open_Face(
FontLibrary1,
&args1,
0, // index of face inside font file
@ -78,13 +85,13 @@ FontRenderer::FontRenderer(const char* filename0, const char* filename1, int pts
);
if (error)
{
FT_Done_Face(FontFace0);
FT_Done_FreeType(FontLibrary0);
FT_Done_FreeType(FontLibrary1);
DLLFT_Done_Face(FontFace0);
DLLFT_Done_FreeType(FontLibrary0);
DLLFT_Done_FreeType(FontLibrary1);
throw "Error loading secondary font face";
}
error = FT_Set_Char_Size(
error = DLLFT_Set_Char_Size(
FontFace0,
0, // char_width in 1/64th of points
ptsize*64, // char_height in 1/64th of points
@ -93,14 +100,14 @@ FontRenderer::FontRenderer(const char* filename0, const char* filename1, int pts
);
if (error)
{
FT_Done_Face(FontFace0);
FT_Done_Face(FontFace1);
FT_Done_FreeType(FontLibrary0);
FT_Done_FreeType(FontLibrary1);
DLLFT_Done_Face(FontFace0);
DLLFT_Done_Face(FontFace1);
DLLFT_Done_FreeType(FontLibrary0);
DLLFT_Done_FreeType(FontLibrary1);
throw "Error loading scalable character from primary font - is this a TrueType font?";
}
error = FT_Set_Char_Size(
error = DLLFT_Set_Char_Size(
FontFace1,
0, // char_width in 1/64th of points
ptsize*64, // char_height in 1/64th of points
@ -109,10 +116,10 @@ FontRenderer::FontRenderer(const char* filename0, const char* filename1, int pts
);
if (error)
{
FT_Done_Face(FontFace0);
FT_Done_Face(FontFace1);
FT_Done_FreeType(FontLibrary0);
FT_Done_FreeType(FontLibrary1);
DLLFT_Done_Face(FontFace0);
DLLFT_Done_Face(FontFace1);
DLLFT_Done_FreeType(FontLibrary0);
DLLFT_Done_FreeType(FontLibrary1);
throw "Error loading scalable character from secondary font - is this a TrueType font?";
}
@ -124,10 +131,10 @@ FontRenderer::FontRenderer(const char* filename0, const char* filename1, int pts
FontRenderer::~FontRenderer()
{
FT_Done_Face(FontFace0);
FT_Done_Face(FontFace1);
FT_Done_FreeType(FontLibrary0);
FT_Done_FreeType(FontLibrary1);
DLLFT_Done_Face(FontFace0);
DLLFT_Done_Face(FontFace1);
DLLFT_Done_FreeType(FontLibrary0);
DLLFT_Done_FreeType(FontLibrary1);
}
#define deg2rad(a) ((double)a * 3.14159265358979323846 / 180.0)
@ -135,19 +142,19 @@ FontRenderer::~FontRenderer()
void FontRenderer::LoadGlyph(const int charcode)
{
FT_Face FontFace = FontFace0;
int glyph_index = FT_Get_Char_Index(FontFace0, charcode);
int glyph_index = DLLFT_Get_Char_Index(FontFace0, charcode);
Missing = false;
if (glyph_index == 0)
{
// Can't find glyph in primary font - switch to secondary
FontFace = FontFace1;
glyph_index = FT_Get_Char_Index(FontFace1, charcode);
glyph_index = DLLFT_Get_Char_Index(FontFace1, charcode);
// Still can't find it - use the missing glyph symbol
if (glyph_index == 0)
{
glyph_index = FT_Get_Char_Index(FontFace1, 0xFFFD);
glyph_index = DLLFT_Get_Char_Index(FontFace1, 0xFFFD);
Missing = true;
}
}
@ -163,13 +170,13 @@ void FontRenderer::LoadGlyph(const int charcode)
mat.xy = mat.yx = (FT_Fixed)(0x00000L);
// Apply shear
FT_Fixed f = (FT_Fixed)(tan(deg2rad(Italicness)) * 0x10000L);
mat.xy += FT_MulFix(f, mat.xx);
mat.yy += FT_MulFix(f, mat.yx);
mat.xy += DLLFT_MulFix(f, mat.xx);
mat.yy += DLLFT_MulFix(f, mat.yx);
FT_Set_Transform(FontFace, &mat, 0);
DLLFT_Set_Transform(FontFace, &mat, 0);
}
error = FT_Load_Glyph(FontFace, glyph_index, FT_LOAD_DEFAULT);
error = DLLFT_Load_Glyph(FontFace, glyph_index, FT_LOAD_DEFAULT);
if (error)
throw "Error loading glyph";
@ -218,7 +225,7 @@ void FontRenderer::LoadGlyph(const int charcode)
else
{
// Simple version:
error = FT_Render_Glyph(FontFace->glyph, FT_RENDER_MODE_NORMAL);
error = DLLFT_Render_Glyph(FontFace->glyph, FT_RENDER_MODE_NORMAL);
if (error)
throw "Error rendering glyph";
}

View File

@ -1,4 +1,4 @@
// $Id: font.h,v 1.2 2004/07/16 15:32:34 philip Exp $
// $Id: font.h,v 1.3 2004/08/10 15:51:06 philip Exp $
#ifndef _FONT_H_
#define _FONT_H_
@ -9,12 +9,6 @@
#include FT_BBOX_H
// XXX: Kerning ( = hard? got to store giant table for OpenGL to use)
// XXX: Right-to-left text
// Make my IDE a little happier:
#if 0
#include "freetype/freetype.h"
@ -32,7 +26,7 @@ public:
// Two fonts are required - a primary (0) font which will be used first,
// and a secondary (1) font for filling in missing glyphs.
// (The secondary font should usually be Arial Unicode MS).
FontRenderer(const char* filename0, const char* filename1, int ptsize, bool unpatented_hinting);
FontRenderer(const char* filename0, const char* filename1, int ptsize, bool unpatented_hinting, bool hinting);
~FontRenderer();

View File

@ -55,6 +55,13 @@
<FileConfiguration
Name="Release|Win32"/>
</File>
<File
RelativePath=".\freetypedll.cpp">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
</File>
<File
RelativePath=".\imagemanip.cpp">
<FileConfiguration
@ -135,6 +142,20 @@
<FileConfiguration
Name="Release|Win32"/>
</File>
<File
RelativePath=".\freetypedll.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
</File>
<File
RelativePath=".\freetypedll_funcs.h">
<FileConfiguration
Name="Debug|Win32"/>
<FileConfiguration
Name="Release|Win32"/>
</File>
<File
RelativePath=".\imagemanip.h">
<FileConfiguration

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,47 @@
#include "stdafx.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#include "freetypedll.h"
#define FUNC(ret, name, par) ret (* DLL##name) par
#include "freetypedll_funcs.h"
#undef FUNC
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
HINSTANCE dlls[2] = { 0, 0 };
bool SelectDLL(int DLL)
{
const char* name;
switch (DLL)
{
case 0: name = "freetypea.dll"; break;
case 1: name = "freetypeb.dll"; break;
default: assert(! "Invalid DLL id!"); return true;
}
HINSTANCE hDLL;
if (dlls[DLL])
hDLL = dlls[DLL];
else
hDLL = dlls[DLL] = LoadLibraryA(name);
if (! hDLL)
return true;
#define FUNC(ret, name, par) if (NULL == (DLL##name = (ret (*) par) GetProcAddress(hDLL, #name)) ) { return true; }
#include "freetypedll_funcs.h"
return false;
}
void FreeDLLs()
{
for (int i=0; i<2; ++i)
if (dlls[i])
FreeLibrary(dlls[i]);
}

View File

@ -0,0 +1,5 @@
bool SelectDLL(int DLL);
#define FUNC(ret, name, par) extern ret (* DLL##name) par
#include "freetypedll_funcs.h"
#undef FUNC

View File

@ -0,0 +1,13 @@
//*
FUNC(FT_Error, FT_Init_FreeType, ( FT_Library *alibrary ));
FUNC(FT_Error, FT_Done_FreeType, ( FT_Library Library ));
FUNC(FT_Error, FT_Open_Face, ( FT_Library library, const FT_Open_Args* args, FT_Long face_index, FT_Face *aface ));
FUNC(FT_Error, FT_Done_Face, ( FT_Face face ));
FUNC(FT_Error, FT_Set_Char_Size, ( FT_Face face, FT_F26Dot6 char_width, FT_F26Dot6 char_height, FT_UInt horz_resolution, FT_UInt vert_resolution ));
FUNC(FT_UInt, FT_Get_Char_Index, ( FT_Face face, FT_ULong charcode ));
FUNC(FT_Long, FT_MulFix, ( FT_Long a, FT_Long b ));
FUNC(void, FT_Set_Transform, ( FT_Face face, FT_Matrix* matrix, FT_Vector* delta ));
FUNC(FT_Error, FT_Load_Glyph, ( FT_Face face, FT_UInt glyph_index, FT_Int32 load_flags ));
FUNC(FT_Error, FT_Render_Glyph, ( FT_GlyphSlot slot, FT_Render_Mode render_mode ));
//*/
//FUNC(FT_Error, FT_Init_FreeType, ( FT_Library* ));

View File

@ -1,8 +1,6 @@
// $Id: fontselect.cpp,v 1.3 2004/07/16 15:32:34 philip Exp $
// $Id: fontselect.cpp,v 1.4 2004/08/10 15:51:06 philip Exp $
// Switch as appropriate, because MSVC's PCH support doesn't like me
#include "../../stdafx.h"
//#include "stdafx.h"
#include "stdafx.h"
#include "../fontselect.h"

View File

@ -1,10 +1,12 @@
$Id: todo.txt,v 1.1 2004/06/17 19:32:04 philip Exp $
$Id: todo.txt,v 1.2 2004/08/10 15:51:06 philip Exp $
* Optimise storage of duplicated bitmaps (e.g. e and e-with-some-accent,
comma and semicolon, anything and fullwidth versions, etc)
* Optional antialiasing
* Right-to-left text
* Optional outlining (text with e.g. yellow fill and black outline
is made by drawing the black outline font and then the yellow
normal font)
@ -14,3 +16,5 @@ $Id: todo.txt,v 1.1 2004/06/17 19:32:04 philip Exp $
compression and filtering and antialiasing
* Work out when I should say 'character', when 'code point', and when 'glyph'
* Kerning

View File

@ -1 +1 @@
const wxString version = L"v1.0";
const wxString version = L"v1.1";

View File

@ -1,4 +1,4 @@
// $Id: wxframe.cpp,v 1.6 2004/07/16 15:32:34 philip Exp $
// $Id: wxframe.cpp,v 1.7 2004/08/10 15:51:06 philip Exp $
#include "stdafx.h"
@ -162,7 +162,7 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si
StyleSizer->Add(new wxStaticText(Panel, -1, wxT("Leading:")), 0, wxALIGN_RIGHT | wxLEFT | wxRIGHT, 2);
StyleSizer->Add(new StyleSpinCtrl(Panel, ID_Style_Leading, -256, 256, 0), 0, wxGROW | wxLEFT | wxRIGHT, 2);
StyleSizer->Add(new wxStaticText(Panel, -1, wxT("Alt. hinting:")), 0, wxALIGN_RIGHT | wxLEFT | wxRIGHT, 2);
StyleSizer->Add(new wxStaticText(Panel, -1, wxT("Disable hinting:")), 0, wxALIGN_RIGHT | wxLEFT | wxRIGHT, 2);
StyleSizer->Add(new wxCheckBox(Panel, ID_Style_Hinting, wxT("")), 0, wxGROW | wxLEFT | wxRIGHT, 2);
ControlSizer->Add(StyleSizer, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER, 8);
@ -269,7 +269,7 @@ void MainFrame::LoadSettings(wxString& filename)
Settings->GetAttributeValue(wxT("Size"), t); SizeCtrl->SetValue(t);
Settings->GetAttributeValue(wxT("Tracking"), t); TrackingCtrl->SetValue(t);
Settings->GetAttributeValue(wxT("Leading"), t); LeadingCtrl->SetValue(t);
Settings->GetAttributeValue(wxT("Hinting"), t); HintingCtrl->SetValue(t);
Settings->GetAttributeValue(wxT("Hinting"), t); HintingCtrl->SetValue(t ? true : false);
// Convert back to UTF16 from hex, because wxExpr doesn't like non-ASCII
@ -415,7 +415,8 @@ void MainFrame::GeneratePreview()
FontFilename0.ToAscii(),
FontFilename1.ToAscii(),
SizeCtrl->GetValidValue(),
HintingCtrl->GetValue() );
false,
!HintingCtrl->GetValue() );
Font.Boldness = BoldnessCtrl->GetValidValue();
Font.Italicness = 5 * ItalicnessCtrl->GetValidValue();
@ -516,7 +517,8 @@ void MainFrame::GenerateTexture(wxString TextureFilename, wxString FontDefnFilen
FontFilename0.ToAscii(),
FontFilename1.ToAscii(),
SizeCtrl->GetValidValue(),
HintingCtrl->GetValue() );
false,
!HintingCtrl->GetValue() );
Font.Boldness = BoldnessCtrl->GetValidValue();
Font.Italicness = 5 * ItalicnessCtrl->GetValidValue();