Skip to content

Commit fd468ca

Browse files
committed
Adding the rest of the options possible via the font shorthand notation that the canvas context, and therefore, vectorize-text uses
1 parent 0083e1f commit fd468ca

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
vectorize-text
22
==============
3-
Convert a string of text into a vectorized geometric representation. Works in both node.js and [browserify](http://browserify.org/).
3+
Convert a string of text into a vectorized geometric representation. Works in both node.js and [browserify](http://browserify.org/).
44

55
# Example
66

@@ -119,14 +119,18 @@ Renders a string to a 2D cell complex
119119
* `string` is a string of text (single line)
120120
* `options` is an optional object of parameters
121121

122-
+ `options.font` is the font to use (default: `"normal"`)
123-
+ `options.triangles` if set, then output a triangulation
124-
+ `options.polygons` if set, output a list of polygons
122+
+ `options.font` is the font family to use (default: `"normal"`)
123+
+ `options.fontStyle` if set, determines the [font-style](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style)
124+
+ `options.fontVariant` if set, determines the [font-variant](https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant)
125+
+ `options.fontWeight` if set, determines the [font-weight](https://developer.mozilla.org/en/docs/Web/CSS/font-weight)
126+
+ `options.size` is the [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size) used for the rasterization step (determines level of detail of the mesh)
125127
+ `options.textBaseline` determines the baseline, same semantics as the canvas [textBaseline](https://developer.mozilla.org/en-US/docs/Drawing_text_using_a_canvas#Attributes) property. Default: `"alphabetic"`
126128
+ `options.textAlign` determines the alignment for the text, same semantics as canvas [textAlign](https://developer.mozilla.org/en-US/docs/Drawing_text_using_a_canvas#Attributes). Default: `"start"`
127129
+ `options.lineHeight` determines the height of a line. Default: `1.0`
128130
+ `options.width` determines the width of the text, overrides `lineHeight` if specified
129131
+ `options.height` determines the height of the text, overrides `lineHeight` if specified
132+
+ `options.triangles` if set, then output a triangulation
133+
+ `options.polygons` if set, output a list of polygons
130134
+ `options.orientation` determines the orientation of any output triangles/polygon curves. Must be either `"cw"` for clockwise or `"ccw"` for counter clockwise. Default is `"cw"`.
131135
+ `options.canvas` an optional canvas element
132136
+ `options.context` an optional canvas 2D context
@@ -145,7 +149,7 @@ Renders a string to a 2D cell complex
145149
+ `cells` are the faces of the triangulation, encoded as triples of indices into the vertex array
146150
+ `positions` are the positions of the vertices in the triangulation
147151

148-
**Note** In node.js, this library requires Cairo. For more information on how to set this up, look at the documentation for the [canvas module](https://www.npmjs.org/package/canvas).
152+
**Note** In node.js, this library requires Cairo. For more information on how to set this up, look at the documentation for the [canvas module](https://www.npmjs.org/package/canvas).
149153

150154
# Credits
151155
(c) 2014 Mikola Lysenko. MIT License

lib/vtext.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,14 @@ function processPixels(pixels, options, size) {
191191

192192
function vectorizeText(str, canvas, context, options) {
193193
var size = options.size || 64
194-
var family = options.font || "normal"
195-
196-
context.font = size + "px " + family
194+
195+
context.font = [
196+
options.fontStyle,
197+
options.fontVariant,
198+
options.fontWeight,
199+
size + "px",
200+
options.font
201+
].filter(function(d) {return d}).join(" ")
197202
context.textAlign = "start"
198203
context.textBaseline = "alphabetic"
199204
context.direction = "ltr"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vectorize-text",
3-
"version": "3.0.2",
3+
"version": "3.1.0",
44
"description": "Render a string to a vectorized cell complex",
55
"main": "index.js",
66
"directories": {

0 commit comments

Comments
 (0)