You've already forked lazarus-ccr
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:
@ -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.
|
||||
|
||||
|
@ -797,20 +797,12 @@ end;
|
||||
|
||||
function GLUIPainter.getFontHeight: integer;
|
||||
begin
|
||||
Result := Font.Height;
|
||||
exit;
|
||||
Result := 12 + 4;
|
||||
Result := Font.Height + 4;
|
||||
end;
|
||||
|
||||
function GLUIPainter.getTextLineWidth(const Text: string): integer;
|
||||
var
|
||||
w: integer = 0;
|
||||
i: integer;
|
||||
begin
|
||||
for i := 1 to Length(Text) do
|
||||
w := w + glutBitmapWidth(GLUT_BITMAP_HELVETICA_12, Ord(Text[i]));
|
||||
|
||||
Result := w + 2;
|
||||
Result := Font.TextWidth(Text) + 2;
|
||||
end;
|
||||
|
||||
function GLUIPainter.getTextSize(const Text: string; out nbLines: integer): integer;
|
||||
@ -842,7 +834,7 @@ begin
|
||||
for i := 0 to charNb - 1 do
|
||||
begin
|
||||
if (Text[i] <> #13) and (Text[i + 1] <> #10) then
|
||||
w := w + glutBitmapWidth(GLUT_BITMAP_HELVETICA_12, Ord(Text[i]))
|
||||
w := w + Font.TextWidth(Text[i])
|
||||
else
|
||||
begin
|
||||
Result := w + 1;
|
||||
@ -870,7 +862,7 @@ begin
|
||||
i := 0;
|
||||
while (i <= Length(Text)) and (Text[i] <> #13) and (Text[i + 1] <> #10) do
|
||||
begin
|
||||
w := w + glutBitmapWidth(GLUT_BITMAP_HELVETICA_12, Ord(Text[i]));
|
||||
w := w + Font.TextWidth(Text[i]);
|
||||
if at.x < w then
|
||||
begin
|
||||
Result := i - textstart;
|
||||
@ -933,7 +925,7 @@ end;
|
||||
|
||||
procedure GLUIPainter.drawString(x: integer; y: integer; Text: string; nbLines: integer);
|
||||
begin
|
||||
Font.Print(x, y, Text);
|
||||
Font.Print(x, y + 2, Text);
|
||||
end;
|
||||
|
||||
procedure GLUIPainter.drawRect(aRect: Rect; fillColorId: integer; borderColorId: integer);
|
||||
|
Reference in New Issue
Block a user