private static void WriteStyleRunProperties(BsonWriter bsonWriter, OXmlStyleRunProperties element) { if (element.Bold != null) bsonWriter.WriteBoolean("Bold", (bool)element.Bold); if (element.BoldComplexScript != null) bsonWriter.WriteBoolean("BoldComplexScript", (bool)element.BoldComplexScript); if (element.Caps != null) bsonWriter.WriteBoolean("Caps", (bool)element.Caps); if (element.CharacterScale != null) bsonWriter.WriteInt32("CharacterScale", (int)element.CharacterScale); if (element.DoubleStrike != null) bsonWriter.WriteBoolean("DoubleStrike", (bool)element.DoubleStrike); if (element.Emboss != null) bsonWriter.WriteBoolean("Emboss", (bool)element.Emboss); if (element.Emphasis != null) bsonWriter.WriteString("Emphasis", element.Emphasis.ToString()); if (element.FontSize != null) bsonWriter.WriteString("FontSize", element.FontSize); if (element.FontSizeComplexScript != null) bsonWriter.WriteString("FontSizeComplexScript", element.FontSizeComplexScript); if (element.Imprint != null) bsonWriter.WriteBoolean("Imprint", (bool)element.Imprint); if (element.Italic != null) bsonWriter.WriteBoolean("Italic", (bool)element.Italic); if (element.ItalicComplexScript != null) bsonWriter.WriteBoolean("ItalicComplexScript", (bool)element.ItalicComplexScript); if (element.Kern != null) bsonWriter.WriteInt32("Kern", (int)element.Kern); if (element.NoProof != null) bsonWriter.WriteBoolean("NoProof", (bool)element.NoProof); if (element.Outline != null) bsonWriter.WriteBoolean("Outline", (bool)element.Outline); if (element.Position != null) bsonWriter.WriteString("Position", element.Position); if (element.RunFonts != null) { bsonWriter.WriteStartDocument("RunFonts"); OXmlCommonSerializer.WriteRunFonts(bsonWriter, element.RunFonts); bsonWriter.WriteEndDocument(); } if (element.Shadow != null) bsonWriter.WriteBoolean("Shadow", (bool)element.Shadow); if (element.SmallCaps != null) bsonWriter.WriteBoolean("SmallCaps", (bool)element.SmallCaps); if (element.SnapToGrid != null) bsonWriter.WriteBoolean("SnapToGrid", (bool)element.SnapToGrid); if (element.Spacing != null) bsonWriter.WriteInt32("Spacing", (int)element.Spacing); if (element.SpecVanish != null) bsonWriter.WriteBoolean("SpecVanish", (bool)element.SpecVanish); if (element.Strike != null) bsonWriter.WriteBoolean("Strike", (bool)element.Strike); if (element.TextEffect != null) bsonWriter.WriteString("TextEffect", element.TextEffect.ToString()); if (element.Vanish != null) bsonWriter.WriteBoolean("Vanish", (bool)element.Vanish); if (element.VerticalTextAlignment != null) bsonWriter.WriteString("VerticalTextAlignment", element.VerticalTextAlignment.ToString()); if (element.WebHidden != null) bsonWriter.WriteBoolean("WebHidden", (bool)element.WebHidden); }
private static OXmlStyleRunProperties ReadStyleRunProperties(BsonReader bsonReader) { bsonReader.ReadStartDocument(); OXmlStyleRunProperties value = new OXmlStyleRunProperties(); while (true) { BsonType bsonType = bsonReader.ReadBsonType(); if (bsonType == BsonType.EndOfDocument) break; string name = bsonReader.ReadName(); switch (name.ToLower()) { case "bold": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties Bold value {bsonType}"); value.Bold = bsonReader.ReadBoolean(); break; case "boldcomplexscript": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties BoldComplexScript value {bsonType}"); value.BoldComplexScript = bsonReader.ReadBoolean(); break; case "caps": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties Caps value {bsonType}"); value.Caps = bsonReader.ReadBoolean(); break; case "characterscale": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Int32) throw new PBException($"wrong StyleRunProperties CharacterScale value {bsonType}"); value.CharacterScale = bsonReader.ReadInt32(); break; case "doublestrike": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties DoubleStrike value {bsonType}"); value.DoubleStrike = bsonReader.ReadBoolean(); break; case "emboss": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties Emboss value {bsonType}"); value.Emboss = bsonReader.ReadBoolean(); break; case "emphasis": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.String) throw new PBException($"wrong StyleRunProperties Emphasis value {bsonType}"); value.Emphasis = bsonReader.ReadString().zParseEnum<EmphasisMarkValues>(ignoreCase: true); break; case "fontsize": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.String) throw new PBException($"wrong StyleRunProperties FontSize value {bsonType}"); value.FontSize = bsonReader.ReadString(); break; case "fontsizecomplexscript": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.String) throw new PBException($"wrong StyleRunProperties FontSizeComplexScript value {bsonType}"); value.FontSizeComplexScript = bsonReader.ReadString(); break; case "imprint": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties Imprint value {bsonType}"); value.Imprint = bsonReader.ReadBoolean(); break; case "italic": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties Italic value {bsonType}"); value.Italic = bsonReader.ReadBoolean(); break; case "italiccomplexscript": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties ItalicComplexScript value {bsonType}"); value.ItalicComplexScript = bsonReader.ReadBoolean(); break; case "kern": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Int32) throw new PBException($"wrong StyleRunProperties Kern value {bsonType}"); value.Kern = (uint)bsonReader.ReadInt32(); break; case "noproof": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties NoProof value {bsonType}"); value.NoProof = bsonReader.ReadBoolean(); break; case "outline": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties Outline value {bsonType}"); value.Outline = bsonReader.ReadBoolean(); break; case "position": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.String) throw new PBException($"wrong StyleRunProperties Position value {bsonType}"); value.Position = bsonReader.ReadString(); break; case "runfonts": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Document) throw new PBException($"wrong RunFonts value {bsonType}"); value.RunFonts = OXmlCommonSerializer.ReadRunFonts(bsonReader); break; case "shadow": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties Shadow value {bsonType}"); value.Shadow = bsonReader.ReadBoolean(); break; case "smallcaps": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties SmallCaps value {bsonType}"); value.SmallCaps = bsonReader.ReadBoolean(); break; case "snaptogrid": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties SnapToGrid value {bsonType}"); value.SnapToGrid = bsonReader.ReadBoolean(); break; case "spacing": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Int32) throw new PBException($"wrong StyleRunProperties Spacing value {bsonType}"); value.Spacing = bsonReader.ReadInt32(); break; case "specvanish": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties SpecVanish value {bsonType}"); value.SpecVanish = bsonReader.ReadBoolean(); break; case "strike": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties Strike value {bsonType}"); value.Strike = bsonReader.ReadBoolean(); break; case "texteffect": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.String) throw new PBException($"wrong StyleRunProperties TextEffect value {bsonType}"); value.TextEffect = bsonReader.ReadString().zParseEnum<TextEffectValues>(ignoreCase: true); break; case "vanish": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties Vanish value {bsonType}"); value.Vanish = bsonReader.ReadBoolean(); break; case "verticaltextalignment": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.String) throw new PBException($"wrong StyleRunProperties VerticalTextAlignment value {bsonType}"); value.VerticalTextAlignment = bsonReader.ReadString().zParseEnum<VerticalPositionValues>(ignoreCase: true); break; case "webhidden": if (bsonType == BsonType.Null) break; if (bsonType != BsonType.Boolean) throw new PBException($"wrong StyleRunProperties WebHidden value {bsonType}"); value.WebHidden = bsonReader.ReadBoolean(); break; default: throw new PBException($"unknow PageMargin value \"{name}\""); } } bsonReader.ReadEndDocument(); return value; }