public static void stbrp_pack_rects(stbrp_context *con, stbrp_rect *rects, int num_rects) { int i = 0; for (i = (int)(0); (i) < (num_rects); ++i) { if ((con->x + rects[i].w) > (con->width)) { con->x = (int)(0); con->y = (int)(con->bottom_y); } if ((con->y + rects[i].h) > (con->height)) { break; } rects[i].x = (int)(con->x); rects[i].y = (int)(con->y); rects[i].was_packed = (int)(1); con->x += (int)(rects[i].w); if ((con->y + rects[i].h) > (con->bottom_y)) { con->bottom_y = (int)(con->y + rects[i].h); } } for (; (i) < (num_rects); ++i) { rects[i].was_packed = (int)(0); } }
public static void stbrp_pack_rects(stbrp_context *con, stbrp_rect *rects, int num_rects) { var i = 0; for (i = 0; i < num_rects; ++i) { if (con->x + rects[i].w > con->width) { con->x = 0; con->y = con->bottom_y; } if (con->y + rects[i].h > con->height) { break; } rects[i].x = con->x; rects[i].y = con->y; rects[i].was_packed = 1; con->x += rects[i].w; if (con->y + rects[i].h > con->bottom_y) { con->bottom_y = con->y + rects[i].h; } } for (; i < num_rects; ++i) { rects[i].was_packed = 0; } }
public static int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects) { var i = 0; var all_rects_packed = 1; for (i = 0; i < num_rects; ++i) { rects[i].was_packed = i; } CRuntime.qsort(rects, (ulong)num_rects, (ulong)sizeof(stbrp_rect), rect_height_compare); for (i = 0; i < num_rects; ++i) { if (rects[i].w == 0 || rects[i].h == 0) { rects[i].x = rects[i].y = 0; } else { var fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h); if (fr.prev_link != null) { rects[i].x = (int)fr.x; rects[i].y = (int)fr.y; } else { rects[i].x = rects[i].y = 0xffff; } } } CRuntime.qsort(rects, (ulong)num_rects, (ulong)sizeof(stbrp_rect), rect_original_order); for (i = 0; i < num_rects; ++i) { rects[i].was_packed = rects[i].x == 0xffff && rects[i].y == 0xffff ? 0 : 1; if (rects[i].was_packed == 0) { all_rects_packed = 0; } } return(all_rects_packed); }
public static void stbtt_PackFontRangesPackRects(stbtt_pack_context spc, stbrp_rect *rects, int num_rects) { stbrp_pack_rects((stbrp_context *)(spc.pack_info), rects, (int)(num_rects)); }
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)); }
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); }
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 unsafe extern void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects);