示例#1
0
        public void OnGet(string font, string text, double emsize = 50)
        {
            if (!_typefaces.ContainsKey(font))
            {
                font = "Roboto-Regular.ttf";
            }

            if (string.IsNullOrEmpty(text))
            {
                text = "The quick brown fox jumps over the lazy dog";
            }

            var tf = _typefaces[font];

            double x = emsize * 0.2;
            double y = 0;

            foreach (char c in text)
            {
                ushort glyphIndex = 0;
                if (tf.CharacterToGlyphMap.ContainsKey((int)c))
                {
                    glyphIndex = tf.CharacterToGlyphMap[(int)c];
                }
                double advanceWidth = tf.AdvanceWidths[glyphIndex] * emsize;
                double baseline     = tf.Baseline * emsize;
                Glyphs.Add(new Glyph(x, y + baseline, tf.GetGlyphOutline(glyphIndex, emsize)));
                x += advanceWidth;
            }

            Width  = x + (emsize * 0.2);
            Height = emsize + (emsize * 0.3);
        }
示例#2
0
        public void OnGet(string font, ushort index = 0)
        {
            if (!_typefaces.ContainsKey(font))
            {
                font = "Roboto-Regular.ttf";
            }

            if (index < 0 || _typefaces[font].GlyphCount <= index)
            {
                index = 0;
            }

            var tf               = _typefaces[font];
            var emsize           = 200;
            var renderer         = new GraphRenderer();
            var typefaceGeometry = tf.GetGlyphOutline(index, emsize);

            Graph = renderer.CreateGraph(
                typefaceGeometry,
                tf.Baseline,
                tf.AdvanceWidths[index],
                tf.AdvanceHeights[index],
                tf.LeftSideBearings[index],
                tf.RightSideBearings[index],
                tf.TopSideBearings[index],
                tf.BottomSideBearings[index],
                emsize);
        }