how to remove space between characters

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
airpas
Posts: 48
Joined: Wed Apr 18, 2012 11:50 am

how to remove space between characters

Post 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
Attachments
Untitled.jpg
Untitled.jpg (22.13 KiB) Viewed 5247 times
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Re: how to remove space between characters

Post 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
airpas
Posts: 48
Joined: Wed Apr 18, 2012 11:50 am

Post by airpas »

thanks Kjell , its much better now .
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post 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.
Attachments
screenshot with proportional texts
screenshot with proportional texts
scr.png (133.14 KiB) Viewed 5229 times
Post Reply