Skip to content

Commit fd54837

Browse files
authored
fix: Merge pull request #194 from tancredi/remove-duplicate-svg-glyphs
Remove duplicate glyphs in SVG output
2 parents 6595000 + 0a48309 commit fd54837

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`\`SVG\` font generator passes correctly format options to \`SVGIcons2SVGFontStream\` 1`] = `"processed->content->/root/foo.svg|{\\"name\\":\\"foo\\",\\"unicode\\":[\\"\\\\u0001\\"]}$processed->content->/root/bar.svg|{\\"name\\":\\"bar\\",\\"unicode\\":[\\"\\\\u0001\\"]}$"`;
4+
5+
exports[`\`SVG\` font generator resolves with the result of the completed \`SVGIcons2SVGFontStream\` 1`] = `"processed->content->/root/foo.svg|{\\"name\\":\\"foo\\",\\"unicode\\":[\\"\\\\u0001\\"]}$processed->content->/root/bar.svg|{\\"name\\":\\"bar\\",\\"unicode\\":[\\"\\\\u0001\\"]}$"`;

src/generators/asset-types/__tests__/svg.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _SVGIcons2SVGFontStream from 'svgicons2svgfont';
1+
import * as _SVGIcons2SVGFontStream from 'svgicons2svgfont';
22
import { FontAssetType } from '../../../types/misc';
33
import { FontGeneratorOptions } from '../../../types/generator';
44
import svgGen from '../svg';
@@ -21,7 +21,12 @@ jest.mock('svgicons2svgfont', () => {
2121
public content = '';
2222

2323
public write(chunk: any) {
24-
this.events.emit('data', Buffer.from(`processed->${chunk.content}$`));
24+
this.events.emit(
25+
'data',
26+
Buffer.from(
27+
`processed->${chunk.content}|${JSON.stringify(chunk.metadata)}$`
28+
)
29+
);
2530
return this;
2631
}
2732

@@ -71,15 +76,15 @@ describe('`SVG` font generator', () => {
7176
__mock: 'options__'
7277
});
7378

74-
expect(result).toBe(
75-
'processed->content->/root/foo.svg$processed->content->/root/bar.svg$'
76-
);
79+
expect(result).toMatchSnapshot();
7780
});
7881

7982
test('passes correctly format options to `SVGIcons2SVGFontStream`', async () => {
8083
const log = () => null;
8184
const formatOptions = { descent: 5, fontHeight: 6, log };
82-
await svgGen.generate(mockOptions(formatOptions), null);
85+
const result = await svgGen.generate(mockOptions(formatOptions), null);
86+
87+
expect(result).toMatchSnapshot();
8388

8489
expect(SVGIcons2SVGFontStream).toHaveBeenCalledTimes(1);
8590
expect(SVGIcons2SVGFontStream).toHaveBeenCalledWith({

src/generators/asset-types/svg.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,8 @@ const generator: FontGenerator<void> = {
3131
for (const { id, absolutePath } of Object.values(assets)) {
3232
const glyph: GglyphStream = createReadStream(absolutePath);
3333
const unicode = String.fromCharCode(codepoints[id]);
34-
let ligature = '';
3534

36-
for (let i = 0; i < id.length; i++) {
37-
ligature += String.fromCharCode(id.charCodeAt(i));
38-
}
39-
40-
glyph.metadata = { name: id, unicode: [unicode, ligature] };
35+
glyph.metadata = { name: id, unicode: [unicode] };
4136

4237
fontStream.write(glyph);
4338
}

0 commit comments

Comments
 (0)