Esempio n. 1
0
        public FontFileStream(IFontSource fontSource)
        {
            // Previously we were using fontSource->GetStream() which caused crashes in the XPS scenarios
            // as the stream was getting closed by some other object. In XPS scenarios GetStream() would return
            // MS::Internal::IO:Packaging::SynchronizingStream which is owned by the XPS docs and
            // is known to have issues regarding the lifetime management where by if the current XPS page is
            // flipped then the stream will get disposed. Thus, we cannot rely on the stream directly and hence we now use
            // fontSource->GetUnmanagedStream() which returns a copy of the content of the stream. Special casing XPS will not
            // guarantee that this problem will be fixed so we will use the GetUnmanagedStream(). Note: This path will only
            // be taken for embedded fonts among which XPS is a main scenario. For local fonts we use DWrite's APIs.
            _fontSourceStream = fontSource.GetUnmanagedStream();
            try
            {
                _lastWriteTime = fontSource.GetLastWriteTimeUtc().ToFileTimeUtc();
            }
            catch (ArgumentOutOfRangeException) //The resulting file time would represent a date and time before 12:00 midnight January 1, 1601 C.E. UTC.
            {
                _lastWriteTime = -1;
            }

            // Create lock to control access to font source stream.
            _fontSourceStreamLock = new Object();
        }