Terminal: Font width can be a fractional value, so we need to use a float.

Adapt other code accordingly. Minimum changes to fix ticket #11478
In theory also font height could be fractional, so we might need to
review other parts of the code.

Change-Id: Idbdbe38193ca5a32b3d09c7cf9accfc917760cae
Reviewed-on: https://review.haiku-os.org/821
Reviewed-by: waddlesplash <[email protected]>
Reviewed-by: Stephan Aßmus <[email protected]>
This commit is contained in:
JackBurton79
2019-01-03 21:27:27 +00:00
committed by Stephan Aßmus
parent 4c1d9cf74e
commit fe55edcaf4
3 changed files with 17 additions and 17 deletions
+12 -12
View File
@@ -545,7 +545,7 @@ TermView::TerminalName() const
//! Get width and height for terminal font //! Get width and height for terminal font
void void
TermView::GetFontSize(int* _width, int* _height) TermView::GetFontSize(float* _width, float* _height)
{ {
*_width = fFontWidth; *_width = fFontWidth;
*_height = fFontHeight; *_height = fFontHeight;
@@ -631,8 +631,8 @@ void
TermView::GetTermSizeFromRect(const BRect &rect, int *_rows, TermView::GetTermSizeFromRect(const BRect &rect, int *_rows,
int *_columns) int *_columns)
{ {
int columns = (rect.IntegerWidth() + 1) / fFontWidth; int columns = int((rect.IntegerWidth() + 1) / fFontWidth);
int rows = (rect.IntegerHeight() + 1) / fFontHeight; int rows = int((rect.IntegerHeight() + 1) / fFontHeight);
if (_rows) if (_rows)
*_rows = rows; *_rows = rows;
@@ -738,7 +738,7 @@ TermView::GetTermFont(BFont *font) const
void void
TermView::SetTermFont(const BFont *font) TermView::SetTermFont(const BFont *font)
{ {
int halfWidth = 0; float halfWidth = 0;
fHalfFont = font; fHalfFont = font;
fBoldFont = font; fBoldFont = font;
@@ -752,7 +752,7 @@ TermView::SetTermFont(const BFont *font)
for (int c = 0x20; c <= 0x7e; c++) { for (int c = 0x20; c <= 0x7e; c++) {
char buf[4]; char buf[4];
sprintf(buf, "%c", c); sprintf(buf, "%c", c);
int tmpWidth = (int)fHalfFont.StringWidth(buf); float tmpWidth = fHalfFont.StringWidth(buf);
if (tmpWidth > halfWidth) if (tmpWidth > halfWidth)
halfWidth = tmpWidth; halfWidth = tmpWidth;
} }
@@ -958,7 +958,7 @@ TermView::_Deactivate()
//! Draw part of a line in the given view. //! Draw part of a line in the given view.
void void
TermView::_DrawLinePart(int32 x1, int32 y1, uint32 attr, char *buf, TermView::_DrawLinePart(float x1, float y1, uint32 attr, char *buf,
int32 width, Highlight* highlight, bool cursor, BView *inView) int32 width, Highlight* highlight, bool cursor, BView *inView)
{ {
if (highlight != NULL) if (highlight != NULL)
@@ -968,8 +968,8 @@ TermView::_DrawLinePart(int32 x1, int32 y1, uint32 attr, char *buf,
? &fBoldFont : &fHalfFont); ? &fBoldFont : &fHalfFont);
// Set pen point // Set pen point
int x2 = x1 + fFontWidth * width; float x2 = x1 + fFontWidth * width;
int y2 = y1 + fFontHeight; float y2 = y1 + fFontHeight;
rgb_color rgb_fore = fTextForeColor; rgb_color rgb_fore = fTextForeColor;
rgb_color rgb_back = fTextBackColor; rgb_color rgb_back = fTextBackColor;
@@ -1238,8 +1238,8 @@ TermView::DetachedFromWindow()
void void
TermView::Draw(BRect updateRect) TermView::Draw(BRect updateRect)
{ {
int32 x1 = (int32)updateRect.left / fFontWidth; int32 x1 = (int32)(updateRect.left / fFontWidth);
int32 x2 = std::min((int)updateRect.right / fFontWidth, fColumns - 1); int32 x2 = std::min((int)(updateRect.right / fFontWidth), fColumns - 1);
int32 firstVisible = _LineAt(0); int32 firstVisible = _LineAt(0);
int32 y1 = _LineAt(updateRect.top); int32 y1 = _LineAt(updateRect.top);
@@ -1444,8 +1444,8 @@ void
TermView::FrameResized(float width, float height) TermView::FrameResized(float width, float height)
{ {
//debug_printf("TermView::FrameResized(%f, %f)\n", width, height); //debug_printf("TermView::FrameResized(%f, %f)\n", width, height);
int32 columns = ((int32)width + 1) / fFontWidth; int32 columns = (int32)((width + 1) / fFontWidth);
int32 rows = ((int32)height + 1) / fFontHeight; int32 rows = (int32)((height + 1) / fFontHeight);
if (columns == fColumns && rows == fRows) if (columns == fColumns && rows == fRows)
return; return;
+3 -3
View File
@@ -76,7 +76,7 @@ public:
void GetTermFont(BFont* font) const; void GetTermFont(BFont* font) const;
void SetTermFont(const BFont* font); void SetTermFont(const BFont* font);
void GetFontSize(int* width, int* height); void GetFontSize(float* width, float* height);
int Rows() const; int Rows() const;
int Columns() const; int Columns() const;
BRect SetTermSize(int rows, int cols, BRect SetTermSize(int rows, int cols,
@@ -194,7 +194,7 @@ private:
void _Activate(); void _Activate();
void _Deactivate(); void _Deactivate();
void _DrawLinePart(int32 x1, int32 y1, uint32 attr, void _DrawLinePart(float x1, float y1, uint32 attr,
char* buffer, int32 width, char* buffer, int32 width,
Highlight* highlight, bool cursor, Highlight* highlight, bool cursor,
BView* inView); BView* inView);
@@ -271,7 +271,7 @@ private:
// Font and Width // Font and Width
BFont fHalfFont; BFont fHalfFont;
BFont fBoldFont; BFont fBoldFont;
int fFontWidth; float fFontWidth;
int fFontHeight; int fFontHeight;
int fFontAscent; int fFontAscent;
struct escapement_delta fEscapement; struct escapement_delta fEscapement;
+2 -2
View File
@@ -1267,7 +1267,7 @@ TermWindow::_AddTab(Arguments* args, const BString& currentDirectory)
_GetPreferredFont(font); _GetPreferredFont(font);
view->SetTermFont(&font); view->SetTermFont(&font);
int width, height; float width, height;
view->GetFontSize(&width, &height); view->GetFontSize(&width, &height);
float minimumHeight = -1; float minimumHeight = -1;
@@ -1648,7 +1648,7 @@ TermWindow::NextTermView(TermView* view)
void void
TermWindow::_ResizeView(TermView *view) TermWindow::_ResizeView(TermView *view)
{ {
int fontWidth, fontHeight; float fontWidth, fontHeight;
view->GetFontSize(&fontWidth, &fontHeight); view->GetFontSize(&fontWidth, &fontHeight);
float minimumHeight = -1; float minimumHeight = -1;