int generic_pgf_draw_text(vita2d_pgf *font, int draw, int *height, int x, int y, unsigned int color, float scale, const char *text) { unsigned int character; bp2d_rectangle rect; texture_atlas_entry_data data; vita2d_texture *tex = font->atlas->texture; int start_x = x; int max_x = 0; int pen_x = x; int pen_y = y; while (*text) { character = utf8_character(&text); if (character == '\n') { if (pen_x > max_x) max_x = pen_x; pen_x = start_x; pen_y += font->vsize * scale; continue; } if (!texture_atlas_get(font->atlas, character, &rect, &data)) { if (!atlas_add_glyph(font, character)) { continue; } if (!texture_atlas_get(font->atlas, character, &rect, &data)) continue; } if (draw) { vita2d_draw_texture_tint_part_scale(tex, pen_x + data.bitmap_left * scale, pen_y - data.bitmap_top * scale, rect.x, rect.y, rect.w, rect.h, scale, scale, color); } pen_x += (data.advance_x >> 6) * scale; } if (pen_x > max_x) max_x = pen_x; if (height) *height = pen_y + font->vsize * scale - y; return max_x - x; }
void vita2d_font_draw_text(vita2d_font *font, int x, int y, unsigned int color, unsigned int size, const char *text) { FTC_FaceID face_id = (FTC_FaceID)font; FT_Face face; FTC_Manager_LookupFace(font->ftcmanager, face_id, &face); FT_Int charmap_index; charmap_index = FT_Get_Charmap_Index(face->charmap); FT_Glyph glyph; FT_Bool use_kerning = FT_HAS_KERNING(face); FT_UInt glyph_index, previous = 0; int pen_x = x; int pen_y = y + size; FTC_ScalerRec scaler; scaler.face_id = face_id; scaler.width = size; scaler.height = size; scaler.pixel = 1; FT_ULong flags = FT_LOAD_RENDER | FT_LOAD_TARGET_NORMAL; while (*text) { glyph_index = FTC_CMapCache_Lookup(font->cmapcache, (FTC_FaceID)font, charmap_index, *text); if (use_kerning && previous && glyph_index) { FT_Vector delta; FT_Get_Kerning(face, previous, glyph_index, FT_KERNING_DEFAULT, &delta); pen_x += delta.x >> 6; } if (!texture_atlas_exists(font->tex_atlas, glyph_index)) { FTC_ImageCache_LookupScaler(font->imagecache, &scaler, flags, glyph_index, &glyph, NULL); if (!atlas_add_glyph(font->tex_atlas, glyph_index, (FT_BitmapGlyph)glyph, size)) { continue; } } bp2d_rectangle rect; int bitmap_left, bitmap_top; int advance_x, advance_y; int glyph_size; texture_atlas_get(font->tex_atlas, glyph_index, &rect, &bitmap_left, &bitmap_top, &advance_x, &advance_y, &glyph_size); const float draw_scale = size/(float)glyph_size; vita2d_draw_texture_tint_part_scale(font->tex_atlas->tex, pen_x + bitmap_left * draw_scale, pen_y - bitmap_top * draw_scale, rect.x, rect.y, rect.w, rect.h, draw_scale, draw_scale, color); pen_x += (advance_x >> 16) * draw_scale; pen_y += (advance_y >> 16) * draw_scale; previous = glyph_index; text++; }