diff --git a/autoclass/adapter/docx/StyleAdapter@DOCX.tsf b/autoclass/adapter/docx/StyleAdapter@DOCX.tsf new file mode 100644 index 0000000..a8df4cc --- /dev/null +++ b/autoclass/adapter/docx/StyleAdapter@DOCX.tsf @@ -0,0 +1,36 @@ +type StyleAdapter = class +public + function Create(_obj: Style); + function Init(); + + function GetTblStylePrByType(_key: string); + function SetTblStylePrByType(_key: string; _value: tslobj); + +private + object_: Style; + tblstylepr_hash_: tableArray; +end; + +function StyleAdapter.Create(_obj: Style); +begin + object_ := _obj; + tblstylepr_hash_ := array(); + {self.}Init(); +end; + +function StyleAdapter.Init(); +begin + elements := object_.TblStylePrs(); + for k,v in elements do + tblstylepr_hash_[v.Type] := v; +end; + +function StyleAdapter.GetTblStylePrByType(_key: string); +begin + return tblstylepr_hash_[_key]; +end; + +function StyleAdapter.SetTblStylePrByType(_key: string; _value: tslobj); +begin + tblstylepr_hash_[_key] := _value; +end; diff --git a/autoclass/decorator/docx/GridSpanUnitDecorator@DOCX.tsf b/autoclass/decorator/docx/GridSpanUnitDecorator@DOCX.tsf new file mode 100644 index 0000000..db0a5e9 --- /dev/null +++ b/autoclass/decorator/docx/GridSpanUnitDecorator@DOCX.tsf @@ -0,0 +1,26 @@ +type GridSpanUnitDecorator = class(GridSpan) +uses TSSafeUnitConverter; +public + function Create(_obj: GridSpan); + function GetObject(); + function Convert(); +private + object_: GridSpan; +end; + +function GridSpanUnitDecorator.Create(_obj: GridSpan); +begin + class(GridSpan).Create(); + object_ := _obj; + {self.}Convert(); +end; + +function GridSpanUnitDecorator.GetObject(); +begin + return object_; +end; + +function GridSpanUnitDecorator.Convert(); +begin + {self.}XmlAttrVal.Value := TSSafeUnitConverter.ToInt(object_.XmlAttrVal.Value); +end; \ No newline at end of file diff --git a/autoclass/decorator/docx/PgNumTypeUnitDecorator@DOCX.tsf b/autoclass/decorator/docx/PgNumTypeUnitDecorator@DOCX.tsf index cc0b9e6..c4b223d 100644 --- a/autoclass/decorator/docx/PgNumTypeUnitDecorator@DOCX.tsf +++ b/autoclass/decorator/docx/PgNumTypeUnitDecorator@DOCX.tsf @@ -22,5 +22,5 @@ end; function PgNumTypeUnitDecorator.Convert(); begin - {self.}XmlAttrStart.Value := object_.XmlAttrStart.Value; + {self.}XmlAttrStart.Value := TSSafeUnitConverter.ToInt(object_.XmlAttrStart.Value); end; \ No newline at end of file diff --git a/autoclass/decorator/docx/StyleUnitDecorator@DOCX.tsf b/autoclass/decorator/docx/StyleUnitDecorator@DOCX.tsf index fd33ddb..24adc7e 100644 --- a/autoclass/decorator/docx/StyleUnitDecorator@DOCX.tsf +++ b/autoclass/decorator/docx/StyleUnitDecorator@DOCX.tsf @@ -41,5 +41,4 @@ begin {self.}TblPr := new TblPrUnitDecorator(object_.TblPr); {self.}TrPr := new TrPrUnitDecorator(object_.TrPr); {self.}TcPr := new TcPrUnitDecorator(object_.TcPr); - {self.}TblStylePr := new TblStylePrUnitDecorator(object_.TblStylePr); end; \ No newline at end of file diff --git a/autoclass/decorator/docx/TblPrUnitDecorator@DOCX.tsf b/autoclass/decorator/docx/TblPrUnitDecorator@DOCX.tsf index e8b8678..fd9fc7b 100644 --- a/autoclass/decorator/docx/TblPrUnitDecorator@DOCX.tsf +++ b/autoclass/decorator/docx/TblPrUnitDecorator@DOCX.tsf @@ -22,6 +22,8 @@ end; function TblPrUnitDecorator.Convert(); begin + {self.}TblStyleRowBandSize := new PureWValUnitDecorator(object_.TblStyleRowBandSize); + {self.}TblStyleColBandSize := new PureWValUnitDecorator(object_.TblStyleColBandSize); {self.}Jc := new PureWValUnitDecorator(object_.Jc); {self.}TblStyle := new PureWValUnitDecorator(object_.TblStyle); {self.}TblW := new TblWUnitDecorator(object_.TblW); diff --git a/autoclass/decorator/docx/TblStylePrUnitDecorator@DOCX.tsf b/autoclass/decorator/docx/TblStylePrUnitDecorator@DOCX.tsf index f62231e..b6084f7 100644 --- a/autoclass/decorator/docx/TblStylePrUnitDecorator@DOCX.tsf +++ b/autoclass/decorator/docx/TblStylePrUnitDecorator@DOCX.tsf @@ -22,6 +22,7 @@ end; function TblStylePrUnitDecorator.Convert(); begin + {self.}XmlAttrType.Value := object_.XmlAttrType.Value; {self.}PPr := new PPrUnitDecorator(object_.PPr); {self.}TblPr := new TblPrUnitDecorator(object_.TblPr); {self.}TrPr := new TrPrUnitDecorator(object_.TrPr); diff --git a/autoclass/decorator/docx/TcPrUnitDecorator@DOCX.tsf b/autoclass/decorator/docx/TcPrUnitDecorator@DOCX.tsf index 3488e0b..a261703 100644 --- a/autoclass/decorator/docx/TcPrUnitDecorator@DOCX.tsf +++ b/autoclass/decorator/docx/TcPrUnitDecorator@DOCX.tsf @@ -23,8 +23,8 @@ end; function TcPrUnitDecorator.Convert(); begin {self.}TcW := new TblWUnitDecorator(object_.TcW); - {self.}GridSpan := new PureWValUnitDecorator(object_.GridSpan); - {self.}VMerge := new PureWValUnitDecorator(object_.VMerge); + {self.}GridSpan := new GridSpanUnitDecorator(object_.GridSpan); + if not ifnil(object_.XmlChildVMerge.Value) then {self.}XmlChildVMerge.Value := object_.XmlChildVMerge.Value; {self.}VAlign := new PureWValUnitDecorator(object_.VAlign); {self.}Shd := new ShdUnitDecorator(object_.Shd); end; \ No newline at end of file diff --git a/autoclass/docx/GridSpan@DOCX.tsf b/autoclass/docx/GridSpan@DOCX.tsf new file mode 100644 index 0000000..c0f8632 --- /dev/null +++ b/autoclass/docx/GridSpan@DOCX.tsf @@ -0,0 +1,81 @@ +type GridSpan = class(OpenXmlElement) +public + function Create();overload; + function Create(_node: XmlNode);overload; + function Create(_parent: tslobj; _prefix: string; _local_name: string);overload; + function Init();override; + function InitAttributes();override; + function InitChildren();override; + function InitNode(_node: XmlNode);override; + function Copy(_obj: GridSpan);override; + + property Val read ReadXmlAttrVal write WriteXmlAttrVal; + function ReadXmlAttrVal(); + function WriteXmlAttrVal(_value); + +public + // Attributes + XmlAttrVal: OpenXmlAttribute; + + // Children + +end; + +function GridSpan.Create();overload; +begin + {self.}Create(nil, "w", "gridSpan"); +end; + +function GridSpan.Create(_node: XmlNode);overload; +begin + class(OpenXmlElement).Create(_node: XmlNode); +end; + +function GridSpan.Create(_parent: tslobj; _prefix: string; _local_name: string);overload; +begin + class(OpenXmlElement).Create(_parent, _prefix, _local_name); +end; + +function GridSpan.Init();override; +begin + {self.}XmlAttrVal := new OpenXmlAttribute({self.}Prefix, "val", nil); +end; + +function GridSpan.InitAttributes();override; +begin + attributes_ := array( + {self.}XmlAttrVal, + ); +end; + +function GridSpan.InitChildren();override; +begin + child_elements_ := array( + ); + sorted_child_ := array( + "": -1, + ); +end; + +function GridSpan.InitNode(_node: XmlNode);override; +begin + if ifObj({self.}XmlNode) then + for k,v in child_elements_ do v.InitNode(nil); + {self.}XmlNode := ifObj(_node) ? _node : nil; +end; + +function GridSpan.Copy(_obj: GridSpan);override; +begin + if not ifnil(_obj.XmlAttrVal.Value) then + {self.}XmlAttrVal.Value := _obj.XmlAttrVal.Value; +end; + +function GridSpan.ReadXmlAttrVal(); +begin + return {self.}XmlAttrVal.Value; +end; + +function GridSpan.WriteXmlAttrVal(_value); +begin + {self.}XmlAttrVal.Value := _value; +end; diff --git a/autoclass/docx/Style@DOCX.tsf b/autoclass/docx/Style@DOCX.tsf index e280c84..e490dcc 100644 --- a/autoclass/docx/Style@DOCX.tsf +++ b/autoclass/docx/Style@DOCX.tsf @@ -8,6 +8,11 @@ public function InitChildren();override; function InitNode(_node: XmlNode);override; function Copy(_obj: Style);override; + function AddTblStylePr(): TblStylePr; + function AppendTblStylePr(): TblStylePr; + + property TblStylePrs read ReadTblStylePrs; + function ReadTblStylePrs(_index); property Type read ReadXmlAttrType write WriteXmlAttrType; property Default read ReadXmlAttrDefault write WriteXmlAttrDefault; @@ -54,7 +59,6 @@ public TblPr: TblPr; TrPr: TrPr; TcPr: TcPr; - TblStylePr: TblStylePr; end; @@ -93,7 +97,6 @@ begin {self.}TblPr := new TblPr(self, {self.}Prefix, "tblPr"); {self.}TrPr := new TrPr(self, {self.}Prefix, "trPr"); {self.}TcPr := new TcPr(self, {self.}Prefix, "tcPr"); - {self.}TblStylePr := new TblStylePr(self, {self.}Prefix, "tblStylePr"); end; function Style.InitAttributes();override; @@ -123,7 +126,6 @@ begin 12: {self.}TblPr, 13: {self.}TrPr, 14: {self.}TcPr, - 15: {self.}TblStylePr, ); sorted_child_ := array( "": -1, @@ -142,7 +144,6 @@ begin {self.}TblPr.ElementName: 12, {self.}TrPr.ElementName: 13, {self.}TcPr.ElementName: 14, - {self.}TblStylePr.ElementName: 15, ); end; @@ -168,6 +169,7 @@ begin begin obj := nil; case node_name of + pre + "tblStylePr": obj := {self.}AppendTblStylePr(); end; if ifObj(obj) then obj.InitNode(node); end @@ -207,7 +209,42 @@ begin {self.}TblPr.Copy(_obj.TblPr); {self.}TrPr.Copy(_obj.TrPr); {self.}TcPr.Copy(_obj.TcPr); - {self.}TblStylePr.Copy(_obj.TblStylePr); +end; + +function Style.AddTblStylePr(): TblStylePr; +begin + len := length(child_elements_); + if len = 0 then i := -1; + else begin + for i:=len-1 downto 0 do + if child_elements_[i].LocalName = "tblStylePr" then break; + end + obj := new TblStylePr(self, {self.}Prefix, "tblStylePr"); + {self.}InsertChild(obj, i+1); + return obj; +end; + +function Style.AppendTblStylePr(): TblStylePr; +begin + obj := new TblStylePr(self, {self.}Prefix, "tblStylePr"); + child_elements_[length(child_elements_)] := obj; + return obj; +end; + +function Style.ReadTblStylePrs(_index); +begin + ind := ifnil(_index) ? -2 : _index; + arr := array(); + for k,v in child_elements_ do + begin + if v.LocalName = "tblStylePr" then + begin + arr[length(arr)] := v; + ind--; + end; + if ind = -1 then return v; + end; + return arr; end; function Style.ReadXmlAttrType(); diff --git a/autoclass/docx/TblPr@DOCX.tsf b/autoclass/docx/TblPr@DOCX.tsf index 3be7c6e..9cd0a56 100644 --- a/autoclass/docx/TblPr@DOCX.tsf +++ b/autoclass/docx/TblPr@DOCX.tsf @@ -13,6 +13,8 @@ public // Attributes // Children + TblStyleRowBandSize: PureWVal; + TblStyleColBandSize: PureWVal; Jc: PureWVal; TblStyle: PureWVal; TblW: TblW; @@ -41,6 +43,8 @@ end; function TblPr.Init();override; begin + {self.}TblStyleRowBandSize := new PureWVal(self, {self.}Prefix, "tblStyleRowBandSize"); + {self.}TblStyleColBandSize := new PureWVal(self, {self.}Prefix, "tblStyleColBandSize"); {self.}Jc := new PureWVal(self, {self.}Prefix, "jc"); {self.}TblStyle := new PureWVal(self, {self.}Prefix, "tblStyle"); {self.}TblW := new TblW(self, {self.}Prefix, "tblW"); @@ -60,25 +64,29 @@ end; function TblPr.InitChildren();override; begin child_elements_ := array( - 0: {self.}Jc, - 1: {self.}TblStyle, - 2: {self.}TblW, - 3: {self.}TblInd, - 4: {self.}TblLayout, - 5: {self.}TblLook, - 6: {self.}TblBorders, - 7: {self.}TblCellMar, + 0: {self.}TblStyleRowBandSize, + 1: {self.}TblStyleColBandSize, + 2: {self.}Jc, + 3: {self.}TblStyle, + 4: {self.}TblW, + 5: {self.}TblInd, + 6: {self.}TblLayout, + 7: {self.}TblLook, + 8: {self.}TblBorders, + 9: {self.}TblCellMar, ); sorted_child_ := array( "": -1, - {self.}Jc.ElementName: 0, - {self.}TblStyle.ElementName: 1, - {self.}TblW.ElementName: 2, - {self.}TblInd.ElementName: 3, - {self.}TblLayout.ElementName: 4, - {self.}TblLook.ElementName: 5, - {self.}TblBorders.ElementName: 6, - {self.}TblCellMar.ElementName: 7, + {self.}TblStyleRowBandSize.ElementName: 0, + {self.}TblStyleColBandSize.ElementName: 1, + {self.}Jc.ElementName: 2, + {self.}TblStyle.ElementName: 3, + {self.}TblW.ElementName: 4, + {self.}TblInd.ElementName: 5, + {self.}TblLayout.ElementName: 6, + {self.}TblLook.ElementName: 7, + {self.}TblBorders.ElementName: 8, + {self.}TblCellMar.ElementName: 9, ); end; @@ -122,6 +130,8 @@ end; function TblPr.Copy(_obj: TblPr);override; begin + {self.}TblStyleRowBandSize.Copy(_obj.TblStyleRowBandSize); + {self.}TblStyleColBandSize.Copy(_obj.TblStyleColBandSize); {self.}Jc.Copy(_obj.Jc); {self.}TblStyle.Copy(_obj.TblStyle); {self.}TblW.Copy(_obj.TblW); diff --git a/autoclass/docx/TblStylePr@DOCX.tsf b/autoclass/docx/TblStylePr@DOCX.tsf index b661b41..c8c862d 100644 --- a/autoclass/docx/TblStylePr@DOCX.tsf +++ b/autoclass/docx/TblStylePr@DOCX.tsf @@ -9,8 +9,13 @@ public function InitNode(_node: XmlNode);override; function Copy(_obj: TblStylePr);override; + property Type read ReadXmlAttrType write WriteXmlAttrType; + function ReadXmlAttrType(); + function WriteXmlAttrType(_value); + public // Attributes + XmlAttrType: OpenXmlAttribute; // Children PPr: PPr; @@ -37,6 +42,7 @@ end; function TblStylePr.Init();override; begin + {self.}XmlAttrType := new OpenXmlAttribute({self.}Prefix, "type", nil); {self.}PPr := new PPr(self, {self.}Prefix, "pPr"); {self.}TblPr := new TblPr(self, {self.}Prefix, "tblPr"); {self.}TrPr := new TrPr(self, {self.}Prefix, "trPr"); @@ -46,6 +52,7 @@ end; function TblStylePr.InitAttributes();override; begin attributes_ := array( + {self.}XmlAttrType, ); end; @@ -106,8 +113,20 @@ end; function TblStylePr.Copy(_obj: TblStylePr);override; begin + if not ifnil(_obj.XmlAttrType.Value) then + {self.}XmlAttrType.Value := _obj.XmlAttrType.Value; {self.}PPr.Copy(_obj.PPr); {self.}TblPr.Copy(_obj.TblPr); {self.}TrPr.Copy(_obj.TrPr); {self.}TcPr.Copy(_obj.TcPr); end; + +function TblStylePr.ReadXmlAttrType(); +begin + return {self.}XmlAttrType.Value; +end; + +function TblStylePr.WriteXmlAttrType(_value); +begin + {self.}XmlAttrType.Value := _value; +end; diff --git a/autoclass/docx/TcPr@DOCX.tsf b/autoclass/docx/TcPr@DOCX.tsf index 226a582..9d3e9f5 100644 --- a/autoclass/docx/TcPr@DOCX.tsf +++ b/autoclass/docx/TcPr@DOCX.tsf @@ -9,13 +9,17 @@ public function InitNode(_node: XmlNode);override; function Copy(_obj: TcPr);override; + property VMerge read ReadXmlChildVMerge write WriteXmlChildVMerge; + function ReadXmlChildVMerge(); + function WriteXmlChildVMerge(_value); + public // Attributes // Children TcW: TblW; - GridSpan: PureWVal; - VMerge: PureWVal; + GridSpan: GridSpan; + XmlChildVMerge: OpenXmlEmpty; VAlign: PureWVal; Shd: Shd; @@ -39,8 +43,8 @@ end; function TcPr.Init();override; begin {self.}TcW := new TblW(self, {self.}Prefix, "tcW"); - {self.}GridSpan := new PureWVal(self, {self.}Prefix, "gridSpan"); - {self.}VMerge := new PureWVal(self, {self.}Prefix, "vMerge"); + {self.}GridSpan := new GridSpan(self, {self.}Prefix, "gridSpan"); + {self.}XmlChildVMerge := new OpenXmlEmpty(self, {self.}Prefix, "vMerge"); {self.}VAlign := new PureWVal(self, {self.}Prefix, "vAlign"); {self.}Shd := new Shd(self, {self.}Prefix, "shd"); end; @@ -56,7 +60,7 @@ begin child_elements_ := array( 0: {self.}TcW, 1: {self.}GridSpan, - 2: {self.}VMerge, + 2: {self.}XmlChildVMerge, 3: {self.}VAlign, 4: {self.}Shd, ); @@ -64,7 +68,7 @@ begin "": -1, {self.}TcW.ElementName: 0, {self.}GridSpan.ElementName: 1, - {self.}VMerge.ElementName: 2, + {self.}XmlChildVMerge.ElementName: 2, {self.}VAlign.ElementName: 3, {self.}Shd.ElementName: 4, ); @@ -112,7 +116,17 @@ function TcPr.Copy(_obj: TcPr);override; begin {self.}TcW.Copy(_obj.TcW); {self.}GridSpan.Copy(_obj.GridSpan); - {self.}VMerge.Copy(_obj.VMerge); + {self.}XmlChildVMerge.Copy(_obj.XmlChildVMerge); {self.}VAlign.Copy(_obj.VAlign); {self.}Shd.Copy(_obj.Shd); end; + +function TcPr.ReadXmlChildVMerge(); +begin + return ifnil({self.}XmlChildVMerge.Value) ? false : true; +end; + +function TcPr.WriteXmlChildVMerge(_value); +begin + {self.}XmlChildVMerge.Value := _value; +end; diff --git a/utils/TSSafeUnitConverter.tsf b/utils/TSSafeUnitConverter.tsf index 0ac7215..29debfe 100644 --- a/utils/TSSafeUnitConverter.tsf +++ b/utils/TSSafeUnitConverter.tsf @@ -4,6 +4,7 @@ interface function EmusToPoints(value): real; function HalfPointToPoints(value): real; function PercentToNumber(value): real; + function ToInt(value): integer; implementation @@ -37,5 +38,11 @@ uses TSUnitConverter; return TSUnitConverter.PercentToNumber(new_value); end; + function ToInt(value): integer; + begin + if ifNil(value) then return 0; + return tryStrtoInt(value, r) ? r : 0; + end; + end.