Exemple #1
0
        private Glyph GetGlyph(char character)
        {
            Glyph glyph;

            if (!glyphs.TryGetValue(character, out glyph))
            {
                // if we have a loaded ttf try to create the glyph data
                if (_ofTypeface != null)
                {
                    var storage    = new VertexStorage();
                    var translator = new VertexSourceGlyphTranslator(storage);
                    var glyphIndex = _ofTypeface.LookupIndex(character);
                    var ttfGlyph   = _ofTypeface.GetGlyphByIndex(glyphIndex);
                    //
                    Typography.OpenFont.IGlyphReaderExtensions.Read(translator, ttfGlyph.GlyphPoints, ttfGlyph.EndPoints);

                    //
                    glyph             = new Glyph();
                    glyph.unicode     = character;
                    glyph.horiz_adv_x = _ofTypeface.GetHAdvanceWidthFromGlyphIndex(glyphIndex);

                    glyphs.Add(character, glyph);

                    // Wrap glyph data with ClosedLoopGlyphData to ensure all loops are correctly closed
                    glyph.glyphData = new ClosedLoopGlyphData(storage);
                }
            }

            return(glyph);
        }
Exemple #2
0
        internal IVertexSource GetGlyphForCharacter(char character)
        {
            if (ttfTypeFace != null)
            {
                // TODO: MAKE SURE THIS IS OFF!!!!!!! It is un-needed and only for debugging
                //glyphs.Clear();
            }

            IVertexSource vertexSource = null;
            // TODO: check for multi character glyphs (we don't currently support them in the reader).
            Glyph glyph = null;

            if (!glyphs.TryGetValue(character, out glyph))
            {
                // if we have a loaded ttf try to create the glyph data
                if (ttfTypeFace != null)
                {
                    glyph = new Glyph();
                    var translator = new VertexSourceGlyphTranslator(glyph.glyphData);
                    var glyphIndex = ttfTypeFace.LookupIndex(character);
                    var ttfGlyph   = ttfTypeFace.GetGlyphByIndex(glyphIndex);
                    translator.Read(ttfGlyph.GlyphPoints, ttfGlyph.EndPoints);
                    glyph.unicode     = character;
                    glyph.horiz_adv_x = ttfTypeFace.GetHAdvanceWidthFromGlyphIndex(glyphIndex);
                    glyphs.Add(character, glyph);
                    vertexSource = glyph.glyphData;
                }
            }
            else
            {
                vertexSource = glyph.glyphData;
            }

            return(vertexSource);
        }
Exemple #3
0
        internal IVertexSource GetGlyphForCharacter(char character)
        {
            if (_ofTypeface != null)
            {
                // TODO: MAKE SURE THIS IS OFF!!!!!!! It is un-needed and only for debugging
                //glyphs.Clear();
            }

            // TODO: check for multi character glyphs (we don't currently support them in the reader).
            Glyph glyph = null;

            if (!glyphs.TryGetValue(character, out glyph))
            {
                // if we have a loaded ttf try to create the glyph data
                if (_ofTypeface != null)
                {
                    var storage    = new VertexStorage();
                    var translator = new VertexSourceGlyphTranslator(storage);
                    var glyphIndex = _ofTypeface.LookupIndex(character);
                    var ttfGlyph   = _ofTypeface.GetGlyphByIndex(glyphIndex);
                    //
                    Typography.OpenFont.IGlyphReaderExtensions.Read(translator, ttfGlyph.GlyphPoints, ttfGlyph.EndPoints);

                    //
                    glyph             = new Glyph();
                    glyph.unicode     = character;
                    glyph.horiz_adv_x = _ofTypeface.GetHAdvanceWidthFromGlyphIndex(glyphIndex);

                    glyphs.Add(character, glyph);

                    // Wrap glyph data with ClosedLoopGlyphData to ensure all loops are correctly closed
                    glyph.glyphData = new ClosedLoopGlyphData(storage);
                }
            }

            return(glyph?.glyphData);
        }