支持文本框

This commit is contained in:
csh
2024-08-26 15:03:35 +08:00
parent 70ad4acbdb
commit 4c6f4d6e09
3 changed files with 142 additions and 17 deletions
+92 -10
View File
@@ -14,6 +14,7 @@ private
function SetRPrByStyleId(var rpr: RPr; style_id: string);
function SetLvlText();
function GetImageFileType(data: binary): string;
function GetImageData(id: string): PdfImage;
function GetParagraphLineSpace(size: real; line: integer): real;
function BasicRangesToLineRange(): tableArray;
function CheckAndAddPage(y: real; offset: real): boolean;
@@ -21,12 +22,14 @@ private
function RToTextRange(r: R; link: string);
function SplitTextToTextRange(text: string; rpr: RPrUnitDecorator; link: string);
function RToDrawingRange(r: R);
function RAlternateContentToRange(r: R);
function SetLinesAlignment();
function ResetCoordinates();
function NewLineRange(): TSPdfLineRange;
function BookMarkLinkToc();
function HyperlinkToToc();
function HyperlinkToTextRange(hyperlink: Hyperlink; ppr: PPrUnitDecorator);
function GetXYCordinates(): array of real;
private
[weakref]docx_to_pdf_: TSDocxToPdf;
@@ -106,6 +109,7 @@ begin
else if element.Br.Type = "page" then
{self.}CheckAndAddPage({self.}LowerBound, 1);
else if ifObj(element.Drawing.XmlNode) then {self.}RToDrawingRange(element);
else if ifObj(element.AlternateContent.XmlNode) then {self.}RAlternateContentToRange(element);
else if not fld then {self.}RToTextRange(element, bookmark_name);
end
else if element.LocalName = "hyperlink" then
@@ -420,9 +424,93 @@ end;
function TSPdfParagraphRange.RToDrawingRange(r: R);
begin
xfrm := new XfrmUnitDecorator(r.Drawing._Inline.Graphic.GraphicData.Pic.SpPr.Xfrm);
rels_adapter := docx_components_ware_.GetDocumentRelsAdapter();
id := r.Drawing._Inline.Graphic.GraphicData.Pic.BlipFill.Blip.Embed;
if ifObj(r.Drawing._Inline.XmlNode) then
begin
id := r.Drawing._Inline.Graphic.GraphicData.Pic.BlipFill.Blip.Embed;
image := {self.}GetImageData(id);
if not image then return;
xfrm := new XfrmUnitDecorator(r.Drawing._Inline.Graphic.GraphicData.Pic.SpPr.Xfrm);
image_range := new TSPdfImageRange();
image_range.Image := image;
image_range.StartX := xfrm.Off.X;
image_range.StartY := xfrm.Off.Y;
image_range.Width := xfrm.Ext.CX;
image_range.DynamicHeight := xfrm.Ext.CY;
range_array_[length(range_array_)] := image_range;
end
else if ifObj(r.Drawing.Anchor.XmlNode) then
begin
anchor := r.Drawing.Anchor;
id := anchor.Graphic.GraphicData.Pic.BlipFill.Blip.Embed;
image := {self.}GetImageData(id);
if not image then return;
[x, y] := {self.}GetXYCordinates();
xfrm := new XfrmUnitDecorator(anchor.Graphic.GraphicData.Pic.SpPr.Xfrm);
position_h := new PositionHUnitDecorator(anchor.PositionH);
position_v := new PositionVUnitDecorator(anchor.PositionV);
image_range := new TSPdfImageRange();
image_range.Image := image;
image_range.EndX := x + position_h.PosOffset.Text;
image_range.EndY := y - position_v.PosOffset.Text - xfrm.Ext.CY;
image_range.Width := xfrm.Ext.CX;
image_range.DynamicHeight := xfrm.Ext.CY;
image_range.TSPage := page_;
image_range.Do();
end
end;
function TSPdfParagraphRange.RAlternateContentToRange(r: R);
begin
anchor := r.AlternateContent.Choice.Drawing.Anchor;
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);
x += position_h.PosOffset.Text;
y -= position_v.PosOffset.Text;
w := xfrm.Ext.CX;
body_pr := new BodyPrUnitDecorator(wsp.BodyPr);
x += body_pr.LIns;
w -= (body_pr.LIns + body_pr.RIns);
ps := wsp.Txbx.TxbxContent.Ps();
for _,p in ps do
begin
range := new TSPdfParagraphRange(docx_to_pdf_, page_, docx_components_ware_, p);
range.StartX := x;
range.StartY := y;
range.Width := w;
range.Calc();
range.Do();
y := range.EndY;
end
end;
function TSPdfParagraphRange.GetXYCordinates(): array of real;
begin
xml_file := docx_to_pdf_.GetCurrentXmlFile();
if xml_file = "document.xml" then
[x, y] := docx_to_pdf_.CalculateTextCoordinates();
else begin
sect_ware := docx_to_pdf_.GetCurrentSectWare();
x := sect_ware.SectPr.PgMar.Left;
if ansiContainsStr(xml_file, "footer") then
y := sect_ware.SectPr.PgMar.Bottom;
else if ansiContainsStr(xml_file, "header") then
y := sect_ware.SectPr.PgSz.H - sect_ware.SectPr.PgMar.Header;
end
return array(x, y);
end;
function TSPdfParagraphRange.GetImageData(id: string): PdfImage;
begin
xml_file := docx_to_pdf_.GetCurrentXmlFile();
if xml_file = "document.xml" then
rels_adapter := docx_components_ware_.GetDocumentRelsAdapter();
else if ansiContainsStr(xml_file, "footer") then
rels_adapter := docx_components_ware_.GetFtrRelsAdapter(xml_file);
else if ansiContainsStr(xml_file, "header") then
rels_adapter := docx_components_ware_.GetHdrRelsAdapter(xml_file);
rel := rels_adapter.GetRelationshipById(id);
image_path := "word/" + rel.Target;
image := docx_components_ware_.Zip().Get(image_path);
@@ -436,14 +524,8 @@ begin
"jpg":
image := docx_to_pdf_.GetPdf().LoadJpegImageFromFile("", image_path);
end;
image_range := new TSPdfImageRange();
image_range.Image := image;
image_range.StartX := xfrm.Off.X;
image_range.StartY := xfrm.Off.Y;
image_range.Width := xfrm.Ext.CX;
image_range.DynamicHeight := xfrm.Ext.CY;
fileDelete("", image_path);
range_array_[length(range_array_)] := image_range;
return image;
end;
function TSPdfParagraphRange.GetImageFileType(data: binary): string;