Exemplo n.º 1
0
        public VertexStore CreateVxs(char[] buffer, double x = 0, double y = 0)
        {
            int j        = buffer.Length;
            int buffsize = j * 2;

            //get kerning list

            ProperGlyph[] properGlyphs = new ProperGlyph[buffsize];
            currentFont.GetGlyphPos(buffer, 0, buffsize, properGlyphs);
            VertexStore resultVxs = new VertexStore();
            double      xpos      = x;

            for (int i = 0; i < buffsize; ++i)
            {
                uint codepoint = properGlyphs[i].codepoint;
                if (codepoint == 0)
                {
                    break;
                }
                //-------------------------------------------------------------
                FontGlyph glyph = this.currentFont.GetGlyphByIndex(codepoint);
                var       left  = glyph.exportGlyph.img_horiBearingX;
                //--------------------------------------------------------
                VertexStore vxs1 = Agg.Transform.Affine.TranslateToVxs(
                    glyph.flattenVxs,
                    (float)(xpos),
                    (float)(y));
                //--------------------------------------------------------
                resultVxs.AddSubVertices(vxs1);
                int w = (glyph.exportGlyph.advanceX) >> 6;
                xpos += (w);
                //-------------------------------------------------------------
            }
            return(resultVxs);
        }
Exemplo n.º 2
0
        public void Print(CanvasPainter painter, char[] buffer, double x, double y)
        {
            int j        = buffer.Length;
            int buffsize = j * 2;

            //get kerning list

            ProperGlyph[] properGlyphs = new ProperGlyph[buffsize];
            currentFont.GetGlyphPos(buffer, 0, buffsize, properGlyphs);
            double xpos = x;

            for (int i = 0; i < buffsize; ++i)
            {
                uint codepoint = properGlyphs[i].codepoint;
                if (codepoint == 0)
                {
                    break;
                }
                //-------------------------------------------------------------
                FontGlyph glyph = this.currentFont.GetGlyphByIndex(codepoint);
                var       left  = glyph.exportGlyph.img_horiBearingX;
                //--------------------------------------------------------
                //render with vector
                //var mat = Agg.Transform.Affine.NewMatix(
                //Agg.Transform.AffinePlan.Scale(0.30),
                //Agg.Transform.AffinePlan.Translate(xpos, y));
                //var vxs1 = mat.TransformToVxs(glyph.flattenVxs);

                VertexStore vxs1 = Agg.Transform.Affine.TranslateToVxs(
                    glyph.flattenVxs,
                    (float)(xpos),
                    (float)(y));
                painter.Fill(vxs1);
                //--------------------------------------------------------
                ////render with bitmap
                //this.painter.DrawImage(glyph.glyphImage32,
                //    (float)(xpos + (left >> 6)),
                //    (float)(y + (glyph.exportGlyph.bboxYmin >> 6)));

                int w = (glyph.exportGlyph.advanceX) >> 6;
                xpos += (w);
                //-------------------------------------------------------------
            }
        }
        protected override void GetGlyphPosImpl(ActualFont actualFont, char[] buffer,
                                                int startAt, int len,
                                                List <GlyphPlan> glyphPlans)
        {
            NativeFont nativeFont = actualFont as NativeFont;

            if (nativeFont == null)
            {
                nativeFont = ResolveForNativeFont(actualFont);
            }

            unsafe
            {
                //TODO: review proper array size here
                int          lim = len * 2;
                ProperGlyph *properGlyphArray = stackalloc ProperGlyph[lim];
                fixed(char *head = &buffer[0])
                {
                    //we use font shaping engine here
                    NativeMyFontsLib.MyFtShaping(
                        nativeFont.NativeFontFace.HBFont,
                        head,
                        buffer.Length,
                        properGlyphArray);
                }

                //copy from proper glyph to
                //create glyph plan

                for (int i = 0; i < lim; ++i)
                {
                    ProperGlyph propGlyph = properGlyphArray[i];
                    if (propGlyph.codepoint == 0)
                    {
                        //finish , just return
                        return;
                    }
                    GlyphPlan plan = new GlyphPlan((ushort)propGlyph.codepoint);
                    plan.advX = propGlyph.x_advance;
                    glyphPlans.Add(plan);
                }
            }
        }