示例#1
0
        public static void SetHintTechnique(this GlyphPathBuilder builder, HintTechnique hintTech)
        {
            builder.UseTrueTypeInstructions = false; //reset
            builder.UseVerticalHinting      = false; //reset
            switch (hintTech)
            {
            case HintTechnique.TrueTypeInstruction:
                builder.UseTrueTypeInstructions = true;
                break;

            case HintTechnique.TrueTypeInstruction_VerticalOnly:
                builder.UseTrueTypeInstructions = true;
                builder.UseVerticalHinting      = true;
                break;

            case HintTechnique.CustomAutoFit:
                //custom agg autofit
                builder.UseVerticalHinting = true;
                break;
            }
        }
示例#2
0
 public static void Build(this GlyphPathBuilder builder, char c, float sizeInPoints)
 {
     builder.BuildFromGlyphIndex((ushort)builder.Typeface.LookupIndex(c), sizeInPoints);
 }
示例#3
0
        public GlyphImage CreateGlyphImage(GlyphPathBuilder builder, float pxscale)
        {
            //1. create

            var txToVxs = new GlyphTranslatorToVxs();

            builder.ReadShapes(txToVxs);
            //
            //create new one
            var glyphVxs = new VertexStore();

            txToVxs.WriteOutput(glyphVxs, pxscale);
            //find bound
            //--------------------------------------------
            //GlyphImage glyphImg = new GlyphImage()
            RectD bounds = new RectD();

            BoundingRect.GetBoundingRect(new VertexStoreSnap(glyphVxs), ref bounds);

            ////--------------------------------------------
            int w = (int)System.Math.Ceiling(bounds.Width);
            int h = (int)System.Math.Ceiling(bounds.Height);

            if (w < 5)
            {
                w = 5;
            }
            if (h < 5)
            {
                h = 5;
            }
            ////translate to positive quadrant
            double dx = (bounds.Left < 0) ? -bounds.Left : 0;
            double dy = (bounds.Bottom < 0) ? -bounds.Bottom : 0;

            //we need some borders
            int horizontal_margin = 1; //'margin' 1px
            int vertical_margin   = 1; //margin 1 px

            dx += horizontal_margin;   //+ left margin
            dy += vertical_margin;     //+ top margin
                                       //--------------------------------------------
                                       //create glyph img


            w = (int)Math.Ceiling(dx + w + horizontal_margin); //+right margin
            h = (int)Math.Ceiling(dy + h + vertical_margin);   //+bottom margin

            ActualImage      img     = new ActualImage(w, h, PixelFormat.ARGB32);
            AggRenderSurface aggsx   = new AggRenderSurface(img);
            AggPainter       painter = new AggPainter(aggsx);

            if (TextureKind == TextureKind.StencilLcdEffect)
            {
                VertexStore vxs2 = new VertexStore();
                glyphVxs.TranslateToNewVxs(dx + 0.33f, dy, vxs2); //offset to proper x of subpixel rendering  ***
                glyphVxs = vxs2;
                //
                painter.UseSubPixelLcdEffect = true;

                //we use white glyph on black bg for this texture
                painter.Clear(Color.Black);
                painter.FillColor = Color.White;
                painter.Fill(glyphVxs);

                //apply sharpen filter
                //painter.DoFilter(new RectInt(0, h, w, 0), 2);
                //painter.DoFilter(new RectInt(0, h, w, 0), 2); //?
            }
            else
            {
                VertexStore vxs2 = new VertexStore();
                glyphVxs.TranslateToNewVxs(dx, dy, vxs2);
                glyphVxs = vxs2;

                painter.UseSubPixelLcdEffect = false;

                if (TextureKind == TextureKind.StencilGreyScale)
                {
                    painter.Clear(Color.Empty);
                    painter.FillColor = Color.Black;
                }
                else
                {
                    painter.Clear(BackGroundColor);
                    painter.FillColor = this.GlyphColor;
                }
                painter.Fill(glyphVxs);
            }
            //
            var glyphImage = new GlyphImage(w, h);

            glyphImage.TextureOffsetX = dx;
            glyphImage.TextureOffsetY = dy;
            glyphImage.SetImageBuffer(ActualImageExtensions.CopyImgBuffer(img, w), false);
            //copy data from agg canvas to glyph image
            return(glyphImage);
        }