#if QT_VERSION >= 0x050100
#include <QtMath>
#else
-#define qDegreesToRadians(degree) (degree * (M_PI / 180))
+#define qDegreesToRadians(degree) (degree) * (M_PI / 180)
#endif
using namespace std;
#endif
-#if QT_VERSION < 0x050000
-inline uint qHash(double key)
-{
- return qHash(QByteArray(reinterpret_cast<char const *>(&key), sizeof(key)));
-}
-#endif
-
-
namespace std {
/*
int const breakstr_cache_max_cost = 10 * 1024 * 1024;
// Qt 5.x already has its own caching of QTextLayout objects
// but it does not seem to work well on MacOS X.
-#if (QT_VERSION < 0x050000) || defined(Q_OS_MAC)
+#if defined(Q_OS_MAC)
+// For some reason, the built-in cache of QTextLayout does not work or
+// exist on macOS.
// Limit qtextlayout_cache_ size to 500 elements (we do not know the
// size of the QTextLayout objects anyway).
int const qtextlayout_cache_max_size = 500;
GuiFontMetrics::GuiFontMetrics(QFont const & font)
- : font_(font), metrics_(font, 0),
+ : font_(font), metrics_(font, 0), xheight_(metrics_.xHeight()),
strwidth_cache_(strwidth_cache_max_cost),
breakstr_cache_(breakstr_cache_max_cost),
qtextlayout_cache_(qtextlayout_cache_max_size)
slope_ = defaultSlope;
LYXERR(Debug::FONT, "Italic slope: " << slope_);
}
- // If those characters have a non-zero width, we need to avoid them.
- // This happens with Qt4 with monospace fonts
- needs_naked_ = width(QString() + QChar(0x2060) + QChar(0x202d) + QChar(0x202e)) > 0;
- // if (needs_naked_)
- // LYXERR0("Font " << font.family() << " needs naked text layouts!");
}
int GuiFontMetrics::xHeight() const
{
// LATTEST(metrics_.xHeight() == ascent('x'));
- return metrics_.xHeight();
+ return xheight_;
}
return *wid_p;
PROFILE_CACHE_MISS(width);
/* Several problems have to be taken into account:
- * * QFontMetrics::width does not returns a wrong value with Qt5 with
+ * * QFontMetrics::width returns a wrong value with Qt5 with
* some arabic text, since the glyph-shaping operations are not
* done (documented in Qt5).
* * QTextLayout is broken for single characters with null width
*/
int w = 0;
// is the string a single character from a math font ?
-#if QT_VERSION >= 0x040800
bool const math_char = s.length() == 1 && font_.styleName() == "LyX";
-#else
- bool const math_char = s.length() == 1;
-#endif
if (math_char) {
QString const qs = toqstr(s);
int br_width = metrics_.boundingRect(qs).width();
/// Create the helper
/// \c s is the original string
/// \c isrtl is true if the string is right-to-left
- /// \c naked is true to disable the insertion of zero width annotations
- /// FIXME: remove \c naked argument when Qt4 support goes away.
- TextLayoutHelper(docstring const & s, bool isrtl, bool naked = false);
+ TextLayoutHelper(docstring const & s, bool isrtl);
/// translate QString index to docstring index
docstring::size_type qpos2pos(int qpos) const
};
-TextLayoutHelper::TextLayoutHelper(docstring const & s, bool isrtl, bool naked)
+TextLayoutHelper::TextLayoutHelper(docstring const & s, bool isrtl)
: docstr(s), rtl(isrtl)
{
// Reserve memory for performance purpose
*/
// Unicode character WORD JOINER
QChar const word_joiner(0x2060);
- if (!naked)
- qstr += word_joiner;
+ qstr += word_joiner;
#ifdef BIDI_USE_OVERRIDE
/* Unicode override characters enforce drawing direction
* Source: http://www.iamcal.com/understanding-bidirectional-text/
* Left-to-right override is 0x202d and right-to-left override is 0x202e.
*/
- if (!naked)
- qstr += QChar(rtl ? 0x202e : 0x202d);
+ qstr += QChar(rtl ? 0x202e : 0x202d);
#endif
// Now translate the string character-by-character.
for (char_type const c : s) {
// insert a word joiner character between consecutive spaces
bool const is_space = isSpace(c);
- if (!naked && is_space && was_space)
+ if (is_space && was_space)
qstr += word_joiner;
was_space = is_space;
// Remember the QString index at this point
}
// Final word joiner (see above)
- if (!naked)
- qstr += word_joiner;
+ qstr += word_joiner;
// Add virtual position at the end of the string
pos2qpos_.push_back(qstr.size());
if (auto ptl = qtextlayout_cache_[key])
return ptl;
PROFILE_CACHE_MISS(getTextLayout);
- TextLayoutHelper tlh(s, rtl, needs_naked_);
+ TextLayoutHelper tlh(s, rtl);
auto const ptl = getTextLayout_helper(tlh, wordspacing, font_);
qtextlayout_cache_.insert(key, ptl);
return ptl;
int GuiFontMetrics::pos2x(docstring const & s, int pos, bool const rtl,
double const wordspacing) const
{
- TextLayoutHelper tlh(s, rtl, needs_naked_);
+ TextLayoutHelper tlh(s, rtl);
auto ptl = getTextLayout(tlh, wordspacing);
// pos can be negative, see #10506.
int const qpos = tlh.pos2qpos(max(pos, 0));
int GuiFontMetrics::x2pos(docstring const & s, int & x, bool const rtl,
double const wordspacing) const
{
- TextLayoutHelper tlh(s, rtl, needs_naked_);
+ TextLayoutHelper tlh(s, rtl);
auto ptl = getTextLayout(tlh, wordspacing);
QTextLine const & tline = ptl->lineForTextPosition(0);
int qpos = tline.xToCursor(x);
GuiFontMetrics::breakString_helper(docstring const & s, int first_wid, int wid,
bool rtl, bool force) const
{
- TextLayoutHelper const tlh(s, rtl, needs_naked_);
+ TextLayoutHelper const tlh(s, rtl);
QTextLayout tl;
#ifdef BIDI_USE_FLAG