Esempio n. 1
0
        public void DrawText(Bitmap bitmap, string text, float x, float y)
        {
            if (UseInterpreter)
            {
                interpreter.ppem = FontSize;
                InterpretPrep();
            }

            context.UseInterpreter         = UseInterpreter;
            context.UseBitmapGlyph         = UseBitmapGlyph;
            context.DX                     = x;
            context.DY                     = y;
            context.FontSize               = FontSize;
            context.Bitmap                 = bitmap;
            context.Graphics               = Graphics.FromImage(bitmap);
            context.Graphics.SmoothingMode = SmoothingMode.HighQuality;

            HmtxTable hmtx          = font.Tables.hmtx;
            GlyfTable glyf          = font.Tables.glyf;
            char      highSurrogate = '\0';
            int       length        = text.Length;

            for (int i = 0; i < length; i++)
            {
                char charCode = text[i];
                if (char.IsHighSurrogate(charCode))
                {
                    highSurrogate = charCode;
                    continue;
                }
                int codePoint;
                if (char.IsLowSurrogate(charCode))
                {
                    codePoint = char.ConvertToUtf32(highSurrogate, charCode);
                }
                else
                {
                    codePoint = charCode;
                }
                context.CodePoint = codePoint;
                context.GlyphId   = font.GetGlyphId(codePoint);
                if (hmtx != null)
                {
                    context.hMetric = hmtx.GetMetric(context.GlyphId);
                }
                if (glyf != null)
                {
                    context.Glyph = glyf.GetGlyph(context.GlyphId);
                    if (context.Glyph == null)
                    {
                        //context.GlyphId = 0;
                        //context.Glyph = glyf.GetGlyph(0);
                        if (hmtx != null)
                        {
                            //context.hMetric = hmtx.GetMetric(0);
                        }
                    }
                }
                DrawGlyph(context);
            }
            context.Reset();
        }