Exemplo n.º 1
0
        }         // DoVisitSpecial

        // ----------------------------------------------------------------------
        public void VisitImage(IRtfVisualImage visualImage)
        {
            if (visualImage != null)
            {
                DoVisitImage(visualImage);
            }
        }         // VisitImage
Exemplo n.º 2
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
Exemplo n.º 3
0
		} // DoVisitSpecial

		// ----------------------------------------------------------------------
		public void VisitImage( IRtfVisualImage visualImage )
		{
			if ( visualImage != null )
			{
				DoVisitImage( visualImage );
			}
		} // VisitImage
Exemplo n.º 4
0
        public void ImageFormatDecodingTest()
        {
            const RtfParserListenerLogger parserLogger = null;
            //parserLogger = new RtfParserListenerLogger();

            const RtfInterpreterListenerLogger interpreterLogger = null;

            //interpreterLogger = new RtfInterpreterListenerLogger();

// ReSharper disable RedundantExplicitArrayCreation
            int[] imageResources = new int[] { 4, 5, 6, 7, 8, 19 };
// ReSharper restore RedundantExplicitArrayCreation
            for (int i = 0; i < imageResources.Length; i++)
            {
                string    testCaseName = BuildTestResourceName("", imageResources[i], false, "rtf");
                IRtfGroup rtfStructure =
                    RtfParserTool.Parse(GetTestResource(testCaseName), parserLogger);
                IRtfDocument rtfDoc = RtfInterpreterTool.BuildDoc(rtfStructure, interpreterLogger);
                Assert.IsNotNull(rtfDoc);
                bool imageFound = false;
                foreach (IRtfVisual visual in rtfDoc.VisualContent)
                {
                    if (visual.Kind == RtfVisualKind.Image)
                    {
                        IRtfVisualImage img = (IRtfVisualImage)visual;
                        Assert.IsNotNull(img.ImageForDrawing);
                        imageFound = true;
                        //Console.WriteLine( "image: " + img.ImageForDrawing );
                    }
                }
                Assert.IsTrue(imageFound, "no image found in test case " + testCaseName);
            }
        }         // ImageFormatDecodingTest
Exemplo n.º 5
0
        }         // RtfSympleInterpreter

        // ----------------------------------------------------------------------
        static void RtfWriteDocument(IRtfDocument document)
        {
            Console.WriteLine("RTF Version: " + document.RtfVersion.ToString());

            // document info
            Console.WriteLine("Title: " + document.DocumentInfo.Title);
            Console.WriteLine("Subject: " + document.DocumentInfo.Subject);
            Console.WriteLine("Author: " + document.DocumentInfo.Author);
            // ...

            // fonts
            foreach (IRtfFont font in document.FontTable)
            {
                //	Console.WriteLine( "Font: " + font.Name );
            }

            // colors
            foreach (IRtfColor color in document.ColorTable)
            {
                //	Console.WriteLine( "Color: " + color.AsDrawingColor.ToString() );
            }

            // user properties
            foreach (IRtfDocumentProperty documentProperty in document.UserProperties)
            {
                Console.WriteLine("User property: " + documentProperty.Name);
            }

            // visuals
            foreach (IRtfVisual visual in document.VisualContent)
            {
                switch (visual.Kind)
                {
                case RtfVisualKind.Text:
                    Console.WriteLine("Text: " + ((IRtfVisualText)visual).Text);
                    break;

                case RtfVisualKind.Break:
                    Console.WriteLine("Tag: " + ((IRtfVisualBreak)visual).BreakKind.ToString());
                    break;

                case RtfVisualKind.Special:
                    Console.WriteLine("Text: " + ((IRtfVisualSpecialChar)visual).CharKind.ToString());
                    break;

                case RtfVisualKind.Image:
                    IRtfVisualImage image = (IRtfVisualImage)visual;
                    Console.WriteLine("Text: " + image.Format.ToString() +
                                      " " + image.Width.ToString() + "x" + image.Height.ToString());
                    break;
                }
            }
        } // RtfWriteElement
Exemplo n.º 6
0
        }         // DoVisitText

        // ----------------------------------------------------------------------
        protected override void DoVisitImage(IRtfVisualImage visualImage)
        {
            if (!EnterVisual(visualImage))
            {
                return;
            }

            switch (visualImage.Alignment)
            {
            case RtfTextAlignment.Left:
                //Writer.AddStyleAttribute( HtmlTextWriterStyle.TextAlign, "left" );
                break;

            case RtfTextAlignment.Center:
                Writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "center");
                break;

            case RtfTextAlignment.Right:
                Writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "right");
                break;

            case RtfTextAlignment.Justify:
                Writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "justify");
                break;
            }

            BeginParagraph();

            int    imageIndex = documentImages.Count + 1;
            string fileName   = settings.GetImageUrl(imageIndex, visualImage.Format);
            int    width      = settings.ImageAdapter.CalcImageWidth(visualImage.Format, visualImage.Width,
                                                                     visualImage.DesiredWidth, visualImage.ScaleWidthPercent);
            int height = settings.ImageAdapter.CalcImageHeight(visualImage.Format, visualImage.Height,
                                                               visualImage.DesiredHeight, visualImage.ScaleHeightPercent);

            Writer.AddAttribute(HtmlTextWriterAttribute.Width, width.ToString(CultureInfo.InvariantCulture));
            Writer.AddAttribute(HtmlTextWriterAttribute.Height, height.ToString(CultureInfo.InvariantCulture));
            string htmlFileName = HttpUtility.HtmlEncode(fileName);

            Writer.AddAttribute(HtmlTextWriterAttribute.Src, htmlFileName, false);
            RenderImgTag();
            RenderEndTag();

            documentImages.Add(new RtfConvertedImageInfo(
                                   htmlFileName,
                                   settings.ImageAdapter.TargetFormat,
                                   new Size(width, height)));

            LeaveVisual(visualImage);
        }         // DoVisitImage
Exemplo n.º 7
0
        }         // DoVisitText

        // ----------------------------------------------------------------------
        protected override void DoVisitImage(IRtfVisualImage visualImage)
        {
            WriteStartElement("rtfVisualImage");

            WriteElementString("format", visualImage.Format.ToString());
            WriteElementString("width", visualImage.Width.ToString(CultureInfo.InvariantCulture));
            WriteElementString("height", visualImage.Height.ToString(CultureInfo.InvariantCulture));
            WriteElementString("desiredWidth", visualImage.DesiredWidth.ToString(CultureInfo.InvariantCulture));
            WriteElementString("desiredHeight", visualImage.DesiredHeight.ToString(CultureInfo.InvariantCulture));
            WriteElementString("scaleWidthPercent", visualImage.ScaleWidthPercent.ToString(CultureInfo.InvariantCulture));
            WriteElementString("scaleHeightPercent", visualImage.ScaleHeightPercent.ToString(CultureInfo.InvariantCulture));
            WriteElementString("alignment", visualImage.Alignment.ToString());

            WriteElementString("image", visualImage.ImageDataHex);

            WriteEndElement();
        }         // DoVisitImage
Exemplo n.º 8
0
        } // DoVisitText

        // ----------------------------------------------------------------------
        protected override void DoVisitImage(IRtfVisualImage visualImage)
        {
            if (!EnterVisual(visualImage))
            {
                return;
            }

            if (BeginParagraph())
            {
                switch (visualImage.Alignment)
                {
                case RtfTextAlignment.Left:
                    //Writer.AddStyleAttribute( HtmlTextWriterStyle.TextAlign, "left" );
                    break;

                case RtfTextAlignment.Center:
                    Writer.WriteAttributeString("style", "text-align:center");
                    break;

                case RtfTextAlignment.Right:
                    Writer.WriteAttributeString("style", "text-align:right");
                    break;

                case RtfTextAlignment.Justify:
                    Writer.WriteAttributeString("style", "text-align:justify");
                    break;
                }
            }

            string fileName = _settings.ObjectVisitor.GetUri(visualImage);
            int    width    = _settings.ObjectVisitor.CalcImageWidth(visualImage);
            int    height   = _settings.ObjectVisitor.CalcImageHeight(visualImage);

            RenderImgTag();
            Writer.WriteAttributeString("width", width.ToString(CultureInfo.InvariantCulture));
            Writer.WriteAttributeString("height", height.ToString(CultureInfo.InvariantCulture));
            Writer.WriteAttributeString("src", fileName);
            RenderEndTag();

            LeaveVisual(visualImage);
        } // DoVisitImage
Exemplo n.º 9
0
        public virtual string GetUri(IRtfVisualImage image)
        {
            var result = "data:";

            switch (image.Format)
            {
            case RtfVisualImageFormat.Bmp:
                result += "image/bmp;base64,";
                break;

            case RtfVisualImageFormat.Jpg:
                result += "image/jpg;base64,";
                break;

            case RtfVisualImageFormat.Wmf:
                result += "windows/metafile;base64,";
                break;

            default:
                result += "image/png;base64,";
                break;
            }
            return(result + Convert.ToBase64String(image.ImageDataBinary));
        }
Exemplo n.º 10
0
        }         // VisitImage

        // ----------------------------------------------------------------------
        protected virtual void DoVisitImage(IRtfVisualImage visualImage)
        {
        } // DoVisitImage
        // ----------------------------------------------------------------------
        protected override void DoVisitImage( IRtfVisualImage visualImage )
        {
            WriteStartElement( "rtfVisualImage" );

            WriteElementString( "format", visualImage.Format.ToString() );
            WriteElementString( "width", visualImage.Width.ToString() );
            WriteElementString( "height", visualImage.Height.ToString() );
            WriteElementString( "desiredWidth", visualImage.DesiredWidth.ToString() );
            WriteElementString( "desiredHeight", visualImage.DesiredHeight.ToString() );
            WriteElementString( "scaleWidthPercent", visualImage.ScaleWidthPercent.ToString() );
            WriteElementString( "scaleHeightPercent", visualImage.ScaleHeightPercent.ToString() );
            WriteElementString( "alignment", visualImage.Alignment.ToString() );

            WriteElementString( "image", visualImage.ImageDataHex );

            WriteEndElement();
        }
Exemplo n.º 12
0
		} // VisitImage

		// ----------------------------------------------------------------------
		protected virtual void DoVisitImage( IRtfVisualImage visualImage )
		{
		} // DoVisitImage
        // ----------------------------------------------------------------------
        protected override void DoVisitImage( IRtfVisualImage visualImage )
        {
            if ( !EnterVisual( visualImage ) )
            {
                return;
            }

            switch ( visualImage.Alignment )
            {
                case RtfTextAlignment.Left:
                    //Writer.AddAttribute( HtmlTextWriterAttribute.Align, "left", false );
                    break;
                case RtfTextAlignment.Center:
                    Writer.AddAttribute( HtmlTextWriterAttribute.Align, "center", false );
                    break;
                case RtfTextAlignment.Right:
                    Writer.AddAttribute( HtmlTextWriterAttribute.Align, "right", false );
                    break;
                case RtfTextAlignment.Justify:
                    Writer.AddAttribute( HtmlTextWriterAttribute.Align, "justify", false );
                    break;
            }

            BeginParagraph();

            int imageIndex = documentImages.Count + 1;
            string fileName = settings.GetImageUrl( imageIndex, visualImage.Format );
            int width = settings.ImageAdapter.CalcImageWidth( visualImage.Format, visualImage.Width,
                visualImage.DesiredWidth, visualImage.ScaleWidthPercent );
            int height = settings.ImageAdapter.CalcImageHeight( visualImage.Format, visualImage.Height,
                visualImage.DesiredHeight, visualImage.ScaleHeightPercent );

            Writer.AddAttribute( HtmlTextWriterAttribute.Width, width.ToString() );
            Writer.AddAttribute( HtmlTextWriterAttribute.Height, height.ToString() );
            string htmlFileName = HttpUtility.HtmlEncode( fileName );
            Writer.AddAttribute( HtmlTextWriterAttribute.Src, htmlFileName, false );
            RenderImgTag();
            RenderEndTag();

            documentImages.Add( new RtfConvertedImageInfo(
                htmlFileName,
                settings.ImageAdapter.TargetFormat,
                new Size( width, height ) ) );

            LeaveVisual( visualImage );
        }
Exemplo n.º 14
0
        public virtual int CalcImageHeight(IRtfVisualImage image)
        {
            float imgScaleY = image.ScaleHeightPercent / 100.0f;

            return((int)Math.Round((double)image.DesiredHeight * imgScaleY / twipsPerInch * DefaultDpi));
        }
Exemplo n.º 15
0
        public virtual int CalcImageWidth(IRtfVisualImage image)
        {
            float imgScaleX = image.ScaleWidthPercent / 100.0f;

            return((int)Math.Round((double)image.DesiredWidth * imgScaleX / twipsPerInch * DefaultDpi));
        }