imagescript 3.7.0 → 3.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -143,11 +143,11 @@ export class ShapeFont {
143
143
  advance(glyph) {
144
144
  return glyph < this.font.numGlyphs ? this.font.advance(glyph) : 0;
145
145
  }
146
- plan(script, direction) {
147
- const key = `${script}:${direction}`;
146
+ plan(script, direction, features = []) {
147
+ const key = `${script}:${direction}:${features.map(([tag, value]) => `${tag}=${value}`).join(',')}`;
148
148
  let plan = this.plans.get(key);
149
149
  if (!plan)
150
- this.plans.set(key, plan = new Planner(this, script, direction).compile());
150
+ this.plans.set(key, plan = new Planner(this, script, direction, features).compile());
151
151
  return plan;
152
152
  }
153
153
  }
@@ -166,12 +166,14 @@ export class Planner {
166
166
  font;
167
167
  script;
168
168
  direction;
169
+ features;
169
170
  map;
170
171
  shaper;
171
- constructor(font, script, direction) {
172
+ constructor(font, script, direction, features = []) {
172
173
  this.font = font;
173
174
  this.script = script;
174
175
  this.direction = direction;
176
+ this.features = features;
175
177
  this.map = new MapBuilder([font.gsub, font.gpos], scriptTags(script));
176
178
  this.shaper = shaperFor.categorize(script, direction, this.map.chosenScript[0]);
177
179
  }
@@ -203,6 +205,10 @@ export class Planner {
203
205
  map.addFeature(tag, flags);
204
206
  for (const [tag, flags] of HORIZONTAL_FEATURES)
205
207
  map.addFeature(tag, flags);
208
+ if (this.features.length)
209
+ map.isSimple = false;
210
+ for (const [tag, value] of this.features)
211
+ map.addFeature(tag, 1, value);
206
212
  if (shaper.overrideFeatures)
207
213
  shaper.overrideFeatures(this);
208
214
  const m = map.compile();
@@ -932,7 +938,7 @@ function position(plan, font, buffer) {
932
938
  if (buffer.direction === 5)
933
939
  buffer.reverse();
934
940
  }
935
- export function shapeRun(font, codepoints, script, direction, clusters, context = { before: [], after: [] }) {
941
+ export function shapeRun(font, codepoints, script, direction, clusters, context = { before: [], after: [] }, features = []) {
936
942
  const buffer = new Buffer();
937
943
  buffer.direction = direction;
938
944
  buffer.script = script;
@@ -947,7 +953,7 @@ export function shapeRun(font, codepoints, script, direction, clusters, context
947
953
  buffer.limit();
948
954
  if (!buffer.len)
949
955
  return [];
950
- const plan = font.plan(script, direction);
956
+ const plan = font.plan(script, direction, features);
951
957
  const targetDirection = buffer.direction;
952
958
  let hasFractionSlash = false;
953
959
  for (const info of buffer.info)