IDEA-161827 use line metrics to paint underwave

This commit is contained in:
Sergey Malenkov
2016-10-10 13:24:12 +03:00
parent 1153b60414
commit 07e3ddc1df
@@ -119,6 +119,9 @@ public enum EffectPainter implements RegionPainter<Font> {
if (!Registry.is("ide.text.effect.new")) {
WavePainter.forColor(g.getColor()).paint(g, x, x + width, y + height);
}
else if (Registry.is("ide.text.effect.new.metrics")) {
paintUnderline(g, x, y, width, height, font, 3, this);
}
else if (width > 0 && height > 0) {
Cached.WAVE_UNDERSCORE.paint(g, x, y, width, height, null);
}
@@ -166,6 +169,10 @@ public enum EffectPainter implements RegionPainter<Font> {
LineMetrics metrics = font.getLineMetrics("", g.getFontRenderContext());
thickness = Math.max(thickness, (int)(0.5 + thickness * metrics.getUnderlineThickness()));
int offset = Math.min(height - thickness, Math.max(1, (int)(0.5 + metrics.getUnderlineOffset())));
if (offset < 1) {
offset = height > 3 ? 1 : 0;
thickness = height - offset;
}
drawLine(g, x, y + offset, width, thickness, painter);
}
else {
@@ -198,6 +205,9 @@ public enum EffectPainter implements RegionPainter<Font> {
int dw = (w % height + height) % height;
Cached.BOLD_DOTTED_UNDERSCORE.paint(g, x - dx, y, dw == 0 ? w : w - dw + height, height, null);
}
else if (painter == WAVE_UNDERSCORE) {
Cached.WAVE_UNDERSCORE.paint(g, x, y, width, height, null);
}
else {
g.fillRect(x, y, width, height);
}
@@ -223,7 +233,7 @@ public enum EffectPainter implements RegionPainter<Font> {
@Override
int getPeriod(int height) {
return getMaxHeight(height) - 1;
return (Registry.is("ide.text.effect.new.metrics") ? height : getMaxHeight(height)) - 1;
}
@Override
@@ -231,6 +241,22 @@ public enum EffectPainter implements RegionPainter<Font> {
double dx = 0;
double lower = height - 1;
double upper = lower - period;
if (Registry.is("ide.text.effect.new.metrics")) {
if (height > 3) {
float fix = height / 3f;
g.setStroke(new BasicStroke(fix));
if (fix > 1) {
fix = (fix - 1) / 2;
lower -= fix;
upper += fix;
}
}
height += 2;
if (g.getClass().getName().equals("com.intellij.util.HiDPIScaledGraphics")) {
lower += .5;
upper += .5;
}
}
Path2D path = new Path2D.Double();
path.moveTo(dx, lower);
if (height < 6) {