You've already forked lazarus-ccr
added font sources to documentation
painter and fonts are now user creatable properties added font option to fpmake implemented font styles for gl freetype started work on glut font class clean-up of nvglutwidgets class git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2243 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -17,25 +17,11 @@ uses
|
||||
//freetype font that we want to create.
|
||||
type
|
||||
|
||||
{ TGLFreeTypeFont }
|
||||
{ TGLFreeType }
|
||||
|
||||
TGLFreeTypeFont = object //class(TNVBaseFont)
|
||||
TGLFreeType = object
|
||||
textures: pGLuint; //< Holds the texture id's
|
||||
list_base: GLuint; //< Holds the first display list id
|
||||
{ public
|
||||
constructor Create(AName: string; ASize: integer); override;
|
||||
|
||||
//text metrics
|
||||
function TextHeight(Text: string): integer; override;
|
||||
function TextWidth(Text: string): integer; override;
|
||||
procedure TextSize(Text: string; var w, h: integer); override;
|
||||
|
||||
//printing function
|
||||
procedure TextOut(x, y: double; Text: string); override;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Height: cardinal; //< Holds the height of the font.
|
||||
|
||||
//The init function will create a font of
|
||||
@ -202,7 +188,7 @@ begin
|
||||
FT_Done_Glyph(glyph);
|
||||
end;
|
||||
|
||||
procedure TGLFreeTypeFont.Init(const fname: string; AHeight: cardinal);
|
||||
procedure TGLFreeType.Init(const fname: string; AHeight: cardinal);
|
||||
var
|
||||
library_: PFT_Library = nil;
|
||||
face: PFT_Face = nil; //The object in which Freetype holds information on a given font is called a "face".
|
||||
@ -247,7 +233,7 @@ begin
|
||||
FT_Done_FreeType(library_);
|
||||
end;
|
||||
|
||||
procedure TGLFreeTypeFont.Clean;
|
||||
procedure TGLFreeType.Clean;
|
||||
begin
|
||||
glDeleteLists(list_base, CHAR_NUM);
|
||||
glDeleteTextures(CHAR_NUM, textures);
|
||||
@ -282,7 +268,7 @@ end;
|
||||
|
||||
//Much like Nehe's glPrint function, but modified to work
|
||||
//with freetype fonts.
|
||||
procedure TGLFreeTypeFont.Print(x, y: double; Text: string);
|
||||
procedure TGLFreeType.Print(x, y: double; Text: string);
|
||||
var
|
||||
font: GLuint;
|
||||
modelview_matrix: array [0..15] of double;
|
||||
@ -327,7 +313,7 @@ begin
|
||||
pop_projection_matrix;
|
||||
end;
|
||||
|
||||
function TGLFreeTypeFont.TextWidth(const Text: string): integer;
|
||||
function TGLFreeType.TextWidth(const Text: string): integer;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
|
136
components/nvidia-widgets/src/gl/glfreetypefont.pas
Normal file
136
components/nvidia-widgets/src/gl/glfreetypefont.pas
Normal file
@ -0,0 +1,136 @@
|
||||
unit GLFreeTypeFont;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, GLFreeType,
|
||||
nvBaseFont;
|
||||
|
||||
type
|
||||
TFontStyles = record
|
||||
Name: string;
|
||||
Bold: boolean;
|
||||
Italic: boolean;
|
||||
StrikeTrough: boolean;
|
||||
Underline: boolean;
|
||||
Font: TGLFreeType;
|
||||
end;
|
||||
|
||||
{ TGLFreeTypeFont }
|
||||
|
||||
TGLFreeTypeFont = class(TNVBaseFont)
|
||||
private
|
||||
FFontList: array of TFontStyles;
|
||||
FCount: integer;
|
||||
FActiveFont: integer;
|
||||
procedure FindStylizedFont;
|
||||
protected
|
||||
procedure SetFlags(AIndex: integer; AValue: boolean); override;
|
||||
public
|
||||
constructor Create(AName: string; ASize: integer); override;
|
||||
destructor Destroy; override;
|
||||
|
||||
//add stylized fonts
|
||||
procedure Add(AName: string; ABold, AItalic, AStrikeTrough, AUnderline: boolean); override;
|
||||
|
||||
//text metrics
|
||||
function TextHeight(Text: string): integer; override;
|
||||
function TextWidth(Text: string): integer; override;
|
||||
|
||||
//printing function
|
||||
procedure TextOut(x, y: double; Text: string); override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TGLFreeTypeFont }
|
||||
|
||||
procedure TGLFreeTypeFont.FindStylizedFont;
|
||||
var
|
||||
item: TFontStyles;
|
||||
i: integer;
|
||||
begin
|
||||
//if more fonts defined then find stylized font
|
||||
if FCount > 1 then
|
||||
for i := 0 to FCount - 1 do
|
||||
begin
|
||||
item := FFontList[i];
|
||||
|
||||
if (item.Bold = Bold) and
|
||||
(item.Italic = Italic) and
|
||||
(item.StrikeTrough = StrikeTrough) and
|
||||
(item.Underline = Underline) then
|
||||
begin
|
||||
FActiveFont := i;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
//no font found, select default one
|
||||
FActiveFont := 0;
|
||||
end;
|
||||
|
||||
procedure TGLFreeTypeFont.SetFlags(AIndex: integer; AValue: boolean);
|
||||
begin
|
||||
inherited SetFlags(AIndex, AValue);
|
||||
|
||||
FindStylizedFont;
|
||||
end;
|
||||
|
||||
constructor TGLFreeTypeFont.Create(AName: string; ASize: integer);
|
||||
begin
|
||||
inherited Create(AName, ASize);
|
||||
|
||||
FCount := 0;
|
||||
FSize := ASize;
|
||||
Add(AName, False, False, False, False);
|
||||
end;
|
||||
|
||||
destructor TGLFreeTypeFont.Destroy;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
for i := 0 to FCount - 1 do
|
||||
FFontList[i].Font.Clean;
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TGLFreeTypeFont.Add(AName: string; ABold, AItalic, AStrikeTrough, AUnderline: boolean);
|
||||
begin
|
||||
Inc(FCount);
|
||||
SetLength(FFontList, FCount);
|
||||
|
||||
with FFontList[FCount - 1] do
|
||||
begin
|
||||
Font.Init(AName, Size);
|
||||
Name := AName;
|
||||
Bold := ABold;
|
||||
Italic := AItalic;
|
||||
StrikeTrough := AStrikeTrough;
|
||||
Underline := AUnderline;
|
||||
end;
|
||||
|
||||
FindStylizedFont;
|
||||
end;
|
||||
|
||||
function TGLFreeTypeFont.TextHeight(Text: string): integer;
|
||||
begin
|
||||
Result := Size;
|
||||
end;
|
||||
|
||||
function TGLFreeTypeFont.TextWidth(Text: string): integer;
|
||||
begin
|
||||
//only one font available or style not found then show default
|
||||
Result := FFontList[FActiveFont].Font.TextWidth(Text);
|
||||
end;
|
||||
|
||||
procedure TGLFreeTypeFont.TextOut(x, y: double; Text: string);
|
||||
begin
|
||||
FFontList[FActiveFont].Font.Print(x, y, Text);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -15,7 +15,7 @@ interface
|
||||
|
||||
uses
|
||||
Classes, nvWidgets,
|
||||
GL, ftFont, FPCanvas, GLFreeType;
|
||||
GL, ftFont, FPCanvas;
|
||||
|
||||
const
|
||||
cBase = 0;
|
||||
@ -196,8 +196,6 @@ type
|
||||
|
||||
procedure init; override;
|
||||
private
|
||||
Font: TGLFreeTypeFont;
|
||||
|
||||
m_setupStateDL: integer;
|
||||
m_restoreStateDL: integer;
|
||||
m_foregroundDL: integer;
|
||||
@ -256,13 +254,11 @@ begin
|
||||
m_texelScaleUniform := 0;
|
||||
m_texelOffsetUniform := 0;
|
||||
m_texelSwizzlingUniform := 0;
|
||||
|
||||
Font.Init('Ubuntu-R.ttf', 10);
|
||||
end;
|
||||
|
||||
destructor GLUIPainter.Destroy;
|
||||
begin
|
||||
Font.Clean;
|
||||
Font.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
@ -797,7 +793,7 @@ end;
|
||||
|
||||
function GLUIPainter.getFontHeight: integer;
|
||||
begin
|
||||
Result := Font.Height + 4;
|
||||
Result := Font.TextHeight('X') + 4;
|
||||
end;
|
||||
|
||||
function GLUIPainter.getTextLineWidth(const Text: string): integer;
|
||||
@ -925,7 +921,7 @@ end;
|
||||
|
||||
procedure GLUIPainter.drawString(x: integer; y: integer; Text: string; nbLines: integer);
|
||||
begin
|
||||
Font.Print(x, y + 2, Text);
|
||||
Font.TextOut(x, y + 2, Text);
|
||||
end;
|
||||
|
||||
procedure GLUIPainter.drawRect(aRect: Rect; fillColorId: integer; borderColorId: integer);
|
||||
|
Reference in New Issue
Block a user