OfficeXml/autoclass/docx/Font@DOCX.tsf

143 lines
3.7 KiB
Plaintext

type Font = 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: Font);override;
property Name read ReadXmlAttrName write WriteXmlAttrName;
function ReadXmlAttrName();
function WriteXmlAttrName(_value);
public
// Attributes
XmlAttrName: OpenXmlAttribute;
// Children
AltName: PureWVal;
Panosel: PureWVal;
Charset: PureWVal;
Family: PureWVal;
Pitch: PureWVal;
Sig: Sig;
end;
function Font.Create();overload;
begin
self.Create(nil, "w", "font");
end;
function Font.Create(_node: XmlNode);overload;
begin
class(OpenXmlElement).Create(_node: XmlNode);
end;
function Font.Create(_parent: tslobj; _prefix: string; _local_name: string);overload;
begin
class(OpenXmlElement).Create(_parent, _prefix, _local_name);
end;
function Font.Init();override;
begin
self.XmlAttrName := new OpenXmlAttribute(self.Prefix, "name", nil);
self.AltName := new PureWVal(self, self.Prefix, "altName");
self.Panosel := new PureWVal(self, self.Prefix, "panosel");
self.Charset := new PureWVal(self, self.Prefix, "charset");
self.Family := new PureWVal(self, self.Prefix, "family");
self.Pitch := new PureWVal(self, self.Prefix, "pitch");
self.Sig := new Sig(self, self.Prefix, "sig");
end;
function Font.InitAttributes();override;
begin
attributes_ := array(
self.XmlAttrName,
);
end;
function Font.InitChildren();override;
begin
child_elements_ := array(
0: self.AltName,
1: self.Panosel,
2: self.Charset,
3: self.Family,
4: self.Pitch,
5: self.Sig,
);
sorted_child_ := array(
"": -1,
self.AltName.ElementName: 0,
self.Panosel.ElementName: 1,
self.Charset.ElementName: 2,
self.Family.ElementName: 3,
self.Pitch.ElementName: 4,
self.Sig.ElementName: 5,
);
end;
function Font.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;
node := ifObj(_node) ? _node.FirstChild() : nil;
flag := false;
if ifnil(child_elements_[0]) and length(child_elements_) > 0 then
begin
flag := true;
arr := child_elements_;
child_elements_ := array();
end
pre := ifString(self.Prefix) ? self.Prefix + ":" : "";
while ifObj(node) do
begin
node_name := node.GetName();
pos := sorted_child_[node_name];
if ifnil(pos) or pos = -1 then
begin
obj := nil;
case node_name of
end;
if ifObj(obj) then obj.InitNode(node);
end
else if flag then
begin
obj := arr[pos];
obj.InitNode(node);
child_elements_[length(child_elements_)] := obj;
end
else begin
child_elements_[pos].InitNode(node);
end
node := node.NextElement();
end
end;
function Font.Copy(_obj: Font);override;
begin
if not ifnil(_obj.XmlAttrName.Value) then
self.XmlAttrName.Value := _obj.XmlAttrName.Value;
self.AltName.Copy(_obj.AltName);
self.Panosel.Copy(_obj.Panosel);
self.Charset.Copy(_obj.Charset);
self.Family.Copy(_obj.Family);
self.Pitch.Copy(_obj.Pitch);
self.Sig.Copy(_obj.Sig);
end;
function Font.ReadXmlAttrName();
begin
return self.XmlAttrName.Value;
end;
function Font.WriteXmlAttrName(_value);
begin
self.XmlAttrName.Value := _value;
end;