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

View File

@ -31,7 +31,7 @@ private
private private
pdf_: PdfFile; pdf_: PdfFile;
docx_components_: Components; // Components@DOCX docx_components_: TSDocxComponentsWare; // TSDocxComponentsWare
cache_path_: string; // 临时目录,用来存放临时文件 cache_path_: string; // 临时目录,用来存放临时文件
sect_ware_array_: array of TSSectWare; // 页面布局组件数组 sect_ware_array_: array of TSSectWare; // 页面布局组件数组
font_ware_: TSFontWare; // 字体部件 font_ware_: TSFontWare; // 字体部件
@ -44,10 +44,10 @@ end;
function TSDocxToPdf.Create(alias: string; file: string); function TSDocxToPdf.Create(alias: string; file: string);
begin begin
pdf_ := new PdfFile(); pdf_ := new PdfFile();
self.InitPdfEncoder(); {self.}InitPdfEncoder();
self.InitDocxComponents(alias, file); {self.}InitDocxComponents(alias, file);
self.InitCachePath(file); {self.}InitCachePath(file);
self.InitSectWare(); {self.}InitSectWare();
font_ware_ := new TSFontWare(pdf_); font_ware_ := new TSFontWare(pdf_);
current_page_ := nil; current_page_ := nil;
point_ := new TSPoint(); point_ := new TSPoint();
@ -58,7 +58,6 @@ end;
function TSDocxToPdf.Destroy(); function TSDocxToPdf.Destroy();
begin begin
removeDir("", cache_path_); removeDir("", cache_path_);
class(TSPdfSingletonKit).Release(docx_components_);
end; end;
function TSDocxToPdf.SaveToFile(alias: string; file: string): integer; function TSDocxToPdf.SaveToFile(alias: string; file: string): integer;
@ -73,14 +72,14 @@ begin
begin begin
if prev <> sect_ware then if prev <> sect_ware then
begin begin
self.AddPage(sect_ware); {self.}AddPage(sect_ware);
prev := sect_ware; prev := sect_ware;
end end
elements := sect_ware.Elements; elements := sect_ware.Elements;
for _,element in elements do for _,element in elements do
begin begin
if element.LocalName = "p" then self.TransformP(sect_ware, element); if element.LocalName = "p" then {self.}TransformP(sect_ware, element);
else if element.LocalName = "tbl" then self.TransformTbl(sect_ware, element); else if element.LocalName = "tbl" then {self.}TransformTbl(sect_ware, element);
end end
end end
end; end;
@ -120,7 +119,7 @@ end;
function TSDocxToPdf.InitDocxComponents(alias: string; file: string); function TSDocxToPdf.InitDocxComponents(alias: string; file: string);
begin begin
namespace "DOCX"; namespace "DOCX";
docx_components_ := new Components(); docx_components_ := new TSDocxComponentsWare();
[err, msg] := docx_components_.OpenFile(alias, file, nil); [err, msg] := docx_components_.OpenFile(alias, file, nil);
if err then raise "Create obejct 'TSDocxFile' failed."; if err then raise "Create obejct 'TSDocxFile' failed.";
end; end;
@ -139,7 +138,7 @@ begin
document := docx_components_.Document; document := docx_components_.Document;
document.Deserialize(); document.Deserialize();
sect_ware_array_ := array(); sect_ware_array_ := array();
self.AllocateElementsToSectWare(); {self.}AllocateElementsToSectWare();
end; end;
function TSDocxToPdf.AllocateElementsToSectWare(); function TSDocxToPdf.AllocateElementsToSectWare();
@ -177,14 +176,14 @@ begin
current_page_ := pdf_.AddPage(); current_page_ := pdf_.AddPage();
current_page_.SetWidth(sect_ware.SectPr.PgSz.W); current_page_.SetWidth(sect_ware.SectPr.PgSz.W);
current_page_.SetHeight(sect_ware.SectPr.PgSz.H); current_page_.SetHeight(sect_ware.SectPr.PgSz.H);
self.ResetCoordinates(sect_ware); {self.}ResetCoordinates(sect_ware);
len := length(page_array_); len := length(page_array_);
page_array_[len] := current_page_; page_array_[len] := current_page_;
page_index_[current_page_] := len; page_index_[current_page_] := len;
if sysparams["_PDF_PAGE_GRID_DEBUG_"] then if sysparams["_PDF_PAGE_GRID_DEBUG_"] then
self.PrintGrid(current_page_, sect_ware); {self.}PrintGrid(current_page_, sect_ware);
return current_page_; return current_page_;
end; end;

View File

@ -1,18 +1,18 @@
type TSPdfCellRange = class(TSPdfBasicRange) type TSPdfCellRange = class(TSPdfBasicRange)
public 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 Calc();
function AlignHeight(surplus: real); function AlignHeight(height: real; surplus: real);
function GetLastPage(); function GetLastPage();
function Do();override; function Do();override;
private private
docx_to_pdf_: TSDocxToPdf; [weakref]docx_to_pdf_: TSDocxToPdf;
page_: PdfPage; page_: PdfPage;
docx_components_: Components; [weakref]docx_components_ware_: TSDocxComponentsWare;
sect_ware_: TSSectWare; [weakref]sect_ware_: TSSectWare;
tc_: Tc; [weakref]tc_: Tc;
tbl_pr_: TblPr; [weakref]tbl_pr_: TblPr;
region_array_: array of Region; // 单元格可能跨页,所以可能存在多个 region_array_: array of Region; // 单元格可能跨页,所以可能存在多个
end; end;
@ -27,46 +27,46 @@ type Region = class
RangeArr: array of TSPdfAbstractRange; RangeArr: array of TSPdfAbstractRange;
end; 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 begin
docx_to_pdf_ := docx_to_pdf; docx_to_pdf_ := docx_to_pdf;
page_ := pg; page_ := pg;
docx_components_ := components; docx_components_ware_ := components;
sect_ware_ := sect_ware; sect_ware_ := sect_ware;
tc_ := tc; tc_ := tc;
tbl_pr_ := tbl_pr; tbl_pr_ := tbl_pr;
region_array_ := array(); region_array_ := array();
self.Page := page_; {self.}Page := page_;
end; end;
function TSPdfCellRange.Calc(); function TSPdfCellRange.Calc();
begin begin
region := new Region(); region := new Region();
region.RectangleRange.EndX := self.StartX; region.RectangleRange.EndX := {self.}StartX;
region.RectangleRange.EndY := self.StartY; region.RectangleRange.EndY := {self.}StartY;
region.RectangleRange.Width := self.Width; region.RectangleRange.Width := {self.}Width;
region.RectangleRange.FixedHeight := self.FixedHeight; region.RectangleRange.FixedHeight := {self.}FixedHeight;
region.RectangleRange.Page := page_; region.RectangleRange.Page := page_;
region_array_[length(region_array_)] := region; region_array_[length(region_array_)] := region;
self.EndX := self.StartX; {self.}EndX := {self.}StartX;
self.EndY := self.StartY; {self.}EndY := {self.}StartY;
cell_x := self.EndX + tbl_pr_.TblCellMar.Left.W; cell_x := {self.}EndX + tbl_pr_.TblCellMar.Left.W;
cell_y := self.EndY - tbl_pr_.TblCellMar.Top.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_w := {self.}Width - tbl_pr_.TblCellMar.Right.W - tbl_pr_.TblCellMar.Left.W;
cell_h := self.FixedHeight; cell_h := {self.}FixedHeight;
elements := tc_.Elements(); elements := tc_.Elements();
for _,element in elements do for _,element in elements do
begin begin
range := nil; range := nil;
if element.LocalName = "p" then if element.LocalName = "p" then
begin 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); range.SetExtraStyleId(tbl_pr_.TblStyle.Val);
end end
else if element.LocalName = "tbl" then else if element.LocalName = "tbl" then
begin 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 end
if ifObj(range) then if ifObj(range) then
begin begin
@ -76,12 +76,12 @@ begin
range.FixedHeight := cell_h; range.FixedHeight := cell_h;
range.Calc(); range.Calc();
region.RangeArr[length(region.RangeArr)] := range; region.RangeArr[length(region.RangeArr)] := range;
self.DynamicHeight += range.DynamicHeight; {self.}DynamicHeight += range.DynamicHeight;
cell_y -= range.DynamicHeight; cell_y -= range.DynamicHeight;
end end
end end
self.EndY := cell_y; {self.}EndY := cell_y;
self.DynamicHeight += tbl_pr_.TblCellMar.Top.W + tbl_pr_.TblCellMar.Bottom.W; {self.}DynamicHeight += tbl_pr_.TblCellMar.Top.W + tbl_pr_.TblCellMar.Bottom.W;
end; end;
function TSPdfCellRange.Do();override; function TSPdfCellRange.Do();override;
@ -94,16 +94,17 @@ begin
end end
end; end;
function TSPdfCellRange.AlignHeight(surplus: real); function TSPdfCellRange.AlignHeight(height: real; surplus: real);
begin begin
region := region_array_[0]; region := region_array_[0];
if surplus < 1e-6 then if surplus < 1e-6 then
begin begin
region.RectangleRange.DynamicHeight := height;
if region.RectangleRange.FixedHeight then region.RectangleRange.DynamicHeight := region.RectangleRange.FixedHeight; 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; return;
end end
region.RectangleRange.DynamicHeight := self.StartY - sect_ware_.SectPr.PgMar.Bottom; region.RectangleRange.DynamicHeight := {self.}StartY - sect_ware_.SectPr.PgMar.Bottom;
arr := region.RangeArr; arr := region.RangeArr;
region.RangeArr := array(); region.RangeArr := array();
span := sect_ware_.SectPr.PgSz.H - sect_ware_.SectPr.PgMar.Top - sect_ware_.SectPr.PgMar.Bottom; span := sect_ware_.SectPr.PgSz.H - sect_ware_.SectPr.PgMar.Top - sect_ware_.SectPr.PgMar.Bottom;
@ -112,11 +113,11 @@ begin
begin begin
page_ := docx_to_pdf_.GetNextPage(page_); page_ := docx_to_pdf_.GetNextPage(page_);
region := new Region(); region := new Region();
region.RectangleRange.EndX := self.StartX; region.RectangleRange.EndX := {self.}StartX;
region.RectangleRange.EndY := self.StartY; region.RectangleRange.EndY := {self.}StartY;
region.RectangleRange.Width := self.Width; region.RectangleRange.Width := {self.}Width;
region.RectangleRange.DynamicHeight := span; region.RectangleRange.DynamicHeight := span;
region.Page := page_; region.RectangleRange.Page := page_;
region_array_[length(region_array_)] := region; region_array_[length(region_array_)] := region;
surplus -= span; surplus -= span;
hash[region.RectangleRange.Page] := region; hash[region.RectangleRange.Page] := region;
@ -125,14 +126,14 @@ begin
begin begin
page_ := docx_to_pdf_.GetNextPage(page_); page_ := docx_to_pdf_.GetNextPage(page_);
region := new Region(); 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.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.DynamicHeight := surplus;
region.RectangleRange.Page := page_; region.RectangleRange.Page := page_;
region_array_[length(region_array_)] := region; region_array_[length(region_array_)] := region;
hash[region.RectangleRange.Page] := region; hash[region.RectangleRange.Page] := region;
self.EndY := region.RectangleRange.EndY - surplus; {self.}EndY := region.RectangleRange.EndY - surplus;
end end
for _,range in arr do for _,range in arr do
begin begin

View File

@ -12,7 +12,7 @@ end;
function TSPdfLineRange.Create(pg: PdfPage); function TSPdfLineRange.Create(pg: PdfPage);
begin begin
self.Page := pg; {self.}Page := pg;
range_array_ := array(); range_array_ := array();
end; end;
@ -49,9 +49,9 @@ begin
last := range_array_[length(range_array_)-1]; last := range_array_[length(range_array_)-1];
case jc of case jc of
"center": "center":
offset := (self.Width - last.EndX + first.EndX - last.Width) / 2; offset := ({self.}Width - last.EndX + first.EndX - last.Width) / 2;
"right": "right":
offset := self.Width - last.EndX + first.EndX - last.Width; offset := {self.}Width - last.EndX + first.EndX - last.Width;
end; end;
if offset <= 0 then return; if offset <= 0 then return;
for _,range in range_array_ do for _,range in range_array_ do

View File

@ -1,6 +1,6 @@
type TSPdfParagraphRange = class(TSPdfBasicRange) type TSPdfParagraphRange = class(TSPdfBasicRange)
public 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 Calc();
function Do();override; function Do();override;
function SetExtraStyleId(style_id: string); function SetExtraStyleId(style_id: string);
@ -20,62 +20,72 @@ private
function SplitTextToTextRange(text: string; rpr: RPr); function SplitTextToTextRange(text: string; rpr: RPr);
function RToDrawingRange(r: R; ppr: PPr); function RToDrawingRange(r: R; ppr: PPr);
function SetLinesAlignment(ppr: PPr); function SetLinesAlignment(ppr: PPr);
function ResetCoordinates(ppr); function ResetCoordinates(ppr: PPr);
function NewLineRange(): TSPdfLineRange; function NewLineRange(): TSPdfLineRange;
private private
docx_to_pdf_: TSDocxToPdf; [weakref]docx_to_pdf_: TSDocxToPdf;
docx_components_: Components; [weakref]docx_components_ware_: TSDocxComponentsWare;
sect_ware_: TSSectWare; [weakref]sect_ware_: TSSectWare;
paragraph_: P; [weakref]paragraph_: P;
extra_style_id_: string;
page_: PdfPage; page_: PdfPage;
extra_style_id_: string;
range_array_: array of TSPdfBasicRange; range_array_: array of TSPdfBasicRange;
line_range_array_: array of TSPdfLineRange; line_range_array_: array of TSPdfLineRange;
end; 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 begin
docx_to_pdf_ := docx_to_pdf; docx_to_pdf_ := docx_to_pdf;
page_ := pg; page_ := pg;
docx_components_ := Components; docx_components_ware_ := components;
sect_ware_ := sect_ware; sect_ware_ := sect_ware;
paragraph_ := paragraph; paragraph_ := paragraph;
extra_style_id_ := ""; extra_style_id_ := "";
range_array_ := array(); range_array_ := array();
line_range_array_ := array(); line_range_array_ := array();
self.Page := page_; {self.}Page := page_;
end; end;
function TSPdfParagraphRange.Calc(): tableArray; function TSPdfParagraphRange.Calc(): tableArray;
begin begin
self.SetPPr(paragraph_.PPr); {self.}SetPPr(paragraph_.PPr);
self.SetLvlText(); {self.}SetLvlText();
ppr := new PPrUnitDecorator(paragraph_.PPr); ppr := new PPrUnitDecorator(paragraph_.PPr);
self.ResetCoordinates(ppr); {self.}ResetCoordinates(ppr);
self.EndX := self.StartX; {self.}EndX := {self.}StartX;
self.EndY := self.StartY; {self.}EndY := {self.}StartY;
self.CheckAndAddPage(self.EndY, ppr.Spacing.Before); {self.}CheckAndAddPage({self.}EndY, ppr.Spacing.Before);
self.EndY -= ppr.Spacing.Before; {self.}EndY -= ppr.Spacing.Before;
self.DynamicHeight += ppr.Spacing.Before; {self.}DynamicHeight += ppr.Spacing.Before;
rs := paragraph_.Rs(); rs := paragraph_.Rs();
if length(rs) = 0 then if length(rs) = 0 then
begin begin
line_space := self.GetParagraphLineSpace(ppr.RPr.Sz.Val, ppr.Spacing.Line); line_space := {self.}GetParagraphLineSpace(ppr.RPr.Sz.Val, ppr.Spacing.Line);
self.DynamicHeight += ppr.Spacing.After + line_space; {self.}DynamicHeight += ppr.Spacing.After + line_space;
self.EndY -= self.DynamicHeight; {self.}EndY -= {self.}DynamicHeight;
end end
else begin else begin
for _, r in rs do for _, r in rs do
begin begin
self.SetRPr(r.RPr, paragraph_.PPr); {self.}SetRPr(r.RPr, paragraph_.PPr);
if r.Br.Type = "page" then if r.Br.Type = "page" then
self.CheckAndAddPage(sect_ware_.SectPr.PgMar.Bottom, 1); {self.}CheckAndAddPage(sect_ware_.SectPr.PgMar.Bottom, 1);
else if ifObj(r.Drawing.XmlNode) then self.RToDrawingRange(r, ppr); else if ifObj(r.Drawing.XmlNode) then {self.}RToDrawingRange(r, ppr);
else self.RToTextRange(r, ppr); else {self.}RToTextRange(r, ppr);
end end
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; end;
function TSPdfParagraphRange.Do(); function TSPdfParagraphRange.Do();
@ -92,53 +102,53 @@ end;
function TSPdfParagraphRange.NewLineRange(): TSPdfLineRange; function TSPdfParagraphRange.NewLineRange(): TSPdfLineRange;
begin begin
line_range := new TSPdfLineRange(page_); line_range := new TSPdfLineRange(page_);
line_range.StartX := self.EndX; line_range.StartX := {self.}EndX;
line_range.StartY := self.EndY; line_range.StartY := {self.}EndY;
line_range.Width := self.Width; line_range.Width := {self.}Width;
return line_range; return line_range;
end; end;
function TSPdfParagraphRange.RangesToLines(ppr: PPr); function TSPdfParagraphRange.RangesToLines(ppr: PPr);
begin begin
line_range := self.NewLineRange(); line_range := {self.}NewLineRange();
i := 0; i := 0;
max_size := 0; max_size := 0;
max_y := 0; max_y := 0;
while i <= length(range_array_)-1 do while i <= length(range_array_)-1 do
begin begin
range := range_array_[i]; 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 if range is class(TSPdfTextRange) and range.RPr.Sz.Val > max_size then
max_size := range.RPr.Sz.Val; max_size := range.RPr.Sz.Val;
if range.DynamicHeight > max_y then max_y := range.DynamicHeight; if range.DynamicHeight > max_y then max_y := range.DynamicHeight;
line_space := self.GetParagraphLineSpace(max_size, ppr.Spacing.Line); line_space := {self.}GetParagraphLineSpace(max_size, ppr.Spacing.Line);
diff := self.EndY - sect_ware_.SectPr.PgMar.Bottom; diff := {self.}EndY - sect_ware_.SectPr.PgMar.Bottom;
if self.CheckAndAddPage(self.EndY, max(line_space, range.DynamicHeight)) then if {self.}CheckAndAddPage({self.}EndY, max(line_space, range.DynamicHeight)) then
self.DynamicHeight += diff; {self.}DynamicHeight += diff;
if_newline := self.EndX + range.Width - self.StartX > self.Width + 1e-6; if_newline := {self.}EndX + range.Width - {self.}StartX > {self.}Width + 1e-6;
if if_newline and range.Width < self.Width then if if_newline and range.Width < {self.}Width then
begin begin
offset := line_space > max_y ? (line_space - max_size) / 2 + max_size - max_size / 5 : max_y; offset := line_space > max_y ? (line_space - max_size) / 2 + max_size - max_size / 5 : max_y;
max_value := max(line_space, max_y); max_value := max(line_space, max_y);
line_range.Page := page_; 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.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_array_[length(line_range_array_)] := line_range;
line_range := self.NewLineRange(); line_range := {self.}NewLineRange();
max_size := 0; max_size := 0;
max_y := 0; max_y := 0;
self.DynamicHeight += max_value; {self.}DynamicHeight += max_value;
self.EndY -= max_value; {self.}EndY -= max_value;
self.EndX := self.StartX; {self.}EndX := {self.}StartX;
// w:hanging // w:hanging
sz := range.RPr.SzCs.Val ? range.RPr.SzCs.Val : range.RPr.Sz.Val ? range.RPr.Sz.Val : docx_to_pdf_.Font.GetDefaultSz(); 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; continue;
end end
range.EndX := self.EndX - range.StartX; range.EndX := {self.}EndX - range.StartX;
self.EndX += range.Width; {self.}EndX += range.Width;
line_range.AddRange(range); line_range.AddRange(range);
i++; i++;
if i = length(range_array_) then 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; 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; max_value := max(line_space, max_y) + ppr.Spacing.After;
line_range.Page := page_; 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.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_array_[length(line_range_array_)] := line_range;
self.DynamicHeight += max_value; {self.}DynamicHeight += max_value;
self.EndY -= max_value; {self.}EndY -= max_value;
end end
end end
self.SetLinesAlignment(ppr); {self.}SetLinesAlignment(ppr);
end; end;
function TSPdfParagraphRange.SetLinesAlignment(ppr: PPr); function TSPdfParagraphRange.SetLinesAlignment(ppr: PPr);
@ -172,7 +182,7 @@ begin
page_ := docx_to_pdf_.GetNextPage(page_); page_ := docx_to_pdf_.GetNextPage(page_);
if ifnil(page_) then page_ := docx_to_pdf_.AddPage(sect_ware_); if ifnil(page_) then page_ := docx_to_pdf_.AddPage(sect_ware_);
point := docx_to_pdf_.GetCurrentPoint(); point := docx_to_pdf_.GetCurrentPoint();
self.EndY := point.Y; {self.}EndY := point.Y;
return true; return true;
end end
return false; return false;
@ -194,7 +204,7 @@ function TSPdfParagraphRange.RToTextRange(r: R; ppr: PPr);
begin begin
rpr := new RPrUnitDecorator(r.RPr); rpr := new RPrUnitDecorator(r.RPr);
text := r.T.Text; text := r.T.Text;
if ifString(text) then self.SplitTextToTextRange(text, rpr); if ifString(text) then {self.}SplitTextToTextRange(text, rpr);
end; end;
function TSPdfParagraphRange.SplitTextToTextRange(text: string; rpr: RPr); function TSPdfParagraphRange.SplitTextToTextRange(text: string; rpr: RPr);
@ -202,7 +212,7 @@ begin
pos := 1; pos := 1;
while pos <= length(text) do while pos <= length(text) do
begin begin
num := self.GetUtf8CharLength(text[pos]); num := {self.}GetUtf8CharLength(text[pos]);
word := text[pos : pos+num-1]; word := text[pos : pos+num-1];
word := utf8ToAnsi(word); word := utf8ToAnsi(word);
pos += num; pos += num;
@ -223,16 +233,16 @@ end;
function TSPdfParagraphRange.RToDrawingRange(r: R; ppr: PPr); function TSPdfParagraphRange.RToDrawingRange(r: R; ppr: PPr);
begin begin
xfrm := new XfrmUnitDecorator(r.Drawing._Inline.Graphic.GraphicData.Pic.SpPr.Xfrm); 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; id := r.Drawing._Inline.Graphic.GraphicData.Pic.BlipFill.Blip.Embed;
rel := rels_adapter.Id(id); rel := rels_adapter.Id(id);
image_path := "word/" + rel.Target; image_path := "word/" + rel.Target;
image := docx_components_.Zip().Get(image_path); image := docx_components_ware_.Zip().Get(image_path);
data := image.Data(); data := image.Data();
image_path := docx_to_pdf_.GetCachePath(image_path); image_path := docx_to_pdf_.GetCachePath(image_path);
writeFile(rwBinary(), "", image_path, 0, length(data)-1, data); writeFile(rwBinary(), "", image_path, 0, length(data)-1, data);
image := nil; image := nil;
case self.GetImageFileType(data) of case {self.}GetImageFileType(data) of
"png": "png":
image := docx_to_pdf_.GetPdf().LoadPngImageFromFile("", image_path); image := docx_to_pdf_.GetPdf().LoadPngImageFromFile("", image_path);
"jpg": "jpg":
@ -283,23 +293,23 @@ end;
function TSPdfParagraphRange.SetPPr(var ppr: PPr); function TSPdfParagraphRange.SetPPr(var ppr: PPr);
begin begin
new_ppr := new PPr(); 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.Copy(styles.DocDefaults.PPrDefault.PPr);
new_ppr.RPr.Copy(styles.DocDefaults.RPrDefault.RPr); new_ppr.RPr.Copy(styles.DocDefaults.RPrDefault.RPr);
self.SetPPrByStyleId(new_ppr, extra_style_id_); {self.}SetPPrByStyleId(new_ppr, extra_style_id_);
self.SetPPrByStyleId(new_ppr, ppr.PStyle.Val); {self.}SetPPrByStyleId(new_ppr, ppr.PStyle.Val);
new_ppr.Copy(ppr); new_ppr.Copy(ppr);
ppr.Copy(new_ppr); ppr.Copy(new_ppr);
end; end;
function TSPdfParagraphRange.SetPPrByStyleId(var ppr: PPr; style_id: string); function TSPdfParagraphRange.SetPPrByStyleId(var ppr: PPr; style_id: string);
begin begin
styles := class(TSPdfSingletonKit).GetComponent(docx_components_, "styles_adapter"); styles := docx_components_ware_.GetStylesAdapter();
style := styles.StyleId(style_id); style := styles.StyleId(style_id);
if ifObj(style) then if ifObj(style) then
begin begin
based_on := style.BasedOn.Val; based_on := style.BasedOn.Val;
self.SetPPrByStyleId(ppr, based_on); {self.}SetPPrByStyleId(ppr, based_on);
ppr.Copy(style.PPr); ppr.Copy(style.PPr);
ppr.RPr.Copy(style.RPr); ppr.RPr.Copy(style.RPr);
end end
@ -311,39 +321,39 @@ begin
new_rpr := new RPr(); new_rpr := new RPr();
style_id := rpr.RStyle.Val; style_id := rpr.RStyle.Val;
new_rpr.Copy(ppr.RPr); new_rpr.Copy(ppr.RPr);
self.SetRPrByStyleId(new_rpr, style_id); {self.}SetRPrByStyleId(new_rpr, style_id);
new_rpr.Copy(rpr); new_rpr.Copy(rpr);
rpr.Copy(new_rpr); rpr.Copy(new_rpr);
end; end;
function TSPdfParagraphRange.SetRPrByStyleId(var rpr: RPr; style_id: string); function TSPdfParagraphRange.SetRPrByStyleId(var rpr: RPr; style_id: string);
begin begin
styles := class(TSPdfSingletonKit).GetComponent(docx_components_, "styles_adapter"); styles := docx_components_ware_.GetStylesAdapter();
style := styles.StyleId(style_id); style := styles.StyleId(style_id);
if ifObj(style) then if ifObj(style) then
begin begin
based_on := style.BasedOn.Val; based_on := style.BasedOn.Val;
self.SetRPrByStyleId(rpr, based_on); {self.}SetRPrByStyleId(rpr, based_on);
rpr.Copy(style.RPr); rpr.Copy(style.RPr);
end end
end; end;
function TSPdfParagraphRange.SetLvlText(); function TSPdfParagraphRange.SetLvlText();
begin begin
numbering_ware := class(TSPdfSingletonKit).GetComponent(docx_components_, "numbering_ware"); numbering_ware := docx_components_ware_.GetNumberingWare();
if not ifObj(numbering_ware) then return; if not ifObj(numbering_ware) then return;
[lvl_text, lvl] := numbering_ware.GetNumberLvl(paragraph_.PPr); [lvl_text, lvl] := numbering_ware.GetNumberLvl(paragraph_.PPr);
if lvl_text = "" and ifnil(lvl) then return; 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); rpr := new RPrUnitDecorator(lvl.RPr);
self.SplitTextToTextRange(lvl_text, rpr); {self.}SplitTextToTextRange(lvl_text, rpr);
end; end;
function TSPdfParagraphRange.ResetCoordinates(ppr); function TSPdfParagraphRange.ResetCoordinates(ppr: PPr);
begin begin
// 根据段落的间距确定新的坐标 // 根据段落的间距确定新的坐标
sz := ppr.RPr.SzCs.Val ? ppr.RPr.SzCs.Val : ppr.RPr.Sz.Val ? ppr.RPr.Sz.Val : docx_to_pdf_.Font.GetDefaultSz(); 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.}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.LeftChars ? ppr.Ind.LeftChars * sz : ppr.Ind.Left;
self.Width -= ppr.Ind.RightChars ? ppr.Ind.RightChars * sz : ppr.Ind.Right; {self.}Width -= ppr.Ind.RightChars ? ppr.Ind.RightChars * sz : ppr.Ind.Right;
end; end;

View File

@ -16,12 +16,12 @@ private
function SetTcPrByStyleId(var tc_pr: TcPr; style_id: string); function SetTcPrByStyleId(var tc_pr: TcPr; style_id: string);
private private
docx_to_pdf_: TSDocxToPdf; [weakref]docx_to_pdf_: TSDocxToPdf;
docx_components_: Components; [weakref]docx_components_ware_: Components;
sect_ware_: TSSectWare; [weakref]sect_ware_: TSSectWare;
table_: Tbl; [weakref]table_: Tbl;
range_array_: tableArray;
page_: PdfPage; page_: PdfPage;
[weakref]range_array_: tableArray;
point_: TSPoint; point_: TSPoint;
end; end;
@ -29,27 +29,28 @@ function TSPdfTableRange.Create(docx_to_pdf: TSDocxToPdf; pg: PdfPage; component
begin begin
docx_to_pdf_ := docx_to_pdf; docx_to_pdf_ := docx_to_pdf;
page_ := pg; page_ := pg;
docx_components_ := Components; docx_components_ware_ := Components;
sect_ware_ := sect_ware; sect_ware_ := sect_ware;
table_ := table; table_ := table;
range_array_ := array(); range_array_ := array();
self.Page := page_; {self.}Page := page_;
end; end;
function TSPdfTableRange.Calc(); function TSPdfTableRange.Calc();
begin begin
self.SetTblPr(table_.TblPr); // return;
{self.}SetTblPr(table_.TblPr);
tbl_pr := new TblPrUnitDecorator(table_.TblPr); tbl_pr := new TblPrUnitDecorator(table_.TblPr);
grid_cols := table_.TblGrid.GridCols(); grid_cols := table_.TblGrid.GridCols();
for i:=0 to length(grid_cols)-1 do for i:=0 to length(grid_cols)-1 do
grid_cols[i] := new GridColUnitDecorator(grid_cols[i]); grid_cols[i] := new GridColUnitDecorator(grid_cols[i]);
self.ResetCoordinates(tbl_pr, grid_cols); {self.}ResetCoordinates(tbl_pr, grid_cols);
self.EndX := self.StartX; {self.}EndX := {self.}StartX;
self.EndY := self.StartY; {self.}EndY := {self.}StartY;
// 如果是根据内容自适应应该计算并调整grid_cols的值 // 如果是根据内容自适应应该计算并调整grid_cols的值
trs := table_.Trs(); trs := table_.Trs();
for i,tr in trs do 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; end;
function TSPdfTableRange.Do(); function TSPdfTableRange.Do();
@ -66,7 +67,7 @@ begin
page_ := docx_to_pdf_.GetNextPage(page_); page_ := docx_to_pdf_.GetNextPage(page_);
if ifnil(page_) then page_ := docx_to_pdf_.AddPage(sect_ware_); if ifnil(page_) then page_ := docx_to_pdf_.AddPage(sect_ware_);
point := docx_to_pdf_.GetCurrentPoint(); point := docx_to_pdf_.GetCurrentPoint();
self.EndY := point.Y; {self.}EndY := point.Y;
return true; return true;
end end
return false; return false;
@ -74,18 +75,18 @@ end;
function TSPdfTableRange.ProcessTrData(grid_cols: array of GridCol; tr: Tr; tbl_pr: TblPr): array of TSPdfAbstractRange; function TSPdfTableRange.ProcessTrData(grid_cols: array of GridCol; tr: Tr; tbl_pr: TblPr): array of TSPdfAbstractRange;
begin begin
self.SetTrPr(tr.TrPr); {self.}SetTrPr(tr.TrPr);
tr_pr := new TrPrUnitDecorator(tr.TrPr); tr_pr := new TrPrUnitDecorator(tr.TrPr);
height := tr_pr.TrHeight.Val; height := tr_pr.TrHeight.Val;
tc_x := self.EndX; tc_x := {self.}EndX;
tc_y := self.EndY; tc_y := {self.}EndY;
tc_h := height; tc_h := height;
max_height := 0; max_height := 0;
cell_range_array := array(); cell_range_array := array();
tcs := tr.Tcs(); tcs := tr.Tcs();
for i,tc in tcs do for i,tc in tcs do
begin 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.StartX := tc_x;
cell_range.StartY := tc_y; cell_range.StartY := tc_y;
cell_range.Width := grid_cols[i].W; cell_range.Width := grid_cols[i].W;
@ -96,11 +97,11 @@ begin
cell_range_array[length(cell_range_array)] := cell_range; cell_range_array[length(cell_range_array)] := cell_range;
end end
if tc_h > max_height then max_height := tc_h; 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 for _,range in cell_range_array do
begin begin
range.AlignHeight(surplus); range.AlignHeight(max_height, surplus);
self.EndY := range.EndY; // 理论上每个range.EndY都是一个值 {self.}EndY := range.EndY; // 理论上每个range.EndY都是一个值
page_ := range.GetLastPage(); page_ := range.GetLastPage();
end end
return cell_range_array; return cell_range_array;
@ -111,37 +112,37 @@ begin
total_width := 0; total_width := 0;
for _,grid_col in grid_cols do for _,grid_col in grid_cols do
total_width += grid_col.W; total_width += grid_col.W;
diff := total_width - self.Width; diff := total_width - {self.}Width;
case tbl_pr.jc.Val of case tbl_pr.jc.Val of
"center": "center":
begin begin
offset := diff/2; offset := diff/2;
self.StartX -= offset; {self.}StartX -= offset;
end end
"right": "right":
begin begin
self.StartX -= diff; {self.}StartX -= diff;
end end
end; end;
self.Width := total_width; {self.}Width := total_width;
end; end;
function TSPdfTableRange.SetTblPr(var tbl_pr: TblPr); function TSPdfTableRange.SetTblPr(var tbl_pr: TblPr);
begin begin
new_tbl_pr := new TblPr(); 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); new_tbl_pr.Copy(tbl_pr);
tbl_pr.Copy(new_tbl_pr); tbl_pr.Copy(new_tbl_pr);
end; end;
function TSPdfTableRange.SetTblPrByStyleId(var tbl_pr: TblPr; style_id: string); function TSPdfTableRange.SetTblPrByStyleId(var tbl_pr: TblPr; style_id: string);
begin begin
styles := class(TSPdfSingletonKit).GetComponent(docx_components_, "styles_adapter"); styles := docx_components_ware_.GetStylesAdapter();
style := styles.StyleId(style_id); style := styles.StyleId(style_id);
if ifObj(style) then if ifObj(style) then
begin begin
based_on := style.BasedOn.Val; based_on := style.BasedOn.Val;
self.SetTblPrByStyleId(tbl_pr, based_on); {self.}SetTblPrByStyleId(tbl_pr, based_on);
tbl_pr.Copy(style.TblPr); tbl_pr.Copy(style.TblPr);
end end
end; end;
@ -149,19 +150,19 @@ end;
function TSPdfTableRange.SetTrPr(var tr_pr: TrPr); function TSPdfTableRange.SetTrPr(var tr_pr: TrPr);
begin begin
new_tr_pr := new TrPr(); 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); new_tr_pr.Copy(tr_pr);
tr_pr.Copy(new_tr_pr); tr_pr.Copy(new_tr_pr);
end; end;
function TSPdfTableRange.SetTrPrByStyleId(var tr_pr: TrPr; style_id: string); function TSPdfTableRange.SetTrPrByStyleId(var tr_pr: TrPr; style_id: string);
begin begin
styles := class(TSPdfSingletonKit).GetComponent(docx_components_, "styles_adapter"); styles := docx_components_ware_.GetStylesAdapter();
style := styles.StyleId(style_id); style := styles.StyleId(style_id);
if ifObj(style) then if ifObj(style) then
begin begin
based_on := style.BasedOn.Val; based_on := style.BasedOn.Val;
self.SetTrPrByStyleId(tr_pr, based_on); {self.}SetTrPrByStyleId(tr_pr, based_on);
tr_pr.Copy(style.TrPr); tr_pr.Copy(style.TrPr);
end end
end; end;
@ -169,19 +170,19 @@ end;
function TSPdfTableRange.SetTcPr(var tc_pr: TcPr); function TSPdfTableRange.SetTcPr(var tc_pr: TcPr);
begin begin
new_tc_pr := new TcPr(); 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); new_tc_pr.Copy(tc_pr);
tc_pr.Copy(new_tc_pr); tc_pr.Copy(new_tc_pr);
end; end;
function TSPdfTableRange.SetTcPrByStyleId(var tc_pr: TcPr; style_id: string); function TSPdfTableRange.SetTcPrByStyleId(var tc_pr: TcPr; style_id: string);
begin begin
styles := class(TSPdfSingletonKit).GetComponent(docx_components_, "styles_adapter"); styles := docx_components_ware_.GetStylesAdapter();
style := styles.StyleId(style_id); style := styles.StyleId(style_id);
if ifObj(style) then if ifObj(style) then
begin begin
based_on := style.BasedOn.Val; based_on := style.BasedOn.Val;
self.SetTcPrByStyleId(tc_pr, based_on); {self.}SetTcPrByStyleId(tc_pr, based_on);
tc_pr.Copy(style.TcPr); tc_pr.Copy(style.TcPr);
end end
end; end;

View File

@ -0,0 +1,9 @@
type TSPdfTocRange = class(TSPdfBasicRange)
public
function Create();
end;
function TSPdfTocRange.Create();
begin
end;

View File

@ -16,12 +16,12 @@ end;
function TSPdfBasicRange.Create(); function TSPdfBasicRange.Create();
begin begin
self.StartX := 0; {self.}StartX := 0;
self.StartY := 0; {self.}StartY := 0;
self.EndX := 0; {self.}EndX := 0;
self.EndY := 0; {self.}EndY := 0;
self.Width := 0; {self.}Width := 0;
self.FixedHeight := 0; {self.}FixedHeight := 0;
self.DynamicHeight := 0; {self.}DynamicHeight := 0;
self.Page := nil; {self.}Page := nil;
end; end;

View File

@ -10,19 +10,19 @@ end;
function TSPdfImageRange.Create(); function TSPdfImageRange.Create();
begin begin
class(TSPdfBasicRange).Create(); class(TSPdfBasicRange).Create();
self.Image := nil; {self.}Image := nil;
end; end;
function TSPdfImageRange.Do(); function TSPdfImageRange.Do();
begin begin
// println("image = {}, x = {}, y = {}, w = {}, h = {}", 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); {self.}Page.DrawImage({self.}Image, {self.}EndX, {self.}EndY, {self.}Width, {self.}DynamicHeight);
if sysparams["_PDF_IMAGE_DEBUG_"] then if sysparams["_PDF_IMAGE_DEBUG_"] then
begin begin
self.Page.SetLineWidth(0.1); {self.}Page.SetLineWidth(0.1);
self.Page.SetRGBStroke(0.8, 0.8, 0); {self.}Page.SetRGBStroke(0.8, 0.8, 0);
self.Page.Rectangle(self.EndX, self.EndY, self.Width, self.DynamicHeight); {self.}Page.Rectangle({self.}EndX, {self.}EndY, {self.}Width, {self.}DynamicHeight);
self.Page.Stroke(); {self.}Page.Stroke();
end end
end; end;

View File

@ -12,11 +12,11 @@ end;
function TSPdfRectangleRange.Do();override; function TSPdfRectangleRange.Do();override;
begin begin
// self.Page.SetRGBStroke(1.0, 0.0, 0.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); // println("page = {}, endx = {}, endy = {}, DynamicHeight = {}, Width = {}", {self.}Page, {self.}EndX, {self.}EndY, {self.}DynamicHeight, {self.}Width);
self.Page.SetGrayStroke(0.5); {self.}Page.SetGrayStroke(0.5);
self.Page.SetLineWidth(0.5); {self.}Page.SetLineWidth(0.5);
self.Page.Rectangle(self.EndX, self.EndY - self.DynamicHeight, self.Width, self.DynamicHeight); {self.}Page.Rectangle({self.}EndX, {self.}EndY - {self.}DynamicHeight, {self.}Width, {self.}DynamicHeight);
self.Page.Stroke(); {self.}Page.Stroke();
self.Page.SetGrayStroke(0); {self.}Page.SetGrayStroke(0);
end; end;

View File

@ -13,31 +13,31 @@ end;
function TSPdfTextRange.Create(); function TSPdfTextRange.Create();
begin begin
class(TSPdfBasicRange).Create(); class(TSPdfBasicRange).Create();
self.RPr := nil; {self.}RPr := nil;
self.Text := ""; {self.}Text := "";
self.Font := nil; {self.}Font := nil;
end; end;
function TSPdfTextRange.Do(); function TSPdfTextRange.Do();
begin begin
// println("text = {}, endx = {}, endy = {}, width = {}, page = {}", ansiToUtf8(text), endx, endy, width, page); // println("text = {}, endx = {}, endy = {}, width = {}, page = {}", ansiToUtf8(text), endx, endy, width, page);
[r, g, b] := array(0, 0, 0); [r, g, b] := array(0, 0, 0);
if self.RPr.Color.Val then [r, g, b] := TSColorToolKit.HexToRGB(self.RPr.Color.Val); 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.SetRGBFill(r / 255, g / 255, b / 255);
self.Page.SetFontAndSize(self.Font, self.RPr.Sz.Val); {self.}Page.SetFontAndSize({self.}Font, {self.}RPr.Sz.Val);
self.Page.BeginText(); {self.}Page.BeginText();
self.Page.TextOut(self.EndX, self.EndY, self.Text); {self.}Page.TextOut({self.}EndX, {self.}EndY, {self.}Text);
self.Page.EndText(); {self.}Page.EndText();
self.Page.SetRGBFill(0, 0, 0); {self.}Page.SetRGBFill(0, 0, 0);
if sysparams["_PDF_TEXT_DEBUG_"] then if sysparams["_PDF_TEXT_DEBUG_"] then
begin begin
self.Page.SetLineWidth(0.1); {self.}Page.SetLineWidth(0.1);
self.Page.SetRGBStroke(1.0, 0.5, 0.0); {self.}Page.SetRGBStroke(1.0, 0.5, 0.0);
self.Page.MoveTo(0, self.EndY); {self.}Page.MoveTo(0, {self.}EndY);
self.Page.LineTo(600, self.EndY); {self.}Page.LineTo(600, {self.}EndY);
self.Page.Stroke(); {self.}Page.Stroke();
end end
end; end;

View File

@ -1,65 +0,0 @@
type TSPdfSingletonKit = class
public
function Create();
class function Release(components: Components);
class function GetComponent(components: Components; type: string);
public
hash_: array of tslobj;
private
static singleton_: Singleton;
end;
function TSPdfSingletonKit.Create();
begin
hash_ := array();
end;
class function TSPdfSingletonKit.Release(components: Components);
begin
singleton_.hash_[components] := nil;
end;
class function TSPdfSingletonKit.GetComponent(components: Components; type: string);
begin
if not ifObj(singleton_) then singleton_ := new TSPdfSingletonKit();
if ifnil(singleton_.hash_[components]) then singleton_.hash_[components] := array();
if ifObj(singleton_.hash_[components][type]) then return singleton_.hash_[components][type];
case type of
"styles":
begin
styles := components.Styles;
styles.Deserialize();
singleton_.hash_[components][type] := styles;
return styles;
end
"styles_adapter":
begin
styles := class(TSPdfSingletonKit).GetComponent(components, "styles");
styles_adapter := new StylesAdapter(styles);
singleton_.hash_[components][type] := styles_adapter;
return styles_adapter;
end
"numbering_ware":
begin
numbering := components.Numbering;
numbering_ware := nil;
if ifObj(numbering) then
begin
numbering.Deserialize();
numbering_ware := new TSNumberingWare(numbering);
end
singleton_.hash_[components][type] := numbering_ware;
return numbering_ware;
end
"document_rels_adapter":
begin
document_rels := components.DocumentRels;
document_rels.Deserialize();
rels_adapter := new RelationShipsAdapter(document_rels);
singleton_.hash_[components][type] := rels_adapter;
return rels_adapter;
end
end;
end;

View File

@ -1,8 +1,8 @@
type TSPoint = class type TSPoint = class
function Create(); function Create();
begin begin
self.X := 0; {self.}X := 0;
self.Y := 0; {self.}Y := 0;
end end
X: real; X: real;
Y: real; Y: real;

View File

@ -0,0 +1,52 @@
type TSDocxComponentsWare = class(Components)
public
function Create();
function GetStyles(): Styles;
function GetStylesAdapter(): StylesAdapter;
function GetDocumentRelsAdapter(): RelationShipsAdapter;
function GetNumberingWare(): TSNumberingWare;
private
styles_deserialize_flag_;
styles_adapter_;
document_rels_adapter_;
numbering_ware_;
end;
function TSDocxComponentsWare.Create();
begin
class(Components).Create();
end;
function TSDocxComponentsWare.GetStyles(): Styles;
begin
if styles_deserialize_flag_ then return {self.}Styles;
{self.}Styles.Deserialize();
styles_deserialize_flag_ := true;
return {self.}Styles;
end;
function TSDocxComponentsWare.GetStylesAdapter(): StylesAdapter;
begin
if styles_adapter_ then return styles_adapter_;
styles_adapter_ := new StylesAdapter({self.}GetStyles());
return styles_adapter_;
end;
function TSDocxComponentsWare.GetDocumentRelsAdapter(): RelationShipsAdapter;
begin
if document_rels_adapter_ then return document_rels_adapter_;
{self.}DocumentRels.Deserialize();
document_rels_adapter_ := new RelationShipsAdapter({self.}DocumentRels);
return document_rels_adapter_;
end;
function TSDocxComponentsWare.GetNumberingWare(): TSNumberingWare;
begin
if numbering_ware_ then return numbering_ware_;
if not {self.}Numbering then return nil;
{self.}Numbering.Deserialize();
numbering_ware_ := new TSNumberingWare({self.}Numbering);
return numbering_ware_;
end;

View File

@ -65,7 +65,7 @@ end;
function TSFontWare.GetFont(name: string; bold: boolean; italic: boolean); function TSFontWare.GetFont(name: string; bold: boolean; italic: boolean);
begin begin
return use_built_in_font_ ? self.GetBuiltInFont(name, bold, italic) : self.GetExternalFont(name, bold, italic); return use_built_in_font_ ? {self.}GetBuiltInFont(name, bold, italic) : {self.}GetExternalFont(name, bold, italic);
end; end;
function TSFontWare.GetBuiltInFont(name: string; bold: boolean; italic: boolean); function TSFontWare.GetBuiltInFont(name: string; bold: boolean; italic: boolean);

View File

@ -13,19 +13,19 @@ end;
function TSSectWare.Create(); function TSSectWare.Create();
begin begin
self.Elements := array(); {self.}Elements := array();
self.SectPr := nil; {self.}SectPr := nil;
self.BaseSize := 0; {self.}BaseSize := 0;
end; end;
function TSSectWare.Do(); function TSSectWare.Do();
begin begin
if ifObj(self.SectPr) then if ifObj({self.}SectPr) then
self.BaseSize := round(self.SectPr.DocGrid.LinePitch * 0.75); {self.}BaseSize := round({self.}SectPr.DocGrid.LinePitch * 0.75);
// println("LinePitch = {}, Type = {}", self.SectPr.DocGrid.LinePitch, self.SectPr.DocGrid.Type); // println("LinePitch = {}, Type = {}", {self.}SectPr.DocGrid.LinePitch, {self.}SectPr.DocGrid.Type);
// println("Width = {}, Height = {}", self.SectPr.PgSz.W, self.SectPr.PgSz.H); // println("Width = {}, Height = {}", {self.}SectPr.PgSz.W, {self.}SectPr.PgSz.H);
// println("Top = {}, Right = {}, Bottom = {}, Left = {}, Header = {}, Footer = {}\n", // println("Top = {}, Right = {}, Bottom = {}, Left = {}, Header = {}, Footer = {}\n",
// self.SectPr.PgMar.Top, self.SectPr.PgMar.Right, self.SectPr.PgMar.Bottom, self.SectPr.PgMar.Left, self.SectPr.PgMar.Header, self.SectPr.PgMar.Footer); // {self.}SectPr.PgMar.Top, {self.}SectPr.PgMar.Right, {self.}SectPr.PgMar.Bottom, {self.}SectPr.PgMar.Left, {self.}SectPr.PgMar.Header, {self.}SectPr.PgMar.Footer);
end; end;
function TSSectWare.AddElement(element: tslobj); function TSSectWare.AddElement(element: tslobj);