Beispiel #1
0
        public static ImagedButton GetImagedButton(EmbeddedImage image, float imageRotationAngle)
        {
            ImagedButton btn = new ImagedButton(DefaultsService.GetDefaultImage(image, EmbeddedImageSize.Size32x32),
                                                imageRotationAngle);

            return(btn);
        }
        private IImageAsset TransformImage(Image o, string id, ReaderContext context)
        {
            var transformImage = new EmbeddedImage(o.GetImageContent());

            transformImage.Id            = id;
            transformImage.FileExtension = o.FileExtension;
            return(transformImage);
        }
        private async Task CreateVersionCompatData(
            ImageFormat format,
            FileInfo inputZipFIle,
            EncryptionConfiguration encryption,
            CompressionConfiguration compression,
            EmbeddedImage embeddedImage)
        {
            var    inputFileName = Path.GetFileNameWithoutExtension(inputZipFIle.Name);
            string outputName    = inputFileName.Substring(0, Math.Min(inputFileName.Length, 10)) + "-" + Enum.GetName(typeof(ImageFormat), format);

            if (embeddedImage != null)
            {
                outputName += "-E";
            }

            if (encryption != null)
            {
                outputName += "-" + Enum.GetName(typeof(EncryptionType), encryption.Type).Substring(0, 3);
            }

            if (compression != null)
            {
                outputName += "-" + Enum.GetName(typeof(CompressionType), compression.Type).Substring(0, 3);
            }


            var tempInputDataDirectory = _ouputTempVersionDataDirectory.CreateSubdirectory(outputName + "_original_data");

            using (var zipFile = ZipFile.Read(inputZipFIle.FullName))
            {
                zipFile.ExtractAll(tempInputDataDirectory.FullName);
            }


            DirectoryInfo outputDirectory = _ouputTempVersionDataDirectory.CreateSubdirectory(outputName);
            var           encoder         = new ImageEncoder(format, encryption, compression, embeddedImage);

            using (Stream encodedImageFile = File.Create(Path.Combine(outputDirectory.FullName, inputFileName + "." + encoder.Extension)))
            {
                encoder.AddDirectory(tempInputDataDirectory);
                await encoder.SaveAsync(encodedImageFile, new EncodingConfiguration(
                                            password : "******",
                                            tempStorageProvider : new MemoryStorageProvider(),
                                            bufferSize : 4096,
                                            fileGroupSize : 1024 * 500));

                inputZipFIle.CopyTo(Path.Combine(outputDirectory.FullName, "Original_Data.zip"), true);
            }

            tempInputDataDirectory.Delete(true);
        }
        public async Task EncodingThenDecoding_ProducesEquivalentResults(
            ImageFormat format,
            FileInfo inputZipFile,
            EncryptionConfiguration encryption,
            CompressionConfiguration compression,
            EmbeddedImage embeddedImage,
            IDictionary <string, string> metadata)
        {
            DirectoryInfo inputDirectory  = null;
            DirectoryInfo outputDirectory = null;

            try
            {
                using (var storageStream = new MemoryStream())
                {
                    inputDirectory = _inputRootDirectory.CreateSubdirectory(Path.GetFileNameWithoutExtension(inputZipFile.Name));
                    using (var zipFile = ZipFile.Read(inputZipFile.FullName))
                    {
                        zipFile.ExtractAll(inputDirectory.FullName);
                    }

                    var encoder = new ImageEncoder(format, encryption, compression, embeddedImage);

                    encoder.Metadata = metadata;
                    encoder.AddDirectory(inputDirectory);
                    await encoder.SaveAsync(storageStream, ImageConfigurations.EncodingConfiguration);

                    storageStream.Position = 0;

                    var decoder = await ImageDecoder.LoadAsync(storageStream, ImageConfigurations.DecodingConfiguration);

                    outputDirectory = _ouputRootDirectory.CreateSubdirectory(inputDirectory.Name);
                    await decoder.DecodeAsync(outputDirectory);

                    AssertEx.AreEqualByJson(metadata, decoder.Metadata);
                    DirectoryAssert.AreEquivalent(inputDirectory, outputDirectory);
                }
            }
            finally
            {
                foreach (var directory in new[] { inputDirectory, outputDirectory })
                {
                    if (directory != null)
                    {
                        directory.Delete(true);
                    }
                }
            }
        }
Beispiel #5
0
        public void InizializeImage()
        {
            EmbeddedImage e = new EmbeddedImage();

            e.Resource = "fondomerende.image.History.png";

            var tinted = new TintedImage
            {
                Scale             = 0.5,
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                Aspect            = Aspect.AspectFill,
                Source            = e.Resource,
            };

            tinted.TintColor = Color.FromHex(Preferences.Get("Colore", "#000000"));
            Griglia.Children.Add(tinted, 0, 0);
        }
        List<EmbeddedImage> _Items;			// list of EmbeddedImage

		public EmbeddedImages(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p)
		{
            _Items = new List<EmbeddedImage>();
			// Loop thru all the child nodes
			foreach(XmlNode xNodeLoop in xNode.ChildNodes)
			{
				if (xNodeLoop.NodeType != XmlNodeType.Element)
					continue;
				if (xNodeLoop.Name == "EmbeddedImage")
				{
					EmbeddedImage ei = new EmbeddedImage(r, this, xNodeLoop);
					_Items.Add(ei);
				}
				else
					this.OwnerReport.rl.LogError(4, "Unknown Report element '" + xNodeLoop.Name + "' ignored.");
			}
			if (_Items.Count == 0)
				OwnerReport.rl.LogError(8, "For EmbeddedImages at least one EmbeddedImage is required.");
			else
                _Items.TrimExcess();
		}
Beispiel #7
0
        private void ProccessStyle(BaseStyle style)
        {
            if (style.BackgroundImage != null)
            {
                BackgroundImage cellBackgroundImage = style.BackgroundImage;
                if (cellBackgroundImage.Image is EmbeddedImage)
                {
                    EmbeddedImage embeddedImage = (EmbeddedImage)cellBackgroundImage.Image;

                    if (!_report.GlobalEmbeddedImages.ContainsKey(embeddedImage.Name))
                    {
                        _report.GlobalEmbeddedImages.Add(embeddedImage.Name,
                                                         System.Drawing.Image.FromStream(new MemoryStream(embeddedImage.ImageData)));

                        embeddedImage.Value = embeddedImage.Name;
                    }
                    else
                    {
                    }
                }
            }
        }
Beispiel #8
0
        public void GetObjectAtIndex_WhenIndexValid_ReturnsEmbeddedObject()
        {
            var document = new SplashDocument();
            var obj      = new EmbeddedImage(new Bitmap(16, 16));

            document.AppendText("obj");
            document.AppendObject(obj);
            document.AppendText("...");

            Assert.Multiple(() =>
            {
                for (int i = 0; i < 3; i++)
                {
                    Assert.IsNull(document.GetObjectAtIndex(i));
                }
                Assert.AreEqual(obj, document.GetObjectAtIndex(3));
                for (int i = 4; i < 7; i++)
                {
                    Assert.IsNull(document.GetObjectAtIndex(i));
                }
            });
        }
Beispiel #9
0
        private Stream GetEmbeddedImageStream(object value)
        {
            if (!(value is string))
            {
                return(null);
            }
            string        result        = value as string;
            EmbeddedImage embeddedImage = FindEmbeddedImage(result);

            if (embeddedImage == null || string.IsNullOrEmpty(embeddedImage.ImageData))
            {
                return(null);
            }
            try
            {
                return(new MemoryStream(Convert.FromBase64String(embeddedImage.ImageData)));
            }
            catch (Exception)             // catch everything -- there could be out of memory, file not found else???
            {
                Trace.TraceError("Error reading embeded image data.");
                return(null);
            }
        }
Beispiel #10
0
        public ImageConfiguration(
            ImageFormat format,
            EmbeddedImage embeddedImage,
            IEnumerable <Directory> directories,
            IDictionary <string, string> metadata,
            EncryptionConfiguration encryption,
            CompressionConfiguration compression)
        {
            if (directories == null)
            {
                throw new ArgumentNullException("directories");
            }

            if (metadata == null)
            {
                throw new ArgumentNullException("metadata");
            }

            var directoryList = directories.ToList();

            if (directoryList.Contains(null))
            {
                throw new ArgumentException("The supplied directories cannot contain null", "directories");
            }

            if (directoryList.Select(directory => directory.Path).Distinct(StringComparer.OrdinalIgnoreCase).Count() < directoryList.Count)
            {
                throw new ArgumentException("The supplied directories cannot contain duplicate paths", "directories");
            }

            _format        = format;
            _embeddedImage = embeddedImage;
            _metadata      = metadata;
            _directories   = directoryList.AsReadOnly();
            _encryption    = encryption;
            _compression   = compression;
        }
Beispiel #11
0
 public CIImageBox(EmbeddedImage embeddedImage)
     : base()
 {
     _image = embeddedImage;
 }
Beispiel #12
0
 public REmbeddedImage(EmbeddedImage embeddedImage)
 {
     EmbImage = embeddedImage;
 }
        public unsafe void AppendStuff()
        {
            var style1 = new StyleBuilder() { Color = Color.Red }.ToStyle();
            var style2 = new StyleBuilder() { LeftMargin = 10, RightMargin = 10 }.ToStyle();
            var style3 = new StyleBuilder() { Font = SystemFonts.SmallCaptionFont, Color = Color.Blue }.ToStyle();
            var embeddedObject = new EmbeddedImage(new Bitmap(16, 16));

            var document = new SplashDocument();
            var changedParagraphIndices = new List<int>();

            document.ParagraphChanged += (sender, e) => changedParagraphIndices.Add(e.ParagraphIndex);

            using (document.BeginStyle(style1))
                document.AppendText("Some text, lalala.\nMore text.");

            using (document.BeginStyle(style2))
            {
                document.AppendText("Tab\t.\n");

                document.AppendText("\0\r"); // these control characters will be discarded

                using (document.BeginStyle(style3))
                {
                    document.AppendLine();
                    document.AppendText(""); // to verify that no change event is raised for empty text
                }

                document.AppendText("(");
                document.AppendObject(embeddedObject);
                document.AppendText(")");
            }

            Assert.Multiple(() =>
            {
                // Check char content.
                Assert.AreEqual("Some text, lalala.\nMore text.Tab\t.\n\n( )", document.ToString());

                // Check style table.
                Assert.AreEqual(4, document.StyleCount);
                Assert.AreEqual(Style.Default, document.LookupStyle(0));
                Assert.AreEqual(style1, document.LookupStyle(1));
                Assert.AreEqual(style2, document.LookupStyle(2));
                Assert.AreEqual(style3, document.LookupStyle(3));

                // Check object table.
                Assert.AreEqual(1, document.ObjectCount);
                Assert.AreEqual(embeddedObject, document.LookupObject(0));

                // Check paragraph table.
                Assert.AreEqual(4, document.ParagraphCount);
                Paragraph* paragraphs = document.GetParagraphZero();

                Assert.AreEqual(0, paragraphs[0].CharIndex); // "Some text, lalala.\n"
                Assert.AreEqual(19, paragraphs[0].CharCount);
                Assert.AreEqual(0, paragraphs[0].RunIndex);
                Assert.AreEqual(1, paragraphs[0].RunCount);

                Assert.AreEqual(19, paragraphs[1].CharIndex); // "More text.Tab\t.\n"
                Assert.AreEqual(16, paragraphs[1].CharCount);
                Assert.AreEqual(1, paragraphs[1].RunIndex);
                Assert.AreEqual(4, paragraphs[1].RunCount);

                Assert.AreEqual(35, paragraphs[2].CharIndex); // "\n"
                Assert.AreEqual(1, paragraphs[2].CharCount);
                Assert.AreEqual(5, paragraphs[2].RunIndex);
                Assert.AreEqual(1, paragraphs[2].RunCount);

                Assert.AreEqual(36, paragraphs[3].CharIndex); // "( )"
                Assert.AreEqual(3, paragraphs[3].CharCount);
                Assert.AreEqual(6, paragraphs[3].RunIndex);
                Assert.AreEqual(3, paragraphs[3].RunCount);

                // Check run table.
                Assert.AreEqual(9, document.RunCount);
                Run* runs = document.GetRunZero();

                Assert.AreEqual(RunKind.Text, runs[0].RunKind); // "Some text, lalala.\n"
                Assert.AreEqual(19, runs[0].CharCount);
                Assert.AreEqual(1, runs[0].StyleIndex);

                Assert.AreEqual(RunKind.Text, runs[1].RunKind); // "More text."
                Assert.AreEqual(10, runs[1].CharCount);
                Assert.AreEqual(1, runs[1].StyleIndex);

                Assert.AreEqual(RunKind.Text, runs[2].RunKind); // "Tab"
                Assert.AreEqual(3, runs[2].CharCount);
                Assert.AreEqual(2, runs[2].StyleIndex);

                Assert.AreEqual(RunKind.Tab, runs[3].RunKind); // "\t"
                Assert.AreEqual(1, runs[3].CharCount);
                Assert.AreEqual(2, runs[3].StyleIndex);

                Assert.AreEqual(RunKind.Text, runs[4].RunKind); // ".\n"
                Assert.AreEqual(2, runs[4].CharCount);
                Assert.AreEqual(2, runs[4].StyleIndex);

                Assert.AreEqual(RunKind.Text, runs[5].RunKind); // "\n"
                Assert.AreEqual(1, runs[5].CharCount);
                Assert.AreEqual(3, runs[5].StyleIndex);

                Assert.AreEqual(RunKind.Text, runs[6].RunKind); // "("
                Assert.AreEqual(1, runs[6].CharCount);
                Assert.AreEqual(2, runs[6].StyleIndex);

                Assert.AreEqual(RunKind.Object, runs[7].RunKind); // "("
                Assert.AreEqual(1, runs[7].CharCount);
                Assert.AreEqual(2, runs[7].StyleIndex);
                Assert.AreEqual(0, runs[7].ObjectIndex);

                Assert.AreEqual(RunKind.Text, runs[8].RunKind); // ")"
                Assert.AreEqual(1, runs[8].CharCount);
                Assert.AreEqual(2, runs[8].StyleIndex);

                // Check that paragraph changed notifications were raised as needed.
                Assert.AreElementsEqual(new[] { 0, 1, 2, 2, 3, 3, 3 }, changedParagraphIndices);
            });
        }
        public void GetObjectAtIndex_WhenIndexValid_ReturnsEmbeddedObject()
        {
            var document = new SplashDocument();
            var obj = new EmbeddedImage(new Bitmap(16, 16));
            document.AppendText("obj");
            document.AppendObject(obj);
            document.AppendText("...");

            Assert.Multiple(() =>
            {
                for (int i = 0; i < 3; i++)
                    Assert.IsNull(document.GetObjectAtIndex(i));
                Assert.AreEqual(obj, document.GetObjectAtIndex(3));
                for (int i = 4; i < 7; i++)
                    Assert.IsNull(document.GetObjectAtIndex(i));
            });
        }
Beispiel #15
0
		private void ParseImage(Scene scene, XElement image)
		{
			var initFrom = image.ElementValue(this.schema.initFromName);
			if (!string.IsNullOrEmpty(initFrom))
			{
				var fileReferenceImage = new FileReferenceImage { Path = Path.Combine(this.basePath, initFrom) };
				this.ParseIdAndName(image, fileReferenceImage);
				scene.Images.Add(fileReferenceImage);
				return;
			}
			var embeddedImage = new EmbeddedImage();
			this.ParseIdAndName(image, embeddedImage);
			scene.Images.Add(embeddedImage);
		}
Beispiel #16
0
 public void VisitImage(EmbeddedImage part)
 {
     Html += "<img alt='" + part.Text + "' src='" + part.UrlImage + "'></img>";
 }
Beispiel #17
0
        public unsafe void AppendStuff()
        {
            var style1 = new StyleBuilder()
            {
                Color = Color.Red
            }.ToStyle();
            var style2 = new StyleBuilder()
            {
                LeftMargin = 10, RightMargin = 10
            }.ToStyle();
            var style3 = new StyleBuilder()
            {
                Font = SystemFonts.SmallCaptionFont, Color = Color.Blue
            }.ToStyle();
            var embeddedObject = new EmbeddedImage(new Bitmap(16, 16));

            var document = new SplashDocument();
            var changedParagraphIndices = new List <int>();

            document.ParagraphChanged += (sender, e) => changedParagraphIndices.Add(e.ParagraphIndex);

            using (document.BeginStyle(style1))
                document.AppendText("Some text, lalala.\nMore text.");

            using (document.BeginStyle(style2))
            {
                document.AppendText("Tab\t.\n");

                document.AppendText("\0\r"); // these control characters will be discarded

                using (document.BeginStyle(style3))
                {
                    document.AppendLine();
                    document.AppendText(""); // to verify that no change event is raised for empty text
                }

                document.AppendText("(");
                document.AppendObject(embeddedObject);
                document.AppendText(")");
            }

            Assert.Multiple(() =>
            {
                // Check char content.
                Assert.AreEqual("Some text, lalala.\nMore text.Tab\t.\n\n( )", document.ToString());

                // Check style table.
                Assert.AreEqual(4, document.StyleCount);
                Assert.AreEqual(Style.Default, document.LookupStyle(0));
                Assert.AreEqual(style1, document.LookupStyle(1));
                Assert.AreEqual(style2, document.LookupStyle(2));
                Assert.AreEqual(style3, document.LookupStyle(3));

                // Check object table.
                Assert.AreEqual(1, document.ObjectCount);
                Assert.AreEqual(embeddedObject, document.LookupObject(0));

                // Check paragraph table.
                Assert.AreEqual(4, document.ParagraphCount);
                Paragraph *paragraphs = document.GetParagraphZero();

                Assert.AreEqual(0, paragraphs[0].CharIndex); // "Some text, lalala.\n"
                Assert.AreEqual(19, paragraphs[0].CharCount);
                Assert.AreEqual(0, paragraphs[0].RunIndex);
                Assert.AreEqual(1, paragraphs[0].RunCount);

                Assert.AreEqual(19, paragraphs[1].CharIndex); // "More text.Tab\t.\n"
                Assert.AreEqual(16, paragraphs[1].CharCount);
                Assert.AreEqual(1, paragraphs[1].RunIndex);
                Assert.AreEqual(4, paragraphs[1].RunCount);

                Assert.AreEqual(35, paragraphs[2].CharIndex); // "\n"
                Assert.AreEqual(1, paragraphs[2].CharCount);
                Assert.AreEqual(5, paragraphs[2].RunIndex);
                Assert.AreEqual(1, paragraphs[2].RunCount);

                Assert.AreEqual(36, paragraphs[3].CharIndex); // "( )"
                Assert.AreEqual(3, paragraphs[3].CharCount);
                Assert.AreEqual(6, paragraphs[3].RunIndex);
                Assert.AreEqual(3, paragraphs[3].RunCount);

                // Check run table.
                Assert.AreEqual(9, document.RunCount);
                Run *runs = document.GetRunZero();

                Assert.AreEqual(RunKind.Text, runs[0].RunKind); // "Some text, lalala.\n"
                Assert.AreEqual(19, runs[0].CharCount);
                Assert.AreEqual(1, runs[0].StyleIndex);

                Assert.AreEqual(RunKind.Text, runs[1].RunKind); // "More text."
                Assert.AreEqual(10, runs[1].CharCount);
                Assert.AreEqual(1, runs[1].StyleIndex);

                Assert.AreEqual(RunKind.Text, runs[2].RunKind); // "Tab"
                Assert.AreEqual(3, runs[2].CharCount);
                Assert.AreEqual(2, runs[2].StyleIndex);

                Assert.AreEqual(RunKind.Tab, runs[3].RunKind); // "\t"
                Assert.AreEqual(1, runs[3].CharCount);
                Assert.AreEqual(2, runs[3].StyleIndex);

                Assert.AreEqual(RunKind.Text, runs[4].RunKind); // ".\n"
                Assert.AreEqual(2, runs[4].CharCount);
                Assert.AreEqual(2, runs[4].StyleIndex);

                Assert.AreEqual(RunKind.Text, runs[5].RunKind); // "\n"
                Assert.AreEqual(1, runs[5].CharCount);
                Assert.AreEqual(3, runs[5].StyleIndex);

                Assert.AreEqual(RunKind.Text, runs[6].RunKind); // "("
                Assert.AreEqual(1, runs[6].CharCount);
                Assert.AreEqual(2, runs[6].StyleIndex);

                Assert.AreEqual(RunKind.Object, runs[7].RunKind); // "("
                Assert.AreEqual(1, runs[7].CharCount);
                Assert.AreEqual(2, runs[7].StyleIndex);
                Assert.AreEqual(0, runs[7].ObjectIndex);

                Assert.AreEqual(RunKind.Text, runs[8].RunKind); // ")"
                Assert.AreEqual(1, runs[8].CharCount);
                Assert.AreEqual(2, runs[8].StyleIndex);

                // Check that paragraph changed notifications were raised as needed.
                Assert.AreElementsEqual(new[] { 0, 1, 2, 2, 3, 3, 3 }, changedParagraphIndices);
            });
        }