diff --git a/TSDocxToPdf.tsf b/TSDocxToPdf.tsf index 210773e..5d3996c 100644 --- a/TSDocxToPdf.tsf +++ b/TSDocxToPdf.tsf @@ -1,5 +1,5 @@ type TSDocxToPdf = class -uses TSPdfEnumerations, DocxML, DocxMLAdapter, DocxMLUnitDecorator, DTPModules, DTPUtils, DTPAdvancedRanges; +uses TSPdfEnumerations, DocxML, DocxMLAdapter, 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.GetObject()); + current_sect_pr_adapter_ := new SectPrAdapter(current_sect_module_.SectPr); {self.}AddPage(true); end @@ -182,6 +182,7 @@ begin current_sect_pr_adapter_ := nil; document := docx_components_module_.Document; document.Deserialize(); + document.ConvertToPoint(); {self.}AllocateElementsToSectModule(); end; @@ -191,7 +192,6 @@ 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_.PPrUnitDecorator.OutlineLvl.Val) and (range is class(TblRange) or ifnil(range.PPrUnitDecorator.OutlineLvl.Val)) then + 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 begin - if last_range_.PPrUnitDecorator.Spacing.AfterAutospacing then + if last_range_.P.PPr.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.PPrUnitDecorator.OutlineLvl.Val) and (last_range_ is class(TblRange) or ifnil(last_range_.PPrUnitDecorator.OutlineLvl.Val)) then + 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 begin - if range.PPrUnitDecorator.Spacing.BeforeAutospacing then + if range.P.PPr.Spacing.BeforeAutospacing then begin line_range := range.PLineRanges(); line_range := line_range[length(line_range)-1]; diff --git a/internal/DTPAdvancedRanges.tsf b/internal/DTPAdvancedRanges.tsf index 2a5584b..9e5a8af 100644 --- a/internal/DTPAdvancedRanges.tsf +++ b/internal/DTPAdvancedRanges.tsf @@ -1,6 +1,6 @@ unit DTPAdvancedRanges; interface -uses DTPPrimitiveRanges, DTPUtils, DTPModules, SharedML, DocxML, DrawingMLUnitDecorator, DocxMLUnitDecorator, TSPdfEnumerations; +uses DTPPrimitiveRanges, DTPUtils, DTPModules, SharedML, DocxML, TSPdfEnumerations; type AdvancedRange = class(BasicRange) public @@ -98,7 +98,7 @@ public function IsFirstLineOnNextPage(): boolean; function PLineRanges(): array of PLineRange; - property PPrUnitDecorator read ppr_unit_decorator_; + property P read p_; 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_unit_decorator: PPrUnitDecorator); + function SetRRPr(var r: R; ppr_: PPr); 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: RPrUnitDecorator; anchor: string); + function SplitTextToTextRange(range_arr: array of BasicRange; text: string; rpr: RPr; anchor: string); function RBr(r: R); function RFootnoteReference(r: R); @@ -140,7 +140,7 @@ private private [weakref]docx_to_pdf_: TSDocxToPdf; p_: P; - ppr_unit_decorator_: PPrUnitDecorator; + ppr_: PPr; 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_unit_decorator_: TcPrUnitDecorator; + tc_pr_: TcPr; content_next_page_: boolean; range_array_: array of BasicRange; region_array_: array of Region; @@ -202,12 +202,12 @@ public function Calc(): boolean;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 Cols read cols_; 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 SetTblTblPr(var table: Tbl); function SetTblPrByStyleId(var tbl_pr: TblPr; style_id: string); @@ -220,8 +220,8 @@ private private [weakref]docx_to_pdf_: TSDocxToPdf; tbl_: Tbl; - tbl_pr_unit_decorator_: TblPrUnitDecorator; - grid_cols_: array of GridColUnitDecorator; + tbl_pr_: TblPr; + grid_cols_: array of GridCol; rows_: integer; cols_: integer; tc_range_matrix_: array of TcRange; @@ -713,7 +713,7 @@ begin realtime_page_array_ := array(); realtime_numpages_array_ := array(); // 根据段落的间距确定新的坐标 - ppr := ppr_unit_decorator_; + ppr := ppr_; 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; @@ -725,7 +725,7 @@ begin 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 {self.}EndPage.PdfPage.SetLineWidth(0.5); {self.}EndPage.PdfPage.SetGrayStroke(0.25); @@ -747,8 +747,8 @@ function PRange.Calc(): boolean;override; begin // ppr.rpr是无效的,应该以ppr.pStyle为准 {self.}SetPPPr(p_); - 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(); + ppr_ := p_.PPr; + if not ppr_.RPr.Sz.Val then ppr_.RPr.Sz.Val := docx_to_pdf_.Font.GetDefaultSz(); {self.}Init(); {self.}SetLvlText(); @@ -769,7 +769,7 @@ begin end else if element.LocalName = "r" then begin - {self.}SetRRPr(element, ppr_unit_decorator_); + {self.}SetRRPr(element, ppr_); if element.FldChar.FldCharType = "begin" then begin fld_struct := new DTPUtils.FldStruct(); @@ -846,7 +846,6 @@ 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); @@ -871,14 +870,13 @@ begin id := r.Drawing._Inline.Graphic.GraphicData.Pic.BlipFill.Blip.Embed; [image_type, image] := {self.}GetImageData(id); if not image then return; - xfrm := new XfrmUnitDecorator(r.Drawing._Inline.Graphic.GraphicData.Pic.SpPr.Xfrm); - rpr := new RPrUnitDecorator(r.RPr); + xfrm := r.Drawing._Inline.Graphic.GraphicData.Pic.SpPr.Xfrm; 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 := rpr; + image_range.RPr := r.RPr; body_range_array_[length(body_range_array_)] := image_range; end end; @@ -895,13 +893,12 @@ 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 := rpr; + image_range.RPr := r.RPr; body_range_array_[length(body_range_array_)] := image_range; end; @@ -940,9 +937,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); @@ -957,7 +954,6 @@ 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); @@ -1003,12 +999,11 @@ begin end end r := fld_simple.Rs(0); - {self.}SetRRPr(r, ppr_unit_decorator_); + {self.}SetRRPr(r, ppr_); 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); @@ -1047,8 +1042,7 @@ begin else if separate then begin docx_to_pdf_.Toc.AddDocxPage(hyperlink.Anchor, r); - - rpr := new RPrUnitDecorator(r.RPr); + rpr := 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); @@ -1061,7 +1055,7 @@ begin if not fld_stack.Empty() then continue; if r.T then begin - {self.}SetRRPr(r, ppr_unit_decorator_); + {self.}SetRRPr(r, ppr_); r.RPr.Color.Val := nil; {self.}RT(r); end @@ -1099,7 +1093,6 @@ end; function PRange.HyperlinkToToc(); begin - ppr_ := ppr_unit_decorator_; for anchor, arr in hyperlink_hash_ do begin text := arr[0]; @@ -1199,13 +1192,13 @@ function PRange.BasicRangesToPLineRange(); begin line_range_array_ := array(); {self.}DynamicHeight := 0; - {self.}DynamicHeight += ppr_unit_decorator_.Spacing.Before; + {self.}DynamicHeight += ppr_.Spacing.Before; // 段落的x偏移是缩进 - {self.}XOffset := ppr_unit_decorator_.Ind.LeftChars ? ppr_unit_decorator_.Ind.LeftChars * ppr_unit_decorator_.RPr.Sz.Val : ppr_unit_decorator_.Ind.Left; + {self.}XOffset := ppr_.Ind.LeftChars ? ppr_.Ind.LeftChars * ppr_.RPr.Sz.Val : ppr_.Ind.Left; {self.}YOffset := 0; pline_range := {self.}NewPLineRange(); - pline_range.XOffset := ppr_unit_decorator_.Ind.FirstLine; // 首行有间距.用offsetx作为位置计算 + pline_range.XOffset := ppr_.Ind.FirstLine; // 首行有间距.用offsetx作为位置计算 i := 0; anchor := nil; while i < length(body_range_array_) do @@ -1221,8 +1214,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; @@ -1236,10 +1229,10 @@ begin if length(line_range_array_) = 0 then begin - line_space := {self.}GetParagraphLineSpace(ppr_unit_decorator_.RPr.Sz.Val, ppr_unit_decorator_.Spacing.Line, ppr_unit_decorator_.Spacing.LineRule); + line_space := {self.}GetParagraphLineSpace(ppr_.RPr.Sz.Val, ppr_.Spacing.Line, ppr_.Spacing.LineRule); {self.}DynamicHeight += line_space; end - {self.}DynamicHeight += ppr_unit_decorator_.Spacing.After; + {self.}DynamicHeight += ppr_.Spacing.After; // println("line_range_array_ = {}", line_range_array_); end; @@ -1254,7 +1247,7 @@ end; function PRange.AddPLineRange(pline_range: PLineRange); begin - pline_range.LineSpace := {self.}GetParagraphLineSpace(pline_range.TextMaxSize, ppr_unit_decorator_.Spacing.Line, ppr_unit_decorator_.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.Index := length(line_range_array_); line_range_array_[length(line_range_array_)] := pline_range; @@ -1307,11 +1300,11 @@ begin {self.}EndY := {self.}LowerBound; // 段前距只有不换页情况才计算 - if not {self.}CheckAndAddPage({self.}EndY, ppr_unit_decorator_.Spacing.Before) then - {self.}EndY -= ppr_unit_decorator_.Spacing.Before; + if not {self.}CheckAndAddPage({self.}EndY, ppr_.Spacing.Before) then + {self.}EndY -= ppr_.Spacing.Before; // 检查是否有段前分页 - if ppr_unit_decorator_.PageBreakBefore then + if ppr_.PageBreakBefore then {self.}CheckAndAddPage({self.}LowerBound, 1); for _,line_range in line_range_array_ do @@ -1320,7 +1313,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_unit_decorator_.Jc.Val); + line_range.Align(ppr_.Jc.Val); {self.}EndY := line_range.EndY; end if not {self.}Parent is class(TcRange) then @@ -1328,7 +1321,7 @@ begin if length(line_range_array_) = 0 then // 空段落 begin - line_space := {self.}GetParagraphLineSpace(ppr_unit_decorator_.RPr.Sz.Val, ppr_unit_decorator_.Spacing.Line, ppr_unit_decorator_.Spacing.LineRule); + line_space := {self.}GetParagraphLineSpace(ppr_.RPr.Sz.Val, ppr_.Spacing.Line, ppr_.Spacing.LineRule); {self.}EndY -= line_space; end @@ -1336,7 +1329,7 @@ begin {self.}DoAlternateContentAnchor(); {self.}DoToc(); - {self.}EndY -= ppr_unit_decorator_.Spacing.After; + {self.}EndY -= ppr_.Spacing.After; end; function PRange.DoToc(); @@ -1352,9 +1345,9 @@ begin id := anchor.Graphic.GraphicData.Pic.BlipFill.Blip.Embed; [image_type, image] := {self.}GetImageData(id); if not image then return; - xfrm := new XfrmUnitDecorator(anchor.Graphic.GraphicData.Pic.SpPr.Xfrm); - position_h := new PositionHUnitDecorator(anchor.PositionH); - position_v := new PositionVUnitDecorator(anchor.PositionV); + xfrm := anchor.Graphic.GraphicData.Pic.SpPr.Xfrm; + position_h := anchor.PositionH; + position_v := anchor.PositionV; [x, y] := {self.}GetXYCordinates(); if position_h.RelativeFrom = "paragraph" then x := {self.}StartY; @@ -1378,9 +1371,9 @@ begin begin wsp := anchor.Graphic.GraphicData.Wsp; [x, y] := {self.}GetXYCordinates(); - xfrm := new XfrmUnitDecorator(wsp.SpPr.Xfrm); - position_h := new PositionHUnitDecorator(anchor.PositionH); - position_v := new PositionVUnitDecorator(anchor.PositionV); + xfrm := wsp.SpPr.Xfrm; + position_h := anchor.PositionH; + position_v := anchor.PositionV; if position_h.RelativeFrom = "paragraph" then x := {self.}StartY; if position_v.RelativeFrom = "paragraph" then @@ -1388,7 +1381,7 @@ begin x += position_h.PosOffset.Text; y -= position_v.PosOffset.Text; w := xfrm.Ext.CX; - body_pr := new BodyPrUnitDecorator(wsp.BodyPr); + body_pr := wsp.BodyPr; x += body_pr.LIns; w -= (body_pr.LIns + body_pr.RIns); ps := wsp.Txbx.TxbxContent.Ps(); @@ -1452,12 +1445,11 @@ 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, rpr, anchor); + if text then {self.}SplitTextToTextRange(body_range_array_, text, r.rpr, anchor); 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 pos := 1; if not rpr.Sz.Val then rpr.Sz.Val := rpr.SzCs.Val ? rpr.SzCs.Val : docx_to_pdf_.Font.GetDefaultSz(); @@ -1551,14 +1543,14 @@ begin end end; -function PRange.SetRRPr(var r: R; ppr_unit_decorator: PPrUnitDecorator); +function PRange.SetRRPr(var r: R; ppr_: PPr); begin new_rpr := new RPr(); styles := docx_to_pdf_.DocxComponents.GetStyles(); 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, ppr_.PStyle.Val); {self.}SetRPrByStyleId(new_rpr, r.RPr.RStyle.Val); new_rpr.Copy(r.RPr); r.RPr.Copy(new_rpr); @@ -1600,10 +1592,9 @@ 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_unit_decorator_); - rpr := new RPrUnitDecorator(lvl.RPr); + {self.}SetRRPr(lvl, ppr_); // {self.}SplitTextToTextRange(bullet_range_array_, lvl_text, rpr); - {self.}SplitTextToTextRange(body_range_array_, lvl_text, rpr); + {self.}SplitTextToTextRange(body_range_array_, lvl_text, lvl.RPr); end; function PRange.GetXYCordinates(): array of real; @@ -1691,8 +1682,8 @@ begin else begin lines := roundto(line / 240, -1); multi := ceil(size / docx_to_pdf_.CurrentSect.BaseSize); - 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 + if (not ifnil(ppr_.SnapToGrid) and not ppr_.SnapToGrid) or + ((ifnil(ppr_.SnapToGrid) or ppr_.SnapToGrid) and lines > multi) then multi *= lines; return docx_to_pdf_.CurrentSect.SectPr.DocGrid.LinePitch * multi; end @@ -1704,7 +1695,7 @@ begin docx_to_pdf_ := docx_to_pdf; tc_ := tc; trp_ := trp; - tc_pr_unit_decorator_ := new TcPrUnitDecorator(tc_.TcPr); + tc_pr_ := tc_.TcPr; content_next_page_ := false; top_ := false; end; @@ -1793,7 +1784,7 @@ begin region := new DTPUtils.Region(); region.BordersRange.Width := {self.}Width; region.BordersRange.FixedHeight := {self.}FixedHeight; - region.BordersRange.TcPr := tc_pr_unit_decorator_; + region.BordersRange.TcPr := tc_pr_; {self.}SetBorderRange(region.BordersRange); region_array_[length(region_array_)] := region; @@ -1836,7 +1827,7 @@ begin region.BordersRange.EndY := y; region.BordersRange.EndPage := pg; region.BordersRange.DynamicHeight := page_remaining_height; - region.BordersRange.TcPr := tc_pr_unit_decorator_; + region.BordersRange.TcPr := tc_pr_; region.BordersRange.Top := true; region.BordersRange.Bottom := true; {self.}SetBorderRange(region.BordersRange); @@ -1855,7 +1846,7 @@ begin region.BordersRange.EndY := y; region.BordersRange.EndPage := pg; region.BordersRange.DynamicHeight := surplus; - region.BordersRange.TcPr := tc_pr_unit_decorator_; + region.BordersRange.TcPr := tc_pr_; region.BordersRange.Top := true; page_hash[pg.Index] := region; {self.}SetBorderRange(region.BordersRange); @@ -1907,26 +1898,26 @@ begin begin if tbl_pr.TblBorders.Top then begin - if not tc_pr_unit_decorator_.TcBorders.Top then - tc_pr_unit_decorator_.TcBorders.Top.Copy(tbl_pr.TblBorders.Top); + if not tc_pr_.TcBorders.Top then + tc_pr_.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_unit_decorator_.TcBorders.Bottom then - tc_pr_unit_decorator_.TcBorders.Bottom.Copy(tbl_pr.TblBorders.InsideH); + if not tc_pr_.TcBorders.Bottom then + tc_pr_.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_unit_decorator_.TcBorders.Right then - tc_pr_unit_decorator_.TcBorders.Right.Copy(tbl_pr.TblBorders.InsideV); + if not tc_pr_.TcBorders.Right then + tc_pr_.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_unit_decorator_.TcBorders.Bottom then - tc_pr_unit_decorator_.TcBorders.Bottom.Copy(tbl_pr.TblBorders.Bottom); + if not tc_pr_.TcBorders.Bottom then + tc_pr_.TcBorders.Bottom.Copy(tbl_pr.TblBorders.Bottom); range.Bottom := true; end end @@ -1934,34 +1925,34 @@ begin begin if tbl_pr.TblBorders.Bottom then begin - if not tc_pr_unit_decorator_.TcBorders.Bottom then - tc_pr_unit_decorator_.TcBorders.Bottom.Copy(tbl_pr.TblBorders.Bottom); + if not tc_pr_.TcBorders.Bottom then + tc_pr_.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_unit_decorator_.TcBorders.Right then - tc_pr_unit_decorator_.TcBorders.Right.Copy(tbl_pr.TblBorders.InsideV); + if not tc_pr_.TcBorders.Right then + tc_pr_.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_unit_decorator_.TcBorders.Bottom then - tc_pr_unit_decorator_.TcBorders.Bottom.Copy(tbl_pr.TblBorders.Bottom); + if not tc_pr_.TcBorders.Bottom then + tc_pr_.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_unit_decorator_.TcBorders.Bottom then - tc_pr_unit_decorator_.TcBorders.Bottom.Copy(tbl_pr.TblBorders.InsideH); + if not tc_pr_.TcBorders.Bottom then + tc_pr_.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_unit_decorator_.TcBorders.Right then - tc_pr_unit_decorator_.TcBorders.Right.Copy(tbl_pr.TblBorders.InsideV); + if not tc_pr_.TcBorders.Right then + tc_pr_.TcBorders.Right.Copy(tbl_pr.TblBorders.InsideV); range.Right := true; end end @@ -1970,8 +1961,8 @@ begin begin if tbl_pr.TblBorders.Left then begin - if not tc_pr_unit_decorator_.TcBorders.Left then - tc_pr_unit_decorator_.TcBorders.Left.Copy(tbl_pr.TblBorders.Left); + if not tc_pr_.TcBorders.Left then + tc_pr_.TcBorders.Left.Copy(tbl_pr.TblBorders.Left); range.Left := true; end end @@ -1979,8 +1970,8 @@ begin begin if tbl_pr.TblBorders.Right then begin - if not tc_pr_unit_decorator_.TcBorders.Right then - tc_pr_unit_decorator_.TcBorders.Right.Copy(tbl_pr.TblBorders.Right); + if not tc_pr_.TcBorders.Right then + tc_pr_.TcBorders.Right.Copy(tbl_pr.TblBorders.Right); range.Right := true; end end @@ -2028,9 +2019,9 @@ end; function TblRange.Calc(); begin {self.}SetTblTblPr(tbl_); - tbl_pr_unit_decorator_ := new TblPrUnitDecorator(tbl_.TblPr); - tbl_grid_unit_decorator := new TblGridUnitDecorator(tbl_.TblGrid); - grid_cols_ := tbl_grid_unit_decorator.GridCols(); + tbl_pr_:= tbl_.TblPr; + tbl_grid_:= tbl_.TblGrid; + grid_cols_ := tbl_grid_.GridCols(); // 如果是根据内容自适应,应该计算并调整grid_cols的值 trs := tbl_.Trs(); rows_ := length(trs); @@ -2041,12 +2032,12 @@ begin {self.}CreateTableMatrix(grid_cols_, trs); 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 for i,tr in trs do begin {self.}SetTrTrPr(tr); - tr_pr := new TrPrUnitDecorator(tr.TrPr); + tr_pr := tr.TrPr; tc_x := 0; trp := new DTPUtils.TrProperty(); trp.TrPr := tr_pr; @@ -2061,7 +2052,7 @@ begin else if (i + 1) % 2 = 0 then {self.}OverrideTcPrByTblStylePrType(tc.TcPr, "band1Horz"); 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 begin tc_x += grid_cols[pos++].W; @@ -2102,7 +2093,7 @@ begin {self.}StartX := x + {self.}XOffset; {self.}StartY := y + {self.}YOffset; // table的offset实际都为0 {self.}StartPage := page; - {self.}ResetCoordinates(tbl_pr_unit_decorator_, grid_cols_); + {self.}ResetCoordinates(tbl_pr_, grid_cols_); {self.}EndX := {self.}StartX; {self.}EndY := {self.}StartY; {self.}EndPage := {self.}StartPage; @@ -2209,7 +2200,7 @@ 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); + tbl_style_pr := docx_to_pdf_.DocxComponents.GetTblStylePrByType(tbl_pr_.TblStyle.Val, type); if tbl_style_pr then tc_pr.Copy(tbl_style_pr.TcPr); end; @@ -2236,7 +2227,7 @@ end; function TblRange.SetTrTrPr(var tr: Tr); begin new_tr_pr := new TrPr(); - {self.}SetTrPrByStyleId(new_tr_pr, tbl_pr_unit_decorator_.TblStyle.Val); + {self.}SetTrPrByStyleId(new_tr_pr, tbl_pr_.TblStyle.Val); new_tr_pr.Copy(tr.TrPr); tr.TrPr.Copy(new_tr_pr); end; @@ -2256,7 +2247,7 @@ end; function TblRange.SetTcTcPr(var tc: Tc); begin new_tc_pr := new TcPr(); - {self.}SetTcPrByStyleId(new_tc_pr, tbl_pr_unit_decorator_.TblStyle.Val); + {self.}SetTcPrByStyleId(new_tc_pr, tbl_pr_.TblStyle.Val); new_tc_pr.Copy(tc.TcPr); tc.TcPr.Copy(new_tc_pr); end; diff --git a/internal/DTPModules.tsf b/internal/DTPModules.tsf index 5e6708b..c4e1c7d 100644 --- a/internal/DTPModules.tsf +++ b/internal/DTPModules.tsf @@ -94,7 +94,7 @@ public function AddElement(element: tslobj); public - SectPr: SectPrUnitDecorator; + SectPr: SectPr; Elements: array of tslobj; BaseSize: real; end; @@ -142,7 +142,7 @@ public public Index: integer; Number: integer; - SectPr: SectPrUnitDecorator; + SectPr: SectPr; TextPoint: Point; // 正文坐标 FtrPoint: Point; // 页脚坐标 HdrPoint: Point; // 页眉坐标 @@ -185,6 +185,7 @@ 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; @@ -209,6 +210,7 @@ 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; @@ -230,6 +232,7 @@ begin index := replaceStr(replaceStr(target, "footer", ""), ".xml", ""); obj := {self.}Footers(strtoint(index)); obj.Deserialize(); + obj.ConvertToPoint(); ftr_hash_[target] := obj; return obj; end; @@ -240,6 +243,7 @@ begin index := replaceStr(replaceStr(target, "header", ""), ".xml", ""); obj := {self.}Headers(strtoint(index)); obj.Deserialize(); + obj.ConvertToPoint(); hdr_hash_[target] := obj; return obj; end; @@ -271,6 +275,7 @@ begin if footnotes_adapter_ then return footnotes_adapter_; obj := {self.}Footnotes; obj.Deserialize(); + obj.ConvertToPoint(); footnotes_adapter_ := new FootnotesAdapter(obj); return footnotes_adapter_; end; diff --git a/internal/DTPPrimitiveRanges.tsf b/internal/DTPPrimitiveRanges.tsf index f5ae75c..83d5bf8 100644 --- a/internal/DTPPrimitiveRanges.tsf +++ b/internal/DTPPrimitiveRanges.tsf @@ -30,7 +30,7 @@ public function Do();override; public - RPr: RPrUnitDecorator; + RPr: RPr; Text: string; Font: PdfFont; Type: integer; // 0:默认,1: 数字,2:英文,3:中文,4:中文标点,5:,.英文逗号和点 @@ -43,7 +43,7 @@ public function DoFill(); public - TcPr: TcPrUnitDecorator; + TcPr: TcPr; Left: boolean; Top: boolean; Right: boolean; @@ -60,7 +60,7 @@ public function Do();override; public - RPr: RPrUnitDecorator; + RPr: RPr; Image: PdfImage; Type: string; end; diff --git a/internal/DTPUtils.tsf b/internal/DTPUtils.tsf index 8694298..6438ab7 100644 --- a/internal/DTPUtils.tsf +++ b/internal/DTPUtils.tsf @@ -54,7 +54,7 @@ public function Create(); public - TrPr: TrPrUnitDecorator; + TrPr: TrPr; Height: real; end;