コード例 #1
0
        public static PssgSchema.Node RenameNode(PssgNode pssgNode, string nodeName)
        {
            PssgSchema.Node node = PssgSchema.AddNode(nodeName);

            foreach (PssgAttribute attr in pssgNode.Attributes)
            {
                PssgSchema.AddAttribute(node.Name, attr.AttributeInfo.Name, attr.AttributeInfo.DataType);
            }

            return(node);
        }
コード例 #2
0
        public PssgAttribute(XAttribute xAttr, PssgFile file, PssgNode node)
        {
            this.file       = file;
            this.ParentNode = node;

            //this.id = PssgSchema.GetAttributeId(ParentNode.Name, xAttr.Name.LocalName);
            string attrName = xAttr.Name.LocalName.StartsWith("___") ? xAttr.Name.LocalName.Substring(3) : xAttr.Name.LocalName;

            this.AttributeInfo = PssgSchema.AddAttribute(this.ParentNode.Name, attrName);// PssgSchema.GetAttribute(this.ParentNode.Name, xAttr.Name.LocalName);
            this.data          = this.FromString(xAttr.Value);
            PssgSchema.SetAttributeDataTypeIfNull(this.AttributeInfo, this.ValueType);
        }
コード例 #3
0
        public PssgAttribute(PssgBinaryReader reader, PssgFile file, PssgNode node)
        {
            this.file       = file;
            this.ParentNode = node;

            int id = reader.ReadInt32();

            this.AttributeInfo = PssgSchema.GetAttribute(id);
            this.size          = reader.ReadInt32();
            this.data          = reader.ReadAttributeValue(this.AttributeInfo.DataType, size);
            this.AttributeInfo = PssgSchema.AddAttribute(this.ParentNode.Name, this.Name, this.ValueType);
        }
コード例 #4
0
        public PssgAttribute AddAttribute(string attributeName, object data)
        {
            if (this.Attributes == null)
            {
                this.Attributes = new PssgAttributeCollection();
            }
            else if (this.HasAttribute(attributeName))
            {
                this.GetAttribute(attributeName).Value = data;
                return(this.GetAttribute(attributeName));
            }

            PssgAttribute newAttr = new PssgAttribute(PssgSchema.AddAttribute(this.Name, attributeName, data.GetType()), data, this.File, this);

            this.Attributes.Add(newAttr);

            return(newAttr);
        }
コード例 #5
0
        public static void LoadFromPssg(PssgBinaryReader reader)
        {
            int       attributeInfoCount = reader.ReadInt32();
            int       nodeInfoCount      = reader.ReadInt32();
            Node      node;
            Attribute attribute;

            for (int i = 0; i < nodeInfoCount; i++)
            {
                int nId = reader.ReadInt32();
                node    = new Node(reader.ReadPSSGString());
                node.Id = nId;

                if (entries.ContainsKey(node.Name))
                {
                    entries[node.Name].Id = node.Id;
                }
                else
                {
                    PssgSchema.AddNode(node);
                }

                int subAttributeInfoCount = reader.ReadInt32();
                for (int j = 0; j < subAttributeInfoCount; j++)
                {
                    int id = reader.ReadInt32();
                    attribute    = new Attribute(reader.ReadPSSGString());
                    attribute.Id = id;

                    Attribute attr = PssgSchema.GetAttribute(node.Name, attribute.Name);
                    if (attr == null)
                    {
                        PssgSchema.AddAttribute(node.Name, attribute);
                    }
                    else
                    {
                        attr.Id = attribute.Id;
                    }
                }
            }
        }
コード例 #6
0
        public static void LoadSchema(Stream stream)
        {
            entries.Clear();

            PssgSchema.AddAttribute("FETEXTLAYOUT", "height", typeof(Single));
            PssgSchema.AddAttribute("FETEXTLAYOUT", "depth", typeof(Single));
            PssgSchema.AddAttribute("FETEXTLAYOUT", "tracking", typeof(Single));

            PssgSchema.AddAttribute("NEGLYPHMETRICS", "advanceWidth", typeof(Single));
            PssgSchema.AddAttribute("NEGLYPHMETRICS", "horizontalBearing", typeof(Single));
            PssgSchema.AddAttribute("NEGLYPHMETRICS", "verticalBearing", typeof(Single));
            PssgSchema.AddAttribute("NEGLYPHMETRICS", "physicalWidth", typeof(Single));
            PssgSchema.AddAttribute("NEGLYPHMETRICS", "physicalHeight", typeof(Single));

            PssgSchema.AddAttribute("FEATLASINFODATA", "u0", typeof(Single));
            PssgSchema.AddAttribute("FEATLASINFODATA", "v0", typeof(Single));
            PssgSchema.AddAttribute("FEATLASINFODATA", "u1", typeof(Single));
            PssgSchema.AddAttribute("FEATLASINFODATA", "v1", typeof(Single));

            if (stream.Length == 0)
            {
                return;
            }

            using (stream)
            {
                XDocument xDoc = XDocument.Load(stream);

                foreach (XNode xN in xDoc.Descendants("node"))
                {
                    if (xN is XElement)
                    {
                        XElement elemNode = (XElement)xN;
                        string   nodeName = elemNode.Attribute("name").Value;
                        Node     node     = PssgSchema.AddNode(nodeName);
                        Type     nodeType = Type.GetType(elemNode.Attribute("dataType").Value, false);
                        if (nodeType != null)
                        {
                            node.DataType = nodeType;
                        }
                        node.ElementsPerRow = Convert.ToInt32(elemNode.Attribute("elementsPerRow").Value);
                        string linkAttributeName = elemNode.Attribute("linkAttributeName").Value;
                        if (!string.IsNullOrEmpty(linkAttributeName))
                        {
                            node.LinkAttributeName = linkAttributeName;
                        }

                        foreach (XNode subNode in elemNode.Descendants("attribute"))
                        {
                            if (xN is XElement)
                            {
                                string attrName = ((XElement)subNode).Attribute("name").Value;
                                Type   attrType = Type.GetType(((XElement)subNode).Attribute("dataType").Value, false);
                                if (attrType != null)
                                {
                                    bool add = true;
                                    for (int i = 0; i < node.Attributes.Count; i++)
                                    {
                                        if (node.Attributes[i].Name == attrName)
                                        {
                                            add = false;
                                            node.Attributes[i].DataType = attrType;
                                            break;
                                        }
                                    }

                                    if (add)
                                    {
                                        node.Attributes.Add(new Attribute(attrName, attrType));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }