Пример #1
0
        private void CreateTabs(BsonDocument spp)
        {
            BsonArray tabs = spp.zGet("Tabs").zAsBsonArray();
            if (tabs == null)
                return;

            //Tabs tabsElement = new Tabs();
            List<OXmlTabStop> tabsElement = new List<OXmlTabStop>();
            foreach (BsonValue tab in tabs)
            {
                BsonDocument dtab = tab.AsBsonDocument;

                // TabStop, <w:tab>
                //TabStop tabStop = new TabStop();
                OXmlTabStop tabStop = new OXmlTabStop();
                // Tab Stop Position, <w:tab w:pos="">
                tabStop.Position = dtab.zGet("Position", mandatory: true).zAsInt();
                // Tab Stop Type, <w:tab w:val="">, Clear, Left, Start, Center, Right, End, Decimal, Bar, Number
                tabStop.Alignment = dtab.zGet("Alignment", mandatory: true).zAsEnum<TabStopValues>(ignoreCase: true);
                // Tab Leader Character, <w:tab w:leader="">, None, Dot, Hyphen, Underscore, Heavy, MiddleDot
                tabStop.LeaderChar = dtab.zGet("LeaderChar").zTryAsEnum(TabStopLeaderCharValues.None, ignoreCase: true);

                //tabsElement.AppendChild(tabStop);
                tabsElement.Add(tabStop);
            }
            _paragraphProperties.Tabs = tabsElement.ToArray();
        }
Пример #2
0
 private static void WriteTabs(BsonWriter bsonWriter, OXmlTabStop[] tabs)
 {
     foreach (OXmlTabStop tab in tabs)
     {
         bsonWriter.WriteStartDocument();
         WriteTab(bsonWriter, tab);
         bsonWriter.WriteEndDocument();
     }
 }
Пример #3
0
 private static void WriteTab(BsonWriter bsonWriter, OXmlTabStop element)
 {
     bsonWriter.WriteInt32("Position", element.Position);
     bsonWriter.WriteString("Alignment", element.Alignment.ToString());
     if (element.LeaderChar != TabStopLeaderCharValues.None)
         bsonWriter.WriteString("LeaderChar", element.LeaderChar.ToString());
 }
Пример #4
0
        private static OXmlTabStop[] ReadTabs(BsonReader bsonReader)
        {
            bsonReader.ReadStartArray();
            List<OXmlTabStop> values = new List<OXmlTabStop>();
            while (true)
            {
                BsonType bsonType = bsonReader.ReadBsonType();
                if (bsonType == BsonType.EndOfDocument)
                    break;

                if (bsonType != BsonType.Document)
                    throw new PBException($"wrong Tabs value {bsonType}");
                bsonReader.ReadStartDocument();

                OXmlTabStop value = new OXmlTabStop();
                while (true)
                {
                    bsonType = bsonReader.ReadBsonType();
                    if (bsonType == BsonType.EndOfDocument)
                        break;
                    string name = bsonReader.ReadName();
                    switch (name.ToLower())
                    {
                        case "position":
                            if (bsonType == BsonType.Null)
                                break;
                            if (bsonType != BsonType.Int32)
                                throw new PBException($"wrong TabStop Position value {bsonType}");
                            value.Position = bsonReader.ReadInt32();
                            break;
                        case "alignment":
                            if (bsonType == BsonType.Null)
                                break;
                            if (bsonType != BsonType.String)
                                throw new PBException($"wrong TabStop Alignment value {bsonType}");
                            value.Alignment = bsonReader.ReadString().zParseEnum<TabStopValues>(ignoreCase: true);
                            break;
                        case "leaderchar":
                            if (bsonType == BsonType.Null)
                                break;
                            if (bsonType != BsonType.String)
                                throw new PBException($"wrong TabStop LeaderChar value {bsonType}");
                            value.LeaderChar = bsonReader.ReadString().zParseEnum<TabStopLeaderCharValues>(ignoreCase: true);
                            break;
                        default:
                            throw new PBException($"unknow TabStop value \"{name}\"");
                    }
                }
                bsonReader.ReadEndDocument();
                values.Add(value);
            }
            bsonReader.ReadEndArray();
            return values.ToArray();
        }