冒险解谜游戏中文网 ChinaAVG

标题: 图片字库制作利器SDFont [打印本页]

作者: shane007    时间: 2010-1-18 23:49
标题: 图片字库制作利器SDFont
原文* i9 x1 O! _+ e. }
http://www.gamedev.net/community/forums/topic.asp?topic_id=491938. _7 K" M1 H4 Y2 `/ }/ w
5 o% `& a& A2 I$ A8 T1 P: B
用法# h& O1 J% n( K2 g/ R
How to use:
( K5 z2 v" I( K+ r* drag font files onto the exe# f; ~( B/ }5 |# a
* the app asks for a texture size (256 will yield a 256x256 texture for each input font file)8 Q" v$ K  ~: O# g
* the app will render all valid glyphs in the ANSI range [0..255], n4 [. k( i' s! \4 Z2 {9 ~0 D3 ]6 X
* the app will automatically search for the largest rendering size (integer pixels only, so hinting works with a greater range of TrueType fonts) where it can pack the output into the texture you specified earlier
1 C6 ]: R% P1 r7 X# P* the app packs the rendered Signed Distance Field glyphs into a single texture
4 J0 `+ ~! L& w1 W$ Y1 G* look at the output PNG and TXT file (in the same directory as the font file)$ i8 Q8 ~1 p4 }2 F9 d- A4 X8 f  \" a
. ~  U$ I" J/ _" d
Credits:$ G/ @* Z" w5 w4 }$ K1 y' N; J3 ~: Y
* FreeType2 for font rendering
6 x) S% S0 Q# o# c& V- p& I* k% C* LodePNG for saving the resultant file+ n* A- p& `; _& I5 H3 M
* BinPacker code from GameDev's own jyk!
$ u( O# W0 Q! w$ X! m+ D; B' A1 n- }
Please try it out and let me know what you think. Here are my ideas for where I'm going after this (please give any feedback or feature requests):
' Z  S/ J  {3 z6 H
5 l7 u! y" J: H* Y* I want to output a text file compliant with AngelCode's BMFont spec so existing loaders can use this output without changing anything other than the alpha threshold0 v" L8 a0 N0 |! E* C1 Q
! A3 |" [$ `) n
* I want an XML file for configuration so you can specify specific unicode characters (I'm thinking <range>A B</range> and <chars>A B C...ZY ZZ</chars>)
; F" [1 T1 M9 ?  d9 b8 ~: _6 Z0 ~3 N) Z7 D
* I want to allow an image for input, where a Signed Distance Field would then be computed from that into a lower resolution texture
. M5 H2 l# |6 I0 |) ?
- z& _0 `1 P3 G7 w( @So, what do you think? The source will be released (MIT) when I'm a bit closer to done. (Note, the RGB and A channels all share the same signed distance data, so there is a bit of a border to each glyph...I could just use all white for the color, but I think this looks pretty good.)$ C, h, i0 R/ a  P: k$ |1 w  t
% |: v3 y3 ^& V2 P
-----------------------------------------------------------------------------------------------------------% o" O  {, }7 R
I've updated the zip (same link). The changes:/ I) O! V7 G4 T2 c

! U  Y# G! E. \1 k9 y$ o* after dragging fonts onto the exe, you specify texture size and the highest Unicode character number (only characters with glyphs will be rendered).  u$ \# G  m, d2 \( R

; {$ [. L8 @, r* the output text file now has the offset and advance information, so you can finally render text properly (I hope!) I appended "page=0 chnl=0" to the end of each line to mirror the AngelCode BMFont tool. Note that this info is not integer data, and the offsets may be negative (both functions of the same thing...the actual glyph has border texels to help define the Signed Distance Field)
8 H* v* {1 l& L, b! q% |6 U. Y! a8 x& x1 w- y
* There is a bit more text describing the requested inputs
. ~! i/ z- W3 u, O  |+ h8 }& _4 p, {$ {0 O& W! J
* there is much better error checking (e.g. dragging non-font files onto the exe)
* c$ o& D- A% z0 z$ Y( E: X, J  L1 r, Y5 Q# ?3 s1 x6 e
* the zip now includes all my source code, ugly as it is (it also has the LodePNG and BinPacker code...you'll need to get and compile FreeType2 yourself)
. N8 l) F1 L7 c4 @8 T7 d; M: S9 [
. U6 @" E+ d6 B, |1 _' o% I' A
$ a' p4 b7 x6 `6 j- A) ^@AndyPandyV2: thanks for the kind words, you're welcome for the app [8^)! G- O4 a- Y! E

+ M2 g( h7 g2 b& |@OrangyTang & Kylotan: thanks for the feedback/input. As a simple hack you can now input the range of characters to be rendered. I think I like the XML approach as it would be slightly easier for me to implement than the UTF-8 file with all needed characters for 3 reasons: easier to parse as I already use an XML lib, I could see the UTF-8 file getting huge, and there is no guarantee of the glyph order after the packing (though the attendant text file would be in the specified order). Would the XML file be an OK solution for your needs? Or even the current incarnation? (note that rendering the entire Microsoft Arial font into a 4096x4096 took > 20 minutes, so I could see the use of limited sub-ranges! [8^)8 w6 v+ f8 b% h. w4 d9 f

- N. Y; F: _0 p# ]* Z+ h. GHere is some sample output, as I forgot to include this last time:
作者: 修普诺斯    时间: 2010-1-18 23:54
这会是个转折吗 [s:45]




欢迎光临 冒险解谜游戏中文网 ChinaAVG (https://chinaavg.com/) Powered by Discuz! X3.2