mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
text: Error instead of crash when glyph does not fit into page
Fixes #1626
This commit is contained in:
parent
8ea2301d16
commit
237d27dfd9
@ -621,6 +621,9 @@ make_glyph(int character, FT_Face face, int glyph_index) {
|
|||||||
render_distance_field(image, outline, bounds.xMin, bounds.yMin);
|
render_distance_field(image, outline, bounds.xMin, bounds.yMin);
|
||||||
|
|
||||||
glyph = slot_glyph(character, int_x_size, int_y_size, advance);
|
glyph = slot_glyph(character, int_x_size, int_y_size, advance);
|
||||||
|
if (glyph == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
if (!_needs_image_processing) {
|
if (!_needs_image_processing) {
|
||||||
copy_pnmimage_to_texture(image, glyph);
|
copy_pnmimage_to_texture(image, glyph);
|
||||||
} else {
|
} else {
|
||||||
@ -633,6 +636,9 @@ make_glyph(int character, FT_Face face, int glyph_index) {
|
|||||||
// other processing before it goes to the texture, we can just copy it
|
// other processing before it goes to the texture, we can just copy it
|
||||||
// directly into the texture.
|
// directly into the texture.
|
||||||
glyph = slot_glyph(character, bitmap.width, bitmap.rows, advance);
|
glyph = slot_glyph(character, bitmap.width, bitmap.rows, advance);
|
||||||
|
if (glyph == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
copy_bitmap_to_texture(bitmap, glyph);
|
copy_bitmap_to_texture(bitmap, glyph);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -660,6 +666,9 @@ make_glyph(int character, FT_Face face, int glyph_index) {
|
|||||||
tex_x_size += outline * 2;
|
tex_x_size += outline * 2;
|
||||||
tex_y_size += outline * 2;
|
tex_y_size += outline * 2;
|
||||||
glyph = slot_glyph(character, int_x_size, int_y_size, advance);
|
glyph = slot_glyph(character, int_x_size, int_y_size, advance);
|
||||||
|
if (glyph == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (outline != 0) {
|
if (outline != 0) {
|
||||||
// Pad the glyph image to make room for the outline.
|
// Pad the glyph image to make room for the outline.
|
||||||
@ -940,10 +949,7 @@ slot_glyph(int character, int x_size, int y_size, PN_stdfloat advance) {
|
|||||||
|
|
||||||
if (page->is_empty()) {
|
if (page->is_empty()) {
|
||||||
// If we couldn't even put it on an empty page, we're screwed.
|
// If we couldn't even put it on an empty page, we're screwed.
|
||||||
text_cat.error()
|
goto does_not_fit;
|
||||||
<< "Glyph of size " << x_size << " by " << y_size
|
|
||||||
<< " pixels won't fit on an empty page.\n";
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pi = (pi + 1) % _pages.size();
|
pi = (pi + 1) % _pages.size();
|
||||||
@ -954,15 +960,27 @@ slot_glyph(int character, int x_size, int y_size, PN_stdfloat advance) {
|
|||||||
if (garbage_collect() != 0) {
|
if (garbage_collect() != 0) {
|
||||||
// Yes, we just freed up some space. Try once more, recursively.
|
// Yes, we just freed up some space. Try once more, recursively.
|
||||||
return slot_glyph(character, x_size, y_size, advance);
|
return slot_glyph(character, x_size, y_size, advance);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
// No good; all recorded glyphs are actually in use. We need to make a new
|
||||||
// No good; all recorded glyphs are actually in use. We need to make a
|
// page.
|
||||||
// new page.
|
{
|
||||||
_preferred_page = _pages.size();
|
_preferred_page = _pages.size();
|
||||||
PT(DynamicTextPage) page = new DynamicTextPage(this, _preferred_page);
|
PT(DynamicTextPage) page = new DynamicTextPage(this, _preferred_page);
|
||||||
_pages.push_back(page);
|
_pages.push_back(page);
|
||||||
return page->slot_glyph(character, x_size, y_size, _texture_margin, advance);
|
|
||||||
|
DynamicTextGlyph *glyph = page->slot_glyph(character, x_size, y_size, _texture_margin, advance);
|
||||||
|
if (glyph != nullptr) {
|
||||||
|
return glyph;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
does_not_fit:
|
||||||
|
// If you get this error, increase text-page-size in Config.prc.
|
||||||
|
text_cat.error()
|
||||||
|
<< "Glyph of size " << x_size << " by " << y_size
|
||||||
|
<< " pixels won't fit on an empty page.\n";
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user