Skip to content

Commit

Permalink
Add font-weight parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLoer committed Jun 27, 2017
1 parent cb70986 commit f73e27f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ Create a TinySDF for drawing SDFs based on font parameters:
var cutoff = 0.25 // Across the board alpha channel reduction
// Reduces low-alpha pixels to zero, "thins" SDF overall

var fontFamily = 'sans-serif'; // css font-family to use
var tinySDFGenerator = new TinySDF(fontsize, buffer, radius, cutoff, fontFamily);
var fontFamily = 'sans-serif'; // css font-family
var fontWeight = 'normal'; // css font-weight
var tinySDFGenerator = new TinySDF(fontsize,
buffer,
radius,
cutoff,
fontFamily,
fontWeight);

var oneSDF = tinySDFGenerator.draw('泽');
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ module.exports = TinySDF;

var INF = 1e20;

function TinySDF(fontSize, buffer, radius, cutoff, fontFamily) {
function TinySDF(fontSize, buffer, radius, cutoff, fontFamily, fontWeight) {
this.fontSize = fontSize || 24;
this.buffer = buffer === undefined ? 3 : buffer;
this.cutoff = cutoff || 0.25;
this.fontFamily = fontFamily || 'sans-serif';
this.fontWeight = fontWeight || 'normal';
this.radius = radius || 8;
var size = this.size = this.fontSize + this.buffer * 2;

this.canvas = document.createElement('canvas');
this.canvas.width = this.canvas.height = size;

this.ctx = this.canvas.getContext('2d');
this.ctx.font = fontSize + 'px ' + this.fontFamily;
/* style | variant | weight | size/line-height | family */
this.ctx.font = `normal normal ${this.fontWeight} ${fontSize}px/normal ${this.fontFamily}`;
this.ctx.textBaseline = 'middle';
this.ctx.fillStyle = 'black';

Expand Down

0 comments on commit f73e27f

Please sign in to comment.