Ejemplo n.º 1
0
        }         // RtfDocument

        // ----------------------------------------------------------------------
        public RtfDocument(
            int rtfVersion,
            IRtfFont defaultFont,
            IRtfFontCollection fontTable,
            IRtfColorCollection colorTable,
            string generator,
            IRtfTextFormatCollection uniqueTextFormats,
            IRtfDocumentInfo documentInfo,
            IRtfDocumentPropertyCollection userProperties,
            IRtfVisualCollection visualContent
            )
        {
            if (rtfVersion != RtfSpec.RtfVersion1)
            {
                throw new RtfUnsupportedStructureException(Strings.UnsupportedRtfVersion(rtfVersion));
            }
            if (defaultFont == null)
            {
                throw new ArgumentNullException("defaultFont");
            }
            if (fontTable == null)
            {
                throw new ArgumentNullException("fontTable");
            }
            if (colorTable == null)
            {
                throw new ArgumentNullException("colorTable");
            }
            if (uniqueTextFormats == null)
            {
                throw new ArgumentNullException("uniqueTextFormats");
            }
            if (documentInfo == null)
            {
                throw new ArgumentNullException("documentInfo");
            }
            if (userProperties == null)
            {
                throw new ArgumentNullException("userProperties");
            }
            if (visualContent == null)
            {
                throw new ArgumentNullException("visualContent");
            }
            this.rtfVersion        = rtfVersion;
            this.defaultFont       = defaultFont;
            defaultTextFormat      = new RtfTextFormat(defaultFont, RtfSpec.DefaultFontSize);
            this.fontTable         = fontTable;
            this.colorTable        = colorTable;
            this.generator         = generator;
            this.uniqueTextFormats = uniqueTextFormats;
            this.documentInfo      = documentInfo;
            this.userProperties    = userProperties;
            this.visualContent     = visualContent;
        }         // RtfDocument
Ejemplo n.º 2
0
 // ----------------------------------------------------------------------
 public RtfDocument(
     int rtfVersion,
     IRtfFont defaultFont,
     IRtfFontCollection fontTable,
     IRtfColorCollection colorTable,
     string generator,
     IRtfTextFormatCollection uniqueTextFormats,
     IRtfDocumentInfo documentInfo,
     IRtfDocumentPropertyCollection userProperties,
     IRtfVisualCollection visualContent
     )
 {
     if ( rtfVersion != RtfSpec.RtfVersion1 )
     {
         throw new RtfUnsupportedStructureException( Strings.UnsupportedRtfVersion( rtfVersion ) );
     }
     if ( defaultFont == null )
     {
         throw new ArgumentNullException( "defaultFont" );
     }
     if ( fontTable == null )
     {
         throw new ArgumentNullException( "fontTable" );
     }
     if ( colorTable == null )
     {
         throw new ArgumentNullException( "colorTable" );
     }
     if ( uniqueTextFormats == null )
     {
         throw new ArgumentNullException( "uniqueTextFormats" );
     }
     if ( documentInfo == null )
     {
         throw new ArgumentNullException( "documentInfo" );
     }
     if ( userProperties == null )
     {
         throw new ArgumentNullException( "userProperties" );
     }
     if ( visualContent == null )
     {
         throw new ArgumentNullException( "visualContent" );
     }
     this.rtfVersion = rtfVersion;
     this.defaultFont = defaultFont;
     defaultTextFormat = new RtfTextFormat( defaultFont, RtfSpec.DefaultFontSize );
     this.fontTable = fontTable;
     this.colorTable = colorTable;
     this.generator = generator;
     this.uniqueTextFormats = uniqueTextFormats;
     this.documentInfo = documentInfo;
     this.userProperties = userProperties;
     this.visualContent = visualContent;
 }
Ejemplo n.º 3
0
        } // RtfDocument

        public RtfDocument(
            int rtfVersion,
            IRtfFont defaultFont,
            IRtfFontCollection fontTable,
            IRtfColorCollection colorTable,
            string generator,
            IRtfTextFormatCollection uniqueTextFormats,
            IRtfDocumentInfo documentInfo,
            IRtfDocumentPropertyCollection userProperties,
            IRtfVisualCollection visualContent
            )
        {
            if (rtfVersion != RtfSpec.RtfVersion1)
            {
                throw new RtfUnsupportedStructureException(Strings.UnsupportedRtfVersion(rtfVersion));
            }
            if (defaultFont == null)
            {
                throw new ArgumentNullException(nameof(defaultFont));
            }
            if (fontTable == null)
            {
                throw new ArgumentNullException(nameof(fontTable));
            }
            if (colorTable == null)
            {
                throw new ArgumentNullException(nameof(colorTable));
            }
            if (uniqueTextFormats == null)
            {
                throw new ArgumentNullException(nameof(uniqueTextFormats));
            }
            if (documentInfo == null)
            {
                throw new ArgumentNullException(nameof(documentInfo));
            }
            if (userProperties == null)
            {
                throw new ArgumentNullException(nameof(userProperties));
            }
            if (visualContent == null)
            {
                throw new ArgumentNullException(nameof(visualContent));
            }
            RtfVersion        = rtfVersion;
            DefaultFont       = defaultFont;
            DefaultTextFormat = new RtfTextFormat(defaultFont, RtfSpec.DefaultFontSize);
            FontTable         = fontTable;
            ColorTable        = colorTable;
            Generator         = generator;
            UniqueTextFormats = uniqueTextFormats;
            DocumentInfo      = documentInfo;
            UserProperties    = userProperties;
            VisualContent     = visualContent;
        } // RtfDocument
Ejemplo n.º 4
0
        public void DocumentBuilderTest()
        {
            const RtfParserListenerLogger parserLogger = null;
            //parserLogger = new RtfParserListenerLogger();
            IRtfGroup rtfStructure =
                RtfParserTool.Parse(GetTestResource("RtfInterpreterTest_1.rtf"), parserLogger);

            Assert.IsNotNull(rtfStructure);

            const RtfInterpreterListenerLogger interpreterLogger = null;
            //interpreterLogger = new RtfInterpreterListenerLogger();

            RtfInterpreterListenerDocumentBuilder docBuilder =
                new RtfInterpreterListenerDocumentBuilder();

            RtfInterpreterTool.Interpret(rtfStructure, docBuilder, interpreterLogger);
            IRtfDocument doc = docBuilder.Document;

            Assert.IsNotNull(doc);

            Assert.AreEqual("TX_RTF32 14.0.520.501", doc.Generator);

            Assert.AreEqual(3, doc.FontTable.Count);
            Assert.AreEqual(RtfFontKind.Swiss, doc.FontTable[0].Kind);
            Assert.AreEqual(RtfFontPitch.Variable, doc.FontTable[0].Pitch);
            Assert.AreEqual(0, doc.FontTable[0].CharSet);
            Assert.AreEqual(1252, doc.FontTable[0].CodePage);
            Assert.AreEqual("Arial", doc.FontTable[0].Name);

            Assert.AreEqual(RtfFontKind.Swiss, doc.FontTable[1].Kind);
            Assert.AreEqual(RtfFontPitch.Variable, doc.FontTable[1].Pitch);
            Assert.AreEqual(0, doc.FontTable[01].CharSet);
            Assert.AreEqual(1252, doc.FontTable[1].CodePage);
            Assert.AreEqual("Verdana", doc.FontTable[1].Name);

            Assert.AreEqual(RtfFontKind.Roman, doc.FontTable[2].Kind);
            Assert.AreEqual(RtfFontPitch.Variable, doc.FontTable[2].Pitch);
            Assert.AreEqual(2, doc.FontTable[2].CharSet);
            Assert.AreEqual(42, doc.FontTable[2].CodePage);
            Assert.AreEqual("Symbol", doc.FontTable[2].Name);

            Assert.AreSame(doc.DefaultFont, doc.FontTable[1]);

            Assert.AreEqual(4, doc.ColorTable.Count);
            Assert.AreEqual(RtfColor.Black, doc.ColorTable[0]);
            Assert.AreEqual(RtfColor.Black, doc.ColorTable[1]);
            Assert.AreEqual(RtfColor.White, doc.ColorTable[2]);
            Assert.AreEqual(new RtfColor(10, 20, 30), doc.ColorTable[3]);

            Assert.AreEqual(2, doc.VisualContent.Count);
            Assert.AreEqual(RtfVisualKind.Text, doc.VisualContent[0].Kind);
            Assert.AreEqual("Hellou RTF Wörld", ((IRtfVisualText)doc.VisualContent[0]).Text);
            Assert.AreEqual("Verdana", ((IRtfVisualText)doc.VisualContent[0]).Format.Font.Name);
            Assert.AreEqual(36, ((IRtfVisualText)doc.VisualContent[0]).Format.FontSize);
            Assert.AreEqual(RtfVisualKind.Break, doc.VisualContent[1].Kind);
            Assert.AreEqual(RtfVisualBreakKind.Paragraph, ((IRtfVisualBreak)doc.VisualContent[1]).BreakKind);

            Assert.AreEqual(5, doc.UserProperties.Count);
            Assert.AreEqual("created", doc.UserProperties[0].Name);
            Assert.AreEqual(RtfPropertyKind.Date, doc.UserProperties[0].PropertyKind);
            Assert.AreEqual("2008-05-23", doc.UserProperties[0].StaticValue);
            Assert.IsNull(doc.UserProperties[0].LinkValue);
            Assert.AreEqual("a link", doc.UserProperties[4].LinkValue);

            IRtfDocumentInfo info = doc.DocumentInfo;

            Assert.AreEqual(2, info.Version);
            Assert.AreEqual(3, info.Revision);
            Assert.AreEqual(1, info.NumberOfPages);
            Assert.AreEqual(3, info.NumberOfWords);
            Assert.AreEqual(16, info.NumberOfCharacters);
            Assert.AreEqual(314, info.Id);
            Assert.AreEqual(17, info.EditingTimeInMinutes);
            Assert.AreEqual("Not really important", info.Title);
            Assert.AreEqual("RTF parsing", info.Subject);
            Assert.AreEqual("John Doe", info.Author);
            Assert.AreEqual("John Doe's boss", info.Manager);
            Assert.AreEqual("Itenso GmbH", info.Company);
            Assert.AreEqual("Foo Bar", info.Operator);
            Assert.AreEqual("Development", info.Category);
            Assert.AreEqual("RTF, Parser, Interpreter", info.Keywords);
            Assert.AreEqual("a testing document", info.Comment);
            Assert.AreEqual("with more commentary", info.DocumentComment);
            Assert.AreEqual("http://wwww.nowhere.com/foo/bar", info.HyperLinkbase);
            Assert.AreEqual(Time("2008.05.23-17:55:12"), info.CreationTime);
            Assert.AreEqual(Time("2008.05.23-18:01:00"), info.RevisionTime);
            Assert.AreEqual(Time("2008.05.23-17:59:00"), info.PrintTime);
            Assert.AreEqual(Time("2008.05.23-18:00:00"), info.BackupTime);
        }         // DocumentBuilderTest