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