Compare commits

..

No commits in common. "7da30f77ab0aba7b2199037a264e801848449a2e" and "5121a94b158bdc88947d504e970573cc500fa87a" have entirely different histories.

5 changed files with 175 additions and 167 deletions

View File

@ -1,5 +1,5 @@
type TSDocxToPdf = class
uses TSPdfEnumerations, DocxML, DocxMLAdapter, DTPModules, DTPUtils, DTPAdvancedRanges;
uses TSPdfEnumerations, DocxML, DocxMLAdapter, DocxMLUnitDecorator, DTPModules, DTPUtils, DTPAdvancedRanges;
public
function Create(alias: string; file: string);
function Destroy();
@ -113,7 +113,7 @@ begin
if current_sect_module_ <> sect_module then
begin
current_sect_module_ := sect_module;
current_sect_pr_adapter_ := new SectPrAdapter(current_sect_module_.SectPr);
current_sect_pr_adapter_ := new SectPrAdapter(current_sect_module_.SectPr.GetObject());
{self.}AddPage(true);
end
@ -182,7 +182,6 @@ begin
current_sect_pr_adapter_ := nil;
document := docx_components_module_.Document;
document.Deserialize();
document.ConvertToPoint();
{self.}AllocateElementsToSectModule();
end;
@ -192,6 +191,7 @@ begin
module := new DTPModules.SectModule();
fp := function(module, sect);
begin
sect := new SectPrUnitDecorator(sect);
sect.PgSz.Orient := sect.PgSz.Orient ? "portrait" : "landscape";
sect.Type.Val := sect.Type.Val ?: "nextPage";
module.SectPr := sect;
@ -322,9 +322,9 @@ function TSDocxToPdf.RangesSpacing(range: BasicRange);
begin
if last_range_ then
begin
if last_range_ is class(PRange) and not ifnil(last_range_.P.PPr.OutlineLvl.Val) and (range is class(TblRange) or ifnil(range.P.PPr.OutlineLvl.Val)) then
if last_range_ is class(PRange) and not ifnil(last_range_.PPrUnitDecorator.OutlineLvl.Val) and (range is class(TblRange) or ifnil(range.PPrUnitDecorator.OutlineLvl.Val)) then
begin
if last_range_.P.PPr.Spacing.AfterAutospacing then
if last_range_.PPrUnitDecorator.Spacing.AfterAutospacing then
begin
line_range := last_range_.PLineRanges();
line_range := line_range[length(line_range)-1];
@ -332,9 +332,9 @@ begin
if y >= 0 then current_page_.TextPoint.Y := y;
end
end
if range is class(PRange) and not ifnil(range.P.PPr.OutlineLvl.Val) and (last_range_ is class(TblRange) or ifnil(last_range_.P.PPr.OutlineLvl.Val)) then
if range is class(PRange) and not ifnil(range.PPrUnitDecorator.OutlineLvl.Val) and (last_range_ is class(TblRange) or ifnil(last_range_.PPrUnitDecorator.OutlineLvl.Val)) then
begin
if range.P.PPr.Spacing.BeforeAutospacing then
if range.PPrUnitDecorator.Spacing.BeforeAutospacing then
begin
line_range := range.PLineRanges();
line_range := line_range[length(line_range)-1];

View File

@ -1,6 +1,6 @@
unit DTPAdvancedRanges;
interface
uses DTPPrimitiveRanges, DTPUtils, DTPModules, SharedML, DocxML, TSPdfEnumerations;
uses DTPPrimitiveRanges, DTPUtils, DTPModules, SharedML, DocxML, DrawingMLUnitDecorator, DocxMLUnitDecorator, TSPdfEnumerations;
type AdvancedRange = class(BasicRange)
public
@ -98,7 +98,7 @@ public
function IsFirstLineOnNextPage(): boolean;
function PLineRanges(): array of PLineRange;
property P read p_;
property PPrUnitDecorator read ppr_unit_decorator_;
private
function RangesToLines();
@ -115,7 +115,7 @@ private
function SetPPPr(var p: P);
function SetPPrByStyleId(var ppr: PPr; style_id: string);
function SetRRPr(var r: R; ppr_: PPr);
function SetRRPr(var r: R; ppr_unit_decorator: PPrUnitDecorator);
function SetRPrByStyleId(var rpr: RPr; style_id: string);
function SetRPrByTblStyleId(var rpr: RPr; style_id: string);
function SetLvlText();
@ -123,7 +123,7 @@ private
function GetImageFileType(data: binary): string;
function GetImageData(id: string): PdfImage;
function GetParagraphLineSpace(size: real; line: integer; line_rule: string): real;
function SplitTextToTextRange(range_arr: array of BasicRange; text: string; rpr: RPr; anchor: string);
function SplitTextToTextRange(range_arr: array of BasicRange; text: string; rpr: RPrUnitDecorator; anchor: string);
function RBr(r: R);
function RFootnoteReference(r: R);
@ -140,7 +140,7 @@ private
private
[weakref]docx_to_pdf_: TSDocxToPdf;
p_: P;
ppr_: PPr;
ppr_unit_decorator_: PPrUnitDecorator;
body_range_array_: array of BasicRange; // 正文range
bullet_range_array_: array of BasicRange; // 项目符号的range
line_range_array_: array of PLineRange; // 行range
@ -187,7 +187,7 @@ private
[weakref]docx_to_pdf_: TSDocxToPdf;
tc_: Tc;
trp_: TrProperty;
tc_pr_: TcPr;
tc_pr_unit_decorator_: TcPrUnitDecorator;
content_next_page_: boolean;
range_array_: array of BasicRange;
region_array_: array of Region;
@ -202,25 +202,26 @@ public
function Calc(): boolean;override;
function Offset(x: real; y: real; page: Page);override;
property TblPr read tbl_pr_;
property TblPr read tbl_pr_unit_decorator_;
property Rows read rows_;
property Cols read cols_;
private
function CreateTableMatrix(grid_cols: array of GridCol; trs: array of Tr);
function CreateTableMatrix(grid_cols: array of GridColUnitDecorator; trs: array of Tr);
function ResetCoordinates(tbl_pr: TblPr; grid_cols: array of GridCol);
function SetTblTblPr(var table: Tbl);
function SetTblPrByStyleId(var tbl_pr: TblPr; style_id: string);
function SetTrTrPr(var tr_pr: TrPr);
function SetTrPrByStyleId(var tr_pr: TrPr; style_id: string);
function SetTcTcPr(var tc: Tc; type: string);
function SetTcPrByStyleId(var tc_pr: TcPr; style_id: string; type: string);
function SetTcTcPr(var tc: Tc);
function SetTcPrByStyleId(var tc_pr: TcPr; style_id: string);
function OverrideTcPrByTblStylePrType(var tc_pr: TcPr; type: string);
private
[weakref]docx_to_pdf_: TSDocxToPdf;
tbl_: Tbl;
tbl_pr_: TblPr;
grid_cols_: array of GridCol;
tbl_pr_unit_decorator_: TblPrUnitDecorator;
grid_cols_: array of GridColUnitDecorator;
rows_: integer;
cols_: integer;
tc_range_matrix_: array of TcRange;
@ -712,7 +713,7 @@ begin
realtime_page_array_ := array();
realtime_numpages_array_ := array();
// 根据段落的间距确定新的坐标
ppr := ppr_;
ppr := ppr_unit_decorator_;
sz := ppr.RPr.SzCs.Val ? : ppr.RPr.Sz.Val;
{self.}Width -= ppr.Ind.LeftChars ? ppr.Ind.LeftChars * sz : ppr.Ind.Left;
{self.}Width -= ppr.Ind.RightChars ? ppr.Ind.RightChars * sz : ppr.Ind.Right;
@ -724,7 +725,7 @@ begin
line_range.Do();
// 段落边框
if length(line_range_array_) > 0 and ppr_.PBdr.Bottom.Val = "single" then
if length(line_range_array_) > 0 and ppr_unit_decorator_.PBdr.Bottom.Val = "single" then
begin
{self.}EndPage.PdfPage.SetLineWidth(0.5);
{self.}EndPage.PdfPage.SetGrayStroke(0.25);
@ -746,8 +747,8 @@ function PRange.Calc(): boolean;override;
begin
// ppr.rpr是无效的应该以ppr.pStyle为准
{self.}SetPPPr(p_);
if not p_.PPr.RPr.Sz.Val then p_.PPr.RPr.Sz.Val := docx_to_pdf_.Font.GetDefaultSz();
ppr_ := p_.PPr;
ppr_unit_decorator_ := new DocxMLUnitDecorator.PPrUnitDecorator(p_.PPr);
if not ppr_unit_decorator_.RPr.Sz.Val then ppr_unit_decorator_.RPr.Sz.Val := docx_to_pdf_.Font.GetDefaultSz();
{self.}Init();
{self.}SetLvlText();
@ -768,7 +769,7 @@ begin
end
else if element.LocalName = "r" then
begin
{self.}SetRRPr(element, ppr_);
{self.}SetRRPr(element, ppr_unit_decorator_);
if element.FldChar.FldCharType = "begin" then
begin
fld_struct := new DTPUtils.FldStruct();
@ -845,6 +846,7 @@ function PRange.RFootnoteReference(r: R);
begin
return;
docx_to_pdf_.Note.AddFootnoteId(r.FootnoteReference.Id);
rpr := new RPrUnitDecorator(r.RPr);
if not rpr.Sz.Val then rpr.Sz.Val := rpr.SzCs.Val ? rpr.SzCs.Val : docx_to_pdf_.Font.GetDefaultSz();
font_name := rpr.RFonts.Ascii ?: rpr.RFonts.EastAsia;
font_obj := docx_to_pdf_.Font.GetCNSFont(font_name, rpr.B.IsApplied, rpr.I.IsApplied);
@ -869,13 +871,14 @@ begin
id := r.Drawing._Inline.Graphic.GraphicData.Pic.BlipFill.Blip.Embed;
[image_type, image] := {self.}GetImageData(id);
if not image then return;
xfrm := r.Drawing._Inline.Graphic.GraphicData.Pic.SpPr.Xfrm;
xfrm := new XfrmUnitDecorator(r.Drawing._Inline.Graphic.GraphicData.Pic.SpPr.Xfrm);
rpr := new RPrUnitDecorator(r.RPr);
image_range := new ImageRange();
image_range.Image := image;
image_range.Type := image_type;
image_range.Width := xfrm.Ext.CX;
image_range.DynamicHeight := xfrm.Ext.CY;
image_range.RPr := r.RPr;
image_range.RPr := rpr;
body_range_array_[length(body_range_array_)] := image_range;
end
end;
@ -892,12 +895,13 @@ begin
if startsStr("width:", str) then w := strtofloat(str[7:length(str)-2]);
else if startsStr("height:", str) then h := strtofloat(str[8:length(str)-2]);
end
rpr := new RPrUnitDecorator(r.RPr);
image_range := new ImageRange();
image_range.Image := image;
image_range.Type := image_type;
image_range.Width := w;
image_range.DynamicHeight := h;
image_range.RPr := r.RPr;
image_range.RPr := rpr;
body_range_array_[length(body_range_array_)] := image_range;
end;
@ -936,9 +940,9 @@ begin
end
if fld_struct.Status = 1 then
begin
rpr := r.RPr;
if fld_struct.Type.Page then
begin
rpr := new RPrUnitDecorator(r.RPr);
if not rpr.Sz.Val then rpr.Sz.Val := rpr.SzCs.Val ? rpr.SzCs.Val : docx_to_pdf_.Font.GetDefaultSz();
font_name := rpr.RFonts.EastAsia ? rpr.RFonts.EastAsia : rpr.RFonts.Ascii;
font_obj := docx_to_pdf_.Font.GetCNSFont(font_name, rpr.B.IsApplied, rpr.I.IsApplied);
@ -953,6 +957,7 @@ begin
end
else if fld_struct.Type.NumPages then
begin
rpr := new RPrUnitDecorator(r.RPr);
if not rpr.Sz.Val then rpr.Sz.Val := rpr.SzCs.Val ? rpr.SzCs.Val : docx_to_pdf_.Font.GetDefaultSz();
font_name := rpr.RFonts.EastAsia ? rpr.RFonts.EastAsia : rpr.RFonts.Ascii;
font_obj := docx_to_pdf_.Font.GetCNSFont(font_name, rpr.B.IsApplied, rpr.I.IsApplied);
@ -998,11 +1003,12 @@ begin
end
end
r := fld_simple.Rs(0);
{self.}SetRRPr(r, ppr_);
{self.}SetRRPr(r, ppr_unit_decorator_);
if fld_struct.Type.NumPages then
begin
if fld_struct.Arabic then
begin
rpr := new RPrUnitDecorator(r.RPr);
if not rpr.Sz.Val then rpr.Sz.Val := rpr.SzCs.Val ? rpr.SzCs.Val : docx_to_pdf_.Font.GetDefaultSz();
font_name := rpr.RFonts.EastAsia ? rpr.RFonts.EastAsia : rpr.RFonts.Ascii;
font_obj := docx_to_pdf_.Font.GetCNSFont(font_name, rpr.B.IsApplied, rpr.I.IsApplied);
@ -1041,7 +1047,8 @@ begin
else if separate then
begin
docx_to_pdf_.Toc.AddDocxPage(hyperlink.Anchor, r);
rpr := r.RPr;
rpr := new RPrUnitDecorator(r.RPr);
if not rpr.Sz.Val then rpr.Sz.Val := rpr.SzCs.Val ? rpr.SzCs.Val : docx_to_pdf_.Font.GetDefaultSz();
font_name := rpr.RFonts.EastAsia ? rpr.RFonts.EastAsia : rpr.RFonts.Ascii;
font_obj := docx_to_pdf_.Font.GetCNSFont(font_name, rpr.B.IsApplied, rpr.I.IsApplied);
@ -1054,7 +1061,7 @@ begin
if not fld_stack.Empty() then continue;
if r.T then
begin
{self.}SetRRPr(r, ppr_);
{self.}SetRRPr(r, ppr_unit_decorator_);
r.RPr.Color.Val := nil;
{self.}RT(r);
end
@ -1092,6 +1099,7 @@ end;
function PRange.HyperlinkToToc();
begin
ppr_ := ppr_unit_decorator_;
for anchor, arr in hyperlink_hash_ do
begin
text := arr[0];
@ -1191,13 +1199,13 @@ function PRange.BasicRangesToPLineRange();
begin
line_range_array_ := array();
{self.}DynamicHeight := 0;
{self.}DynamicHeight += ppr_.Spacing.Before;
{self.}DynamicHeight += ppr_unit_decorator_.Spacing.Before;
// 段落的x偏移是缩进
{self.}XOffset := ppr_.Ind.LeftChars ? ppr_.Ind.LeftChars * ppr_.RPr.Sz.Val : ppr_.Ind.Left;
{self.}XOffset := ppr_unit_decorator_.Ind.LeftChars ? ppr_unit_decorator_.Ind.LeftChars * ppr_unit_decorator_.RPr.Sz.Val : ppr_unit_decorator_.Ind.Left;
{self.}YOffset := 0;
pline_range := {self.}NewPLineRange();
pline_range.XOffset := ppr_.Ind.FirstLine; // 首行有间距.用offsetx作为位置计算
pline_range.XOffset := ppr_unit_decorator_.Ind.FirstLine; // 首行有间距.用offsetx作为位置计算
i := 0;
anchor := nil;
while i < length(body_range_array_) do
@ -1213,8 +1221,8 @@ begin
if range is class(TextRange) and range.RPr.Sz.Val > pline_range.TextMaxSize then
pline_range.TextMaxSize := range.RPr.Sz.Val;
if range.DynamicHeight > pline_range.DynamicHeight then pline_range.DynamicHeight := range.DynamicHeight;
// range.AdjustOffset(pline_range.XOffset, 0);
range.XOffset := pline_range.XOffset;
range.AdjustOffset(pline_range.XOffset, 0);
// range.XOffset := pline_range.XOffset;
range.Parent := pline_range;
pline_range.AddRange(range);
pline_range.XOffset += range.Width;
@ -1228,10 +1236,10 @@ begin
if length(line_range_array_) = 0 then
begin
line_space := {self.}GetParagraphLineSpace(ppr_.RPr.Sz.Val, ppr_.Spacing.Line, ppr_.Spacing.LineRule);
line_space := {self.}GetParagraphLineSpace(ppr_unit_decorator_.RPr.Sz.Val, ppr_unit_decorator_.Spacing.Line, ppr_unit_decorator_.Spacing.LineRule);
{self.}DynamicHeight += line_space;
end
{self.}DynamicHeight += ppr_.Spacing.After;
{self.}DynamicHeight += ppr_unit_decorator_.Spacing.After;
// println("line_range_array_ = {}", line_range_array_);
end;
@ -1246,7 +1254,7 @@ end;
function PRange.AddPLineRange(pline_range: PLineRange);
begin
pline_range.LineSpace := {self.}GetParagraphLineSpace(pline_range.TextMaxSize, ppr_.Spacing.Line, ppr_.Spacing.LineRule);
pline_range.LineSpace := {self.}GetParagraphLineSpace(pline_range.TextMaxSize, ppr_unit_decorator_.Spacing.Line, ppr_unit_decorator_.Spacing.LineRule);
pline_range.DynamicHeight := max(pline_range.LineSpace, pline_range.DynamicHeight);
pline_range.Index := length(line_range_array_);
line_range_array_[length(line_range_array_)] := pline_range;
@ -1299,11 +1307,11 @@ begin
{self.}EndY := {self.}LowerBound;
// 段前距只有不换页情况才计算
if not {self.}CheckAndAddPage({self.}EndY, ppr_.Spacing.Before) then
{self.}EndY -= ppr_.Spacing.Before;
if not {self.}CheckAndAddPage({self.}EndY, ppr_unit_decorator_.Spacing.Before) then
{self.}EndY -= ppr_unit_decorator_.Spacing.Before;
// 检查是否有段前分页
if ppr_.PageBreakBefore then
if ppr_unit_decorator_.PageBreakBefore then
{self.}CheckAndAddPage({self.}LowerBound, 1);
for _,line_range in line_range_array_ do
@ -1312,7 +1320,7 @@ begin
if {self.}CheckAndAddPage(y, line_range.DynamicHeight) then // 行不够时候调整上一页LowerBound
docx_to_pdf_.PageManager[{self.}EndPage.Index - 1].LowerBound := y;
line_range.Offset({self.}EndX, {self.}EndY, {self.}EndPage);
line_range.Align(ppr_.Jc.Val);
line_range.Align(ppr_unit_decorator_.Jc.Val);
{self.}EndY := line_range.EndY;
end
if not {self.}Parent is class(TcRange) then
@ -1320,7 +1328,7 @@ begin
if length(line_range_array_) = 0 then // 空段落
begin
line_space := {self.}GetParagraphLineSpace(ppr_.RPr.Sz.Val, ppr_.Spacing.Line, ppr_.Spacing.LineRule);
line_space := {self.}GetParagraphLineSpace(ppr_unit_decorator_.RPr.Sz.Val, ppr_unit_decorator_.Spacing.Line, ppr_unit_decorator_.Spacing.LineRule);
{self.}EndY -= line_space;
end
@ -1328,7 +1336,7 @@ begin
{self.}DoAlternateContentAnchor();
{self.}DoToc();
{self.}EndY -= ppr_.Spacing.After;
{self.}EndY -= ppr_unit_decorator_.Spacing.After;
end;
function PRange.DoToc();
@ -1344,9 +1352,9 @@ begin
id := anchor.Graphic.GraphicData.Pic.BlipFill.Blip.Embed;
[image_type, image] := {self.}GetImageData(id);
if not image then return;
xfrm := anchor.Graphic.GraphicData.Pic.SpPr.Xfrm;
position_h := anchor.PositionH;
position_v := anchor.PositionV;
xfrm := new XfrmUnitDecorator(anchor.Graphic.GraphicData.Pic.SpPr.Xfrm);
position_h := new PositionHUnitDecorator(anchor.PositionH);
position_v := new PositionVUnitDecorator(anchor.PositionV);
[x, y] := {self.}GetXYCordinates();
if position_h.RelativeFrom = "paragraph" then
x := {self.}StartY;
@ -1370,9 +1378,9 @@ begin
begin
wsp := anchor.Graphic.GraphicData.Wsp;
[x, y] := {self.}GetXYCordinates();
xfrm := wsp.SpPr.Xfrm;
position_h := anchor.PositionH;
position_v := anchor.PositionV;
xfrm := new XfrmUnitDecorator(wsp.SpPr.Xfrm);
position_h := new PositionHUnitDecorator(anchor.PositionH);
position_v := new PositionVUnitDecorator(anchor.PositionV);
if position_h.RelativeFrom = "paragraph" then
x := {self.}StartY;
if position_v.RelativeFrom = "paragraph" then
@ -1380,7 +1388,7 @@ begin
x += position_h.PosOffset.Text;
y -= position_v.PosOffset.Text;
w := xfrm.Ext.CX;
body_pr := wsp.BodyPr;
body_pr := new BodyPrUnitDecorator(wsp.BodyPr);
x += body_pr.LIns;
w -= (body_pr.LIns + body_pr.RIns);
ps := wsp.Txbx.TxbxContent.Ps();
@ -1444,11 +1452,12 @@ end;
function PRange.RT(r: R; anchor: string);
begin
rpr := new DocxMLUnitDecorator.RPrUnitDecorator(r.RPr);
text := r.T.Text;
if text then {self.}SplitTextToTextRange(body_range_array_, text, r.rpr, anchor);
if text then {self.}SplitTextToTextRange(body_range_array_, text, rpr, anchor);
end;
function PRange.SplitTextToTextRange(range_arr: array of BasicRange; text: string; rpr: RPr; anchor: string);
function PRange.SplitTextToTextRange(range_arr: array of BasicRange; text: string; rpr: RPrUnitDecorator; anchor: string);
begin
pos := 1;
if not rpr.Sz.Val then rpr.Sz.Val := rpr.SzCs.Val ? rpr.SzCs.Val : docx_to_pdf_.Font.GetDefaultSz();
@ -1518,17 +1527,15 @@ end;
function PRange.SetPPPr(var p: P);
begin
if not p.PPr then
begin
new_ppr := new PPr();
styles := docx_to_pdf_.DocxComponents.GetStyles();
p.PPr := styles.DocDefaults.PPrDefault.PPr;
end
else begin
if p.PPr.PStyle.Val then
{self.}SetPPrByStyleId(p.PPr, p.PPr.PStyle.Val);
else if {self.}Parent is class(TcRange) then
{self.}SetPPrByStyleId(p.PPr, {self.}Parent.GetTblStyleId());
end
new_ppr.Copy(styles.DocDefaults.PPrDefault.PPr);
new_ppr.RPr.Copy(styles.DocDefaults.RPrDefault.RPr);
if {self.}Parent is class(TcRange) then
{self.}SetPPrByStyleId(new_ppr, {self.}Parent.GetTblStyleId());
{self.}SetPPrByStyleId(new_ppr, p.PPr.PStyle.Val);
new_ppr.Copy(p.PPr);
p.PPr.Copy(new_ppr);
end;
function PRange.SetPPrByStyleId(var ppr: PPr; style_id: string);
@ -1537,27 +1544,24 @@ begin
style := styles.GetStyleByStyleId(style_id);
if ifObj(style) then
begin
ppr.SetFallback(style.PPr);
based_on := style.BasedOn.Val;
{self.}SetPPrByStyleId(ifnil(style.PPr) ? ppr : style.PPr, based_on);
{self.}SetPPrByStyleId(ppr, based_on);
ppr.Copy(style.PPr);
ppr.RPr.Copy(style.RPr);
end
end;
function PRange.SetRRPr(var r: R; ppr_: PPr);
function PRange.SetRRPr(var r: R; ppr_unit_decorator: PPrUnitDecorator);
begin
if ifnil(r.RPr) then
begin
new_rpr := new RPr();
styles := docx_to_pdf_.DocxComponents.GetStyles();
r.RPr := styles.DocDefaults.RPrDefault.RPr;
end
else begin
if r.RPr.RStyle.Val then
{self.}SetRPrByStyleId(r.RPr, r.RPr.RStyle.Val);
else if ppr_.PStyle.Val then
{self.}SetRPrByStyleId(r.RPr, ppr_.PStyle.Val);
else if {self.}Parent is class(TcRange) then
{self.}SetRPrByTblStyleId(r.RPr, {self.}Parent.GetTblStyleId());
end
new_rpr.Copy(styles.DocDefaults.RPrDefault.RPr);
if {self.}Parent is class(TcRange) then
{self.}SetRPrByTblStyleId(new_rpr, {self.}Parent.GetTblStyleId());
{self.}SetRPrByStyleId(new_rpr, ppr_unit_decorator.PStyle.Val);
{self.}SetRPrByStyleId(new_rpr, r.RPr.RStyle.Val);
new_rpr.Copy(r.RPr);
r.RPr.Copy(new_rpr);
end;
function PRange.SetRPrByTblStyleId(var rpr: RPr; style_id: string);
@ -1565,11 +1569,16 @@ begin
styles := docx_to_pdf_.DocxComponents.GetStylesAdapter();
style := styles.GetStyleByStyleId(style_id);
if ifObj(style) then
begin
based_on := style.BasedOn.Val;
{self.}SetRPrByTblStyleId(rpr, based_on);
rpr.Copy(style.RPr);
end
if {self.}Parent is class(TcRange) then
begin
pr_type := {self.}Parent.GetPrType();
tbl_style_pr := docx_to_pdf_.DocxComponents.GetTblStylePrByType(style_id, pr_type);
rpr.SetFallback(tbl_style_pr.RPr);
{self.}SetRPrByTblStyleId(ifnil(tbl_style_pr.RPr) ? rpr : tbl_style_pr.RPr, style.BasedOn.Val);
if tbl_style_pr then rpr.Copy(tbl_style_pr.RPr);
end
end;
@ -1579,9 +1588,9 @@ begin
style := styles.GetStyleByStyleId(style_id);
if ifObj(style) then
begin
rpr.SetFallback(style.RPr);
based_on := style.BasedOn.Val;
{self.}SetRPrByStyleId(ifnil(style.RPr) ? rpr : style.RPr, based_on);
{self.}SetRPrByStyleId(rpr, based_on);
rpr.Copy(style.RPr);
end
end;
@ -1591,9 +1600,10 @@ begin
if not ifObj(numbering_module) then return;
[lvl_text, lvl] := numbering_module.GetNumberLvl(p_.PPr);
if lvl_text = "" and ifnil(lvl) then return;
{self.}SetRRPr(lvl, ppr_);
{self.}SetRRPr(lvl, ppr_unit_decorator_);
rpr := new RPrUnitDecorator(lvl.RPr);
// {self.}SplitTextToTextRange(bullet_range_array_, lvl_text, rpr);
{self.}SplitTextToTextRange(body_range_array_, lvl_text, lvl.RPr);
{self.}SplitTextToTextRange(body_range_array_, lvl_text, rpr);
end;
function PRange.GetXYCordinates(): array of real;
@ -1681,8 +1691,8 @@ begin
else begin
lines := roundto(line / 240, -1);
multi := ceil(size / docx_to_pdf_.CurrentSect.BaseSize);
if (not ifnil(ppr_.SnapToGrid) and not ppr_.SnapToGrid) or
((ifnil(ppr_.SnapToGrid) or ppr_.SnapToGrid) and lines > multi) then
if (not ifnil(ppr_unit_decorator_.SnapToGrid) and not ppr_unit_decorator_.SnapToGrid) or
((ifnil(ppr_unit_decorator_.SnapToGrid) or ppr_unit_decorator_.SnapToGrid) and lines > multi) then
multi *= lines;
return docx_to_pdf_.CurrentSect.SectPr.DocGrid.LinePitch * multi;
end
@ -1694,7 +1704,7 @@ begin
docx_to_pdf_ := docx_to_pdf;
tc_ := tc;
trp_ := trp;
tc_pr_ := tc_.TcPr;
tc_pr_unit_decorator_ := new TcPrUnitDecorator(tc_.TcPr);
content_next_page_ := false;
top_ := false;
end;
@ -1783,7 +1793,7 @@ begin
region := new DTPUtils.Region();
region.BordersRange.Width := {self.}Width;
region.BordersRange.FixedHeight := {self.}FixedHeight;
region.BordersRange.TcPr := tc_pr_;
region.BordersRange.TcPr := tc_pr_unit_decorator_;
{self.}SetBorderRange(region.BordersRange);
region_array_[length(region_array_)] := region;
@ -1826,7 +1836,7 @@ begin
region.BordersRange.EndY := y;
region.BordersRange.EndPage := pg;
region.BordersRange.DynamicHeight := page_remaining_height;
region.BordersRange.TcPr := tc_pr_;
region.BordersRange.TcPr := tc_pr_unit_decorator_;
region.BordersRange.Top := true;
region.BordersRange.Bottom := true;
{self.}SetBorderRange(region.BordersRange);
@ -1845,7 +1855,7 @@ begin
region.BordersRange.EndY := y;
region.BordersRange.EndPage := pg;
region.BordersRange.DynamicHeight := surplus;
region.BordersRange.TcPr := tc_pr_;
region.BordersRange.TcPr := tc_pr_unit_decorator_;
region.BordersRange.Top := true;
page_hash[pg.Index] := region;
{self.}SetBorderRange(region.BordersRange);
@ -1897,26 +1907,26 @@ begin
begin
if tbl_pr.TblBorders.Top then
begin
if not tc_pr_.TcBorders.Top then
tc_pr_.TcBorders.Top.SetFallback(tbl_pr.TblBorders.Top);
if not tc_pr_unit_decorator_.TcBorders.Top then
tc_pr_unit_decorator_.TcBorders.Top.Copy(tbl_pr.TblBorders.Top);
range.Top := true;
end
if tbl_pr.TblBorders.InsideH and {self.}VMerge <> {self.}Parent.Rows-1 then
begin
if not tc_pr_.TcBorders.Bottom then
tc_pr_.TcBorders.Bottom.SetFallback(tbl_pr.TblBorders.InsideH);
if not tc_pr_unit_decorator_.TcBorders.Bottom then
tc_pr_unit_decorator_.TcBorders.Bottom.Copy(tbl_pr.TblBorders.InsideH);
range.Bottom := true;
end
if tbl_pr.TblBorders.InsideV and {self.}Col <> {self.}Parent.Cols()-1 then
begin
if not tc_pr_.TcBorders.Right then
tc_pr_.TcBorders.Right.SetFallback(tbl_pr.TblBorders.InsideV);
if not tc_pr_unit_decorator_.TcBorders.Right then
tc_pr_unit_decorator_.TcBorders.Right.Copy(tbl_pr.TblBorders.InsideV);
range.Right := true;
end
if tbl_pr.TblBorders.Bottom and {self.}VMerge = {self.}Parent.Rows-1 then
begin
if not tc_pr_.TcBorders.Bottom then
tc_pr_.TcBorders.Bottom.SetFallback(tbl_pr.TblBorders.Bottom);
if not tc_pr_unit_decorator_.TcBorders.Bottom then
tc_pr_unit_decorator_.TcBorders.Bottom.Copy(tbl_pr.TblBorders.Bottom);
range.Bottom := true;
end
end
@ -1924,34 +1934,34 @@ begin
begin
if tbl_pr.TblBorders.Bottom then
begin
if not tc_pr_.TcBorders.Bottom then
tc_pr_.TcBorders.Bottom.SetFallback(tbl_pr.TblBorders.Bottom);
if not tc_pr_unit_decorator_.TcBorders.Bottom then
tc_pr_unit_decorator_.TcBorders.Bottom.Copy(tbl_pr.TblBorders.Bottom);
range.Bottom := true;
end
if tbl_pr.TblBorders.InsideV and {self.}Col <> {self.}Parent.Cols()-1 then
begin
if not tc_pr_.TcBorders.Right then
tc_pr_.TcBorders.Right.SetFallback(tbl_pr.TblBorders.InsideV);
if not tc_pr_unit_decorator_.TcBorders.Right then
tc_pr_unit_decorator_.TcBorders.Right.Copy(tbl_pr.TblBorders.InsideV);
range.Right := true;
end
end
else begin
if tbl_pr.TblBorders.Bottom and {self.}VMerge = {self.}Parent.Rows-1 then
begin
if not tc_pr_.TcBorders.Bottom then
tc_pr_.TcBorders.Bottom.SetFallback(tbl_pr.TblBorders.Bottom);
if not tc_pr_unit_decorator_.TcBorders.Bottom then
tc_pr_unit_decorator_.TcBorders.Bottom.Copy(tbl_pr.TblBorders.Bottom);
range.Bottom := true;
end
if tbl_pr.TblBorders.InsideH and {self.}VMerge <> {self.}Parent.Rows-1 then
begin
if not tc_pr_.TcBorders.Bottom then
tc_pr_.TcBorders.Bottom.SetFallback(tbl_pr.TblBorders.InsideH);
if not tc_pr_unit_decorator_.TcBorders.Bottom then
tc_pr_unit_decorator_.TcBorders.Bottom.Copy(tbl_pr.TblBorders.InsideH);
range.Bottom := true;
end
if tbl_pr.TblBorders.InsideV and {self.}Col <> {self.}Parent.Cols()-1 then
begin
if not tc_pr_.TcBorders.Right then
tc_pr_.TcBorders.Right.SetFallback(tbl_pr.TblBorders.InsideV);
if not tc_pr_unit_decorator_.TcBorders.Right then
tc_pr_unit_decorator_.TcBorders.Right.Copy(tbl_pr.TblBorders.InsideV);
range.Right := true;
end
end
@ -1960,8 +1970,8 @@ begin
begin
if tbl_pr.TblBorders.Left then
begin
if not tc_pr_.TcBorders.Left then
tc_pr_.TcBorders.Left.SetFallback(tbl_pr.TblBorders.Left);
if not tc_pr_unit_decorator_.TcBorders.Left then
tc_pr_unit_decorator_.TcBorders.Left.Copy(tbl_pr.TblBorders.Left);
range.Left := true;
end
end
@ -1969,8 +1979,8 @@ begin
begin
if tbl_pr.TblBorders.Right then
begin
if not tc_pr_.TcBorders.Right then
tc_pr_.TcBorders.Right.SetFallback(tbl_pr.TblBorders.Right);
if not tc_pr_unit_decorator_.TcBorders.Right then
tc_pr_unit_decorator_.TcBorders.Right.Copy(tbl_pr.TblBorders.Right);
range.Right := true;
end
end
@ -2018,9 +2028,9 @@ end;
function TblRange.Calc();
begin
{self.}SetTblTblPr(tbl_);
tbl_pr_:= tbl_.TblPr;
tbl_grid_:= tbl_.TblGrid;
grid_cols_ := tbl_grid_.GridCols();
tbl_pr_unit_decorator_ := new TblPrUnitDecorator(tbl_.TblPr);
tbl_grid_unit_decorator := new TblGridUnitDecorator(tbl_.TblGrid);
grid_cols_ := tbl_grid_unit_decorator.GridCols();
// 如果是根据内容自适应应该计算并调整grid_cols的值
trs := tbl_.Trs();
rows_ := length(trs);
@ -2031,12 +2041,12 @@ begin
{self.}CreateTableMatrix(grid_cols_, trs);
end;
function TblRange.CreateTableMatrix(grid_cols: array of GridCol; trs: array of Tr);
function TblRange.CreateTableMatrix(grid_cols: array of GridColUnitDecorator; trs: array of Tr);
begin
for i,tr in trs do
begin
{self.}SetTrTrPr(tr);
tr_pr := tr.TrPr;
tr_pr := new TrPrUnitDecorator(tr.TrPr);
tc_x := 0;
trp := new DTPUtils.TrProperty();
trp.TrPr := tr_pr;
@ -2045,12 +2055,13 @@ begin
pos := 0;
for j,tc in tcs do
begin
if i = 0 then {self.}SetTcTcPr(tc, "firstRow");
else if i = length(trs)-1 then {self.}SetTcTcPr(tc, "lastRow")
else if (i + 1) % 2 = 0 then {self.}SetTcTcPr(tc, "band1Horz");
else {self.}SetTcTcPr(tc, "band2Horz");
{self.}SetTcTcPr(tc);
if i = 0 then {self.}OverrideTcPrByTblStylePrType(tc.TcPr, "firstRow");
else if i = length(trs)-1 then {self.}OverrideTcPrByTblStylePrType(tc.TcPr, "lastRow")
else if (i + 1) % 2 = 0 then {self.}OverrideTcPrByTblStylePrType(tc.TcPr, "band1Horz");
else {self.}OverrideTcPrByTblStylePrType(tc.TcPr, "band2Horz");
grid_span := tc.TcPr.GridSpan;
grid_span := new GridSpanUnitDecorator(tc.TcPr.GridSpan);
if tc.TcPr.VMerge.IsApplied and tc.TcPr.VMerge.Val <> "restart" then
begin
tc_x += grid_cols[pos++].W;
@ -2091,7 +2102,7 @@ begin
{self.}StartX := x + {self.}XOffset;
{self.}StartY := y + {self.}YOffset; // table的offset实际都为0
{self.}StartPage := page;
{self.}ResetCoordinates(tbl_pr_, grid_cols_);
{self.}ResetCoordinates(tbl_pr_unit_decorator_, grid_cols_);
{self.}EndX := {self.}StartX;
{self.}EndY := {self.}StartY;
{self.}EndPage := {self.}StartPage;
@ -2195,11 +2206,19 @@ begin
{self.}Width := total_width;
end;
function TblRange.OverrideTcPrByTblStylePrType(var tc_pr: TcPr; type: string);
begin
// tc_pr应该是经过外层copy的
tbl_style_pr := docx_to_pdf_.DocxComponents.GetTblStylePrByType(tbl_pr_unit_decorator_.TblStyle.Val, type);
if tbl_style_pr then tc_pr.Copy(tbl_style_pr.TcPr);
end;
function TblRange.SetTblTblPr(var tbl: Tbl);
begin
if ifnil(tbl.TblPr) then
tbl.TblPr := new TblPr();
{self.}SetTblPrByStyleId(tbl.TblPr, tbl.TblPr.TblStyle.Val);
new_tbl_pr := new TblPr();
{self.}SetTblPrByStyleId(new_tbl_pr, tbl.TblPr.TblStyle.Val);
new_tbl_pr.Copy(tbl.TblPr);
tbl.TblPr.Copy(new_tbl_pr);
end;
function TblRange.SetTblPrByStyleId(var tbl_pr: TblPr; style_id: string);
@ -2208,17 +2227,18 @@ begin
style := styles.GetStyleByStyleId(style_id);
if ifObj(style) then
begin
tbl_pr.SetFallback(style.TblPr);
based_on := style.BasedOn.Val;
{self.}SetTblPrByStyleId(ifnil(style.TblPr) ? tbl_pr : style.TblPr, based_on);
{self.}SetTblPrByStyleId(tbl_pr, based_on);
tbl_pr.Copy(style.TblPr);
end
end;
function TblRange.SetTrTrPr(var tr: Tr);
begin
if ifnil(tr.TrPr) then
tr.TrPr := new TrPr();
{self.}SetTrPrByStyleId(tr.TrPr, tbl_pr_.TblStyle.Val);
new_tr_pr := new TrPr();
{self.}SetTrPrByStyleId(new_tr_pr, tbl_pr_unit_decorator_.TblStyle.Val);
new_tr_pr.Copy(tr.TrPr);
tr.TrPr.Copy(new_tr_pr);
end;
function TblRange.SetTrPrByStyleId(var tr_pr: TrPr; style_id: string);
@ -2227,36 +2247,29 @@ begin
style := styles.GetStyleByStyleId(style_id);
if ifObj(style) then
begin
tr_pr.SetFallback(style.TrPr);
based_on := style.BasedOn.Val;
{self.}SetTrPrByStyleId(ifnil(style.TrPr) ? tr_pr : style.TrPr, based_on);
{self.}SetTrPrByStyleId(tr_pr, based_on);
tr_pr.Copy(style.TrPr);
end
end;
function TblRange.SetTcTcPr(var tc: Tc; type: string);
function TblRange.SetTcTcPr(var tc: Tc);
begin
if ifnil(tc.TcPr) then
tc.TcPr := new TcPr();
{self.}SetTcPrByStyleId(tc.TcPr, tbl_pr_.TblStyle.Val, type);
new_tc_pr := new TcPr();
{self.}SetTcPrByStyleId(new_tc_pr, tbl_pr_unit_decorator_.TblStyle.Val);
new_tc_pr.Copy(tc.TcPr);
tc.TcPr.Copy(new_tc_pr);
end;
function TblRange.SetTcPrByStyleId(var tc_pr: TcPr; style_id: string; type: string);
function TblRange.SetTcPrByStyleId(var tc_pr: TcPr; style_id: string);
begin
if type then
begin
style := docx_to_pdf_.DocxComponents.GetTblStylePrByType(style_id, type);
if ifObj(style) then
tc_pr.SetFallback(style.TcPr);
end
else begin
styles := docx_to_pdf_.DocxComponents.GetStylesAdapter();
style := styles.GetStyleByStyleId(style_id);
if ifObj(style) then
begin
tc_pr.SetFallback(style.TcPr);
based_on := style.BasedOn.Val;
{self.}SetTcPrByStyleId(ifnil(style.TcPr) ? tc_pr : style.TcPr, based_on);
end
{self.}SetTcPrByStyleId(tc_pr, based_on);
tc_pr.Copy(style.TcPr);
end
end;
@ -2424,7 +2437,7 @@ begin
styles := docx_to_pdf_.DocxComponents.GetStyles();
default_rpr := styles.DocDefaults.RPrDefault.RPr;
default_rpr.SetFallback(rpr);
if rpr then default_rpr.Copy(rpr);
{self.}BaseSz := strtofloat(default_rpr.Sz.Val) / 2;
end;

View File

@ -94,7 +94,7 @@ public
function AddElement(element: tslobj);
public
SectPr: SectPr;
SectPr: SectPrUnitDecorator;
Elements: array of tslobj;
BaseSize: real;
end;
@ -142,7 +142,7 @@ public
public
Index: integer;
Number: integer;
SectPr: SectPr;
SectPr: SectPrUnitDecorator;
TextPoint: Point; // 正文坐标
FtrPoint: Point; // 页脚坐标
HdrPoint: Point; // 页眉坐标
@ -185,7 +185,6 @@ function DocxComponentsModule.GetStyles(): Styles;
begin
if styles_deserialize_flag_ then return {self.}Styles;
{self.}Styles.Deserialize();
{self.}Styles.ConvertToPoint();
styles_deserialize_flag_ := true;
return {self.}Styles;
end;
@ -210,7 +209,6 @@ begin
if numbering_module_ then return numbering_module_;
if not {self.}Numbering then return nil;
{self.}Numbering.Deserialize();
{self.}Numbering.ConvertToPoint();
numbering_module_ := new NumberingModule({self.}Numbering);
return numbering_module_;
end;
@ -232,7 +230,6 @@ begin
index := replaceStr(replaceStr(target, "footer", ""), ".xml", "");
obj := {self.}Footers(strtoint(index));
obj.Deserialize();
obj.ConvertToPoint();
ftr_hash_[target] := obj;
return obj;
end;
@ -243,7 +240,6 @@ begin
index := replaceStr(replaceStr(target, "header", ""), ".xml", "");
obj := {self.}Headers(strtoint(index));
obj.Deserialize();
obj.ConvertToPoint();
hdr_hash_[target] := obj;
return obj;
end;
@ -275,7 +271,6 @@ begin
if footnotes_adapter_ then return footnotes_adapter_;
obj := {self.}Footnotes;
obj.Deserialize();
obj.ConvertToPoint();
footnotes_adapter_ := new FootnotesAdapter(obj);
return footnotes_adapter_;
end;

View File

@ -30,7 +30,7 @@ public
function Do();override;
public
RPr: RPr;
RPr: RPrUnitDecorator;
Text: string;
Font: PdfFont;
Type: integer; // 0默认1: 数字2英文3中文4中文标点5,.英文逗号和点
@ -43,7 +43,7 @@ public
function DoFill();
public
TcPr: TcPr;
TcPr: TcPrUnitDecorator;
Left: boolean;
Top: boolean;
Right: boolean;
@ -60,7 +60,7 @@ public
function Do();override;
public
RPr: RPr;
RPr: RPrUnitDecorator;
Image: PdfImage;
Type: string;
end;

View File

@ -54,7 +54,7 @@ public
function Create();
public
TrPr: TrPr;
TrPr: TrPrUnitDecorator;
Height: real;
end;