void StaffTypeTablature::setFretMetrics() { if(_fretMetricsValid && _refDPI == MScore::DPI) return; QFontMetricsF fm(fretFont()); // compute total height of used characters QRectF bb(fm.tightBoundingRect(_useNumbers ? g_strNumbers : g_strLetters)); // compute vertical displacement if(_useNumbers) { // for numbers: centre on '0': move down by the whole part above (negative) // the base line ( -bb.y() ) then up by half the whole height ( -bb.height()/2 ) QRectF bx( fm.tightBoundingRect("0") ); _fretYOffset = -(bx.y() + bx.height()/2.0); // _fretYOffset = -(bb.y() + bb.height()/2.0); // <- using bbox of all chars } else { // for letters: centre on the 'a' ascender, by moving down half of the part above the base line in bx QRectF bx( fm.tightBoundingRect("a") ); _fretYOffset = -bx.y() / 2.0; } // if on string, we are done; if between strings, raise by half line distance if(!_onLines) _fretYOffset -= lineDistance().val()*MScore::DPI*SPATIUM20 / 2.0; // from _fretYOffset, compute _charBoxH and _charBoxY _fretBoxH = bb.height(); _fretBoxY = bb.y() + _fretYOffset; // keep track of the conditions under which metrics have been computed _refDPI = MScore::DPI; _fretMetricsValid = true; }
void StaffTypeTablature::setFretMetrics() { if(_fretMetricsValid && _refDPI == MScore::DPI) return; QFontMetricsF fm(fretFont()); QRectF bb; // compute vertical displacement if(_useNumbers) { // compute total height of used characters QString txt = QString(); for (int idx = 0; idx < 10; idx++) // use only first 10 digits txt.append(_fretFonts[_fretFontIdx].displayDigit[idx]); bb = fm.tightBoundingRect(txt); // for numbers: centre on '0': move down by the whole part above (negative) // the base line ( -bb.y() ) then up by half the whole height ( -bb.height()/2 ) QRectF bx( fm.tightBoundingRect(_fretFonts[_fretFontIdx].displayDigit[0]) ); _fretYOffset = -(bx.y() + bx.height()/2.0); // _fretYOffset = -(bb.y() + bb.height()/2.0); // <- using bbox of all chars } else { // compute total height of used characters QString txt(_fretFonts[_fretFontIdx].displayLetter, NUM_OF_LETTERFRETS); bb = fm.tightBoundingRect(txt); // for letters: centre on the 'a' ascender, by moving down half of the part above the base line in bx QRectF bx( fm.tightBoundingRect(_fretFonts[_fretFontIdx].displayLetter[0]) ); _fretYOffset = -bx.y() / 2.0; } // if on string, we are done; if between strings, raise by half line distance if(!_onLines) _fretYOffset -= lineDistance().val()*MScore::DPI*SPATIUM20 / 2.0; // from _fretYOffset, compute _charBoxH and _charBoxY _fretBoxH = bb.height(); _fretBoxY = bb.y() + _fretYOffset; // keep track of the conditions under which metrics have been computed _refDPI = MScore::DPI; _fretMetricsValid = true; }