I'm rendering a text svg using handwriting style google fonts. Assume that I must use these fonts.
For this example, lets use Princess Sofia
Setup
rendering text svg to png via cairo svg in python
text svg is being prepared in the browser
The Problem:
When creating a PNG out of the text svg with this font, some part of it is being cut off. The cut off part matches the areas that are not higlighted in the screenshot below:
Rendering result for A (cut off in the screenshot):
Rendering result for P (NOT cut off in the screenshot):
Question
Is there a way to work around this using CSS or JS?
What won't work
"Kerning, stretching, font variants, word and letter spacing options, glyph orientations, baseline shifts and many other properties are not supported" by Cairo SVG
It's difficult to quickly test this without seeing some code reproducing the problem.
However, this may be rectified by using font kerning which can be specified in CSS using the font-kerning property:
font-kerning: normal;
Setting font-kerning to normal achieves the following effect:
Font kerning information stored in the font must be applied.
The default is auto, which allows the browser to decide whether to use font kerning or not. Forcing it to normal means that the kerning specified in the font itself will be used.
The docs for font-kerning can be read here.
Related
Please refer to this jsfiddle.
It includes text, both inside a highcharts chart and outside, where the text includes a "sun" character as shown in this page. I've also included variants both with and without variation selectors (see also here) to see what difference they make.
Outside highcharts:
<p>Embedded: ☼ ☼︎ ☼️</p>
symbols.innerHTML = '<p>Added: \u263C \u263C\uFE0E \u263C\uFE0F</p>';
Inside highcharts:
title: {
text: 'In highcharts: \u263C \u263C\uFE0E \u263C\uFE0F'
},
Now, it seems to depend on which browser you view this jsfiddle as to whether you get a coloured emoji version of the sun symbol, or a plain-text black version... or even both versions!
For example, in Chrome on a Windows desktop you get the plain version all round:
... while in Chrome on Android 7 you get part-plain and part-emoji:
I really don't like that the style of the emoji versions is completely out of my control, particularly when the style clashes horribly with the rest of the page (e.g. the sun symbol is bright orange and the equivalent moon symbol is bright blue).
So I'd like to force the page to use the plain version on all browsers in all contexts... any idea how?
It would seem completely crazy to have to resort to using images, because I want the symbols to have the same appearance as the surrounding text, including text colour (which the user can change at will). And isn't UTF-8 meant to be a character encoding rather than an emoji encoding? I have nothing against cute emojis per se, but only in the right context.
The symbols appearance depends on the font you use.
Please look at your updated jsfiddle.
I've just changed the font on all elements:
* {font-family:serif !important}
Any element can have its own font.
It's up to you which font to use. So choose the right one and tune it up.
Update
I have to clarify several points:
There are NO 'safe' or 'unsafe' fonts.
Basically font works like a key-value storage {code1 => glyph1, code2 => glyph2, ...}, input a code and get the corresponding glyph
Font may or may not contain any code-glyph pair
You can make your own font containing only desired symbols, having codes of your choice associated with glyphs of your choice e.g. \u263d can be any glyph you want, not always the moon
In css font-family: you can specify one or several font-families and/or generic-families (look here). When the style's being applied to the text the browser converts each symbol ('A', ' ' or '\u263d') to its code and tries to get the glyph from the specified font-families until the glyph has been found or no more fonts have left.
If the font contains the desired code-glyph pair we can see a glyph, if not - we can see a space, ?, an outlined rectangle, a rectangle with the code inside, etc. (depends on the browser).
In this case: {font-family:serif} for \u263d browser searches for the glyph for \u263d in all system fonts of generic-family serif. And on Android it firstly finds what you name the 'emoji'.
The solution is to find (see the jsfiddle) or to make (see the other jsfiddle) a font with the desired glyphs and apply it to the desired elements.
Hope it's helpful and clear.
The answer by Kosh Very has hit on something. Indeed, changing the font-family on all elements to serif does indeed result in the plain symbol being used in highcharts, even in Android 7. The trouble is, in actual use I cannot stick to a single "safe" font family... the font can be specified by the user, from any web font listed on Google fonts.
I've updated the jsfiddle to include loading and use of a web font:
// see https://github.com/typekit/webfontloader
WebFont.load({
google: {
families: ['Fresca:400']
}
});
And I use that font throughout, both inside and outside highcharts. The result on Windows Chrome is as before (plain text symbols all over), but now the result in Android 7 Chrome is:
So this now rather suggests that the issue isn't highcharts-specific after all, and more of a font issue as Kosh Very as indicated. Indeed in the original example, without any font stated explicitly, the font used in highcharts is different to that used outside... and probably hence the difference in symbol style.
But I've tried a couple of other completely different web fonts in the updated jsfiddle example, with the same result. In other words, the emoji sun symbol is not apparently coming from the font itself. Perhaps when a font is missing a particular character (these fonts probably don't have a character for every unicode value) then it reverts to using characters from the system font? From other discussions it seems that these coloured emojis might only show on Samsung devices, so maybe the system font on Samsung has these?
The solution (or workaround) seems to be use a "safe font" only where required (for the graphical characters), and your desired font elsewhere, as per this updated jsfiddle, which gives the following result on Android 7 Chrome:
BUT I've hit a snag with this solution... it works nicely for the sun symbol as above, but for the very next unicode character (moon symbol) it doesn't... so maybe that symbol is missing from the serif font family and it reverts again to system emoji.
jsfiddle with moon
So the solution is probably still very patchy... maybe only limited to certain symbols.
Even for a font like Cardo that apparently supports the moon character \u263d, this example doesn't work in Android Chrome... still get the coloured emoji version rather than the plain version.
I use the unicode symbol ⏬ on my webpage. The problem is that this symbol is displayed good in chrome of the linux but in chrome of the windows 10 this symbol has the border and blue background color.
Here is my code: <div>Hello world ⏬</div>
Could anybody help me please?
Well this is something which are rendered by the browser dom itself. Every engines are showing something else, instead those who has the same engine. There are some possible ways to change the style a bit by changing the font-family where it's writing in.
If you want, you could do it by HTML and CSS by making a background image or do it with simply using font-awesome!
Hopefully this is a answer on your question.
<div>Hello world ⏬</div>
Since you haven't set any font, the browser will use whatever default font it has. In Chrome, that means colour fonts:
As with any other piece of text, if you need to have full control on how it looks you need to set your own font. For instance, Google provides the Noto family, which includes two emoji fonts (monochrome and colour).
An alternative is to handle it as icon and use either SVG or an iconic font.
In my website, I want my header to use the 'Tw Cen MT Condensed Extra Bold' font. However, I am only able to create a font using 'Tw Cen MT Condensed' even with adding the bold effect, it does not look the same. I created the banner in photoshop and now I want to replicate the text in CSS.
Below is the link to my current code on Fiddle. Below that is an example of the text I want to create via Photoshop.
Also, is there a way so that I can include the same pattern from my background onto the text?
If all else fails, I could just upload the text itself as an image onto the website, but I would only do that as a last resort.
Thanks.
Link to Fiddle
Banner I want to create
Your going to need to find a web font version of that font for the best results, you can google for it or if the license for the font allows you to create one you can do that.
A good one is
http://www.fontsquirrel.com/tools/webfont-generator
And you'll have to include those files alongside your html and css to load it, otherwise someone who doesn't have the font won't be able to see it and the system will default to a different font.
Unfortunately, it won't work because the font is "non-standard"--as has already been explained.
To get the look you want, create the text banner you want in your image editor (Photoshop?) and save it as a ".png" image file, directing Photoshop to "keep transparency" (I'm using a different image editor, so the command wording will probably be different in Photoshop). To minimize file size, set the image frame bars as close to the font as you can (the more area a ".png" covers, the greater the file size--clear space included--and the size difference seems to increase exponentially [by square]).
All you'll have left to do is manipulate the position of the text banner in the div (float, padding, margin, etc.).
I know this is isn't the answer you want, but it works--and you don't have to worry about contingency code for different browsers, script blockers, etc. (you still have to code for the few who still block images and for accessibility standards, but IMHO it's more effective--and cleaner--than writing contingency code and having to allow for the variability between this font and the widest/narrowest contingency font in your designated family.
At least one part of your page will render the same in just about every browser.
Do all font ascenders/descenders have the same space above/below? I'm trying to write a global stylesheet which will take away top and bottom space from h1-6 elements which I found to be no more than 8 pixels or so (which lowers as the h elements lower.) The reason I'm considering this is because I won't have any tall characters which will occupy the ascender/descender so I really have no usage for it (plus I need exact precision in the positioning of my elements.)
My question is if all fonts have the same ascending/descending space, or if it varies by font or OS or browser.
Do all font ascenders/descenders have the same space above/below?
Nope
It varies by font, by OS, by Browser, and probably lunar cycle as well. You can expect fonts to consistently be inconsistent.
Some fonts don't even have the concept of ascenders/descenders. What would you do if an icon font was used? Some fonts align descenders such that they don't even descend below the baseline. Others, such as calligraphic fonts tend to drop below the baseline, whether or not the character has an actual descender.
When I'm building pages off of comps that don't include font-size descriptions, I often have to render a large set of varying font-sizes of a particular family. I have a utility webpage that I use locally so that I can determine which font size must be used, and what font alignment will work.
Example:
This example uses Arial, and even Arial renders differently for some sizes between Chrome, Firefox and IE. When you're using sets of fonts you then also have to worry about all the other options in the set, in case the user doesn't have that font installed.
If you absolutely must have an exact rendering, you should be using an image to render the text. Use the [alt] attribute to reference the text in the image. It's not as manageable as text because it requires re-rendering every time a content change is desired, but it works well enough, especially for things like logos which absolutely must render in a specified manner.
I have some text on my website that I would like to make 'bold', and its font-size to be 'x-small'. But whenever I apply the font-size, the text loses its bold. When I remove the font-size, and the text goes back to default, it's bold again. What's going on here?
<span style="font-size:x-small; font-weight:bold;">TESTING</span
Have you tried other font families? If I remember correctly, Arial in small sizes looks the same in bold and normal weights. Give Verdana a shot.
the thing is that true type fonts DO render differently on various sizes.
If you have bitmap fonts, its just resampled to whatever size necessary.
TTF are based on vector graphics and can be scaled to any size needed.
However there are, depending on the font family, differences in how the font is rendered in different sizes.
Theese changes are intentionally and coded by in by the designer of the font.
Usually lines get thinner the smaller the font is rendered, this could cause the effect you are experiencing. You can try different fonts, but rest assuered that, unless you use certified standardized fonts, there is no guarantee of how they will be rendered.
Some font families will appear as normal when you shrink them.
Try using Type Tester to see exactly how your fonts look. It will use the web safe ones as well as what's on your machine if your using #font-face.
http://www.typetester.org/