I have a large Raphael canvas with hundreds of SVGs drawn on it, and am using the "raphael pan and zoom" plugin to zoom in and out.
Because of this, I initially draw my svgs very small, and the user just zooms in/out.
The problem I am having is 2px text size is too large, and 1px text size is too small, however when I try "1.5px", it just gets displayed as 1px text size again.
I am having trouble changing the font size to be 1.5px, or any half size of one (1.2, 1.6, 1.9...)
Here is my code:
...
this.paper.text(x, y, string)
.attr({'font-family':'myFont', 'font-size':'1.5px'});
...
The CSS for 'myFont' is:
@font-face {
font-family: 'myFont';
src:url('fonts/myFont.eot');
src:url('fonts/myFont.eot?#iefix') format('embedded-opentype'),
url('fonts/myFont.woff') format('woff'),
url('fonts/myFont.ttf') format('truetype'),
url('fonts/myFont.svg#myFont') format('svg');
font-weight: normal;
font-style: normal;
}
[data-icon]:before {
font-family: 'myFont';
content: attr(data-icon);
speak: none;
font-weight: normal;
font-variant: normal;
text-transform: none;
/* line-height: 1; */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-home, .icon-zoom-in{
font-family: 'myFont';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
/* line-height: 1; */
-webkit-font-smoothing: antialiased;
pointer-events:none;
}
.icon-home:before {
content: "\e000";
}
.icon-zoom-in:before {
content: "\e001";
}
/* Note: Generated from ico-moon, it's just a font that is a bunch of icons. */
I've tried setting 'line-height' to '0.5', with no luck. Any ideas?
Thanks!
All browsers doesn't support for decimal places when you define the width in pixels. In chrome the decimal places are truncated and thus 5.5px or 5.6px becomes 5px. Some browser displays this without truncated.
The width will be rounded to an integer number of pixels.
I don't know if every browser will round it the same way though. They all seem to have a different strategy when rounding sub-pixel percentages. If you're interested in the details of sub-pixel rounding in different browsers, there's an excellent article on ElastiCSS.
Even when the number is rounded when the page is painted, the full value is preserved in memory and used for subsequent child calculation. For example, if your box of 100.4999px paints to 100px, it's child with a width of 50% will be calculated as .5*100.4999 instead of .5*100. And so on to deeper levels.
more about on this q/a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With