Example #1
0
        /// <summary>
        /// Function to get the kerning pairs for a font.
        /// </summary>
        /// <returns>A list of kerning pair values for the active font.</returns>
        public static KERNINGPAIR[] GetKerningPairs()
        {
            KERNINGPAIR[] pairs;

            if (_hdc == IntPtr.Zero)
            {
                throw new GorgonException(GorgonResult.CannotEnumerate, Resources.GORGFX_ERR_FONT_CANNOT_RETRIEVE_KERNING);
            }

            MapModes lastMode = SetMapMode(_hdc, MapModes.MM_TEXT);

            try
            {
                // Get the number of pairs.
                int size = (int)GetKerningPairsW(_hdc, 0, null);

                // If we have no pairs, then leave here.
                if (size == 0)
                {
                    return(Array.Empty <KERNINGPAIR>());
                }

                pairs = new KERNINGPAIR[size];
                KERNINGPAIR *pairPtr = stackalloc KERNINGPAIR[size];

                if (GetKerningPairsW(_hdc, (uint)size, pairPtr) == 0)
                {
                    throw new GorgonException(GorgonResult.CannotEnumerate, Resources.GORGFX_ERR_FONT_CANNOT_RETRIEVE_KERNING);
                }

                for (int i = 0; i < size; i++)
                {
                    pairs[i] = pairPtr[i];
                }
            }
            finally
            {
                SetMapMode(_hdc, lastMode);
            }

            return(pairs);
        }
Example #2
0
 private static extern uint GetKerningPairsW(IntPtr HDC, uint numberOfPairs, KERNINGPAIR *kernPairs);