From 033666c2def42ebfa20478e92ec01df7b8bc7768 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Tue, 23 Nov 2004 18:19:27 +0000 Subject: [PATCH] Various ancient changes that were never committed (since they don't quite work yet) This was SVN commit r1380. --- source/tools/fontbuilder/fileformat.txt | 8 +++- source/tools/fontbuilder/font.cpp | 39 ++++++++++---------- source/tools/fontbuilder/font.h | 8 ++-- source/tools/fontbuilder/freetypedll.cpp | 15 +++++--- source/tools/fontbuilder/freetypedll.h | 3 +- source/tools/fontbuilder/freetypedll_funcs.h | 1 + source/tools/fontbuilder/stdafx.h | 6 ++- source/tools/fontbuilder/todo.txt | 31 +++++++++++++++- source/tools/fontbuilder/wxframe.cpp | 12 +++++- 9 files changed, 88 insertions(+), 35 deletions(-) diff --git a/source/tools/fontbuilder/fileformat.txt b/source/tools/fontbuilder/fileformat.txt index d93298c62d..d56e046fb8 100755 --- a/source/tools/fontbuilder/fileformat.txt +++ b/source/tools/fontbuilder/fileformat.txt @@ -1,4 +1,4 @@ -$Id: fileformat.txt,v 1.1 2004/06/17 19:32:04 philip Exp $ +$Id: fileformat.txt,v 1.2 2004/11/23 18:19:27 philip Exp $ Fonts consist of @@ -12,10 +12,11 @@ TGA's 1 byte/pixel, and DXTC's lossiness is almost noticeable.) The .fnt file is something like: - 100 + 101 512 256 3 16 + 12 32 0 0 10 10 12 33 10 0 6 10 7 3300 16 0 6 10 7 @@ -29,6 +30,9 @@ Third line = number of glyphs in the font. Fourth line = line spacing (pixels between each baseline) +Fifth line = text 'height' (height of the "I" glyph, possibly manually + adjusted so that vertical centering works) + Each subsequent line is diff --git a/source/tools/fontbuilder/font.cpp b/source/tools/fontbuilder/font.cpp index f0a234ba9d..ab6ea3856a 100755 --- a/source/tools/fontbuilder/font.cpp +++ b/source/tools/fontbuilder/font.cpp @@ -1,4 +1,4 @@ -// $Id: font.cpp,v 1.5 2004/08/27 20:24:15 philip Exp $ +// $Id: font.cpp,v 1.6 2004/11/23 18:19:27 philip Exp $ #include "stdafx.h" @@ -10,11 +10,15 @@ #include "freetypedll.h" +static char err[255]; // not exactly thread-safe + FontRenderer::FontRenderer(const char* filename0, const char* filename1, double ptsize, bool unpatented_hinting, bool hinting) { - if (SelectDLL(hinting ? 0 : 1)) + char* err_str = SelectDLL(hinting ? 0 : 1); + if (err_str) { - throw "Error loading FreeType DLL (freetype(a|b).dll)"; + sprintf(err, "Error loading FreeType DLL (freetype(a|b).dll (%d)): %s", hinting, err_str); + throw err; } int error; @@ -48,14 +52,7 @@ FontRenderer::FontRenderer(const char* filename0, const char* filename1, double NULL, NULL, 1, &openparam }; -/* - error = FT_New_Face( - FontLibrary0, - filename0, - 0, // index of face inside font file - &FontFace0 - ); -*/ + error = DLLFT_Open_Face( FontLibrary0, &args0, @@ -69,14 +66,6 @@ FontRenderer::FontRenderer(const char* filename0, const char* filename1, double throw "Error loading primary font"; } -/* - error = FT_New_Face( - FontLibrary1, - filename1, - 0, // index of face inside font file - &FontFace1 - ); -*/ error = DLLFT_Open_Face( FontLibrary1, &args1, @@ -139,7 +128,7 @@ FontRenderer::~FontRenderer() #define deg2rad(a) ((double)a * 3.14159265358979323846 / 180.0) -void FontRenderer::LoadGlyph(const int charcode) +int FontRenderer::LoadGlyph(const int charcode) { FT_Face FontFace = FontFace0; int glyph_index = DLLFT_Get_Char_Index(FontFace0, charcode); @@ -232,6 +221,8 @@ void FontRenderer::LoadGlyph(const int charcode) } LastFontFace = FontFace; + + return glyph_index; } @@ -354,3 +345,11 @@ void FontRenderer::GetMetrics(int& offset_x, int& offset_y, int& advance) if (advance) offset_x += Tracking; } + +int FontRenderer::GetKerning(int left, int right) +{ + FT_Vector vec; + DLLFT_Get_Kerning(LastFontFace, left, right, FT_KERNING_DEFAULT, &vec); + assert(vec.y == 0); + return vec.x>>6; +} \ No newline at end of file diff --git a/source/tools/fontbuilder/font.h b/source/tools/fontbuilder/font.h index d1089f6b1b..130e38e814 100755 --- a/source/tools/fontbuilder/font.h +++ b/source/tools/fontbuilder/font.h @@ -1,4 +1,4 @@ -// $Id: font.h,v 1.4 2004/08/27 20:24:15 philip Exp $ +// $Id: font.h,v 1.5 2004/11/23 18:19:27 philip Exp $ #ifndef _FONT_H_ #define _FONT_H_ @@ -30,8 +30,8 @@ public: ~FontRenderer(); - // Generate the glyph for the given Unicode code point - void LoadGlyph(const int charcode); + // Generate the glyph for the given Unicode code point. Returns the glyph index. + int LoadGlyph(const int charcode); // Put the appropriate pixel sizes into width and height void GetBoundingBox(int& width, int& height); @@ -50,6 +50,8 @@ public: // Supplies some information for positioning glyphs void GetMetrics(int& offset_x, int& offset_y, int& advance); + int GetKerning(int left, int right); + // Set by LoadGlyph if it can't find the right glyph bool Missing; diff --git a/source/tools/fontbuilder/freetypedll.cpp b/source/tools/fontbuilder/freetypedll.cpp index 8d40e325b2..628dcd4ba7 100755 --- a/source/tools/fontbuilder/freetypedll.cpp +++ b/source/tools/fontbuilder/freetypedll.cpp @@ -14,14 +14,16 @@ HINSTANCE dlls[2] = { 0, 0 }; -bool SelectDLL(int DLL) +static char err[255]; // not exactly thread-safe + +char* 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; + default: assert(! "Invalid DLL id!"); return "Invalid DLL ID"; } HINSTANCE hDLL; @@ -31,12 +33,15 @@ bool SelectDLL(int DLL) hDLL = dlls[DLL] = LoadLibraryA(name); if (! hDLL) - return true; + { + sprintf(err, "LoadLibrary failed (%d)", GetLastError()); + return err; + } - #define FUNC(ret, name, par) if (NULL == (DLL##name = (ret (*) par) GetProcAddress(hDLL, #name)) ) { return true; } + #define FUNC(ret, name, par) if (NULL == (DLL##name = (ret (*) par) GetProcAddress(hDLL, #name)) ) { sprintf(err, "GetProcAddress on %s failed (%d)", #name, GetLastError()); return err; } #include "freetypedll_funcs.h" - return false; + return NULL; } void FreeDLLs() diff --git a/source/tools/fontbuilder/freetypedll.h b/source/tools/fontbuilder/freetypedll.h index b78759e24b..06ba3ba7b4 100755 --- a/source/tools/fontbuilder/freetypedll.h +++ b/source/tools/fontbuilder/freetypedll.h @@ -1,4 +1,5 @@ -bool SelectDLL(int DLL); +// Returns NULL on success, else an error message +char* SelectDLL(int DLL); #define FUNC(ret, name, par) extern ret (* DLL##name) par #include "freetypedll_funcs.h" diff --git a/source/tools/fontbuilder/freetypedll_funcs.h b/source/tools/fontbuilder/freetypedll_funcs.h index f40e04e249..e66d76d94c 100755 --- a/source/tools/fontbuilder/freetypedll_funcs.h +++ b/source/tools/fontbuilder/freetypedll_funcs.h @@ -8,3 +8,4 @@ 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_Get_Kerning, ( FT_Face face, FT_UInt left_glyph, FT_UInt right_glyph, FT_UInt kern_mode, FT_Vector *akerning )); diff --git a/source/tools/fontbuilder/stdafx.h b/source/tools/fontbuilder/stdafx.h index 30c2359c0b..5718625efa 100755 --- a/source/tools/fontbuilder/stdafx.h +++ b/source/tools/fontbuilder/stdafx.h @@ -1,4 +1,4 @@ -// $Id: stdafx.h,v 1.6 2004/07/16 15:32:34 philip Exp $ +// $Id: stdafx.h,v 1.7 2004/11/23 18:19:27 philip Exp $ // Precompiled headers @@ -67,3 +67,7 @@ #endif #include "wx/defs.h" + +#ifdef _WIN32 +# define swprintf _snwprintf +#endif \ No newline at end of file diff --git a/source/tools/fontbuilder/todo.txt b/source/tools/fontbuilder/todo.txt index 7c96ec11ff..cc43a2a3f8 100755 --- a/source/tools/fontbuilder/todo.txt +++ b/source/tools/fontbuilder/todo.txt @@ -1,4 +1,12 @@ -$Id: todo.txt,v 1.3 2004/08/24 14:54:10 philip Exp $ +$Id: todo.txt,v 1.4 2004/11/23 18:19:27 philip Exp $ + +* Don't store full font path when it's unnecessary + +* Command line batch conversion + +* Fix bugs + +* >2 fonts (standard+unavailable+Hebrew, maybe) * Optimise storage of duplicated bitmaps (e.g. e and e-with-some-accent, comma and semicolon, anything and fullwidth versions, etc) @@ -14,3 +22,24 @@ $Id: todo.txt,v 1.3 2004/08/24 14:54:10 philip Exp $ * Work out when I should say 'character', when 'code point', and when 'glyph' * Kerning + + +Unicodeness: + +Many Latin-1 Supplement characters can be made from Basic Latin plus Combining Diacritical Marks. Storing the decomposed forms saves space in the texture, at the expense of longer and slightly more complex strings elsewhere. + +Assume all displayed text comes out of the i18n system. (When displaying fixed strings, always use translate("$string")<25% less pixels required. +* Works easily when fonts have only standard (accentless) Latin characters, though not necessarily well (Need to investigate that). +Disadvantages: +* Strings require a bit more memory +* Processing necessary when displaying strings (=> [small] decomposition database in the C++ code) + +But it looks really, really ugly. + + +Boldness: +Use SetTransform, 26.6, move fractional pixels \ No newline at end of file diff --git a/source/tools/fontbuilder/wxframe.cpp b/source/tools/fontbuilder/wxframe.cpp index 73007362e5..07c0c983f7 100755 --- a/source/tools/fontbuilder/wxframe.cpp +++ b/source/tools/fontbuilder/wxframe.cpp @@ -1,4 +1,4 @@ -// $Id: wxframe.cpp,v 1.7 2004/08/10 15:51:06 philip Exp $ +// $Id: wxframe.cpp,v 1.8 2004/11/23 18:19:27 philip Exp $ #include "stdafx.h" @@ -426,6 +426,8 @@ void MainFrame::GeneratePreview() int x = 16, y = Font.GetLineSpacing(); + int prev_glyph_index = 0; + wxString PreviewText = PreviewTextCtrl->GetValue(); for (size_t i = 0; i < PreviewText.Length(); ++i) { @@ -436,8 +438,14 @@ void MainFrame::GeneratePreview() } else { - Font.LoadGlyph(PreviewText[i]); + int glyph_index = Font.LoadGlyph(PreviewText[i]); + + if (prev_glyph_index) + x += Font.GetKerning(prev_glyph_index, glyph_index); + Font.RenderGlyph(PreviewImageData, x, y, PreviewWidth, PreviewHeight, PreviewWidth*3, false); + + prev_glyph_index = glyph_index; } } }