Ejemplo n.º 1
0
        GeneratePrintTicketResource(
            ContentType contentType,
            PrintTicket printTicket
            )
        {
            IXpsOMPrintTicketResource printTicketResource  = null;
            XpsPrintStream            printTicketXpsStream = XpsPrintStream.CreateXpsPrintStream();

            printTicket.SaveTo(printTicketXpsStream);
            IStream printTicketStream = printTicketXpsStream.GetManagedIStream();

            Uri printTicketUri = _xpsManager.GeneratePrintTicketUri(contentType);

            try
            {
                IOpcPartUri printTicketPart = GenerateIOpcPartUri(printTicketUri);
                printTicketResource = _xpsOMFactory.CreatePrintTicketResource(printTicketStream, printTicketPart);
            }
            catch (COMException)
            {
                Invalidate();
                throw new PrintingCanceledException();
            }

            return(printTicketResource);
        }
Ejemplo n.º 2
0
        AddCurrentPageToPackageWriter()
        {
            try
            {
                _currentFixedPageXmlWriter.Flush();
                IStream     pageMarkupStream = _currentFixedPagePrintStream.GetManagedIStream();
                IOpcPartUri partUri          = GenerateIOpcPartUri(_currentFixedPageUri);

                if (_currentPagePrintTicket == null)
                {
                    _currentPagePrintTicket = new PrintTicket();
                }

                IXpsOMPrintTicketResource printTicketResource = GeneratePrintTicketResource(XpsS0Markup.FixedPageContentType, _currentPagePrintTicket);
                _currentFixedPagePrintStream.Seek(0, SeekOrigin.Begin);
                _currentFixedPageWriter = _xpsOMFactory.CreatePageFromStream(pageMarkupStream, partUri, _xpsPartResources, 0);

                SetHyperlinkTargetsForCurrentPage();

                XPS_SIZE xpsSize = new XPS_SIZE()
                {
                    width = (float)_currentPageSize.Width, height = (float)_currentPageSize.Height
                };
                _currentFixedDocumentSequenceWriter.AddPage(_currentFixedPageWriter, xpsSize, null, null, printTicketResource, null);
            }
            catch (COMException)
            {
                Invalidate();
                throw new PrintingCanceledException();
            }
        }
Ejemplo n.º 3
0
        AcquireResourceStreamForXpsColorContext(
            string resourceId
            )
        {
            XpsResourceStream resourceStream = null;

            if (_currentXpsColorContextRef == 0)
            {
                try
                {
                    XpsPrintStream colorContextStreamWrapper = XpsPrintStream.CreateXpsPrintStream();
                    Uri            colorContextUri           = _xpsManager.GenerateUniqueUri(XpsS0Markup.ColorContextContentType);
                    _colorContextResourceStream = new XpsResourceStream(colorContextStreamWrapper, colorContextUri);
                    IStream _colorIStream = colorContextStreamWrapper.GetManagedIStream();

                    IOpcPartUri partUri = GenerateIOpcPartUri(colorContextUri);
                    IXpsOMColorProfileResource           colorResource   = _xpsOMFactory.CreateColorProfileResource(_colorIStream, partUri);
                    IXpsOMColorProfileResourceCollection colorCollection = _xpsPartResources.GetColorProfileResources();
                    colorCollection.Append(colorResource);
                }
                catch (COMException)
                {
                    Invalidate();
                    throw new PrintingCanceledException();
                }
            }

            _currentXpsColorContextRef++;

            resourceStream = _colorContextResourceStream;

            return(resourceStream);
        }
Ejemplo n.º 4
0
        ///////////////////////////////////////////////////////////////////////////////
        // Description: Gets the target part of a relationship with the 'Internal' target mode.
        ///////////////////////////////////////////////////////////////////////////////
        private static void GetRelationshipTargetPart(IOpcPartSet partSet,           // Set of the parts in the package.
                                                      IOpcRelationship relationship, // Relationship that targets the required part.
                                                      string expectedContentType,    // Content type expected for the target part.
                                                      out IOpcPart targetPart        // Recieves pointer to target part. Method may return a valid
                                                                                     // pointer even on failure, and the caller must always release if a non-default value is returned.
                                                      )
        {
            targetPart = null;

            OPC_URI_TARGET_MODE targetMode = relationship.GetTargetMode();

            if (targetMode != OPC_URI_TARGET_MODE.OPC_URI_TARGET_MODE_INTERNAL)
            {
                // The relationship's target is not a part.
                var relationshipType = relationship.GetRelationshipType();

                Console.Error.Write("Invalid music bundle package: relationship with type {0} must have Internal target mode.\n", relationshipType);

                // Set the return code to an error.
                throw new InvalidOperationException();
            }

            // Relationship's target is a part; the target mode is 'Internal'.

            // Get the URI of the relationship source.
            IOpcUri sourceUri = relationship.GetSourceUri();

            // Get the URI of the relationship target.
            IUri targetUri = relationship.GetTargetUri();

            // Resolve the target URI to the part name of the target part.
            IOpcPartUri targetPartUri = sourceUri.CombinePartUri(targetUri);

            // Check that a part with the resolved part name exists in the part set.
            var partExists = partSet.PartExists(targetPartUri);

            if (!partExists)
            {
                // The part does not exist in the part set.
                Console.Error.Write("Invalid music bundle package: the target part of relationship does not exist.\n");

                // Set the return code to an error.
                throw new InvalidOperationException();
            }

            // Get the part.
            targetPart = partSet.GetPart(targetPartUri);

            // Get the content type of the part.
            var contentType = targetPart.GetContentType();

            if (contentType != expectedContentType)
            {
                // Content type of the part did not match the expected content type.
                Console.Error.Write("Invalid music bundle package: the target part does not have correct content type.\n");

                // Set the return code to an error.
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 5
0
        AcquireResourceStreamForXpsFont(
            string resourceId
            )
        {
            XpsResourceStream resourceStream = null;

            ResourceStreamCacheItem resourceStreamCacheItem = (ResourceStreamCacheItem)_fontsCache[resourceId];

            if (resourceStreamCacheItem == null)
            {
                resourceStreamCacheItem = new ResourceStreamCacheItem();

                //
                // We need to create the corresponding part in the Xps package
                // and then acquire the Stream
                //
                if (_currentFixedPageXmlWriter != null)
                {
                    try
                    {
                        Uri         uri     = GenerateUriForObfuscatedFont();
                        IOpcPartUri partUri = GenerateIOpcPartUri(uri);

                        XpsPrintStream fontStreamWrapper = XpsPrintStream.CreateXpsPrintStream();

                        IStream fontIStream = fontStreamWrapper.GetManagedIStream();

                        IXpsOMFontResource           fontResource   = _xpsOMFactory.CreateFontResource(fontIStream, XPS_FONT_EMBEDDING.XPS_FONT_EMBEDDING_OBFUSCATED, partUri, 1);
                        IXpsOMFontResourceCollection fontCollection = _xpsPartResources.GetFontResources();
                        fontCollection.Append(fontResource);

                        XpsResourceStream fontResourceStream = new XpsResourceStream(fontStreamWrapper, uri);
                        resourceStreamCacheItem.XpsResourceStream = fontResourceStream;

                        _fontsCache[resourceId] = resourceStreamCacheItem;

                        resourceStream = fontResourceStream;
                    }
                    catch (COMException)
                    {
                        Invalidate();
                        throw new PrintingCanceledException();
                    }
                }
                else
                {
                    throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_NoFixedPageWriter));
                }
            }
            else
            {
                resourceStream = resourceStreamCacheItem.XpsResourceStream;
                resourceStreamCacheItem.IncRef();
            }

            return(resourceStream);
        }
Ejemplo n.º 6
0
 GenerateIOpcPartUri(
     Uri uri
     )
 {
     try
     {
         IOpcPartUri partUri = _xpsOMFactory.CreatePartUri(uri.ToString());
         return(partUri);
     }
     catch (COMException)
     {
         Invalidate();
         throw new PrintingCanceledException();
     }
 }
Ejemplo n.º 7
0
        AcquireResourceStreamForXpsImage(
            string resourceId
            )
        {
            XpsResourceStream resourceStream = null;

            if (resourceId == null)
            {
                throw new ArgumentNullException(nameof(resourceId));
            }

            ContentType contentType = new ContentType(resourceId);

            if (ContentType.Empty.AreTypeAndSubTypeEqual(contentType))
            {
                throw new ArgumentException(SR.Get(SRID.ReachPackaging_InvalidContentType, contentType.ToString()));
            }

            if (_currentXpsImageRef == 0)
            {
                try
                {
                    _currentImageType = GetXpsImageTypeFromContentType(contentType);
                    XpsPrintStream imageStreamWrapper = XpsPrintStream.CreateXpsPrintStream();
                    Uri            imageUri           = _xpsManager.GenerateUniqueUri(contentType);
                    _imageResourceStream = new XpsResourceStream(imageStreamWrapper, imageUri);
                    IStream imageIStream = imageStreamWrapper.GetManagedIStream();

                    IOpcPartUri                   partUri         = GenerateIOpcPartUri(imageUri);
                    IXpsOMImageResource           imageResource   = _xpsOMFactory.CreateImageResource(imageIStream, _currentImageType, partUri);
                    IXpsOMImageResourceCollection imageCollection = _xpsPartResources.GetImageResources();
                    imageCollection.Append(imageResource);
                }
                catch (COMException)
                {
                    Invalidate();
                    throw new PrintingCanceledException();
                }
            }

            _currentXpsImageRef++;
            resourceStream = _imageResourceStream;
            return(resourceStream);
        }
Ejemplo n.º 8
0
 StartNewDocument()
 {
     try
     {
         Uri uri = _xpsManager.GenerateUniqueUri(XpsS0Markup.FixedDocumentContentType);
         _currentFixedDocumentUri = uri;
         IOpcPartUri partUri = GenerateIOpcPartUri(uri);
         if (_currentDocumentPrintTicket == null)
         {
             _currentDocumentPrintTicket = new PrintTicket();
         }
         IXpsOMPrintTicketResource printTicketResource = GeneratePrintTicketResource(XpsS0Markup.FixedDocumentContentType, _currentDocumentPrintTicket);
         _currentFixedDocumentSequenceWriter.StartNewDocument(partUri, printTicketResource, null, null, null);
         _currentFixedDocumentWriterRef++;
     }
     catch (COMException)
     {
         Invalidate();
         throw new PrintingCanceledException();
     }
 }
Ejemplo n.º 9
0
        EnsureXpsOMPackageWriter()
        {
            if (_currentDocumentSequenceWriterRef == 0)
            {
                try
                {
                    IOpcPartUri partUri = GenerateIOpcPartUri(XpsS0Markup.DocumentSequenceContentType);
                    _currentFixedDocumentSequenceWriter = _packageTarget.GetXpsOMPackageWriter(partUri, null);
                    if (_printQueue != null)
                    {
                        ((PrintQueue)_printQueue).XpsOMPackageWriter = _currentFixedDocumentSequenceWriter;
                    }
                }
                catch (COMException)
                {
                    Invalidate();
                    throw new PrintingCanceledException();
                }
            }

            _currentDocumentSequenceWriterRef++;
        }
Ejemplo n.º 10
0
 public virtual extern IXpsOMImageResource GenerateThumbnail([In] IXpsOMPage page, [In][ComAliasName("System.Windows.Xps.Serialization.RCW.XPS_IMAGE_TYPE")] XPS_IMAGE_TYPE thumbnailType, [In][ComAliasName("System.Windows.Xps.Serialization.RCW.XPS_THUMBNAIL_SIZE")] XPS_THUMBNAIL_SIZE thumbnailSize, [In] IOpcPartUri imageResourcePartName);