コード例 #1
0
ファイル: text.c プロジェクト: 0502758187/libdarnit
struct TEXT_FONT_GLYPH *textRenderGlyph(struct TEXT_FONT_CACHE *index, unsigned int glyph, int glyph_index, TEXT_FONT *font) {
	int pos_x, pos_y, w, h, x1, x2, y1, y2, ad, sb;
	unsigned char *data;
	struct TEXT_FONT_GLYPH *next, *alloc;
	float skipf;

	if ((alloc = malloc(sizeof(struct TEXT_FONT_GLYPH))) == NULL)
		return NULL;

	next = index->glyph;
	alloc->next = NULL;

	if (next == NULL)
		index->glyph = alloc;
	else {
		while (next->next != NULL)
			next = next->next;
		next->next = alloc;
	}

	x1 = y1 = x2 = y2 = 0;
	data = stbtt_GetGlyphBitmap(&font->face, 0, font->scale, glyph_index, &w, &h, 0, 0);
	textCacheGetCoordinates(index, w, h, &pos_x, &pos_y);
	stbtt_GetGlyphBox(&font->face, glyph_index, &x1, &y1, &x2, &y2);
	stbtt_GetGlyphHMetrics(&font->face, glyph_index, &ad, &sb);

	alloc->u1 = index->sheet_pwf * pos_x;
	alloc->v1 = index->sheet_phf * pos_y;
	alloc->u2 = index->sheet_pwf * pos_x + index->sheet_pwf * (w);
	alloc->v2 = index->sheet_phf * pos_y + index->sheet_phf * (h);
	alloc->wf = index->sheet_pwf * w;
	alloc->hf = index->sheet_phf * h;
	alloc->risei = y2 * font->scale;
	alloc->rise = index->ts->shgran * alloc->risei;

	alloc->cw = w;
	alloc->ch = h;
	alloc->adv = lrintf(font->scale * ad);
	alloc->advf = index->ts->swgran * alloc->adv;
	skipf = font->scale * sb;
	alloc->skip = skipf;
	alloc->skipf = index->ts->swgran * skipf;

	alloc->glyph = glyph;
	alloc->tex_cache = index;

	renderUpdateTilesheet(index->ts, pos_x, pos_y, data, w, h);
	stbtt_FreeBitmap(data, NULL);

	return alloc;
}
コード例 #2
0
static inline jint wrapped_Java_com_badlogic_gdx_graphics_g2d_stbtt_StbTrueType_getGlyphBox
(JNIEnv* env, jclass clazz, jlong info, jint glyphIndex, jintArray obj_box, int* box) {

//@line:103

		int x0, y0, x1, y1;
		x0 = y0 = x1 = y1 = 0;
		int result = stbtt_GetGlyphBox((stbtt_fontinfo*)info, glyphIndex, &x0, &y0, &x1, &y1);
		box[0] = x0;
		box[1] = y0;
		box[2] = x1;
		box[3] = y1;
		return result;
	
}
コード例 #3
0
ファイル: stb_unicode.c プロジェクト: diablodiab/RetroArch
static uint32_t font_renderer_stb_unicode_update_atlas(
      stb_unicode_font_renderer_t *self, uint32_t charcode)
{
   int advance_width, left_side_bearing;
   int id, glyph_index, offset_x, offset_y;
   struct font_glyph *glyph = NULL;
   uint8_t *dst             = NULL;
   int x0                   = 0;
   int y1                   = 0;

   if(charcode > 0xFFFF)
      return 0;

   if(self->uc_to_id[charcode])
      return self->uc_to_id[charcode];

   id                       = font_renderer_stb_unicode_get_slot(self);
   self->id_to_uc[id]       = charcode;
   self->uc_to_id[charcode] = id;
   self->atlas.dirty        = true;

   glyph                    = &self->glyphs[id];

   glyph_index              = stbtt_FindGlyphIndex(&self->info, charcode);

   offset_x                 = (id % 16) * self->max_glyph_width;
   offset_y                 = (id / 16) * self->max_glyph_height;

   dst                      = self->atlas.buffer + offset_x + offset_y 
      * self->atlas.width;

   stbtt_MakeGlyphBitmap(&self->info, dst, self->max_glyph_width, self->max_glyph_height,
         self->atlas.width, self->scale_factor, self->scale_factor, glyph_index);

   stbtt_GetGlyphHMetrics(&self->info, glyph_index, &advance_width, &left_side_bearing);
   stbtt_GetGlyphBox(&self->info, glyph_index, &x0, NULL, NULL, &y1);

   glyph->advance_x      = advance_width * self->scale_factor;
   glyph->atlas_offset_x = offset_x;
   glyph->atlas_offset_y = offset_y;
   glyph->draw_offset_x  = x0 * self->scale_factor;
   glyph->draw_offset_y  = - y1 * self->scale_factor;
   glyph->width          = self->max_glyph_width;
   glyph->height         = self->max_glyph_height;

   return id;
}