对依赖的OfficeXml性能优化版本做调整

This commit is contained in:
csh 2024-09-19 10:48:53 +08:00
parent 0417669eb2
commit 448bbfc7e2
5 changed files with 61 additions and 20 deletions

View File

@ -33,4 +33,4 @@ TSDocxToPdf中的[Font](./ware/TSFontWare.tsf)属性是设置转PDF时的一些
1. `office_plugin.dll`
2. [PDF](https://git.mytsl.cn/tinysoft/Pdf)相关包
3. [Office](https://git.mytsl.cn/tinysoft/Office)相关包
3. [Office](https://git.mytsl.cn/tinysoft/OfficeXml)相关包

View File

@ -118,8 +118,8 @@ begin
elements := sect_ware.Elements();
for _,element in elements do
begin
// if _ = 3 then break;
// if _ <> 4 then continue;
// if _ = 4 then break;
// if _ = 624 then
// println("_ = {}, xml_file_ = {}", _, xml_file_);
if element.LocalName = "p" then {self.}TransformP(text_point_, element, w, lb);
else if element.LocalName = "tbl" then {self.}TransformTbl(text_point_, element, w, lb);

View File

@ -24,10 +24,11 @@ private
function BasicRangesToLineRange(): tableArray;
function CheckAndAddPage(y: real; offset: real): boolean;
function GetUtf8CharLength(byte: string): integer;
function RToTextRange(r: R; link: string);
function SplitTextToTextRange(text: string; rpr: RPrUnitDecorator; link: string);
function RToTextRange(r: R; link: string);
function RToDrawingRange(r: R);
function RAlternateContentToRange(r: R);
function RFootnoteReference(r: R);
function SetLinesAlignment();
function ResetCoordinates();
function NewLineRange(): TSPdfLineRange;
@ -118,6 +119,7 @@ begin
{self.}CheckAndAddPage({self.}LowerBound, 1);
else if ifObj(element.Drawing.XmlNode) then {self.}RToDrawingRange(element);
else if ifObj(element.AlternateContent.XmlNode) then {self.}RAlternateContentToRange(element);
else if ifObj(element.FootnoteReference.XmlNode) then {self.}RFootnoteReference(element);
else if not fld then {self.}RToTextRange(element, bookmark_name);
end
else if element.LocalName = "fldSimple" then
@ -261,8 +263,11 @@ begin
for _,r in rs do
begin
if r.FldChar.FldCharType = "begin" then break;
r.RPr := new RPr();
// TODOofficexml项目是否应该保留赋值接口如何统一
r.RPr.Lang.Val := "zh-CN";
// r.RPr := new RPr();
{self.}SetRPr(r.RPr, ppr_unit_decorator_);
r.RPr.Color.Val := nil;
{self.}RToTextRange(r, hyperlink.Anchor);
end
arr := array();
@ -502,6 +507,18 @@ begin
end
end;
function TSPdfParagraphRange.RFootnoteReference(r: R);
begin
id := R.FootnoteReference.Id;
footnotes_adapter := docx_components_ware_.GetFootnotesAdapter();
footnote := footnotes_adapter.GetFootnoteById(id);
sect_ware := docx_to_pdf_.GetCurrentSectWare();
w := sect_ware.SectPr.PgSz.W - sect_ware.SectPr.PgMar.Right - sect_ware.SectPr.PgMar.Left;
lb := 0;
[x, y] := docx_to_pdf_.CalculateTextCoordinates();
// range := new TSPdfParagraphRange(self, page_, docx_components_ware_, );
end;
function TSPdfParagraphRange.GetXYCordinates(): array of real;
begin
xml_file := docx_to_pdf_.GetCurrentXmlFile();
@ -585,8 +602,11 @@ begin
new_ppr.RPr.Copy(styles.DocDefaults.RPrDefault.RPr);
{self.}SetPPrByStyleId(new_ppr, extra_style_id_);
{self.}SetPPrByStyleId(new_ppr, ppr.PStyle.Val);
if ifObj(ppr) then
begin
new_ppr.Copy(ppr);
ppr.Copy(new_ppr);
end
end;
function TSPdfParagraphRange.SetPPrByStyleId(var ppr: PPr; style_id: string);
@ -609,8 +629,11 @@ begin
new_rpr.Copy(styles.DocDefaults.RPrDefault.RPr);
{self.}SetRPrByStyleId(new_rpr, ppr.PStyle.Val);
{self.}SetRPrByStyleId(new_rpr, rpr.RStyle.Val);
if ifObj(rpr) then
begin
new_rpr.Copy(rpr);
rpr.Copy(new_rpr);
end
end;
function TSPdfParagraphRange.SetRPrByStyleId(var rpr: RPr; style_id: string);

View File

@ -25,6 +25,7 @@ private
[weakref]docx_components_ware_: Components;
[weakref]table_: Tbl;
[weakref]page_: TSPage;
tbl_pr_unit_decorator_: TblPrUnitDecorator;
cell_range_array_: tableArray;
end;
@ -41,11 +42,11 @@ end;
function TSPdfTableRange.Calc();
begin
{self.}SetTblPr(table_.TblPr);
table_.TblPr := new TblPrUnitDecorator(table_.TblPr);
tbl_pr_unit_decorator_ := 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(table_.TblPr, grid_cols);
{self.}ResetCoordinates(tbl_pr_unit_decorator_, grid_cols);
{self.}EndX := {self.}StartX;
{self.}EndY := {self.}StartY;
// 如果是根据内容自适应应该计算并调整grid_cols的值
@ -123,7 +124,7 @@ begin
cell_range_array_[vmerge_arr[pos][0]][pos].VMerge := vmerge_arr[pos][1];
vmerge_arr[pos] := nil;
end
cell_range := new TSPdfCellRange(self, docx_to_pdf_, page_, docx_components_ware_, tc, table_.TblPr, tr.TrPr);
cell_range := new TSPdfCellRange(self, docx_to_pdf_, page_, docx_components_ware_, tc, tbl_pr_unit_decorator_, tr.TrPr);
cell_range.StartX := tc_x;
cell_range.Width := grid_cols[pos].W;
cell_range.LowerBound := {self.}LowerBound;
@ -234,7 +235,7 @@ end;
function TSPdfTableRange.SetTblStylePr(var tc_pr: TcPr; type: string);
begin
{self.}SetTcPr(tc_pr);
tbl_style_pr := docx_components_ware_.GetTblStylePrByType(table_.TblPr.TblStyle.Val, type);
tbl_style_pr := docx_components_ware_.GetTblStylePrByType(tbl_pr_unit_decorator_.TblStyle.Val, type);
if tbl_style_pr then tc_pr.Copy(tbl_style_pr.TcPr);
end;
@ -244,7 +245,7 @@ begin
for _,grid_col in grid_cols do
total_width += grid_col.W;
diff := total_width - {self.}Width;
case tbl_pr.jc.Val of
case tbl_pr.Jc.Val of
"center":
begin
offset := diff/2;
@ -281,9 +282,12 @@ 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, tbl_pr_unit_decorator_.TblStyle.Val);
if ifObj(tr_pr) then
begin
new_tr_pr.Copy(tr_pr);
tr_pr.Copy(new_tr_pr);
end
end;
function TSPdfTableRange.SetTrPrByStyleId(var tr_pr: TrPr; style_id: string);
@ -301,9 +305,12 @@ 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, tbl_pr_unit_decorator_.TblStyle.Val);
if ifObj(tc_pr) then
begin
new_tc_pr.Copy(tc_pr);
tc_pr.Copy(new_tc_pr);
end
end;
function TSPdfTableRange.SetTcPrByStyleId(var tc_pr: TcPr; style_id: string);

View File

@ -10,6 +10,7 @@ public
function GetHdr(target: string): Hdr;
function GetFtrRelsAdapter(target: string): RelationShipsAdapter;
function GetHdrRelsAdapter(target: string): RelationShipsAdapter;
function GetFootnotesAdapter(): FootnotesAdapter;
private
styles_deserialize_flag_: boolean;
@ -21,6 +22,7 @@ private
hdr_hash_: array of Hdr;
hdr_rel_hash_: array of RelationShipsAdapter;
ftr_rel_hash_: array of RelationShipsAdapter;
footnotes_adapter_: FootnotesAdapter;
end;
function TSDocxComponentsWare.Create();
@ -117,3 +119,12 @@ begin
ftr_rel_hash_[target] := rels_adapter;
return rels_adapter;
end;
function TSDocxComponentsWare.GetFootnotesAdapter(): FootnotesAdapter;
begin
if footnotes_adapter_ then return footnotes_adapter_;
obj := {self.}Footnotes;
obj.Deserialize();
footnotes_adapter_ := new FootnotesAdapter();
return footnotes_adapter_;
end;