Example #1
0
        public DocumentImage(DocumentDeserializationContext context, PropertyDictionary framedObjectDictionary)
        {
            int imageLinkIndex = framedObjectDictionary.IntegerFor("imageLinkIndex").Value;

            if (!context.ImageLinksByKey.ContainsKey(imageLinkIndex))
            {
                throw new DocumentReadingException(string.Format(
                    "The image link index \"{0}\" was not found in the image link manager dictionary.",
                    imageLinkIndex));
            }

            _imageLink = context.ImageLinksByKey[imageLinkIndex];
        }
        internal ImageLinkManager(DocumentDeserializationContext context, PropertyDictionary managerDictionary)
        {
            PropertyDictionary imageLinks = managerDictionary.DictionaryFor("imageLinks");

            if (imageLinks == null) throw new InvalidOperationException("The image manager dictionary is missing the \"imageLinks\" key.");

            foreach (object key in imageLinks.Keys)
            {
                if (!(key is int)) throw new InvalidOperationException("The image links dictionary contains a non-integer key, which is not permitted.");

                int linkIndex = (int)key;

                PropertyDictionary imageDictionary = imageLinks.DictionaryFor(key);

                ImageLink link = new ImageLink(context, imageDictionary);

                _referenceCountByLink[link] = 0;
                context.ImageLinksByKey[linkIndex] = link;
            }
        }
Example #3
0
        public DocumentImage(ImageLink imageLink)
        {
            _imageLink = imageLink;

            _document = null;
        }
        public void Test()
        {
            // Build a document:
            Document document = new Document();

            LabelDocumentFrame label = new LabelDocumentFrame();
            label.Label = "Testing 123";
            label.OffsetInDocument = new Point(1, 2);
            label.CallOutOffsetInDocument = new Size(3, 4);

            DocumentFill fill = new DocumentFill();
            fill.Color = Color.Red;

            RectangularDocumentFrame fillFrame = new RectangularDocumentFrame(fill);
            fillFrame.ClipBounds = new Rectangle(5, 6, 7, 8);
            fillFrame.OffsetInDocument = new Point(9, 10);

            ImageLink imageLink = new ImageLink(@"C:\Windows\Prairie Wind.bmp");
            DocumentImage image = new DocumentImage(imageLink);
            RectangularDocumentFrame imageFrame = new RectangularDocumentFrame(image);

            document.Frames.Add(label);
            document.Frames.Add(fillFrame);
            document.Frames.Add(imageFrame);

            // Round trip it:
            PropertyDictionary serialized = document.Serialize(null);

            Document resultingDocument = Document.Deserialize(serialized, @"C:\");

            // Check the frames list:
            Assert.AreEqual(3, resultingDocument.Frames.Count);
            Assert.IsAssignableFrom(typeof(LabelDocumentFrame), resultingDocument.Frames[0]);
            Assert.IsAssignableFrom(typeof(RectangularDocumentFrame), resultingDocument.Frames[1]);
            Assert.IsAssignableFrom(typeof(RectangularDocumentFrame), resultingDocument.Frames[2]);

            // Check the label frame:
            LabelDocumentFrame resultingLabel = resultingDocument.Frames[0] as LabelDocumentFrame;

            Assert.AreEqual(label.Label, resultingLabel.Label);
            Assert.AreEqual(label.OffsetInDocument, resultingLabel.OffsetInDocument);
            Assert.AreEqual(label.CallOutOffsetInDocument, resultingLabel.CallOutOffsetInDocument);

            // Check the fill frame:
            RectangularDocumentFrame resultingFillFrame = resultingDocument.Frames[1] as RectangularDocumentFrame;
            DocumentFill resultingFill = resultingFillFrame.FramedObject as DocumentFill;

            Assert.AreEqual(resultingFillFrame.ClipBounds, fillFrame.ClipBounds);
            Assert.AreEqual(resultingFillFrame.OffsetInDocument, fillFrame.OffsetInDocument);

            Assert.AreEqual(resultingFill.Color.ToArgb(), fill.Color.ToArgb());

            // Check the image frame:
            RectangularDocumentFrame resultingImageFrame = resultingDocument.Frames[2] as RectangularDocumentFrame;
            DocumentImage resultingImage = resultingImageFrame.FramedObject as DocumentImage;

            Assert.AreEqual(resultingImageFrame.ClipBounds, imageFrame.ClipBounds);
            Assert.AreEqual(resultingImageFrame.OffsetInDocument, imageFrame.OffsetInDocument);

            ImageLink resultingImageLink = resultingImage.ImageLink;

            Assert.AreEqual(imageLink.FileName, resultingImageLink.FileName);
            Assert.AreEqual(imageLink.PhysicalDimension, resultingImageLink.PhysicalDimension);
        }
Example #5
0
 public Image GetCachedImage(ImageLink link)
 {
     return _images[link];
 }
Example #6
0
        private void PasteUpControl_DragDrop(object sender, DragEventArgs e)
        {
            string[] fileNames = e.Data.GetData(DataFormats.FileDrop) as string[];

            foreach (string fileName in fileNames)
            {
                ImageLink link = new ImageLink(Path.GetFullPath(fileName));

                _document.Frames.Add(new RectangularDocumentFrame(new DocumentImage(link)));
            }
        }
Example #7
0
        public void AddEncodedImage(byte[] image)
        {
            ImageLink link = new ImageLink(image);

            _document.Frames.Add(new RectangularDocumentFrame(new DocumentImage(link)));
        }
        public void Detach(ImageLink link)
        {
            if (!_referenceCountByLink.ContainsKey(link)) throw new InvalidOperationException();

            int newReferenceCount = _referenceCountByLink[link] - 1;

            if (newReferenceCount == 0)
            {
                _referenceCountByLink.Remove(link);

                if (LinkDetached != null) LinkDetached(this, new LinkEventArgs(this, link));
            }
            else
            {
                _referenceCountByLink[link] = newReferenceCount;
            }
        }
        public void Attach(ImageLink link)
        {
            if (_referenceCountByLink.ContainsKey(link))
            {
                _referenceCountByLink[link] = _referenceCountByLink[link] + 1;
            }
            else
            {
                _referenceCountByLink[link] = 1;

                if (LinkAttached != null) LinkAttached(this, new LinkEventArgs(this, link));
            }
        }