Forum > BGRABitmap and LazPaint
BGRABitmap - System font
Dibo:
Hi,
How works fonts in bgrabitmap? I want my font has the same typeface and size as the system font, but even when I set height from canvas TextHeight, BGRA font is bigger and looks different (see attached screen). This is my test code:
--- Code: ---procedure TForm1.FormPaint(Sender: TObject);
var b: TBGRABitmap;
begin
b := TBGRABitmap.Create(120,100);
b.FontName := Canvas.Font.Name;
b.FontHeight := Canvas.TextHeight('Test (BGRA)');
b.TextOut(25,25,'Test (BGRA)', BGRABlack);
b.Draw(Self.Canvas,0,0,False);
b.Free;
Canvas.Brush.Style := bsClear;
Canvas.TextOut(25,50,'Test (Canvas)');
end;
--- End code ---
Regards
lainz:
circular say something about using negative font height
also check this, not related to height but font conversion
--- Code: ---procedure AssignFontToBGRA(Source: TFont; Dest: TBGRABitmap);
begin
Dest.FontAntialias := True;
Dest.FontName := Source.Name;
Dest.FontStyle := Source.Style;
Dest.FontOrientation := Source.Orientation;
case Source.Quality of
fqNonAntialiased: Dest.FontQuality := fqSystem;
fqAntialiased: Dest.FontQuality := fqFineAntialiasing;
fqProof: Dest.FontQuality := fqFineClearTypeRGB;
fqDefault, fqDraft, fqCleartype, fqCleartypeNatural: Dest.FontQuality :=
fqSystemClearType;
end;
Dest.FontHeight := Source.Height;
//if (Dest.FontQuality = fqFineAntialiasing) or (Dest.FontQuality =
// fqFineClearTypeRGB) and (Dest.FontHeight = 0) then
// Dest.FontHeight := round(Source.GetTextHeight('QWERTY') * 1.15);
end;
--- End code ---
circular:
If you want to assign TextHeight value, then you should rather use FontFullHeight property. FontHeight is the "em" size.
You can use a negative value in FontHeight to specify the full height.
I recommend to use this :
--- Code: ---b.FontFullHeight := Canvas.TextHeight('Test (BGRA)');
--- End code ---
But you can also write :
--- Code: ---b.FontHeight := -Canvas.TextHeight('Test (BGRA)');
--- End code ---
You should obtain exactly the same "look" by specifying
--- Code: ---b.FontQuality:= fqSystemClearType;
--- End code ---
Dibo:
It's better now but still bigger than canvas font (see attached screen). It's better when I don't copy font name (in bgra is by default "arial", in canvas is "default"). When I copy "default" to TBGRABitmap.Fontname then font is larger than before (second screen)
--- Code: ---procedure TForm1.FormPaint(Sender: TObject);
var b: TBGRABitmap;
begin
b := TBGRABitmap.Create(120,100);
//b.FontName := Canvas.Font.Name;
b.FontHeight := -Canvas.TextHeight('Test TextOut');
b.FontStyle := Canvas.Font.Style;
b.FontQuality := fqSystemClearType;
b.TextOut(25,25,'Test TextOut', BGRABlack);
b.Draw(Self.Canvas,0,0,False);
b.Free;
Canvas.Brush.Style := bsClear;
Canvas.TextOut(25,50,'Test TextOut');
end;
--- End code ---
On the screens: 1 is BGRABitmap, 2 is canvas, 3 is TLabel
circular:
Yes, "default" is not really understood by BGRABitmap. What if you set font name to "Arial" both in the Canvas and in the BGRABitmap ?
Navigation
[0] Message Index
[#] Next page