changes font handling for MultiBitStencil

This commit is contained in:
Eyck Jentzsch 2023-06-27 21:20:08 +02:00
parent aaf8a9e5d0
commit abb8b45cd8
2 changed files with 52 additions and 30 deletions

View File

@ -18,10 +18,12 @@ import javax.swing.JPanel;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import com.minres.scviewer.database.BitVector; import com.minres.scviewer.database.BitVector;
import com.minres.scviewer.database.DoubleVal; import com.minres.scviewer.database.DoubleVal;
@ -99,7 +101,7 @@ public class SignalPainter extends TrackPainter {
long scaleFactor = this.waveCanvas.getScale(); long scaleFactor = this.waveCanvas.getScale();
long beginPos = area.x; long beginPos = area.x;
long beginTime = beginPos*scaleFactor; long beginTime = beginPos*scaleFactor;
long endTime = beginTime + area.width*scaleFactor; long endTime = beginTime + area.width*scaleFactor;
EventEntry first = signal.getEvents().floorEntry(beginTime); EventEntry first = signal.getEvents().floorEntry(beginTime);
if (first == null) if (first == null)
@ -137,24 +139,27 @@ public class SignalPainter extends TrackPainter {
SignalStencil stencil = getStencil(proj.getGC(), left, entries); SignalStencil stencil = getStencil(proj.getGC(), left, entries);
if(stencil!=null) do { if(stencil!=null) {
stencil.draw(proj, area, left.value, right.value, xSigChangeBeginPos, xSigChangeEndPos, multiple); do {
if (right.time >= endTime) stencil.draw(proj, area, left.value, right.value, xSigChangeBeginPos, xSigChangeEndPos, multiple);
break; if (right.time >= endTime)
left.assign(right); break;
xSigChangeBeginPos = xSigChangeEndPos; left.assign(right);
right.set(entries.higherEntry(left.time), endTime); xSigChangeBeginPos = xSigChangeEndPos;
xSigChangeEndPos = getXPosEnd(right.time); right.set(entries.higherEntry(left.time), endTime);
multiple = false; xSigChangeEndPos = getXPosEnd(right.time);
if (xSigChangeEndPos == xSigChangeBeginPos) { multiple = false;
multiple = true; if (xSigChangeEndPos == xSigChangeBeginPos) {
long eTime = (xSigChangeBeginPos + 1) * this.waveCanvas.getScale(); multiple = true;
EventEntry entry = entries.floorEntry(eTime); long eTime = (xSigChangeBeginPos + 1) * this.waveCanvas.getScale();
if(entry!=null && entry.timestamp> right.time) EventEntry entry = entries.floorEntry(eTime);
right.set(entry, endTime); if(entry!=null && entry.timestamp> right.time)
xSigChangeEndPos = getXPosEnd(eTime); right.set(entry, endTime);
} xSigChangeEndPos = getXPosEnd(eTime);
} while (left.time < endTime); }
} while (left.time < endTime);
stencil.dispose();
}
} }
private SignalStencil getStencil(GC gc, SignalChange left, IEventList entries) { private SignalStencil getStencil(GC gc, SignalChange left, IEventList entries) {
@ -178,17 +183,24 @@ public class SignalPainter extends TrackPainter {
private interface SignalStencil { private interface SignalStencil {
public void draw(Projection proj, Rectangle area, IEvent left, IEvent right, int xBegin, int xEnd, boolean multiple); public void draw(Projection proj, Rectangle area, IEvent left, IEvent right, int xBegin, int xEnd, boolean multiple);
public void dispose();
} }
private class MultiBitStencil implements SignalStencil { private class MultiBitStencil implements SignalStencil {
private java.awt.Font tmpAwtFont; private java.awt.Font tmpAwtFont;
private int height; private int height;
private Font font;
public MultiBitStencil(GC gc) { public MultiBitStencil(GC gc) {
FontData fd = gc.getFont().getFontData()[0]; FontData fd = gc.getFont().getFontData()[0];
height = gc.getDevice().getDPI().y * fd.getHeight() / 72; height = gc.getDevice().getDPI().y * fd.getHeight() / 72;
tmpAwtFont = new java.awt.Font(fd.getName(), fd.getStyle(), height); tmpAwtFont = new java.awt.Font(fd.getName(), fd.getStyle(), (height+1)*3/4); // determines the length of the box
font = new Font(Display.getCurrent(), "monospace", (height+1)/2, 0); // determines the size of the labels
}
public void dispose() {
font.dispose();
} }
public void draw(Projection proj, Rectangle area, IEvent left, IEvent right, int xBegin, int xEnd, boolean multiple) { public void draw(Projection proj, Rectangle area, IEvent left, IEvent right, int xBegin, int xEnd, boolean multiple) {
@ -241,8 +253,11 @@ public class SignalPainter extends TrackPainter {
if (width > (bb.x+1)) { if (width > (bb.x+1)) {
Rectangle old = proj.getClipping(); Rectangle old = proj.getClipping();
proj.setClipping(xBegin + 3, yOffsetT, xEnd - xBegin - 5, yOffsetB - yOffsetT); proj.setClipping(xBegin + 3, yOffsetT, xEnd - xBegin - 5, yOffsetB - yOffsetT);
Font old_font = proj.getGC().getFont();
proj.getGC().setFont(font);
proj.drawText(label+ext, xBegin + 3, yOffsetM - bb.y / 2 - 1); proj.drawText(label+ext, xBegin + 3, yOffsetM - bb.y / 2 - 1);
proj.setClipping(old); proj.setClipping(old);
proj.getGC().setFont(old_font);
} }
break; break;
} }
@ -291,6 +306,8 @@ public class SignalPainter extends TrackPainter {
} }
public void dispose() { }
public void draw(Projection proj, Rectangle area, IEvent left, IEvent right, int xBegin, int xEnd, boolean multiple) { public void draw(Projection proj, Rectangle area, IEvent left, IEvent right, int xBegin, int xEnd, boolean multiple) {
BigInteger leftVal = signed?((BitVector)left).toSignedValue():((BitVector)left).toUnsignedValue(); BigInteger leftVal = signed?((BitVector)left).toSignedValue():((BitVector)left).toUnsignedValue();
BigInteger rightVal= signed?((BitVector)right).toSignedValue():((BitVector)right).toUnsignedValue(); BigInteger rightVal= signed?((BitVector)right).toSignedValue():((BitVector)right).toUnsignedValue();
@ -320,6 +337,8 @@ public class SignalPainter extends TrackPainter {
} }
private class SingleBitStencil implements SignalStencil { private class SingleBitStencil implements SignalStencil {
public void dispose() { }
public void draw(Projection proj, Rectangle area, IEvent left, IEvent right, int xBegin, int xEnd, boolean multiple) { public void draw(Projection proj, Rectangle area, IEvent left, IEvent right, int xBegin, int xEnd, boolean multiple) {
if (multiple) { if (multiple) {
proj.setForeground(waveCanvas.styleProvider.getColor(WaveformColors.SIGNALU)); proj.setForeground(waveCanvas.styleProvider.getColor(WaveformColors.SIGNALU));
@ -405,6 +424,8 @@ public class SignalPainter extends TrackPainter {
} }
} }
public void dispose() { }
public void draw(Projection proj, Rectangle area, IEvent left, IEvent right, int xBegin, int xEnd, boolean multiple) { public void draw(Projection proj, Rectangle area, IEvent left, IEvent right, int xBegin, int xEnd, boolean multiple) {
double leftVal = ((DoubleVal) left).value; double leftVal = ((DoubleVal) left).value;
double rightVal= ((DoubleVal) right).value; double rightVal= ((DoubleVal) right).value;

View File

@ -168,8 +168,9 @@ public class BitVector implements IEvent {
} }
} }
} }
if(res[i]==0) if(res[i]==0) {
res[i] = Character.forDigit(digit, 16); // ((digit < 10) ? '0' + digit : 'a' + digit -10) res[i] = (digit < 10) ? (char)('0' + digit) : (char)('A' - 10 + digit);
}
start_idx=3; start_idx=3;
} }
int idx=0; int idx=0;