ReleaseResourceStreamForXpsFont(
            String resourceId
            )
        {
            if (_fontAcquireMode == ResourceAcquireMode.MultipleAcquired)
            {
                ResourceStreamCacheItem resourceStreamCacheItem = (ResourceStreamCacheItem)_fontsCache[resourceId];

                if (resourceStreamCacheItem != null)
                {
                    if (resourceStreamCacheItem.Release() == 0)
                    {
                        //resourceStreamCacheItem.XpsResource.Commit();
                        _fontsCache.Remove(resourceId);

                        if (_fontsCache.Count == 0)
                        {
                            _fontAcquireMode = ResourceAcquireMode.NoneAcquired;
                        }
                    }
                }
                else
                {
                    throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_CannotReleaseXmlWriter));
                }
            }
            else
            {
                //
                // throw the appropriate exception
                //
            }
        }
Ejemplo n.º 2
0
        AcquireResourceStreamForXpsFont(
            String resourceId
            )
        {
            XpsResourceStream resourceStream = null;

            if (_fontAcquireMode != ResourceAcquireMode.SingleAcquired)
            {
                if (_fontAcquireMode == ResourceAcquireMode.NoneAcquired)
                {
                    _fontAcquireMode = ResourceAcquireMode.MultipleAcquired;
                }

                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 (_currentFixedPageWriter != null)
                    {
                        XpsFont reachFont = _currentFixedPageWriter.AddFont();

                        if (reachFont != null)
                        {
                            _interleavingPolicy.AddItem((INode)reachFont, 0, (INode)_currentFixedPageWriter);
                            resourceStreamCacheItem.XpsResource = (XpsResource)reachFont;
                            //
                            // retreive the appropriate stream and uri from the reach package api layer
                            //
                            _fontResourceStream = new XpsResourceStream(reachFont.GetStream(),
                                                                        reachFont.Uri);

                            resourceStreamCacheItem.XpsResourceStream = _fontResourceStream;

                            _fontsCache[resourceId] = resourceStreamCacheItem;

                            resourceStream = _fontResourceStream;
                        }
                    }
                    else
                    {
                        throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_NoFixedPageWriter));
                    }
                }
                else
                {
                    resourceStream = resourceStreamCacheItem.XpsResourceStream;
                    resourceStreamCacheItem.IncRef();
                }
            }

            return(resourceStream);
        }
        AcquireResourceStreamForXpsFont(
            String resourceId
            )
        {
            XpsResourceStream resourceStream = null;

            if (_fontAcquireMode != ResourceAcquireMode.SingleAcquired)
            {
                if (_fontAcquireMode == ResourceAcquireMode.NoneAcquired)
                {
                    _fontAcquireMode = ResourceAcquireMode.MultipleAcquired;
                }

                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 (_currentFixedPageWriter != null)
                    {
                        //XpsFont reachFont = _currentFixedPageWriter.AddFont(resourceId);

                        Stream fontStream = new MemoryStream();

                        if (fontStream != null)
                        {
                            resourceStreamCacheItem.XpsResource = null;
                            //
                            // retreive the appropriate stream and uri from the reach package api layer
                            //
                            _fontResourceStream = new XpsResourceStream(fontStream,
                                                                        new Uri("package/font", UriKind.Relative));

                            resourceStreamCacheItem.XpsResourceStream = _fontResourceStream;

                            _fontsCache[resourceId] = resourceStreamCacheItem;

                            resourceStream = _fontResourceStream;
                            //
                            // This is to handle PSharp bug claiming we do not dispose
                            // this class.  We can not dipose because ownership has been handed off.
                            // thus we set it to null
                            //
                            fontStream = null;
                        }
                        else
                        {
                            //
                            // throw the appropriate exception
                            //
                        }
                    }
                    else
                    {
                        throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_NoFixedPageWriter));
                    }
                }
                else
                {
                    resourceStream = resourceStreamCacheItem.XpsResourceStream;
                    resourceStreamCacheItem.IncRef();
                }
            }
            else
            {
                //
                // throw the appropraite exception
                //
            }

            return(resourceStream);
        }