OfficeVba/docx/shading/TSDocxShadingRange.tsf

174 lines
4.4 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Type TSDocxShadingRange = Class(TSDocxShading)
Uses TSDocxEnumerations;
public
Function Init(rangeObj);
Function Apply();override;
private
Function GetShadingObjectByNode(node);
Function GetShading(arr, hash);
Function CallFunction(fname, value);overload;
Function CallFunction(fname);overload;
Function SplitRun();
private
range_obj_;
public
Function WriteTexture(value);override;
Function ReadTexture();override;
Function WriteForegroundPatternColorIndex(value);override;
Function ReadForegroundPatternColorIndex();override;
Function WriteForegroundPatternColor(value);override;
Function ReadForegroundPatternColor();override;
Function WriteBackgroundPatternColorIndex(value);override;
Function ReadBackgroundPatternColorIndex();override;
Function WriteBackgroundPatternColor(value);override;
Function ReadBackgroundPatternColor();override;
End;
// ============== 实现 ================= //
Function TSDocxShadingRange.Init(rangeObj);
Begin
range_obj_ := rangeObj;
class(TSDocxShading).Init(nil);
End;
Function TSDocxShadingRange.Apply();override;
Begin
CallFunction(ThisFunction(class(TSDocxShading).Apply), nil);
End;
Function TSDocxShadingRange.SplitRun();
Begin
range_obj_.SplitRangeRun();
self.Parent.SetRangeObj(range_obj_);
End;
Function TSDocxShadingRange.GetShading(arr, hash);
Begin
if arr.Entirety then
begin
if not ifnil(hash[arr.Entirety]) then nil;
hash[arr.Entirety] := true;
shading := GetShadingObjectByNode(arr.Entirety);
end
else begin
trun := arr.TRun;
if not ifObj(trun.Root()) then return nil;
shading := new TSDocxShading(self.Application, self.Creator, self.Parent);
shading.Init(trun.rPr.Shading);
end
return shading;
End;
Function TSDocxShadingRange.GetShadingObjectByNode(node);
Begin
name := node.GetName();
if name = "w:p" then
begin
obj := TOfficeObj("TParagraph");
obj.Init(node);
paragraph_obj := new TSDocxParagraph(self.Application, self.Creator, self.Parent);
paragraph_obj.Init(nil, obj, nil);
return paragraph_obj.Shading();
end
else if name = "w:tbl" then
begin
obj := TOfficeObj("TTable");
obj.Init(node);
table_obj := new TSDocxTable(self.Application, self.Creator, self.Parent);
table_obj.Init(nil, obj);
return table_obj.Shading();
end
else if name = "w:tc" then
begin
cell_obj := new TSDocxCell(self.Application, self.Creator, self.Parent);
cell_obj.Init(node);
return cell_obj.Shading();
end
End;
Function TSDocxShadingRange.CallFunction(fname, value);overload;
Begin
// 这样设计是为了段落走走段落的shadingtable走table的cell走cell的
SplitRun();
hash := array();
for i:=0 to range_obj_.Size()-1 do
begin
shading := GetShading(range_obj_[i], hash);
if ifnil(shading) then continue;
pf := FindFunction(fname, shading);
pf.Do(value);
end
End;
Function TSDocxShadingRange.CallFunction(fname);overload;
Begin
hash := array();
ret := nil;
for i:=0 to range_obj_.Size()-1 do
begin
shading := GetShading(range_obj_[i], hash);
if ifnil(shading) then continue;
pf := FindFunction(fname, shading);
r := pf.Do();
if ifnil(ret) then ret := r;
if ret <> r then return TSDocxEnumerations.WdUnderline();
end
return ret;
End;
// property
Function TSDocxShadingRange.WriteTexture(value);override;
Begin
CallFunction("WriteTexture", value);
End;
Function TSDocxShadingRange.ReadTexture();override;
Begin
CallFunction("ReadTexture");
End;
Function TSDocxShadingRange.WriteForegroundPatternColorIndex(value);override;
Begin
CallFunction("WriteForegroundPatternColorIndex", value);
End;
Function TSDocxShadingRange.ReadForegroundPatternColorIndex();override;
Begin
CallFunction("ReadForegroundPatternColorIndex");
End;
Function TSDocxShadingRange.WriteForegroundPatternColor(value);override;
Begin
CallFunction("WriteForegroundPatternColor", value);
End;
Function TSDocxShadingRange.ReadForegroundPatternColor();override;
Begin
CallFunction("ReadForegroundPatternColor");
End;
Function TSDocxShadingRange.WriteBackgroundPatternColorIndex(value);override;
Begin
CallFunction("WriteBackgroundPatternColorIndex", value);
End;
Function TSDocxShadingRange.ReadBackgroundPatternColorIndex();override;
Begin
CallFunction("ReadBackgroundPatternColorIndex");
End;
Function TSDocxShadingRange.WriteBackgroundPatternColor(value);override;
Begin
CallFunction("WriteBackgroundPatternColor", value);
End;
Function TSDocxShadingRange.ReadBackgroundPatternColor();override;
Begin
CallFunction("ReadBackgroundPatternColor");
End;