Code Monkey home page Code Monkey logo

sdf-glyph-foundry's Introduction

sdf-glyph-foundry

Build Status

A library that delivers glyphs rendered as SDFs (signed distance fields). We use these encoded glyphs as the basic blocks of font rendering in Mapbox GL. SDF encoding is superior to traditional fonts for our usecase in terms of scaling, rotation, and quickly deriving halos - WebGL doesn't have built-in font rendering, so the decision is between vectorization, which tends to be slow, and SDF generation.

The approach this library takes is to parse and rasterize the font with Freetype (hence the C++ requirement), and then generate a distance field from that rasterized image.

This library is used by node-fontnik to generate SDF glyphs on the server side, and may be used in the future in Mapbox GL Native to locally generate SDFs when a system font is available and appropriate.

Using sdf-glyph-foundry

The glyph foundry is a header-only library. To successfully build it within your project you must also include Boost, Freetype, and Zlib. After pulling the include paths in to your project, use it like this:

#include <mapbox/glyph_foundry.hpp>
#include <mapbox/glyph_foundry_impl.hpp>

...

sdf_glyph_foundry::glyph_info glyph; // Fill with glyph request information
sdf_glyph_foundry::RenderSDF(glyph_info &glyph,
               int size,
               int buffer,
               float cutoff,
               FT_Face ft_face);

// SDF bitmap is returned in glyph.bitmap

Testing

Building the sdf-glyph-foundry tests depend on:

  • make
  • git
  • curl
  • a c++11 capable compiler

Once you have these things then you can run:

make test

This will automatically install boost and freetype locally using mason, and build a simple test harness that compares the library results to known SDFs.

Background reading

sdf-glyph-foundry's People

Contributors

chrisloer avatar mapsam avatar

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.