- Home /
imported font(s) : bold style looks like compressed
Hello every one,
i've a problem when I import font in unity.
Every time i put the bold style to my guiText (by inspector or with ), it looks like compressed, with no space between letters.
No problem at all with default font (arial)
Does anybody allready have this problem and find a solution ? since it's impossible to change Font in ONE GUIText, it cause me a lots of problem.
Thank you in advance.
It seems like this is an issue with Unities Arial Font. Googles Droid Sans Font is working well in both, bold and regular, styles.
Answer by gheeler · Nov 28, 2013 at 01:58 PM
a simple solution is to import the bold version of the font as an individual font. if you're on windows you can dig it out of C:\\Windows\\Fonts
Answer by karljj1 · Nov 28, 2013 at 02:00 PM
Try using a bold version of the font:
http://www.xfreefonts.com/free-fonts-download/se-optimist.html
EDIT:
Ok try this: link text
Its a script that will allow you to mix bold and normal fonts. Its something i just knocked up so feel free to optimise/improve.
using UnityEngine;
using System.Collections.Generic;
public class ScriptText : MonoBehaviour
{
public string label;
public Font normal, bold;
public void OnGUI()
{
// Split the string into normal/bold The first item will be normal, then bold alternating
string[] split = label.Split( new string[] { "<b>", "</b>" }, System.StringSplitOptions.None );
GUI.skin.label.alignment = TextAnchor.LowerLeft;
// Normalised coords
Rect labelRect = new Rect( transform.position.x * Screen.width, transform.position.y * Screen.height, 0, 30 );
GUI.skin.font = normal;
for( int i = 0; i < split.Length; ++i )
{
if( i > 0 && !split[i].StartsWith( " " ) )
{
split[i] = " " + split[i];
}
GUIContent labelGC = new GUIContent( split[i] );
// Calculate the size of this item
Vector2 sz = GUI.skin.label.CalcSize( labelGC );
// Size of draw rect
labelRect.width = sz.x;
// Draw
GUI.Label( labelRect, labelGC );
// Move our rect along
labelRect.x += sz.x;
// Toggle fonts
GUI.skin.font = GUI.skin.font == normal ? bold : normal;
}
}
}
Answer by Dezky · Nov 28, 2013 at 03:15 PM
thank you for your anwsers, but i want to use normal AND bold at the same time in ONE GUIText like this :
all the TTF Style are imported, but since we can't change font on the same GUIText, i can't use the bold version...
What can i do ?
Thanks again for your help !
is this for desktop or handheld devices?
dynamic fonts dont work properly on android and ios im pretty sure. i had problems trying to use different sizes on handhelds and they were bunched together and ins$$anonymous$$d had to import a new copy of the same font for each size i needed
For Both, but the problem is here on desktop & iOs... Did I need to do any report to unity ?
I really need to use THIS fonts, so i'm a little bit blocked...
well i dont think youre going to be able to fix it for the handhelds. have you tested it with another font? you can see the problem i had with fonts here http://answers.unity3d.com/questions/403698/help-with-guistyles-between-platforms.html most of it is about textures but the font bit is there too
you may have to just do one section with one font then the next with the other but you should still be ablt to position them together if there is no padding in the guistyle
heres an explanation of some of the problems with fonts http://wiki.etc.cmu.edu/unity3d/index.php/Unity_font_issue_on_iOS/Android
You could do it using a script. Use the OnGUI function and GUI.Label.
You can then use both fonts.
$$anonymous$$G a rought draft:
public string ourLabel;
public Font normal;
public Font bold;
void OnGUI()
{
// Split the string using the <b> tag
for each item split
GUI.skin.font = select font
GUI.Label( item, GUILayout.Width( GUI.skin.label.CalcSize( item ).x ) );
}
If your interested i will try and knock a script together for you later.