range重新设计

This commit is contained in:
csh
2023-11-29 17:27:34 +08:00
parent 3781bc96e7
commit f0560b2330
28 changed files with 2829 additions and 383 deletions
+305
View File
@@ -0,0 +1,305 @@
Type TSDocxShading = Class(TSVbaBase)
Uses TSDocxEnumerations;
public
Function Init(shading);
Function Apply();virtual;
private
shading_; // TOfficeObj("TwShading")
color_index_;
color_;
public
property BackgroundPatternColor read ReadBackgroundPatternColor write WriteBackgroundPatternColor;
property BackgroundPatternColorIndex read ReadBackgroundPatternColorIndex write WriteBackgroundPatternColorIndex;
property ForegroundPatternColor read ReadForegroundPatternColor write WriteForegroundPatternColor;
property ForegroundPatternColorIndex read ReadForegroundPatternColorIndex write WriteForegroundPatternColorIndex;
property Texture read ReadTexture write WriteTexture;
Function WriteTexture(value);virtual;
Function ReadTexture();virtual;
Function WriteForegroundPatternColorIndex(value);virtual;
Function ReadForegroundPatternColorIndex();virtual;
Function WriteForegroundPatternColor(value);virtual;
Function ReadForegroundPatternColor();virtual;
Function WriteBackgroundPatternColorIndex(value);virtual;
Function ReadBackgroundPatternColorIndex();virtual;
Function WriteBackgroundPatternColor(value);virtual;
Function ReadBackgroundPatternColor();virtual;
End;
// ============== 实现 ================= //
Function TSDocxShading.Init(shading);
Begin
shading_ := shading;
color_index_ := TSWdColorIndex();
color_ := TSWdColor();
End;
Function TSDocxShading.Apply();virtual;
Begin
shading_.Update();
End;
// property
Function TSDocxShading.WriteTexture(value);
Begin
case value of
TSDocxEnumerations.wdTexture10Percent():
shading_.Val := "pct10";
TSDocxEnumerations.wdTexture12Pt5Percent():
shading_.Val := "pct12";
TSDocxEnumerations.wdTexture15Percent():
shading_.Val := "pct15";
TSDocxEnumerations.wdTexture17Pt5Percent():
shading_.Val := "pct17";
TSDocxEnumerations.wdTexture20Percent():
shading_.Val := "pct20";
TSDocxEnumerations.wdTexture22Pt5Percent():
shading_.Val := "pct22";
TSDocxEnumerations.wdTexture25Percent():
shading_.Val := "pct25";
TSDocxEnumerations.wdTexture27Pt5Percent():
shading_.Val := "clear";
TSDocxEnumerations.wdTexture2Pt5Percent():
shading_.Val := "clear";
TSDocxEnumerations.wdTexture30Percent():
shading_.Val := "pct30";
TSDocxEnumerations.wdTexture32Pt5Percent():
shading_.Val := "pct32";
TSDocxEnumerations.wdTexture35Percent():
shading_.Val := "pct35";
TSDocxEnumerations.wdTexture37Pt5Percent():
shading_.Val := "pct37";
TSDocxEnumerations.wdTexture40Percent():
shading_.Val := "pct40";
TSDocxEnumerations.wdTexture42Pt5Percent():
shading_.Val := "pct42";
TSDocxEnumerations.wdTexture45Percent():
shading_.Val := "pct45";
TSDocxEnumerations.wdTexture47Pt5Percent():
shading_.Val := "pct47";
TSDocxEnumerations.wdTexture50Percent():
shading_.Val := "pct50";
TSDocxEnumerations.wdTexture52Pt5Percent():
shading_.Val := "pct52";
TSDocxEnumerations.wdTexture55Percent():
shading_.Val := "pct55";
TSDocxEnumerations.wdTexture57Pt5Percent():
shading_.Val := "clear";
TSDocxEnumerations.wdTexture5Percent():
shading_.Val := "pct5";
TSDocxEnumerations.wdTexture60Percent():
shading_.Val := "pct60";
TSDocxEnumerations.wdTexture62Pt5Percent():
shading_.Val := "pct62";
TSDocxEnumerations.wdTexture65Percent():
shading_.Val := "pct65";
TSDocxEnumerations.wdTexture67Pt5Percent():
shading_.Val := "pct67";
TSDocxEnumerations.wdTexture70Percent():
shading_.Val := "pct70";
TSDocxEnumerations.wdTexture72Pt5Percent():
shading_.Val := "pct72";
TSDocxEnumerations.wdTexture75Percent():
shading_.Val := "pct75";
TSDocxEnumerations.wdTexture77Pt5Percent():
shading_.Val := "pct77";
TSDocxEnumerations.wdTexture7Pt5Percent():
shading_.Val := "clear";
TSDocxEnumerations.wdTexture80Percent():
shading_.Val := "pct80";
TSDocxEnumerations.wdTexture82Pt5Percent():
shading_.Val := "pct82";
TSDocxEnumerations.wdTexture85Percent():
shading_.Val := "pct85";
TSDocxEnumerations.wdTexture87Pt5Percent():
shading_.Val := "pct87";
TSDocxEnumerations.wdTexture90Percent():
shading_.Val := "pct90";
TSDocxEnumerations.wdTexture92Pt5Percent():
shading_.Val := "pct92";
TSDocxEnumerations.wdTexture95Percent():
shading_.Val := "pct95";
TSDocxEnumerations.wdTexture97Pt5Percent():
shading_.Val := "pct97";
TSDocxEnumerations.wdTextureCross():
shading_.Val := "thinHorzCross";
TSDocxEnumerations.wdTextureDarkCross():
shading_.Val := "HorzCross";
TSDocxEnumerations.wdTextureDarkDiagonalCross():
shading_.Val := "diagCross";
TSDocxEnumerations.wdTextureDarkDiagonalDown():
shading_.Val := "reverseDiagStripe";
TSDocxEnumerations.wdTextureDarkDiagonalUp():
shading_.Val := "diagStripe";
TSDocxEnumerations.wdTextureDarkHorizontal():
shading_.Val := "horzStripe";
TSDocxEnumerations.wdTextureDarkVertical():
shading_.Val := "vertStripe";
TSDocxEnumerations.wdTextureDiagonalCross():
shading_.Val := "thinDiagCross";
TSDocxEnumerations.wdTextureDiagonalDown():
shading_.Val := "thinReverseDiagStripe";
TSDocxEnumerations.wdTextureDiagonalUp():
shading_.Val := "thinDiagStripe";
TSDocxEnumerations.wdTextureHorizontal():
shading_.Val := "thinHorzStripe";
TSDocxEnumerations.wdTextureNone():
shading_.Val := "none";
TSDocxEnumerations.wdTextureSolid():
shading_.Val := "solid";
TSDocxEnumerations.wdTextureVertical():
shading_.Val := "thinVertStripe";
end;
End;
Function TSDocxShading.ReadTexture();
Begin
value := shading_.Value("Val");
case value of
"pct10":
return TSDocxEnumerations.wdTexture10Percent();
"pct12":
return TSDocxEnumerations.wdTexture12Pt5Percent();
"pct15":
return TSDocxEnumerations.wdTexture15Percent();
"pct17":
return TSDocxEnumerations.wdTexture17Pt5Percent();
"pct20":
return TSDocxEnumerations.wdTexture20Percent();
"pct22":
return TSDocxEnumerations.wdTexture22Pt5Percent();
"pct25":
return TSDocxEnumerations.wdTexture25Percent();
"clear":
return TSDocxEnumerations.wdTexture27Pt5Percent();
"clear":
return TSDocxEnumerations.wdTexture2Pt5Percent();
"pct30":
return TSDocxEnumerations.wdTexture30Percent();
"pct32":
return TSDocxEnumerations.wdTexture32Pt5Percent();
"pct35":
return TSDocxEnumerations.wdTexture35Percent();
"pct37":
return TSDocxEnumerations.wdTexture37Pt5Percent();
"pct40":
return TSDocxEnumerations.wdTexture40Percent();
"pct42":
return TSDocxEnumerations.wdTexture42Pt5Percent();
"pct45":
return TSDocxEnumerations.wdTexture45Percent();
"pct47":
return TSDocxEnumerations.wdTexture47Pt5Percent();
"pct50":
return TSDocxEnumerations.wdTexture50Percent();
"pct52":
return TSDocxEnumerations.wdTexture52Pt5Percent();
"pct55":
return TSDocxEnumerations.wdTexture55Percent();
"clear":
return TSDocxEnumerations.wdTexture57Pt5Percent();
"pct5":
return TSDocxEnumerations.wdTexture5Percent();
"pct60":
return TSDocxEnumerations.wdTexture60Percent();
"pct62":
return TSDocxEnumerations.wdTexture62Pt5Percent();
"pct65":
return TSDocxEnumerations.wdTexture65Percent();
"pct67":
return TSDocxEnumerations.wdTexture67Pt5Percent();
"pct70":
return TSDocxEnumerations.wdTexture70Percent();
"pct72":
return TSDocxEnumerations.wdTexture72Pt5Percent();
"pct75":
return TSDocxEnumerations.wdTexture75Percent();
"pct77":
return TSDocxEnumerations.wdTexture77Pt5Percent();
"clear":
return TSDocxEnumerations.wdTexture7Pt5Percent();
"pct80":
return TSDocxEnumerations.wdTexture80Percent();
"pct82":
return TSDocxEnumerations.wdTexture82Pt5Percent();
"pct85":
return TSDocxEnumerations.wdTexture85Percent();
"pct87":
return TSDocxEnumerations.wdTexture87Pt5Percent();
"pct90":
return TSDocxEnumerations.wdTexture90Percent();
"pct92":
return TSDocxEnumerations.wdTexture92Pt5Percent();
"pct95":
return TSDocxEnumerations.wdTexture95Percent();
"pct97":
return TSDocxEnumerations.wdTexture97Pt5Percent();
"thinHorzCross":
return TSDocxEnumerations.wdTextureCross();
"HorzCross":
return TSDocxEnumerations.wdTextureDarkCross();
"diagCross":
return TSDocxEnumerations.wdTextureDarkDiagonalCross();
"reverseDiagStripe":
return TSDocxEnumerations.wdTextureDarkDiagonalDown();
"diagStripe":
return TSDocxEnumerations.wdTextureDarkDiagonalUp();
"horzStripe":
return TSDocxEnumerations.wdTextureDarkHorizontal();
"vertStripe":
return TSDocxEnumerations.wdTextureDarkVertical();
"thinDiagCross":
return TSDocxEnumerations.wdTextureDiagonalCross();
"thinReverseDiagStripe":
return TSDocxEnumerations.wdTextureDiagonalDown();
"thinDiagStripe":
return TSDocxEnumerations.wdTextureDiagonalUp();
"thinHorzStripe":
return TSDocxEnumerations.wdTextureHorizontal();
"none":
return TSDocxEnumerations.wdTextureNone();
"solid":
return TSDocxEnumerations.wdTextureSolid();
"thinVertStripe":
return TSDocxEnumerations.wdTextureVertical();
end;
End;
Function TSDocxShading.WriteForegroundPatternColorIndex(value);
Begin
shading_.Color := color_index_[value];
End;
Function TSDocxShading.ReadForegroundPatternColorIndex();
Begin
return color_index_[shading_.Value("Color")];
End;
Function TSDocxShading.WriteForegroundPatternColor(value);
Begin
shading_.Color := color_[value];
End;
Function TSDocxShading.ReadForegroundPatternColor();
Begin
return color_[shading_.Value("Color")];
End;
Function TSDocxShading.WriteBackgroundPatternColorIndex(value);
Begin
shading_.Fill := color_index_[value];
End;
Function TSDocxShading.ReadBackgroundPatternColorIndex();
Begin
return color_index_[shading_.Value("Fill")];
End;
Function TSDocxShading.WriteBackgroundPatternColor(value);
Begin
shading_.Fill := color_[value];
End;
Function TSDocxShading.ReadBackgroundPatternColor();
Begin
return color_[shading_.Value("Fill")];
End;
+169
View File
@@ -0,0 +1,169 @@
Type TSDocxShadingRange = Class(TSDocxShading)
Uses TSDocxEnumerations;
public
Function Init(rangeObj);
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.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();
range_arr := rangeObj.GetInfo();
for i:=0 to length(range_arr)-1 do
begin
shading := GetShading(range_arr[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;
range_arr := rangeObj.GetInfo();
for i:=0 to length(range_arr)-1 do
begin
shading := GetShading(range_arr[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;