未验证 提交 06fea14e 编写于 作者: J Justin McCandless 提交者: GitHub

Glitchiness with Tab Characters (#8591)

Fix a bug that caused jumping and flashing when entering tab characters into a TextField.
上级 b6787096
......@@ -32,8 +32,6 @@ using std::vector;
namespace minikin {
const int CHAR_TAB = 0x0009;
// Large scores in a hierarchy; we prefer desperate breaks to an overfull line.
// All these constants are larger than any reasonable actual width score.
const float SCORE_INFTY = std::numeric_limits<float>::max();
......@@ -159,22 +157,14 @@ float LineBreaker::addStyleRun(MinikinPaint* paint,
size_t postSpaceCount = mSpaceCount;
for (size_t i = start; i < end; i++) {
uint16_t c = mTextBuf[i];
if (c == CHAR_TAB) {
mWidth = mPreBreak + mTabStops.nextTab(mWidth - mPreBreak);
if (mFirstTabIndex == INT_MAX) {
mFirstTabIndex = (int)i;
}
// fall back to greedy; other modes don't know how to deal with tabs
mStrategy = kBreakStrategy_Greedy;
} else {
if (isWordSpace(c))
mSpaceCount += 1;
mWidth += mCharWidths[i];
if (!isLineEndSpace(c)) {
postBreak = mWidth;
postSpaceCount = mSpaceCount;
afterWord = i + 1;
}
// libtxt: Tab handling was removed here.
if (isWordSpace(c))
mSpaceCount += 1;
mWidth += mCharWidths[i];
if (!isLineEndSpace(c)) {
postBreak = mWidth;
postSpaceCount = mSpaceCount;
afterWord = i + 1;
}
if (i + 1 == current) {
size_t wordStart = mWordBreaker.wordStart();
......
......@@ -85,30 +85,6 @@ class LineWidths {
std::vector<float> mIndents;
};
class TabStops {
public:
void set(const int* stops, size_t nStops, int tabWidth) {
if (stops != nullptr) {
mStops.assign(stops, stops + nStops);
} else {
mStops.clear();
}
mTabWidth = tabWidth;
}
float nextTab(float widthSoFar) const {
for (size_t i = 0; i < mStops.size(); i++) {
if (mStops[i] > widthSoFar) {
return mStops[i];
}
}
return floor(widthSoFar / mTabWidth + 1) * mTabWidth;
}
private:
std::vector<int> mStops;
int mTabWidth;
};
class LineBreaker {
public:
const static int kTab_Shift =
......@@ -143,10 +119,6 @@ class LineBreaker {
void setIndents(const std::vector<float>& indents);
void setTabStops(const int* stops, size_t nStops, int tabWidth) {
mTabStops.set(stops, nStops, tabWidth);
}
BreakStrategy getStrategy() const { return mStrategy; }
void setStrategy(BreakStrategy strategy) { mStrategy = strategy; }
......@@ -246,7 +218,6 @@ class LineBreaker {
HyphenationFrequency mHyphenationFrequency = kHyphenationFrequency_Normal;
bool mJustified;
LineWidths mLineWidths;
TabStops mTabStops;
// result of line breaking
std::vector<int> mBreaks;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册