这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export declare type TinySDFOptions = {
fontFamily?: string;
fontWeight?: string;
fontStyle?: string;
lang?: string;
};

export default class TinySDF {
Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ export default class TinySDF {
cutoff = 0.25,
fontFamily = 'sans-serif',
fontWeight = 'normal',
fontStyle = 'normal'
fontStyle = 'normal',
lang = null
} = {}) {
this.buffer = buffer;
this.cutoff = cutoff;
this.radius = radius;
this.lang = lang;

// make the canvas size big enough to both have the specified buffer around the glyph
// for "halo", and account for some glyphs possibly being larger than their font size
Expand Down Expand Up @@ -67,6 +69,7 @@ export default class TinySDF {
if (glyphWidth === 0 || glyphHeight === 0) return glyph;

const {ctx, buffer, gridInner, gridOuter} = this;
if (this.lang) ctx.lang = this.lang;
ctx.clearRect(buffer, buffer, glyphWidth, glyphHeight);
ctx.fillText(char, buffer, buffer + glyphTop);
const imgData = ctx.getImageData(buffer, buffer, glyphWidth, glyphHeight);
Expand Down
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,13 @@ test('does not return negative-width glylphs', () => {
assert.equal(glyph.glyphWidth, 0);
assert.equal(glyph.width, 6); // zero-width glyph with 3px buffer
});

/*
test('renders Chinese and Japanese versions of characters', () => {
const sdf1 = new MockTinySDF({lang: 'zh'});
const glyph1 = sdf1.draw('门');
const sdf2 = new MockTinySDF({lang: 'ja'});
const glyph2 = sdf2.draw('门');
assert.notDeepStrictEqual(glyph1.data, glyph2.data);
});
*/