Noto-sans-mono-bitmap (Rust library)

Overview

noto-sans-mono-bitmap (Rust library)

Pre-rasterized bitmap font from "Noto Sans Mono", an open font from Google.

Strictly speaking, this crate is more than a basic bitmap font, because it encodes each pixel as a byte and not as a bit, which results in a much nicer result on the screen.

TL;DR

  • no_std, zero allocations, no floating point operations
  • most important symbols, numbers, and letters as pre-rasterized bitmap
  • Noto Sans Mono font as base
  • different sizes and font weights (light, normal, bold)
  • nice anti-aliasing/smoothing and better looking than legacy bitmap fonts
  • every pixel is encoded in a byte (0-255) and not a bit, which results in a much nicer result on the screen.
  • relevant font sizes: 14, 16, 24, 32, and 64px (as optional build time features)

Screenshot of the bitmap font.

Terminology: Is Bitmap Font The Right Term?

Legacy (8x8) bitmap fonts usually refer to a font where each symbol is encoded in 8 bytes. The ones in a byte (0b00110000) means "pixel on" and the zeroes' means "pixel off". However, my bitmap font actually encodes the intensity of each pixel as a byte from 0 to 255. Hence, this is less size efficient than legacy bitmap fonts, but looks much better. I still use the term bitmap font, because that term is used and known when talking about pre-rasterized fonts/font rendering in an early stage of the boot process.

When To Use This Crate

If you develop a kernel, you usually don't want to use the FPU (i.e. only soft float), because otherwise you need to save the floating point registers on every context switch, which is expensive. Because nice font rendering of TTF fonts heavily relies on many floating point operations, this is not optimal inside a kernel (noticeable performance penalties). Furthermore, in my experience it was hard to get some of the popular font rasterization crates to compile with CPU features "+soft-float" and "-sse" (at least on x86_64).

Legacy 8x8 bitmap fonts are ugly when printed to the screen. My crate can be seen as a nice replacement with very nice anti-aliasing.

If you have a standard environment or support for floating point operations, you might want to rasterize the font by yourself with the crate fontdue and some TTF fonts rather than using my crate.

Minimal Code Example

use noto_sans_mono_bitmap::{get_bitmap, get_bitmap_width, BitmapHeight, FontWeight};

// Minimal example.
fn main() {
    let width = get_bitmap_width(FontWeight::Regular, BitmapHeight::Size16);
    println!(
        "Each char of the mono-spaced font will be {}px in width if the font \
         weight={:?} and the bitmap height={}",
        width,
        FontWeight::Regular,
        BitmapHeight::Size16.val()
    );
    let bitmap_char = get_bitmap('A', FontWeight::Regular, BitmapHeight::Size16).expect("unsupported char");
    println!("{:?}", bitmap_char);
    for (row_i, row) in bitmap_char.bitmap().iter().enumerate() {
        for (col_i, pixel) in row.iter().enumerate() {
            println!("[{:02}][{:02}]: {:03}", row_i, col_i, pixel);
        }
    }
}

Cargo Build Time Features

If all Cargo features are available, this bitmap fonts supports light, regular, and bold, but no italic style, because Noto Sans Mono doesn't have an italic TTF file. The rasterization was done with the awesome fontdue-Crate.

By default, all sizes and font styles/weights are included via the cargo feature all. This can be restricted by only using features such as regular and size_14. Anyhow, a test of mine showed, that including all features in a release build only increases the file size by a few dozen to a few hundred kilobytes. The Rust compiler is really smart throwing out unused parts of the bitmap font, even if they are included as dependency. Your binary will not be bloated by a few megabytes, according to my findings.

The bitmap font includes the following unicode range:

  • BASIC LATIN,
  • LATIN 1 Supplement
  • LATIN EXTENDED-A

This means unicode symbols from 0 .. 0x17f, hence letters and symbols from a QWERTZ/QWERTY keyboard plus symbols such as Ö, Ä, and Ü. Control characters are not included.

Quick Demo

$ cargo run --example show_chars_in_window

Build Prerequisites

Because the examples uses "minifb" as dependency, on Linux the package libxkbcommon-dev is required to run them. This is not necessary, if you just use this crate as dependency.

License

See LICENSE file in repository.

MSRV

Rust stable 1.52.1.

You might also like...
An asynchronous Rust client library for the Hashicorp Vault API

vaultrs An asynchronous Rust client library for the Hashicorp Vault API The following features are currently supported: Auth AppRole JWT/OIDC Token Us

Culture ship names in a rust library.

General Systems Vehicles Culture Ships In case you ever needed Iain M. Banks's Culture ship names as a service. Names sourced from the pleasingly exte

Modrinth API is a simple library for using, you guessed it, the Modrinth API in Rust projects

Modrinth API is a simple library for using, you guessed it, the Modrinth API in Rust projects. It uses reqwest as its HTTP(S) client and deserialises responses to typed structs using serde.

Wrapper library for utilizing DigitalOcean API v2 in Rust

doapi-rs Wrapper library for utilizing DigitalOcean API v2 in Rust Disclaimer This library is in alpha - it may do anything up to, and including, eati

Rust LZ4 bindins library

lz4 This repository contains binding for lz4 compression library (https://github.com/Cyan4973/lz4). LZ4 is a very fast lossless compression algorithm,

Serenity is a Rust library for the Discord API
Serenity is a Rust library for the Discord API

serenity Serenity is a Rust library for the Discord API. View the examples on how to make and structure a bot. Serenity supports bot login via the use

Deser: an experimental serialization and deserialization library for Rust

deser: an experimental serialization and deserialization library for Rust Deser is an experimental serialization system for Rust. It wants to explore

An (unofficial) Rust library for querying db-ip.com data

db_ip An (unofficial) library for querying db-ip.com CSV databases in safe Rust. This library is not affiliated with or endorsed by db-ip.com. Be advi

Quinine is a Rust library that implements atomic, lock-free, but write-once versions of containers like `Box` or `Arc`

Quinine is a Rust library that implements atomic, lock-free, but write-once versions of containers like `Box` or `Arc`

Releases(v0.2.0)
  • v0.2.0(Oct 7, 2022)

    v0.2.0 (2022-10-07)

    • Breaking renamed get_bitmap to get_raster
    • Breaking renamed get_bitmap_width to get_raster_width
    • Breaking renamed BitmapHeight to RasterHeight
    • Breaking Now there are only the following RasterHeight available: 16, 20, 24, 32. Otherwise the space requirements are too big, especially, if new symbols are added in the future.
    • it's clear now which unicode ranges are supported: check the Cargo.toml's feature section
    • changed the amount and naming of modules that are offered
      • now, there is a *_default and *_all module for font-weight, raster height, and unicode ranges

    Furthermore, I investigated the impact on size. The crate size (what needs to be downloaded) is relatively high. It is multiple MiB. However, after compilation, this is very small. The compiler reliably discards unused code paths. For example, if basic-latin and latin-1-supplement are used with FontWeight::Regular and RasterHeight::14, then the overhead is less than 200KiB. If the full support of all currently supported font weights and raster heights is needed, this adds about 5 MiB to the binary.

    While the compiler can reliable discards unused font weights, it can not reliably discard unused unicode ranges. Usually, if you pass a char to get_raster, the whole variety of unicode ranges can be reached. Thus, Rust doesn't discard unused ranges. Hence, it is recommended to only select the unicode ranges that you do need.

    Source code(tar.gz)
    Source code(zip)
Owner
Philipp Schuster
Hello, I'm Philipp. I'm studying computer science at TU Dresden and I love coding. I'm especially interested in operating systems and low-level code.
Philipp Schuster
A highly modular Bitcoin Lightning library written in Rust. Its Rust-Lightning, not Rusty's Lightning!

Rust-Lightning is a Bitcoin Lightning library written in Rust. The main crate, lightning, does not handle networking, persistence, or any other I/O. Thus, it is runtime-agnostic, but users must implement basic networking logic, chain interactions, and disk storage. More information is available in the About section.

Lightning Dev Kit 850 Jan 3, 2023
Rust library that can be reset if you think it's slow

GoodbyeKT Rust library that can be reset if you think it's slow

null 39 Jun 16, 2022
Notion Offical API client library for rust

Notion API client library for rust.

Jake Swenson 65 Dec 26, 2022
Rust library for program synthesis of string transformations from input-output examples 🔮

Synox implements program synthesis of string transformations from input-output examples. Perhaps the most well-known use of string program synthesis in end-user programs is the Flash Fill feature in Excel. These string transformations are learned from input-output examples.

Anish Athalye 21 Apr 27, 2022
SE3 Rust library for Robotics

Algebraic Robots A small Rust Library for SE3 Supported: Twist Screw SE3 Group se3 algebra Adjoint SE3 Twist Chains Wrenches Future plans: Jacobians V

Pau Carré Cardona 4 Jul 18, 2021
Rust library for emulating RISC-V rv32imac

This library can execute instructions against any memory and register file that implements the required primitives in the traits lib_rv32::traits::{Memory, RegisterFile}. This is to encourage usage with whatever frontend you desire.

Trevor McKay 14 Dec 7, 2022
Yet another ROS2 client library written in Rust

RclRust Target CI Status Document Foxy (Ubuntu 20.04) Introduction This is yet another ROS2 client library written in Rust. I have implemented it inde

rclrust 42 Dec 1, 2022
A boiler plate code to create dynamic link library in rust.

?? rust-dll-bp This is a boiler plate code that will be generated as a dll binary. I personally cache this here for me but if you're intend to create

s3pt3mb3r 9 Nov 7, 2022
Rust telegram bot library for many runtimes

Telbot Telbot provides telegram bot types and api wrappers. Specifically, telbot now supports: telbot-types: basic telegram types / requests / respons

kiwiyou 17 Dec 3, 2022
Strongly typed Gura library for Rust

Serde Gura This crate is a Rust library for using the Serde serialization framework with data in Gura file format. This library does not re-implement

Gura Config Lang 12 Nov 14, 2022