Page 1 of 1
how to remove space between characters
Posted: Wed May 14, 2014 8:50 am
by airpas
how to shrink the sapce between characters ?
this screenshot from rado1 ZGEBox2DTestbed example . i just tried to to make the text more compact by removing the spaces between the characters . but seems no options for that .
thanks
Re: how to remove space between characters
Posted: Wed May 14, 2014 10:45 am
by Kjell
Hi airpas,
airpas wrote:how to shrink the space between characters?
There is currently no property for that. Fortunately it can be "hacked" in using a expression.
In order to adjust the letter spacing for text that uses Left alignment, set the RenderCharExpression property to the following expression.
Code: Select all
const float spacing = 0.5;
if(CharI)CharX -= spacing;
And for text that uses Center alignment, use this instead.
Code: Select all
const float spacing = 0.5;
CharX -= CharI ? spacing : length(this.Text)*-0.5*spacing;
Or in case you want to support both, you can use the following.
Code: Select all
const float spacing = 0.5;
if(this.Align)
{
if(CharI)CharX -= spacing;
}
else
{
CharX -= CharI ? spacing : length(this.Text)*-0.5*spacing;
}
Simply set the spacing constant to the value of you choice ( letter spacing is halved when it's set to 0.5 and doubled when set to 2 ).
K
Posted: Wed May 14, 2014 11:49 am
by airpas
thanks Kjell , its much better now .
Posted: Wed May 14, 2014 1:42 pm
by Rado1
In some of my projects I also used proportional character spacing. The trick is to store width of characters in a separate persistent array. I usually use the CBFG (Codehead's Bitmap Font Generator) which is able to produce such a list of character width values. Loading to excel, transpose the table, copy and paste to ZGE's array... that's it.
See the attached screenshot. In this concrete case I used the RenderCharExpression like this:
this.CharX -= this.CharI > 0 ? (64 - CharacterWidth[ord(substr(this.Text, this.CharI-1, 1)) - 32]) * 0.015 : 0;
Of course if you will try it, you can use different constants for different fonts.