Пример #1
0
        /// <Summary>
        ///   Releases a reference to the current XpsFont ResourceStream.</Summary>
        /// <param name="resourceId">
        ///   ID of the Resource to release.</param>
        public override void ReleaseResourceStreamForXpsFont(String resourceId)
        {
            ResourceStreamCacheItem resourceStreamCacheItem = (ResourceStreamCacheItem)_fontsCache[resourceId];

            if (resourceStreamCacheItem != null)
            {
                if (resourceStreamCacheItem.Release() == 0)
                {
                    _fontsCache.Remove(resourceId);
                }
            }
            else
            {
                throw new XpsSerializationException("Cannot release XmlWriter");
            }
        }
Пример #2
0
        // ------------------- AcquireResourceStreamForXpsFont -------------------
        /// <Summary>
        ///  Acquires a ResourceStream for an XpsFont with a specified ID.</Summary>
        /// <param name="resourceId">
        ///   The ID of the Resource.</param>
        public override XpsResourceStream 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
                //
                Stream fontStream = null;
                String fileName;
                if (_currentFixedPageHelper != null)
                {
                    // Create a new Font Stream
                    fileName   = FileHelper.GenerateFileName(XpsFileType.Font, _path);
                    fontStream = FileHelper.CreateFile(fileName, _path);

                    if (fontStream != null)
                    {
                        resourceStreamCacheItem.XpsResource = null;
                        //
                        // retreive the appropriate stream and uri from the package API layer
                        //
                        String fileUri = "/" + fileName;
                        _fontResourceStream = new XpsResourceStream(
                            fontStream, new Uri(fileUri, UriKind.Relative));

                        resourceStreamCacheItem.XpsResourceStream = _fontResourceStream;

                        _fontsCache[resourceId] = resourceStreamCacheItem;

                        resourceStream = _fontResourceStream;

                        //Add Obfuscatedfont type to content type file
                        _contentTypeFile.AddType(XpsFileType.ObfuscatedFont,
                                                 FileHelper.GetExtension(XpsFileType.ObfuscatedFont));

                        fontStream = null;
                    }
                    else
                    {
                        throw new ArgumentNullException("Could not create FontStream");
                    }
                }
                else
                {
                    throw new XpsSerializationException("No FixedPage Writer");
                }
            }
            else
            {
                resourceStream = resourceStreamCacheItem.XpsResourceStream;
                resourceStreamCacheItem.IncRef();
            }

            //Add relationship to fixedpage for resource stream
            _fixedPageRelationshipStream.AddFixedRelationship(
                _requiredResource, resourceStream.Uri.ToString());
            return(resourceStream);
        }