LazMapViewer: Fix text size issue in BGRABitmap drawing engine. Improved detection of default font name and size.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9322 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
0562f757ef
commit
6faf17d531
@ -347,7 +347,7 @@ end;
|
|||||||
|
|
||||||
procedure TMvBGRADrawingEngine.SetPenColor(AValue: TColor);
|
procedure TMvBGRADrawingEngine.SetPenColor(AValue: TColor);
|
||||||
begin
|
begin
|
||||||
FBuffer.CanvasBGRA.pen.Color := AValue;
|
FBuffer.CanvasBGRA.Pen.Color := AValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMvBGRADrawingEngine.SetPenWidth(AValue: Integer);
|
procedure TMvBGRADrawingEngine.SetPenWidth(AValue: Integer);
|
||||||
@ -356,120 +356,22 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TMvBGRADrawingEngine.TextExtent(const AText: String): TSize;
|
function TMvBGRADrawingEngine.TextExtent(const AText: String): TSize;
|
||||||
var
|
|
||||||
bmp: TBitmap;
|
|
||||||
begin
|
begin
|
||||||
bmp := TBitmap.Create;
|
Result := FBuffer.CanvasBGRA.TextExtent(AText);
|
||||||
try
|
|
||||||
bmp.SetSize(1, 1);
|
|
||||||
bmp.Canvas.Font.Name := FFontName;
|
|
||||||
bmp.Canvas.Font.Size := FFontSize;
|
|
||||||
bmp.Canvas.Font.Style := FFontStyle;
|
|
||||||
Result := bmp.Canvas.TextExtent(AText);
|
|
||||||
finally
|
|
||||||
bmp.Free;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
(*
|
|
||||||
procedure TMvBGRADrawingEngine.TextOut(X, Y: Integer; const AText: String);
|
procedure TMvBGRADrawingEngine.TextOut(X, Y: Integer; const AText: String);
|
||||||
var
|
|
||||||
bmp: TBitmap;
|
|
||||||
ex: TSize;
|
|
||||||
img: TLazIntfImage;
|
|
||||||
brClr: TFPColor;
|
|
||||||
imgClr: TFPColor;
|
|
||||||
i, j: Integer;
|
|
||||||
begin
|
begin
|
||||||
if (AText = '') then
|
if (AText <> '') then
|
||||||
exit;
|
begin
|
||||||
|
FBuffer.CanvasBGRA.Font.Name := FFontName;
|
||||||
bmp := TBitmap.Create;
|
FBuffer.CanvasBGRA.Font.Height := -Round(ScreenInfo.PixelsPerInchY / 72.0 * FFontSize);
|
||||||
try
|
FBuffer.CanvasBGRA.Font.Style := FFontStyle;
|
||||||
bmp.PixelFormat := pf32Bit;
|
FBuffer.CanvasBGRA.Font.Color := FFontColor;
|
||||||
bmp.SetSize(1, 1);
|
FBuffer.CanvasBGRA.Font.Antialiasing := true;
|
||||||
bmp.Canvas.Font.Name := FFontName;
|
FBuffer.CanvasBGRA.TextOut(X, Y, AText);
|
||||||
bmp.Canvas.Font.Size := FFontSize;
|
|
||||||
bmp.Canvas.Font.Style := FFontStyle;
|
|
||||||
bmp.Canvas.Font.Color := FFontColor;
|
|
||||||
ex := bmp.Canvas.TextExtent(AText);
|
|
||||||
bmp.SetSize(ex.CX, ex.CY);
|
|
||||||
bmp.Canvas.Brush.Color := GetBrushColor;
|
|
||||||
if GetBrushStyle = bsClear then
|
|
||||||
bmp.Canvas.Brush.Style := bsSolid
|
|
||||||
else
|
|
||||||
bmp.Canvas.Brush.Style := GetBrushStyle;
|
|
||||||
bmp.Canvas.FillRect(0, 0, bmp.Width, bmp.Height);
|
|
||||||
bmp.Canvas.TextOut(0, 0, AText);
|
|
||||||
img := bmp.CreateIntfImage;
|
|
||||||
try
|
|
||||||
if GetBrushStyle = bsClear then begin
|
|
||||||
brClr := TColorToFPColor(GetBrushColor);
|
|
||||||
for j := 0 to img.Height - 1 do
|
|
||||||
for i := 0 to img.Width - 1 do begin
|
|
||||||
imgClr := img.Colors[i, j];
|
|
||||||
if (imgClr.Red = brClr.Red) and (imgClr.Green = brClr.Green) and (imgClr.Blue = brClr.Blue) then
|
|
||||||
Continue;
|
|
||||||
FBuffer.Canvas.SetColor(X + i, Y + j, FPColorToTColor(imgClr));
|
|
||||||
end;
|
|
||||||
end else
|
|
||||||
for j := 0 to img.Height - 1 do
|
|
||||||
for i := 0 to img.Width - 1 do
|
|
||||||
FBuffer.Canvas.SetColor(X + i, Y + j, FPColorToTColor(img.Colors[i, j]));
|
|
||||||
finally
|
|
||||||
img.Free;
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
bmp.Free;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
*)
|
|
||||||
|
|
||||||
procedure TMvBGRADrawingEngine.TextOut(X, Y: Integer; const AText: String);
|
|
||||||
var
|
|
||||||
bmp: TBitmap;
|
|
||||||
ex: TSize;
|
|
||||||
begin
|
|
||||||
if (AText = '') then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
FBuffer.CanvasBGRA.Font.Name := FFontName;
|
|
||||||
FBuffer.CanvasBGRA.Font.Height := Round((96.0 / 72.0) * FFontSize);
|
|
||||||
FBuffer.CanvasBGRA.Font.Style := FFontStyle;
|
|
||||||
FBuffer.CanvasBGRA.Font.Color := FFontColor;
|
|
||||||
FBuffer.CanvasBGRA.TextOut(X, Y, AText);
|
|
||||||
|
|
||||||
(*
|
|
||||||
bmp := TBitmap.Create;
|
|
||||||
try
|
|
||||||
bmp.PixelFormat := pf32Bit;
|
|
||||||
bmp.SetSize(1, 1);
|
|
||||||
bmp.Canvas.Font.Name := FFontName;
|
|
||||||
bmp.Canvas.Font.Size := FFontSize;
|
|
||||||
bmp.Canvas.Font.Style := FFontStyle;
|
|
||||||
bmp.Canvas.Font.Color := FFontColor;
|
|
||||||
ex := bmp.Canvas.TextExtent(AText);
|
|
||||||
bmp.SetSize(ex.CX, ex.CY);
|
|
||||||
if GetBrushStyle <> bsClear then begin
|
|
||||||
bmp.Canvas.Brush.Color := GetBrushColor;
|
|
||||||
bmp.Canvas.FillRect(0, 0, bmp.Width, bmp.Height);
|
|
||||||
bmp.Canvas.TextOut(0, 0, AText);
|
|
||||||
DrawBitmap(X, Y, bmp, false);
|
|
||||||
end else
|
|
||||||
begin
|
|
||||||
if FFontColor = clWhite then
|
|
||||||
bmp.Canvas.Brush.Color := clBlack
|
|
||||||
else
|
|
||||||
bmp.Canvas.Brush.Color := clWhite;
|
|
||||||
bmp.Canvas.FillRect(0, 0, bmp.Width, bmp.Height);
|
|
||||||
bmp.Canvas.TextOut(0, 0, AText);
|
|
||||||
DrawBitmapOT(X, Y, bmp, FFontColor, bmp.Canvas.Brush.Color);
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
bmp.Free;
|
|
||||||
end;
|
|
||||||
*)
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TMvBGRADrawingEngine.GetCacheItemClass: TPictureCacheItemClass;
|
function TMvBGRADrawingEngine.GetCacheItemClass: TPictureCacheItemClass;
|
||||||
begin
|
begin
|
||||||
|
@ -2848,15 +2848,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMapView.UpdateFont(Sender: TObject);
|
procedure TMapView.UpdateFont(Sender: TObject);
|
||||||
|
var
|
||||||
|
fd: TFontData;
|
||||||
begin
|
begin
|
||||||
if SameText(FFont.Name, 'default') then
|
fd := GetFontData(FFont.Handle);
|
||||||
DrawingEngine.FontName := Screen.SystemFont.Name
|
DrawingEngine.FontName := fd.Name;
|
||||||
else
|
DrawingEngine.FontSize := abs(round(fd.Height / FFont.PixelsPerInch * 72));
|
||||||
DrawingEngine.FontName := FFont.Name;
|
|
||||||
if FFont.Size = 0 then
|
|
||||||
DrawingEngine.FontSize := Screen.SystemFont.Size
|
|
||||||
else
|
|
||||||
DrawingEngine.FontSize := FFont.Size;
|
|
||||||
DrawingEngine.FontStyle := FFont.Style;
|
DrawingEngine.FontStyle := FFont.Style;
|
||||||
DrawingEngine.FontColor := ColorToRGB(FFont.Color);
|
DrawingEngine.FontColor := ColorToRGB(FFont.Color);
|
||||||
Invalidate;
|
Invalidate;
|
||||||
|
Loading…
Reference in New Issue
Block a user