Fix regression in handling zero cells caused by refactoring

This commit is contained in:
Kovid Goyal 2017-10-30 21:31:02 +05:30
parent 8fc9f97c12
commit 646e8dab0a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 8 additions and 9 deletions

View File

@ -97,7 +97,7 @@ fallback_font(Cell *cell) {
}
if (get_fallback_font == NULL || i == (sizeof(fallback_fonts)/sizeof(fallback_fonts[0])-1)) return &missing_font;
Py_UCS4 buf[10];
size_t n = cell_as_unicode(cell, true, buf);
size_t n = cell_as_unicode(cell, true, buf, ' ');
PyObject *face = PyObject_CallFunction(get_fallback_font, "NOO", PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, buf, n), bold ? Py_True : Py_False, italic ? Py_True : Py_False);
if (face == NULL) { PyErr_Print(); return &missing_font; }
if (face == Py_None) { Py_DECREF(face); return &missing_font; }

View File

@ -153,8 +153,8 @@ get_load_flags(int hinting, int hintstyle, int base) {
}
static inline bool
load_glyph(Face *self, int glyph_index) {
int flags = get_load_flags(self->hinting, self->hintstyle, FT_LOAD_RENDER);
load_glyph(Face *self, int glyph_index, int load_type) {
int flags = get_load_flags(self->hinting, self->hintstyle, load_type);
int error = FT_Load_Glyph(self->face, glyph_index, flags);
if (error) { set_freetype_error("Failed to load glyph, with error:", error); Py_CLEAR(self); return false; }
return true;
@ -165,7 +165,7 @@ calc_cell_width(Face *self) {
unsigned int ans = 0;
for (char_type i = 32; i < 128; i++) {
int glyph_index = FT_Get_Char_Index(self->face, i);
if (load_glyph(self, glyph_index)) {
if (load_glyph(self, glyph_index, FT_LOAD_DEFAULT)) {
ans = MAX(ans, (unsigned long)ceilf((float)self->face->glyph->metrics.horiAdvance / 64.f));
}
}

View File

@ -166,9 +166,9 @@ text_at(Line* self, Py_ssize_t xval) {
}
size_t
cell_as_unicode(Cell *cell, bool include_cc, Py_UCS4 *buf) {
cell_as_unicode(Cell *cell, bool include_cc, Py_UCS4 *buf, char_type zero_char) {
size_t n = 1;
buf[0] = cell->ch;
buf[0] = cell->ch ? cell->ch : zero_char;
if (include_cc) {
char_type cc = cell->cc;
Py_UCS4 cc1 = cc & CC_MASK, cc2;
@ -191,9 +191,8 @@ unicode_in_range(Line *self, index_type start, index_type limit, bool include_cc
char_type ch = self->cells[i].ch;
if (ch == 0) {
if (previous_width == 2) { previous_width = 0; continue; };
ch = ' ';
}
n += cell_as_unicode(self->cells + i, include_cc, buf + n);
n += cell_as_unicode(self->cells + i, include_cc, buf + n, ' ');
previous_width = self->cells[i].attrs & WIDTH_MASK;
}
return PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, buf, n);

View File

@ -67,7 +67,7 @@ index_type line_url_start_at(Line *self, index_type x);
index_type line_url_end_at(Line *self, index_type x);
index_type line_as_ansi(Line *self, Py_UCS4 *buf, index_type buflen);
unsigned int line_length(Line *self);
size_t cell_as_unicode(Cell *cell, bool include_cc, Py_UCS4 *buf);
size_t cell_as_unicode(Cell *cell, bool include_cc, Py_UCS4 *buf, char_type);
PyObject* unicode_in_range(Line *self, index_type start, index_type limit, bool include_cc, char leading_char);
void linebuf_init_line(LineBuf *, index_type);