Le 17/10/2016 à 01:28, racoon a écrit :
I just tried to do some fine tuning on the inset offsets (minimalistic and classic so far).
Hi racoon, I am glad you are looking at this. I agree that small offsets are better.
Though I have a non-high resolution display. Maybe it does not look as good on a high-res display. If so, maybe there should be an adjustment for high-res displays?
I had a go earlier to replace TEXT_TO_INSET_OFFSET with a function that computes the length according to current zoom and screen resolution. I abandonned the patch (attached) for now because it created problems for vertical spacing. You are welcome to borrow parts of it (the margins are already in).
You would be welcome to have a look at it. Another option would be to have a length in em, that is relative to the current font. That would make the inset spacing comparable to normal spacing in the enclosing space. This is the best solution IMO, but I am not sure that the font information is available when we need it.
JMarc
From a6c9f8a782d561ccea0bd5c2bb70c71527280c0e Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes <lasgout...@lyx.org> Date: Thu, 12 Nov 2015 10:19:08 +0100 Subject: [PATCH] Replace hardcoded TEXT_TO_INSET_OFFSET by dynamic value The value is counted as 1 millimeter now (the same at 100 dpi). We also ensures that it measures at least 1 pixel. Similarly, the Workarea default margin is now 2.5mm instead of being hardcoded to 10. This should improve the situation for HiDPI systems. --- src/BufferView.cpp | 6 ++++-- src/RowPainter.cpp | 2 +- src/frontends/qt4/GuiFontMetrics.cpp | 6 +++--- src/frontends/qt4/GuiPainter.cpp | 4 ++-- src/insets/Inset.cpp | 9 +++++++++ src/insets/Inset.h | 2 +- src/insets/InsetCaption.cpp | 8 ++++---- src/insets/InsetCollapsable.cpp | 6 +++--- src/insets/InsetIPA.cpp | 12 ++++++------ src/insets/InsetPhantom.cpp | 4 ++-- src/insets/InsetPreview.cpp | 12 ++++++------ src/insets/InsetTabular.cpp | 4 ++-- src/insets/InsetText.cpp | 28 ++++++++++++++-------------- src/insets/RenderGraphic.cpp | 18 +++++++++--------- src/insets/RenderPreview.cpp | 2 +- 15 files changed, 67 insertions(+), 56 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 0030f33..902f8a7 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -351,11 +351,13 @@ BufferView::~BufferView() int BufferView::rightMargin() const { + // THe value used to be hardcoded to 10, which is 2.5mm at 100dpi + int const default_margin = Length(2.5, Length::MM).inPixels(0); // The additional test for the case the outliner is opened. if (!full_screen_ || !lyxrc.full_screen_limit || - width_ < lyxrc.full_screen_width + 20) - return 10; + width_ < lyxrc.full_screen_width + 2 * default_margin) + return default_margin; return (width_ - lyxrc.full_screen_width) / 2; } diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp index ce5780b..3d360d4 100644 --- a/src/RowPainter.cpp +++ b/src/RowPainter.cpp @@ -540,7 +540,7 @@ void RowPainter::paintLast() FontMetrics const & fm = theFontMetrics(font); int const size = int(0.75 * fm.maxAscent()); int const y = yo_ - size; - int const max_row_width = width_ - size - Inset::TEXT_TO_INSET_OFFSET; + int const max_row_width = width_ - size - Inset::textToInsetOffset(); int x = is_rtl ? nestMargin() + changebarMargin() : max_row_width - row_.right_margin; diff --git a/src/frontends/qt4/GuiFontMetrics.cpp b/src/frontends/qt4/GuiFontMetrics.cpp index 8d0b026..d4f3585 100644 --- a/src/frontends/qt4/GuiFontMetrics.cpp +++ b/src/frontends/qt4/GuiFontMetrics.cpp @@ -237,9 +237,9 @@ bool GuiFontMetrics::breakAt(docstring & s, int & x, bool const rtl, bool const void GuiFontMetrics::rectText(docstring const & str, int & w, int & ascent, int & descent) const { - static int const d = Inset::TEXT_TO_INSET_OFFSET / 2; + static int const d = Inset::textToInsetOffset() / 2; - w = width(str) + Inset::TEXT_TO_INSET_OFFSET; + w = width(str) + Inset::textToInsetOffset(); ascent = metrics_.ascent() + d; descent = metrics_.descent() + d; } @@ -250,7 +250,7 @@ void GuiFontMetrics::buttonText(docstring const & str, int & w, int & ascent, int & descent) const { rectText(str, w, ascent, descent); - w += Inset::TEXT_TO_INSET_OFFSET; + w += Inset::textToInsetOffset(); } diff --git a/src/frontends/qt4/GuiPainter.cpp b/src/frontends/qt4/GuiPainter.cpp index 2b024d8..af75547 100644 --- a/src/frontends/qt4/GuiPainter.cpp +++ b/src/frontends/qt4/GuiPainter.cpp @@ -533,10 +533,10 @@ void GuiPainter::buttonText(int x, int y, docstring const & str, FontMetrics const & fm = theFontMetrics(font); fm.buttonText(str, width, ascent, descent); - static int const d = Inset::TEXT_TO_INSET_OFFSET / 2; + static int const d = Inset::textToInsetOffset() / 2; button(x + d, y - ascent, width - d, descent + ascent, mouseHover); - text(x + Inset::TEXT_TO_INSET_OFFSET, y, str, font); + text(x + Inset::textToInsetOffset(), y, str, font); } diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index 0fce648..1d8e9f4 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -27,6 +27,7 @@ #include "DispatchResult.h" #include "FuncRequest.h" #include "FuncStatus.h" +#include "Length.h" #include "MetricsInfo.h" #include "output_xhtml.h" #include "Text.h" @@ -617,6 +618,14 @@ ColorCode Inset::labelColor() const } +int Inset::textToInsetOffset() +{ + // Hardcoded value was 4. At 100dpi default resolution, this is + // equivalent to 1 millimeter. + return Length(1, Length::MM).inPixels(0); +} + + void Inset::setPosCache(PainterInfo const & pi, int x, int y) const { //LYXERR("Inset: set position cache to " << x << " " << y); diff --git a/src/insets/Inset.h b/src/insets/Inset.h index f928830..9639ccc 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -567,7 +567,7 @@ public: /// virtual ColorCode labelColor() const; // - enum { TEXT_TO_INSET_OFFSET = 4 }; + static int textToInsetOffset(); protected: /// Constructors diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index 21b834a..fb26166 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -118,7 +118,7 @@ void InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const mi.base.font = mi.base.bv->buffer().params().getFont().fontInfo(); labelwidth_ = theFontMetrics(mi.base.font).width(full_label_); // add some space to separate the label from the inset text - labelwidth_ += 2 * TEXT_TO_INSET_OFFSET; + labelwidth_ += 2 * textToInsetOffset(); dim.wid = labelwidth_; Dimension textdim; // Correct for button and label width @@ -135,8 +135,8 @@ void InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const void InsetCaption::drawBackground(PainterInfo & pi, int x, int y) const { TextMetrics & tm = pi.base.bv->textMetrics(&text()); - int const h = tm.height() + 2 * TEXT_TO_INSET_OFFSET; - int const yy = y - TEXT_TO_INSET_OFFSET - tm.ascent(); + int const h = tm.height() + 2 * textToInsetOffset(); + int const yy = y - textToInsetOffset() - tm.ascent(); pi.pain.fillRectangle(x, yy, labelwidth_, h, pi.backgroundColor(this)); } @@ -154,7 +154,7 @@ void InsetCaption::draw(PainterInfo & pi, int x, int y) const FontInfo tmpfont = pi.base.font; pi.base.font = pi.base.bv->buffer().params().getFont().fontInfo(); pi.base.font.setColor(pi.textColor(pi.base.font.color()).baseColor); - int const xx = x + TEXT_TO_INSET_OFFSET; + int const xx = x + textToInsetOffset(); pi.pain.text(xx, y, full_label_, pi.base.font); InsetText::draw(pi, x + labelwidth_, y); pi.base.font = tmpfont; diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index aeac8b3..47728f1 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -230,7 +230,7 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des); dim.asc = textdim.asc; } else { - dim.des += textdim.height() + TEXT_TO_INSET_OFFSET; + dim.des += textdim.height() + textToInsetOffset(); dim.wid = max(dim.wid, textdim.wid); } } @@ -314,8 +314,8 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const if (geometry(bv) == Corners) desc -= 3; - const int xx1 = x + TEXT_TO_INSET_OFFSET - 1; - const int xx2 = x + textdim.wid - TEXT_TO_INSET_OFFSET + 1; + const int xx1 = x + textToInsetOffset() - 1; + const int xx2 = x + textdim.wid - textToInsetOffset() + 1; pi.pain.line(xx1, y + desc - 4, xx1, y + desc, Color_foreground); diff --git a/src/insets/InsetIPA.cpp b/src/insets/InsetIPA.cpp index 8bc3d46..d641d42 100644 --- a/src/insets/InsetIPA.cpp +++ b/src/insets/InsetIPA.cpp @@ -153,7 +153,7 @@ void InsetIPA::draw(PainterInfo & pi, int x, int y) const use_preview_ = previewState(pi.base.bv); if (use_preview_) { - preview_->draw(pi, x + TEXT_TO_INSET_OFFSET, y); + preview_->draw(pi, x + textToInsetOffset(), y); setPosCache(pi, x, y); return; } @@ -183,16 +183,16 @@ void InsetIPA::metrics(MetricsInfo & mi, Dimension & dim) const { if (previewState(mi.base.bv)) { preview_->metrics(mi, dim); - mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET; + mi.base.textwidth += 2 * textToInsetOffset(); dim.wid = max(dim.wid, 4); dim.asc = max(dim.asc, 4); - dim.asc += TEXT_TO_INSET_OFFSET; - dim.des += TEXT_TO_INSET_OFFSET; - dim.wid += TEXT_TO_INSET_OFFSET; + dim.asc += textToInsetOffset(); + dim.des += textToInsetOffset(); + dim.wid += textToInsetOffset(); dim_ = dim; - dim.wid += TEXT_TO_INSET_OFFSET; + dim.wid += textToInsetOffset(); // insert a one pixel gap dim.wid += 1; // Cache the inset dimension. diff --git a/src/insets/InsetPhantom.cpp b/src/insets/InsetPhantom.cpp index c6efe9a..aa04467 100644 --- a/src/insets/InsetPhantom.cpp +++ b/src/insets/InsetPhantom.cpp @@ -203,10 +203,10 @@ void InsetPhantom::draw(PainterInfo & pi, int x, int y) const // | | | | // x1 x2 x3 x4 - x = x + TEXT_TO_INSET_OFFSET; + x = x + textToInsetOffset(); int const x1 = x; int const x2 = x + arrow_size; - int const x4 = x + dim.wid - 2 * TEXT_TO_INSET_OFFSET; + int const x4 = x + dim.wid - 2 * textToInsetOffset(); int const x3 = x4 - arrow_size; int const y2 = y + (dim.des - dim.asc) / 2; diff --git a/src/insets/InsetPreview.cpp b/src/insets/InsetPreview.cpp index d327fe5..aaf6feb 100644 --- a/src/insets/InsetPreview.cpp +++ b/src/insets/InsetPreview.cpp @@ -141,7 +141,7 @@ void InsetPreview::draw(PainterInfo & pi, int x, int y) const if (use_preview_) { // one pixel gap in front - preview_->draw(pi, x + 1 + TEXT_TO_INSET_OFFSET, y); + preview_->draw(pi, x + 1 + textToInsetOffset(), y); setPosCache(pi, x, y); return; } @@ -171,16 +171,16 @@ void InsetPreview::metrics(MetricsInfo & mi, Dimension & dim) const { if (previewState(mi.base.bv)) { preview_->metrics(mi, dim); - mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET; + mi.base.textwidth += 2 * textToInsetOffset(); dim.wid = max(dim.wid, 4); dim.asc = max(dim.asc, 4); - dim.asc += TEXT_TO_INSET_OFFSET; - dim.des += TEXT_TO_INSET_OFFSET; - dim.wid += TEXT_TO_INSET_OFFSET; + dim.asc += textToInsetOffset(); + dim.des += textToInsetOffset(); + dim.wid += textToInsetOffset(); dim_ = dim; - dim.wid += TEXT_TO_INSET_OFFSET; + dim.wid += textToInsetOffset(); // insert a one pixel gap dim.wid += 1; // Cache the inset dimension. diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 437ac7e..57238df 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -3648,9 +3648,9 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const tabular.cell_info[r][c].decimal_width = decimal_width; // with LYX_VALIGN_BOTTOM the descent is relative to the last par - // = descent of text in last par + TEXT_TO_INSET_OFFSET: + // = descent of text in last par + textToInsetOffset(): int const lastpardes = tm.last().second->descent() - + TEXT_TO_INSET_OFFSET; + + textToInsetOffset(); int offset = 0; switch (tabular.getVAlignment(cell)) { case Tabular::LYX_VALIGN_TOP: diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 80b0bac..3c86d73 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -141,9 +141,9 @@ Dimension const InsetText::dimension(BufferView const & bv) const { TextMetrics const & tm = bv.textMetrics(&text_); Dimension dim = tm.dimension(); - dim.wid += 2 * TEXT_TO_INSET_OFFSET; - dim.des += TEXT_TO_INSET_OFFSET; - dim.asc += TEXT_TO_INSET_OFFSET; + dim.wid += 2 * textToInsetOffset(); + dim.des += textToInsetOffset(); + dim.asc += textToInsetOffset(); return dim; } @@ -192,7 +192,7 @@ void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const // Hand font through to contained lyxtext: tm.font_.fontInfo() = mi.base.font; - mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET; + mi.base.textwidth -= 2 * textToInsetOffset(); // This can happen when a layout has a left and right margin, // and the view is made very narrow. We can't do better than @@ -204,10 +204,10 @@ void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const tm.metrics(mi, dim, mi.base.textwidth); else tm.metrics(mi, dim); - mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET; - dim.asc += TEXT_TO_INSET_OFFSET; - dim.des += TEXT_TO_INSET_OFFSET; - dim.wid += 2 * TEXT_TO_INSET_OFFSET; + mi.base.textwidth += 2 * textToInsetOffset(); + dim.asc += textToInsetOffset(); + dim.des += textToInsetOffset(); + dim.wid += 2 * textToInsetOffset(); } @@ -216,10 +216,10 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const TextMetrics & tm = pi.base.bv->textMetrics(&text_); if (drawFrame_ || pi.full_repaint) { - int const w = tm.width() + TEXT_TO_INSET_OFFSET; - int const yframe = y - TEXT_TO_INSET_OFFSET - tm.ascent(); - int const h = tm.height() + 2 * TEXT_TO_INSET_OFFSET; - int const xframe = x + TEXT_TO_INSET_OFFSET / 2; + int const w = tm.width() + textToInsetOffset(); + int const yframe = y - textToInsetOffset() - tm.ascent(); + int const h = tm.height() + 2 * textToInsetOffset(); + int const xframe = x + textToInsetOffset() / 2; if (pi.full_repaint) pi.pain.fillRectangle(xframe, yframe, w, h, pi.backgroundColor(this)); @@ -230,7 +230,7 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const ColorCode const old_color = pi.background_color; pi.background_color = pi.backgroundColor(this, false); - tm.draw(pi, x + TEXT_TO_INSET_OFFSET, y); + tm.draw(pi, x + textToInsetOffset(), y); pi.background_color = old_color; } @@ -649,7 +649,7 @@ void InsetText::getArgs(otexstream & os, OutputParams const & runparams_in, void InsetText::cursorPos(BufferView const & bv, CursorSlice const & sl, bool boundary, int & x, int & y) const { - x = bv.textMetrics(&text_).cursorX(sl, boundary) + TEXT_TO_INSET_OFFSET; + x = bv.textMetrics(&text_).cursorX(sl, boundary) + textToInsetOffset(); y = bv.textMetrics(&text_).cursorY(sl, boundary); } diff --git a/src/insets/RenderGraphic.cpp b/src/insets/RenderGraphic.cpp index 48b41e2..0f4d4b8 100644 --- a/src/insets/RenderGraphic.cpp +++ b/src/insets/RenderGraphic.cpp @@ -144,7 +144,7 @@ void RenderGraphic::metrics(MetricsInfo & mi, Dimension & dim) const bool const image_ready = displayGraphic(params_) && readyToDisplay(loader_); if (image_ready) { - dim.wid = loader_.image()->width() + 2 * Inset::TEXT_TO_INSET_OFFSET; + dim.wid = loader_.image()->width() + 2 * Inset::textToInsetOffset(); dim.asc = loader_.image()->height(); dim_ = dim; return; @@ -184,16 +184,16 @@ void RenderGraphic::draw(PainterInfo & pi, int x, int y) const // loaded yet, we draw just a rectangle. if (displayGraphic(params_) && readyToDisplay(loader_)) { - pi.pain.image(x + Inset::TEXT_TO_INSET_OFFSET, + pi.pain.image(x + Inset::textToInsetOffset(), y - dim_.asc, - dim_.wid - 2 * Inset::TEXT_TO_INSET_OFFSET, + dim_.wid - 2 * Inset::textToInsetOffset(), dim_.asc + dim_.des, *loader_.image()); } else { - pi.pain.rectangle(x + Inset::TEXT_TO_INSET_OFFSET, + pi.pain.rectangle(x + Inset::textToInsetOffset(), y - dim_.asc, - dim_.wid - 2 * Inset::TEXT_TO_INSET_OFFSET, + dim_.wid - 2 * Inset::textToInsetOffset(), dim_.asc + dim_.des, Color_foreground); @@ -204,8 +204,8 @@ void RenderGraphic::draw(PainterInfo & pi, int x, int y) const if (!justname.empty()) { msgFont.setSize(FONT_SIZE_FOOTNOTE); - pi.pain.text(x + Inset::TEXT_TO_INSET_OFFSET + 6, - y - theFontMetrics(msgFont).maxAscent() - 4, + pi.pain.text(x + Inset::textToInsetOffset() * 5 / 2, + y - theFontMetrics(msgFont).maxAscent() - Inset::textToInsetOffset(), from_utf8(justname), msgFont); } @@ -213,8 +213,8 @@ void RenderGraphic::draw(PainterInfo & pi, int x, int y) const docstring const msg = statusMessage(params_, loader_.status()); if (!msg.empty()) { msgFont.setSize(FONT_SIZE_TINY); - pi.pain.text(x + Inset::TEXT_TO_INSET_OFFSET + 6, - y - 4, msg, msgFont); + pi.pain.text(x + Inset::textToInsetOffset() * 5 / 2, + y - Inset::textToInsetOffset(), msg, msgFont); } } } diff --git a/src/insets/RenderPreview.cpp b/src/insets/RenderPreview.cpp index 9d7304f..489f37b 100644 --- a/src/insets/RenderPreview.cpp +++ b/src/insets/RenderPreview.cpp @@ -173,7 +173,7 @@ void RenderPreview::draw(PainterInfo & pi, int x, int y) const pi.pain.image(x, y - dim_.asc, dim_.wid, dim_.height(), *image); } else { - int const offset = Inset::TEXT_TO_INSET_OFFSET; + int const offset = Inset::textToInsetOffset(); pi.pain.rectangle(x + offset, y - dim_.asc, -- 2.5.0