nb-codeoutline icon indicating copy to clipboard operation
nb-codeoutline copied to clipboard

Improve scaling quality for files with many lines

Open nmatt opened this issue 9 years ago • 10 comments

Currently (v1.3), text in different text lines appear to have a different height -- probably an artifact of the scaling algorithm used. It would be nice if the font size could be configured such that each text lines takes up an equal integral number of pixels in height (like for example 2 pixels or 3 pixels). Or else use a "smoother" scaling algorithm (e.g. bicubic).

nmatt avatar Jan 07 '16 00:01 nmatt

fixed in 1.3.1

markiewb avatar Jan 07 '16 20:01 markiewb

@nmatt: Try 1.3.1 and give me feedback https://github.com/markiewb/nb-codeoutline/releases/tag/v1.3.1

markiewb avatar Jan 07 '16 20:01 markiewb

It's improved, but there is still some strange moiréing going on. To illustrate, here is an example with 300 identical lines filled with "M": moire It looks a bit like the scaling is skipping certain rendered text pixel lines, so sometimes it only picks up the middle of the text line (=black) and sometimes only the space between text lines (=white). Here is the same content scaled with Gimp to the same height (using "Cubic" interpolation): gimp

nmatt avatar Jan 08 '16 19:01 nmatt

Strange. I will have a look. Perhaps I should disable anti-aliasing before scaling

markiewb avatar Jan 10 '16 21:01 markiewb

Yes it looks strange. I can reproduce it. There is some logic regarding height.

If you like, you can debug it and fix it. https://github.com/markiewb/nb-codeoutline/blob/master/src/main/java/bluej/editor/moe/NaviView.java

markiewb avatar Jan 11 '16 19:01 markiewb

Did you tried http://docs.oracle.com/javase/tutorial/2d/advanced/quality.html ?

p2rkw avatar Jan 11 '16 23:01 p2rkw

Ok, the way it is currently implemented, i.e. rendering the text at a very small size into a buffer with the same height as the target area, probably can't ever look right. This is because the text rendering logic will render the text line by line into the buffer, where each line has only a fractional pixel height. This can't possibly produce high-quality results.

What needs to be done is to render the text into a much larger buffer, so that each text line is rendered with multiple pixels in height (preferably an integral (non-fractional) number of pixels to avoid aliasing differences between lines), and then scale this buffer down into the target graphics context. For very large files (10.000's of lines or more), this probably should be done in chunks to avoid out-of-memory due to buffer size.

nmatt avatar Jan 12 '16 01:01 nmatt

Perhaps that is the reason, why Sublime only shows font-size=1 lines?

markiewb avatar Jan 12 '16 21:01 markiewb

@p2rkw: Thanks for the note. It is already used - see https://github.com/markiewb/nb-codeoutline/blob/master/src/main/java/bluej/editor/moe/NaviView.java#L627

markiewb avatar Jan 12 '16 21:01 markiewb

I won't invest time to fix this issue. I am not using this plugin that often. Thank you for your understanding.

If you like to get it fixed, please provide a pullrequest! I would be happy to integrate it!

The relevant source file is https://github.com/markiewb/nb-codeoutline/blob/master/src/main/java/bluej/editor/moe/NaviView.java

markiewb avatar Jan 23 '16 11:01 markiewb