|
|
|
@@ -101,6 +101,56 @@ private
|
|
|
|
|
end
|
|
|
|
|
End;
|
|
|
|
|
|
|
|
|
|
Function SetRObject(node);
|
|
|
|
|
Begin
|
|
|
|
|
image_data_node := class(TSXml).GetNode(node, 'v:shape/v:imagedata');
|
|
|
|
|
if not ifObj(node) then return;
|
|
|
|
|
rid := image_data_node.GetAttribute('r:id');
|
|
|
|
|
id := CopyRidContent(rid, 'media/image', 'image');
|
|
|
|
|
if id then image_data_node.SetAttribute('r:id', 'rId' $ id);
|
|
|
|
|
ole_node := class(TSXml).GetNode(node, 'o:OLEObject');
|
|
|
|
|
if not ifObj(node) then return;
|
|
|
|
|
rid := ole_node.GetAttribute('r:id');
|
|
|
|
|
id := CopyRidContent(rid, 'embeddings/oleObject', 'oleObject');
|
|
|
|
|
if id then ole_node.SetAttribute('r:id', 'rId' $ id);
|
|
|
|
|
End;
|
|
|
|
|
|
|
|
|
|
function CopyRidContent(id, tar_prefix, type_postfix);
|
|
|
|
|
begin
|
|
|
|
|
rels := new_docx_obj_.Zip().Get('word/_rels/document.xml.rels');
|
|
|
|
|
target := class(TSXml).FindRelationshipTarget(rels, id);
|
|
|
|
|
image_file := new_docx_obj_.Zip().Get('word/' $ target).Data();
|
|
|
|
|
|
|
|
|
|
// 比较新文件的图片在旧文件中是否存在
|
|
|
|
|
zip := old_docx_obj_.Zip();
|
|
|
|
|
xml := zip.Get('word/_rels/document.xml.rels');
|
|
|
|
|
files := sselect ['FileName'] from zip.Files() where AnsiStartsText('word/' $ tar_prefix, ['FileName']) end;
|
|
|
|
|
for i:=0 to length(files)-1 do Begin
|
|
|
|
|
if zip.Diff(files[i], image_file) = 0 then Begin
|
|
|
|
|
prefix := ReplaceStr(files[i], 'word/', '');
|
|
|
|
|
[maxRid, imageFile, rid] := class(TSXml).FindRelationshipRid(xml, prefix);
|
|
|
|
|
End;
|
|
|
|
|
End;
|
|
|
|
|
if rid = 0 then
|
|
|
|
|
begin
|
|
|
|
|
image_cnt := length(files) + 1;
|
|
|
|
|
if ParseRegExpr("\\w+$", target, "", result, Mpos, Mlen) then
|
|
|
|
|
begin
|
|
|
|
|
postfix := result[0][0];
|
|
|
|
|
image_path := tar_prefix $ image_cnt $ '.' $ postfix;
|
|
|
|
|
[rid, tar] := class(TSXml).FindRelationshipRid(xml, '');
|
|
|
|
|
rid ++;
|
|
|
|
|
class(TSXml).AddRelationshipRid(xml, image_path, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' $ type_postfix, 'rId' $ rid);
|
|
|
|
|
zip.Add('word/' + image_path, image_file);
|
|
|
|
|
contentXml := zip.Get('[Content_Types].xml');
|
|
|
|
|
if postfix = 'wmf' then content_type := 'image/x-wmf';
|
|
|
|
|
else if postfix = 'bin' then content_type := 'application/vnd.openxmlformats-officedocument.oleObject';
|
|
|
|
|
class(TSXml).AddDefaultContentType(contentXml, postfix, content_type);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return rid;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
Function SetPic(node);
|
|
|
|
|
Begin
|
|
|
|
|
// 获取新文件的图片
|
|
|
|
@@ -224,6 +274,9 @@ private
|
|
|
|
|
begin
|
|
|
|
|
CopyFootnote(run);
|
|
|
|
|
CopyStyle(run, 'w:rPr/w:rStyle');
|
|
|
|
|
obj_node := class(TSXml).GetNode(run, 'w:object');
|
|
|
|
|
if ifObj(obj_node) then
|
|
|
|
|
SetRObject(obj_node);
|
|
|
|
|
run := run.NextElement();
|
|
|
|
|
end
|
|
|
|
|
End;
|
|
|
|
|