Use integer line thickness in painter

There is no need for real-valued line width in painters. Actually, this even leads to uneven dashes for continuous spell checker.

The new code is supposed to be equivalent to the old one, just more readable. From this, we can try to see whether some lines need to be made thicker on HiDPI screens.
This commit is contained in:
Jean-Marc Lasgouttes 2015-07-14 17:42:45 +02:00
parent 468cedb923
commit 463bd17d75
6 changed files with 29 additions and 29 deletions

View File

@ -61,8 +61,8 @@ RowPainter::RowPainter(PainterInfo & pi,
row_(row), pit_(pit), par_(text.paragraphs()[pit]), row_(row), pit_(pit), par_(text.paragraphs()[pit]),
pm_(text_metrics_.parMetrics(pit)), change_(pi_.change_), pm_(text_metrics_.parMetrics(pit)), change_(pi_.change_),
xo_(x), yo_(y), width_(text_metrics_.width()), xo_(x), yo_(y), width_(text_metrics_.width()),
solid_line_thickness_(1.0), solid_line_offset_(1), solid_line_thickness_(1), solid_line_offset_(1),
dotted_line_thickness_(1.0), dotted_line_offset_(2) dotted_line_thickness_(1), dotted_line_offset_(2)
{ {
bidi_.computeTables(par_, pi_.base.bv->buffer(), row_); bidi_.computeTables(par_, pi_.base.bv->buffer(), row_);
@ -70,17 +70,17 @@ RowPainter::RowPainter(PainterInfo & pi,
// derive the line thickness from zoom factor // derive the line thickness from zoom factor
// the zoom is given in percent // the zoom is given in percent
// (increase thickness at 250%, 450% etc.) // (increase thickness at 250%, 450% etc.)
solid_line_thickness_ = (float)(int((lyxrc.zoom + 50) / 200.0)); solid_line_thickness_ = (lyxrc.zoom + 50) / 200;
// adjust line_offset_ too // adjust line_offset_ too
solid_line_offset_ = 1 + int(0.5 * solid_line_thickness_); solid_line_offset_ = 1 + solid_line_thickness_ / 2;
} }
if (lyxrc.zoom >= 100) { if (lyxrc.zoom >= 100) {
// derive the line thickness from zoom factor // derive the line thickness from zoom factor
// the zoom is given in percent // the zoom is given in percent
// (increase thickness at 150%, 250% etc.) // (increase thickness at 150%, 250% etc.)
dotted_line_thickness_ = (float)(int((lyxrc.zoom + 50) / 100.0)); dotted_line_thickness_ = (lyxrc.zoom + 50) / 100;
// adjust line_offset_ too // adjust line_offset_ too
dotted_line_offset_ = int(0.5 * dotted_line_thickness_) + 1; dotted_line_offset_ = 1 + dotted_line_thickness_ / 2;
} }
x_ = row_.left_margin + xo_; x_ = row_.left_margin + xo_;
@ -286,7 +286,7 @@ void RowPainter::paintForeignMark(double orig_x, Language const * lang, int desc
if (lang == pi_.base.bv->buffer().params().language) if (lang == pi_.base.bv->buffer().params().language)
return; return;
int const y = yo_ + solid_line_offset_ + desc + int(solid_line_thickness_/2); int const y = yo_ + solid_line_offset_ + desc + solid_line_thickness_ / 2;
pi_.pain.line(int(orig_x), y, int(x_), y, Color_language, pi_.pain.line(int(orig_x), y, int(x_), y, Color_language,
Painter::line_solid, solid_line_thickness_); Painter::line_solid, solid_line_thickness_);
} }
@ -444,12 +444,12 @@ int RowPainter::paintAppendixStart(int y) const
void RowPainter::paintTooLargeMarks(bool const left, bool const right) const void RowPainter::paintTooLargeMarks(bool const left, bool const right) const
{ {
if (left) if (left)
pi_.pain.line(int(dotted_line_thickness_), yo_ - row_.ascent(), pi_.pain.line(dotted_line_thickness_, yo_ - row_.ascent(),
int(dotted_line_thickness_), yo_ + row_.descent(), dotted_line_thickness_, yo_ + row_.descent(),
Color_scroll, Color_scroll,
Painter::line_onoffdash, dotted_line_thickness_); Painter::line_onoffdash, dotted_line_thickness_);
if (right) { if (right) {
int const wwidth = pi_.base.bv->workWidth() - int(dotted_line_thickness_); int const wwidth = pi_.base.bv->workWidth() - dotted_line_thickness_;
pi_.pain.line(wwidth, yo_ - row_.ascent(), pi_.pain.line(wwidth, yo_ - row_.ascent(),
wwidth, yo_ + row_.descent(), wwidth, yo_ + row_.descent(),
Color_scroll, Color_scroll,

View File

@ -122,9 +122,9 @@ private:
int const yo_; // current baseline int const yo_; // current baseline
double x_; double x_;
int width_; int width_;
float solid_line_thickness_; int solid_line_thickness_;
int solid_line_offset_; int solid_line_offset_;
float dotted_line_thickness_; int dotted_line_thickness_;
int dotted_line_offset_; int dotted_line_offset_;
}; };

View File

@ -56,7 +56,7 @@ class Painter {
public: public:
Painter(double pixel_ratio) : drawing_enabled_(true), pixel_ratio_(pixel_ratio) {} Painter(double pixel_ratio) : drawing_enabled_(true), pixel_ratio_(pixel_ratio) {}
static const float thin_line; static const int thin_line;
/// possible line styles /// possible line styles
enum line_style { enum line_style {
@ -83,7 +83,7 @@ public:
/// draw a line from point to point /// draw a line from point to point
virtual void line(int x1, int y1, int x2, int y2, Color, virtual void line(int x1, int y1, int x2, int y2, Color,
line_style = line_solid, float line_width = thin_line) = 0; line_style = line_solid, int line_width = thin_line) = 0;
/** /**
* lines - draw a set of lines * lines - draw a set of lines
@ -93,11 +93,11 @@ public:
*/ */
virtual void lines(int const * xp, int const * yp, int np, Color, virtual void lines(int const * xp, int const * yp, int np, Color,
fill_style = fill_none, line_style = line_solid, fill_style = fill_none, line_style = line_solid,
float line_width = thin_line) = 0; int line_width = thin_line) = 0;
/// draw a rectangle /// draw a rectangle
virtual void rectangle(int x, int y, int w, int h, Color, virtual void rectangle(int x, int y, int w, int h, Color,
line_style = line_solid, float line_width = thin_line) = 0; line_style = line_solid, int line_width = thin_line) = 0;
/// draw a filled rectangle /// draw a filled rectangle
virtual void fillRectangle(int x, int y, int w, int h, Color) = 0; virtual void fillRectangle(int x, int y, int w, int h, Color) = 0;

View File

@ -50,7 +50,7 @@ using namespace lyx::support;
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
const float Painter::thin_line = 0.0; const int Painter::thin_line = 0;
GuiPainter::GuiPainter(QPaintDevice * device, double pixel_ratio) GuiPainter::GuiPainter(QPaintDevice * device, double pixel_ratio)
: QPainter(device), Painter(pixel_ratio), : QPainter(device), Painter(pixel_ratio),
@ -71,7 +71,7 @@ GuiPainter::~GuiPainter()
void GuiPainter::setQPainterPen(QColor const & col, void GuiPainter::setQPainterPen(QColor const & col,
Painter::line_style ls, float lw) Painter::line_style ls, int lw)
{ {
if (col == current_color_ && ls == current_ls_ && lw == current_lw_) if (col == current_color_ && ls == current_ls_ && lw == current_lw_)
return; return;
@ -88,7 +88,7 @@ void GuiPainter::setQPainterPen(QColor const & col,
case line_onoffdash: pen.setStyle(Qt::DotLine); break; case line_onoffdash: pen.setStyle(Qt::DotLine); break;
} }
pen.setWidthF(lw); pen.setWidth(lw);
setPen(pen); setPen(pen);
} }
@ -180,7 +180,7 @@ void GuiPainter::point(int x, int y, Color col)
void GuiPainter::line(int x1, int y1, int x2, int y2, void GuiPainter::line(int x1, int y1, int x2, int y2,
Color col, Color col,
line_style ls, line_style ls,
float lw) int lw)
{ {
if (!isDrawingEnabled()) if (!isDrawingEnabled())
return; return;
@ -198,7 +198,7 @@ void GuiPainter::lines(int const * xp, int const * yp, int np,
Color col, Color col,
fill_style fs, fill_style fs,
line_style ls, line_style ls,
float lw) int lw)
{ {
if (!isDrawingEnabled()) if (!isDrawingEnabled())
return; return;
@ -236,7 +236,7 @@ void GuiPainter::lines(int const * xp, int const * yp, int np,
void GuiPainter::rectangle(int x, int y, int w, int h, void GuiPainter::rectangle(int x, int y, int w, int h,
Color col, Color col,
line_style ls, line_style ls,
float lw) int lw)
{ {
if (!isDrawingEnabled()) if (!isDrawingEnabled())
return; return;

View File

@ -42,7 +42,7 @@ public:
int x2, int y2, int x2, int y2,
Color, Color,
line_style ls = line_solid, line_style ls = line_solid,
float lw = thin_line); int lw = thin_line);
/** /**
* lines - draw a set of lines * lines - draw a set of lines
@ -57,7 +57,7 @@ public:
Color, Color,
fill_style fs = fill_none, fill_style fs = fill_none,
line_style ls = line_solid, line_style ls = line_solid,
float lw = thin_line); int lw = thin_line);
/// draw a rectangle /// draw a rectangle
virtual void rectangle( virtual void rectangle(
@ -65,7 +65,7 @@ public:
int w, int h, int w, int h,
Color, Color,
line_style = line_solid, line_style = line_solid,
float lw = thin_line); int lw = thin_line);
/// draw a filled rectangle /// draw a filled rectangle
virtual void fillRectangle( virtual void fillRectangle(
@ -163,11 +163,11 @@ private:
/// set pen parameters /// set pen parameters
void setQPainterPen(QColor const & col, void setQPainterPen(QColor const & col,
line_style ls = line_solid, float lw = thin_line); line_style ls = line_solid, int lw = thin_line);
QColor current_color_; QColor current_color_;
Painter::line_style current_ls_; Painter::line_style current_ls_;
float current_lw_; int current_lw_;
/// ///
bool const use_pixmap_cache_; bool const use_pixmap_cache_;
/// ///

View File

@ -159,7 +159,7 @@ void InsetLine::draw(PainterInfo & pi, int x, int y) const
y - offset_ - height_/2, y - offset_ - height_/2,
x + dim.wid - height_/2 - 2, x + dim.wid - height_/2 - 2,
y - offset_ - height_/2, y - offset_ - height_/2,
Line_color, Painter::line_solid, float(height_)); Line_color, Painter::line_solid, height_);
} }