Coder Social home page Coder Social logo

flyingyizi / embedded-fonts Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 0.0 1.51 MB

split and convert the ttf/pcf/bdf fonts into the internal data structure and text renderer for use with embedded-graphics

License: Apache License 2.0

Rust 100.00%
bdf chinese cjk font split ttf embedded-grahics

embedded-fonts's Introduction

Introduction

althrough embedded-graphics defaultly support mono fonts. but is it not enough for other language, e.g. chinese, kerea, japan and so on.

This project includes a small tool convert-bdf to split(optional) and convert the BDF file format into the internal data structure for text render by the embedded-graphics library. this work is based on embedded-graphic BDF utils. attention: below section also describe how to convert ttf/pcf to bdf.

With this crate, you can only import the required glyphs into your project. For example, only 35 characters "**欢迎China welcomes日本へようこそWelcome to Japan북한 환영Welcome North Korea" are introduced, which is very meaningful in MCUs with limited space, such as avr.

convert-bdf tool introduction

tool convert-bdf to split(optional) and convert the BDF file format into the internal data structure for text render by the embedded-graphics library.

convert-bdf result is rust code, the result can be merge to you rust crate to display text. usage please refer the examples.

install/uninstall convert-bdf

install binary convert-bdf through below command:

# install
#$ cargo install --path . --features build-binary
$ cargo install --git https://github.com/flyingyizi/embedded-fonts --features build-binary                                          
  Updating git repository `https://github.com/flyingyizi/embedded-fonts`                  
  Installing embedded-fonts v0.1.0 (https://github.com/flyingyizi/embedded-fonts#ac02aec3)
  ....
  Installing D:\prog\Scoop\persist\rustup\.cargo\bin\convert-bdf.exe
   Installed package `embedded-fonts v0.1.0 (https://github.com/flyingyizi/embedded-fonts#ac02aec3)` (executable `convert-bdf.exe`) 

#uninstall
$ cargo install --list
  ....
embedded-fonts v0.1.0 (https://github.com/flyingyizi/embedded-fonts#ac02aec3):
    convert-bdf.exe
  .....
$ cargo uninstall -p embedded-fonts
    Removing ~\.cargo\bin\convert-bdf.exe

#help information
$ convert-bdf --help
convert-bdf

USAGE:
    convert-bdf [OPTIONS] <BDF_FILE>

ARGS:
    <BDF_FILE>    BDF input

OPTIONS:
    -h, --help                       Print help information
    -o, --output <OUTPUT>            output rust embedded glyphs [default: ./]

        --range <RANGE>              export characters list,defaultly export all glyphs in the bdf.
                                     e.g --range "abc" means only export a,b and c code's glyphs.
                                     if exist range and range-* options at the same time. merge them
                                     as final exporting glyphs scope
        --range-file <RANGE_FILE>    same as range option, but through characters file.
        --range-path <RANGE_PATH>    same as range option, but through rust source directory. it
                                     will colllect the first paraments of all Text::new stmts as the
                                     characters list

$convert-bdf  --range "中國zhongguo"  wenquanyi_12pt.bdf
output rust glyphs file :"./wenquanyi_12pt.rs"

$convert-bdf --range-path ./examples .\examples\testdata\wenquanyi_12pt.bdf
output rust glyphs file :"./wenquanyi_12pt.rs"

BDF to rust-file conversion

Use the tool convert-bdf (part of this project) to create a rust-file:

$ convert-bdf   --range "**欢迎China welcomes日本へようこそWelcome to Japan북한 환영Welcome North Korea"   wenquanyi_12pt.bdf

TTF (truetype font) conversion

Overview

This is the conversion procedure for truetype fonts:

  • 1.Find out a suitable point size (ftview)
  • 2.Convert TTF to BDF (otf2bdf)
  • 3.Convert BDF to a rust code (convert-bdf)

TTF point size

A truetype font often does not look very well with every point size. You can use the unix command ftview from the freetype tool collection to check the font with different point sizes:

$ftview 8 <fontname>.ttf

Different point sizes can be accessed with cursor up and down. Often it is useful to turn off aliasing by pressing "a".

TTF to BDF conversion

The tool otf2bdf can convert the truetype font into bitmap format (bdf). For a linux environment, otf2bdf should be available as software package.

This conversion is done for a specific point size:

$otf2bdf -p <pointsize> -r 75 -o <fontname>.bdf <fontname>.ttf

The result can be checked with font tools, e.g. fontforge.

BDF to rust-file conversion

refer the tool convert-bdf (part of this project) introduction.

Add font to a project

refer examples

PCF (Portable Compiled Format) conversion

Fonts distributed in the .pcf or .pcf.gz file format are part of the X11 distribution. Steps are:

  • 1.Convert PCF to BDF (pcf2bdf)
  • 2.Convert BDF to the internal representation (through convert-bdf)

pcf2bdf is often available as a software package on a linux system:

for example:

$sudo apt-get install xfonts-wqy

$apt-file list xfonts-wqy
xfonts-wqy: /etc/X11/fonts/misc/xfonts-wqy-1.alias
xfonts-wqy: /etc/fonts/conf.avail/85-xfonts-wqy-1.conf
xfonts-wqy: /usr/share/doc/xfonts-wqy/AUTHORS.gz
xfonts-wqy: /usr/share/doc/xfonts-wqy/LOGO.png
xfonts-wqy: /usr/share/doc/xfonts-wqy/README.gz
xfonts-wqy: /usr/share/doc/xfonts-wqy/changelog.Debian.gz
xfonts-wqy: /usr/share/doc/xfonts-wqy/copyright
xfonts-wqy: /usr/share/fonts/X11/misc/wenquanyi_10pt.pcf
xfonts-wqy: /usr/share/fonts/X11/misc/wenquanyi_11pt.pcf
xfonts-wqy: /usr/share/fonts/X11/misc/wenquanyi_12pt.pcf
xfonts-wqy: /usr/share/fonts/X11/misc/wenquanyi_13px.pcf
xfonts-wqy: /usr/share/fonts/X11/misc/wenquanyi_9pt.pcf

# uncompress , then get bdf file
$sudo apt-get install pcf2bdf
$pcf2bdf -v -o wenquanyi_9pt.bdf  wenquanyi_9pt.pcf 

See the section for truetype conversion for further handling of the BDF file.

Create new BDF fonts

There are several tools available for the creation of new fonts:

gbdfed. fontforge Both tools can export to the BDF file format.

BDF to rust-file conversion

refer the tool convert-bdf (part of this project) introduction.

Add font to a project

refer examples

embedded-fonts's People

Contributors

flyingyizi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

embedded-fonts's Issues

关于预编译生成交流

请问下大佬,rust可以实现编译期使用宏生成style的S_DATA数据或者字体实现类型吗?类似include_bytes!,在编译期从bdf文件中把宏的入参文字转换为字体数据。
我不太清楚rust是否支持限定库的资源文件的生命周期。大概的想法是:
let txt: Text=font!("你好",Point::new(5, 60),Rgb888::BLUE...) 这种,让宏在编译期提取入参文字信息,并生成对应的所需字体数据。

大佬能解答一下我这个想法吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.