1. self.替换成{self.}

2. 修复table表格绘画失败问题
This commit is contained in:
csh
2024-07-10 16:17:44 +08:00
parent 615f4a5b39
commit d3f9431b26
15 changed files with 276 additions and 269 deletions
+36 -35
View File
@@ -1,18 +1,18 @@
type TSPdfCellRange = class(TSPdfBasicRange)
public
function Create(docx_to_pdf: TSDocxToPdf; pg: PdfPage; components: Components; sect_ware: TSSectWare; tc: Tc; tbl_pr: TblPr);
function Create(docx_to_pdf: TSDocxToPdf; pg: PdfPage; components: TSDocxComponentsWare; sect_ware: TSSectWare; tc: Tc; tbl_pr: TblPr);
function Calc();
function AlignHeight(surplus: real);
function AlignHeight(height: real; surplus: real);
function GetLastPage();
function Do();override;
private
docx_to_pdf_: TSDocxToPdf;
[weakref]docx_to_pdf_: TSDocxToPdf;
page_: PdfPage;
docx_components_: Components;
sect_ware_: TSSectWare;
tc_: Tc;
tbl_pr_: TblPr;
[weakref]docx_components_ware_: TSDocxComponentsWare;
[weakref]sect_ware_: TSSectWare;
[weakref]tc_: Tc;
[weakref]tbl_pr_: TblPr;
region_array_: array of Region; // 单元格可能跨页,所以可能存在多个
end;
@@ -27,46 +27,46 @@ type Region = class
RangeArr: array of TSPdfAbstractRange;
end;
function TSPdfCellRange.Create(docx_to_pdf: TSDocxToPdf; pg: PdfPage; components: Components; sect_ware: TSSectWare; tc: Tc; tbl_pr: TblPr);
function TSPdfCellRange.Create(docx_to_pdf: TSDocxToPdf; pg: PdfPage; components: TSDocxComponentsWare; sect_ware: TSSectWare; tc: Tc; tbl_pr: TblPr);
begin
docx_to_pdf_ := docx_to_pdf;
page_ := pg;
docx_components_ := components;
docx_components_ware_ := components;
sect_ware_ := sect_ware;
tc_ := tc;
tbl_pr_ := tbl_pr;
region_array_ := array();
self.Page := page_;
{self.}Page := page_;
end;
function TSPdfCellRange.Calc();
begin
region := new Region();
region.RectangleRange.EndX := self.StartX;
region.RectangleRange.EndY := self.StartY;
region.RectangleRange.Width := self.Width;
region.RectangleRange.FixedHeight := self.FixedHeight;
region.RectangleRange.EndX := {self.}StartX;
region.RectangleRange.EndY := {self.}StartY;
region.RectangleRange.Width := {self.}Width;
region.RectangleRange.FixedHeight := {self.}FixedHeight;
region.RectangleRange.Page := page_;
region_array_[length(region_array_)] := region;
self.EndX := self.StartX;
self.EndY := self.StartY;
cell_x := self.EndX + tbl_pr_.TblCellMar.Left.W;
cell_y := self.EndY - tbl_pr_.TblCellMar.Top.W;
cell_w := self.Width - tbl_pr_.TblCellMar.Right.W - tbl_pr_.TblCellMar.Left.W;
cell_h := self.FixedHeight;
{self.}EndX := {self.}StartX;
{self.}EndY := {self.}StartY;
cell_x := {self.}EndX + tbl_pr_.TblCellMar.Left.W;
cell_y := {self.}EndY - tbl_pr_.TblCellMar.Top.W;
cell_w := {self.}Width - tbl_pr_.TblCellMar.Right.W - tbl_pr_.TblCellMar.Left.W;
cell_h := {self.}FixedHeight;
elements := tc_.Elements();
for _,element in elements do
begin
range := nil;
if element.LocalName = "p" then
begin
range := new TSPdfParagraphRange(docx_to_pdf_, page_, docx_components_, sect_ware_, element);
range := new TSPdfParagraphRange(docx_to_pdf_, page_, docx_components_ware_, sect_ware_, element);
range.SetExtraStyleId(tbl_pr_.TblStyle.Val);
end
else if element.LocalName = "tbl" then
begin
range := new TSPdfTableRange(docx_to_pdf_, page_, docx_components_, sect_ware_, element);
range := new TSPdfTableRange(docx_to_pdf_, page_, docx_components_ware_, sect_ware_, element);
end
if ifObj(range) then
begin
@@ -76,12 +76,12 @@ begin
range.FixedHeight := cell_h;
range.Calc();
region.RangeArr[length(region.RangeArr)] := range;
self.DynamicHeight += range.DynamicHeight;
{self.}DynamicHeight += range.DynamicHeight;
cell_y -= range.DynamicHeight;
end
end
self.EndY := cell_y;
self.DynamicHeight += tbl_pr_.TblCellMar.Top.W + tbl_pr_.TblCellMar.Bottom.W;
{self.}EndY := cell_y;
{self.}DynamicHeight += tbl_pr_.TblCellMar.Top.W + tbl_pr_.TblCellMar.Bottom.W;
end;
function TSPdfCellRange.Do();override;
@@ -94,16 +94,17 @@ begin
end
end;
function TSPdfCellRange.AlignHeight(surplus: real);
function TSPdfCellRange.AlignHeight(height: real; surplus: real);
begin
region := region_array_[0];
if surplus < 1e-6 then
begin
region.RectangleRange.DynamicHeight := height;
if region.RectangleRange.FixedHeight then region.RectangleRange.DynamicHeight := region.RectangleRange.FixedHeight;
self.EndY := self.StartY - region.RectangleRange.DynamicHeight;
{self.}EndY := {self.}StartY - region.RectangleRange.DynamicHeight;
return;
end
region.RectangleRange.DynamicHeight := self.StartY - sect_ware_.SectPr.PgMar.Bottom;
region.RectangleRange.DynamicHeight := {self.}StartY - sect_ware_.SectPr.PgMar.Bottom;
arr := region.RangeArr;
region.RangeArr := array();
span := sect_ware_.SectPr.PgSz.H - sect_ware_.SectPr.PgMar.Top - sect_ware_.SectPr.PgMar.Bottom;
@@ -112,11 +113,11 @@ begin
begin
page_ := docx_to_pdf_.GetNextPage(page_);
region := new Region();
region.RectangleRange.EndX := self.StartX;
region.RectangleRange.EndY := self.StartY;
region.RectangleRange.Width := self.Width;
region.RectangleRange.EndX := {self.}StartX;
region.RectangleRange.EndY := {self.}StartY;
region.RectangleRange.Width := {self.}Width;
region.RectangleRange.DynamicHeight := span;
region.Page := page_;
region.RectangleRange.Page := page_;
region_array_[length(region_array_)] := region;
surplus -= span;
hash[region.RectangleRange.Page] := region;
@@ -125,14 +126,14 @@ begin
begin
page_ := docx_to_pdf_.GetNextPage(page_);
region := new Region();
region.RectangleRange.EndX := self.StartX;
region.RectangleRange.EndX := {self.}StartX;
region.RectangleRange.EndY := sect_ware_.SectPr.PgSz.H - sect_ware_.SectPr.PgMar.Top;
region.RectangleRange.Width := self.Width;
region.RectangleRange.Width := {self.}Width;
region.RectangleRange.DynamicHeight := surplus;
region.RectangleRange.Page := page_;
region_array_[length(region_array_)] := region;
hash[region.RectangleRange.Page] := region;
self.EndY := region.RectangleRange.EndY - surplus;
{self.}EndY := region.RectangleRange.EndY - surplus;
end
for _,range in arr do
begin
+3 -3
View File
@@ -12,7 +12,7 @@ end;
function TSPdfLineRange.Create(pg: PdfPage);
begin
self.Page := pg;
{self.}Page := pg;
range_array_ := array();
end;
@@ -49,9 +49,9 @@ begin
last := range_array_[length(range_array_)-1];
case jc of
"center":
offset := (self.Width - last.EndX + first.EndX - last.Width) / 2;
offset := ({self.}Width - last.EndX + first.EndX - last.Width) / 2;
"right":
offset := self.Width - last.EndX + first.EndX - last.Width;
offset := {self.}Width - last.EndX + first.EndX - last.Width;
end;
if offset <= 0 then return;
for _,range in range_array_ do
+82 -72
View File
@@ -1,6 +1,6 @@
type TSPdfParagraphRange = class(TSPdfBasicRange)
public
function Create(docx_to_pdf: TSDocxToPdf; pg: PdfPage; components: Components; sect_ware: TSSectWare; paragraph: P);
function Create(docx_to_pdf: TSDocxToPdf; pg: PdfPage; components: TSDocxComponentsWare; sect_ware: TSSectWare; paragraph: P);
function Calc();
function Do();override;
function SetExtraStyleId(style_id: string);
@@ -20,62 +20,72 @@ private
function SplitTextToTextRange(text: string; rpr: RPr);
function RToDrawingRange(r: R; ppr: PPr);
function SetLinesAlignment(ppr: PPr);
function ResetCoordinates(ppr);
function ResetCoordinates(ppr: PPr);
function NewLineRange(): TSPdfLineRange;
private
docx_to_pdf_: TSDocxToPdf;
docx_components_: Components;
sect_ware_: TSSectWare;
paragraph_: P;
extra_style_id_: string;
[weakref]docx_to_pdf_: TSDocxToPdf;
[weakref]docx_components_ware_: TSDocxComponentsWare;
[weakref]sect_ware_: TSSectWare;
[weakref]paragraph_: P;
page_: PdfPage;
extra_style_id_: string;
range_array_: array of TSPdfBasicRange;
line_range_array_: array of TSPdfLineRange;
end;
function TSPdfParagraphRange.Create(docx_to_pdf: TSDocxToPdf; pg: PdfPage; components: Components; sect_ware: TSSectWare; paragraph: P);
function TSPdfParagraphRange.Create(docx_to_pdf: TSDocxToPdf; pg: PdfPage; components: TSDocxComponentsWare; sect_ware: TSSectWare; paragraph: P);
begin
docx_to_pdf_ := docx_to_pdf;
page_ := pg;
docx_components_ := Components;
docx_components_ware_ := components;
sect_ware_ := sect_ware;
paragraph_ := paragraph;
extra_style_id_ := "";
range_array_ := array();
line_range_array_ := array();
self.Page := page_;
{self.}Page := page_;
end;
function TSPdfParagraphRange.Calc(): tableArray;
begin
self.SetPPr(paragraph_.PPr);
self.SetLvlText();
{self.}SetPPr(paragraph_.PPr);
{self.}SetLvlText();
ppr := new PPrUnitDecorator(paragraph_.PPr);
self.ResetCoordinates(ppr);
self.EndX := self.StartX;
self.EndY := self.StartY;
self.CheckAndAddPage(self.EndY, ppr.Spacing.Before);
self.EndY -= ppr.Spacing.Before;
self.DynamicHeight += ppr.Spacing.Before;
{self.}ResetCoordinates(ppr);
{self.}EndX := {self.}StartX;
{self.}EndY := {self.}StartY;
{self.}CheckAndAddPage({self.}EndY, ppr.Spacing.Before);
{self.}EndY -= ppr.Spacing.Before;
{self.}DynamicHeight += ppr.Spacing.Before;
rs := paragraph_.Rs();
if length(rs) = 0 then
begin
line_space := self.GetParagraphLineSpace(ppr.RPr.Sz.Val, ppr.Spacing.Line);
self.DynamicHeight += ppr.Spacing.After + line_space;
self.EndY -= self.DynamicHeight;
line_space := {self.}GetParagraphLineSpace(ppr.RPr.Sz.Val, ppr.Spacing.Line);
{self.}DynamicHeight += ppr.Spacing.After + line_space;
{self.}EndY -= {self.}DynamicHeight;
end
else begin
for _, r in rs do
begin
self.SetRPr(r.RPr, paragraph_.PPr);
{self.}SetRPr(r.RPr, paragraph_.PPr);
if r.Br.Type = "page" then
self.CheckAndAddPage(sect_ware_.SectPr.PgMar.Bottom, 1);
else if ifObj(r.Drawing.XmlNode) then self.RToDrawingRange(r, ppr);
else self.RToTextRange(r, ppr);
{self.}CheckAndAddPage(sect_ware_.SectPr.PgMar.Bottom, 1);
else if ifObj(r.Drawing.XmlNode) then {self.}RToDrawingRange(r, ppr);
else {self.}RToTextRange(r, ppr);
end
end
self.RangesToLines(ppr);
{self.}RangesToLines(ppr);
// hyperlinks := paragraph_.Hyperlinks(); // TOC
// for _,hyperlink in hyperlinks do
// begin
// rs := hyperlink.Rs();
// for _,r in rs do
// begin
// if r.FldChar.FldCharType = "begin" then break;
// {self.}RToTextRange(r, ppr);
// end
// end
end;
function TSPdfParagraphRange.Do();
@@ -92,53 +102,53 @@ end;
function TSPdfParagraphRange.NewLineRange(): TSPdfLineRange;
begin
line_range := new TSPdfLineRange(page_);
line_range.StartX := self.EndX;
line_range.StartY := self.EndY;
line_range.Width := self.Width;
line_range.StartX := {self.}EndX;
line_range.StartY := {self.}EndY;
line_range.Width := {self.}Width;
return line_range;
end;
function TSPdfParagraphRange.RangesToLines(ppr: PPr);
begin
line_range := self.NewLineRange();
line_range := {self.}NewLineRange();
i := 0;
max_size := 0;
max_y := 0;
while i <= length(range_array_)-1 do
begin
range := range_array_[i];
if i = 0 then self.EndX += ppr.Ind.FirstLine;
if i = 0 then {self.}EndX += ppr.Ind.FirstLine;
if range is class(TSPdfTextRange) and range.RPr.Sz.Val > max_size then
max_size := range.RPr.Sz.Val;
if range.DynamicHeight > max_y then max_y := range.DynamicHeight;
line_space := self.GetParagraphLineSpace(max_size, ppr.Spacing.Line);
diff := self.EndY - sect_ware_.SectPr.PgMar.Bottom;
if self.CheckAndAddPage(self.EndY, max(line_space, range.DynamicHeight)) then
self.DynamicHeight += diff;
if_newline := self.EndX + range.Width - self.StartX > self.Width + 1e-6;
if if_newline and range.Width < self.Width then
line_space := {self.}GetParagraphLineSpace(max_size, ppr.Spacing.Line);
diff := {self.}EndY - sect_ware_.SectPr.PgMar.Bottom;
if {self.}CheckAndAddPage({self.}EndY, max(line_space, range.DynamicHeight)) then
{self.}DynamicHeight += diff;
if_newline := {self.}EndX + range.Width - {self.}StartX > {self.}Width + 1e-6;
if if_newline and range.Width < {self.}Width then
begin
offset := line_space > max_y ? (line_space - max_size) / 2 + max_size - max_size / 5 : max_y;
max_value := max(line_space, max_y);
line_range.Page := page_;
line_range.EndY := self.EndY - max_value;
line_range.EndY := {self.}EndY - max_value;
line_range.DynamicHeight := max_value;
line_range.SetAllRangeProp(pg: page_, ey: self.EndY - offset);
line_range.SetAllRangeProp(pg: page_, ey: {self.}EndY - offset);
line_range_array_[length(line_range_array_)] := line_range;
line_range := self.NewLineRange();
line_range := {self.}NewLineRange();
max_size := 0;
max_y := 0;
self.DynamicHeight += max_value;
self.EndY -= max_value;
self.EndX := self.StartX;
{self.}DynamicHeight += max_value;
{self.}EndY -= max_value;
{self.}EndX := {self.}StartX;
// w:hanging
sz := range.RPr.SzCs.Val ? range.RPr.SzCs.Val : range.RPr.Sz.Val ? range.RPr.Sz.Val : docx_to_pdf_.Font.GetDefaultSz();
self.EndX -= ppr.Ind.HangingChars ? ppr.Ind.HangingChars * sz : ppr.Ind.Hanging;
{self.}EndX -= ppr.Ind.HangingChars ? ppr.Ind.HangingChars * sz : ppr.Ind.Hanging;
continue;
end
range.EndX := self.EndX - range.StartX;
self.EndX += range.Width;
range.EndX := {self.}EndX - range.StartX;
{self.}EndX += range.Width;
line_range.AddRange(range);
i++;
if i = length(range_array_) then
@@ -146,15 +156,15 @@ begin
offset := line_space > max_y ? (line_space - max_size) / 2 + max_size - max_size / 5 : max_y;
max_value := max(line_space, max_y) + ppr.Spacing.After;
line_range.Page := page_;
line_range.EndY := self.EndY - max_value;
line_range.EndY := {self.}EndY - max_value;
line_range.DynamicHeight := max_value;
line_range.SetAllRangeProp(pg: page_, ey: self.EndY - offset);
line_range.SetAllRangeProp(pg: page_, ey: {self.}EndY - offset);
line_range_array_[length(line_range_array_)] := line_range;
self.DynamicHeight += max_value;
self.EndY -= max_value;
{self.}DynamicHeight += max_value;
{self.}EndY -= max_value;
end
end
self.SetLinesAlignment(ppr);
{self.}SetLinesAlignment(ppr);
end;
function TSPdfParagraphRange.SetLinesAlignment(ppr: PPr);
@@ -172,7 +182,7 @@ begin
page_ := docx_to_pdf_.GetNextPage(page_);
if ifnil(page_) then page_ := docx_to_pdf_.AddPage(sect_ware_);
point := docx_to_pdf_.GetCurrentPoint();
self.EndY := point.Y;
{self.}EndY := point.Y;
return true;
end
return false;
@@ -194,7 +204,7 @@ function TSPdfParagraphRange.RToTextRange(r: R; ppr: PPr);
begin
rpr := new RPrUnitDecorator(r.RPr);
text := r.T.Text;
if ifString(text) then self.SplitTextToTextRange(text, rpr);
if ifString(text) then {self.}SplitTextToTextRange(text, rpr);
end;
function TSPdfParagraphRange.SplitTextToTextRange(text: string; rpr: RPr);
@@ -202,7 +212,7 @@ begin
pos := 1;
while pos <= length(text) do
begin
num := self.GetUtf8CharLength(text[pos]);
num := {self.}GetUtf8CharLength(text[pos]);
word := text[pos : pos+num-1];
word := utf8ToAnsi(word);
pos += num;
@@ -223,16 +233,16 @@ end;
function TSPdfParagraphRange.RToDrawingRange(r: R; ppr: PPr);
begin
xfrm := new XfrmUnitDecorator(r.Drawing._Inline.Graphic.GraphicData.Pic.SpPr.Xfrm);
rels_adapter := class(TSPdfSingletonKit).GetComponent(docx_components_, "document_rels_adapter");
rels_adapter := docx_components_ware_.GetDocumentRelsAdapter();
id := r.Drawing._Inline.Graphic.GraphicData.Pic.BlipFill.Blip.Embed;
rel := rels_adapter.Id(id);
image_path := "word/" + rel.Target;
image := docx_components_.Zip().Get(image_path);
image := docx_components_ware_.Zip().Get(image_path);
data := image.Data();
image_path := docx_to_pdf_.GetCachePath(image_path);
writeFile(rwBinary(), "", image_path, 0, length(data)-1, data);
image := nil;
case self.GetImageFileType(data) of
case {self.}GetImageFileType(data) of
"png":
image := docx_to_pdf_.GetPdf().LoadPngImageFromFile("", image_path);
"jpg":
@@ -283,23 +293,23 @@ end;
function TSPdfParagraphRange.SetPPr(var ppr: PPr);
begin
new_ppr := new PPr();
styles := class(TSPdfSingletonKit).GetComponent(docx_components_, "styles");
styles := docx_components_ware_.GetStyles();
new_ppr.Copy(styles.DocDefaults.PPrDefault.PPr);
new_ppr.RPr.Copy(styles.DocDefaults.RPrDefault.RPr);
self.SetPPrByStyleId(new_ppr, extra_style_id_);
self.SetPPrByStyleId(new_ppr, ppr.PStyle.Val);
{self.}SetPPrByStyleId(new_ppr, extra_style_id_);
{self.}SetPPrByStyleId(new_ppr, ppr.PStyle.Val);
new_ppr.Copy(ppr);
ppr.Copy(new_ppr);
end;
function TSPdfParagraphRange.SetPPrByStyleId(var ppr: PPr; style_id: string);
begin
styles := class(TSPdfSingletonKit).GetComponent(docx_components_, "styles_adapter");
styles := docx_components_ware_.GetStylesAdapter();
style := styles.StyleId(style_id);
if ifObj(style) then
begin
based_on := style.BasedOn.Val;
self.SetPPrByStyleId(ppr, based_on);
{self.}SetPPrByStyleId(ppr, based_on);
ppr.Copy(style.PPr);
ppr.RPr.Copy(style.RPr);
end
@@ -311,39 +321,39 @@ begin
new_rpr := new RPr();
style_id := rpr.RStyle.Val;
new_rpr.Copy(ppr.RPr);
self.SetRPrByStyleId(new_rpr, style_id);
{self.}SetRPrByStyleId(new_rpr, style_id);
new_rpr.Copy(rpr);
rpr.Copy(new_rpr);
end;
function TSPdfParagraphRange.SetRPrByStyleId(var rpr: RPr; style_id: string);
begin
styles := class(TSPdfSingletonKit).GetComponent(docx_components_, "styles_adapter");
styles := docx_components_ware_.GetStylesAdapter();
style := styles.StyleId(style_id);
if ifObj(style) then
begin
based_on := style.BasedOn.Val;
self.SetRPrByStyleId(rpr, based_on);
{self.}SetRPrByStyleId(rpr, based_on);
rpr.Copy(style.RPr);
end
end;
function TSPdfParagraphRange.SetLvlText();
begin
numbering_ware := class(TSPdfSingletonKit).GetComponent(docx_components_, "numbering_ware");
numbering_ware := docx_components_ware_.GetNumberingWare();
if not ifObj(numbering_ware) then return;
[lvl_text, lvl] := numbering_ware.GetNumberLvl(paragraph_.PPr);
if lvl_text = "" and ifnil(lvl) then return;
self.SetRPr(lvl.RPr, paragraph_.PPr);
{self.}SetRPr(lvl.RPr, paragraph_.PPr);
rpr := new RPrUnitDecorator(lvl.RPr);
self.SplitTextToTextRange(lvl_text, rpr);
{self.}SplitTextToTextRange(lvl_text, rpr);
end;
function TSPdfParagraphRange.ResetCoordinates(ppr);
function TSPdfParagraphRange.ResetCoordinates(ppr: PPr);
begin
// 根据段落的间距确定新的坐标
sz := ppr.RPr.SzCs.Val ? ppr.RPr.SzCs.Val : ppr.RPr.Sz.Val ? ppr.RPr.Sz.Val : docx_to_pdf_.Font.GetDefaultSz();
self.StartX += ppr.Ind.LeftChars ? ppr.Ind.LeftChars * sz : ppr.Ind.Left;
self.Width -= ppr.Ind.LeftChars ? ppr.Ind.LeftChars * sz : ppr.Ind.Left;
self.Width -= ppr.Ind.RightChars ? ppr.Ind.RightChars * sz : ppr.Ind.Right;
{self.}StartX += ppr.Ind.LeftChars ? ppr.Ind.LeftChars * sz : ppr.Ind.Left;
{self.}Width -= ppr.Ind.LeftChars ? ppr.Ind.LeftChars * sz : ppr.Ind.Left;
{self.}Width -= ppr.Ind.RightChars ? ppr.Ind.RightChars * sz : ppr.Ind.Right;
end;
+34 -33
View File
@@ -16,12 +16,12 @@ private
function SetTcPrByStyleId(var tc_pr: TcPr; style_id: string);
private
docx_to_pdf_: TSDocxToPdf;
docx_components_: Components;
sect_ware_: TSSectWare;
table_: Tbl;
range_array_: tableArray;
[weakref]docx_to_pdf_: TSDocxToPdf;
[weakref]docx_components_ware_: Components;
[weakref]sect_ware_: TSSectWare;
[weakref]table_: Tbl;
page_: PdfPage;
[weakref]range_array_: tableArray;
point_: TSPoint;
end;
@@ -29,27 +29,28 @@ function TSPdfTableRange.Create(docx_to_pdf: TSDocxToPdf; pg: PdfPage; component
begin
docx_to_pdf_ := docx_to_pdf;
page_ := pg;
docx_components_ := Components;
docx_components_ware_ := Components;
sect_ware_ := sect_ware;
table_ := table;
range_array_ := array();
self.Page := page_;
{self.}Page := page_;
end;
function TSPdfTableRange.Calc();
begin
self.SetTblPr(table_.TblPr);
// return;
{self.}SetTblPr(table_.TblPr);
tbl_pr := new TblPrUnitDecorator(table_.TblPr);
grid_cols := table_.TblGrid.GridCols();
for i:=0 to length(grid_cols)-1 do
grid_cols[i] := new GridColUnitDecorator(grid_cols[i]);
self.ResetCoordinates(tbl_pr, grid_cols);
self.EndX := self.StartX;
self.EndY := self.StartY;
{self.}ResetCoordinates(tbl_pr, grid_cols);
{self.}EndX := {self.}StartX;
{self.}EndY := {self.}StartY;
// 如果是根据内容自适应,应该计算并调整grid_cols的值
trs := table_.Trs();
for i,tr in trs do
range_array_[i] := self.ProcessTrData(grid_cols, tr, tbl_pr);
range_array_[i] := {self.}ProcessTrData(grid_cols, tr, tbl_pr);
end;
function TSPdfTableRange.Do();
@@ -66,7 +67,7 @@ begin
page_ := docx_to_pdf_.GetNextPage(page_);
if ifnil(page_) then page_ := docx_to_pdf_.AddPage(sect_ware_);
point := docx_to_pdf_.GetCurrentPoint();
self.EndY := point.Y;
{self.}EndY := point.Y;
return true;
end
return false;
@@ -74,18 +75,18 @@ end;
function TSPdfTableRange.ProcessTrData(grid_cols: array of GridCol; tr: Tr; tbl_pr: TblPr): array of TSPdfAbstractRange;
begin
self.SetTrPr(tr.TrPr);
{self.}SetTrPr(tr.TrPr);
tr_pr := new TrPrUnitDecorator(tr.TrPr);
height := tr_pr.TrHeight.Val;
tc_x := self.EndX;
tc_y := self.EndY;
tc_x := {self.}EndX;
tc_y := {self.}EndY;
tc_h := height;
max_height := 0;
cell_range_array := array();
tcs := tr.Tcs();
for i,tc in tcs do
begin
cell_range := new TSPdfCellRange(docx_to_pdf_, page_, docx_components_, sect_ware_, tc, tbl_pr);
cell_range := new TSPdfCellRange(docx_to_pdf_, page_, docx_components_ware_, sect_ware_, tc, tbl_pr);
cell_range.StartX := tc_x;
cell_range.StartY := tc_y;
cell_range.Width := grid_cols[i].W;
@@ -96,11 +97,11 @@ begin
cell_range_array[length(cell_range_array)] := cell_range;
end
if tc_h > max_height then max_height := tc_h;
surplus := max_height - (self.EndY - sect_ware_.SectPr.PgMar.Bottom);
surplus := max_height - ({self.}EndY - sect_ware_.SectPr.PgMar.Bottom);
for _,range in cell_range_array do
begin
range.AlignHeight(surplus);
self.EndY := range.EndY; // 理论上每个range.EndY都是一个值
range.AlignHeight(max_height, surplus);
{self.}EndY := range.EndY; // 理论上每个range.EndY都是一个值
page_ := range.GetLastPage();
end
return cell_range_array;
@@ -111,37 +112,37 @@ begin
total_width := 0;
for _,grid_col in grid_cols do
total_width += grid_col.W;
diff := total_width - self.Width;
diff := total_width - {self.}Width;
case tbl_pr.jc.Val of
"center":
begin
offset := diff/2;
self.StartX -= offset;
{self.}StartX -= offset;
end
"right":
begin
self.StartX -= diff;
{self.}StartX -= diff;
end
end;
self.Width := total_width;
{self.}Width := total_width;
end;
function TSPdfTableRange.SetTblPr(var tbl_pr: TblPr);
begin
new_tbl_pr := new TblPr();
self.SetTblPrByStyleId(new_tbl_pr, tbl_pr.TblStyle.Val);
{self.}SetTblPrByStyleId(new_tbl_pr, tbl_pr.TblStyle.Val);
new_tbl_pr.Copy(tbl_pr);
tbl_pr.Copy(new_tbl_pr);
end;
function TSPdfTableRange.SetTblPrByStyleId(var tbl_pr: TblPr; style_id: string);
begin
styles := class(TSPdfSingletonKit).GetComponent(docx_components_, "styles_adapter");
styles := docx_components_ware_.GetStylesAdapter();
style := styles.StyleId(style_id);
if ifObj(style) then
begin
based_on := style.BasedOn.Val;
self.SetTblPrByStyleId(tbl_pr, based_on);
{self.}SetTblPrByStyleId(tbl_pr, based_on);
tbl_pr.Copy(style.TblPr);
end
end;
@@ -149,19 +150,19 @@ end;
function TSPdfTableRange.SetTrPr(var tr_pr: TrPr);
begin
new_tr_pr := new TrPr();
self.SetTrPrByStyleId(new_tr_pr, table_.TblPr.TblStyle.Val);
{self.}SetTrPrByStyleId(new_tr_pr, table_.TblPr.TblStyle.Val);
new_tr_pr.Copy(tr_pr);
tr_pr.Copy(new_tr_pr);
end;
function TSPdfTableRange.SetTrPrByStyleId(var tr_pr: TrPr; style_id: string);
begin
styles := class(TSPdfSingletonKit).GetComponent(docx_components_, "styles_adapter");
styles := docx_components_ware_.GetStylesAdapter();
style := styles.StyleId(style_id);
if ifObj(style) then
begin
based_on := style.BasedOn.Val;
self.SetTrPrByStyleId(tr_pr, based_on);
{self.}SetTrPrByStyleId(tr_pr, based_on);
tr_pr.Copy(style.TrPr);
end
end;
@@ -169,19 +170,19 @@ end;
function TSPdfTableRange.SetTcPr(var tc_pr: TcPr);
begin
new_tc_pr := new TcPr();
self.SetTcPrByStyleId(new_tc_pr, table_.TblPr.TblStyle.Val);
{self.}SetTcPrByStyleId(new_tc_pr, table_.TblPr.TblStyle.Val);
new_tc_pr.Copy(tc_pr);
tc_pr.Copy(new_tc_pr);
end;
function TSPdfTableRange.SetTcPrByStyleId(var tc_pr: TcPr; style_id: string);
begin
styles := class(TSPdfSingletonKit).GetComponent(docx_components_, "styles_adapter");
styles := docx_components_ware_.GetStylesAdapter();
style := styles.StyleId(style_id);
if ifObj(style) then
begin
based_on := style.BasedOn.Val;
self.SetTcPrByStyleId(tc_pr, based_on);
{self.}SetTcPrByStyleId(tc_pr, based_on);
tc_pr.Copy(style.TcPr);
end
end;
+9
View File
@@ -0,0 +1,9 @@
type TSPdfTocRange = class(TSPdfBasicRange)
public
function Create();
end;
function TSPdfTocRange.Create();
begin
end;
+8 -8
View File
@@ -16,12 +16,12 @@ end;
function TSPdfBasicRange.Create();
begin
self.StartX := 0;
self.StartY := 0;
self.EndX := 0;
self.EndY := 0;
self.Width := 0;
self.FixedHeight := 0;
self.DynamicHeight := 0;
self.Page := nil;
{self.}StartX := 0;
{self.}StartY := 0;
{self.}EndX := 0;
{self.}EndY := 0;
{self.}Width := 0;
{self.}FixedHeight := 0;
{self.}DynamicHeight := 0;
{self.}Page := nil;
end;
+7 -7
View File
@@ -10,19 +10,19 @@ end;
function TSPdfImageRange.Create();
begin
class(TSPdfBasicRange).Create();
self.Image := nil;
{self.}Image := nil;
end;
function TSPdfImageRange.Do();
begin
// println("image = {}, x = {}, y = {}, w = {}, h = {}", self.image, self.endx, self.endy, self.width, self.DynamicHeight);
self.Page.DrawImage(self.Image, self.EndX, self.EndY, self.Width, self.DynamicHeight);
// println("image = {}, x = {}, y = {}, w = {}, h = {}", {self.}image, {self.}endx, {self.}endy, {self.}width, {self.}DynamicHeight);
{self.}Page.DrawImage({self.}Image, {self.}EndX, {self.}EndY, {self.}Width, {self.}DynamicHeight);
if sysparams["_PDF_IMAGE_DEBUG_"] then
begin
self.Page.SetLineWidth(0.1);
self.Page.SetRGBStroke(0.8, 0.8, 0);
self.Page.Rectangle(self.EndX, self.EndY, self.Width, self.DynamicHeight);
self.Page.Stroke();
{self.}Page.SetLineWidth(0.1);
{self.}Page.SetRGBStroke(0.8, 0.8, 0);
{self.}Page.Rectangle({self.}EndX, {self.}EndY, {self.}Width, {self.}DynamicHeight);
{self.}Page.Stroke();
end
end;
+7 -7
View File
@@ -12,11 +12,11 @@ end;
function TSPdfRectangleRange.Do();override;
begin
// self.Page.SetRGBStroke(1.0, 0.0, 0.0);
// println("page = {}, endx = {}, endy = {}, DynamicHeight = {}, Width = {}", self.Page, self.EndX, self.EndY, self.DynamicHeight, self.Width);
self.Page.SetGrayStroke(0.5);
self.Page.SetLineWidth(0.5);
self.Page.Rectangle(self.EndX, self.EndY - self.DynamicHeight, self.Width, self.DynamicHeight);
self.Page.Stroke();
self.Page.SetGrayStroke(0);
// {self.}Page.SetRGBStroke(1.0, 0.0, 0.0);
// println("page = {}, endx = {}, endy = {}, DynamicHeight = {}, Width = {}", {self.}Page, {self.}EndX, {self.}EndY, {self.}DynamicHeight, {self.}Width);
{self.}Page.SetGrayStroke(0.5);
{self.}Page.SetLineWidth(0.5);
{self.}Page.Rectangle({self.}EndX, {self.}EndY - {self.}DynamicHeight, {self.}Width, {self.}DynamicHeight);
{self.}Page.Stroke();
{self.}Page.SetGrayStroke(0);
end;
+15 -15
View File
@@ -13,31 +13,31 @@ end;
function TSPdfTextRange.Create();
begin
class(TSPdfBasicRange).Create();
self.RPr := nil;
self.Text := "";
self.Font := nil;
{self.}RPr := nil;
{self.}Text := "";
{self.}Font := nil;
end;
function TSPdfTextRange.Do();
begin
// println("text = {}, endx = {}, endy = {}, width = {}, page = {}", ansiToUtf8(text), endx, endy, width, page);
[r, g, b] := array(0, 0, 0);
if self.RPr.Color.Val then [r, g, b] := TSColorToolKit.HexToRGB(self.RPr.Color.Val);
self.Page.SetRGBFill(r / 255, g / 255, b / 255);
self.Page.SetFontAndSize(self.Font, self.RPr.Sz.Val);
self.Page.BeginText();
self.Page.TextOut(self.EndX, self.EndY, self.Text);
self.Page.EndText();
self.Page.SetRGBFill(0, 0, 0);
if {self.}RPr.Color.Val then [r, g, b] := TSColorToolKit.HexToRGB({self.}RPr.Color.Val);
{self.}Page.SetRGBFill(r / 255, g / 255, b / 255);
{self.}Page.SetFontAndSize({self.}Font, {self.}RPr.Sz.Val);
{self.}Page.BeginText();
{self.}Page.TextOut({self.}EndX, {self.}EndY, {self.}Text);
{self.}Page.EndText();
{self.}Page.SetRGBFill(0, 0, 0);
if sysparams["_PDF_TEXT_DEBUG_"] then
begin
self.Page.SetLineWidth(0.1);
self.Page.SetRGBStroke(1.0, 0.5, 0.0);
self.Page.MoveTo(0, self.EndY);
self.Page.LineTo(600, self.EndY);
self.Page.Stroke();
{self.}Page.SetLineWidth(0.1);
{self.}Page.SetRGBStroke(1.0, 0.5, 0.0);
{self.}Page.MoveTo(0, {self.}EndY);
{self.}Page.LineTo(600, {self.}EndY);
{self.}Page.Stroke();
end
end;