}
-namespace {
-
// This holds a translation table between the original string and the
// QString that we can use with QTextLayout.
struct TextLayoutHelper
//LYXERR0("TLH: " << dump.replace(word_joiner, "|").toStdString());
}
-}
-shared_ptr<QTextLayout const>
-GuiFontMetrics::getTextLayout(docstring const & s, bool const rtl,
- double const wordspacing) const
+namespace {
+
+shared_ptr<QTextLayout>
+getTextLayout_helper(TextLayoutHelper const & tlh, double const wordspacing,
+ QFont font)
{
- PROFILE_THIS_BLOCK(getTextLayout);
- TextLayoutKey key{s, rtl, wordspacing};
- if (auto ptl = qtextlayout_cache_[key])
- return ptl;
- PROFILE_CACHE_MISS(getTextLayout);
auto const ptl = make_shared<QTextLayout>();
ptl->setCacheEnabled(true);
- QFont copy = font_;
- copy.setWordSpacing(wordspacing);
- ptl->setFont(copy);
-
+ font.setWordSpacing(wordspacing);
+ ptl->setFont(font);
#ifdef BIDI_USE_FLAG
/* Use undocumented flag to enforce drawing direction
* FIXME: This does not work with Qt 5.11 (ticket #11284).
*/
- ptl->setFlags(rtl ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight);
-#endif
-
-#ifdef BIDI_USE_OVERRIDE
- ptl->setText(bidi_override[rtl] + toqstr(s));
-#else
- ptl->setText(toqstr(s));
+ ptl->setFlags(tlh.rtl ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight);
#endif
+ ptl->setText(tlh.qstr);
ptl->beginLayout();
ptl->createLine();
ptl->endLayout();
+
+ return ptl;
+}
+
+}
+
+shared_ptr<QTextLayout const>
+GuiFontMetrics::getTextLayout(TextLayoutHelper const & tlh,
+ double const wordspacing) const
+{
+ PROFILE_THIS_BLOCK(getTextLayout_TLH);
+ TextLayoutKey key{tlh.docstr, tlh.rtl, wordspacing};
+ if (auto ptl = qtextlayout_cache_[key])
+ return ptl;
+ PROFILE_CACHE_MISS(getTextLayout_TLH);
+ auto const ptl = getTextLayout_helper(tlh, wordspacing, font_);
+ qtextlayout_cache_.insert(key, ptl);
+ return ptl;
+}
+
+
+shared_ptr<QTextLayout const>
+GuiFontMetrics::getTextLayout(docstring const & s, bool const rtl,
+ double const wordspacing) const
+{
+ PROFILE_THIS_BLOCK(getTextLayout);
+ TextLayoutKey key{s, rtl, wordspacing};
+ if (auto ptl = qtextlayout_cache_[key])
+ return ptl;
+ PROFILE_CACHE_MISS(getTextLayout);
+ TextLayoutHelper tlh(s, rtl);
+ auto const ptl = getTextLayout_helper(tlh, wordspacing, font_);
qtextlayout_cache_.insert(key, ptl);
return ptl;
}
namespace lyx {
namespace frontend {
+struct TextLayoutHelper;
+
struct BreakStringKey
{
bool operator==(BreakStringKey const & key) const {
/// Return a pointer to a cached QTextLayout object
std::shared_ptr<QTextLayout const>
- getTextLayout(docstring const & s, bool const rtl,
- double const wordspacing) const;
+ getTextLayout(docstring const & s, bool const rtl, double const wordspacing) const;
private:
Breaks breakString_helper(docstring const & s, int first_wid, int wid,
bool rtl, bool force) const;
+ /// A different version of getTextLayout for internal use
+ std::shared_ptr<QTextLayout const>
+ getTextLayout(TextLayoutHelper const & tlh, double const wordspacing) const;
+
/// The font
QFont font_;