Exemple #1
0
 internal void SetCodepoint(UnicodeCharacter codepoint)
 {
     if (HasCodepoint)
     {
         throw new InvalidOperationException("Unable to set glyph's codpoint, already set");
     }
     else
     {
         Character    = codepoint;
         HasCodepoint = true;
     }
 }
Exemple #2
0
        /// <summary>
        /// Gets the spacing adjustment (ie, kerning) between any two characters.
        /// </summary>
        public float GetKerning(UnicodeCharacter cp1, UnicodeCharacter cp2, float size)
        {
            // Compute scaling factor
            var scale = ComputeScale(size);

            // Get the pair of glyphs
            var g1 = GetGlyph(cp1);
            var g2 = GetGlyph(cp2);

            // Get kerning advance between this glyph an another
            return(stbtt_GetGlyphKernAdvance(Info, g1.Index, g2.Index) * scale);
        }
Exemple #3
0
        /// <summary>
        /// Gets the information about a particular glyph in this font.
        /// </summary>
        /// <param name="ch">Some character.</param>
        public Glyph GetGlyph(UnicodeCharacter ch)
        {
            // Attempt to lookup glyph from dictionary
            if (!_glyphLookup.TryGetValue(ch, out var glyph))
            {
                // Get the index for the specified codepoint
                var index = stbtt_FindGlyphIndex(Info, (int)ch);

                // Gets the glyph by its index
                glyph = GetGlyphByIndex(index);

                // Glyph doesn't know its codepoint, so we will set it here since we know now.
                // This is because stb doesn't have a way for mapping index -> codpoint (yet?)
                if (!glyph.HasCodepoint)
                {
                    glyph.SetCodepoint(ch);
                }

                // Store glyph by codepoint
                _glyphLookup[ch] = glyph;
            }

            // Return the glyph data for the specified codepoint
            return(glyph);

            Glyph GetGlyphByIndex(int index)
            {
                // Glyph is not yet known
                if (_glyphs[index] == null)
                {
                    // Create glyph (codepoint is unknown)
                    _glyphs[index] = new Glyph(this, index);
                }

                return(_glyphs[index]);
            }
        }