mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 00:49:18 +02:00
TAChart: Fix legend items being drawn too small on printer
git-svn-id: trunk@47199 -
This commit is contained in:
parent
2f68fa15b1
commit
f11c461743
@ -340,14 +340,17 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLegendItem.Draw(ADrawer: IChartDrawer; const ARect: TRect);
|
procedure TLegendItem.Draw(ADrawer: IChartDrawer; const ARect: TRect);
|
||||||
|
var
|
||||||
|
symTextSpc: Integer;
|
||||||
begin
|
begin
|
||||||
|
symTextSpc := ADrawer.Scale(SYMBOL_TEXT_SPACING);
|
||||||
if ADrawer.GetRightToLeft then
|
if ADrawer.GetRightToLeft then
|
||||||
ADrawer.TextOut.
|
ADrawer.TextOut.
|
||||||
Pos(ARect.Left - SYMBOL_TEXT_SPACING - ADrawer.TextExtent(FText).X, ARect.Top).
|
Pos(ARect.Left - symTextSpc - ADrawer.TextExtent(FText).X, ARect.Top).
|
||||||
Text(FText).Done
|
Text(FText).Done
|
||||||
else
|
else
|
||||||
ADrawer.TextOut.
|
ADrawer.TextOut.
|
||||||
Pos(ARect.Right + SYMBOL_TEXT_SPACING, ARect.Top).Text(FText).Done;
|
Pos(ARect.Right + symTextSpc, ARect.Top).Text(FText).Done;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TLegendItem.HasSymbol: Boolean;
|
function TLegendItem.HasSymbol: Boolean;
|
||||||
@ -435,8 +438,8 @@ begin
|
|||||||
if FPointer = nil then exit;
|
if FPointer = nil then exit;
|
||||||
c := CenterPoint(ARect);
|
c := CenterPoint(ARect);
|
||||||
// Max width slightly narrower then ARect to leave place for the line.
|
// Max width slightly narrower then ARect to leave place for the line.
|
||||||
sz.X := Min(FPointer.HorizSize, (ARect.Right - ARect.Left) div 3);
|
sz.X := Min(ADrawer.Scale(FPointer.HorizSize), (ARect.Right - ARect.Left) div 3);
|
||||||
sz.Y := Min(FPointer.VertSize, (ARect.Bottom - ARect.Top) div 2);
|
sz.Y := Min(ADrawer.Scale(FPointer.VertSize), (ARect.Bottom - ARect.Top) div 2);
|
||||||
FPointer.DrawSize(ADrawer, c, sz, Color);
|
FPointer.DrawSize(ADrawer, c, sz, Color);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -556,9 +559,12 @@ var
|
|||||||
prevFont: TFont = nil;
|
prevFont: TFont = nil;
|
||||||
r: TRect;
|
r: TRect;
|
||||||
isRTL: Boolean;
|
isRTL: Boolean;
|
||||||
|
space, symwid: Integer;
|
||||||
begin
|
begin
|
||||||
isRTL := drawer.GetRightToLeft;
|
isRTL := drawer.GetRightToLeft;
|
||||||
with AData do begin
|
with AData do begin
|
||||||
|
space := FDrawer.Scale(Spacing);
|
||||||
|
symwid := FDrawer.Scale(SymbolWidth);
|
||||||
for i := 0 to FItems.Count - 1 do begin
|
for i := 0 to FItems.Count - 1 do begin
|
||||||
FItems[i].UpdateFont(drawer, prevFont);
|
FItems[i].UpdateFont(drawer, prevFont);
|
||||||
drawer.Brush := BackgroundBrush;
|
drawer.Brush := BackgroundBrush;
|
||||||
@ -574,22 +580,24 @@ var
|
|||||||
end;
|
end;
|
||||||
if isRTL then
|
if isRTL then
|
||||||
r := Bounds(
|
r := Bounds(
|
||||||
FBounds.Right - Spacing - x * (FItemSize.X + Spacing) - SymbolWidth,
|
FBounds.Right - space - x * (FItemSize.X + space) - symwid,
|
||||||
FBounds.Top + Spacing + y * (FItemSize.Y + Spacing),
|
FBounds.Top + space + y * (FItemSize.Y + space),
|
||||||
SymbolWidth, FItemSize.Y)
|
symwid,
|
||||||
|
FItemSize.Y)
|
||||||
else
|
else
|
||||||
r := Bounds(
|
r := Bounds(
|
||||||
FBounds.Left + Spacing + x * (FItemSize.X + Spacing),
|
FBounds.Left + space + x * (FItemSize.X + space),
|
||||||
FBounds.Top + Spacing + y * (FItemSize.Y + Spacing),
|
FBounds.Top + space + y * (FItemSize.Y + space),
|
||||||
SymbolWidth, FItemSize.Y);
|
symwid,
|
||||||
|
FItemSize.Y);
|
||||||
FItems[i].Draw(drawer, r);
|
FItems[i].Draw(drawer, r);
|
||||||
OffsetRect(r, 0, FItemSize.Y + Spacing);
|
OffsetRect(r, 0, FItemSize.Y + space);
|
||||||
end;
|
end;
|
||||||
if GridHorizontal.EffVisible then begin
|
if GridHorizontal.EffVisible then begin
|
||||||
drawer.Pen := GridHorizontal;
|
drawer.Pen := GridHorizontal;
|
||||||
drawer.SetBrushParams(bsClear, clTAColor);
|
drawer.SetBrushParams(bsClear, clTAColor);
|
||||||
for i := 1 to FRowCount - 1 do begin
|
for i := 1 to FRowCount - 1 do begin
|
||||||
y := FBounds.Top + Spacing div 2 + i * (FItemSize.Y + Spacing);
|
y := FBounds.Top + space div 2 + i * (FItemSize.Y + space);
|
||||||
drawer.Line(FBounds.Left, y, FBounds.Right, y);
|
drawer.Line(FBounds.Left, y, FBounds.Right, y);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -597,7 +605,7 @@ var
|
|||||||
drawer.Pen := GridVertical;
|
drawer.Pen := GridVertical;
|
||||||
drawer.SetBrushParams(bsClear, clTAColor);
|
drawer.SetBrushParams(bsClear, clTAColor);
|
||||||
for i := 1 to FColCount - 1 do begin
|
for i := 1 to FColCount - 1 do begin
|
||||||
x := FBounds.Left + Spacing div 2 + i * (FItemSize.X + Spacing);
|
x := FBounds.Left + space div 2 + i * (FItemSize.X + space);
|
||||||
drawer.Line(x, FBounds.Top, x, FBounds.Bottom);
|
drawer.Line(x, FBounds.Top, x, FBounds.Bottom);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -646,11 +654,11 @@ begin
|
|||||||
else
|
else
|
||||||
p := ADrawer.TextExtent(li.Text);
|
p := ADrawer.TextExtent(li.Text);
|
||||||
if li.HasSymbol then
|
if li.HasSymbol then
|
||||||
p.X += SYMBOL_TEXT_SPACING + SymbolWidth;
|
p.X += ADrawer.Scale(SYMBOL_TEXT_SPACING + SymbolWidth);
|
||||||
Result := MaxPoint(p, Result);
|
Result := MaxPoint(p, Result);
|
||||||
end;
|
end;
|
||||||
if FixedItemHeight > 0 then
|
if FixedItemHeight > 0 then
|
||||||
Result.Y := FixedItemHeight;
|
Result.Y := ADrawer.Scale(FixedItemHeight);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TChartLegend.Prepare(
|
procedure TChartLegend.Prepare(
|
||||||
@ -658,21 +666,25 @@ procedure TChartLegend.Prepare(
|
|||||||
var
|
var
|
||||||
x, y: Integer;
|
x, y: Integer;
|
||||||
sidebar, legendSize: TPoint;
|
sidebar, legendSize: TPoint;
|
||||||
|
margX, margY, space: Integer;
|
||||||
begin
|
begin
|
||||||
with AData do begin
|
with AData do begin
|
||||||
|
margX := FDrawer.Scale(MarginX);
|
||||||
|
margY := FDrawer.Scale(MarginY);
|
||||||
|
space := FDrawer.Scale(Spacing);
|
||||||
FColCount := Max(Min(ColumnCount, FItems.Count), 1);
|
FColCount := Max(Min(ColumnCount, FItems.Count), 1);
|
||||||
FRowCount := (FItems.Count - 1) div FColCount + 1;
|
FRowCount := (FItems.Count - 1) div FColCount + 1;
|
||||||
FItemSize := MeasureItem(FDrawer, FItems);
|
FItemSize := MeasureItem(FDrawer, FItems);
|
||||||
legendSize.X := (FItemSize.X + Spacing) * FColCount + Spacing;
|
legendSize.X := (FItemSize.X + space) * FColCount + space;
|
||||||
legendSize.Y := (FItemSize.Y + Spacing) * FRowCount + Spacing;
|
legendSize.Y := (FItemSize.Y + space) * FRowCount + space;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
sidebar.X := 2 * MarginX;
|
sidebar.X := 2 * margX;
|
||||||
with AClipRect do
|
with AClipRect do
|
||||||
legendSize.X := EnsureRange(legendSize.X, 0, Right - Left - sidebar.X);
|
legendSize.X := EnsureRange(legendSize.X, 0, Right - Left - sidebar.X);
|
||||||
sidebar.X += legendSize.X;
|
sidebar.X += legendSize.X;
|
||||||
|
|
||||||
sidebar.Y := 2 * MarginX;
|
sidebar.Y := 2 * margX;
|
||||||
with AClipRect do
|
with AClipRect do
|
||||||
legendSize.Y := EnsureRange(legendSize.Y, 0, Bottom - Top - sidebar.Y);
|
legendSize.Y := EnsureRange(legendSize.Y, 0, Bottom - Top - sidebar.Y);
|
||||||
sidebar.Y += legendSize.Y;
|
sidebar.Y += legendSize.Y;
|
||||||
@ -680,17 +692,17 @@ begin
|
|||||||
// Determine position according to the alignment.
|
// Determine position according to the alignment.
|
||||||
case Alignment of
|
case Alignment of
|
||||||
laTopLeft, laCenterLeft, laBottomLeft:
|
laTopLeft, laCenterLeft, laBottomLeft:
|
||||||
x := AClipRect.Left + MarginX;
|
x := AClipRect.Left + margX;
|
||||||
laTopRight, laCenterRight, laBottomRight:
|
laTopRight, laCenterRight, laBottomRight:
|
||||||
x := AClipRect.Right - legendSize.X - MarginX;
|
x := AClipRect.Right - legendSize.X - margX;
|
||||||
laTopCenter, laBottomCenter:
|
laTopCenter, laBottomCenter:
|
||||||
x := (AClipRect.Right + AClipRect.Left - legendSize.X) div 2;
|
x := (AClipRect.Right + AClipRect.Left - legendSize.X) div 2;
|
||||||
end;
|
end;
|
||||||
case Alignment of
|
case Alignment of
|
||||||
laTopLeft, laTopCenter, laTopRight:
|
laTopLeft, laTopCenter, laTopRight:
|
||||||
y := AClipRect.Top + MarginY;
|
y := AClipRect.Top + margY;
|
||||||
laBottomLeft, laBottomCenter, laBottomRight:
|
laBottomLeft, laBottomCenter, laBottomRight:
|
||||||
y := AClipRect.Bottom - MarginY - legendSize.Y;
|
y := AClipRect.Bottom - margY - legendSize.Y;
|
||||||
laCenterLeft, laCenterRight:
|
laCenterLeft, laCenterRight:
|
||||||
y := (AClipRect.Top + AClipRect.Bottom - legendSize.Y) div 2;
|
y := (AClipRect.Top + AClipRect.Bottom - legendSize.Y) div 2;
|
||||||
end;
|
end;
|
||||||
@ -701,9 +713,9 @@ begin
|
|||||||
laTopRight, laCenterRight, laBottomRight:
|
laTopRight, laCenterRight, laBottomRight:
|
||||||
AClipRect.Right -= sidebar.X;
|
AClipRect.Right -= sidebar.X;
|
||||||
laTopCenter:
|
laTopCenter:
|
||||||
AClipRect.Top += legendSize.Y + 2 * MarginY;
|
AClipRect.Top += legendSize.Y + 2 * margY;
|
||||||
laBottomCenter:
|
laBottomCenter:
|
||||||
AClipRect.Bottom -= legendSize.Y + 2 * MarginY;
|
AClipRect.Bottom -= legendSize.Y + 2 * margY;
|
||||||
end;
|
end;
|
||||||
AData.FBounds := Bounds(x, y, legendSize.X, legendSize.Y);
|
AData.FBounds := Bounds(x, y, legendSize.X, legendSize.Y);
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user