コード例 #1
0
ファイル: Document.cs プロジェクト: gregorypilar/interlace
        public static Document Deserialize(PropertyDictionary container, string absolutePath)
        {
            PropertyDictionary documentProperties = container.DictionaryFor("pasteUp");

            if (documentProperties == null) return null;

            if (!documentProperties.HasIntegerFor("majorVersion", "majorVersion"))
            {
                throw new DocumentReadingException("The document lacks the required major and minor version numbers.");
            }

            if (documentProperties.IntegerFor("majorVersion") > MajorVersion)
            {
                throw new DocumentReadingException("The document version is not supported by this reader.");
            }

            Document document = new Document();

            if (documentProperties.IntegerFor("majorVersion") == MajorVersion &&
                documentProperties.IntegerFor("minorVersion") > MinorVersion)
            {
                document._wasDownConverted = true;
            }

            DocumentDeserializationContext context = new DocumentDeserializationContext(
                documentProperties.IntegerFor("majorVersion").Value,
                documentProperties.IntegerFor("minorVersion").Value,
                absolutePath);

            PropertyDictionary imageLinkManagerProperties = documentProperties.DictionaryFor("imageLinkManager");

            if (imageLinkManagerProperties == null) throw new DocumentReadingException(
                "The image link manager dictionary is missing from the document.");

            document._imageLinkManager = new ImageLinkManager(context, imageLinkManagerProperties);

            PropertyArray framesArray = documentProperties.ArrayFor("frames");

            if (framesArray == null) throw new DocumentReadingException("The frames array is missing from the document.");

            for (int i = 0; i < framesArray.Count; i++)
            {
                PropertyDictionary frameProperties = framesArray.DictionaryAt(i);

                if (frameProperties == null) throw new DocumentReadingException(
                    "The document frame array contains an invalid non-dictionary object.");

                document._frames.Add(DeserializeFrame(context, frameProperties));
            }

            return document;
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public DocumentImage(ImageLink imageLink)
        {
            _imageLink = imageLink;

            _document = null;
        }
コード例 #4
0
 public PasteUpRenderer(Document document)
 {
     _document = document;
     _cache = new ImageLinkCache(_document.ImageLinkManager);
 }