Giter Club home page Giter Club logo

p5-hershey-js's Introduction

p5.js Hershey Vector Font Library. (Live Demo)

The Hershey fonts are a collection of vector fonts developed c. 1967 by Dr. Allen Vincent Hershey at the Naval Weapons Laboratory, originally designed to be rendered using vectors on early cathode ray tube displays. The fonts are publicly available and have few usage restrictions. Vector fonts are easily scaled and rotated in two or three dimensions; consequently the Hershey fonts have been widely used in computer graphics, computer-aided design programs, and more recently also in computer-aided manufacturing applications like laser engraving. (Wikipedia)

This p5.js library renders the Hershey fonts in the browser. It can parse user-provided Hershey fonts along with custom character mapping.

Supported Character Sets

Roman Gothic Greek Other
COMPLEX GOTHIC_ENGLISH_TRIPLEX GREEK_COMPLEX ITALIC_COMPLEX
COMPLEX_SMALL GOTHIC_GERMAN_TRIPLEX GREEK_COMPLEX_SMALL ITALIC_COMPLEX_SMALL
DUPLEX GOTHIC_ITALIAN_TRIPLEX GREEK_PLAIN ITALIC_TRIPLEX
PLAIN GREEK_SIMPLEX SCRIPT_COMPLEX
SIMPLEX SCRIPT_SIMPLEX
TRIPLEX CYRILLIC_COMPLEX

Usage

Minimal Example

In HTML, include the library as well as the data file.

<script src="p5.hershey.js"></script>  
<script src="p5.hershey.data.js"></script>  

And in the p5 sketch javascript, call P5.hershey.putText

push();
translate(100,100);
noFill();
stroke(0);
strokeWeight(1);
P5.hershey.putText("Hello World!");
pop();

Advanced

P5.hershey.putText("Hello World!",{
	cmap:  FONT_HERSHEY.GOTHIC_GERMAN_TRIPLEX,
	align: "center",
	noise: 0.5,
});
  • cmap specifies the character mapping to use, see Supported Character Sets for details.
  • align can be one of left, center or right.
  • noise can be used to add special effects to the vertices. noise can be either of the following datatypes:
    • if noise is a number, a default randomGaussian filter is applied to give a jiggly/nervous effect using noise as the standard deviation.
    • if noise is an object of the form {x: (x,y)=>(x_offset), y: (x,y)=>(y_offset)}, noise.x and noise.y will be called on each vertex, and the return value is used as the offset for the respective axis.

Custom Fonts

Users can also provide their own Hershey fonts and mappings. To parse a correctly formatted Hershey font as a string, use:

var font_data = P5.hershey.parseFontString("   49 12LXRMRV RNOOPOSQTSTUSUPVO");

A mapping from unicode entry point to the index used by the hershey font is also required. If the indices are identical, this can be as simple as:

var cmap = (x)=>(x);

Say you have a more complicated mapping, where characters A,B,C,D will be mapped to indices 2,4,6,8 in the Hershey font:

var cmap = (x)=>([2,4,6,8][x-65]);

Finally feed the font and the mapping to P5.hershey.putText:

P5.hershey.putText("Hello World!",{
	font:  font_data,
	cmap:  cmap,
});

Other Tools

  • P5.hershey.estimateTextWidth(text, args) returns the width in pixels of the text if it is to be drawn with arguments args.
  • P5.hershey.validateFont(font_data) returns an Array containing indices of all the invalid glyphs in a font object.

Examples

  • Live Demo, see index.html for details.
  • ttf2hershey, a tool for converting True Type Fonts to Hershey fonts.

Preview

References

p5-hershey-js's People

Contributors

lingdong- avatar lynneyun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

p5-hershey-js's Issues

Loading Custom Font

Hi Ling Dong!

I have successfully output-ed the json file and i am so lost on how to load my output with this project, despite after reading the custom font section as i have very little programming background

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.