[Kde-games-devel] Localization of in game strings
kleag at free.fr
kleag at free.fr
Mon Jul 16 08:11:42 CEST 2007
Hello,
As discussed during yesterday's meeting I report here my experiences
concerning sizing strings and placing localized strings inside the game
area.
In kgraphviewer (a graphviz dot graphs viewer), the dot tool gives dimensions
of graphs nodes and says which font to use. It can happen that the given
font will produce too large strings in QGV, larger than their containing
node. So, I do the following loop:
int stringWidthGoal = int(dro.integers[3] * m_scaleX);
int fontSize = node()->fontSize();
m_font->setPointSize(fontSize);
QFontMetrics fm(*m_font);
while (fm.width(dro.str) > stringWidthGoal && fontSize > 1)
{
fontSize--;
m_font->setPointSize(fontSize);
fm = QFontMetrics(*m_font);
}
In KsirK, the localized countries names are drawn on the map. I have currently
no real size problems but they have to be placed centered on given points.
These points are defined in the skin (theme) file and related to the default
size of the SVG map. They are finaly painted with:
const QString& countryName = i18n(country->name().toUtf8().data());
QRect countryNameRect = painter.fontMetrics().boundingRect(countryName);
painter.drawText(
int((country->centralPoint().x()*m_zoom-countryNameRect.width()/2)),
int((country->centralPoint().y()*m_zoom+countryNameRect.height()/2)),
countryName);
As you can see, a combination of the two above methods could be used to define
a bounding box in the SGV file of the theme and then force the drawing of
localized strings of the correct size inside inside this box.
Comments ?
Best regards,
Kleag
More information about the kde-games-devel
mailing list