Exemple #1
0
        SimulateBeginFixedPage(
            )
        {
            XmlWriter xmlWriter = null;

            (_serializationManager as IXpsSerializationManager)?.RegisterPageStart();
            //
            // Build the current Page Image Table
            //
            _serializationManager.ResourcePolicy.CurrentPageImageTable = new Dictionary <int, Uri>();
            //
            // Build the current Page ColorContext Table
            //
            _serializationManager.ResourcePolicy.CurrentPageColorContextTable = new Dictionary <int, Uri>();
            //
            // Get the correct namespace
            //
            String xmlnsForType = _serializationManager.GetXmlNSForType(typeof(FixedPage));

            //
            // Pick the correct XmlWriter
            //
            xmlWriter = _serializationManager.AcquireXmlWriter(typeof(FixedPage));

            Visual visual = _serializedObject as Visual;

            if (visual != null)
            {
                _treeWalker = new ReachTreeWalker(xmlWriter, _serializationManager);
                _treeWalker.SerializeLinksInVisual(visual);
            }

            //
            // Write the start element and the namespace
            //
            if (xmlnsForType == null)
            {
                xmlWriter.WriteStartElement(XpsS0Markup.FixedPage);
            }
            else
            {
                xmlWriter.WriteStartElement(XpsS0Markup.FixedPage);

                xmlWriter.WriteAttributeString(XpsS0Markup.Xmlns, xmlnsForType);
                xmlWriter.WriteAttributeString(XpsS0Markup.XmlnsX, XpsS0Markup.XmlnsXSchema);
                xmlWriter.WriteAttributeString(XpsS0Markup.XmlLang, XpsS0Markup.XmlLangValue);
            }

            //
            // Simulating the PrintTicket
            //
            XpsSerializationPrintTicketRequiredEventArgs e =
                new XpsSerializationPrintTicketRequiredEventArgs(PrintTicketLevel.FixedPagePrintTicket,
                                                                 0);

            SimulatePrintTicketRaisingEvent(e);

            //
            // Adding Width and Height being mandatory attributes on the FixedPage
            //
            Size size = SimulateFixedPageSize(visual, e.PrintTicket);

            ((IXpsSerializationManager)_serializationManager).FixedPageSize = size;

            xmlWriter.WriteAttributeString(XpsS0Markup.PageWidth,
                                           TypeDescriptor.GetConverter(size.Width).ConvertToInvariantString(size.Width));
            xmlWriter.WriteAttributeString(XpsS0Markup.PageHeight,
                                           TypeDescriptor.GetConverter(size.Height).ConvertToInvariantString(size.Height));

            return(xmlWriter);
        }