From fb42932f2e3d9848976c2b693ef6d72d3d683397 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 2 Apr 2024 20:23:37 +0000 Subject: [PATCH] LazMapViewer: Improved text rendering by IntfGraphicsDrawingEngine git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9309 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../lazmapviewer/examples/fulldemo/main.lfm | 13 ++--- .../lazmapviewer/examples/fulldemo/main.pas | 3 ++ .../lazmapviewer/source/mvde_intfgraphics.pas | 54 ++----------------- 3 files changed, 13 insertions(+), 57 deletions(-) diff --git a/components/lazmapviewer/examples/fulldemo/main.lfm b/components/lazmapviewer/examples/fulldemo/main.lfm index 5387de3a6..3a8ef8a70 100644 --- a/components/lazmapviewer/examples/fulldemo/main.lfm +++ b/components/lazmapviewer/examples/fulldemo/main.lfm @@ -448,13 +448,14 @@ object MainForm: TMainForm AnchorSideRight.Control = GbSearch AnchorSideRight.Side = asrBottom Left = 4 - Height = 70 + Height = 92 Top = 364 Width = 259 Anchors = [akTop, akLeft, akRight] + AutoSize = True BorderSpacing.Top = 6 Caption = 'GPS points' - ClientHeight = 50 + ClientHeight = 72 ClientWidth = 255 TabOrder = 6 object BtnGPSPoints: TButton @@ -498,7 +499,7 @@ object MainForm: TMainForm AnchorSideBottom.Control = GbGPS AnchorSideBottom.Side = asrBottom Left = 6 - Height = 0 + Height = 15 Top = 57 Width = 245 Anchors = [akTop, akLeft, akRight, akBottom] @@ -516,7 +517,7 @@ object MainForm: TMainForm AnchorSideTop.Side = asrBottom Left = 4 Height = 25 - Top = 440 + Top = 462 Width = 110 AutoSize = True BorderSpacing.Top = 6 @@ -530,7 +531,7 @@ object MainForm: TMainForm AnchorSideTop.Control = BtnSaveToFile Left = 120 Height = 25 - Top = 440 + Top = 462 Width = 105 AutoSize = True BorderSpacing.Left = 6 @@ -546,7 +547,7 @@ object MainForm: TMainForm AnchorSideRight.Side = asrBottom Left = 4 Height = 26 - Top = 471 + Top = 493 Width = 110 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 6 diff --git a/components/lazmapviewer/examples/fulldemo/main.pas b/components/lazmapviewer/examples/fulldemo/main.pas index 5c4334cdc..c886ff4bc 100644 --- a/components/lazmapviewer/examples/fulldemo/main.pas +++ b/components/lazmapviewer/examples/fulldemo/main.pas @@ -364,7 +364,10 @@ procedure TMainForm.BtnPOITextFontClick(Sender: TObject); begin FontDialog.Font.Assign(MapView.Font); if FontDialog.Execute then + begin MapView.Font.Assign(FontDialog.Font); + MapView.Invalidate; + end; end; procedure TMainForm.cbCyclicViewChange(Sender: TObject); diff --git a/components/lazmapviewer/source/mvde_intfgraphics.pas b/components/lazmapviewer/source/mvde_intfgraphics.pas index 9d2c1d963..f09b6ae13 100644 --- a/components/lazmapviewer/source/mvde_intfgraphics.pas +++ b/components/lazmapviewer/source/mvde_intfgraphics.pas @@ -279,15 +279,6 @@ begin cimg := intfImg.Colors[i, j]; cbuf := FBuffer.Colors[iX, jY]; FBuffer.Colors[iX, jY] := AlphaBlend(cbuf, cimg); - { - alpha := cimg.Alpha / word($FFFF); - if InRange(i + X, 0, FBuffer.Width-1) then begin - cbuf := FBuffer.Colors[i + X, j + Y]; - cbuf.Red := Round(alpha * cimg.Red + (1 - alpha) * cbuf.Red); - cbuf.Green := Round(alpha * cimg.Green + (1 - alpha) * cbuf.Green); - cbuf.Blue := Round(alpha * cimg.Blue + (1 - alpha) * cbuf.Blue); - FBuffer.Colors[i + X, j + Y] := cbuf; - } end; end; end; @@ -328,7 +319,6 @@ begin img := ABitmap.CreateIntfImage; try - img.SetSize(ABitmap.Width, ABitmap.Height); for j := 0 to img.Height - 1 do begin jY := j + Y; @@ -339,15 +329,15 @@ begin if InRange(iX, 0, FBuffer.Width-1) then begin col := img.Colors[i, j]; - col.Alpha := 0; if SameColor(col, trCol) then - col.Alpha := alphaTransparent + col.Alpha := AlphaTransparent else if SameColor(col, opCol) then - col.Alpha := alphaOpaque + col.Alpha := AlphaOpaque else begin gray := CalculateGray(col); + col := opCol; col.Alpha := $FFFF - gray; end; FBuffer.Colors[iX, jY] := AlphaBlend(FBuffer.Colors[iX, jY], col); @@ -683,13 +673,6 @@ procedure TMvIntfGraphicsDrawingEngine.TextOut(X, Y: Integer; const AText: Strin var bmp: TBitmap; ex: TSize; - img: TLazIntfImage; - i, j: Integer; - hb, hm: HBitmap; - c: TColor; - fc, tc: TFPColor; - intens, intens0: Int64; - alpha: Double; R: TRect; txtFlags: Integer = DT_CENTER + DT_WORDBREAK; begin @@ -720,37 +703,6 @@ begin bmp.Canvas.FillRect(R); DrawText(bmp.Canvas.Handle, PChar(AText), Length(AText), R, txtFlags); DrawBitmapOT(X, Y, bmp, FFontColor, bmp.Canvas.Brush.Color); - { - img := bmp.CreateIntfImage; - try - fc := TColorToFPColor(bmp.Canvas.Font.Color); - intens0 := Int64(fc.Red) + fc.Green + fc.Blue; - for j := 0 to img.Height - 1 do - for i := 0 to img.Width - 1 do begin - c := bmp.Canvas.Pixels[i, j]; - tc := TColorToFPColor(c); - if c = bmp.Canvas.Brush.Color then - tc.Alpha := alphaTransparent - else if c = FFontColor then - tc.Alpha := alphaOpaque - else begin - intens := Int64(tc.Red) + tc.Green + tc.Blue; - if intens0 = 0 then - alpha := (3 * alphaopaque - intens) / (3 * alphaOpaque - intens0) - else - alpha := intens / intens0; - tc.Alpha := round(alphaOpaque * alpha); - end; - img.Colors[i, j] := tc; - end; - img.CreateBitmaps(hb, hm); - bmp.Handle := hb; - bmp.MaskHandle := hm; - DrawBitmap(X, Y, bmp, true); - finally - img.Free; - end; - } end; finally bmp.Free;