fix bounding box
This commit is contained in:
parent
840dbce493
commit
95527561d0
1 changed files with 69 additions and 24 deletions
|
@ -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;
|
||||||
int n_wraps = wrapBoundingBoxes(bbs,
|
if(layer->getProps().width > 0){
|
||||||
layer->getVariationText(),
|
int n_wraps = wrapBoundingBoxes(bbs,
|
||||||
layer->getProps().width,
|
layer->getVariationText(),
|
||||||
lineHeight);
|
layer->getProps().width,
|
||||||
//if(ofGetFrameNum() % 600 == 0){
|
lineHeight);
|
||||||
//cout
|
float min_x = FLT_MAX;
|
||||||
//<< "n_wraps: " << ofToString(n_wraps) << endl
|
float min_y = FLT_MAX;
|
||||||
//<< "layer->getProps().width: " << ofToString(layer->getProps().width) << endl
|
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;
|
||||||
|
|
||||||
//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;
|
||||||
int n_wraps = wrapBoundingBoxes(bbs,
|
if(layer->getProps().width > 0){
|
||||||
layer->getVariationText(),
|
int n_wraps = wrapBoundingBoxes(bbs,
|
||||||
layer->getProps().width,
|
layer->getVariationText(),
|
||||||
lineHeight);
|
layer->getProps().width,
|
||||||
//if(ofGetFrameNum() % 600 == 0){
|
lineHeight);
|
||||||
//cout
|
// could be optimized by:
|
||||||
//<< "n_wraps: " << ofToString(n_wraps) << endl
|
// - min_x = bbs[0].p0.x
|
||||||
//<< "layer->getProps().width: " << ofToString(layer->getProps().width) << endl
|
// - max_x = min_x + layer->getProps().width
|
||||||
//;
|
// - min_y = bbs[0].p0.y
|
||||||
//}
|
// - max_y = lineHeight * (n_wraps + 1)
|
||||||
//bb.p2.y += n_wraps * lineHeight;
|
float min_x = FLT_MAX;
|
||||||
//bb.p3.y += n_wraps * lineHeight;
|
float min_y = FLT_MAX;
|
||||||
|
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;
|
||||||
//}
|
//}
|
||||||
|
|
Loading…
Reference in a new issue