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
File diff suppressed because it is too large Load Diff
+6 -2
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;
+15 -10
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);
+44 -31
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);