Esempio n. 1
0
 public bool MoveNext()
 {
     if (CurrentFontFile == null)
     {
         CurrentFontFile = _fontFile;
         return(true);
     }
     CurrentFontFile = null;
     return(false);
 }
Esempio n. 2
0
        /// <summary>
        /// Obtains the font files representing a font face.
        /// </summary>
        /// <remarks>
        /// The IDWriteFontFace::GetFiles method should be called twice.  The first time you call GetFilesfontFiles should be NULL. When the method returns, numberOfFiles receives the number of font files that represent the font face. Then, call the method a second time, passing the numberOfFiles value that was output the first call, and a non-null buffer of the correct size to store the <see cref="SharpDX.DirectWrite.FontFile"/> references.
        /// </remarks>
        /// <returns>An array that stores references to font files representing the font face. This parameter can be NULL if the user wants only the number of files representing the font face. This API increments reference count of the font file references returned according to COM conventions, and the client should release them when finished. </returns>
        /// <unmanaged>HRESULT IDWriteFontFace::GetFiles([InOut] int* numberOfFiles,[Out, Buffer, Optional] IDWriteFontFile** fontFiles)</unmanaged>
        public FontFile[] GetFiles()
        {
            int numberOfFiles = 0;

            GetFiles(ref numberOfFiles, null);
            var files = new FontFile[numberOfFiles];

            GetFiles(ref numberOfFiles, files);
            return(files);
        }
Esempio n. 3
0
        /// <summary>
        /// Advances to the next font file in the collection. When it is first created, the enumerator is positioned before the first element of the collection and the first call to MoveNext advances to the first file.
        /// </summary>
        /// <returns>
        /// the value TRUE if the enumerator advances to a file; otherwise, FALSE if the enumerator advances past the last file in the collection.
        /// </returns>
        /// <unmanaged>HRESULT IDWriteFontFileEnumerator::MoveNext([Out] BOOL* hasCurrentFile)</unmanaged>
        bool FontFileEnumerator.MoveNext()
        {
            bool moveNext = keyStream.RemainingLength != 0;
            if (moveNext)
            {
                if (_currentFontFile != null)
                    _currentFontFile.Dispose();

                _currentFontFile = new FontFile(_factory, keyStream.PositionPointer, 4, _loader);
                keyStream.Position += 4;
            }
            return moveNext;
        }
Esempio n. 4
0
        /// <inheritdoc/>
        public override FontFace GetFontFace()
        {
            if (!File.Exists(Source))
            {
                // Font does not exist
                throw new FontNotFoundException(Source);
            }

            var factory = new Factory();

            using (var fontFile = new FontFile(factory, Source))
            {
                FontSimulations fontSimulations;
                switch (Style)
                {
                    case Xenko.Graphics.Font.FontStyle.Regular:
                        fontSimulations = FontSimulations.None;
                        break;
                    case Xenko.Graphics.Font.FontStyle.Bold:
                        fontSimulations = FontSimulations.Bold;
                        break;
                    case Xenko.Graphics.Font.FontStyle.Italic:
                        fontSimulations = FontSimulations.Oblique;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }

                RawBool isSupported;
                FontFileType fontType;
                FontFaceType faceType;
                int numberFaces;

                fontFile.Analyze(out isSupported, out fontType, out faceType, out numberFaces);

                return new FontFace(factory, faceType, new[] { fontFile }, 0, fontSimulations);
            }
        }
Esempio n. 5
0
 public FontFileEnumerator(SharpDX.DirectWrite.FontFile fontFile)
 {
     _fontFile = fontFile;
     //CurrentFontFile = _fontFile;
 }
Esempio n. 6
0
 public FontCollectionLoader(SharpDX.DirectWrite.FontFile fontFile)
 {
     _fontFileEnumerator = new FontFileEnumerator(fontFile);
 }
Esempio n. 7
0
        public static SharpDX.DirectWrite.Font GetDxFont(string fontFamily, SharpDX.DirectWrite.FontWeight weight, SharpDX.DirectWrite.FontStretch stretch, SharpDX.DirectWrite.FontStyle style)
        {
            //Windows.UI.Xaml.Media.FontFamily fontFamily = textBlock.FontFamily;

            if (fontFamily == null)
            {
                fontFamily = LabeLRenderer._defaultTextBlock.FontFamily.Source;
            }

            var fontKey = fontFamily + "-" + weight + "-" + stretch + "-" + style;

            if (_loadedFonts.TryGetValue(fontKey, out SharpDX.DirectWrite.Font font))
            {
                return(font);
            }

            using (var factory = new Factory())
            {
                if (fontFamily.StartsWith("ms-appdata:///"))
                {
                    var    fontFamilyFilePath = fontFamily.Substring(14);
                    string dir = null;
                    if (fontFamilyFilePath.StartsWith("local/"))
                    {
                        dir = ApplicationData.Current.LocalFolder.Path;
                        fontFamilyFilePath = fontFamilyFilePath.Substring(6);
                    }
                    else if (fontFamilyFilePath.StartsWith("localcache/"))
                    {
                        dir = ApplicationData.Current.LocalCacheFolder.Path;
                        fontFamilyFilePath = fontFamilyFilePath.Substring(11);
                    }
                    else if (fontFamilyFilePath.StartsWith("roaming/"))
                    {
                        dir = ApplicationData.Current.RoamingFolder.Path;
                        fontFamilyFilePath = fontFamilyFilePath.Substring(8);
                    }
                    else if (fontFamilyFilePath.StartsWith("temp/"))
                    {
                        dir = ApplicationData.Current.TemporaryFolder.Path;
                        fontFamilyFilePath = fontFamilyFilePath.Substring(5);
                    }
                    else
                    {
                        System.Console.WriteLine("Unknown StorageFolder for " + fontFamily);
                        return(null);
                    }
                    var path = System.IO.Path.Combine(dir, fontFamilyFilePath.Split('#')[0]);
                    path = path.Replace('/', '\\');
                    var fontFile = new SharpDX.DirectWrite.FontFile(factory, path);

                    var loader = fontFile.Loader;

                    var key = fontFile.GetReferenceKey();

                    using (var fontCollectionLoader = new FontCollectionLoader(fontFile))
                    {
                        factory.RegisterFontCollectionLoader(fontCollectionLoader);

                        using (var fontCollection = new FontCollection(factory, fontCollectionLoader, key))
                        {
                            var family = fontCollection.GetFontFamily(0);


                            var familyNames = family.FamilyNames;

                            font = family.GetFirstMatchingFont(weight, stretch, style);

                            _loadedFonts[fontKey] = font;
                        }
                    }
                    return(font);
                }
                using (var fontCollection = factory.GetSystemFontCollection(false))
                {
                    var familyCount = fontCollection.FontFamilyCount;
                    for (int i = 0; i < familyCount; i++)
                    {
                        try
                        {
                            using (var dxFontFamily = fontCollection.GetFontFamily(i))
                            {
                                var familyNames = dxFontFamily.FamilyNames;

                                if (!familyNames.FindLocaleName(System.Globalization.CultureInfo.CurrentCulture.Name, out int index))
                                {
                                    familyNames.FindLocaleName("en-us", out index);
                                }

                                var name = familyNames.GetString(index);

                                var display = name;
                                using (var dxFont = dxFontFamily.GetFont(index))
                                {
                                    if (dxFont.IsSymbolFont)
                                    {
                                        display = "Segoe UI";
                                    }
                                }

                                //fontList.Add(new InstalledFont { Name = name, DisplayFont = display });
                                if ((fontFamily == name || fontFamily == display) && dxFontFamily.GetFirstMatchingFont(weight, stretch, style) is SharpDX.DirectWrite.Font systemFont)
                                {
                                    _loadedFonts[fontKey] = systemFont;
                                    return(systemFont);
                                }
                            }
                        }
#pragma warning disable CC0004    // Catch block cannot be empty
                        catch { } // Corrupted font files throw an exception - ignore them
#pragma warning restore CC0004    // Catch block cannot be empty
                    }
                }
            }
            return(null);
        }
Esempio n. 8
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);
 }
Esempio n. 9
0
 /// <summary>	
 /// Obtains the font files representing a font face. 	
 /// </summary>	
 /// <remarks>	
 /// The IDWriteFontFace::GetFiles method should be called twice.  The first time you call GetFilesfontFiles should be NULL. When the method returns, numberOfFiles receives the number of font files that represent the font face. Then, call the method a second time, passing the numberOfFiles value that was output the first call, and a non-null buffer of the correct size to store the <see cref="SharpDX.DirectWrite.FontFile"/> references. 	
 /// </remarks>	
 /// <returns>An array that stores references to font files representing the font face. This parameter can be NULL if the user wants only the number of files representing the font face. This API increments reference count of the font file references returned according to COM conventions, and the client should release them when finished. </returns>
 /// <unmanaged>HRESULT IDWriteFontFace::GetFiles([InOut] int* numberOfFiles,[Out, Buffer, Optional] IDWriteFontFile** fontFiles)</unmanaged>
 public FontFile[] GetFiles()
 {
     int numberOfFiles = 0;
     GetFiles(ref numberOfFiles, null);
     var files = new FontFile[numberOfFiles];
     GetFiles(ref numberOfFiles, files);
     return files;
 }
Esempio n. 10
0
        private FontFace GetFontFaceFromSource(Factory factory, SpriteFontAsset options)
        {
            if (!File.Exists(options.Source))
            {
                // Font does not exist
                throw new FontNotFoundException(options.Source);
            }

            using (var fontFile = new FontFile(factory, options.Source))
            {
                FontSimulations fontSimulations;
                switch (options.Style)
                {
                    case Paradox.Graphics.Font.FontStyle.Regular:
                        fontSimulations = FontSimulations.None;
                        break;
                    case Paradox.Graphics.Font.FontStyle.Bold:
                        fontSimulations = FontSimulations.Bold;
                        break;
                    case Paradox.Graphics.Font.FontStyle.Italic:
                        fontSimulations = FontSimulations.Oblique;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }

                RawBool isSupported;
                FontFileType fontType;
                FontFaceType faceType;
                int numberFaces;

                fontFile.Analyze(out isSupported, out fontType, out faceType, out numberFaces);

                return new FontFace(factory, faceType, new[] { fontFile }, 0, fontSimulations);
            }
        }