mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 02:16:14 +02:00
fpvectorial: Add wmf writing support for TvCircle. Fix wmf reading of TvRectangle in case of top/left coordinates.
git-svn-id: trunk@52881 -
This commit is contained in:
parent
bcead8754c
commit
4544e32da2
@ -1399,7 +1399,7 @@ type
|
|||||||
function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; override;
|
function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TvVectorialReaderFlag = (vrfSVG_UseTopLeftCoords);
|
TvVectorialReaderFlag = (vrfSVG_UseTopLeftCoords, vrfWMF_UseTopLeftCoords);
|
||||||
TvVectorialReaderFlags = set of TvVectorialReaderFlag;
|
TvVectorialReaderFlags = set of TvVectorialReaderFlag;
|
||||||
|
|
||||||
TvVectorialReaderSettings = record
|
TvVectorialReaderSettings = record
|
||||||
@ -5853,6 +5853,8 @@ begin
|
|||||||
curDimY := IfThen(AMulY < 0,
|
curDimY := IfThen(AMulY < 0,
|
||||||
curDimY - (lFontSizePx * (1 + LINE_SPACING) * AMulY),
|
curDimY - (lFontSizePx * (1 + LINE_SPACING) * AMulY),
|
||||||
curDimY + (lFontSizePx * (1 + LINE_SPACING) * AMulY));
|
curDimY + (lFontSizePx * (1 + LINE_SPACING) * AMulY));
|
||||||
|
// wp: isn't this the same as
|
||||||
|
// curDimY := curDimY + (lFontSizePx * (1 + LINE_SPACING) * abs(AMulY);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ procedure TvSVGVectorialWriter.ConvertFPVCoordinatesToSVGCoordinates(
|
|||||||
const ASrcX, ASrcY: Double; var ADestX, ADestY: double);
|
const ASrcX, ASrcY: Double; var ADestX, ADestY: double);
|
||||||
begin
|
begin
|
||||||
ADestX := ASrcX * FLOAT_PIXELS_PER_MILLIMETER;
|
ADestX := ASrcX * FLOAT_PIXELS_PER_MILLIMETER;
|
||||||
if APage.HasNaturalRenderPos then
|
if APage.UseTopLeftCoordinates then
|
||||||
ADestY := ASrcY * FLOAT_PIXELS_PER_MILLIMETER else
|
ADestY := ASrcY * FLOAT_PIXELS_PER_MILLIMETER else
|
||||||
ADestY := (APage.Height - ASrcY) * FLOAT_PIXELS_PER_MILLIMETER;
|
ADestY := (APage.Height - ASrcY) * FLOAT_PIXELS_PER_MILLIMETER;
|
||||||
end;
|
end;
|
||||||
|
@ -124,9 +124,6 @@ type
|
|||||||
procedure ReadFromStream(AStream: TStream; AData: TvVectorialDocument); override;
|
procedure ReadFromStream(AStream: TStream; AData: TvVectorialDocument); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
|
||||||
// Settings
|
|
||||||
gWMFVecReader_UseTopLeftCoords: Boolean = True;
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -801,7 +798,7 @@ var
|
|||||||
page: TvVectorialPage;
|
page: TvVectorialPage;
|
||||||
prevX, prevY: Word;
|
prevX, prevY: Word;
|
||||||
begin
|
begin
|
||||||
page := AData.AddPage(gWMFVecReader_UseTopLeftCoords);
|
page := AData.AddPage(vrfWMF_UseTopLeftCoords in Settings.VecReaderFlags);
|
||||||
|
|
||||||
while AStream.Position < AStream.Size do begin
|
while AStream.Position < AStream.Size do begin
|
||||||
// Store the stream position where the current record begins
|
// Store the stream position where the current record begins
|
||||||
@ -999,31 +996,7 @@ begin
|
|||||||
|
|
||||||
SetLength(params, 0);
|
SetLength(params, 0);
|
||||||
end;
|
end;
|
||||||
(*
|
|
||||||
procedure TvWMFVectorialReader.ReadRectangle(APage: TvVectorialPage;
|
|
||||||
const AParams: TParamArray);
|
|
||||||
// To do: not tested, having not test file
|
|
||||||
var
|
|
||||||
rectRec: PWMFRectRecord; // coordinates are SmallInt
|
|
||||||
poly: TvPolygon;
|
|
||||||
pts: array of T3DPoint;
|
|
||||||
begin
|
|
||||||
rectRec := PWMFRectRecord(@AParams[0]);
|
|
||||||
|
|
||||||
SetLength(pts, 5);
|
|
||||||
pts[0] := Make3DPoint(ScaleX(rectRec^.Left), ScaleY(rectRec^.Top));
|
|
||||||
pts[1] := Make3DPoint(ScaleX(rectRec^.Right), ScaleY(rectRec^.Top));
|
|
||||||
pts[2] := Make3DPoint(ScaleX(rectRec^.Right), ScaleY(rectRec^.Bottom));
|
|
||||||
pts[3] := Make3DPoint(ScaleX(rectRec^.Left), ScaleY(rectRec^.Bottom));
|
|
||||||
pts[4] := pts[0];
|
|
||||||
|
|
||||||
poly := TvPolygon.Create(APage);
|
|
||||||
poly.Points := pts;
|
|
||||||
poly.Pen := FCurrPen;
|
|
||||||
poly.Brush := FCurrBrush;
|
|
||||||
APage.AddEntity(poly);
|
|
||||||
end;
|
|
||||||
*)
|
|
||||||
procedure TvWMFVectorialReader.ReadRectangle(APage: TvVectorialPage;
|
procedure TvWMFVectorialReader.ReadRectangle(APage: TvVectorialPage;
|
||||||
const AParams: TParamArray; IsRounded: Boolean);
|
const AParams: TParamArray; IsRounded: Boolean);
|
||||||
var
|
var
|
||||||
@ -1043,9 +1016,9 @@ begin
|
|||||||
|
|
||||||
rect := TvRectangle.Create(APage);
|
rect := TvRectangle.Create(APage);
|
||||||
rect.X := ScaleX(rectRec^.Left);
|
rect.X := ScaleX(rectRec^.Left);
|
||||||
rect.Y := ScaleY(rectRec^.Bottom); // since the axis goes down bottom and top are interchanged!
|
rect.Y := ScaleY(rectRec^.Top);
|
||||||
rect.CX := ScaleSizeX(rectRec^.Right - rectRec^.Left);
|
rect.CX := ScaleSizeX(abs(rectRec^.Right - rectRec^.Left));
|
||||||
rect.CY := ScaleSizeY(rectRec^.Bottom - rectRec^.Top); // wmf: Top < Bottom!
|
rect.CY := ScaleSizeY(abs(rectRec^.Bottom - rectRec^.Top));
|
||||||
rect.RX := ScaleSizeX(rx);
|
rect.RX := ScaleSizeX(rx);
|
||||||
rect.RY := ScaleSizeY(ry);
|
rect.RY := ScaleSizeY(ry);
|
||||||
rect.Pen := FCurrPen;
|
rect.Pen := FCurrPen;
|
||||||
@ -1358,7 +1331,13 @@ end;
|
|||||||
Coordinates will be increasing downwards, like in SVG }
|
Coordinates will be increasing downwards, like in SVG }
|
||||||
function TvWMFVectorialReader.ScaleY(y: Integer): Double;
|
function TvWMFVectorialReader.ScaleY(y: Integer): Double;
|
||||||
begin
|
begin
|
||||||
Result := ScaleSizeY(y - FWindowOrigin.Y); // there is probably an issue with y direction
|
// Result := ScaleSizeY(y - FWindowOrigin.Y); // there is probably an issue with y direction
|
||||||
|
|
||||||
|
if (vrfWMF_UseTopLeftCoords in Settings.VecReaderFlags) then
|
||||||
|
Result := ScaleSizeY(y - FWindowOrigin.Y)
|
||||||
|
else
|
||||||
|
Result := FPageHeight - ScaleSizeY(y);
|
||||||
|
|
||||||
// Result := FPageHeight - ScaleSizeY(y);
|
// Result := FPageHeight - ScaleSizeY(y);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ type
|
|||||||
procedure WriteBkColor(AStream: TStream; APage: TvVectorialPage);
|
procedure WriteBkColor(AStream: TStream; APage: TvVectorialPage);
|
||||||
procedure WriteBkMode(AStream: TStream; AMode: Word);
|
procedure WriteBkMode(AStream: TStream; AMode: Word);
|
||||||
procedure WriteBrush(AStream: TStream; ABrush: TvBrush);
|
procedure WriteBrush(AStream: TStream; ABrush: TvBrush);
|
||||||
|
procedure WriteCircle(AStream: TStream; ACircle: TvCircle);
|
||||||
procedure WriteEllipse(AStream: TStream; AEllipse: TvEllipse);
|
procedure WriteEllipse(AStream: TStream; AEllipse: TvEllipse);
|
||||||
procedure WriteEOF(AStream: TStream);
|
procedure WriteEOF(AStream: TStream);
|
||||||
procedure WriteExtText(AStream: TStream; AText: TvText);
|
procedure WriteExtText(AStream: TStream; AText: TvText);
|
||||||
@ -441,6 +442,35 @@ begin
|
|||||||
FCurrBrush := ABrush;
|
FCurrBrush := ABrush;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TvWMFVectorialWriter.WriteCircle(AStream: TStream;
|
||||||
|
ACircle: TvCircle);
|
||||||
|
var
|
||||||
|
rec: TWMFRectRecord;
|
||||||
|
c, r: TPoint;
|
||||||
|
begin
|
||||||
|
WritePen(AStream, ACircle.Pen);
|
||||||
|
WriteBrush(AStream, ACircle.Brush);
|
||||||
|
c.x := ScaleX(ACircle.X);
|
||||||
|
c.y := ScaleY(ACircle.Y);
|
||||||
|
r.x := ScaleSizeX(ACircle.Radius);
|
||||||
|
r.y := ScaleSizeY(ACircle.Radius);
|
||||||
|
rec.Left := c.x - r.x;
|
||||||
|
rec.Right := c.x + r.x;
|
||||||
|
if FUseTopLeftCoordinates then begin
|
||||||
|
rec.Top := c.y - r.y;
|
||||||
|
rec.Bottom := c.y + r.y;
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
rec.Top := c.y + r.y;
|
||||||
|
reC.Bottom := c.y - r.y;
|
||||||
|
end;
|
||||||
|
UpdateBounds(rec.Left, rec.Top);
|
||||||
|
UpdateBounds(rec.Right, rec.Bottom);
|
||||||
|
|
||||||
|
// WMF record header + parameters
|
||||||
|
WriteWMFRecord(AStream, META_ELLIPSE, rec, SizeOf(TWMFRectRecord));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TvWMFVectorialWriter.WriteEllipse(AStream: TStream;
|
procedure TvWMFVectorialWriter.WriteEllipse(AStream: TStream;
|
||||||
AEllipse: TvEllipse);
|
AEllipse: TvEllipse);
|
||||||
var
|
var
|
||||||
@ -466,6 +496,8 @@ begin
|
|||||||
WritePolygon(AStream, TvPolygon(AEntity))
|
WritePolygon(AStream, TvPolygon(AEntity))
|
||||||
else if AEntity is TvRectangle then
|
else if AEntity is TvRectangle then
|
||||||
WriteRectangle(AStream, TvRectangle(AEntity))
|
WriteRectangle(AStream, TvRectangle(AEntity))
|
||||||
|
else if AEntity is TvCircle then
|
||||||
|
WriteCircle(AStream, TvCircle(AEntity))
|
||||||
else if AEntity is TvEllipse then
|
else if AEntity is TvEllipse then
|
||||||
WriteEllipse(AStream, TvEllipse(AEntity))
|
WriteEllipse(AStream, TvEllipse(AEntity))
|
||||||
else if AEntity is TvText then
|
else if AEntity is TvText then
|
||||||
@ -904,7 +936,7 @@ begin
|
|||||||
FWMFHeader.MaxRecordSize := 0;
|
FWMFHeader.MaxRecordSize := 0;
|
||||||
FBBox := Rect(0, 0, 0, 0);
|
FBBox := Rect(0, 0, 0, 0);
|
||||||
page := AData.GetPageAsVectorial(PAGE_INDEX);
|
page := AData.GetPageAsVectorial(PAGE_INDEX);
|
||||||
FUseTopLeftCoordinates := page.HasNaturalRenderPos;
|
FUseTopLeftCoordinates := page.UseTopLeftCoordinates;
|
||||||
|
|
||||||
// Prepare scaling
|
// Prepare scaling
|
||||||
PrepareScaling(page);
|
PrepareScaling(page);
|
||||||
|
Loading…
Reference in New Issue
Block a user