mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
Implement real string width computation
Important features: * widths are cached in a map * old behavior is still used when lyxrc.force_paint_single_char is true.
This commit is contained in:
parent
b044696d59
commit
8539f756ed
@ -6,19 +6,28 @@ for now we intend to keep unchanged behavior for testing purposes.
|
|||||||
What is done:
|
What is done:
|
||||||
* Make TextMetrics methods operate on Row objects: breakRow and
|
* Make TextMetrics methods operate on Row objects: breakRow and
|
||||||
setRowHeight instead of rowBreakPoint and rowHeight.
|
setRowHeight instead of rowBreakPoint and rowHeight.
|
||||||
|
|
||||||
* change breakRow operation to operate on text strings on which
|
* change breakRow operation to operate on text strings on which
|
||||||
metrics are computed. Note that for now FontMetrics::width(docstring)
|
metrics are computed. Note that for now
|
||||||
still computes the sum of character widths, so that behavior is
|
FontMetrics::width(docstring) still computes the sum of character
|
||||||
unchanged.
|
widths, so that behavior is unchanged.
|
||||||
|
|
||||||
|
* Implement proper string metrics computation (with cache), when
|
||||||
|
lyxrc.force_paint_single_char is false.
|
||||||
|
|
||||||
Next steps:
|
Next steps:
|
||||||
|
|
||||||
* Make breakRow build a list of elements (string, inset,
|
* Make breakRow build a list of elements (string, inset,
|
||||||
separator,...) in the row. This will be reused by other methods
|
separator,...) in the row. This will be reused by other methods
|
||||||
|
|
||||||
* get rid of rowWidth (breakRow does compute this)
|
* get rid of rowWidth (breakRow does compute this)
|
||||||
|
|
||||||
* re-implement getColumnNearX using row elements
|
* re-implement getColumnNearX using row elements
|
||||||
* re-implement x2pos using row elements
|
|
||||||
* re-implement row painting using row elements
|
* re-implement cursorX using row elements
|
||||||
* Finally, implement proper string metrics computation (with cache)
|
|
||||||
|
* re-implement row painting using row elements (can it be done?)
|
||||||
|
|
||||||
* profile and see how performance can be improved.
|
* profile and see how performance can be improved.
|
||||||
|
|
||||||
Difference in behavior
|
Difference in behavior
|
||||||
|
@ -15,8 +15,9 @@
|
|||||||
|
|
||||||
#include "qt_helpers.h"
|
#include "qt_helpers.h"
|
||||||
|
|
||||||
#include "Language.h"
|
|
||||||
#include "Dimension.h"
|
#include "Dimension.h"
|
||||||
|
#include "Language.h"
|
||||||
|
#include "LyXRC.h"
|
||||||
|
|
||||||
#include "insets/Inset.h"
|
#include "insets/Inset.h"
|
||||||
|
|
||||||
@ -110,21 +111,20 @@ int GuiFontMetrics::rbearing(char_type c) const
|
|||||||
|
|
||||||
int GuiFontMetrics::width(docstring const & s) const
|
int GuiFontMetrics::width(docstring const & s) const
|
||||||
{
|
{
|
||||||
size_t ls = s.size();
|
|
||||||
int w = 0;
|
int w = 0;
|
||||||
for (unsigned int i = 0; i < ls; ++i) {
|
if (lyxrc.force_paint_single_char) {
|
||||||
//FIXME: we need to detect surrogate pairs and act accordingly
|
size_t const ls = s.size();
|
||||||
/**
|
for (size_t i = 0; i < ls; ++i)
|
||||||
if isSurrogateBase(s[i]) {
|
|
||||||
docstring c = s[i];
|
|
||||||
w += metrics_.width(toqstr(c + s[i + 1]));
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*/
|
|
||||||
w += width(s[i]);
|
w += width(s[i]);
|
||||||
|
} else {
|
||||||
|
map<docstring, int>::const_iterator it = strwidth_cache_.find(s);
|
||||||
|
if (it != strwidth_cache_.end()) {
|
||||||
|
w = it->second;
|
||||||
|
} else {
|
||||||
|
w = metrics_.width(toqstr(s));
|
||||||
|
strwidth_cache_[s] = w;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#include "support/docstring.h"
|
#include "support/docstring.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
|
||||||
@ -59,6 +61,10 @@ private:
|
|||||||
/// Cache of char widths
|
/// Cache of char widths
|
||||||
mutable QHash<char_type, int> width_cache_;
|
mutable QHash<char_type, int> width_cache_;
|
||||||
|
|
||||||
|
/// Cache of string widths
|
||||||
|
/// FIXME Try to use a QHash (this requires to define qHash(docstring))
|
||||||
|
mutable std::map<docstring, int> strwidth_cache_;
|
||||||
|
|
||||||
struct AscendDescend {
|
struct AscendDescend {
|
||||||
int ascent;
|
int ascent;
|
||||||
int descent;
|
int descent;
|
||||||
|
Loading…
Reference in New Issue
Block a user