From c38dd82ded6b8c5080c720b8f240eff4f4a70bf5 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Wed, 13 Aug 2014 08:16:03 +0200 Subject: [PATCH] SerialConnect: use ints for font metrics As pointed by Ingo, using a float here is useless because we want each line to be the same integer number of pixels. Now thigs are drawn properly and the view has the exact same size as Terminal's one (tested with font sizes 10 and 18, so different leading values don't seem to be a problem). Thanks for reviewing! --- src/apps/serialconnect/TermView.cpp | 9 ++++----- src/apps/serialconnect/TermView.h | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/apps/serialconnect/TermView.cpp b/src/apps/serialconnect/TermView.cpp index f47c4d5572..f5ba2d4ecf 100644 --- a/src/apps/serialconnect/TermView.cpp +++ b/src/apps/serialconnect/TermView.cpp @@ -141,9 +141,9 @@ void TermView::GetPreferredSize(float* width, float* height) { if (width != NULL) - *width = kDefaultWidth * fFontWidth + 2 * kBorderSpacing; + *width = kDefaultWidth * fFontWidth + 2 * kBorderSpacing - 1; if (height != NULL) - *height = kDefaultHeight * fFontHeight + 2 * kBorderSpacing; + *height = kDefaultHeight * fFontHeight + 2 * kBorderSpacing - 1; } @@ -194,7 +194,8 @@ TermView::_Init() font_height height; GetFontHeight(&height); - fFontHeight = height.ascent + height.descent + height.leading + 1; + fFontHeight = ceilf(height.ascent) + ceilf(height.descent) + + ceilf(height.leading); fFontWidth = be_fixed_font->StringWidth("X"); fTerm = vterm_new(kDefaultHeight, kDefaultWidth); @@ -338,8 +339,6 @@ TermView::_PushLine(int cols, const VTermScreenCell* cells) BScrollBar* scrollBar = ScrollBar(B_VERTICAL); if (scrollBar != NULL) { - // FIXME this is not exactly right, it's off by a few pixels so one step - // isn't exactly equal to one line. float range = (fScrollBuffer.CountItems() + availableRows) * fFontHeight; scrollBar->SetRange(availableRows * fFontHeight - range, 0.0f); // TODO we need to adjust this in FrameResized, as availableRows can diff --git a/src/apps/serialconnect/TermView.h b/src/apps/serialconnect/TermView.h index 3a2b8a2ad8..47c661acfc 100644 --- a/src/apps/serialconnect/TermView.h +++ b/src/apps/serialconnect/TermView.h @@ -49,8 +49,8 @@ class TermView: public BView VTerm* fTerm; VTermScreen* fTermScreen; BList fScrollBuffer; - float fFontWidth; - float fFontHeight; + int fFontWidth; + int fFontHeight; static const VTermScreenCallbacks sScreenCallbacks;