Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way to make icon edges stick to pixels? #78

Open
Finesse opened this issue Oct 14, 2017 · 6 comments
Open

Is there any way to make icon edges stick to pixels? #78

Finesse opened this issue Oct 14, 2017 · 6 comments

Comments

@Finesse
Copy link

Finesse commented Oct 14, 2017

I have an SVG icon which has the size 17x17px and is designed to be pixel-perfect. This is how it looks in an editor:

2017-10-14 12 30 15

When I convert the icon to an SVG font and insert it to a HTML page (the icon has CSS style font-size: 17px;), the icon becomes blurred:

2017-10-14 12 26 04

It happens both on Windows and macOS. Sometimes the icon is rendered crispy, it depends on amount of text before the inline icon.

Is there any way to make the icon edges be sharp and crispy in the font?

The icon SVG:

<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="Layer_1" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns"
	 xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="-241 142 17 17"
	 style="enable-background:new -241 142 17 17;" xml:space="preserve">
<style type="text/css">
	.st0{fill:#000;}
</style>
<path class="st0" d="M-235,143v5h-5v-5H-235 M-234,142h-7v7h7V142L-234,142z M-235,153v5h-5v-5H-235 M-234,152h-7v7h7V152L-234,152z
	 M-225,143v5h-5v-5H-225 M-224,142h-7v7h7V142L-224,142z M-225,153v5h-5v-5H-225 M-224,152h-7v7h7V152L-224,152z"/>
</svg>
@NaridaL
Copy link
Collaborator

NaridaL commented Dec 1, 2017

how are you inserting in into the HTML?

@Finesse
Copy link
Author

Finesse commented Dec 1, 2017

@NaridaL First I make a font file using svgicons2svgfont.

Then I add a font-face rule to a CSS file:

@font-face {
    font-family: 'icons';
    src: url("../fonts/icons.svg") format('svg');
    font-weight: normal;
    font-style: normal;
}

Then describe the icons in the CSS file:

.icon {
    line-height: 1;
}
.icon:before {
    font-family: 'icons';
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-style: normal;
    font-variant: normal;
    font-weight: normal;
    text-decoration: none;
    text-transform: none;
    display: inline-block;
    vertical-align: bottom;
}
.icon__4squares:before {
    content: "\E001"
}

And add an icon to a HTML code:

<i class="icon icon__4squares"></i>

@NaridaL
Copy link
Collaborator

NaridaL commented Dec 4, 2017

This seems related: https://www.w3.org/Graphics/SVG/WG/wiki/Proposals/SVG_hinting#Pixel_snapping
In any case, I don't think there's anything we can do on this end currently. Did you try disabling the font-smoothing/antialiasing? That seems to be the culprit. Also investigate if you can use CSS to align the icon container to a pixel border.

@Finesse
Copy link
Author

Finesse commented Dec 5, 2017

@NaridaL

This seems related: https://www.w3.org/Graphics/SVG/WG/wiki/Proposals/SVG_hinting#Pixel_snapping

Looks interesting. Hope it will be implemented.

Did you try disabling the font-smoothing/antialiasing?

Yes. The icon becomes even more blurry:

2017-12-05 12 16 18

Also investigate if you can use CSS to align the icon container to a pixel border.

This is not possible in my case. I have the icon in the text block aligned to center, and the text block has arbitrary width and content.

@nfroidure
Copy link
Owner

Ensure you set up a sufficient font height, it often cause issues ti be under 1000.

Otherwise, try to use TTFAutoHint: https://www.npmjs.com/package/gulp-iconfont#optionsautohint

@Finesse
Copy link
Author

Finesse commented Dec 5, 2017

@nfroidure

Ensure you set up a sufficient font height, it often cause issues ti be under 1000.

I use fontHeight equals 1024.

Otherwise, try to use TTFAutoHint: https://www.npmjs.com/package/gulp-iconfont#optionsautohint

I actually use gulp-iconfont to convert the icons to a font. TTFAutoHint affects nothing on macOS and totally breaks the icons on Windows:

2017-12-05 20 50 42
(it is the same icon as I showed before)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants