[prev in list] [next in list] [prev in thread] [next in thread]
List: kwrite-devel
Subject: Re: katepart: tighter line spacing
From: Matt Rogers <mattr () kde ! org>
Date: 2009-03-28 18:54:50
Message-ID: 200903281354.50658.mattr () kde ! org
[Download RAW message or body]
On Thursday 26 March 2009 23:14:37 Javier Guerra wrote:
> Hi.
>
> i've been checking why Kate shows so much white space between lines in
> KDE4. in fact, it's the biggest thing i still prefer in KDE3.5
>
> so, looking (for the first time) on Kate's source, i found that it uses
> config()->fontMetrics().height() to get line height. But Qt docs define
> QFontMetrics::height() as "the height of the font", while
> QFontMetrics::lineSpacing() is "the distance from one base line to the
> next. This value is always equal to leading()+height()." Replacing
> height() with lineSpacing() does result in tighter lines, it seems that at
> least monospaced fonts have a negative leading().
>
> so, here's the patch. it's very trivial, and since i didn't find any other
> use of height() outside of katerenderer.cpp, i hope it doesn't break
> anything.
>
>
> diff -ur trunk/katerenderer.cpp new/katerenderer.cpp
> --- trunk/katerenderer.cpp 2009-03-26 22:47:07.000000000 -0500
> +++ new/katerenderer.cpp 2009-03-26 22:54:30.000000000 -0500
> @@ -208,7 +208,7 @@
> }
>
> // Draw line background
> - paint.fillRect(0, 0, xEnd - xStart, config()->fontMetrics().height() *
> layout->viewLineCount(), backgroundColor); + paint.fillRect(0, 0, xEnd -
> xStart, config()->fontMetrics().lineSpacing() * layout->viewLineCount(),
> backgroundColor);
>
> // paint the current line background if we're on the current line
> if (currentViewLine != -1) {
> @@ -223,7 +223,7 @@
> );
> }
>
> - paint.fillRect(0, config()->fontMetrics().height() * currentViewLine,
> xEnd - xStart, config()->fontMetrics().height(), currentLineColor); +
> paint.fillRect(0, config()->fontMetrics().lineSpacing() * currentViewLine,
> xEnd - xStart, config()->fontMetrics().lineSpacing(), currentLineColor); }
> }
>
> @@ -268,7 +268,7 @@
> QPen penBackup( paint.pen() );
> paint.setPen( config()->tabMarkerColor() );
>
> - const int height = config()->fontMetrics().height();
> + const int height = config()->fontMetrics().lineSpacing();
> const int top = 0;
> const int bottom = height-1;
> const int h = bottom - top + 1;
> @@ -449,7 +449,7 @@
> // Draws the dashed underline at the start of a folded block of text.
> if (range->startsInvisibleBlock()) {
> paint.setPen(QPen(config()->wordWrapMarkerColor(), 1, Qt::DashLine));
> - paint.drawLine(0, (fm.height() * range->viewLineCount()) - 1, xEnd -
> xStart, (fm.height() * range->viewLineCount()) - 1); + paint.drawLine(0,
> (fm.lineSpacing() * range->viewLineCount()) - 1, xEnd - xStart,
> (fm.lineSpacing() * range->viewLineCount()) - 1); }
>
> if (range->layout()) {
> @@ -531,9 +531,9 @@
>
> if (draw) {
> int fillStartX = line.endX() - line.startX() + line.xOffset() -
> xStart; - int fillStartY = fm.height() * i;
> + int fillStartY = fm.lineSpacing() * i;
> int width= xEnd - xStart - fillStartX;
> - int height= fm.height();
> + int height= fm.lineSpacing();
>
> // reverse X for right-aligned lines
> if (range->layout()->textOption().alignment() == Qt::AlignRight)
> @@ -558,7 +558,7 @@
> // Draw tab stops and trailing spaces
> if (showTabs() || showTrailingSpaces()) {
> const QString& text = range->textLine()->string();
> - int y = fm.height() * i + fm.ascent() - fm.strikeOutPos();
> + int y = fm.lineSpacing() * i + fm.ascent() - fm.strikeOutPos();
>
> if (showTabs()) {
> int tabIndex = text.indexOf(tabChar, line.startCol());
> @@ -588,9 +588,9 @@
> if ( (range->viewLineCount() > 1) && range->shiftX() &&
> (range->shiftX() > xStart) ) {
> if (backgroundBrushSet)
> - paint.fillRect(0, fm.height(), range->shiftX() - xStart,
> fm.height() * (range->viewLineCount() - 1), + paint.fillRect(0,
> fm.lineSpacing(), range->shiftX() - xStart, fm.lineSpacing() *
> (range->viewLineCount() - 1), backgroundBrush);
> - paint.fillRect(0, fm.height(), range->shiftX() - xStart, fm.height()
> * (range->viewLineCount() - 1), + paint.fillRect(0, fm.lineSpacing(),
> range->shiftX() - xStart, fm.lineSpacing() * (range->viewLineCount() - 1),
> QBrush(config()->wordWrapMarkerColor(), Qt::Dense4Pattern)); }
>
> @@ -643,7 +643,7 @@
> paint.setPen(QPen(c, caretWidth));
>
> // Clip the caret - Qt's caret has a habit of intruding onto other
> lines - paint.setClipRect(0, line.lineNumber() * fm.height(), xEnd -
> xStart, fm.height()); + paint.setClipRect(0, line.lineNumber() *
> fm.lineSpacing(), xEnd - xStart, fm.lineSpacing());
>
> range->layout()->drawCursor(&paint, QPoint(-xStart,0),
> cursor->column(), caretWidth);
>
> @@ -654,7 +654,7 @@
> const KateTextLayout& lastLine =
> range->viewLine(range->viewLineCount() - 1); int x =
> range->widthOfLastLine() + spaceWidth() * (cursor->column() -
> range->length()); if ( (x >= xStart) && (x <= xEnd))
> - paint.fillRect(x, (int)lastLine.lineLayout().y(), caretWidth,
> fm.height(), c); + paint.fillRect(x,
> (int)lastLine.lineLayout().y(), caretWidth, fm.lineSpacing(), c); }
> }
> }
> @@ -664,7 +664,7 @@
> {
> paint.setPen( config()->wordWrapMarkerColor() );
> int _x = m_doc->config()->wordWrapAt() * fm.width('x') - xStart;
> - paint.drawLine( _x,0,_x,fm.height() );
> + paint.drawLine( _x,0,_x,fm.lineSpacing() );
> }
> }
>
> @@ -680,7 +680,7 @@
>
> uint KateRenderer::fontHeight()
> {
> - return config()->fontMetrics().height();
> + return config()->fontMetrics().lineSpacing();
> }
>
> uint KateRenderer::documentHeight()
> @@ -833,7 +833,7 @@
> lineLayout->setShiftX(shiftX);
> }
>
> - height += config()->fontMetrics().height();
> + height += config()->fontMetrics().lineSpacing();
> }
>
> l->endLayout();
do you have a before and after screenshot? Can you also attach the patch
explicitly rather than inlining it in the email?
Thanks
--
Matt
_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic