相关网址 7 J+ i+ y9 E* k# ~2 S0 t; \/ M
http://www.frictionalgames.com/forum/forum-27.html
6 r. f% b- Z# `/ y' M4 N
7 V6 T; B& Q$ c3 D---------------------------------- O5 P& y( y s5 g
2010.10.7 更新# y* }5 u. \7 ^! S
研究了一下这个游戏的源代码,在\sources\resources\FontManager.cpp里,我发现这个游戏还可以支持ttf字体文件。8 I$ z# {7 I4 ^8 N: K- N
方法很简单,只要在fonts目录下放上和.fnt文件同名的.ttf文件,然后把.fnt文件移走即可。
8 x" s; Y0 c: F0 m- |: }* V相关代码如下
" ~ A) _" T" ]* N8 j) y' }iFontData* cFontManager::CreateFontData(const tString& asName, int alSize,unsigned short alFirstChar,
) b2 F$ {# X H unsigned short alLastChar), n: J% `- M! s! A0 l
{
4 ~/ P* y6 M( k: c% p+ H tString sPath;0 h, `" W8 J* ]3 r9 B( r
iFontData* pFont;) b; w0 v. n% K' u. s2 R: z! w% M
tString asNewName = cString::ToLowerCase(asName);+ a4 a7 z) i3 q" a6 j1 ~& C# E
BeginLoad(asName);
* x( R& }0 I1 ?4 p5 X* `2 q( y ) d$ U/ K$ a- c5 j5 x% k
//asNewName = cString::SetFileExt(asName,"ttf");# I: |* N/ f. ?' f: t
pFont = static_cast<iFontData*>(this->FindLoadedResource(asNewName,sPath));7 k( \$ s( ?& T4 G4 X' `" O, Y
if(pFont==NULL && sPath!="")
- q$ ]9 L1 O. l3 O1 [ {' n$ Y; L' m/ p% V+ j1 |
pFont = mpGraphics->GetLowLevel()->CreateFontData(asNewName);
; U* }: u# y& L pFont->SetUp(mpGraphics->GetDrawer(),mpLowLevelResources,mpGui);0 F1 F- C5 F( C" C( R7 T& H
3 }, t# a* K/ m( e$ B; q tString sExt = cString::ToLowerCase(cString::GetFileExt(asName));
0 h8 |$ u) S. s4 Q //True Type Font
! u, }: c8 D) p if(sExt == "ttf")
3 n$ D& s0 u6 ?- f" m' V% b* P {
1 {0 p6 E! _; H' V) [' _. z w if(pFont->CreateFromFontFile(sPath,alSize,alFirstChar,alLastChar)==false){# n5 Q- s* p( @5 n% \9 E+ t7 E
hplDelete(pFont);( g$ K2 M7 D. T1 L4 r
EndLoad();* V+ h1 J I, o% d* M
return NULL;* K1 q9 d& L: p0 C3 M! S2 C
}
4 U: L$ X2 N" k. x/ a( e9 w) E) x }; ~* D7 @$ R2 f, y
//Angel code font type& d2 P+ Q$ E! y* u
else if(sExt == "fnt")
! t! D; J8 M* @! @; l" q3 w {
/ `. o2 S' ^4 s% ?' u1 Y if(pFont->CreateFromBitmapFile(sPath)==false){
. t5 _$ f/ a& G" O' N8 o hplDelete(pFont);
, q. i$ |4 f$ S: n' c EndLoad();
a% q& K: K5 f4 Q return NULL;
7 z9 H7 ?6 R2 _- R) b }
% I8 A2 J2 c- d3 e- n, c }
( S0 G' C6 Y4 V3 a else
) _8 n2 @" \" Q* G6 T {, q; e5 V+ F, a1 D8 d$ f& c& z
Error("Font '%s' has an unkown extension!\n",asName.c_str());2 ^4 n2 k9 I6 ?: u8 S
hplDelete(pFont);
" c2 L5 D- C( ]( s- J* f5 P% K/ U) I EndLoad();
J D7 X) R% [& j return NULL;# O8 }; |4 D' }" t5 s
}
3 u$ a O& e" E$ c
0 h8 F; T! P; a! A //mpResources->GetImageManager()->FlushAll();7 H! Y8 f0 G/ B6 D
AddResource(pFont);% |6 X( z9 R! v& T7 N9 n
}; z9 |% p# ^* J
if(pFont)pFont->IncUserCount();, ~# s6 R! d- p/ o1 C
else Error("Couldn't create font '%s'\n",asNewName.c_str());$ E& h3 O7 V/ `" k3 h
- V9 h5 i) x3 {% ~. v2 Y) n
EndLoad();4 @! U5 N! f/ F
return pFont;
2 A, \% @# D* U" O& l) j" C } |