Exemplo n.º 1
0
        SerializeNextTreeNode(
            ReachVisualSerializerContext context
            )
        {
            if (context.ContextStack.Count > 0)
            {
                Stack <NodeContext> contextStack = context.ContextStack;
                VisualTreeFlattener flattener    = context.VisualFlattener;

                ReachVisualSerializerContext nextContext = new ReachVisualSerializerContext(this,
                                                                                            contextStack,
                                                                                            flattener,
                                                                                            SerializerAction.serializeNextTreeNode);

                ((IXpsSerializationManagerAsync)SerializationManager).OperationStack.Push(nextContext);


                NodeContext ctx = contextStack.Peek();

                Visual v = ctx.GetNextChild();

                if (v != null)
                {
                    if (flattener.StartVisual(v))
                    {
                        contextStack.Push(new NodeContext(v));
                    }
                }
                else
                {
                    contextStack.Pop();
                    flattener.EndVisual();
                }
            }
        }
Exemplo n.º 2
0
        SerializeDisguisedVisual(
            object serializedObject
            )
        {
            Visual v = serializedObject as Visual;

            if (v == null)
            {
                throw new ArgumentException(SR.Get(SRID.MustBeOfType, "serializedObject", typeof(Visual)));
            }

            //  The new class XpsOMSerializationManager now also interacts with this class
            // the cast below is shorthand for cast to either XpsSerializationManager or XpsOMSerializationManager
            // we want this to throw an InvalidCastException if it fails to mantain compatibility.
            if ((IXpsSerializationManager)SerializationManager != null)
            {
                XmlWriter pageWriter = SerializationManager.
                                       PackagingPolicy.AcquireXmlWriterForPage();

                XmlWriter resWriter = SerializationManager.
                                      PackagingPolicy.AcquireXmlWriterForResourceDictionary();

                Size fixedPageSize = ((IXpsSerializationManager)SerializationManager).FixedPageSize;

                VisualTreeFlattener flattener = ((IXpsSerializationManager)SerializationManager).
                                                VisualSerializationService.AcquireVisualTreeFlattener(resWriter,
                                                                                                      pageWriter,
                                                                                                      fixedPageSize);

                return(flattener.StartVisual(v));
            }

            return(false);
        }
Exemplo n.º 3
0
        SerializeDisguisedVisual(
            object serializedObject
            )
        {
            Visual v = serializedObject as Visual;

            if (v == null)
            {
                throw new ArgumentException(SR.Get(SRID.MustBeOfType, "serializedObject", typeof(Visual)));
            }

            IXpsSerializationManagerAsync manager = (IXpsSerializationManagerAsync)SerializationManager;

            XmlWriter pageWriter = ((PackageSerializationManager)manager).
                                   PackagingPolicy.AcquireXmlWriterForPage();

            XmlWriter resWriter = ((PackageSerializationManager)manager).
                                  PackagingPolicy.AcquireXmlWriterForResourceDictionary();

            Size fixedPageSize            = ((IXpsSerializationManager)SerializationManager).FixedPageSize;
            VisualTreeFlattener flattener = ((IXpsSerializationManager)SerializationManager).
                                            VisualSerializationService.AcquireVisualTreeFlattener(resWriter,
                                                                                                  pageWriter,
                                                                                                  fixedPageSize);

            return(flattener.StartVisual(v));
        }
Exemplo n.º 4
0
        SerializeTree(
            Visual visual,
            XmlWriter resWriter,
            XmlWriter bodyWriter
            )
        {
            Size fixedPageSize = ((IXpsSerializationManager)SerializationManager).FixedPageSize;

            VisualTreeFlattener flattener = ((IXpsSerializationManagerAsync)SerializationManager).
                                            VisualSerializationService.AcquireVisualTreeFlattener(resWriter,
                                                                                                  bodyWriter,
                                                                                                  fixedPageSize);

            if (flattener.StartVisual(visual))
            {
                Stack <NodeContext> contextStack = new Stack <NodeContext>();
                contextStack.Push(new NodeContext(visual));

                ReachVisualSerializerContext context = new ReachVisualSerializerContext(this,
                                                                                        contextStack,
                                                                                        flattener,
                                                                                        SerializerAction.serializeNextTreeNode);

                ((IXpsSerializationManagerAsync)SerializationManager).OperationStack.Push(context);
            }
        }
        WalkVisual(
            Visual visual
            )
        {
            bool bManulStartDoc  = false;
            bool bManulStartpage = false;

            if (_startDocCnt == 0)
            {
                StartDocument(visual, true);
                bManulStartDoc = true;
            }
            if (!_isStartPage)
            {
                StartPage();
                bManulStartpage = true;
            }

            //
            // Call VisualTreeFlattener to flatten the visual on IMetroDrawingContext
            //
            VisualTreeFlattener.Walk(visual, _device, PageSize, new TreeWalkProgress());

            if (bManulStartpage)
            {
                EndPage();
            }
            if (bManulStartDoc)
            {
                EndDocument();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Render visual to printer.
        /// </summary>
        private void Render(Visual visual, string uri)
        {
            if (visual == null)
            {
                throw new ArgumentNullException("visual");
            }

            int dpiX = _jobTicket.PageResolution.ResolutionX;
            int dpiY = _jobTicket.PageResolution.ResolutionY;

            if (dpiX < 0)
            {
                dpiX = 600;
            }

            if (dpiY < 0)
            {
                dpiY = 600;
            }

            AssertPositive(dpiX, "PageResolution.ResolutionX");
            AssertPositive(dpiY, "PageResolution.ResolutionY");

            int sizeX = (int)(_jobTicket.PageMediaSize.MediaSizeX * dpiX);
            int sizeY = (int)(_jobTicket.PageMediaSize.MediaSizeY * dpiY);

            AssertPositive(sizeX, "PageCanvasSizeCap.CanvasSizeX");
            AssertPositive(sizeY, "PageCanvasSizeCap.CanvasSizeY");

            if (IsPremium())
            {
                VisualTreeFlattener.SaveAsXml(visual, _writer, new ContainerFixedXamlDesigner(_eDocJob, uri));
            }
        }
Exemplo n.º 7
0
        EndPersistObjectData(bool needEndVisual, ReachTreeWalker treeWalker)
        {
            if (needEndVisual)
            {
                XmlWriter pageWriter = SerializationManager.
                                       PackagingPolicy.AcquireXmlWriterForPage();

                XmlWriter resWriter = SerializationManager.
                                      PackagingPolicy.AcquireXmlWriterForResourceDictionary();

                Size fixedPageSize            = _xpsOMSerializationManager.FixedPageSize;
                VisualTreeFlattener flattener = _xpsOMSerializationManager.
                                                VisualSerializationService.AcquireVisualTreeFlattener(resWriter,
                                                                                                      pageWriter,
                                                                                                      fixedPageSize);

                flattener.EndVisual();
            }

            SerializationManager.PackagingPolicy.PreCommitCurrentPage();

            //
            // Copy hyperlinks into stream
            //
            treeWalker.CommitHyperlinks();

            XmlWriter.WriteEndElement();
            //
            //Release used resources
            //
            XmlWriter = null;
            //
            // Free the image table in use for this page
            //
            _xpsOMSerializationManager.ResourcePolicy.CurrentPageImageTable = null;
            //
            // Free the colorContext table in use for this page
            //
            _xpsOMSerializationManager.ResourcePolicy.CurrentPageColorContextTable = null;
            //
            // Free the resourceDictionary table in use for this page
            //
            _xpsOMSerializationManager.ResourcePolicy.CurrentPageResourceDictionaryTable = null;

            _xpsOMSerializationManager.VisualSerializationService.ReleaseVisualTreeFlattener();

            _xpsOMSerializationManager.RegisterPageEnd();

            //
            // Signal to any registered callers that the Page has been serialized
            //
            XpsSerializationProgressChangedEventArgs progressEvent =
                new XpsSerializationProgressChangedEventArgs(XpsWritingProgressChangeLevel.FixedPageWritingProgress,
                                                             0,
                                                             0,
                                                             null);

            _xpsOMSerializationManager.OnXPSSerializationProgressChanged(progressEvent);
        }
Exemplo n.º 8
0
 ReachVisualSerializerContext(
     ReachSerializerAsync serializer,
     Stack <NodeContext> contextStack,
     VisualTreeFlattener flattener,
     SerializerAction action
     ) :
     base(serializer, action)
 {
     this._contextStack = contextStack;
     this._flattener    = flattener;
 }
Exemplo n.º 9
0
        static int vipID; // = 0;

        static void SerializeVisual(Visual visual, double width, double height, String filename)
        {
            FileStream    stream = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite);
            XmlTextWriter writer = new System.Xml.XmlTextWriter(stream, System.Text.Encoding.UTF8);

            writer.Formatting  = System.Xml.Formatting.Indented;
            writer.Indentation = 4;
            writer.WriteStartElement("FixedDocument");
            writer.WriteAttributeString("xmlns", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
            writer.WriteAttributeString("xmlns:x", "http://schemas.microsoft.com/winfx/2006/xaml");

            writer.WriteStartElement("PageContent");
            writer.WriteStartElement("FixedPage");
            writer.WriteAttributeString("Width", width.ToString(CultureInfo.InvariantCulture));
            writer.WriteAttributeString("Height", height.ToString(CultureInfo.InvariantCulture));
            writer.WriteAttributeString("Background", "White");
            writer.WriteStartElement("Canvas");

            System.IO.StringWriter resString = new StringWriter(CultureInfo.InvariantCulture);

            System.Xml.XmlTextWriter resWriter = new System.Xml.XmlTextWriter(resString);
            resWriter.Formatting  = System.Xml.Formatting.Indented;
            resWriter.Indentation = 4;

            System.IO.StringWriter bodyString = new StringWriter(CultureInfo.InvariantCulture);

            System.Xml.XmlTextWriter bodyWriter = new System.Xml.XmlTextWriter(bodyString);
            bodyWriter.Formatting  = System.Xml.Formatting.Indented;
            bodyWriter.Indentation = 4;

            VisualTreeFlattener.SaveAsXml(visual, resWriter, bodyWriter, filename);

            resWriter.Close();
            bodyWriter.Close();

            writer.Flush();
            writer.WriteRaw(resString.ToString());
            writer.WriteRaw(bodyString.ToString());

            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.WriteEndElement();

            writer.WriteEndElement(); // FixedDocument
            writer.Close();
            stream.Close();
        }
Exemplo n.º 10
0
        AcquireVisualTreeFlattener(
            XmlWriter resWriter,
            XmlWriter bodyWriter,
            Size pageSize
            )
        {
            if (_visualTreeFlattener == null)
            {
                _visualTreeFlattener = new VisualTreeFlattener(resWriter,
                                                               bodyWriter,
                                                               _serializationManager,
                                                               pageSize,
                                                               new TreeWalkProgress());
            }

            return(_visualTreeFlattener);
        }
Exemplo n.º 11
0
        SerializeTree(
            Visual visual,
            XmlWriter resWriter,
            XmlWriter bodyWriter
            )
        {
            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSerializeTreeStart);


            Size fixedPageSize = ((IXpsSerializationManager)SerializationManager).FixedPageSize;

            VisualTreeFlattener flattener = ((IXpsSerializationManager)SerializationManager).
                                            VisualSerializationService.AcquireVisualTreeFlattener(resWriter,
                                                                                                  bodyWriter,
                                                                                                  fixedPageSize);

            Stack <NodeContext> contextStack = new Stack <NodeContext>();

            if (flattener.StartVisual(visual))
            {
                contextStack.Push(new NodeContext(visual));
            }

            while (contextStack.Count > 0)
            {
                NodeContext ctx = contextStack.Peek();

                Visual v = ctx.GetNextChild();
                if (v != null)
                {
                    if (flattener.StartVisual(v))
                    {
                        contextStack.Push(new NodeContext(v));
                    }
                }
                else
                {
                    contextStack.Pop();
                    flattener.EndVisual();
                }
            }

            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSerializeTreeEnd);
        }
Exemplo n.º 12
0
        WalkVisual(
            Visual visual
            )
        {
            bool bManulStartDoc  = false;
            bool bManulStartpage = false;

            if (_startDocCnt == 0)
            {
                StartDocument(visual, true);
                bManulStartDoc = true;
            }
            if (!_isStartPage)
            {
                StartPage();
                bManulStartpage = true;
            }

            //
            // Call VisualTreeFlattener to flatten the visual on IMetroDrawingContext
            //
            Toolbox.EmitEvent(EventTrace.Event.WClientDRXLoadPrimitiveBegin);

            VisualTreeFlattener.Walk(visual, _device, PageSize, new TreeWalkProgress());

            Toolbox.EmitEvent(EventTrace.Event.WClientDRXLoadPrimitiveEnd);

            if (bManulStartpage)
            {
                EndPage();
            }
            if (bManulStartDoc)
            {
                EndDocument();
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Walk a visual tree and flatten it to (S0) DrawingContext
        /// </summary>
        /// <param name="visual"></param>
        /// <param name="dc"></param>
        static public void Walk(Visual visual, DrawingContext dc)
        {
            VisualTreeFlattener flattener = new VisualTreeFlattener(dc);

            flattener.Walk(visual, null);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Serialize a visual to fixed (S0) XAML
 /// </summary>
 /// <param name="visual"></param>
 /// <param name="writer"></param>
 static internal void SaveAsXml(Visual visual, System.Xml.XmlWriter writer)
 {
     VisualTreeFlattener.SaveAsXml(visual, writer, new FixedXamlDesigner());
 }
        EndSerializeReachFixedPage(
            ReachFixedPageSerializerContext context
            )
        {
            ReachFixedPageSerializerContext thisContext = context as ReachFixedPageSerializerContext;

            if (thisContext != null)
            {
                if (thisContext.EndVisual)
                {
                    XmlWriter pageWriter = ((XpsSerializationManagerAsync)SerializationManager).
                                           PackagingPolicy.AcquireXmlWriterForPage();

                    XmlWriter resWriter = ((XpsSerializationManagerAsync)SerializationManager).
                                          PackagingPolicy.AcquireXmlWriterForResourceDictionary();


                    Size fixedPageSize            = ((IXpsSerializationManager)SerializationManager).FixedPageSize;
                    VisualTreeFlattener flattener = ((IXpsSerializationManager)SerializationManager).
                                                    VisualSerializationService.AcquireVisualTreeFlattener(resWriter,
                                                                                                          pageWriter,
                                                                                                          fixedPageSize);

                    flattener.EndVisual();
                }


                ((XpsSerializationManagerAsync)SerializationManager).PackagingPolicy.PreCommitCurrentPage();

                //
                // Copy hyperlinks into stream
                //
                thisContext.TreeWalker.CommitHyperlinks();

                XmlWriter.WriteEndElement();
                //
                //Release used resources
                //
                XmlWriter = null;
                //
                // Free the image table in use for this page
                //
                ((XpsSerializationManagerAsync)SerializationManager).ResourcePolicy.CurrentPageImageTable = null;
                //
                // Free the colorContext table in use for this page
                //
                ((XpsSerializationManagerAsync)SerializationManager).ResourcePolicy.CurrentPageColorContextTable = null;

                //
                // Signal to any registered callers that the Page has been serialized
                //
                XpsSerializationProgressChangedEventArgs progressEvent =
                    new XpsSerializationProgressChangedEventArgs(XpsWritingProgressChangeLevel.FixedPageWritingProgress,
                                                                 0,
                                                                 0,
                                                                 null);

                ((IXpsSerializationManager)SerializationManager).OnXPSSerializationProgressChanged(progressEvent);
                ((IXpsSerializationManager)SerializationManager).VisualSerializationService.ReleaseVisualTreeFlattener();
                if (SerializationManager is IXpsSerializationManager)
                {
                    (SerializationManager as IXpsSerializationManager).RegisterPageEnd();
                }
            }
        }
        /// <summary>
        /// Walk a visual tree and flatten it to (S0) DrawingContext
        /// </summary>
        /// <param name="visual"></param>
        /// <param name="dc"></param>
        //CASRemoval:[StrongNameIdentityPermission(SecurityAction.LinkDemand, PublicKey=Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_STRING)]
        static public void Walk(Visual visual, DrawingContext dc)
        {
            VisualTreeFlattener flattener = new VisualTreeFlattener(dc);

            flattener.Walk(visual, null);
        }
Exemplo n.º 17
0
        private void SerializeHyperlink(PathGeometry geometry, String id, Uri navigateUri)
        {
            String    nameForType = "Path";
            XmlWriter writer      = LinkXmlWriter;

            bool useID = false;

            if (!String.IsNullOrEmpty(id))
            {
                useID = AddLinkTarget(id);
            }

            if (!useID && navigateUri == null)
            {
                // don't write out this path
                return;
            }

            writer.WriteStartElement(nameForType);

            if (navigateUri != null)
            {
                if (IsFragment(navigateUri))
                {
                    XpsPackagingPolicy   policy   = SerializationManager.PackagingPolicy as XpsPackagingPolicy;
                    XpsOMPackagingPolicy omPolicy = SerializationManager.PackagingPolicy as XpsOMPackagingPolicy;
                    if (policy == null && omPolicy == null)
                    {
                        throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_WrongPackagingPolicy));
                    }

                    Uri documentUri = SerializationManager.PackagingPolicy.CurrentFixedDocumentUri;
                    Uri pageUri     = SerializationManager.PackagingPolicy.CurrentFixedPageUri;

                    Uri    relativeUri         = PackUriHelper.GetRelativeUri(pageUri, documentUri);
                    string documentFragmentUri = relativeUri.OriginalString + navigateUri.OriginalString;
                    WriteAttribute(writer, "FixedPage.NavigateUri", documentFragmentUri);
                }
                else
                {
                    WriteAttribute(writer, "FixedPage.NavigateUri", navigateUri);
                }
                WriteAttribute(writer, "Fill", "#00000000");
            }
            else
            {
                WriteAttribute(writer, "Opacity", "0");
            }

            if (useID)
            {
                WriteAttribute(writer, "Name", id);
            }

            geometry.FillRule = FillRule.Nonzero;

            Size pageSize = ((IXpsSerializationManager)_serializationManager).FixedPageSize;

            VisualTreeFlattener.WritePath(writer, geometry, pageSize);

            writer.WriteEndElement();
        }
        PersistObjectData(
            SerializableObjectContext serializableObjectContext
            )
        {
            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSerializationBegin);

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

            if (SerializationManager is IXpsSerializationManager)
            {
                (SerializationManager as IXpsSerializationManager).RegisterPageStart();
            }

            FixedPage fixedPage = serializableObjectContext.TargetObject as FixedPage;

            ReachTreeWalker treeWalker = new ReachTreeWalker(this);

            treeWalker.SerializeLinksInFixedPage((FixedPage)serializableObjectContext.TargetObject);

            String xmlnsForType = SerializationManager.GetXmlNSForType(serializableObjectContext.TargetObject.GetType());

            if (xmlnsForType == null)
            {
                XmlWriter.WriteStartElement(serializableObjectContext.Name);
            }
            else
            {
                XmlWriter.WriteStartElement(serializableObjectContext.Name);

                XmlWriter.WriteAttributeString(XpsS0Markup.Xmlns, xmlnsForType);
                XmlWriter.WriteAttributeString(XpsS0Markup.XmlnsX, XpsS0Markup.XmlnsXSchema);

                XmlLanguage language = fixedPage.Language;
                if (language == null)
                {
                    //If the language property is null, assign the language to the default
                    language = XmlLanguage.GetLanguage(XpsS0Markup.XmlLangValue);
                }

                SerializationManager.Language = language;

                XmlWriter.WriteAttributeString(XpsS0Markup.XmlLang, language.ToString());
            }
            {
                Size fixedPageSize = new Size(fixedPage.Width, fixedPage.Height);
                ((IXpsSerializationManager)SerializationManager).FixedPageSize = fixedPageSize;

                //
                // Before we serialize any properties on the FixedPage, we need to
                // serialize the FixedPage as a Visual
                //
                Visual fixedPageAsVisual = serializableObjectContext.TargetObject as Visual;

                bool needEndVisual = false;

                if (fixedPageAsVisual != null)
                {
                    needEndVisual = SerializePageAsVisual(fixedPageAsVisual);
                }

                if (serializableObjectContext.IsComplexValue)
                {
                    PrintTicket printTicket = ((IXpsSerializationManager)SerializationManager).FixedPagePrintTicket;

                    if (printTicket != null)
                    {
                        PrintTicketSerializer serializer = new PrintTicketSerializer(SerializationManager);
                        serializer.SerializeObject(printTicket);
                        ((IXpsSerializationManager)SerializationManager).FixedPagePrintTicket = null;
                    }

                    SerializeObjectCore(serializableObjectContext);
                }
                else
                {
                    throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_WrongPropertyTypeForFixedPage));
                }

                if (needEndVisual)
                {
                    XmlWriter pageWriter = ((XpsSerializationManager)SerializationManager).
                                           PackagingPolicy.AcquireXmlWriterForPage();

                    XmlWriter resWriter = ((XpsSerializationManager)SerializationManager).
                                          PackagingPolicy.AcquireXmlWriterForResourceDictionary();


                    VisualTreeFlattener flattener = ((IXpsSerializationManager)SerializationManager).
                                                    VisualSerializationService.AcquireVisualTreeFlattener(resWriter,
                                                                                                          pageWriter,
                                                                                                          fixedPageSize);

                    flattener.EndVisual();
                }
            }

            ((XpsSerializationManager)SerializationManager).PackagingPolicy.PreCommitCurrentPage();

            //
            // Copy hyperlinks into stream
            //
            treeWalker.CommitHyperlinks();

            XmlWriter.WriteEndElement();
            //
            //Release used resources
            //
            XmlWriter = null;
            //
            // Free the image table in use for this page
            //
            ((XpsSerializationManager)SerializationManager).ResourcePolicy.CurrentPageImageTable = null;
            //
            // Free the colorContext table in use for this page
            //
            ((XpsSerializationManager)SerializationManager).ResourcePolicy.CurrentPageColorContextTable = null;
            //
            // Free the resourceDictionary table in use for this page
            //
            ((XpsSerializationManager)SerializationManager).ResourcePolicy.CurrentPageResourceDictionaryTable = null;

            ((IXpsSerializationManager)SerializationManager).VisualSerializationService.ReleaseVisualTreeFlattener();

            if (SerializationManager is IXpsSerializationManager)
            {
                (SerializationManager as IXpsSerializationManager).RegisterPageEnd();
            }

            //
            // Signal to any registered callers that the Page has been serialized
            //
            XpsSerializationProgressChangedEventArgs progressEvent =
                new XpsSerializationProgressChangedEventArgs(XpsWritingProgressChangeLevel.FixedPageWritingProgress,
                                                             0,
                                                             0,
                                                             null);

            ((IXpsSerializationManager)SerializationManager).OnXPSSerializationProgressChanged(progressEvent);

            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSerializationEnd);
        }