Exemplo n.º 1
0
def make_charlist_text(sfd: Path) -> str:
    text = ""
    for c in sfd_codepoints(sfd):
        if c > 32 and c not in (127, ):
            ch = chr(c)
            text += ch if charwidth(ch) == "W" else f"{ch} "
    return text
Exemplo n.º 2
0
def make_charlist_text(bdf_font: Path) -> str:
    with bdf_font.open() as f:
        bdf = BdfFont.from_bdf(f)
    text = ""
    for c in bdf.codepoints:
        if c > 32 and c not in (127,):
            ch = chr(c)
            text += ch if charwidth(ch) == "W" else f"{ch} "
    return text
Exemplo n.º 3
0
def make_charmap(sfd: Path) -> List[str]:
    text = [
        "        0 1 2 3 4 5 6 7 8 9 A B C D E F",
        "       ┌───────────────────────────────",
    ]
    codepoints = sfd_codepoints(sfd)
    for i in range(0, codepoints[-1] + 16, 16):
        line = ""
        for j in range(16):
            if (cp := i + j) > 32 and cp not in (127,) and cp in codepoints:
                ch = chr(i + j)
            else:
                ch = " "
            line += ch
            if not charwidth(ch) == "W":
                line += " "
        if line := line.rstrip():
            text.append(f"U+{i//16:04X}_│{line}")
Exemplo n.º 4
0
def wrap_text(src: str, width=79) -> Sample:
    sample_h = 1
    running_w = 0
    idx = 0
    linebreaks = []
    while idx < len(src):
        if running_w - int(src[idx] == " ") >= width:
            linebreaks.append(idx - 1)
            running_w = 0
            sample_h += 1
        if any((h := f"${color}$") == src[idx:len(h)]
               for color in default_palette.keys()):
            idx += len(h)
        else:
            running_w += 1 if charwidth(src[idx]) != "W" else 2
            idx += 1
    for idx in reversed(linebreaks):
        src = src[:idx].rstrip() + "\n" + src[idx:].lstrip()
    return Sample(src, width, sample_h)
Exemplo n.º 5
0
def make_charmap(bdf_font: Path) -> List[str]:
    with bdf_font.open() as f:
        bdf = BdfFont.from_bdf(f)
    text = [
        "       0 1 2 3 4 5 6 7 8 9 A B C D E F",
        "      ┌───────────────────────────────",
    ]
    codepoints = sorted(bdf.codepoints)
    for i in range(0, codepoints[-1] + 16, 16):
        line = ""
        for j in range(16):
            if (cp := i + j) > 32 and cp not in (127,) and cp in codepoints:
                ch = chr(i + j)
            else:
                ch = " "
            line += ch
            if not charwidth(ch) == "W":
                line += " "
        if line := line.rstrip():
            text.append(f"U+{i//16:03X}_│{line}")