This commit is contained in:
csh 2025-04-03 17:52:39 +08:00
parent 9f84a72595
commit 2e0aadd3d0
5 changed files with 505 additions and 371 deletions

View File

@ -127,9 +127,12 @@ begin
else begin
for _,element in elements do
begin
// if _ = 100 then break;
// if _ = 17 then
// println("_ = {}, paraid = {}, xml_file_ = {}, error = {}", _, element.ParaId, xml_file_, pdf_.GetError());
// if _ = 4 then break;
// if _ = 31 then
// if element.LocalName = "p" then
// println("_ = {}, paraid = {}, xml_file_ = {}, error = {}", _, element.ParaId, xml_file_, pdf_.GetError());
// println("_ = {}", _);
if element.LocalName = "p" then {self.}TransformP(element);
else if element.LocalName = "tbl" then {self.}TransformTbl(element);
else if element.LocalName = "sdt" then {self.}TransformSdt(element);
@ -273,16 +276,16 @@ begin
ftr_range := new FtrRange(self, ftr);
ftr_range.Width := w;
ftr_range.Parent := self;
ftr_range.StartX := current_page_.SectPr.PgMar.Left;
ftr_range.StartY := current_page_.SectPr.PgSz.H;
ftr_range.StartPage := current_page_;
ftr_range.LowerBound := 0;
if ftr_range.Calc() then
flag := ftr_range.Calc();
y_offset := current_page_.SectPr.PgSz.H - ftr_range.DynamicHeight - current_page_.SectPr.PgMar.Footer;
ftr_range.Offset(current_page_.SectPr.PgMar.Left, y_offset, current_page_);
if flag then
ftr_range.Do();
else
realtime_range_array_[length(realtime_range_array_)] := ftr_range;
current_page_.FtrPoint.Y := ftr_range.EndY;
current_page_.FtrPoint.Y := ftr_range.StartY; // 向下偏移后的起始位置=正文的下边界
end;
function TSDocxToPdf.SetHdr(type: string);
@ -303,11 +306,10 @@ begin
hdr_range := new HdrRange(self, hdr);
hdr_range.Width := w;
hdr_range.Parent := self;
hdr_range.StartX := current_page_.SectPr.PgMar.Left;
hdr_range.StartY := current_page_.SectPr.PgSz.H - current_page_.SectPr.PgMar.Header;
hdr_range.StartPage := current_page_;
hdr_range.LowerBound := 0;
if hdr_range.Calc() then
flag := hdr_range.Calc();
hdr_range.Offset(current_page_.SectPr.PgMar.Left, current_page_.SectPr.PgSz.H - current_page_.SectPr.PgMar.Header, current_page_);
if flag then
hdr_range.Do();
else
realtime_range_array_[length(realtime_range_array_)] := hdr_range;
@ -349,13 +351,10 @@ begin
range := new PRange(self, p);
range.Width := w;
range.Parent := self;
range.LowerBound := current_page_.LowerBound;
fg := range.Calc();
{self.}RangesSpacing(range);
range.StartX := current_page_.TextPoint.X;
range.StartY := current_page_.TextPoint.Y;
range.StartPage := current_page_;
range.LowerBound := current_page_.LowerBound;
range.Run();
range.Offset(current_page_.TextPoint.X, current_page_.TextPoint.Y, current_page_);
if fg then
range.Do();
else
@ -369,13 +368,10 @@ begin
range := new TblRange(self, tbl);
range.Width := w;
range.Parent := self;
range.LowerBound := current_page_.LowerBound;
fg := range.Calc();
{self.}RangesSpacing(range);
range.StartX := current_page_.TextPoint.X;
range.StartY := current_page_.TextPoint.Y;
range.StartPage := current_page_;
range.LowerBound := current_page_.LowerBound;
range.Run();
range.Offset(current_page_.TextPoint.X, current_page_.TextPoint.Y, current_page_);
range.Do();
current_page_.TextPoint.Y := range.EndY;
end;

File diff suppressed because it is too large Load Diff

View File

@ -354,7 +354,11 @@ begin
end
else begin
word := class(SymbolMapper).SymbolChr(a_word);
if ifnil(word) then raise format("error symbol {{%s}}", a_word);
if ifnil(word) then
begin
echo format("error symbol {{%s}}", a_word);
word := chr(0x20);
end
font_obj := docx_to_pdf_.Font.GetSymbolFont();
end
rpr := new RPr();
@ -1048,7 +1052,7 @@ begin
end;
// CellRange
function CellRange.Create(docx_to_pdf: TSDocxToPdf; pg: Page; components: TSDocxComponentsModule; tc: Tc; tbl_pr: TblPr; trp: TSTrProperty);
function CellRange.Create(docx_to_pdf: TSDocxToPdf; pg: Page; components: DocxComponentsModule; tc: Tc; tbl_pr: TblPr; trp: TSTrProperty);
begin
docx_to_pdf_ := docx_to_pdf;
last_page_ := pg;

View File

@ -105,8 +105,9 @@ public
function UpdateDocxNumPages();
function CalculateRect(anchor: string);
function LinkToToc(anchor: string; range: BasicRange);
function AddToc(anchor: string; toc: Toc);
function LinkToToc(anchor: string; range: BasicRange);overload;
function LinkToToc(anchor: string);overload;
function AddToc(anchor: string; toc: Toc);overload;
function AddDocxPage(anchor: string; r: R);
@ -689,10 +690,10 @@ begin
toc.CalculateRect();
end;
function TocModule.LinkToToc(anchor: string; range: BasicRange);
function TocModule.LinkToToc(anchor: string; range: BasicRange);overload;
begin
arr := toc_hash_[anchor];
if ifnil(arr) then
if ifnil(arr) then // 未匹配到链接,说明链接可能在后面
begin
toc_unmatched_hash_[anchor] := range;
return;
@ -712,16 +713,20 @@ begin
end
end;
function TocModule.LinkToToc(anchor: string);overload;
begin
range := toc_unmatched_hash_[anchor];
if range then
begin
{self.}LinkToToc(anchor, range);
toc_unmatched_hash_[anchor] := nil;
end
end;
function TocModule.AddToc(anchor: string; toc: Toc);
begin
if ifarray(toc_hash_[anchor]) then toc_hash_[anchor] union= array(toc);
else toc_hash_[anchor] := array(toc);
if toc_unmatched_hash_[anchor] then
begin
toc := toc_unmatched_hash_[anchor];
{self.}LinkToToc(anchor, toc[0], toc[1], toc[2]);
toc_unmatched_hash_[anchor] := nil;
end
end;
function TocModule.AddDocxPage(anchor: string; r: R);

View File

@ -2,13 +2,34 @@ unit DTPPrimitiveRanges;
interface
uses DTPColorToolKit, DTPUtils;
type BasicRange = class
public
function Create();
function Do();virtual;
function Offset(x: real; y: real; page: Page);virtual;
public
[weakref]Parent: tslobj;
[weakref]EndPage: Page; // 结束page
XOffset: real;
YOffset: real; // XOffset, YOffset是相对(0,0)的偏移位置
EndX: real;
EndY: real; // range的结束坐标(x,y)
Width: real;
DynamicHeight: real;
FixedHeight: real;
// StartX: real;
// StartY: real; // range的起始坐标(x,y)
end;
type TextRange = class(BasicRange)
public
function Create();
function Do();override;
public
RPr: RPr;
RPr: RPrUnitDecorator;
Text: string;
Font: PdfFont;
Type: integer; // 0默认1: 数字2英文3中文4中文标点5,.英文逗号和点
@ -19,8 +40,9 @@ public
function Create();
function Do();override;
function DoFill();
public
TcPr: TcPr;
TcPr: TcPrUnitDecorator;
Left: boolean;
Top: boolean;
Right: boolean;
@ -39,7 +61,6 @@ public
public
Image: PdfImage;
Type: string;
end;
type LineRange = class(BasicRange)
@ -51,39 +72,30 @@ public
LineWidth: real;
end;
type BasicRange = class
public
function Create();
function Do();virtual;
public
StartX: real;
StartY: real; // range的起始坐标(x,y)
EndX: real;
EndY: real; // range的结束坐标(x,y)
Width: real;
FixedHeight: real;
DynamicHeight: real;
LowerBound: real;
[weakref]Parent: tslobj;
[weakref]StartPage: Page; // 起始page
[weakref]EndPage: Page; // 结束page
end;
implementation
// BasicRange
function BasicRange.Create();
begin
{self.}StartX := 0;
{self.}StartY := 0;
{self.}EndX := 0;
{self.}EndY := 0;
{self.}Width := 0;
{self.}DynamicHeight := 0;
{self.}LowerBound := 0;
{self.}FixedHeight := 0;
{self.}Parent := nil;
{self.}EndPage := nil;
{self.}XOffset := 0.0;
{self.}YOffset := 0.0;
{self.}EndX := 0.0;
{self.}EndY := 0.0;
{self.}Width := 0.0;
{self.}DynamicHeight := 0.0;
{self.}FixedHeight := 0.0;
// {self.}StartX := 0;
// {self.}StartY := 0;
end;
function BasicRange.Offset(x: real; y: real; page: Page);virtual;
begin
{self.}EndX := {self.}XOffset + x;
{self.}EndY := {self.}YOffset + y;
{self.}EndPage := page;
end;
// ImageRange
@ -127,7 +139,8 @@ end;
function BordersRange.DoFill();
begin
borders := {self.}TcPr.TcBorders;
if {self.}TcPr.Shd.Fill and {self.}TcPr.Shd.Fill <> "auto" then
// println("TcPr.Shd.Val = {}", TcPr.Shd.Val);
if {self.}TcPr.Shd.Val <> "clear" and {self.}TcPr.Shd.Fill and {self.}TcPr.Shd.Fill <> "auto" then
begin
[r, g, b] := DTPColorToolKit.HexToRGB({self.}TcPr.Shd.Fill);
{self.}EndPage.PdfPage.SetRGBFill(r/255, g/255, b/255);