}         // DoEndDocument

        // ----------------------------------------------------------------------
        private void EndParagraph(IRtfInterpreterContext context)
        {
            RtfTextAlignment finalParagraphAlignment = context.GetSafeCurrentTextFormat().Alignment;

            foreach (IRtfVisual alignedVisual in pendingParagraphContent)
            {
                switch (alignedVisual.Kind)
                {
                case RtfVisualKind.Image:
                    RtfVisualImage image = (RtfVisualImage)alignedVisual;
                    // ReSharper disable RedundantCheckBeforeAssignment
                    if (image.Alignment != finalParagraphAlignment)
                    // ReSharper restore RedundantCheckBeforeAssignment
                    {
                        image.Alignment = finalParagraphAlignment;
                    }
                    break;

                case RtfVisualKind.Text:
                    RtfVisualText text = (RtfVisualText)alignedVisual;
                    if (text.Format.Alignment != finalParagraphAlignment)
                    {
                        IRtfTextFormat correctedFormat       = ((RtfTextFormat)text.Format).DeriveWithAlignment(finalParagraphAlignment);
                        IRtfTextFormat correctedUniqueFormat = context.GetUniqueTextFormatInstance(correctedFormat);
                        text.Format = correctedUniqueFormat;
                    }
                    break;
                }
            }
            pendingParagraphContent.Clear();
        }         // EndParagraph
Esempio n. 2
0
        }         // DoBeginDocument

        // ----------------------------------------------------------------------
        protected override void DoInsertImage(IRtfInterpreterContext context,
                                              RtfVisualImageFormat format,
                                              int width, int height,
                                              int desiredWidth, int desiredHeight,
                                              int scaleWidthPercent, int scaleHeightPercent,
                                              string imageDataHex, String importFileName
                                              )
        {
            int    imageIndex = convertedImages.Count + 1;
            string fileName   = settings.GetImageFileName(imageIndex, format);

            EnsureImagesPath(fileName);

            byte[]      imageBuffer = RtfVisualImage.ToBinary(imageDataHex);
            Size        imageSize;
            ImageFormat imageFormat;

            if (settings.ImageAdapter.TargetFormat == null)
            {
                using (var memory = new MemoryStream(imageBuffer))
                    using (var random = memory.AsRandomAccessStream())
                    {
                        var image = new BitmapImage();
                        image.SetSource(random);

                        imageFormat = ImageFormat.Jpeg;
                        imageSize   = new Size(image.PixelWidth, image.PixelHeight);
                    }
                using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(fileName, FileMode.Create)))
                {
                    binaryWriter.Write(imageBuffer);
                }
            }
            else
            {
                imageFormat = settings.ImageAdapter.TargetFormat;
                if (settings.ScaleImage)
                {
                    imageSize = new Size(
                        settings.ImageAdapter.CalcImageWidth(format, width, desiredWidth, scaleWidthPercent),
                        settings.ImageAdapter.CalcImageHeight(format, height, desiredHeight, scaleHeightPercent));
                }
                else
                {
                    imageSize = new Size(width, height);
                }

                SaveImage(imageBuffer, format, fileName, imageSize);
            }

            convertedImages.Add(new RtfConvertedImageInfo(fileName, imageFormat, imageSize));
        }         // DoInsertImage
Esempio n. 3
0
        }         // DoBeginDocument

        // ----------------------------------------------------------------------
        protected override void DoInsertImage(IRtfInterpreterContext context,
                                              RtfVisualImageFormat format,
                                              int width, int height,
                                              int desiredWidth, int desiredHeight,
                                              int scaleWidthPercent, int scaleHeightPercent,
                                              string imageDataHex
                                              )
        {
            int    imageIndex = convertedImages.Count + 1;
            string fileName   = settings.GetImageFileName(imageIndex, format);

            EnsureImagesPath(fileName);

            byte[]      imageBuffer = RtfVisualImage.ToBinary(imageDataHex);
            Size        imageSize;
            ImageFormat imageFormat;

            if (settings.ImageAdapter.TargetFormat == null)
            {
                using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(imageBuffer)))
                {
                    imageFormat = image.RawFormat;
                    imageSize   = image.Size;
                }
                using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(fileName, FileMode.Create)))
                {
                    binaryWriter.Write(imageBuffer);
                }
            }
            else
            {
                imageFormat = settings.ImageAdapter.TargetFormat;
                if (settings.ScaleImage)
                {
                    imageSize = new Size(
                        settings.ImageAdapter.CalcImageWidth(format, width, desiredWidth, scaleWidthPercent),
                        settings.ImageAdapter.CalcImageHeight(format, height, desiredHeight, scaleHeightPercent));
                }
                else
                {
                    imageSize = new Size(width, height);
                }

                SaveImage(imageBuffer, format, fileName, imageSize);
            }

            convertedImages.Add(new RtfConvertedImageInfo(fileName, imageFormat, imageSize));
        }         // DoInsertImage