[Plib-users] Bugreport: fntTexFont::getBBox produces wrong size if spaces are present in string
Brought to you by:
sjbaker
From: Jan Schaefer(local) <ta...@gm...> - 2005-06-26 15:22:02
|
(I sent this message twice, because it didn't appear in the archives after the first time, propably because I used an email-address which isn't subsribed to plib-users. I hope it doesn't appear twice.) Hello PLIB-developers, I'm experiencing some strange behaviour from fntTexFont::getBBox. Actually I'm using PUI to draw a GUI and try to layout the width of a frame according to the width of a string. I put the string into puFont::getStringWidth to determine the width. If the string doesn't contain any newlines, everything works fine. But if any number of newlines is present, and any of the lines but the first contain spaces, the width is calculated to large. The effect seems to be somehow proportional to the number of spaces present. I wrote a small example program to eliminate as many other influences as possible, you can find it below. It would be really nice if you could have a look at it, maybe I'm just doing something wrong. The Helvetica.txf file used for the fntTexFont is taken from the plib_examples-1.8.4.tar.gz. The program outputs the results of getBBox twice. The right value differs, even though the string contains exactly the same lines, just in a different order. I already had a look at fntTexFont::getBBox, but couldn't find a mistake. #include <stdlib.h> #include <stdio.h> #include <string> #include <iostream> #include <GL/glut.h> #include <plib/pu.h> #include <plib/fnt.h> int window; puFrame* frame = 0; puText* text = 0; fntTexFont* texFnt = 0; puFont* font = 0; std::string str = ""; void displayFunc(void) { glClear(GL_COLOR_BUFFER_BIT); puDisplay(); glutSwapBuffers(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(640, 480); glutInitWindowPosition(0, 0); window = glutCreateWindow(argv[0]); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor (0.0, 0.0, 0.0, 0.0); glEnable(GL_BLEND); glutIdleFunc(displayFunc); glutDisplayFunc(displayFunc); puInit(); str = "123456789012345678901234567890\n1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 \n123456789012345678901234567890"; frame = new puFrame(0,0,0,0); text = new puText(0,0); texFnt = new fntTexFont(); if(!texFnt->load(std::string("Helvetica.txf").c_str())) { std::cout << "Error loading font file Helvetica.txf" << std::endl; exit(0); } float l = 0; float r = 0; float t = 0; float b = 0; texFnt->getBBox(str.c_str(), 18, 0.0f, &l, &r, &b, &t); std::cout << "1. BBox: " << l << ", " << b << ", " << r << ", " << t << std::endl; str = "1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 \n123456789012345678901234567890\n123456789012345678901234567890"; texFnt->getBBox(str.c_str(), 18, 0.0f, &l, &r, &b, &t); std::cout << "2. BBox: " << l << ", " << b << ", " << r << ", " << t << std::endl; font = new puFont(texFnt, 18, 0.0f); text->setLabelFont(*font); text->setLabel(str.c_str()); text->setColor(PUCOL_LABEL, 0.0f, 0.0f, 0.0f, 1.0f); text->setPosition(0, font->getStringHeight(str.c_str()) + font->getStringDescender() - font->getStringHeight()); frame->setSize(font->getStringWidth(str.c_str()), font->getStringHeight(str.c_str()) + font->getStringDescender()); frame->setStyle(PUSTYLE_BOXED); frame->setColor(PUCOL_FOREGROUND, 1.0f, 1.0f, 1.0f, 1.0f); frame->setColor(PUCOL_HIGHLIGHT, 1.0f, 1.0f, 1.0f, 1.0f); frame->setColor(PUCOL_BACKGROUND, 0.8f, 0.8f, 0.8f, 1.0f); // run GLUT glutMainLoop(); puDeleteObject(text); puDeleteObject(frame); delete font; delete texFnt; glutDestroyWindow(window); return 1; } |