Skip to content

Commit

Permalink
Merge pull request #6163 from neilcsmith-net/terminal-metrics
Browse files Browse the repository at this point in the history
Update rounding in terminal font metrics to address GH5980.
  • Loading branch information
neilcsmith-net authored Jul 7, 2023
2 parents 089991c + 8e4287f commit ca2d1fd
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static synchronized void disposeBy(FontMetrics fm) {

public MyFontMetrics(Component component, Font font) {
fm = component.getFontMetrics(font);
width = fm.charWidth('a');
width = fm.charWidth('m');
height = fm.getHeight();
ascent = fm.getAscent();
leading = fm.getLeading();
Expand Down Expand Up @@ -178,19 +178,21 @@ public int wcwidth(char c) {
cell_width = 1;

} else {
// round up pixel width to multiple of cell size
// round pixel width to multiple of cell size
// then distill into a width in terms of cells.
int mod = pixel_width % width;
int rounded_width = pixel_width;
if (mod != 0) {
if (mod > (width / 2)) {
rounded_width = pixel_width + (width - mod);
} else {
rounded_width = pixel_width - mod;
}
cell_width = rounded_width / width;
if (cell_width == 0) {
cell_width = 1;
} else if (cell_width > 1) {
cwidth_cache.setMultiCell(true);
}

cwidth_cache.setMultiCell(true);
}

cwidth_cache.cache[c] = (byte) cell_width;
Expand Down

0 comments on commit ca2d1fd

Please sign in to comment.