Browse Source

generate_into() now returns the width

David Rose 22 years ago
parent
commit
1573ff1f73

+ 5 - 4
panda/src/pnmtext/pnmTextMaker.I

@@ -131,12 +131,13 @@ get_interior() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: PNMTextMaker::generate_into
 //       Access: Public
-//  Description: Generates text into the indicated image at the
-//               indicated position.
+//  Description: Generates a single line of text into the indicated
+//               image at the indicated position; the return value is
+//               the total width in pixels.
 ////////////////////////////////////////////////////////////////////
-INLINE void PNMTextMaker::
+INLINE int PNMTextMaker::
 generate_into(const string &text, PNMImage &dest_image, int x, int y) {
   TextEncoder encoder;
   encoder.set_text(text);
-  generate_into(encoder.get_wtext(), dest_image, x, y);
+  return generate_into(encoder.get_wtext(), dest_image, x, y);
 }

+ 6 - 3
panda/src/pnmtext/pnmTextMaker.cxx

@@ -60,10 +60,11 @@ PNMTextMaker::
 ////////////////////////////////////////////////////////////////////
 //     Function: PNMTextMaker::generate_into
 //       Access: Public
-//  Description: Generates text into the indicated image at the
-//               indicated position.
+//  Description: Generates a single line of text into the indicated
+//               image at the indicated position; the return value is
+//               the total width in pixels.
 ////////////////////////////////////////////////////////////////////
-void 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;
@@ -102,6 +103,8 @@ generate_into(const wstring &text, PNMImage &dest_image, int x, int y) {
     }
     xp += glyph->get_advance();
   }
+
+  return width;
 }
 
 ////////////////////////////////////////////////////////////////////

+ 4 - 4
panda/src/pnmtext/pnmTextMaker.h

@@ -66,10 +66,10 @@ public:
   INLINE void set_interior(const Colorf &interior);
   INLINE const Colorf &get_interior() const;
 
-  INLINE void generate_into(const string &text,
-                            PNMImage &dest_image, int x, int y);
-  void generate_into(const wstring &text,
-                     PNMImage &dest_image, int x, int y);
+  INLINE int generate_into(const string &text,
+                           PNMImage &dest_image, int x, int y);
+  int generate_into(const wstring &text,
+                    PNMImage &dest_image, int x, int y);
 
   PNMTextGlyph *get_glyph(int character);