@@ -33,49 +33,6 @@ Maryland 20850 USA.
3333*/
3434
3535// tr_font.c
36- //
37- //
38- // The font system uses FreeType 2.x to render TrueType fonts for use within the game.
39- // As of this writing ( Nov, 2000 ) Team Arena uses these fonts for all of the ui and
40- // about 90% of the cgame presentation. A few areas of the CGAME were left uses the old
41- // fonts since the code is shared with standard Q3A.
42- //
43- // If you include this font rendering code in a commercial product you MUST include the
44- // following somewhere with your product, see www.freetype.org for specifics or changes.
45- // The Freetype code also uses some hinting techniques that MIGHT infringe on patents
46- // held by apple so be aware of that also.
47- //
48- // As of Q3A 1.25+ and Team Arena, we are shipping the game with the font rendering code
49- // disabled. This removes any potential patent issues and it keeps us from having to
50- // distribute an actual TrueTrype font which is 1. expensive to do and 2. seems to require
51- // an act of god to accomplish.
52- //
53- // What we did was pre-render the fonts using FreeType ( which is why we leave the FreeType
54- // credit in the credits ) and then saved off the glyph data and then hand touched up the
55- // font bitmaps so they scale a bit better in GL.
56- //
57- // There are limitations in the way fonts are saved and reloaded in that it is based on
58- // point size and not name. So if you pre-render Helvetica in 18 point and Impact in 18 point
59- // you will end up with a single 18 point data file and image set. Typically you will want to
60- // choose 3 sizes to best approximate the scaling you will be doing in the ui scripting system
61- //
62- // In the UI Scripting code, a scale of 1.0 is equal to a 48 point font. In Team Arena, we
63- // use three or four scales, most of them exactly equaling the specific rendered size. We
64- // rendered three sizes in Team Arena, 12, 16, and 20.
65- //
66- // To generate new font data you need to go through the following steps.
67- // 1. delete the fontImage_x_xx.png files and fontImage_xx.dat files from the fonts path.
68- // 2. in a ui script, specify a font, smallFont, and bigFont keyword with font name and
69- // point size. the original TrueType fonts must exist in fonts at this point.
70- // 3. run the game. you should see things.
71- // 4. Exit the game and there will be three dat files and at least three PNG files. The
72- // PNGs are in 256x256 pages so if it takes three images to render a 24 point font you
73- // will end up with fontImage_0_24.tga through fontImage_2_24.tga
74- // 5. In future runs of the game, the system looks for these images and data files when a
75- // specific point sized font is rendered and loads them for use.
76- // 6. Because of the original beta nature of the FreeType code you will probably want to hand
77- // touch the font bitmaps.
78-
7936
8037#include " tr_local.h"
8138
@@ -299,43 +256,6 @@ static glyphInfo_t *RE_ConstructGlyphInfo( unsigned char *imageOut, int *xOut, i
299256 return nullptr ;
300257}
301258
302-
303- static int fdOffset;
304- static byte *fdFile;
305-
306- int readInt ()
307- {
308- int i =
309- fdFile[ fdOffset ] + ( fdFile[ fdOffset + 1 ] << 8 ) + ( fdFile[ fdOffset + 2 ] << 16 ) + ( fdFile[ fdOffset + 3 ] << 24 );
310- fdOffset += 4 ;
311- return i;
312- }
313-
314- union poor
315- {
316- byte fred[ 4 ];
317- float ffred;
318- };
319-
320- float readFloat ()
321- {
322- poor me;
323-
324- #ifdef Q3_BIG_ENDIAN
325- me.fred [ 0 ] = fdFile[ fdOffset + 3 ];
326- me.fred [ 1 ] = fdFile[ fdOffset + 2 ];
327- me.fred [ 2 ] = fdFile[ fdOffset + 1 ];
328- me.fred [ 3 ] = fdFile[ fdOffset + 0 ];
329- #else
330- me.fred [ 0 ] = fdFile[ fdOffset + 0 ];
331- me.fred [ 1 ] = fdFile[ fdOffset + 1 ];
332- me.fred [ 2 ] = fdFile[ fdOffset + 2 ];
333- me.fred [ 3 ] = fdFile[ fdOffset + 3 ];
334- #endif
335- fdOffset += 4 ;
336- return me.ffred ;
337- }
338-
339259void RE_GlyphChar ( fontInfo_t *font, int ch, glyphInfo_t *glyph )
340260{
341261 // default if out of range
@@ -580,9 +500,7 @@ fontInfo_t* RE_RegisterFont( const char *fontName, int pointSize )
580500 FT_Face face;
581501 void *faceData = nullptr ;
582502 int i, len, fontNo;
583- char fileName[ MAX_QPATH ];
584503 char strippedName[ MAX_QPATH ];
585- char registeredName[ MAX_QPATH ];
586504
587505 if ( pointSize <= 0 )
588506 {
@@ -594,17 +512,6 @@ fontInfo_t* RE_RegisterFont( const char *fontName, int pointSize )
594512
595513 COM_StripExtension2 ( fontName, strippedName, sizeof ( strippedName ) );
596514
597- if ( !Q_stricmp ( strippedName, fontName ) )
598- {
599- Com_sprintf ( fileName, sizeof ( fileName ), " fonts/fontImage_%i.dat" , pointSize );
600- }
601- else
602- {
603- Com_sprintf ( fileName, sizeof ( fileName ), " fonts/%s_%i.dat" , strippedName, pointSize );
604- }
605-
606- Com_sprintf ( registeredName, sizeof ( registeredName ), " %s#%d" , strippedName, pointSize );
607-
608515 fontNo = -1 ;
609516
610517 for ( i = 0 ; i < MAX_FONTS; i++ )
@@ -632,51 +539,6 @@ fontInfo_t* RE_RegisterFont( const char *fontName, int pointSize )
632539 fontInfo_t* font = ®isteredFont[ fontNo ];
633540 ResetStruct ( *font );
634541
635- len = ri.FS_ReadFile ( fileName, nullptr );
636-
637- if ( len > 0x5004 && len <= 0x5004 + MAX_QPATH ) // 256 glyphs, scale info, and the bitmap name
638- {
639- glyphInfo_t *glyphs;
640-
641- ri.FS_ReadFile ( fileName, &faceData );
642- fdOffset = 0 ;
643- fdFile = (byte*) faceData;
644-
645- glyphs = font->glyphBlock [0 ] = (glyphInfo_t*) Z_Calloc ( sizeof ( glyphBlock_t ) );
646-
647- for ( i = 0 ; i < GLYPHS_PER_FONT; i++ )
648- {
649- /* height */ readInt ();
650- glyphs[ i ].top = readInt ();
651- glyphs[ i ].bottom = readInt ();
652- glyphs[ i ].pitch = readInt ();
653- glyphs[ i ].xSkip = readInt ();
654- glyphs[ i ].imageWidth = readInt ();
655- glyphs[ i ].imageHeight = readInt ();
656- glyphs[ i ].s = readFloat ();
657- glyphs[ i ].t = readFloat ();
658- glyphs[ i ].s2 = readFloat ();
659- glyphs[ i ].t2 = readFloat ();
660- glyphs[ i ].glyph = readInt ();
661- Q_strncpyz ( glyphs[ i ].shaderName , (const char *) &fdFile[ fdOffset ], sizeof ( glyphs[ i ].shaderName ) );
662- fdOffset += sizeof ( glyphs[ i ].shaderName );
663- }
664-
665- font->pointSize = pointSize;
666- /* glyphScale */ readFloat ();
667- Q_strncpyz ( font->name , registeredName, sizeof ( font->name ) );
668-
669- ri.FS_FreeFile ( faceData );
670-
671- for ( i = GLYPH_START; i <= GLYPH_END; i++ )
672- {
673- glyphs[ i ].glyph = RE_RegisterShader ( glyphs[ i ].shaderName , RSF_NOMIP );
674- }
675-
676- ++fontUsage[ fontNo ];
677- return font;
678- }
679-
680542 if ( ftLibrary == nullptr )
681543 {
682544 Log::Warn (" RE_RegisterFont: FreeType not initialized." );
@@ -685,13 +547,11 @@ fontInfo_t* RE_RegisterFont( const char *fontName, int pointSize )
685547
686548 Q_strncpyz ( font->name , strippedName, sizeof ( font->name ) );
687549
688- Q_strncpyz ( fileName, fontName, sizeof ( fileName ) );
689-
690- len = RE_LoadFontFile ( fileName, &faceData );
550+ len = RE_LoadFontFile ( fontName, &faceData );
691551
692552 if ( len <= 0 )
693553 {
694- Log::Warn (" RE_RegisterFont: Unable to read font file %s" , fileName );
554+ Log::Warn (" RE_RegisterFont: Unable to read font file %s" , fontName );
695555 RE_FreeFontFile ( faceData );
696556 return nullptr ;
697557 }
0 commit comments