Skip to main content
Participating Frequently
June 27, 2019
Answered

Trying to Bold Helvetica in a string, please help

  • June 27, 2019
  • 1 reply
  • 921 views

Here's whats being populated, And its in the document level javascript.

// Place all prepopulation data into a single data structure

var Carddata = { Jarl:{ AP: "3",

                        SP: "5",

                        MA: "3",

                        RA: "2",

                        DF: "3",

                        RS: "1",

                        DR: "3",

                        MN: "2",

                        HP: "3",

                        Size: "2",

                        UnitRank: "War Clan Leader",

                        Base: "30mm",

                        Glorycost: "160",

                        Specialabilities: "Combat Sense, Tactician (12), Teamwork, Hip Shot, Weapon Master",

                        SpecialAB: "Combat Sense: Enemies cannot deploy models that have the Special Ability Stealth within 18 of this model \nTactician: This model can cause one other friendly model within range who has not yet activated this Round to immediately activate following this models activation \nTeamwork: Models with the Special Ability Teamwork gain an additional +1 MA and +1 ST when they gain the Overwhelm bonus \nHip-Shot: This model may use this RA for a Clash action. They can initiate a Clash the moment an enemy model enters LOS and is within Attack range \nWeapon Master: This model may re-roll one failed MA attempt per activation"},

function SetFieldValues(cUnitType)

{

  this.getField("AP").value = Carddata[cUnitType].AP;

  this.getField("SP").value = Carddata[cUnitType].SP;

  this.getField("MA").value = Carddata[cUnitType].MA;

  this.getField("RA").value = Carddata[cUnitType].RA;

  this.getField("DF").value = Carddata[cUnitType].DF;

  this.getField("RS").value = Carddata[cUnitType].RS;

  this.getField("DR").value = Carddata[cUnitType].DR;

  this.getField("MN").value = Carddata[cUnitType].MN;

  this.getField("HP").value = Carddata[cUnitType].HP;

  this.getField("Size").value = Carddata[cUnitType].Size;

  this.getField("UnitRank").value = Carddata[cUnitType].UnitRank;

  this.getField("Base").value = Carddata[cUnitType].Base;

  this.getField("Glorycost").value = Carddata[cUnitType].Glorycost;

  this.getField("Specialabilities").value = Carddata[cUnitType].Specialabilities;

  this.getField("SpecialAB").value = Carddata[cUnitType].SpecialAB;

}

Here's what I was trying to piece together to make parts of a string bold

var one = this.getField("SpecialAB").valueAsString; 

var spans = []; 

 

var span1 = {}; 

span1.textFont = font.HelvB; 

span1.text = "Combat Sense:"; 

spans.push(span1); 

 

var span2 = {}; 

span2.text = " Enemies cannot deploy models that have the Special Ability Stealth within 18 of this model" ; 

spans.push(span2); 

 

event.richValue = spans;

So,

1. I'm not sure where to put this, Document level javascript, or in the Field custom format script.

2. Very new at this, and I've been cobbling bits and pieces from all over learning as I go

3. Please help?

My end goal is to have all the "Special Abilities" names followed by the semicolon bolded in the "SpecialAB" field.

I have them returning to their own lines, but its not enough separation, and bold would stand out more.

This topic has been closed for replies.
Correct answer try67

I see. The structure of that code doesn't lend itself easily to that. I would recommend re-writing it in a different way.

This is not a trivial scripting task, though, if you don't have any experience writing Acrobat JavaScript code.


Actually, it might not be too difficult to do... Try this structure:

SpecialAB: [

               {text: "Combat Sense: ", fontWeight: 700},

               {text: "Enemies cannot deploy models that have the Special Ability Stealth within 18 of this model \n",},

               {text: "Tactician: ", fontWeight: 700},

               //etc.

          ]

And change this:

this.getField("SpecialAB").value = Carddata[cUnitType].SpecialAB;

To:

this.getField("SpecialAB").richValue = Carddata[cUnitType].SpecialAB;

Also, change it back to being a Format script. I misunderstood how it was used before.

1 reply

try67
Community Expert
Community Expert
June 27, 2019

1. As the field's custom calculation script.

2. Yes, that's clear... What is the purpose of the "one" variable? How is this code related to the first code?

3. To make a span bold you need to set the fontWeight property. For example:

span2.fontWeight = 700;

Participating Frequently
June 27, 2019

Hi,

Thanks for the quick answer.

I'm not sure what "var one" is

This is code from somewhere else I'm trying to make work the all the code above that.

Should it be something different?

I will also want to do this several times, so could I use the "var one", as in naming each instance

like "var one" "var two"...

Also,

so does this seem right?

var one = this.getField("SpecialAB").valueAsString;

var spans = [];

 

var span1 = {};

span1.fontWeight = 700;

span1.text = "Combat Sense:";

spans.push(span1);

 

var span2 = {};

span2.text = " Enemies cannot deploy models that have the Special Ability Stealth within 18 of this model" ;

spans.push(span2);

 

event.richValue = spans;

Participating Frequently
June 27, 2019

Hi,

so that works, but I guess I didn't explain enough....  that field "SpecialAB" populates based on a dropdown choice.

if I put the code in the fields custom calculation script, it just is always there. I need it to clear based on choice.

(which it does, except when I added this script)

do I need an if - then statement?

sorry, really new to this, and trying to learn.