Exemple #1
0
        public static void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int opengl_fillrule)
        {
            float            d3d_bias = (opengl_fillrule) != 0 ? 0 : -0.5f;
            float            ipw      = 1.0f / pw;
            float            iph      = 1.0f / ph;
            stbtt_bakedchar *b        = chardata + char_index;
            int round_x = ((int)(CRuntime.Floor((*xpos + b->xoff) + 0.5f)));
            int round_y = ((int)(CRuntime.Floor((*ypos + b->yoff) + 0.5f)));

            q->x0 = round_x + d3d_bias;
            q->y0 = round_y + d3d_bias;
            q->x1 = round_x + b->x1 - b->x0 + d3d_bias;
            q->y1 = round_y + b->y1 - b->y0 + d3d_bias;
            q->s0 = b->x0 * ipw;
            q->t0 = b->y0 * iph;
            q->s1 = b->x1 * ipw;
            q->t1 = b->y1 * iph;
            *xpos += b->xadvance;
        }
        public static void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, int char_index, float *xpos,
                                              float *ypos, stbtt_aligned_quad *q, int opengl_fillrule)
        {
            var d3d_bias = opengl_fillrule != 0 ? 0 : -0.5f;
            var ipw      = 1.0f / pw;
            var iph      = 1.0f / ph;
            var b        = chardata + char_index;
            var round_x  = (int)CRuntime.floor(*xpos + b->xoff + 0.5f);
            var round_y  = (int)CRuntime.floor(*ypos + b->yoff + 0.5f);

            q->x0 = round_x + d3d_bias;
            q->y0 = round_y + d3d_bias;
            q->x1 = round_x + b->x1 - b->x0 + d3d_bias;
            q->y1 = round_y + b->y1 - b->y0 + d3d_bias;
            q->s0 = b->x0 * ipw;
            q->t0 = b->y0 * iph;
            q->s1 = b->x1 * ipw;
            q->t1 = b->y1 * iph;
            *xpos += b->xadvance;
        }
        public static int stbtt_BakeFontBitmap_internal(byte *data, int offset, float pixel_height, byte *pixels,
                                                        int pw, int ph, int first_char, int num_chars, stbtt_bakedchar *chardata)
        {
            float scale    = 0;
            var   x        = 0;
            var   y        = 0;
            var   bottom_y = 0;
            var   i        = 0;
            var   f        = new stbtt_fontinfo();

            f.userdata = null;
            if (stbtt_InitFont(f, data, offset) == 0)
            {
                return(-1);
            }
            CRuntime.memset(pixels, 0, (ulong)(pw * ph));
            x        = y = 1;
            bottom_y = 1;
            scale    = stbtt_ScaleForPixelHeight(f, pixel_height);
            for (i = 0; i < num_chars; ++i)
            {
                var advance = 0;
                var lsb     = 0;
                var x0      = 0;
                var y0      = 0;
                var x1      = 0;
                var y1      = 0;
                var gw      = 0;
                var gh      = 0;
                var g       = stbtt_FindGlyphIndex(f, first_char + i);
                stbtt_GetGlyphHMetrics(f, g, &advance, &lsb);
                stbtt_GetGlyphBitmapBox(f, g, scale, scale, &x0, &y0, &x1, &y1);
                gw = x1 - x0;
                gh = y1 - y0;
                if (x + gw + 1 >= pw)
                {
                    y = bottom_y;
                    x = 1;
                }

                if (y + gh + 1 >= ph)
                {
                    return(-i);
                }
                stbtt_MakeGlyphBitmap(f, pixels + x + y * pw, gw, gh, pw, scale, scale, g);
                chardata[i].x0       = (ushort)(short)x;
                chardata[i].y0       = (ushort)(short)y;
                chardata[i].x1       = (ushort)(short)(x + gw);
                chardata[i].y1       = (ushort)(short)(y + gh);
                chardata[i].xadvance = scale * advance;
                chardata[i].xoff     = x0;
                chardata[i].yoff     = y0;
                x = x + gw + 1;
                if (y + gh + 1 > bottom_y)
                {
                    bottom_y = y + gh + 1;
                }
            }

            return(bottom_y);
        }
 public static int stbtt_BakeFontBitmap(byte *data, int offset, float pixel_height, byte *pixels, int pw, int ph,
                                        int first_char, int num_chars, stbtt_bakedchar *chardata)
 {
     return(stbtt_BakeFontBitmap_internal(data, offset, pixel_height, pixels, pw, ph, first_char, num_chars,
                                          chardata));
 }
Exemple #5
0
        public static int stbtt_BakeFontBitmap_internal(byte *data, int offset, float pixel_height, byte *pixels, int pw, int ph, int first_char, int num_chars, stbtt_bakedchar *chardata)
        {
            float          scale    = 0;
            int            x        = 0;
            int            y        = 0;
            int            bottom_y = 0;
            int            i        = 0;
            stbtt_fontinfo f        = new stbtt_fontinfo();

            f.userdata = (null);
            if (stbtt_InitFont(f, data, (int)(offset)) == 0)
            {
                return((int)(-1));
            }
            CRuntime.memset(pixels, (int)(0), (ulong)(pw * ph));
            x        = (int)(y = (int)(1));
            bottom_y = (int)(1);
            scale    = (float)(stbtt_ScaleForPixelHeight(f, (float)(pixel_height)));
            for (i = (int)(0); (i) < (num_chars); ++i)
            {
                int advance = 0;
                int lsb     = 0;
                int x0      = 0;
                int y0      = 0;
                int x1      = 0;
                int y1      = 0;
                int gw      = 0;
                int gh      = 0;
                int g       = (int)(stbtt_FindGlyphIndex(f, (int)(first_char + i)));
                stbtt_GetGlyphHMetrics(f, (int)(g), &advance, &lsb);
                stbtt_GetGlyphBitmapBox(f, (int)(g), (float)(scale), (float)(scale), &x0, &y0, &x1, &y1);
                gw = (int)(x1 - x0);
                gh = (int)(y1 - y0);
                if ((x + gw + 1) >= (pw))
                {
                    y = (int)(bottom_y);
                    x = (int)(1);
                }
                if ((y + gh + 1) >= (ph))
                {
                    return((int)(-i));
                }
                stbtt_MakeGlyphBitmap(f, pixels + x + y * pw, (int)(gw), (int)(gh), (int)(pw), (float)(scale), (float)(scale), (int)(g));
                chardata[i].x0       = (ushort)((short)(x));
                chardata[i].y0       = (ushort)((short)(y));
                chardata[i].x1       = (ushort)((short)(x + gw));
                chardata[i].y1       = (ushort)((short)(y + gh));
                chardata[i].xadvance = (float)(scale * advance);
                chardata[i].xoff     = ((float)(x0));
                chardata[i].yoff     = ((float)(y0));
                x = (int)(x + gw + 1);
                if ((y + gh + 1) > (bottom_y))
                {
                    bottom_y = (int)(y + gh + 1);
                }
            }
            return((int)(bottom_y));
        }
Exemple #6
0
 public static int stbtt_BakeFontBitmap(byte *data, int offset, float pixel_height, byte *pixels, int pw, int ph, int first_char, int num_chars, stbtt_bakedchar *chardata)
 {
     return((int)(stbtt_BakeFontBitmap_internal(data, (int)(offset), (float)(pixel_height), pixels, (int)(pw), (int)(ph), (int)(first_char), (int)(num_chars), chardata)));
 }