mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
publish textglyph interfaces to make it easier for people to implement their own font rendering algorithm
This commit is contained in:
parent
340169c80c
commit
1286264952
@ -539,6 +539,7 @@ make_glyph(int character, FT_Face face, int glyph_index) {
|
||||
render_polygon_contours(glyph, true, true);
|
||||
return glyph;
|
||||
|
||||
case RM_texture:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -610,7 +611,7 @@ make_glyph(int character, FT_Face face, int glyph_index) {
|
||||
copy_pnmimage_to_texture(reduced, glyph);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
glyph->make_geom((int)floor(slot->bitmap_top + outline * _scale_factor + 0.5f),
|
||||
(int)floor(slot->bitmap_left - outline * _scale_factor + 0.5f),
|
||||
advance, _poly_margin,
|
||||
|
@ -26,7 +26,9 @@ DynamicTextGlyph(int character, DynamicTextPage *page, int x, int y,
|
||||
_page(page),
|
||||
_x(x), _y(y),
|
||||
_x_size(x_size), _y_size(y_size),
|
||||
_margin(margin)
|
||||
_margin(margin),
|
||||
_top(0), _left(0), _bottom(0), _right(0),
|
||||
_uv_top(0), _uv_left(0), _uv_bottom(0), _uv_right(0)
|
||||
{
|
||||
_geom_count = 0;
|
||||
}
|
||||
@ -74,7 +76,7 @@ operator = (const DynamicTextGlyph &) {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DynamicTextGlyph::intersects
|
||||
// Access: Public
|
||||
// Access: Published
|
||||
// Description: Returns true if the particular position this glyph
|
||||
// has been assigned to overlaps the rectangle whose
|
||||
// top left corner is at x, y and whose size is given by
|
||||
@ -91,3 +93,91 @@ intersects(int x, int y, int x_size, int y_size) const {
|
||||
return !(x >= mright || hright <= _x ||
|
||||
y >= mbot || hbot <= _y);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DynamicTextGlyph::get_top
|
||||
// Access: Published
|
||||
// Description: Returns the vertex coordinates that can be used when
|
||||
// creating a custom text renderer.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat DynamicTextGlyph::
|
||||
get_top() const {
|
||||
return _top;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DynamicTextGlyph::get_left
|
||||
// Access: Published
|
||||
// Description: Returns the vertex coordinates that can be used when
|
||||
// creating a custom text renderer.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat DynamicTextGlyph::
|
||||
get_left() const {
|
||||
return _left;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DynamicTextGlyph::get_bottom
|
||||
// Access: Published
|
||||
// Description: Returns the vertex coordinates that can be used when
|
||||
// creating a custom text renderer.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat DynamicTextGlyph::
|
||||
get_bottom() const {
|
||||
return _bottom;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DynamicTextGlyph::get_right
|
||||
// Access: Published
|
||||
// Description: Returns the vertex coordinates that can be used when
|
||||
// creating a custom text renderer.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat DynamicTextGlyph::
|
||||
get_right() const {
|
||||
return _right;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DynamicTextGlyph::get_uv_top
|
||||
// Access: Published
|
||||
// Description: Returns the UV coordinates that can be used when
|
||||
// creating a custom text renderer.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat DynamicTextGlyph::
|
||||
get_uv_top() const {
|
||||
return _uv_top;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DynamicTextGlyph::get_uv_left
|
||||
// Access: Published
|
||||
// Description: Returns the UV coordinates that can be used when
|
||||
// creating a custom text renderer.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat DynamicTextGlyph::
|
||||
get_uv_left() const {
|
||||
return _uv_left;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DynamicTextGlyph::get_uv_bottom
|
||||
// Access: Published
|
||||
// Description: Returns the UV coordinates that can be used when
|
||||
// creating a custom text renderer.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat DynamicTextGlyph::
|
||||
get_uv_bottom() const {
|
||||
return _uv_bottom;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DynamicTextGlyph::get_uv_right
|
||||
// Access: Published
|
||||
// Description: Returns the UV coordinates that can be used when
|
||||
// creating a custom text renderer.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE PN_stdfloat DynamicTextGlyph::
|
||||
get_uv_right() const {
|
||||
return _uv_right;
|
||||
}
|
||||
|
@ -110,38 +110,42 @@ make_geom(int bitmap_top, int bitmap_left, PN_stdfloat advance, PN_stdfloat poly
|
||||
PN_stdfloat tex_poly_margin = poly_margin / tex_pixels_per_unit;
|
||||
PN_stdfloat origin_y = bitmap_top / font_pixels_per_unit;
|
||||
PN_stdfloat origin_x = bitmap_left / font_pixels_per_unit;
|
||||
PN_stdfloat top = origin_y + tex_poly_margin;
|
||||
PN_stdfloat left = origin_x - tex_poly_margin;
|
||||
PN_stdfloat bottom = origin_y - tex_y_size / tex_pixels_per_unit - tex_poly_margin;
|
||||
PN_stdfloat right = origin_x + tex_x_size / tex_pixels_per_unit + tex_poly_margin;
|
||||
_top = origin_y + tex_poly_margin;
|
||||
_left = origin_x - tex_poly_margin;
|
||||
_bottom = origin_y - tex_y_size / tex_pixels_per_unit - tex_poly_margin;
|
||||
_right = origin_x + tex_x_size / tex_pixels_per_unit + tex_poly_margin;
|
||||
|
||||
// And the corresponding corners in UV units. We add 0.5f to center
|
||||
// the UV in the middle of its texel, to minimize roundoff errors
|
||||
// when we are close to 1-to-1 pixel size.
|
||||
PN_stdfloat uv_top = 1.0f - ((PN_stdfloat)(_y - poly_margin) + 0.5f) / _page->get_y_size();
|
||||
PN_stdfloat uv_left = ((PN_stdfloat)(_x - poly_margin) + 0.5f) / _page->get_x_size();
|
||||
PN_stdfloat uv_bottom = 1.0f - ((PN_stdfloat)(_y + poly_margin + tex_y_size) + 0.5f) / _page->get_y_size();
|
||||
PN_stdfloat uv_right = ((PN_stdfloat)(_x + poly_margin + tex_x_size) + 0.5f) / _page->get_x_size();
|
||||
_uv_top = 1.0f - ((PN_stdfloat)(_y - poly_margin) + 0.5f) / _page->get_y_size();
|
||||
_uv_left = ((PN_stdfloat)(_x - poly_margin) + 0.5f) / _page->get_x_size();
|
||||
_uv_bottom = 1.0f - ((PN_stdfloat)(_y + poly_margin + tex_y_size) + 0.5f) / _page->get_y_size();
|
||||
_uv_right = ((PN_stdfloat)(_x + poly_margin + tex_x_size) + 0.5f) / _page->get_x_size();
|
||||
|
||||
// Create a corresponding triangle pair. We use a pair of indexed
|
||||
// triangles rather than a single triangle strip, to avoid the bad
|
||||
// vertex duplication behavior with lots of two-triangle strips.
|
||||
PT(GeomVertexData) vdata = new GeomVertexData
|
||||
(string(), GeomVertexFormat::get_v3t2(),
|
||||
Geom::UH_static);
|
||||
vdata->unclean_set_num_rows(4);
|
||||
|
||||
GeomVertexWriter vertex(vdata, InternalName::get_vertex());
|
||||
GeomVertexWriter texcoord(vdata, InternalName::get_texcoord());
|
||||
|
||||
vertex.add_data3(left, 0, top);
|
||||
vertex.add_data3(left, 0, bottom);
|
||||
vertex.add_data3(right, 0, top);
|
||||
vertex.add_data3(right, 0, bottom);
|
||||
vertex.add_data3(_left, 0, _top);
|
||||
vertex.add_data3(_left, 0, _bottom);
|
||||
vertex.add_data3(_right, 0, _top);
|
||||
vertex.add_data3(_right, 0, _bottom);
|
||||
|
||||
texcoord.add_data2(uv_left, uv_top);
|
||||
texcoord.add_data2(uv_left, uv_bottom);
|
||||
texcoord.add_data2(uv_right, uv_top);
|
||||
texcoord.add_data2(uv_right, uv_bottom);
|
||||
texcoord.add_data2(_uv_left, _uv_top);
|
||||
texcoord.add_data2(_uv_left, _uv_bottom);
|
||||
texcoord.add_data2(_uv_right, _uv_top);
|
||||
texcoord.add_data2(_uv_right, _uv_bottom);
|
||||
|
||||
PT(GeomTriangles) tris = new GeomTriangles(Geom::UH_static);
|
||||
tris->reserve_num_vertices(6);
|
||||
tris->add_vertex(0);
|
||||
tris->add_vertex(1);
|
||||
tris->add_vertex(2);
|
||||
@ -167,7 +171,6 @@ make_geom(int bitmap_top, int bitmap_left, PN_stdfloat advance, PN_stdfloat poly
|
||||
_advance = advance / font_pixels_per_unit;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DynamicTextGlyph::set_geom
|
||||
// Access: Public
|
||||
@ -205,5 +208,4 @@ is_whitespace() const {
|
||||
return (_page == (DynamicTextPage *)NULL);
|
||||
}
|
||||
|
||||
|
||||
#endif // HAVE_FREETYPE
|
||||
|
@ -41,10 +41,22 @@ private:
|
||||
INLINE DynamicTextGlyph(const DynamicTextGlyph ©);
|
||||
INLINE void operator = (const DynamicTextGlyph ©);
|
||||
|
||||
public:
|
||||
PUBLISHED:
|
||||
virtual ~DynamicTextGlyph();
|
||||
|
||||
INLINE bool intersects(int x, int y, int x_size, int y_size) const;
|
||||
|
||||
INLINE PN_stdfloat get_top() const;
|
||||
INLINE PN_stdfloat get_left() const;
|
||||
INLINE PN_stdfloat get_bottom() const;
|
||||
INLINE PN_stdfloat get_right() const;
|
||||
|
||||
INLINE PN_stdfloat get_uv_top() const;
|
||||
INLINE PN_stdfloat get_uv_left() const;
|
||||
INLINE PN_stdfloat get_uv_bottom() const;
|
||||
INLINE PN_stdfloat get_uv_right() const;
|
||||
|
||||
public:
|
||||
unsigned char *get_row(int y);
|
||||
void erase(DynamicTextFont *font);
|
||||
void make_geom(int top, int left, PN_stdfloat advance, PN_stdfloat poly_margin,
|
||||
@ -60,6 +72,8 @@ public:
|
||||
int _x, _y;
|
||||
int _x_size, _y_size;
|
||||
int _margin;
|
||||
PN_stdfloat _top, _left, _bottom, _right;
|
||||
PN_stdfloat _uv_top, _uv_left, _uv_bottom, _uv_right;
|
||||
};
|
||||
|
||||
#include "dynamicTextGlyph.I"
|
||||
|
@ -76,3 +76,20 @@ INLINE void TextFont::
|
||||
set_space_advance(PN_stdfloat space_advance) {
|
||||
_space_advance = space_advance;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DynamicTextFont::get_glyph
|
||||
// Access: Public, Virtual
|
||||
// Description: Gets the glyph associated with the given character
|
||||
// code, as well as an optional scaling parameter that
|
||||
// should be applied to the glyph's geometry and advance
|
||||
// parameters. Returns the glyph on success. On failure,
|
||||
// it may still return a printable glyph, or it may
|
||||
// return NULL.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const TextGlyph *TextFont::
|
||||
get_glyph(int character) {
|
||||
const TextGlyph *glyph = NULL;
|
||||
get_glyph(character, glyph);
|
||||
return glyph;
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ PUBLISHED:
|
||||
|
||||
INLINE PN_stdfloat get_space_advance() const;
|
||||
INLINE void set_space_advance(PN_stdfloat space_advance);
|
||||
INLINE const TextGlyph *get_glyph(int character);
|
||||
|
||||
virtual void write(ostream &out, int indent_level) const;
|
||||
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
INLINE void operator = (const TextGlyph ©);
|
||||
virtual ~TextGlyph();
|
||||
|
||||
PUBLISHED:
|
||||
INLINE int get_character() const;
|
||||
INLINE PT(Geom) get_geom(Geom::UsageHint usage_hint) const;
|
||||
INLINE const RenderState *get_state() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user