Jump to content

Setting tabs as part of a function


seymoujd

Recommended Posts

Wanted to create a function that allows users to choose a style from Field A that formats the text they enter in Field B.

 

I came up with the following function which appears to work pretty well. My problem arrises when I come to the "Bullets" case I need bulleted text to have a tab stop of .125 in and a second line indent of 0p9. Is there a way to include this in the switch statement so that it doesn't effect all the other fields in the text frame?

 


function styleText(style,text){

titleFormat = '<color name="NSU green"><f name ="Interstate Black"><z newsize="28">';
subtitleFormat = '<color name="NSU green"><f name ="Interstate RegularCondensed"><z newsize="20">';

headFormat = '<color name="NSU green"><f name ="Interstate BlackCondensed"><z newsize="16"><uppercase>';
subheadFormat = '<color name="black"><f name ="Interstate RegularCondensed"><z newsize="14">';

bulletCharFormat = '<color name="nsultgreen"><f name ="Interstate Black"><z nesize="10">';
bulletTextFormat = '<color name="black"><f name ="Aldine401 BT"><z newsize="10">';

plainTextFormat ='<color name="black"><f name ="Aldine401 BT"><z newsize="10">';

   var result;



   switch (style) {
       case "Title":
           result = titleFormat+text;
           break;

       case "Subtitle":
           result = subtitleFormat+text;
           break;

       case "Head":
           result = headFormat+text;
           break;

       case "Subhead":
           result = subheadFormat+text;
           break;

       case "Bullets":
           var MyVar=text;
           var MyArray=MyVar.split("<p>");
           var MyString='<p>'+bulletCharFormat+'»<t>'+bulletTextFormat+MyArray[0];

           if (MyVar==""){
               return "";
           }else{
               for (i=1;i<MyArray.length;i++){
                   MyString+='<br><p>'+bulletCharFormat+'»<t>'+bulletTextFormat +MyArray[i];
               }
           };
           return MyString;
           break;

       case "Plain Text":
           result = plainTextFormat+text;
           break;

       default:
           result = plainTextFormat+text;
       }
   return result;
};

Link to comment
Share on other sites

Tabs are part of the paragraph style, specified as the "tabstops" attribute of the <p> tag. I would set up the tab stops you want in a Formatted Text Resource and use the "View Source" button to see exactly what the markup is, and of course refer to the Tags Reference Guide.

 

As for setting the tabs "so that it doesn't effect all the other fields in the text frame," the paragraph style is reset at the start of each new paragraph entered in the Text Editor, so that should just happen automatically.

 

The other trick with <p> tags (which you can see with that "View Source" button") is that you can use the attributes br=false and override=true to override the running paragraph's style, without actually starting a new paragraph. (Also, you can use the <br> tag as a "soft return" to start a new line without actually starting a new paragraph.)

 

The other thing you need is an indent, which is also an attribute of the <p> tag; in this case, it's "lindent" for all lines after the first. (The "fiindent" attribute applies to the first line.)

 

At any rate, DSweet has already provided almost exactly the markup you need in this post:

http://forums.pti.com/showpost.php?p=442&postcount=5

Link to comment
Share on other sites

That worked! Thank you.

 

I have one more question. For some reason the bullet character for the first paragraph in each list is larger that the rest. What is causing that?

 

I have attached a screen shot to show what is happening. Here is my updated code

 

function styleText(style,text){

titleFormat = '<p linespacing=".75"><color name="NSU green"><f name ="Interstate Black"><z newsize="28">'; //
subtitleFormat = '<color name="NSU green"><f name ="Interstate RegularCondensed"><z newsize="20">';

headFormat = '<p leadafter="450"><color name="NSU green"><f name ="Interstate BlackCondensed"><z newsize="16"><uppercase>'; 
subheadFormat = '<p leadafter="450"><color name="black"><f name ="Interstate RegularCondensed"><z newsize="14">';

bulletCharFormat = '<p style="(no style)" br="false" override="true" quad="L" linespacing="1" findent="0" lindent="0" rindent="0" leadbefore="0" leadafter="450" keeplines="true" widows="2" kerning="true" hyphenate="false" skipifempty="false" skipifemptyvar="false" noparabreakoncopyfit="false" tabstops="0;R900,Left"><color name="nsultgreen"><f name ="Interstate Bold"><z nesize="10">';
bulletTextFormat = '<p style="(no style)" br="false" override="true" quad="L" linespacing="1" findent="0" lindent="1800" rindent="0" leadbefore="0" leadafter="450" keeplines="true" widows="2" kerning="true" hyphenate="false" skipifempty="false" skipifemptyvar="false" noparabreakoncopyfit="false" tabstops="0;R900,Left"><color name="black"><f name ="Aldine401 BT"><z newsize="10">';

plainTextFormat ='<color name="black"><f name ="Aldine401 BT"><z newsize="10">';

   var result;



   switch (style) {
       case "Title":
           result = titleFormat+text;
           break;

       case "Subtitle":
           result = subtitleFormat+text;
           break;

       case "Head":
           result = headFormat+text;
           break;

       case "Subhead":
           result = subheadFormat+text;
           break;

       case "Bullets":
           var MyVar=text;
           var MyArray=MyVar.split("<p>");
           var MyString= bulletCharFormat+'»<t>'+bulletTextFormat+MyArray[0];

           if (MyVar==""){
               return "";
           }else{
               for (i=1;i<MyArray.length;i++){
                   MyString+='<br><p>'+bulletCharFormat+'»<t>'+bulletTextFormat +MyArray[i];
               }
           };
           return MyString;
           break;

       case "Plain Text":
           result = plainTextFormat+text;
           break;

       default:
           result = plainTextFormat+text;
       }
   return result;
};

ScreenShot2015-10-23at9_30_47AM.png.8093011637073166d508ffd4efca8168.png

Edited by seymoujd
Link to comment
Share on other sites

I have one more question. For some reason the bullet character for the first paragraph in each list is larger that the rest. What is causing that?

The problem is highlighted in Red here (you may need to scroll to the right):

bulletCharFormat = '<p style="(no style)" br="false" override="true" quad="L" linespacing="1" findent="0" lindent="0" rindent="0" leadbefore="0" leadafter="450" keeplines="true" widows="2" kerning="true" hyphenate="false" skipifempty="false" skipifemptyvar="false" noparabreakoncopyfit="false" tabstops="0;R900,Left"><color name="nsultgreen"><f name ="Interstate Bold">[color="Red"]<z nesize="10">[/color]';
bulletTextFormat = '<p style="(no style)" br="false" override="true" quad="L" linespacing="1" findent="0" lindent="1800" rindent="0" leadbefore="0" leadafter="450" keeplines="true" widows="2" kerning="true" hyphenate="false" skipifempty="false" skipifemptyvar="false" noparabreakoncopyfit="false" tabstops="0;R900,Left"><color name="black"><f name ="Aldine401 BT"><z newsize="10">';

That should be <z newsize="10">, not <z nesize="10">.

 

In fact, if you compose and look in the composition log (.msg) file, there's probably a warning message saying something like "Unknown attribute nesize."

 

You also don't need to specify every attribute of the <p> tag every time, especially for values that already match the defaults, like zero indents. This should work just as well:

bulletCharFormat = '<p br="false" override="true" leadafter="450" lindent="1800" keeplines="true" kerning="true" hyphenate="false" tabstops="0;R900,Left"><color name="nsultgreen"><f name ="Interstate Bold"><z newsize="10">';
bulletTextFormat = '<f name ="Aldine401 BT"><z newsize="10">';

And you can take out the <p> tag after the <br> in case "Bullets" as well.

 

Another thing to know is that you can set up character and paragraph styles in InDesign; then when you export from InDesign, you can use those named paragraph styles in your <p> tags in FusionPro, such as <p name="Head">.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...