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.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import com.minres.scviewer.database.BitVector;
import com.minres.scviewer.database.DoubleVal;
@ -137,7 +139,8 @@ public class SignalPainter extends TrackPainter {
SignalStencil stencil = getStencil(proj.getGC(), left, entries);
if(stencil!=null) do {
if(stencil!=null) {
do {
stencil.draw(proj, area, left.value, right.value, xSigChangeBeginPos, xSigChangeEndPos, multiple);
if (right.time >= endTime)
break;
@ -155,6 +158,8 @@ public class SignalPainter extends TrackPainter {
xSigChangeEndPos = getXPosEnd(eTime);
}
} while (left.time < endTime);
stencil.dispose();
}
}
private SignalStencil getStencil(GC gc, SignalChange left, IEventList entries) {
@ -178,17 +183,24 @@ public class SignalPainter extends TrackPainter {
private interface SignalStencil {
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 java.awt.Font tmpAwtFont;
private int height;
private Font font;
public MultiBitStencil(GC gc) {
FontData fd = gc.getFont().getFontData()[0];
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) {
@ -241,8 +253,11 @@ public class SignalPainter extends TrackPainter {
if (width > (bb.x+1)) {
Rectangle old = proj.getClipping();
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.setClipping(old);
proj.getGC().setFont(old_font);
}
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) {
BigInteger leftVal = signed?((BitVector)left).toSignedValue():((BitVector)left).toUnsignedValue();
BigInteger rightVal= signed?((BitVector)right).toSignedValue():((BitVector)right).toUnsignedValue();
@ -320,6 +337,8 @@ public class SignalPainter extends TrackPainter {
}
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) {
if (multiple) {
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) {
double leftVal = ((DoubleVal) left).value;
double rightVal= ((DoubleVal) right).value;

View File

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