Skip to content

Allow setting fonts directly, instead of file names #7

@awa-xima

Description

@awa-xima

The Config#setFonts currently accepts a list of font files, and constructs Font objects from that. But we do not always have access to the font files. It would be more flexible to allow setting the Font objects directly. Consider e.g.

import java.awt.font;

// ...

        final var fontSize = (int) (Math.round(HEIGHT * 0.8d));
        final var fonts = List.of(
                new Font("Arial", Font.ITALIC, fontSize),
                new Font("Comic Sans MS", Font.PLAIN, fontSize),
                new Font("Georgia", Font.PLAIN, fontSize),
                new Font("Verdana", Font.PLAIN, fontSize));
        final var config = new Config();
       config.setFonts(fonts); // doesn't work, as it currently only accepts file names as string

The problem with the default behavior of randomly selecting from every font available on the system is that not all installed fonts even support basic latin letters, e.g. fonts such as Noto Sans Sinhala Regular or icon fonts. Then the rendered captcha is not readable.

There's no way to get file paths from fonts, and something like new Font("Arial", Font.ITALIC, fontSize) can resolve to a list of font files:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions