This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > VRML > December 2003 > Changing FontStyle family style justify in a script with set_FontStyle





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Changing FontStyle family style justify in a script with set_FontStyle
PrisNo6

2003-12-18, 8:46 pm

In a VRML project, I am able to programmatically change the size
property of a Text fontStyle node with a Script (javascript) and a
set_FontStyle route. The FontStyle.size property changes without
difficulty.

But the same technique does not seem to be able to set
FontStyle.family FontStyle.style and FontStyle.justify properties via
a script. The FontStyle node is exposed, while all of the properties
within a FontStyle node (including the size, which can be changed) are
not.

I am using the Cortona viewer.

Why can I only change one (the size) out of the four non-exposed
FontStyle properties?

If you have been able change the family, style and justify properties
in a script, could you post a sample?

Thanks - Kurt
Bill Angel

2003-12-18, 8:46 pm

Hi:

The following code shows one way that you can use a Script Node to
set the family, style, and justify properties of a FontStyle
node.


#VRML V2.0 utf8


Shape {
geometry DEF TEXT Text {
string ["The Quick Brown Fox","Jumped Over the Lazy Dog"]
}
}



DEF SCRIPT Script {
field SFNode text USE TEXT
field MFNode temp []
directOutput TRUE
url [ "vrmlscript:
function initialize () {

string = 'FontStyle { family \"SANS\" style \"BOLD\" justify \"MIDDLE\" } ';
print(string); // for debug purposes

temp = Browser.createVrmlFromString(string);

text.set_fontStyle = temp[0];

}
"]
}

--- Bill Angel


fisherka@csolutions.net (PrisNo6) wrote in message news:<9865fa0b.0312171348.69013981@posting.google.com>...
quote:

> In a VRML project, I am able to programmatically change the size
> property of a Text fontStyle node with a Script (javascript) and a
> set_FontStyle route. The FontStyle.size property changes without
> difficulty.
>
> But the same technique does not seem to be able to set
> FontStyle.family FontStyle.style and FontStyle.justify properties via
> a script. The FontStyle node is exposed, while all of the properties
> within a FontStyle node (including the size, which can be changed) are
> not.
>
> I am using the Cortona viewer.
>
> Why can I only change one (the size) out of the four non-exposed
> FontStyle properties?
>
> If you have been able change the family, style and justify properties
> in a script, could you post a sample?
>
> Thanks - Kurt


Cecile Muller

2003-12-18, 8:46 pm

> The FontStyle node is exposed, while all of the properties
quote:

> within a FontStyle node (including the size, which can be changed) are
> not.



You're supposed to replace the while fontStyle field's value (a
FontStyle{} node) by another value (another FontStyle{} node). Fields
that aren't exposed shouldn't be changeable, and if they are, it's
browser-specific. Instead, you could make yourself several premade
FontStyle, one with size 1 + italic, one with size 1 but normal, etc.
Or you could create a node via createVrmlFromString if you want a less
case-specific solution.
Here is an example below (it doesn't work in Cosmo (but works in
Contact and Cortona), idea anyone ?) :


-------
#VRML V2.0 utf8

PROTO myText[
exposedField MFFloat length []
exposedField SFFloat maxExtent 0
exposedField MFString string []
field MFString family "SERIF"
field SFBool horizontal TRUE
field MFString justify "BEGIN"
field SFString language ""
field SFBool leftToRight TRUE
field SFFloat size 1
field SFFloat spacing 1
field SFString style "PLAIN"
field SFBool topToBottom TRUE
eventIn MFString change_family
eventIn SFBool change_horizontal
eventIn MFString change_justify
eventIn SFString change_language
eventIn SFBool change_leftToRight
eventIn SFFloat change_size
eventIn SFFloat change_spacing
eventIn SFString change_style
eventIn SFBool change_topToBottom

]{
DEF txt Text{
length IS length
maxExtent IS maxExtent
string IS string
fontStyle FontStyle{family IS family horizontal IS horizontal
justify IS justify language IS language leftToRight IS leftToRight
size IS size spacing IS spacing style IS style topToBottom IS
topToBottom}
}
DEF brain Script{
field MFString family IS family
field SFBool horizontal IS horizontal
field MFString justify IS justify
field SFString language IS language
field SFBool leftToRight IS leftToRight
field SFFloat size IS size
field SFFloat spacing IS spacing
field SFString style IS style
field SFBool topToBottom IS topToBottom
eventIn MFString change_family IS change_family
eventIn SFBool change_horizontal IS change_horizontal
eventIn MFString change_justify IS change_justify
eventIn SFString change_language IS change_language
eventIn SFBool change_leftToRight IS change_leftToRight
eventIn SFFloat change_size IS change_size
eventIn SFFloat change_spacing IS change_spacing
eventIn SFString change_style IS change_style
eventIn SFBool change_topToBottom IS change_topToBottom
eventOut SFNode newStyle
directOutput TRUE
url "java script:
function bool2text(v){if (v) return 'TRUE'; else return 'FALSE';}
function update(){
nodes = Browser.createVrmlFromString('FontStyle{family
[\"'+family+'\"] horizontal '+bool2text(horizontal)+' justify
[\"'+justify+'\"] language \"'+language+'\" leftToRight
'+bool2text(leftToRight)+' size '+size+' spacing '+spacing+' style
\"'+style+'\" topToBottom '+bool2text(topToBottom)+'}');
newStyle = nodes[0];
}
function change_family(v){family = v; update();}
function change_horizontal(v){horizontal = v; update();}
function change_justify(v){justify = v; update();}
function change_language(v){language = v; update();}
function change_leftToRight(v){leftToRight = v; update();}
function change_size(v){size = v; update();}
function change_spacing(v){spacing = v; update();}
function change_style(v){style = v; update();}
function change_topToBottom(v){topToBottom = v; update();}
"
}
ROUTE brain.newStyle TO txt.set_fontStyle
}

Shape{
appearance Appearance{}
geometry DEF myTXT myText{string "My String" size 0.5}
}


Transform{
translation -4 0 0
children [
DEF TS1 TouchSensor{}
Shape{
appearance Appearance{material Material{emissiveColor 1 0 0}}
geometry Box{}
}
]
}
Transform{
translation 4 0 0
children [
DEF TS2 TouchSensor{}
Shape{
appearance Appearance{material Material{emissiveColor 1 0 0}}
geometry Box{}
}
]
}

DEF brain Script{
field SFNode myTXT USE myTXT
eventIn SFTime change_size
eventIn SFTime change_style
directOutput TRUE
url "java script:
function change_size(){myTXT.change_size = 2;}
function change_style(){myTXT.change_style = 'ITALIC';}
"
}
ROUTE TS1.touchTime TO brain.change_size
ROUTE TS2.touchTime TO brain.change_style
PrisNo6

2003-12-18, 8:46 pm

spam@wildpeaks.com (Cecile Muller) wrote in message news:<aff31ac6.0312172115.3347723a@posting.google.com>...[QUOTE][color=darkred]

Thanks to you both for responding - Kurt
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews