mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
calc_width
This commit is contained in:
parent
ca5f030cc1
commit
96dbda26ba
@ -137,3 +137,16 @@ generate_into(const string &text, PNMImage &dest_image, int x, int y) {
|
||||
encoder.set_text(text);
|
||||
return generate_into(encoder.get_wtext(), dest_image, x, y);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMTextMaker::calc_width
|
||||
// Access: Public
|
||||
// Description: Returns the width in pixels of the indicated line of
|
||||
// text.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int PNMTextMaker::
|
||||
calc_width(const string &text) {
|
||||
TextEncoder encoder;
|
||||
encoder.set_text(text);
|
||||
return calc_width(encoder.get_wtext());
|
||||
}
|
||||
|
@ -63,13 +63,7 @@ PNMTextMaker::
|
||||
int PNMTextMaker::
|
||||
generate_into(const wstring &text, PNMImage &dest_image, int x, int y) {
|
||||
// First, measure the total width in pixels.
|
||||
int width = 0;
|
||||
wstring::const_iterator ti;
|
||||
for (ti = text.begin(); ti != text.end(); ++ti) {
|
||||
int ch = (*ti);
|
||||
PNMTextGlyph *glyph = get_glyph(ch);
|
||||
width += glyph->get_advance();
|
||||
}
|
||||
int width = calc_width(text);
|
||||
|
||||
int xp = x;
|
||||
int yp = y;
|
||||
@ -89,6 +83,7 @@ generate_into(const wstring &text, PNMImage &dest_image, int x, int y) {
|
||||
}
|
||||
|
||||
// Now place the text.
|
||||
wstring::const_iterator ti;
|
||||
for (ti = text.begin(); ti != text.end(); ++ti) {
|
||||
int ch = (*ti);
|
||||
PNMTextGlyph *glyph = get_glyph(ch);
|
||||
@ -103,6 +98,24 @@ generate_into(const wstring &text, PNMImage &dest_image, int x, int y) {
|
||||
return width;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMTextMaker::calc_width
|
||||
// Access: Public
|
||||
// Description: Returns the width in pixels of the indicated line of
|
||||
// text.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int PNMTextMaker::
|
||||
calc_width(const wstring &text) {
|
||||
int width = 0;
|
||||
wstring::const_iterator ti;
|
||||
for (ti = text.begin(); ti != text.end(); ++ti) {
|
||||
int ch = (*ti);
|
||||
PNMTextGlyph *glyph = get_glyph(ch);
|
||||
width += glyph->get_advance();
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PNMTextMaker::get_glyph
|
||||
// Access: Public
|
||||
|
@ -66,6 +66,8 @@ PUBLISHED:
|
||||
PNMImage &dest_image, int x, int y);
|
||||
int generate_into(const wstring &text,
|
||||
PNMImage &dest_image, int x, int y);
|
||||
INLINE int calc_width(const string &text);
|
||||
int calc_width(const wstring &text);
|
||||
|
||||
PNMTextGlyph *get_glyph(int character);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user