1
0
forked from 0ad/0ad

Various ancient changes that were never committed (since they don't quite work yet)

This was SVN commit r1380.
This commit is contained in:
Ykkrosh 2004-11-23 18:19:27 +00:00
parent fde2cae72e
commit 033666c2de
9 changed files with 88 additions and 35 deletions

View File

@ -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
<code point> <x> <y> <width> <height> <x offset> <y offset> <advance>

View File

@ -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;
}

View File

@ -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;

View File

@ -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()

View File

@ -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"

View File

@ -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 ));

View File

@ -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

View File

@ -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")<<string)
Standard phrases/words can be decomposed during the conversion process. Names / untranslated phrases need to be decomposed (and cached) by the [C++] i18n system.
Advantages:
* Fonts can have smaller textures. 402 vs 695 glyphs, >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

View File

@ -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;
}
}
}