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:
wp 2016-08-29 15:19:42 +00:00
parent bcead8754c
commit 4544e32da2
4 changed files with 48 additions and 35 deletions

View File

@ -1399,7 +1399,7 @@ type
function GenerateDebugTree(ADestRoutine: TvDebugAddItemProc; APageItem: Pointer): Pointer; override;
end;
TvVectorialReaderFlag = (vrfSVG_UseTopLeftCoords);
TvVectorialReaderFlag = (vrfSVG_UseTopLeftCoords, vrfWMF_UseTopLeftCoords);
TvVectorialReaderFlags = set of TvVectorialReaderFlag;
TvVectorialReaderSettings = record
@ -5853,6 +5853,8 @@ begin
curDimY := IfThen(AMulY < 0,
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;

View File

@ -98,7 +98,7 @@ procedure TvSVGVectorialWriter.ConvertFPVCoordinatesToSVGCoordinates(
const ASrcX, ASrcY: Double; var ADestX, ADestY: double);
begin
ADestX := ASrcX * FLOAT_PIXELS_PER_MILLIMETER;
if APage.HasNaturalRenderPos then
if APage.UseTopLeftCoordinates then
ADestY := ASrcY * FLOAT_PIXELS_PER_MILLIMETER else
ADestY := (APage.Height - ASrcY) * FLOAT_PIXELS_PER_MILLIMETER;
end;

View File

@ -124,9 +124,6 @@ type
procedure ReadFromStream(AStream: TStream; AData: TvVectorialDocument); override;
end;
var
// Settings
gWMFVecReader_UseTopLeftCoords: Boolean = True;
implementation
@ -801,7 +798,7 @@ var
page: TvVectorialPage;
prevX, prevY: Word;
begin
page := AData.AddPage(gWMFVecReader_UseTopLeftCoords);
page := AData.AddPage(vrfWMF_UseTopLeftCoords in Settings.VecReaderFlags);
while AStream.Position < AStream.Size do begin
// Store the stream position where the current record begins
@ -999,31 +996,7 @@ begin
SetLength(params, 0);
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;
const AParams: TParamArray; IsRounded: Boolean);
var
@ -1043,9 +1016,9 @@ begin
rect := TvRectangle.Create(APage);
rect.X := ScaleX(rectRec^.Left);
rect.Y := ScaleY(rectRec^.Bottom); // since the axis goes down bottom and top are interchanged!
rect.CX := ScaleSizeX(rectRec^.Right - rectRec^.Left);
rect.CY := ScaleSizeY(rectRec^.Bottom - rectRec^.Top); // wmf: Top < Bottom!
rect.Y := ScaleY(rectRec^.Top);
rect.CX := ScaleSizeX(abs(rectRec^.Right - rectRec^.Left));
rect.CY := ScaleSizeY(abs(rectRec^.Bottom - rectRec^.Top));
rect.RX := ScaleSizeX(rx);
rect.RY := ScaleSizeY(ry);
rect.Pen := FCurrPen;
@ -1358,7 +1331,13 @@ end;
Coordinates will be increasing downwards, like in SVG }
function TvWMFVectorialReader.ScaleY(y: Integer): Double;
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);
end;

View File

@ -81,6 +81,7 @@ type
procedure WriteBkColor(AStream: TStream; APage: TvVectorialPage);
procedure WriteBkMode(AStream: TStream; AMode: Word);
procedure WriteBrush(AStream: TStream; ABrush: TvBrush);
procedure WriteCircle(AStream: TStream; ACircle: TvCircle);
procedure WriteEllipse(AStream: TStream; AEllipse: TvEllipse);
procedure WriteEOF(AStream: TStream);
procedure WriteExtText(AStream: TStream; AText: TvText);
@ -441,6 +442,35 @@ begin
FCurrBrush := ABrush;
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;
AEllipse: TvEllipse);
var
@ -466,6 +496,8 @@ begin
WritePolygon(AStream, TvPolygon(AEntity))
else if AEntity is TvRectangle then
WriteRectangle(AStream, TvRectangle(AEntity))
else if AEntity is TvCircle then
WriteCircle(AStream, TvCircle(AEntity))
else if AEntity is TvEllipse then
WriteEllipse(AStream, TvEllipse(AEntity))
else if AEntity is TvText then
@ -904,7 +936,7 @@ begin
FWMFHeader.MaxRecordSize := 0;
FBBox := Rect(0, 0, 0, 0);
page := AData.GetPageAsVectorial(PAGE_INDEX);
FUseTopLeftCoordinates := page.HasNaturalRenderPos;
FUseTopLeftCoordinates := page.UseTopLeftCoordinates;
// Prepare scaling
PrepareScaling(page);