public static void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer) { var ipw = 1.0f / pw; var iph = 1.0f / ph; var b = chardata + char_index; if (align_to_integer != 0) { float x = (int)CRuntime.floor(*xpos + b->xoff + 0.5f); float y = (int)CRuntime.floor(*ypos + b->yoff + 0.5f); q->x0 = x; q->y0 = y; q->x1 = x + b->xoff2 - b->xoff; q->y1 = y + b->yoff2 - b->yoff; } else { q->x0 = *xpos + b->xoff; q->y0 = *ypos + b->yoff; q->x1 = *xpos + b->xoff2; q->y1 = *ypos + b->yoff2; } 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_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer) { float ipw = (float)(1.0f / pw); float iph = (float)(1.0f / ph); stbtt_packedchar *b = chardata + char_index; if ((align_to_integer) != 0) { float x = (float)((int)(CRuntime.floor((double)((*xpos + b->xoff) + 0.5f)))); float y = (float)((int)(CRuntime.floor((double)((*ypos + b->yoff) + 0.5f)))); q->x0 = (float)(x); q->y0 = (float)(y); q->x1 = (float)(x + b->xoff2 - b->xoff); q->y1 = (float)(y + b->yoff2 - b->yoff); } else { q->x0 = (float)(*xpos + b->xoff); q->y0 = (float)(*ypos + b->yoff); q->x1 = (float)(*xpos + b->xoff2); q->y1 = (float)(*ypos + b->yoff2); } q->s0 = (float)(b->x0 * ipw); q->t0 = (float)(b->y0 * iph); q->s1 = (float)(b->x1 * ipw); q->t1 = (float)(b->y1 * iph); *xpos += (float)(b->xadvance); }
public static int stbtt_PackFontRange(stbtt_pack_context spc, byte *fontdata, int font_index, float font_size, int first_unicode_codepoint_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range) { stbtt_pack_range range = new stbtt_pack_range(); range.first_unicode_codepoint_in_range = (int)(first_unicode_codepoint_in_range); range.array_of_unicode_codepoints = (null); range.num_chars = (int)(num_chars_in_range); range.chardata_for_range = chardata_for_range; range.font_size = (float)(font_size); return((int)(stbtt_PackFontRanges(spc, fontdata, (int)(font_index), &range, (int)(1)))); }
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_PackFontRange(stbtt_pack_context spc, byte *fontdata, int font_index, float font_size, int first_unicode_codepoint_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range) { var range = new stbtt_pack_range(); range.first_unicode_codepoint_in_range = first_unicode_codepoint_in_range; range.array_of_unicode_codepoints = null; range.num_chars = num_chars_in_range; range.chardata_for_range = chardata_for_range; range.font_size = font_size; return(stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1)); }