Пример #1
0
 public GrayScaleLetterGlyph GetGrayScaleLetter(char ch)
 {
     lock (Glyphs)
     {
         if (!Glyphs.ContainsKey(ch))
         {
             Glyphs[ch] = GrayScaleLetterGlyph.CreateGlyph(Typeface, GlyphTypeface, EmSize, ch);
         }
         return(Glyphs[ch]);
     }
 }
Пример #2
0
        public GrayScaleLetterGlyph GetGrayScaleLetter(char ch)
        {
            lock (this.Glyphs)
            {
                if (!this.Glyphs.ContainsKey(ch))
                {
                    this.Glyphs[ch] = GrayScaleLetterGlyph.CreateGlyph(this.Typeface, this.GlyphTypeface, this.EmSize, ch);
                }

                return(this.Glyphs[ch]);
            }
        }
Пример #3
0
        public static unsafe void DrawLetter(this BitmapContext context, int x0, int y0, IntRect cliprect, Color fontColor, GrayScaleLetterGlyph glyph)
        {
            if (glyph.Items == null)
            {
                return;
            }

            // Use refs for faster access (really important!) speeds up a lot!
            var w      = context.Width;
            var h      = context.Height;
            var pixels = context.Pixels;

            int fr = fontColor.R;
            int fg = fontColor.G;
            int fb = fontColor.B;

            var xmin = cliprect.Left;
            var ymin = cliprect.Top;
            var xmax = cliprect.Right;
            var ymax = cliprect.Bottom;

            if (xmin < 0)
            {
                xmin = 0;
            }
            if (ymin < 0)
            {
                ymin = 0;
            }
            if (xmax >= w)
            {
                xmax = w - 1;
            }
            if (ymax >= h)
            {
                ymax = h - 1;

                fixed(GrayScaleLetterGlyph.Item *items = glyph.Items)
                {
                    var itemCount   = glyph.Items.Length;
                    var currentItem = items;

                    for (var i = 0; i < itemCount; i++, currentItem++)
                    {
                        var x     = x0 + currentItem->X;
                        var y     = y0 + currentItem->Y;
                        var alpha = currentItem->Alpha;
                        if (x < xmin || y < ymin || x > xmax || y > ymax)
                        {
                            continue;
                        }

                        var color = pixels[y * w + x];
                        var r     = ((color >> 16) & 0xFF);
                        var g     = ((color >> 8) & 0xFF);
                        var b     = ((color) & 0xFF);

                        r = (((r << 12) + (fr - r) * alpha) >> 12) & 0xFF;
                        g = (((g << 12) + (fg - g) * alpha) >> 12) & 0xFF;
                        b = (((b << 12) + (fb - b) * alpha) >> 12) & 0xFF;

                        pixels[y * w + x] = (0xFF << 24) | (r << 16) | (g << 8) | (b);
                    }
                }
        }