예제 #1
0
        unsafe public FontFace CreateFontFace(Uri filePathUri, uint faceIndex, FontSimulations fontSimulationFlags)
        {
            FontFile     fontFile = CreateFontFile(filePathUri);
            FontFileType dwriteFontFileType;
            FontFaceType dwriteFontFaceType;
            uint         numberOfFaces = 0;

            int hr;

            if (fontFile.Analyze(
                    out dwriteFontFileType,
                    out dwriteFontFaceType,
                    out numberOfFaces,
                    out hr
                    ))
            {
                if (faceIndex >= numberOfFaces)
                {
                    throw new ArgumentOutOfRangeException("faceIndex");
                }

                IntPtr dwriteFontFace = IntPtr.Zero;                 // IDWriteFontFace
                IntPtr dwriteFontFile = fontFile.DWriteFontFileIface;

                try {
                    dwriteFontFace = _pFactory.CreateFontFace(
                        dwriteFontFaceType,
                        1,
                        &dwriteFontFile,
                        faceIndex,
                        fontSimulationFlags
                        );
                }
                finally {
                    Marshal.Release(dwriteFontFile);
                }

                return(new FontFace(dwriteFontFace));
            }

            // This path is here because there is a behavior mismatch between DWrite and WPF.
            // If a directory was given instead of a font uri WPF previously throws
            // System.UnauthorizedAccessException. We handle most of the exception behavior mismatch
            // in FontFile^ Factory::CreateFontFile by opening the file using WPF's previous (prior to DWrite integration) logic if
            // CreateFontFileReference fails (please see comments in FontFile^ Factory::CreateFontFile).
            // However in this special case DWrite's CreateFontFileReference will succeed if given
            // a directory instead of a font file and it is the Analyze() call will fail returning DWRITE_E_FILEFORMAT.
            // Thus, incase the hr returned from Analyze() was DWRITE_E_FILEFORMAT we do as we did in FontFile^ Factory::CreateFontFile
            // to try and open the file using WPF old logic and throw System.UnauthorizedAccessException as WPF used to do.
            // If a file format exception is expected then opening the file should succeed and ConvertHresultToException()
            // Should throw the correct exception.
            // A final note would be that this overhead is only incurred in error conditions and so the normal execution path should
            // not be affected.
            else
            {
                if (hr == unchecked ((int)0x88985000))                // DWRITE_E_FILEFORMAT
                {
                    IFontSource fontSource = _fontSourceFactory.Create(filePathUri.AbsoluteUri);
                    fontSource.TestFileOpenable();
                }
                Marshal.ThrowExceptionForHR(hr);
            }

            return(null);
        }
예제 #2
0
 /// <summary>
 /// Creates an object that represents a font face.
 /// </summary>
 /// <param name="factory">A reference to a DirectWrite factory <see cref="Factory"/></param>
 /// <param name="fontFaceType">A value that indicates the type of file format of the font face. </param>
 /// <param name="fontFiles">A font file object representing the font face. Because<see cref="T:SharpDX.DirectWrite.FontFace" /> maintains its own references to the input font file objects, you may release them after this call. </param>
 /// <param name="faceIndex">The zero-based index of a font face, in cases when the font files contain a collection of font faces. If the font files contain a single face, this value should be zero. </param>
 /// <param name="fontFaceSimulationFlags">A value that indicates which, if any, font face simulation flags for algorithmic means of making text bold or italic are applied to the current font face. </param>
 /// <unmanaged>HRESULT IDWriteFactory::CreateFontFace([None] DWRITE_FONT_FACE_TYPE fontFaceType,[None] int numberOfFiles,[In, Buffer] const IDWriteFontFile** fontFiles,[None] int faceIndex,[None] DWRITE_FONT_SIMULATIONS fontFaceSimulationFlags,[Out] IDWriteFontFace** fontFace)</unmanaged>
 public FontFace(Factory factory, FontFaceType fontFaceType, FontFile[] fontFiles, int faceIndex, FontSimulations fontFaceSimulationFlags)
 {
     factory.CreateFontFace(fontFaceType, fontFiles.Length, fontFiles, faceIndex, fontFaceSimulationFlags, this);
 }
예제 #3
0
 /// <summary>	
 /// Creates an object that represents a font face. 	
 /// </summary>	
 /// <param name="factory">A reference to a DirectWrite factory <see cref="Factory"/></param>
 /// <param name="fontFaceType">A value that indicates the type of file format of the font face. </param>
 /// <param name="fontFiles">A font file object representing the font face. Because<see cref="T:SharpDX.DirectWrite.FontFace" /> maintains its own references to the input font file objects, you may release them after this call. </param>
 /// <param name="faceIndex">The zero-based index of a font face, in cases when the font files contain a collection of font faces. If the font files contain a single face, this value should be zero. </param>
 /// <param name="fontFaceSimulationFlags">A value that indicates which, if any, font face simulation flags for algorithmic means of making text bold or italic are applied to the current font face. </param>
 /// <unmanaged>HRESULT IDWriteFactory::CreateFontFace([None] DWRITE_FONT_FACE_TYPE fontFaceType,[None] int numberOfFiles,[In, Buffer] const IDWriteFontFile** fontFiles,[None] int faceIndex,[None] DWRITE_FONT_SIMULATIONS fontFaceSimulationFlags,[Out] IDWriteFontFace** fontFace)</unmanaged>
 public FontFace(Factory factory, FontFaceType fontFaceType, FontFile[] fontFiles, int faceIndex, FontSimulations fontFaceSimulationFlags)
 {
     factory.CreateFontFace(fontFaceType, fontFiles.Length, fontFiles, faceIndex, fontFaceSimulationFlags, this);
 }
예제 #4
0
        /// <summary>
        /// Creates an object that represents a font face.
        /// </summary>
        /// <param name="fontFaceType">A value that indicates the type of file format of the font face.</param>
        /// <param name="fontFiles">A font file object representing the font face. Because <see cref="IDWriteFontFace"/> maintains its own references to the input font file objects, you may release them after this call.</param>
        /// <param name="faceIndex">The zero-based index of a font face, in cases when the font files contain a collection of font faces. If the font files contain a single face, this value should be zero.</param>
        /// <param name="fontFaceSimulationFlags">A value that indicates which, if any, font face simulation flags for algorithmic means of making text bold or italic are applied to the current font face.</param>
        /// <returns>Instance of <see cref="IDWriteFontFace"/> or null if failed.</returns>
        public IDWriteFontFace CreateFontFace(FontFaceType fontFaceType, IDWriteFontFile[] fontFiles, int faceIndex = 0, FontSimulations fontFaceSimulationFlags = FontSimulations.None)
        {
            Guard.NotNullOrEmpty(fontFiles, nameof(fontFiles));

            var result = CreateFontFace(
                fontFaceType,
                fontFiles.Length, fontFiles,
                faceIndex,
                fontFaceSimulationFlags,
                out IDWriteFontFace fontFace);

            return(result.Failure ? null : fontFace);
        }
예제 #5
0
파일: Factory.cs 프로젝트: javagg/Particle
 internal FontFace CreateFontFace(Uri filePathUri, uint faceIndex, FontSimulations fontSimulationFlags)
 {
 }
예제 #6
0
        /// <summary>
        /// Creates an object that represents a font face.
        /// </summary>
        /// <param name="fontFaceType">A value that indicates the type of file format of the font face.</param>
        /// <param name="fontFiles">A font file object representing the font face. Because <see cref="IDWriteFontFace"/> maintains its own references to the input font file objects, you may release them after this call.</param>
        /// <param name="faceIndex">The zero-based index of a font face, in cases when the font files contain a collection of font faces. If the font files contain a single face, this value should be zero.</param>
        /// <param name="fontFaceSimulationFlags">A value that indicates which, if any, font face simulation flags for algorithmic means of making text bold or italic are applied to the current font face.</param>
        /// <returns>Instance of <see cref="IDWriteFontFace"/> or null if failed.</returns>
        public IDWriteFontFace CreateFontFace(FontFaceType fontFaceType, IDWriteFontFile[] fontFiles, int faceIndex = 0, FontSimulations fontFaceSimulationFlags = FontSimulations.None)
        {
            var result = CreateFontFace(
                fontFaceType,
                fontFiles.Length, fontFiles,
                faceIndex,
                fontFaceSimulationFlags,
                out var fontFace);

            return(result.Failure ? null : fontFace);
        }
예제 #7
0
 internal FontFace CreateFontFace(Uri filePathUri, uint faceIndex, FontSimulations fontSimulationFlags)
 {
     throw new NotImplementedException();
 }
예제 #8
0
 internal static byte Convert(FontSimulations fontSimulations)
 {
 }