Chris2011 / nb-codeoutline

This is a NetBeans plugin which adds a code overview/outline for the current editor.
http://plugins.netbeans.org/plugin/57219/?show=true
39 stars 8 forks source link

Improve scaling quality for files with many lines #24

Open nmatt opened 8 years ago

nmatt commented 8 years ago

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).

markiewb commented 8 years ago

fixed in 1.3.1

markiewb commented 8 years ago

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

nmatt commented 8 years ago

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

markiewb commented 8 years ago

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

markiewb commented 8 years ago

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

p2rkw commented 8 years ago

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

nmatt commented 8 years ago

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.

markiewb commented 8 years ago

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

markiewb commented 8 years ago

@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 commented 8 years ago

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