|
@@ -48,11 +48,10 @@ type
|
|
|
PFontBitmap = ^TFontBitmap;
|
|
|
|
|
|
|
|
|
- TStringBitMaps = class
|
|
|
+ TBaseStringBitMaps = class
|
|
|
private
|
|
|
FList : TList;
|
|
|
FBounds : TRect;
|
|
|
- FText : string;
|
|
|
FMode : TBitmapType;
|
|
|
function GetCount : integer;
|
|
|
function GetBitmap (index:integer) : PFontBitmap;
|
|
@@ -61,17 +60,30 @@ type
|
|
|
constructor Create (ACount : integer);
|
|
|
destructor destroy; override;
|
|
|
procedure GetBoundRect (out aRect : TRect);
|
|
|
- property Text : string read FText;
|
|
|
property Mode : TBitmapType read FMode;
|
|
|
property Count : integer read GetCount;
|
|
|
property Bitmaps[index:integer] : PFontBitmap read GetBitmap;
|
|
|
end;
|
|
|
|
|
|
+ TStringBitMaps = class(TBaseStringBitMaps)
|
|
|
+ private
|
|
|
+ FText : STring;
|
|
|
+ public
|
|
|
+ property Text : string read FText;
|
|
|
+ end;
|
|
|
+
|
|
|
+ TUnicodeStringBitMaps = class(TBaseStringBitMaps)
|
|
|
+ private
|
|
|
+ FText : UnicodeString;
|
|
|
+ public
|
|
|
+ property Text : Unicodestring read FText;
|
|
|
+ end;
|
|
|
+
|
|
|
TFontManager = class;
|
|
|
|
|
|
PMgrGlyph = ^TMgrGlyph;
|
|
|
TMgrGlyph = record
|
|
|
- Character : char;
|
|
|
+ Character : unicodechar;
|
|
|
GlyphIndex : FT_UInt;
|
|
|
Glyph : PFT_Glyph;
|
|
|
end;
|
|
@@ -109,33 +121,41 @@ type
|
|
|
function GetSearchPath : string;
|
|
|
procedure SetSearchPath (AValue : string);
|
|
|
procedure SetExtention (AValue : string);
|
|
|
+ Procedure DoMakeString (Text : Array of cardinal; ABitmaps : TBaseStringBitmaps);
|
|
|
+ Procedure DoMakeString (Text : Array of cardinal; angle: real; ABitmaps : TBaseStringBitmaps);
|
|
|
protected
|
|
|
function GetFontId (afilename:string; anindex:integer) : integer;
|
|
|
function CreateFont (afilename:string; anindex:integer) : integer;
|
|
|
- function SearchFont (afilename:string) : string;
|
|
|
function GetFont (FontID:integer) : TMgrFont;
|
|
|
procedure GetSize (aSize, aResolution : integer);
|
|
|
function CreateSize (aSize, aResolution : integer) : PMgrSize;
|
|
|
procedure SetPixelSize (aSize, aResolution : integer);
|
|
|
- function GetGlyph (c : char) : PMgrGlyph;
|
|
|
- function CreateGlyph (c : char) : PMgrGlyph;
|
|
|
+ function GetGlyph (c : cardinal) : PMgrGlyph;
|
|
|
+ function CreateGlyph (c : cardinal) : PMgrGlyph;
|
|
|
procedure MakeTransformation (angle:real; out Transformation:FT_Matrix);
|
|
|
procedure InitMakeString (FontID, Size:integer);
|
|
|
function MakeString (FontId:integer; Text:string; size:integer; angle:real) : TStringBitmaps;
|
|
|
function MakeString (FontId:integer; Text:string; Size:integer) : TStringBitmaps;
|
|
|
+ function MakeString (FontId:integer; Text:Unicodestring; size:integer; angle:real) : TUnicodeStringBitmaps;
|
|
|
+ function MakeString (FontId:integer; Text:Unicodestring; Size:integer) : TUnicodeStringBitmaps;
|
|
|
public
|
|
|
constructor Create;
|
|
|
destructor destroy; override;
|
|
|
+ function SearchFont(afilename: string; doraise: boolean=true): string;
|
|
|
function RequestFont (afilename:string) : integer;
|
|
|
function RequestFont (afilename:string; anindex:integer) : integer;
|
|
|
function GetFreeTypeFont (aFontID:integer) : PFT_Face;
|
|
|
function GetString (FontId:integer; Text:string; size:integer; angle:real) : TStringBitmaps;
|
|
|
+ function GetString (FontId:integer; Text:Unicodestring; size:integer; angle:real) : TUnicodeStringBitmaps;
|
|
|
// Black and white
|
|
|
function GetStringGray (FontId:integer; Text:string; size:integer; angle:real) : TStringBitmaps;
|
|
|
+ function GetStringGray (FontId:integer; Text:unicodestring; size:integer; angle:real) : TUnicodeStringBitmaps;
|
|
|
// Anti Aliased gray scale
|
|
|
function GetString (FontId:integer; Text:string; Size:integer) : TStringBitmaps;
|
|
|
+ function GetString (FontId:integer; Text:Unicodestring; Size:integer) : TUnicodeStringBitmaps;
|
|
|
// Black and white, following the direction of the font (left to right, top to bottom, ...)
|
|
|
- function GetStringGray (FontId:integer; Text:string; Size:integer) : TStringBitmaps;
|
|
|
+ function GetStringGray (FontId:integer; Text: String; Size:integer) : TStringBitmaps;
|
|
|
+ function GetStringGray (FontId:integer; Text:Unicodestring; Size:integer) : TUnicodeStringBitmaps;
|
|
|
// Anti Aliased gray scale, following the direction of the font (left to right, top to bottom, ...)
|
|
|
property SearchPath : string read GetSearchPath write SetSearchPath;
|
|
|
property DefaultExtention : string read FExtention write SetExtention;
|
|
@@ -381,11 +401,12 @@ begin
|
|
|
AValue := '';
|
|
|
end;
|
|
|
|
|
|
-function TFontManager.SearchFont (afilename:string) : string;
|
|
|
+function TFontManager.SearchFont (afilename:string; doraise : boolean = true) : string;
|
|
|
// returns full filename of font, taking SearchPath in account
|
|
|
var p,fn : string;
|
|
|
r : integer;
|
|
|
begin
|
|
|
+ Result:='';
|
|
|
if (pos('.', afilename)=0) and (DefaultFontExtention<>'') then
|
|
|
fn := afilename + DefaultFontExtention
|
|
|
else
|
|
@@ -401,14 +422,12 @@ begin
|
|
|
repeat
|
|
|
dec (r);
|
|
|
until (r < 0) or FileExists(FPaths[r]+fn);
|
|
|
- if r < 0 then
|
|
|
- raise FreeTypeException.CreateFmt (sErrFontFileNotFound, [fn])
|
|
|
- else
|
|
|
- result := FPaths[r]+fn;
|
|
|
+ if r >= 0 then
|
|
|
+ Result := FPaths[r]+fn;
|
|
|
end
|
|
|
- else
|
|
|
- raise FreeTypeException.CreateFmt (sErrFontFileNotFound, [afilename]);
|
|
|
end;
|
|
|
+ if (Result='') and doRaise then
|
|
|
+ raise FreeTypeException.CreateFmt (sErrFontFileNotFound, [fn])
|
|
|
end;
|
|
|
|
|
|
function TFontManager.GetFontId (afilename:string; anindex:integer) : integer;
|
|
@@ -527,13 +546,13 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
-function TFontManager.CreateGlyph (c : char) : PMgrGlyph;
|
|
|
+function TFontManager.CreateGlyph (c : cardinal) : PMgrGlyph;
|
|
|
var e : integer;
|
|
|
begin
|
|
|
new (result);
|
|
|
FillByte(Result^,SizeOf(Result),0);
|
|
|
- result^.character := c;
|
|
|
- result^.GlyphIndex := FT_Get_Char_Index (CurFont.font, ord(c));
|
|
|
+ result^.character := unicodechar(c);
|
|
|
+ result^.GlyphIndex := FT_Get_Char_Index (CurFont.font, c);
|
|
|
//WriteFT_Face(CurFont.Font);
|
|
|
e := FT_Load_Glyph (CurFont.font, result^.GlyphIndex, FT_Load_Default);
|
|
|
if e <> 0 then
|
|
@@ -548,7 +567,7 @@ begin
|
|
|
CurSize^.Glyphs.Add (result);
|
|
|
end;
|
|
|
|
|
|
-function TFontManager.GetGlyph (c : char) : PMgrGlyph;
|
|
|
+function TFontManager.GetGlyph (c : cardinal) : PMgrGlyph;
|
|
|
var r : integer;
|
|
|
begin
|
|
|
With CurSize^ do
|
|
@@ -556,7 +575,7 @@ begin
|
|
|
r := Glyphs.Count;
|
|
|
repeat
|
|
|
dec (r)
|
|
|
- until (r < 0) or (PMgrGlyph(Glyphs[r])^.character = c);
|
|
|
+ until (r < 0) or (PMgrGlyph(Glyphs[r])^.character = unicodechar(c));
|
|
|
if r < 0 then
|
|
|
result := CreateGlyph (c)
|
|
|
else
|
|
@@ -571,10 +590,48 @@ begin
|
|
|
end;
|
|
|
|
|
|
function TFontManager.MakeString (FontId:integer; Text:string; size:integer; angle:real) : TStringBitmaps;
|
|
|
+
|
|
|
+Var
|
|
|
+ T : Array of cardinal;
|
|
|
+ C,I : Integer;
|
|
|
+
|
|
|
+begin
|
|
|
+ CurFont := GetFont(FontID);
|
|
|
+ InitMakeString (FontID, Size);
|
|
|
+ c := length(text);
|
|
|
+ result := TStringBitmaps.Create(c);
|
|
|
+ result.FText := Text;
|
|
|
+ SetLength(T,Length(Text));
|
|
|
+ For I:=1 to Length(Text) do
|
|
|
+ T[I-1]:=Ord(Text[i]);
|
|
|
+ DoMakeString(T,Angle,Result);
|
|
|
+end;
|
|
|
+
|
|
|
+function TFontManager.MakeString (FontId:integer; Text:Unicodestring; size:integer; angle:real) : TUnicodeStringBitmaps;
|
|
|
+
|
|
|
+Var
|
|
|
+ T : Array of cardinal;
|
|
|
+ c,I : Integer;
|
|
|
+
|
|
|
+begin
|
|
|
+ CurFont := GetFont(FontID);
|
|
|
+ InitMakeString (FontID, Size);
|
|
|
+ c := length(text);
|
|
|
+ result := TUnicodeStringBitmaps.Create(c);
|
|
|
+ result.FText := Text;
|
|
|
+ SetLength(T,C);
|
|
|
+ For I:=1 to c do
|
|
|
+ T[I-1]:=Ord(Text[i]);
|
|
|
+ DoMakeString(T,Angle,Result);
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
+procedure TFontManager.DoMakeString(Text: Array of cardinal; angle:real; ABitmaps : TBaseStringBitmaps);
|
|
|
+
|
|
|
var g : PMgrGlyph;
|
|
|
bm : PFT_BitmapGlyph;
|
|
|
gl : PFT_Glyph;
|
|
|
- prevIndex, prevx, c, r, rx : integer;
|
|
|
+ prevIndex, prevx, r, rx : integer;
|
|
|
pre, adv, pos, kern : FT_Vector;
|
|
|
buf : PByteArray;
|
|
|
reverse : boolean;
|
|
@@ -582,19 +639,15 @@ var g : PMgrGlyph;
|
|
|
FBM : PFontBitmap;
|
|
|
|
|
|
begin
|
|
|
- CurFont := GetFont(FontID);
|
|
|
if (Angle = 0) or // no angle asked, or can't work with angles (not scalable)
|
|
|
((CurFont.Font^.face_flags and FT_FACE_FLAG_SCALABLE)=0) then
|
|
|
- result := MakeString (FontID, Text, Size)
|
|
|
+ DoMakeString (Text, ABitmaps)
|
|
|
else
|
|
|
begin
|
|
|
- InitMakeString (FontID, Size);
|
|
|
- c := length(text);
|
|
|
- result := TStringBitmaps.Create(c);
|
|
|
if (CurRenderMode = FT_RENDER_MODE_MONO) then
|
|
|
- result.FMode := btBlackWhite
|
|
|
+ ABitmaps.FMode := btBlackWhite
|
|
|
else
|
|
|
- result.FMode := bt256Gray;
|
|
|
+ ABitmaps.FMode := bt256Gray;
|
|
|
MakeTransformation (angle, trans);
|
|
|
prevIndex := 0;
|
|
|
prevx := 0;
|
|
@@ -602,10 +655,10 @@ begin
|
|
|
pos.y := 0;
|
|
|
pre.x := 0;
|
|
|
pre.y := 0;
|
|
|
- for r := 0 to c-1 do
|
|
|
+ for r := 0 to Length(Text)-1 do
|
|
|
begin
|
|
|
// retrieve loaded glyph
|
|
|
- g := GetGlyph (Text[r+1]);
|
|
|
+ g := GetGlyph (Text[r]);
|
|
|
// check kerning
|
|
|
if UseKerning and (g^.glyphindex <>0) and (PrevIndex <> 0) then
|
|
|
begin
|
|
@@ -625,7 +678,7 @@ begin
|
|
|
FTCheck(FT_Glyph_To_Bitmap (gl, CurRenderMode, nil, true),sErrMakingString4);
|
|
|
// Copy what is needed to record
|
|
|
bm := PFT_BitmapGlyph(gl);
|
|
|
- FBM:=result.Bitmaps[r];
|
|
|
+ FBM:=ABitmaps.Bitmaps[r];
|
|
|
with FBM^ do
|
|
|
begin
|
|
|
with gl^.advance do
|
|
@@ -675,36 +728,68 @@ begin
|
|
|
// finish rendered glyph
|
|
|
FT_Done_Glyph (gl);
|
|
|
end;
|
|
|
- result.FText := Text;
|
|
|
- result.CalculateGlobals;
|
|
|
+ ABitmaps.CalculateGlobals;
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
function TFontManager.MakeString (FontId:integer; Text:string; Size:integer) : TStringBitmaps;
|
|
|
+
|
|
|
+Var
|
|
|
+ T : Array of Cardinal;
|
|
|
+ C,I : Integer;
|
|
|
+
|
|
|
+begin
|
|
|
+ CurFont := GetFont(FontID);
|
|
|
+ InitMakeString (FontID, Size);
|
|
|
+ c := length(text);
|
|
|
+ result := TStringBitmaps.Create(c);
|
|
|
+ result.FText := Text;
|
|
|
+ SetLength(T,Length(Text));
|
|
|
+ For I:=1 to Length(Text) do
|
|
|
+ T[I-1]:=Ord(Text[i]);
|
|
|
+ DoMakeString(T,Result);
|
|
|
+end;
|
|
|
+
|
|
|
+function TFontManager.MakeString (FontId:integer; Text:Unicodestring; Size:integer) : TUnicodeStringBitmaps;
|
|
|
+
|
|
|
+Var
|
|
|
+ T : Array of Cardinal;
|
|
|
+ C,I : Integer;
|
|
|
+
|
|
|
+begin
|
|
|
+ CurFont := GetFont(FontID);
|
|
|
+ InitMakeString (FontID, Size);
|
|
|
+ c := length(text);
|
|
|
+ result := TUnicodeStringBitmaps.Create(c);
|
|
|
+ result.FText := Text;
|
|
|
+ SetLength(T,C);
|
|
|
+ For I:=1 to C do
|
|
|
+ T[I-1]:=Ord(Text[i]);
|
|
|
+ DoMakeString(T,Result);
|
|
|
+end;
|
|
|
+
|
|
|
+Procedure TFontManager.DoMakeString (Text : Array of cardinal; ABitmaps : TBaseStringBitmaps);
|
|
|
+
|
|
|
var g : PMgrGlyph;
|
|
|
bm : PFT_BitmapGlyph;
|
|
|
gl : PFT_Glyph;
|
|
|
- e, prevIndex, prevx, c, r, rx : integer;
|
|
|
+ e, prevIndex, prevx, r, rx : integer;
|
|
|
pos, kern : FT_Vector;
|
|
|
buf : PByteArray;
|
|
|
reverse : boolean;
|
|
|
begin
|
|
|
- CurFont := GetFont(FontID);
|
|
|
- InitMakeString (FontID, Size);
|
|
|
- c := length(text);
|
|
|
- result := TStringBitmaps.Create(c);
|
|
|
if (CurRenderMode = FT_RENDER_MODE_MONO) then
|
|
|
- result.FMode := btBlackWhite
|
|
|
+ ABitmaps.FMode := btBlackWhite
|
|
|
else
|
|
|
- result.FMode := bt256Gray;
|
|
|
+ ABitmaps.FMode := bt256Gray;
|
|
|
prevIndex := 0;
|
|
|
prevx := 0;
|
|
|
pos.x := 0;
|
|
|
pos.y := 0;
|
|
|
- for r := 0 to c-1 do
|
|
|
+ for r := 0 to length(text)-1 do
|
|
|
begin
|
|
|
// retrieve loaded glyph
|
|
|
- g := GetGlyph (Text[r+1]);
|
|
|
+ g := GetGlyph (Text[r]);
|
|
|
// check kerning
|
|
|
if UseKerning and (g^.glyphindex <>0) and (PrevIndex <> 0) then
|
|
|
begin
|
|
@@ -719,7 +804,7 @@ begin
|
|
|
FTCheck(FT_Glyph_To_Bitmap (gl, CurRenderMode, @pos, true),sErrMakingString4);
|
|
|
// Copy what is needed to record
|
|
|
bm := PFT_BitmapGlyph(gl);
|
|
|
- with result.Bitmaps[r]^ do
|
|
|
+ with ABitmaps.Bitmaps[r]^ do
|
|
|
begin
|
|
|
with gl^.advance do
|
|
|
begin
|
|
@@ -761,8 +846,7 @@ begin
|
|
|
// finish rendered glyph
|
|
|
FT_Done_Glyph (gl);
|
|
|
end;
|
|
|
- result.FText := Text;
|
|
|
- result.CalculateGlobals;
|
|
|
+ ABitmaps.CalculateGlobals;
|
|
|
end;
|
|
|
|
|
|
function TFontManager.GetString (FontId:integer; Text:string; size:integer; angle:real) : TStringBitmaps;
|
|
@@ -795,6 +879,36 @@ begin
|
|
|
result := MakeString (FontID, text, Size);
|
|
|
end;
|
|
|
|
|
|
+function TFontManager.GetString (FontId:integer; Text:Unicodestring; size:integer; angle:real) : TUnicodeStringBitmaps;
|
|
|
+// Black and white
|
|
|
+begin
|
|
|
+ CurRenderMode := FT_RENDER_MODE_MONO;
|
|
|
+ result := MakeString (FontID, text, Size, angle);
|
|
|
+end;
|
|
|
+
|
|
|
+function TFontManager.GetStringGray (FontId:integer; Text:Unicodestring; size:integer; angle:real) : TUnicodeStringBitmaps;
|
|
|
+// Anti Aliased gray scale
|
|
|
+begin
|
|
|
+ CurRenderMode := FT_RENDER_MODE_NORMAL;
|
|
|
+ result := MakeString (FontID, text, Size, angle);
|
|
|
+end;
|
|
|
+
|
|
|
+{ Procedures without angle have own implementation to have better speed }
|
|
|
+
|
|
|
+function TFontManager.GetString (FontId:integer; Text:Unicodestring; Size:integer) : TUnicodeStringBitmaps;
|
|
|
+// Black and white, following the direction of the font (left to right, top to bottom, ...)
|
|
|
+begin
|
|
|
+ CurRenderMode := FT_RENDER_MODE_MONO;
|
|
|
+ result := MakeString (FontID, text, Size);
|
|
|
+end;
|
|
|
+
|
|
|
+function TFontManager.GetStringGray (FontId:integer; Text:Unicodestring; Size:integer) : TUnicodeStringBitmaps;
|
|
|
+// Anti Aliased gray scale, following the direction of the font (left to right, top to bottom, ...)
|
|
|
+begin
|
|
|
+ CurRenderMode := FT_RENDER_MODE_NORMAL;
|
|
|
+ result := MakeString (FontID, text, Size);
|
|
|
+end;
|
|
|
+
|
|
|
function TFontManager.RequestFont (afilename:string) : integer;
|
|
|
begin
|
|
|
result := RequestFont (afilename,0);
|
|
@@ -821,17 +935,17 @@ end;
|
|
|
|
|
|
{ TStringBitmaps }
|
|
|
|
|
|
-function TStringBitmaps.GetCount : integer;
|
|
|
+function TBaseStringBitmaps.GetCount : integer;
|
|
|
begin
|
|
|
result := FList.Count;
|
|
|
end;
|
|
|
|
|
|
-function TStringBitmaps.GetBitmap (index:integer) : PFontBitmap;
|
|
|
+function TBaseStringBitmaps.GetBitmap (index:integer) : PFontBitmap;
|
|
|
begin
|
|
|
result := PFontBitmap(FList[index]);
|
|
|
end;
|
|
|
|
|
|
-constructor TStringBitmaps.Create (ACount : integer);
|
|
|
+constructor TBaseStringBitmaps.Create (ACount : integer);
|
|
|
var r : integer;
|
|
|
bm : PFontBitmap;
|
|
|
begin
|
|
@@ -846,7 +960,7 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
-destructor TStringBitmaps.destroy;
|
|
|
+destructor TBaseStringBitmaps.destroy;
|
|
|
var r : integer;
|
|
|
bm : PFontBitmap;
|
|
|
begin
|
|
@@ -868,7 +982,7 @@ begin
|
|
|
end;
|
|
|
*)
|
|
|
|
|
|
-procedure TStringBitmaps.CalculateGlobals;
|
|
|
+procedure TBAseStringBitmaps.CalculateGlobals;
|
|
|
var
|
|
|
l,r : integer;
|
|
|
|
|
@@ -907,7 +1021,7 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
-procedure TStringBitmaps.GetBoundRect (out aRect : TRect);
|
|
|
+procedure TBaseStringBitmaps.GetBoundRect (out aRect : TRect);
|
|
|
begin
|
|
|
aRect := FBounds;
|
|
|
end;
|