mabe02 / lanterna

Java library for creating text-based GUIs
GNU Lesser General Public License v3.0
2.23k stars 243 forks source link

broken lines when using any Fontsize apart from 12 #541

Closed botboy0 closed 3 years ago

botboy0 commented 3 years ago

I used a monospaced font to make sure it would work with the library. But because of some scaling issue that does not have to do with the Font I use (I checked that) the vertical Lines are broken. Bild_2021-04-19_020553

My code:

`public class Main { public static void main(String[] args) throws IOException {

    // Setup terminal and screen layers

      GraphicsEnvironment ge =  GraphicsEnvironment.getLocalGraphicsEnvironment();
         try {
            ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File("lib/font/fs.ttf")));
        } catch (FontFormatException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    Font font = new Font("Fixedsys Excelsior 3.01", Font.PLAIN, 40);
    SwingTerminalFontConfiguration cfg= new SwingTerminalFontConfiguration(false, BoldMode.NOTHING, font);
    DefaultTerminalFactory factory = new DefaultTerminalFactory();
    factory.setInitialTerminalSize(new TerminalSize(20, 20));
    factory.setTerminalEmulatorFontConfiguration(cfg);
    Terminal terminal = factory.createTerminal();

    Screen screen = new TerminalScreen(terminal);

    screen.startScreen();

    // Create window to hold the panel
    BasicWindow window = new BasicWindow();
    window.setHints(Arrays.asList(Window.Hint.FULL_SCREEN, Window.Hint.NO_DECORATIONS));
    window.setTheme(new SimpleTheme(new TextColor.RGB(255, 255, 255), TextColor.ANSI.BLACK));

    // Create gui and start gui
    MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));

    Panel mainPanel = new Panel();
    mainPanel.setLayoutManager(new LinearLayout(Direction.HORIZONTAL));

    Label label = new Label("Yeet");
    label.setTheme(new SimpleTheme(new TextColor.RGB(255, 255, 255), TextColor.ANSI.BLACK,SGR.FRAKTUR));
    label.addTo(mainPanel);

    window.setComponent(mainPanel.withBorder(Borders.singleLine("Main Panel")));
    gui.addWindowAndWait(window);
}

}`

avl42 commented 3 years ago

Have you tried using that Font with some standard Java multiline text widget and see if the lines touch there?

Can you debug your application with Eclipse or other IDE, and specifically step into the part where the Font is measured by Lanterna, and Lanterna determines the line spacing?

botboy0 commented 3 years ago

Thank you for the quick reply, I am a bit unsure what is meant by a standard multiline text widget , are you referring to something like a content Panel/Action List Box made by Lanterna or a widget I would create in Swing not using Lanterna?

I am using Eclipse and I will try to debug it into showing the measuring of line spacing in Lanterna, but I am a bit unsure how to go about that as well. I am unsure about the point where to debug and look into the variables specifically.

avl42 commented 3 years ago

For the first question: I meant instancing a javax.swing.JTextArea with your specific Font and otherwise all scaling equal. Make it 2 rows high, and either append two of the vertical bar characters with a newline inbetween, or paste them in at runtime.

By debugging, I mean single-stepping through the code and using the "Variables" view to see lanternas variables while you step through the code.

Lanterna has a list of Fonts, and tries to pick characters from whatever Font contains these chars. But different Fonts have different characteristics, and when it scales the Font A (say, the one you supplied) then it also scales Font B (which has the vertical bar)... and if it scales Font B to something a notch smaller, then it might happen that the bar-ends aren't connected.

Your debugging session should finally tell you, which Font it really picks the bars from (from yours or from one of the standard fonts), and what scaling factor it determines and to what degree it then scales your font and the "vertical bar" font.

botboy0 commented 3 years ago

Through editing the Font I got to the point where it actually does work out to a point where I get continuous lines, but for some reason there is still places where there is a single 1-2 pixel gap in the lines.

image

botboy0 commented 3 years ago

thanks this is no longer an issue