From 98d5cc077be76c1633f0078b794f6d40f747cedc Mon Sep 17 00:00:00 2001 From: Moritz Lamprecht Date: Mon, 7 Aug 2023 07:55:41 +0200 Subject: [PATCH] fpvectorial: moved page margins to TvPage --- components/fpvectorial/fpvectorial.pas | 53 +++++++++++-------- components/fpvectorial/odtvectorialwriter.pas | 8 +-- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/components/fpvectorial/fpvectorial.pas b/components/fpvectorial/fpvectorial.pas index cb3931c065..830128985b 100644 --- a/components/fpvectorial/fpvectorial.pas +++ b/components/fpvectorial/fpvectorial.pas @@ -1416,8 +1416,6 @@ type StyleTextSpanBold, StyleTextSpanItalic, StyleTextSpanUnderline: TvStyle; // Reader properties ReaderSettings: TvVectorialReaderSettings; - // Page Margins (in millimeters) - MarginTop, MarginBottom, MarginLeft, MarginRight: Integer; { Base methods } constructor Create; virtual; destructor Destroy; override; @@ -1448,8 +1446,6 @@ type procedure SetDefaultPageFormat(AFormat: TvPageFormat); function AddPage(AUseTopLeftCoords: Boolean = False): TvVectorialPage; function AddTextPageSequence(): TvTextPageSequence; - procedure SetPageMargin(MTop, MBottom, MLeft, MRight: Integer); - procedure SetPageMargin(AValue: Integer); { Style methods } function AddStyle(): TvStyle; function AddListStyle: TvListStyle; @@ -1489,6 +1485,8 @@ type BackgroundColor: TFPColor; AdjustPenColorToBackground: Boolean; RenderInfo: TvRenderInfo; // Prepared by the reader with info on how to draw the page + // Page Margins (in millimeters) + MarginTop, MarginBottom, MarginLeft, MarginRight: Integer; public { Base methods } constructor Create(AOwner: TvVectorialDocument); virtual; @@ -1497,6 +1495,8 @@ type procedure SetPageFormat(AFormat: TvPageFormat); function RealWidth: Double; function RealHeight: Double; + procedure SetPageMargin(MTop, MBottom, MLeft, MRight: Integer); + procedure SetPageMargin(AValue: Integer); { Data reading methods } procedure CalculateDocumentSize; virtual; function GetEntity(ANum: Cardinal): TvEntity; virtual; abstract; @@ -9013,6 +9013,19 @@ begin Result := abs(MaxY - MinY); end; +procedure TvPage.SetPageMargin(MTop, MBottom, MLeft, MRight: Integer); +begin + MarginTop := MTop; + MarginBottom := MBottom; + MarginLeft := MLeft; + MarginRight := MRight; +end; + +procedure TvPage.SetPageMargin(AValue: Integer); +begin + SetPageMargin(AValue, AValue, AValue, AValue); +end; + procedure TvPage.AutoFit(ADest: TFPCustomCanvas; AWidth, AHeight, ARenderHeight: Integer; out ADeltaX, ADeltaY: Integer; out AZoom: Double); var @@ -9187,6 +9200,13 @@ begin Clear(); BackgroundColor := colWhite; RenderInfo.BackgroundColor := colWhite; + + // set default graphic document margin (0mm) + // TODO: apply values + MarginTop := 0; + MarginBottom := 0; + MarginLeft := 0; + MarginRight := 0; end; destructor TvVectorialPage.Destroy; @@ -9950,6 +9970,12 @@ begin Footer := TvRichText.Create(Self); Header := TvRichText.Create(Self); MainText := TvRichText.Create(Self); + + // set default text document margin (20mm) + MarginTop := 20; + MarginBottom := 20; + MarginLeft := 20; + MarginRight := 20; end; destructor TvTextPageSequence.Destroy; @@ -10154,12 +10180,6 @@ begin FListStyles := TFPList.Create; if gDefaultRenderer <> nil then FRenderer := gDefaultRenderer.Create; - - // set default margin (20mm) - MarginTop := 20; - MarginBottom := 20; - MarginLeft := 20; - MarginRight := 20; end; {@@ @@ -10543,19 +10563,6 @@ begin if FCurrentPageIndex < 0 then FCurrentPageIndex := FPages.Count-1; end; -procedure TvVectorialDocument.SetPageMargin(MTop, MBottom, MLeft, MRight: Integer); -begin - MarginTop := MTop; - MarginBottom := MBottom; - MarginLeft := MLeft; - MarginRight := MRight; -end; - -procedure TvVectorialDocument.SetPageMargin(AValue: Integer); -begin - SetPageMargin(AValue, AValue, AValue, AValue); -end; - function TvVectorialDocument.AddStyle: TvStyle; begin Result := TvStyle.Create; diff --git a/components/fpvectorial/odtvectorialwriter.pas b/components/fpvectorial/odtvectorialwriter.pas index ea77e8be90..ee7864f9ea 100644 --- a/components/fpvectorial/odtvectorialwriter.pas +++ b/components/fpvectorial/odtvectorialwriter.pas @@ -1062,10 +1062,10 @@ begin ' fo:page-height="'+FloatToODTText(dHeight)+'mm"'+ ' style:print-orientation="'+sOrientation+'"'+ ' style:num-format="1"' + - ' fo:margin-top="' + IntToStr(AData.MarginTop) + 'mm"' + - ' fo:margin-bottom="' + IntToStr(AData.MarginBottom) + 'mm"' + - ' fo:margin-left="' + IntToStr(AData.MarginLeft) + 'mm"' + - ' fo:margin-right="' + IntToStr(AData.MarginRight) + 'mm"' + + ' fo:margin-top="' + IntToStr(ACurPage.MarginTop) + 'mm"' + + ' fo:margin-bottom="' + IntToStr(ACurPage.MarginBottom) + 'mm"' + + ' fo:margin-left="' + IntToStr(ACurPage.MarginLeft) + 'mm"' + + ' fo:margin-right="' + IntToStr(ACurPage.MarginRight) + 'mm"' + ' style:writing-mode="lr-tb"' + ' style:footnote-max-height="0in">'+ LineEnding;