PDA

View Full Version : How to change the fontstyle and fontface dynamically


thipperudra
03-17-2004, 06:39 AM
Hi Antun,

I want to change the fontstyle , fontface and alignment of the text dynamically.Is it supports lps-2.0 these attribute setting (fontstyle ,fontface and alignment).How can i do those things in laszlo.

Thanks,
Rudresh

vfunshteyn
03-18-2004, 01:54 PM
Not without resetting the text itself. That is, you will need to call text.setAttribute('text', <some text>) after setting a new fontstyle or other font-related attribute. This is a known issue.

thipperudra
03-18-2004, 09:38 PM
Hi Antun,

<canvas >
<include href="base/basecomponent.lzx" />
<font name="TimesRoman" src="bitstream-vera-1.10/vera.ttf"/>

<simplelayout axis="y"/>
<text name="testtext"><font >Here Some Text</font></text>

<button text="setFontstyle">
<method event="onclick">
canvas.testtext.setAttribute('fontstyle',bold);
</method>
</button>
<button text="setsometext">
<method event="onclick">
canvas.testtext.setAttribute('text','HelloWorld');
</method>
</button>
<button text="setFont">
<method event="onclick">
canvas.testtext.setAttribute('font',TimesRoman);
</method>
</button>
</canvas>

I tried above code,but unable to set the fontstyle and font face to the text.Could you tell me tell how to change the font related attributes dynamically.

Thanks in advance,
-Rudresh

vfunshteyn
03-19-2004, 12:00 PM
Okay, setting fontstyle dynamically doesn't work in 2.1. However, changing the font itself that is used to render text is possible -- in your example you need to quote the font face name:

canvas.testtext.setAttribute('font','TimesRoman');

The call to change the font must precede setting of the text. Also, it is my understanding that the new value of text attribute must differ from the old one by at least one character -- otherwise the text won't be changed. This is a runtime performance optimization, and it cannot be turned off.