openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.89k stars 2.55k forks source link

ofTrueTypeFont::getStringBoundingBox working different since 0.12 and not including \n chars? #7875

Closed moebiussurfing closed 7 months ago

moebiussurfing commented 7 months ago

Hello, I found that ofTrueTypeFont::getStringBoundingBox does not include the '\n' aka brake lines and gets the ofRectangle width taking the paragraph as a single line. but the rectangle height looks being calculated well.

So passing this string:

//--------------------------------------------------------------
void ofApp::draw() {

#if 1
    string ss = R"(
    Lorem Ipsum is simply dummy text of the printing and typesetting industry.
    Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
    when an unknown printer took a galley of type and scrambled it
    to make a type specimen book. It has survived not only five centuries,
    but also the leap into electronic typesetting,
    remaining essentially unchanged. It was popularised
    in the 1960s with the release of Letraset sheets
    containing Lorem Ipsum passages, and more recently
    with desktop publishing software like
    Aldus PageMaker including versions of Lorem Ipsum.)";
#else
    string ss = "";
    ss += "Lorem Ipsum is simply dummy text of the printing and typesetting industry. \n";
    ss += "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, \n";
    ss += "when an unknown printer took a galley of type and scrambled it \n";
    ss += "to make a type specimen book. It has survived not only five centuries, \n";
    ss += "but also the leap into electronic typesetting, \n";
    ss += "remaining essentially unchanged. It was popularised \n";
    ss += "in the 1960s with the release of Letraset sheets \n";
    ss += "containing Lorem Ipsum passages, and more recently \n";
    ss += "with desktop publishing software like \n";
    ss += "Aldus PageMaker including versions of Lorem Ipsum.";
#endif

    x = 1;
    y = 1;

    ofRectangle _r;
    _r = (myFont.getStringBoundingBox(ss, x, y));
    cout << _r.x << ", ";
    cout << _r.y << ", ";
    cout << _r.getWidth() << ", ";
    cout << _r.getHeight();
    cout << endl;

    ofPushStyle();
    ofSetColor(ofColor::red);
    ofNoFill();
    ofDrawRectangle(_r);
    ofPopStyle();

    myFont.drawString(ss, x, y);

    //ofxSurfingHelpers::drawTextBoxed(myFont, ss, x, y);
}

Is getting as output into the console: 1, 1, 5650, 214.2

Both modes when #if 0 or 1, show similar results...

image

dimitre commented 7 months ago

Are you using a version after or before this specific PR?

moebiussurfing commented 7 months ago

thanks @dimitre I was synced one month ago. now I did a pull and updated libs. it works as expected. ps: I saw this error appearing some time ago but I was not sure.

moebiussurfing commented 7 months ago

PS: myFont.drawString(ss, x, y); takes the 0,0 anchor point from the base of the font, Is there a method/way to draw the text from the top left corner as the anchor reference? if not, we just need to add the font size/height to y if we prefer this behaviour...