I played around with this a little and I'm not sure what the exact issue is, but there are two things that kind of stuck out at me.
The first is that for a character size of 50, the glyph returned for a capital 'S' was 36 pixels in height. That's a difference of 14 pixels. Not coincidentally, that's the "top" value I got if I inspected the local bounding box for the text. Because there are no vertices in that area at the top of the glyph, the bounding box returned by the VertexArray isn't what I would normally expect in a local bounding box, which is what sf::Text returns when asked for one. A simple fix library-wise might be to have sf::Text::setPosition() and sf::Text::getPosition() account for the offset automatically.
Anyway, the long and short of it is that you need to apply an offset to counter the empty vertical space in the glyph.
Following is code which illustrates the issue (build as a console app to see the bounding box output:)
#include <SFML/Graphics.hpp>
#include <iostream>
#include <cmath>
void print(const sf::FloatRect & rect)
{
std::cout << '{' << rect.left << ", " << rect.top << ", " << rect.width << ", " << rect.height << "}\n" ;
}
int main()
{
sf::VideoMode vMode(800, 600) ;
sf::RenderWindow window(vMode, "Blocks", sf::Style::Close);
sf::Font font;
if(!font.loadFromFile("sketchflow.ttf")){return 1;};
sf::Vector2f center( floor(window.getSize().x / 2.0f), floor(window.getSize().y / 2.0f)) ;
sf::Text text(sf::String("Text"),font);
sf::FloatRect textBounds = text.getLocalBounds() ;
// offset the text position. text.setPosition(center) won't work correctly!
text.setPosition(center.x-textBounds.left, center.y-textBounds.top) ;
print(textBounds) ;
sf::RectangleShape textRec(sf::Vector2f(textBounds.width, textBounds.height)) ;
textRec.setPosition(center) ;
textRec.setFillColor(sf::Color(0, 127, 63)) ;
sf::FloatRect textRecBounds = textRec.getLocalBounds() ;
print(textRecBounds) ;
while(window.isOpen())
{
sf::Event event ;
if(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
window.clear( sf::Color(63,0, 63) ) ;
window.draw(textRec) ;
window.draw(text) ;
window.display() ;
}
}
The console output I get when i run this:
{-1, 8, 61, 25}
{0, 0, 61, 25}