public static int stbtt_PackFontRangesGatherRects(stbtt_pack_context spc, stbtt_fontinfo info,
                                                          stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
        {
            var i = 0;
            var j = 0;
            var k = 0;
            var missing_glyph_added = 0;

            k = 0;
            for (i = 0; i < num_ranges; ++i)
            {
                var fh    = ranges[i].font_size;
                var scale = fh > 0 ? stbtt_ScaleForPixelHeight(info, fh) : stbtt_ScaleForMappingEmToPixels(info, -fh);
                ranges[i].h_oversample = (byte)spc.h_oversample;
                ranges[i].v_oversample = (byte)spc.v_oversample;
                for (j = 0; j < ranges[i].num_chars; ++j)
                {
                    var x0        = 0;
                    var y0        = 0;
                    var x1        = 0;
                    var y1        = 0;
                    var codepoint = ranges[i].array_of_unicode_codepoints == null
                                                ? ranges[i].first_unicode_codepoint_in_range + j
                                                : ranges[i].array_of_unicode_codepoints[j];
                    var glyph = stbtt_FindGlyphIndex(info, codepoint);
                    if (glyph == 0 && (spc.skip_missing != 0 || missing_glyph_added != 0))
                    {
                        rects[k].w = rects[k].h = 0;
                    }
                    else
                    {
                        stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale * spc.h_oversample, scale * spc.v_oversample,
                                                        0, 0, &x0, &y0, &x1, &y1);
                        rects[k].w = (int)(x1 - x0 + spc.padding + spc.h_oversample - 1);
                        rects[k].h = (int)(y1 - y0 + spc.padding + spc.v_oversample - 1);
                        if (glyph == 0)
                        {
                            missing_glyph_added = 1;
                        }
                    }

                    ++k;
                }
            }

            return(k);
        }
        public static int stbtt_PackFontRanges(stbtt_pack_context spc, byte *fontdata, int font_index,
                                               stbtt_pack_range *ranges, int num_ranges)
        {
            var         info         = new stbtt_fontinfo();
            var         i            = 0;
            var         j            = 0;
            var         n            = 0;
            var         return_value = 1;
            stbrp_rect *rects;

            for (i = 0; i < num_ranges; ++i)
            {
                for (j = 0; j < ranges[i].num_chars; ++j)
                {
                    ranges[i].chardata_for_range[j].x0     = ranges[i].chardata_for_range[j].y0 =
                        ranges[i].chardata_for_range[j].x1 = ranges[i].chardata_for_range[j].y1 = 0;
                }
            }

            n = 0;
            for (i = 0; i < num_ranges; ++i)
            {
                n += ranges[i].num_chars;
            }

            rects = (stbrp_rect *)CRuntime.malloc((ulong)(sizeof(stbrp_rect) * n));
            if (rects == null)
            {
                return(0);
            }
            info.userdata = spc.user_allocator_context;
            stbtt_InitFont(info, fontdata, stbtt_GetFontOffsetForIndex(fontdata, font_index));
            n = stbtt_PackFontRangesGatherRects(spc, info, ranges, num_ranges, rects);
            stbtt_PackFontRangesPackRects(spc, rects, n);
            return_value = stbtt_PackFontRangesRenderIntoRects(spc, info, ranges, num_ranges, rects);
            CRuntime.free(rects);
            return(return_value);
        }
Пример #3
0
        public static int stbtt_PackFontRanges(stbtt_pack_context spc, byte *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)
        {
            stbtt_fontinfo info         = new stbtt_fontinfo();
            int            i            = 0;
            int            j            = 0;
            int            n            = 0;
            int            return_value = (int)(1);
            stbrp_rect *   rects;

            for (i = (int)(0); (i) < (num_ranges); ++i)
            {
                for (j = (int)(0); (j) < (ranges[i].num_chars); ++j)
                {
                    ranges[i].chardata_for_range[j].x0 = (ushort)(ranges[i].chardata_for_range[j].y0 = (ushort)(ranges[i].chardata_for_range[j].x1 = (ushort)(ranges[i].chardata_for_range[j].y1 = (ushort)(0))));
                }
            }
            n = (int)(0);
            for (i = (int)(0); (i) < (num_ranges); ++i)
            {
                n += (int)(ranges[i].num_chars);
            }
            rects = (stbrp_rect *)(CRuntime.malloc((ulong)(sizeof(stbrp_rect) * n)));
            if ((rects) == (null))
            {
                return((int)(0));
            }
            info.userdata = spc.user_allocator_context;
            stbtt_InitFont(info, fontdata, (int)(stbtt_GetFontOffsetForIndex(fontdata, (int)(font_index))));
            n = (int)(stbtt_PackFontRangesGatherRects(spc, info, ranges, (int)(num_ranges), rects));
            stbtt_PackFontRangesPackRects(spc, rects, (int)(n));
            return_value = (int)(stbtt_PackFontRangesRenderIntoRects(spc, info, ranges, (int)(num_ranges), rects));
            CRuntime.free(rects);
            return((int)(return_value));
        }
Пример #4
0
        public static int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context spc, stbtt_fontinfo info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
        {
            int i             = 0;
            int j             = 0;
            int k             = 0;
            int missing_glyph = (int)(-1);
            int return_value  = (int)(1);
            int old_h_over    = (int)(spc.h_oversample);
            int old_v_over    = (int)(spc.v_oversample);

            k = (int)(0);
            for (i = (int)(0); (i) < (num_ranges); ++i)
            {
                float fh      = (float)(ranges[i].font_size);
                float scale   = (float)((fh) > (0) ? stbtt_ScaleForPixelHeight(info, (float)(fh)) : stbtt_ScaleForMappingEmToPixels(info, (float)(-fh)));
                float recip_h = 0;
                float recip_v = 0;
                float sub_x   = 0;
                float sub_y   = 0;
                spc.h_oversample = (uint)(ranges[i].h_oversample);
                spc.v_oversample = (uint)(ranges[i].v_oversample);
                recip_h          = (float)(1.0f / spc.h_oversample);
                recip_v          = (float)(1.0f / spc.v_oversample);
                sub_x            = (float)(stbtt__oversample_shift((int)(spc.h_oversample)));
                sub_y            = (float)(stbtt__oversample_shift((int)(spc.v_oversample)));
                for (j = (int)(0); (j) < (ranges[i].num_chars); ++j)
                {
                    stbrp_rect *r = &rects[k];
                    if ((((r->was_packed) != 0) && (r->w != 0)) && (r->h != 0))
                    {
                        stbtt_packedchar *bc = &ranges[i].chardata_for_range[j];
                        int advance          = 0;
                        int lsb       = 0;
                        int x0        = 0;
                        int y0        = 0;
                        int x1        = 0;
                        int y1        = 0;
                        int codepoint = (int)((ranges[i].array_of_unicode_codepoints) == (null) ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j]);
                        int glyph     = (int)(stbtt_FindGlyphIndex(info, (int)(codepoint)));
                        int pad       = (int)(spc.padding);
                        r->x += (int)(pad);
                        r->y += (int)(pad);
                        r->w -= (int)(pad);
                        r->h -= (int)(pad);
                        stbtt_GetGlyphHMetrics(info, (int)(glyph), &advance, &lsb);
                        stbtt_GetGlyphBitmapBox(info, (int)(glyph), (float)(scale * spc.h_oversample), (float)(scale * spc.v_oversample), &x0, &y0, &x1, &y1);
                        stbtt_MakeGlyphBitmapSubpixel(info, spc.pixels + r->x + r->y * spc.stride_in_bytes, (int)(r->w - spc.h_oversample + 1), (int)(r->h - spc.v_oversample + 1), (int)(spc.stride_in_bytes), (float)(scale * spc.h_oversample), (float)(scale * spc.v_oversample), (float)(0), (float)(0), (int)(glyph));
                        if ((spc.h_oversample) > (1))
                        {
                            stbtt__h_prefilter(spc.pixels + r->x + r->y * spc.stride_in_bytes, (int)(r->w), (int)(r->h), (int)(spc.stride_in_bytes), (uint)(spc.h_oversample));
                        }
                        if ((spc.v_oversample) > (1))
                        {
                            stbtt__v_prefilter(spc.pixels + r->x + r->y * spc.stride_in_bytes, (int)(r->w), (int)(r->h), (int)(spc.stride_in_bytes), (uint)(spc.v_oversample));
                        }
                        bc->x0       = (ushort)((short)(r->x));
                        bc->y0       = (ushort)((short)(r->y));
                        bc->x1       = (ushort)((short)(r->x + r->w));
                        bc->y1       = (ushort)((short)(r->y + r->h));
                        bc->xadvance = (float)(scale * advance);
                        bc->xoff     = (float)((float)(x0) * recip_h + sub_x);
                        bc->yoff     = (float)((float)(y0) * recip_v + sub_y);
                        bc->xoff2    = (float)((x0 + r->w) * recip_h + sub_x);
                        bc->yoff2    = (float)((y0 + r->h) * recip_v + sub_y);
                        if ((glyph) == (0))
                        {
                            missing_glyph = (int)(j);
                        }
                    }
                    else if ((spc.skip_missing) != 0)
                    {
                        return_value = (int)(0);
                    }
                    else if (((((r->was_packed) != 0) && ((r->w) == (0))) && ((r->h) == (0))) && ((missing_glyph) >= (0)))
                    {
                        ranges[i].chardata_for_range[j] = (stbtt_packedchar)(ranges[i].chardata_for_range[missing_glyph]);
                    }
                    else
                    {
                        return_value = (int)(0);
                    }
                    ++k;
                }
            }
            spc.h_oversample = (uint)(old_h_over);
            spc.v_oversample = (uint)(old_v_over);
            return((int)(return_value));
        }
Пример #5
0
        public static int stbtt_PackFontRangesGatherRects(stbtt_pack_context spc, stbtt_fontinfo info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
        {
            int i = 0;
            int j = 0;
            int k = 0;
            int missing_glyph_added = (int)(0);

            k = (int)(0);
            for (i = (int)(0); (i) < (num_ranges); ++i)
            {
                float fh    = (float)(ranges[i].font_size);
                float scale = (float)((fh) > (0) ? stbtt_ScaleForPixelHeight(info, (float)(fh)) : stbtt_ScaleForMappingEmToPixels(info, (float)(-fh)));
                ranges[i].h_oversample = ((byte)(spc.h_oversample));
                ranges[i].v_oversample = ((byte)(spc.v_oversample));
                for (j = (int)(0); (j) < (ranges[i].num_chars); ++j)
                {
                    int x0        = 0;
                    int y0        = 0;
                    int x1        = 0;
                    int y1        = 0;
                    int codepoint = (int)((ranges[i].array_of_unicode_codepoints) == (null) ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j]);
                    int glyph     = (int)(stbtt_FindGlyphIndex(info, (int)(codepoint)));
                    if (((glyph) == (0)) && (((spc.skip_missing) != 0) || ((missing_glyph_added) != 0)))
                    {
                        rects[k].w = (int)(rects[k].h = (int)(0));
                    }
                    else
                    {
                        stbtt_GetGlyphBitmapBoxSubpixel(info, (int)(glyph), (float)(scale * spc.h_oversample), (float)(scale * spc.v_oversample), (float)(0), (float)(0), &x0, &y0, &x1, &y1);
                        rects[k].w = ((int)(x1 - x0 + spc.padding + spc.h_oversample - 1));
                        rects[k].h = ((int)(y1 - y0 + spc.padding + spc.v_oversample - 1));
                        if ((glyph) == (0))
                        {
                            missing_glyph_added = (int)(1);
                        }
                    }
                    ++k;
                }
            }
            return((int)(k));
        }
        public static int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context spc, stbtt_fontinfo info,
                                                              stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
        {
            var i             = 0;
            var j             = 0;
            var k             = 0;
            var missing_glyph = -1;
            var return_value  = 1;
            var old_h_over    = (int)spc.h_oversample;
            var old_v_over    = (int)spc.v_oversample;

            k = 0;
            for (i = 0; i < num_ranges; ++i)
            {
                var   fh      = ranges[i].font_size;
                var   scale   = fh > 0 ? stbtt_ScaleForPixelHeight(info, fh) : stbtt_ScaleForMappingEmToPixels(info, -fh);
                float recip_h = 0;
                float recip_v = 0;
                float sub_x   = 0;
                float sub_y   = 0;
                spc.h_oversample = ranges[i].h_oversample;
                spc.v_oversample = ranges[i].v_oversample;
                recip_h          = 1.0f / spc.h_oversample;
                recip_v          = 1.0f / spc.v_oversample;
                sub_x            = stbtt__oversample_shift((int)spc.h_oversample);
                sub_y            = stbtt__oversample_shift((int)spc.v_oversample);
                for (j = 0; j < ranges[i].num_chars; ++j)
                {
                    var r = &rects[k];
                    if (r->was_packed != 0 && r->w != 0 && r->h != 0)
                    {
                        var bc        = &ranges[i].chardata_for_range[j];
                        var advance   = 0;
                        var lsb       = 0;
                        var x0        = 0;
                        var y0        = 0;
                        var x1        = 0;
                        var y1        = 0;
                        var codepoint = ranges[i].array_of_unicode_codepoints == null
                                                        ? ranges[i].first_unicode_codepoint_in_range + j
                                                        : ranges[i].array_of_unicode_codepoints[j];
                        var glyph = stbtt_FindGlyphIndex(info, codepoint);
                        var pad   = spc.padding;
                        r->x += pad;
                        r->y += pad;
                        r->w -= pad;
                        r->h -= pad;
                        stbtt_GetGlyphHMetrics(info, glyph, &advance, &lsb);
                        stbtt_GetGlyphBitmapBox(info, glyph, scale * spc.h_oversample, scale * spc.v_oversample, &x0,
                                                &y0, &x1, &y1);
                        stbtt_MakeGlyphBitmapSubpixel(info, spc.pixels + r->x + r->y * spc.stride_in_bytes,
                                                      (int)(r->w - spc.h_oversample + 1), (int)(r->h - spc.v_oversample + 1),
                                                      spc.stride_in_bytes, scale * spc.h_oversample, scale * spc.v_oversample, 0, 0, glyph);
                        if (spc.h_oversample > 1)
                        {
                            stbtt__h_prefilter(spc.pixels + r->x + r->y * spc.stride_in_bytes, r->w, r->h,
                                               spc.stride_in_bytes, spc.h_oversample);
                        }
                        if (spc.v_oversample > 1)
                        {
                            stbtt__v_prefilter(spc.pixels + r->x + r->y * spc.stride_in_bytes, r->w, r->h,
                                               spc.stride_in_bytes, spc.v_oversample);
                        }
                        bc->x0       = (ushort)(short)r->x;
                        bc->y0       = (ushort)(short)r->y;
                        bc->x1       = (ushort)(short)(r->x + r->w);
                        bc->y1       = (ushort)(short)(r->y + r->h);
                        bc->xadvance = scale * advance;
                        bc->xoff     = x0 * recip_h + sub_x;
                        bc->yoff     = y0 * recip_v + sub_y;
                        bc->xoff2    = (x0 + r->w) * recip_h + sub_x;
                        bc->yoff2    = (y0 + r->h) * recip_v + sub_y;
                        if (glyph == 0)
                        {
                            missing_glyph = j;
                        }
                    }
                    else if (spc.skip_missing != 0)
                    {
                        return_value = 0;
                    }
                    else if (r->was_packed != 0 && r->w == 0 && r->h == 0 && missing_glyph >= 0)
                    {
                        ranges[i].chardata_for_range[j] = ranges[i].chardata_for_range[missing_glyph];
                    }
                    else
                    {
                        return_value = 0;
                    }

                    ++k;
                }
            }

            spc.h_oversample = (uint)old_h_over;
            spc.v_oversample = (uint)old_v_over;
            return(return_value);
        }