fix bounding box

This commit is contained in:
jrkb 2023-05-17 22:34:05 +02:00
parent 840dbce493
commit 95527561d0

View file

@ -223,18 +223,38 @@ void GPUFontAtlasLayerCombo::draw(int width, int height){
true, layer->getProps().fontSize_px, true, layer->getProps().fontSize_px,
layer->getProps().lineHeight); layer->getProps().lineHeight);
float lineHeight = font->getLineHeight(layer->getProps().fontSize_px) * layer->getProps().lineHeight; float lineHeight = font->getLineHeight(layer->getProps().fontSize_px) * layer->getProps().lineHeight;
if(layer->getProps().width > 0){
int n_wraps = wrapBoundingBoxes(bbs, int n_wraps = wrapBoundingBoxes(bbs,
layer->getVariationText(), layer->getVariationText(),
layer->getProps().width, layer->getProps().width,
lineHeight); lineHeight);
//if(ofGetFrameNum() % 600 == 0){ float min_x = FLT_MAX;
//cout float min_y = FLT_MAX;
//<< "n_wraps: " << ofToString(n_wraps) << endl float max_x = -FLT_MAX;
//<< "layer->getProps().width: " << ofToString(layer->getProps().width) << endl float max_y = -FLT_MAX;
//; for(const auto & sbb : bbs){
min_x = min(sbb.p0.x, min_x);
min_y = min(sbb.p0.y, min_y);
max_x = max(sbb.p2.x, max_x);
max_y = max(sbb.p2.y, max_y);
}
bb.p0.x = min_x;
bb.p0.y = min_y;
bb.p1.x = max_x;
bb.p1.y = min_y;
bb.p2.x = max_x;
bb.p2.y = max_y;
bb.p3.x = min_x;
bb.p3.y = max_y;
//bb.p2.y += n_wraps * lineHeight; if(ofGetFrameNum() % 600 == 0){
//bb.p3.y += n_wraps * lineHeight; cout
<< "n_wraps: " << ofToString(n_wraps) << endl
<< "layer->getProps().width: " << ofToString(layer->getProps().width) << endl
;
}
}
glm::vec4 transformOrigin; glm::vec4 transformOrigin;
getAndApplyTransformOrigin(transformOrigin, getAndApplyTransformOrigin(transformOrigin,
layer->getOuterNode(), layer->getOuterNode(),
@ -462,18 +482,43 @@ void GPUFontAtlasLayerCombo::draw(int width,
true, layer->getProps().fontSize_px, true, layer->getProps().fontSize_px,
layer->getProps().lineHeight); layer->getProps().lineHeight);
float lineHeight = font->getLineHeight(layer->getProps().fontSize_px) * layer->getProps().lineHeight; float lineHeight = font->getLineHeight(layer->getProps().fontSize_px) * layer->getProps().lineHeight;
if(layer->getProps().width > 0){
int n_wraps = wrapBoundingBoxes(bbs, int n_wraps = wrapBoundingBoxes(bbs,
layer->getVariationText(), layer->getVariationText(),
layer->getProps().width, layer->getProps().width,
lineHeight); lineHeight);
//if(ofGetFrameNum() % 600 == 0){ // could be optimized by:
//cout // - min_x = bbs[0].p0.x
//<< "n_wraps: " << ofToString(n_wraps) << endl // - max_x = min_x + layer->getProps().width
//<< "layer->getProps().width: " << ofToString(layer->getProps().width) << endl // - min_y = bbs[0].p0.y
//; // - max_y = lineHeight * (n_wraps + 1)
//} float min_x = FLT_MAX;
//bb.p2.y += n_wraps * lineHeight; float min_y = FLT_MAX;
//bb.p3.y += n_wraps * lineHeight; float max_x = -FLT_MAX;
float max_y = -FLT_MAX;
for(const auto & sbb : bbs){
min_x = min(sbb.p0.x, min_x);
min_y = min(sbb.p0.y, min_y);
max_x = max(sbb.p2.x, max_x);
max_y = max(sbb.p2.y, max_y);
}
bb.p0.x = min_x;
bb.p0.y = min_y;
bb.p1.x = max_x;
bb.p1.y = min_y;
bb.p2.x = max_x;
bb.p2.y = max_y;
bb.p3.x = min_x;
bb.p3.y = max_y;
if(ofGetFrameNum() % 600 == 0){
cout
<< "n_wraps: " << ofToString(n_wraps) << endl
<< "layer->getProps().width: " << ofToString(layer->getProps().width) << endl
;
}
}
glm::vec4 transformOrigin; glm::vec4 transformOrigin;
getAndApplyTransformOrigin(transformOrigin, getAndApplyTransformOrigin(transformOrigin,
layer->getOuterNode(), layer->getOuterNode(),
@ -720,7 +765,7 @@ int GPUFontAtlasLayerCombo::wrapBoundingBoxes(std::vector <ofxGPUFont::Font::Bou
if(variationText[vi].charcode == '-'){ if(variationText[vi].charcode == '-'){
wrapIndex = i; wrapIndex = i;
} }
float xxx = bb.p1.x - collectedWrapWidth; //float xxx = bb.p1.x - collectedWrapWidth;
//if(ofGetFrameNum() % 600 == 0){ //if(ofGetFrameNum() % 600 == 0){
//cout << "WRAP INDEX " << char(variationText[vi].charcode) << ":" << ofToString(wrapIndex) << " xxx: " << ofToString(xxx) << " cww: " << ofToString(collectedWrapWidth) << endl; //cout << "WRAP INDEX " << char(variationText[vi].charcode) << ":" << ofToString(wrapIndex) << " xxx: " << ofToString(xxx) << " cww: " << ofToString(collectedWrapWidth) << endl;
//} //}