u8glib getStrPixelWidth confusion

I'm trying to lay out a graphic display and it would be easier if I could determine ahead of time how many pixels a string would occupy, so I can select a display size, but having been unable to find that info for fonts I might use, I wrote a small sketch using getStrPixelWidth, but the results are nonsensical. I haven't found an example of this, so I'm probably just doing something wrong. Any advice?

Result of the attached code is:
debug mode
70
iiiiiiiiii78
WWWWWWWWWW22
WiWiWiWiWi178

#include "U8glib.h"
U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE);

const char* tenspaces = "          ";
const char teni[] = "iiiiiiiiii";
const char tenW[] = "WWWWWWWWWW";
const char fiveWi[] = "WiWiWiWiWi";

void setup() {
  u8g.setFont(u8g_font_osr18);
  Serial.begin(9600);
  delay(2000);
  Serial.println("");
  Serial.println("debug mode");
  u8g.setFont(u8g_font_osr18);
  Serial.print(tenspaces);
  Serial.println(u8g.getStrPixelWidth(tenspaces));      
  Serial.print(teni);
  Serial.println(u8g.getStrPixelWidth(teni));      
  Serial.print(tenW);
  Serial.println(u8g.getStrPixelWidth(tenW));      
  Serial.print(fiveWi);
  Serial.println(u8g.getStrPixelWidth(fiveWi));      
}

void loop() {
}

I suspect that you are seeing a uint8_t for the width i.e. it probably means 22 + 256 = 278 for tenW

Try fiveW

debug mode
          70
iiiiiiiiii78
WWWWWWWWWW22
WiWiWiWiWi178
WWWWW138

No, I have not checked the Wiki. U8g is no longer supported. Oliver advises using U8g2

David.

Thank you. Problem solved. All I had to do is add "#define U8G_16BIT" to U8glib.h and it now works. I tried putting that just in my sketch and it didn't help. I'm not very comfortable modifying the library source, but if that's what it takes...

I am using this library rather than U8g2 just because some of the display manufacturer (Digole) code says it supports the former and doesn't mention the the latter. I'll give it a try after I get the display going to see if the display is forward compatible. I haven't found much documentation for either.

-Joe

I think u8g2 supports most if not all displays u8glib. So probably only reason to not mention u8g2 is that the documentation is old.

So what is the screen you have?