Beispiel #1
0
        public void ImageTest()
        {
            const RtfParserListenerLogger parserLogger = null;
            //parserLogger = new RtfParserListenerLogger();
            IRtfGroup rtfStructure =
                RtfParserTool.Parse(GetTestResource("RtfInterpreterTest_4.rtf"), parserLogger);

            Assert.IsNotNull(rtfStructure);

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

            IRtfDocument rtfDoc = RtfInterpreterTool.BuildDoc(rtfStructure, interpreterLogger);

            Assert.IsNotNull(rtfDoc);
            IRtfVisualCollection rtfVisuals = rtfDoc.VisualContent;

            Assert.AreEqual(RtfVisualKind.Image, rtfVisuals[4].Kind);
            IRtfVisualImage img = (IRtfVisualImage)rtfVisuals[4];

            Assert.AreEqual(RtfVisualImageFormat.Jpg, img.Format);
            Assert.AreEqual(100, img.Width);
            Assert.AreEqual(142, img.Height);
            Assert.AreEqual(720, img.DesiredWidth);
            Assert.AreEqual(1020, img.DesiredHeight);
        }         // ImageTest
Beispiel #2
0
        private async Task <String> RtfToHtmlSegments(IRtfVisualCollection rtfVisualContent)
        {
            var htmlSegments = new StringBuilder();

            foreach (var visualChild in rtfVisualContent)
            {
                if (visualChild is IRtfVisualImage)
                {
                    var uploaded = await DbContext.Instance.CheckUploadedImage((visualChild as IRtfVisualImage).ImportFileName);

                    if (uploaded == null)
                    {
                        Debugger.Break();
                    }
                    var json          = uploaded.Json;
                    var imgUploadRslt = JsonConvert.DeserializeObject <ImageUploadResult>(json);

                    var imgHtml = String.Format("<img data-rawwidth=\"{0}\" data-rawheight = \"{1}\" class=\"content_image\" src=\"{2}\" style=\"margin:auto auto;width:100%\">",
                                                imgUploadRslt.RawWidth, imgUploadRslt.RawHeight, imgUploadRslt.Source);

                    htmlSegments.Append(imgHtml);
                }
                else if (visualChild is IRtfVisualBreak)
                {
                    htmlSegments.Append("<br>");
                }
                else if (visualChild is IRtfVisualText)
                {
                    htmlSegments.Append((visualChild as IRtfVisualText).Text);
                }
            }
            return(htmlSegments.ToString());
        }
Beispiel #3
0
        public void TextAlignmentTest()
        {
            const RtfParserListenerLogger parserLogger = null;
            //parserLogger = new RtfParserListenerLogger();
            IRtfGroup rtfStructure =
                RtfParserTool.Parse(GetTestResource("RtfInterpreterTest_3.rtf"), parserLogger);

            Assert.IsNotNull(rtfStructure);

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

            IRtfDocument rtfDoc = RtfInterpreterTool.BuildDoc(rtfStructure, interpreterLogger);

            Assert.IsNotNull(rtfDoc);
            IRtfVisualCollection rtfVisuals = rtfDoc.VisualContent;

            Assert.AreEqual(8, rtfVisuals.Count);
            Assert.AreEqual(RtfVisualKind.Text, rtfVisuals[0].Kind);
            Assert.AreEqual("left aligned", ((IRtfVisualText)rtfVisuals[0]).Text);
            Assert.AreEqual(RtfTextAlignment.Left, ((IRtfVisualText)rtfVisuals[0]).Format.Alignment);
            Assert.AreEqual(RtfVisualKind.Text, rtfVisuals[2].Kind);
            Assert.AreEqual("centered", ((IRtfVisualText)rtfVisuals[2]).Text);
            Assert.AreEqual(RtfTextAlignment.Center, ((IRtfVisualText)rtfVisuals[2]).Format.Alignment);
            Assert.AreEqual(RtfVisualKind.Text, rtfVisuals[4].Kind);
            Assert.AreEqual("right aligned", ((IRtfVisualText)rtfVisuals[4]).Text);
            Assert.AreEqual(RtfTextAlignment.Right, ((IRtfVisualText)rtfVisuals[4]).Format.Alignment);
            Assert.AreEqual(RtfVisualKind.Text, rtfVisuals[6].Kind);
            Assert.AreEqual("block aligned", ((IRtfVisualText)rtfVisuals[6]).Text);
            Assert.AreEqual(RtfTextAlignment.Justify, ((IRtfVisualText)rtfVisuals[6]).Format.Alignment);
        }         // TextAlignmentTest
Beispiel #4
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;
 }
Beispiel #5
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
Beispiel #6
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
Beispiel #7
0
        // ----------------------------------------------------------------------
        public RtfDocument( IRtfInterpreterContext context, IRtfVisualCollection visualContent )
            : this(context.RtfVersion,
				context.DefaultFont,
				context.FontTable,
				context.ColorTable,
				context.Generator,
				context.UniqueTextFormats,
				context.DocumentInfo,
				context.UserProperties,
				visualContent)
        {
        }
Beispiel #8
0
 // ----------------------------------------------------------------------
 public RtfDocument(IRtfInterpreterContext context, IRtfVisualCollection visualContent) :
     this(context.RtfVersion,
          context.DefaultFont,
          context.FontTable,
          context.ColorTable,
          context.Generator,
          context.UniqueTextFormats,
          context.DocumentInfo,
          context.UserProperties,
          visualContent
          )
 {
 }         // RtfDocument
Beispiel #9
0
        public void TextAlignmentTestFixed()
        {
            const RtfParserListenerLogger parserLogger = null;
            //parserLogger = new RtfParserListenerLogger();
            IRtfGroup rtfStructure =
                RtfParserTool.Parse(GetTestResource("RtfInterpreterTest_23.rtf"), parserLogger);

            Assert.IsNotNull(rtfStructure);

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

            IRtfDocument rtfDoc = RtfInterpreterTool.BuildDoc(rtfStructure, interpreterLogger);

            Assert.IsNotNull(rtfDoc);
            IRtfVisualCollection rtfVisuals = rtfDoc.VisualContent;

            Assert.AreEqual(2, rtfVisuals.Count);
            Assert.AreEqual(RtfVisualKind.Text, rtfVisuals[0].Kind);
            Assert.AreEqual("Simple text", ((IRtfVisualText)rtfVisuals[0]).Text);
            Assert.AreEqual(RtfTextAlignment.Right, ((IRtfVisualText)rtfVisuals[0]).Format.Alignment);
        }         // TextAlignmentTestFixed