You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* fix incorrect colorRecordIndices in CPAL test data
* Implement drawing of COLR/CPAL layers
* font inspector: display CPAL data and palettes
* glyph inspector: implement drawing of CPAL/COLR glyphs
* docs demo page: fix typo causing JS error and not updating X/Y values next to range sliders
* docs demo page: implement drawing and snapping of COLR/CPAL glyphs
* font inspector: add update button
* font inspector: fix old font information not being overwritten if not present in newly loaded font
* docs: styling for color palettes
* update example code
* WIP: update documentation in README
* add rgba() and hsla() parsing and tests
* add test for hsl() turn unit parsing, less strict regex
* fix: don't draw the BaseGlyph itself, completele replace it with the color glyph
* ignore colr table if no cpal table is present
* log warnings on SVG output of color glyphs, add @todo comments
* fix: make sure defaultRenderOptions are actually used where needed
* fix wrong defaultRenderOptions
* Glyph Inspector: implement palette preview and selection, options.drawLayers checkbox
* add palettes.js tests
* use 'hexa' as the default color format
* update test to account for 'hexa' as the default color value
* implement setColor() and add tests
* implement palettes.delete()
* implement css color name parsing
* test css color name parsing
* initialize fullPath.layers, pass font to glyph.drawPoints()
* move layers to glyph, except for generated paths
* path drawing optimizations
* implement LayerManager, show layers in glyph inspector
* allow parsing of COLRv1/CPALv1 fonts, as they may provide color glyphs in v0 format
* test CPAL baseGlyphs order in Font.validate()
* have Font.validate() return the warnings array and log console warnings (fixes#607)
* implement Font.palettes.deleteColor()
* glyph inspector improvements regarding palette colors
* rename Path.layers to Path._layers so it's not confused with the Glyph.layers property's LayerManager
* WIP: README update, PaletteManager fixes and tests
* finish palette tests
* layer tests and fixes
* handle CHARARRAY null value
* update README for Font.layers
* add basic palette and color handling to glyph inspector
Copy file name to clipboardExpand all lines: README.md
+112-5Lines changed: 112 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -192,12 +192,17 @@ Create a Path that represents the given text.
192
192
*`x`: Horizontal position of the beginning of the text. (default: `0`)
193
193
*`y`: Vertical position of the *baseline* of the text. (default: `0`)
194
194
*`fontSize`: Size of the text in pixels (default: `72`).
195
+
*`options`: _{GlyphRenderOptions}_ passed to each glyph, see below
195
196
196
-
Options is an optional object containing:
197
+
Options is an optional _{GlyphRenderOptions}_ object containing:
198
+
*`script`: script used to determine which features to apply (default: `"DFLT"` or `"latn"`)
199
+
*`language`: language system used to determine which features to apply (default: `"dflt"`)
197
200
*`kerning`: if true takes kerning information into account (default: `true`)
198
201
*`features`: an object with [OpenType feature tags](https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags) as keys, and a boolean value to enable each feature.
199
202
Currently only ligature features `"liga"` and `"rlig"` are supported (default: `true`).
200
203
*`hinting`: if true uses TrueType font hinting if available (default: `false`).
204
+
*`colorFormat`: the format colors are converted to for rendering (default: `"hexa"`). Can be `"rgb"`/`"rgba"` for `rgb()`/`rgba()` output, `"hex"`/`"hexa"` for 6/8 digit hex colors, or `"hsl"`/`"hsla"` for `hsl()`/`hsla()` output. `"bgra"` outputs an object with r, g, b, a keys (r/g/b from 0-255, a from 0-1). `"raw"` outputs an integer as used in the CPAL table.
205
+
*`fill`: font color, the color used to render each glyph (default: `"black"`)
201
206
202
207
_**Note:** there is also `Font.getPaths()` with the same arguments, which returns a list of Paths._
203
208
@@ -207,6 +212,7 @@ Create a Path that represents the given text.
207
212
*`x`: Horizontal position of the beginning of the text. (default: `0`)
208
213
*`y`: Vertical position of the *baseline* of the text. (default: `0`)
209
214
*`fontSize`: Size of the text in pixels (default: `72`).
215
+
*`options`: _{GlyphRenderOptions}_ passed to each glyph, see `Font.getPath()`
210
216
211
217
Options is an optional object containing:
212
218
*`kerning`: if `true`, takes kerning information into account (default: `true`)
@@ -244,7 +250,101 @@ bounding box than its advance width.
244
250
245
251
This corresponds to `canvas2dContext.measureText(text).width`
246
252
*`fontSize`: Size of the text in pixels (default: `72`).
247
-
*`options`: See `Font.getPath()`
253
+
*`options`: _{GlyphRenderOptions}_, see `Font.getPath()`
254
+
255
+
#### The `Font.palettes` object (`PaletteManager`)
256
+
257
+
This allows to manage the palettes and colors in the CPAL table, without having to modify the table manually.
258
+
259
+
###### `Font.palettes.add(colors)`
260
+
Add a new palette.
261
+
*`colors`: (optional) colors to add to the palette, differences to existing palettes will be filled with the defaultValue.
Fills a set of palette colors (from a palette index, or a provided array of CPAL color values) with a set of colors, falling back to the default color value, until a given count. *It does not modify the existing palette, returning a new array instead!* Use `Font.palettes.setColor()` instead if needed.
286
+
*`palette`: palette index or an Array of CPAL color values to fill the palette with, the rest will be filled with the default color
287
+
*`colors`: array of color values to fill the palette with, in a format supported as an output of `colorFormat` in _{GlyphRenderOptions}_, see `Font.getPath()`. CSS color names are also supported in browser context.
288
+
*`colorCount`: Number of colors to fill the palette with, defaults to the value of the numPaletteEntries field
289
+
290
+
###### `Font.palettes.getAll(colorFormat)`
291
+
Returns an array of arrays of color values for each palette, optionally in a specified color format
292
+
*`colorFormat`: (optional) See _{GlyphRenderOptions}_ at `Font.getPath()`, (default: `"hexa"`)
Set one or more colors on a specific palette by its zero-based index
307
+
*`index`: zero-based color index to start filling from
308
+
*`color`: color value or array of color values in a color notation supported as an output of `colorFormat` in _{GlyphRenderOptions}_, see `Font.getPath()`. CSS color names are also supported in browser context.
309
+
*`paletteIndex`: zero-based palette index (default: 0)
310
+
311
+
###### `Font.palettes.toCPALcolor(color)`
312
+
Converts a color value string to a CPAL integer color value
313
+
*`color`: string in a color notation supported as an output of `colorFormat` in _{GlyphRenderOptions}_, see `Font.getPath()`. CSS color names are also supported in browser context.
314
+
315
+
316
+
##### The `Font.layers` object (`LayerManager`)
317
+
318
+
This allows to manage the color glyph layers in the COLR table, without having to modify the table manually.
Mainly used internally. Updates the colr table, adding a baseGlyphRecord if needed, ensuring that it's inserted at the correct position, updating numLayers, and adjusting firstLayerIndex values for all baseGlyphRecords according to any deletions or insertions.
248
348
249
349
#### The Glyph object
250
350
A Glyph is an individual mark that often corresponds to a character. Some glyphs, such as ligatures, are a combination of many characters. Glyphs are the basic building blocks of a font.
@@ -259,24 +359,28 @@ A Glyph is an individual mark that often corresponds to a character. Some glyphs
259
359
*`xMin`, `yMin`, `xMax`, `yMax`: The bounding box of the glyph.
260
360
*`path`: The raw, unscaled path of the glyph.
261
361
262
-
##### `Glyph.getPath(x, y, fontSize)`
362
+
##### `Glyph.getPath(x, y, fontSize, options, font)`
263
363
Get a scaled glyph Path object for use on a drawing context.
264
364
*`x`: Horizontal position of the glyph. (default: `0`)
265
365
*`y`: Vertical position of the *baseline* of the glyph. (default: `0`)
266
366
*`fontSize`: Font size in pixels (default: `72`).
367
+
*`options`: _{GlyphRenderOptions}_, see `Font.getPath()`
368
+
*`font`: a font object, needed for rendering COLR/CPAL fonts to get the layers and colors
267
369
268
370
##### `Glyph.getBoundingBox()`
269
371
Calculate the minimum bounding box for the unscaled path of the given glyph. Returns an `opentype.BoundingBox` object that contains `x1`/`y1`/`x2`/`y2`.
270
372
If the glyph has no points (e.g. a space character), all coordinates will be zero.
271
373
272
-
##### `Glyph.draw(ctx, x, y, fontSize)`
374
+
##### `Glyph.draw(ctx, x, y, fontSize, options, font)`
273
375
Draw the glyph on the given context.
274
376
*`ctx`: The drawing context.
275
377
*`x`: Horizontal position of the glyph. (default: `0`)
276
378
*`y`: Vertical position of the *baseline* of the glyph. (default: `0`)
277
379
*`fontSize`: Font size, in pixels (default: `72`).
380
+
*`options`: _{GlyphRenderOptions}_, see `Font.getPath()`
381
+
*`font`: a font object, needed for rendering COLR/CPAL fonts to get the layers and colors
278
382
279
-
##### `Glyph.drawPoints(ctx, x, y, fontSize)`
383
+
##### `Glyph.drawPoints(ctx, x, y, fontSize, options, font)`
280
384
Draw the points of the glyph on the given context.
281
385
On-curve points will be drawn in blue, off-curve points will be drawn in red.
282
386
The arguments are the same as `Glyph.draw()`.
@@ -291,6 +395,9 @@ The arguments are the same as `Glyph.draw()`.
These are currently only wrapper functions for their counterparts on Path objects (see documentation there), but may be extended in the future to pass on Glyph data for automatic calculation.
293
397
398
+
##### `Glyph.getLayers(font)`
399
+
Gets the color glyph layers for this glyph from the specified font's COLR/CPAL tables
400
+
294
401
### The Path object
295
402
Once you have a path through `Font.getPath()` or `Glyph.getPath()`, you can use it.
<buttontype="button" id="update">update</button> after modifying window.font
87
+
88
+
<hr>
89
+
83
90
<divclass="explain">
84
91
<h1>Free Software</h1>
85
92
<p>opentype.js is available on <ahref="https://github.com/opentypejs/opentype.js">GitHub</a> under the <ahref="https://raw.github.com/opentypejs/opentype.js/master/LICENSE">MIT License</a>.</p>
0 commit comments