Skip to content

Commit

Permalink
fix: Merge pull request #194 from tancredi/remove-duplicate-svg-glyphs
Browse files Browse the repository at this point in the history
Remove duplicate glyphs in SVG output
  • Loading branch information
tancredi committed May 15, 2021
2 parents 6595000 + 0a48309 commit fd54837
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

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\\"]}$"`;

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\\"]}$"`;
17 changes: 11 additions & 6 deletions src/generators/asset-types/__tests__/svg.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _SVGIcons2SVGFontStream from 'svgicons2svgfont';
import * as _SVGIcons2SVGFontStream from 'svgicons2svgfont';
import { FontAssetType } from '../../../types/misc';
import { FontGeneratorOptions } from '../../../types/generator';
import svgGen from '../svg';
Expand All @@ -21,7 +21,12 @@ jest.mock('svgicons2svgfont', () => {
public content = '';

public write(chunk: any) {
this.events.emit('data', Buffer.from(`processed->${chunk.content}$`));
this.events.emit(
'data',
Buffer.from(
`processed->${chunk.content}|${JSON.stringify(chunk.metadata)}$`
)
);
return this;
}

Expand Down Expand Up @@ -71,15 +76,15 @@ describe('`SVG` font generator', () => {
__mock: 'options__'
});

expect(result).toBe(
'processed->content->/root/foo.svg$processed->content->/root/bar.svg$'
);
expect(result).toMatchSnapshot();
});

test('passes correctly format options to `SVGIcons2SVGFontStream`', async () => {
const log = () => null;
const formatOptions = { descent: 5, fontHeight: 6, log };
await svgGen.generate(mockOptions(formatOptions), null);
const result = await svgGen.generate(mockOptions(formatOptions), null);

expect(result).toMatchSnapshot();

expect(SVGIcons2SVGFontStream).toHaveBeenCalledTimes(1);
expect(SVGIcons2SVGFontStream).toHaveBeenCalledWith({
Expand Down
7 changes: 1 addition & 6 deletions src/generators/asset-types/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@ const generator: FontGenerator<void> = {
for (const { id, absolutePath } of Object.values(assets)) {
const glyph: GglyphStream = createReadStream(absolutePath);
const unicode = String.fromCharCode(codepoints[id]);
let ligature = '';

for (let i = 0; i < id.length; i++) {
ligature += String.fromCharCode(id.charCodeAt(i));
}

glyph.metadata = { name: id, unicode: [unicode, ligature] };
glyph.metadata = { name: id, unicode: [unicode] };

fontStream.write(glyph);
}
Expand Down

0 comments on commit fd54837

Please sign in to comment.