Is there a way to get the horizonal advance of every character in a string?
-
wrote on 22 Mar 2020, 16:25 last edited by
Hi,
I'm looking for something like GetPartialTextExtents() in wxWidgets or GDI+ MeasureCharacterRanges(). Does QT have something like that? QFontMetrics doesn't seem to.
Gerald
-
What's wrong with QFontMetrics::horizontalAdvance(QChar ch) ?
-
What's wrong with QFontMetrics::horizontalAdvance(QChar ch) ?
wrote on 24 Mar 2020, 14:51 last edited by@Christian-Ehrlicher Nothing, except that I'm calling it over 600,000 times.
When I switched from individual character measuring to string measuring (getting each characters width) in wxWidgets, I got a 10x speed improvement.
Gerald
-
@GeraldBrandt said in Is there a way to get the horizonal advance of every character in a string?:
Nothing, except that I'm calling it over 600,000 times.
If you really need it then add a cache.
-
Hi
Just as a note
There is an overload that takes a QStringint horizontalAdvance(const QString &, int len = -1) const;
However, if that is faster then looping the string your self and call the QChar version i don't know.
-
Hi
Just as a note
There is an overload that takes a QStringint horizontalAdvance(const QString &, int len = -1) const;
However, if that is faster then looping the string your self and call the QChar version i don't know.
wrote on 24 Mar 2020, 15:43 last edited byActually, 100% my fault. Things are plenty fast. I had an extra call to size() in my method that I didn't need, and that is a slow call.
Thanks,
Gerald
5/6