Exemplo n.º 1
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            // Get rid of this font from its factory cache when its disposed. Otherwise it'll live on in a half initialized state.
            Factory?.UnregisterFont(this);

            foreach (GorgonTexture2D texture in _internalTextures)
            {
                texture?.Dispose();
            }

            var brush = _info.Brush as IDisposable;

            brush?.Dispose();
            _internalTextures.Clear();
            KerningPairs.Clear();
            Glyphs.Clear();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Function to retrieve the built in kerning pairs and advancement information for the font.
        /// </summary>
        /// <param name="graphics">The GDI graphics interface.</param>
        /// <param name="font">The GDI font.</param>
        /// <param name="allowedCharacters">The list of characters available to the font.</param>
        private Dictionary <char, ABC> GetKerningInformation(System.Drawing.Graphics graphics, Font font, IList <char> allowedCharacters)
        {
            Dictionary <char, ABC> advancementInfo;

            KerningPairs.Clear();

            IntPtr prevGdiHandle = Win32API.SetActiveFont(graphics, font);

            try
            {
                advancementInfo = Win32API.GetCharABCWidths(allowedCharacters[0], allowedCharacters[allowedCharacters.Count - 1]);

                if (!Info.UseKerningPairs)
                {
                    return(advancementInfo);
                }

                IList <KERNINGPAIR> kerningPairs = Win32API.GetKerningPairs();

                foreach (KERNINGPAIR pair in kerningPairs.Where(item => item.KernAmount != 0))
                {
                    var newPair = new GorgonKerningPair(Convert.ToChar(pair.First), Convert.ToChar(pair.Second));

                    if ((!allowedCharacters.Contains(newPair.LeftCharacter)) ||
                        (!allowedCharacters.Contains(newPair.RightCharacter)))
                    {
                        continue;
                    }

                    KerningPairs[newPair] = pair.KernAmount;
                }
            }
            finally
            {
                Win32API.RestoreActiveObject(prevGdiHandle);
            }

            return(advancementInfo);
        }