implemented textwidth calculation

removed all the glutBitmap references by the Font instance
recreated documentation + widget screenshots

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2230 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
blaszijk
2012-01-05 18:06:25 +00:00
parent 988658df7c
commit eab8fe3559
90 changed files with 138 additions and 109 deletions

View File

@ -15,6 +15,9 @@ uses
//This holds all of the information related to any
//freetype font that we want to create.
type
{ TGLFreeTypeFont }
TGLFreeTypeFont = object
Height: cardinal; //< Holds the height of the font.
textures: pGLuint; //< Holds the texture id's
@ -31,6 +34,8 @@ type
//out text at window coordinates x, y, using the font ft_font.
//The current modelview matrix will also be applied to the text.
procedure Print(x, y: double; Text: string);
function TextWidth(const Text: string): integer;
end;
implementation
@ -38,6 +43,10 @@ implementation
const
CHAR_NUM = 255;
var
//this is the cached advance of each glyph in pixels
glyphadvance: array[0..CHAR_NUM - 1] of LongInt;
//This function gets the first power of 2 >= the
//int that we pass it.
function next_p2(a: integer): integer; inline;
@ -156,21 +165,21 @@ begin
//so we need to link the texture to the quad
//so that the result will be properly aligned.
glBegin(GL_QUADS);
glTexCoord2d(0, 0);
glVertex2f(0, bitmap.rows);
glTexCoord2d(0, y);
glVertex2f(0, 0);
glTexCoord2d(x, y);
glVertex2f(bitmap.Width, 0);
glTexCoord2d(x, 0);
glVertex2f(bitmap.Width, bitmap.rows);
glTexCoord2d(0, 0);
glVertex2f(0, bitmap.rows);
glTexCoord2d(0, y);
glVertex2f(0, 0);
glTexCoord2d(x, y);
glVertex2f(bitmap.Width, 0);
glTexCoord2d(x, 0);
glVertex2f(bitmap.Width, bitmap.rows);
glEnd;
glPopMatrix;
glTranslatef(face^.glyph^.advance.x shr 6, 0, 0);
//increment the raster position as if we were a bitmap font.
//(only needed if you want to calculate text length)
glBitmap(0, 0, 0, 0, face^.glyph^.advance.x shr 6, 0, nil);
//(needed if you want to calculate text length)
glyphadvance[Ord(ch)] := face^.glyph^.advance.x shr 6;
//Finish the display list
glEndList;
@ -263,9 +272,9 @@ var
font: GLuint;
modelview_matrix: array [0..15] of double;
begin
//We want a coordinate system where things coresponding to window pixels.
pushScreenCoordinateMatrix;
//We want a coordinate system where things coresponding to window pixels.
font := list_base;
//Results Are Stored In Text
@ -303,5 +312,14 @@ begin
pop_projection_matrix;
end;
function TGLFreeTypeFont.TextWidth(const Text: string): integer;
var
i: Integer;
begin
Result := 0;
for i := 1 to Length(Text) do
Result += glyphadvance[Ord(Text[i])];
end;
end.