Hi all,

I've written a plib wrapper for the parts of TexFont used by chromium,
but unfortunately it doesn't render anything. I've attached the new
versions of TexFont.cpp, TexFont.h and the patch needed to let it build
after replacing the old versions with the new versions.

Also our beloved^Wex-DPL might be willing to switch chromium to using
FTGL and TTF fonts.

<pabs> grrrrr
* pabs hates TexFont with a passion
<pabs> anyone feel like helping with getting rid of the non-free code in
chromium? I have a TexFont-compatible wrapper for the plib fnt stuff,
but it doesn't display anything :(
<sam> what does texfont do?
<pabs> its an old font format by Mark J Kilgard, basically for rendering
using OpenGL textures
<pabs> in chromium it renders the menus, scores, etc
<sam> oh, I'll see if I can replace that code with FTGL
<pabs> cool, would you like upstream svn access?
<sam> that would dangerously move my "I'll see if" towards a "I
will" :-)
<sam> let me first look at the code
<pabs> any help is most welcome, been tooo many years since I looked at
opengl stuff
<pabs> mind if I paste this into the bug report?
<sam> I started 2 months ago :-)
<sam> pabs: please do
<pabs> only catch with FTGL would be somehow converting space.txf to a
ttf font
<sam> it looks like only txfRenderFancyString() can possibly be a
problem
<pabs> chromium doesn't use that AFAICT
<sam> it's likely space.txf was created from a truetype font itself
<sam> also, using another font that's already in Debian will allow for
proper i18n
<pabs> true

-- 
bye,
pabs

http://wiki.debian.org/PaulWise
/*
    TexFont-compatible wrapper around plibfnt for Chromium BSU

    This file is placed in the public domain by Paul Wise in 2008.
*/

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cassert>

#include "TexFont.h"

TexFont* txfLoadFont (const char* font_file) {

	TexFont* font = new TexFont;
	if( !font ) return NULL;

	/*
		plib doesn't read the ascent & descent properly
		so we need to read it from the file ourselves
		and return it when txfStringHeight is called
		some version later than 1.8.5 might do this
	*/
	FILE* f = fopen( font_file, "rb" );
	if( f )
	{
			/* Need to read 7 32-bit integers and check 4 of them */
#define LEN 7*4
			unsigned char b[LEN];
			if( fread(b, LEN, 1, f) && 0xFF == b[0] && 't' == b[1] && 'x' == b[2] && 'f' == b[3] ){
					unsigned int ascent;
					unsigned int descent;
					// endianness test
					if( 0x12 == b[4] && 0x34 == b[5] && 0x56 == b[6] && 0x78 == b[7] ){
							ascent = ( b[20] << 24 | b[21] << 16 | b[22] << 8 | b[23] );
							descent = ( b[24] << 24 | b[25] << 16 | b[26] << 8 | b[27] );
					} else {
							ascent = ( b[20] | b[21] << 8 | b[22] << 16 | b[23] << 24 );
							descent = ( b[24] | b[25] << 8 | b[26] << 16 | b[27] << 24 );
					}
					
					font->height = ascent - descent;
			}
#undef LEN
	}
	
	fntInit();
	
	font->texfont = new fntTexFont(font_file);
	if( !font->texfont ){ delete font; return NULL; }
	
	font->renderer = new fntRenderer();
	if( !font->renderer ){ delete font->texfont; delete font; return NULL; }
	
	font->renderer->setFont( font->texfont );

	return font;
}

GLuint txfEstablishTexture(TexFont* font, GLuint b, GLboolean c)
{
	fntInit();

	fprintf(stderr,"txfBindFontTexture: %p %u %s =%u\n", font, b, c?"true":"false", 0);

	return 0;
}

void txfBindFontTexture(TexFont* font)
{
	fntInit();

	fprintf(stderr,"txfBindFontTexture: %p\n", font);
}

void txfUnloadFont(TexFont* font)
{
	assert(font);
	assert(font->texfont);
	assert(font->renderer);
	
	fntInit();
	
	delete font->renderer; font->renderer = NULL;
	delete font->texfont; font->texfont = NULL;
	delete font;

	fprintf(stderr,"txfUnloadFont: %p\n", font);
}

float txfRenderString(TexFont* font, const char* string, int length) {
	assert(font);
	assert(font->renderer);

	fntInit();
	
	font->renderer->begin();
	font->renderer->puts(string);
	font->renderer->end();
	
	fprintf(stderr,"txfStringLength: %p %s %d\n",font, string, length);
}

GLfloat txfStringLength(TexFont* font, const char* string, int length){
	assert(font);
	assert(font->renderer);
	assert(font->texfont);
	
	float left, right;
	
	font->texfont->getBBox(
		string,
		font->renderer->getPointSize(),
		font->renderer->getSlant(),
		&left,
		&right,
		NULL,
		NULL
	);
	
	fprintf(stderr,"txfStringLength: %p %s %d =%f\n", font, string, length, right - left);
	
	return right - left;
}

GLfloat txfStringHeight(TexFont *font){
	assert(font);
	
	fprintf(stderr,"txfStringHeight: %p =%f\n", font, font->height);
	
	return font->height;
}
/*
    TexFont-compatible wrapper around plibfnt for Chromium BSU

    This file is placed in the public domain by Paul Wise in 2008.
*/

#ifndef __TEXFONT_H__
#define __TEXFONT_H__

#include <plib/fnt.h>
#include <GL/gl.h>

typedef struct {
	fntTexFont* texfont;
	fntRenderer* renderer;
	GLfloat height;
} TexFont;

extern TexFont* txfLoadFont(const char*);
extern void txfUnloadFont(TexFont*);
extern GLuint txfEstablishTexture(TexFont*,GLuint,GLboolean);
extern void txfBindFontTexture(TexFont*);
extern float txfRenderString(TexFont*,const char*,int);
extern GLfloat txfStringLength(TexFont*,const char*,int);
extern GLfloat txfStringHeight(TexFont *txf);

#endif /* __TEXFONT_H__ */
commit fb6b8983f1139d09878f39693a485eca2832f6d5
Author: Paul Wise <[EMAIL PROTECTED]>
Date:   Fri May 9 16:29:19 2008 +0800

    Replace non-free TexFont with a TexFont-compatible wrapper for plib.

diff --git a/src/CHROMIUM.pro b/src/CHROMIUM.pro
index cedc211..6e78557 100644
--- a/src/CHROMIUM.pro
+++ b/src/CHROMIUM.pro
@@ -38,7 +38,7 @@ isEmpty(GL_LIBS) {
 
 	
 
-LIBS		+= -lSDL_mixer -lglpng $(GL_LIBS) $(AL_LIBS) $(SDL_LIBS) $(SMPEG_LIBS) $(VORBIS_LIBS)
+LIBS		+= -lplibfnt -lplibul -lSDL_mixer -lglpng $(GL_LIBS) $(AL_LIBS) $(SDL_LIBS) $(SMPEG_LIBS) $(VORBIS_LIBS)
 
 ##-- Debug --
 #CONFIG		+= warn_on debug
diff --git a/src/MainGL.cpp b/src/MainGL.cpp
index 1120088..19152ef 100644
--- a/src/MainGL.cpp
+++ b/src/MainGL.cpp
@@ -97,21 +97,17 @@ int MainGL::initGL()
 //----------------------------------------------------------
 void MainGL::loadTextures()
 {
-	GLuint	texobj;
 	game->texFont = txfLoadFont( dataLoc("fonts/space.txf") );
 	if(!game->texFont)
 	{
 		fprintf(stderr, "\nERROR loading texture font. Check data path and try again.\n\n");
 		exit(1);
 	}
-	glGenTextures(1, &texobj);
-	txfEstablishTexture(game->texFont, texobj, GL_FALSE);
 }
 
 //----------------------------------------------------------
 void MainGL::deleteTextures()
 {
-	glDeleteTextures(1, &game->texFont->texobj);
 	txfUnloadFont(game->texFont);
 	game->texFont = 0;
 }

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to