Пример #1
0
        // This isn't used anymore. It's left here as reference for how to get kerning data in C#.
        public static KerningPair[] GetKerningPairs( Font font, Graphics graphics )
        {
            // Select the HFONT into the HDC.
            IntPtr hDC = graphics.GetHdc();
            Font fontClone = (Font)font.Clone();
            IntPtr hFont = fontClone.ToHfont();
            SelectObject( hDC, hFont );

            // Find out how many pairs there are and allocate them.
            int numKerningPairs = GetKerningPairs( hDC.ToInt32(), 0, null );
            KerningPair[] kerningPairs = new KerningPair[ numKerningPairs ];

            // Get the pairs.
            GetKerningPairs( hDC.ToInt32(), kerningPairs.Length, kerningPairs );

            DeleteObject( hFont );
            graphics.ReleaseHdc();

            return kerningPairs;
        }
Пример #2
0
        // Get Kerning Pairs
        public KerningTable GetKerningTable(string fontFilePath, int pointSize)
        {
            KerningTable kerningInfo = new KerningTable();
            kerningInfo.kerningPairs = new List<KerningPair>();

            // Temporary Array to hold the kerning pairs from the Native Plug-in.
            FT_KerningPair[] kerningPairs = new FT_KerningPair[1000];

            int kpCount = TMPro_FontPlugin.FT_GetKerningPairs(fontFilePath, m_kerningSet, m_kerningSet.Length, kerningPairs);

            for (int i = 0; i < kpCount; i++)
            {
                // Proceed to add each kerning pairs.
                KerningPair kp = new KerningPair(kerningPairs[i].ascII_Left, kerningPairs[i].ascII_Right, kerningPairs[i].xAdvanceOffset * pointSize);
                kerningInfo.kerningPairs.Add(kp);
            }

            return kerningInfo;
        }
        // Get Kerning Pairs
        public KerningTable GetKerningTable(string fontFilePath, int pointSize)
        {
            KerningTable kerningInfo = new KerningTable();
            kerningInfo.kerningPairs = new List<KerningPair>();

            // Temporary Array to hold the kerning pairs from the Native Plug-in.
            FT_KerningPair[] kerningPairs = new FT_KerningPair[5000];

            int kpCount = TMPro_FontPlugin.FT_GetKerningPairs(fontFilePath, m_kerningSet, m_kerningSet.Length, kerningPairs);

            for (int i = 0; i < kpCount; i++)
            {
                // Proceed to add each kerning pairs.
                KerningPair kp = new KerningPair(kerningPairs[i].ascII_Left, kerningPairs[i].ascII_Right, kerningPairs[i].xAdvanceOffset * pointSize);

                // Filter kerning pairs to avoid duplicates
                int index = kerningInfo.kerningPairs.FindIndex(item => item.AscII_Left == kp.AscII_Left && item.AscII_Right == kp.AscII_Right);

                if (index == -1)
                    kerningInfo.kerningPairs.Add(kp);
                else
                    if (!TMP_Settings.warningsDisabled) Debug.LogWarning("Kerning Key for [" + kp.AscII_Left + "] and [" + kp.AscII_Right + "] is a duplicate.");

            }

            return kerningInfo;
        }
Пример #4
0
        public void LoadKerningPairs()
        {
            int blockSize = reader.ReadInt32();
            var kerningPairInfos = new Dictionary<Vector2ui, KerningPair>();
            int read = 0;

            while (read < blockSize)
            {
                var kerningPair = new KerningPair();

                kerningPair.First = reader.ReadUInt32();
                kerningPair.Second = reader.ReadUInt32();
                kerningPair.Amount = reader.ReadInt16();

                kerningPairInfos.Add(new Vector2ui(kerningPair.First, kerningPair.Second), kerningPair);
                read += KerningPair.SizeOf;
            }

            info.KerningPairs = kerningPairInfos;
        }
Пример #5
0
            //
            // NOTE: This is currently unused. This would seem to be the right way to do it,
            //       but the results that we get back don't match what you get if you call Graphics.DrawString.
            //       Instead, see CalculateSpacingInfo.
            //
            public CharacterKerningInfo( CharacterInfo character, FontServices.KerningPair[] kerningPairs, CharacterInfo[] validCharacters )
            {
                this.Character = character;

                // Add a kerning pair for anything that we're the first character in (and has a valid second character).
                for ( int i=0; i < kerningPairs.Length; i++ )
                {
                    if ( kerningPairs[i].wFirst == (short)this.Character.Character )
                    {
                        CharacterInfo second = FindCharacter( (Char)kerningPairs[i].wSecond, validCharacters );	// Find the second kerning character in validCharacters.
                        if ( second != null )
                        {
                            KerningPair pair = new KerningPair()
                            {
                                SecondCharacter = second,
                                KernAmount = kerningPairs[i].iKernAmount
                            };

                            this.Kernings.Add( pair );
                        }
                    }
                }
            }
Пример #6
0
 private void LoadKerningPair( int index, XmlNode kerningPair )
 {
     if( m_kerningTable != null && index >= 0 && index < m_kerningTable.Length )
     {
         m_kerningTable[index] = new KerningPair();
         m_kerningTable[index].unicodeFirst = LoadIntAttribute( kerningPair, "first" );
         m_kerningTable[index].unicodeSecond = LoadIntAttribute( kerningPair, "second" );
         m_kerningTable[index].offset = LoadIntAttribute( kerningPair, "amount" );
     }
 }