6 Replies Latest reply on Aug 28, 2015 8:33 PM by CarlosCanto

    Removing ligatures from certain fonts if tracking greater than 0

    mondayze

      I'm importing files with certain fonts with tracking set at different sizes. Some fonts with certain ligatures don't work when tracking is set to anything higher than 0 without first turning off Standard Ligatures. I'm using a script that checks to see if those certain fonts are active and if so it then turns off ligatures for that font.

       

      My javascript knowledge is very basic and I created this script from mostly copying and pasting and changing things I found in the scripting guide. So I'm sure my code could use some better organizing. I first had it with a bunch of if statements and then found out I could use the || to use multiple values so I thought that might be a better way to write it??

       

      I want to add another if statement that first checks to see if these fonts have tracking set to anything greater than 0 and if so then turn the ligatures off, but if not keep them turned on. They work great when the tracking is at 0 and I would like to be able to use them still instead of completely disabling them.

       

      var docRef = app.activeDocument;
      
          for (var w = 0; w < docRef.textFrames.length; w++) {
              var textRef = docRef.textFrames[w];
              if ((textRef.textRange.characterAttributes.textFont == textFonts.getByName('Skitch')) ||
                  (textRef.textRange.characterAttributes.textFont == textFonts.getByName('AmarelinhaBold')) ||
                  (textRef.textRange.characterAttributes.textFont == textFonts.getByName('Amarelinha')) ||
                  (textRef.textRange.characterAttributes.textFont == textFonts.getByName('Zalderdash')) ) {
                  textRef.textRange.characterAttributes.ligature = false;
              }
          }
      
      redraw();
      
      
      

       

      Again I'm very new to javascript, but I think this should be a pretty simple addition? I'm honestly not even sure if the redraw(); is necessary? I do eventually want to add this to another import script.

       

      Thanks for your time!

        • 1. Re: Removing ligatures from certain fonts if tracking greater than 0
          mondayze Level 1

          And just like that I started thinking about it differently and figured it out... Feel free to weigh in on the syntax or anything I could do to make this more proficient and easier to add more fonts to.

           

          Thanks!

          var docRef = app.activeDocument;
          
              for (var w = 0; w < docRef.textFrames.length; w++) {
                  var textRef = docRef.textFrames[w];
                  if ((textRef.textRange.characterAttributes.textFont == textFonts.getByName('Skitch')) || 
                      (textRef.textRange.characterAttributes.textFont == textFonts.getByName('AmarelinhaBold')) || 
                      (textRef.textRange.characterAttributes.textFont == textFonts.getByName('Amarelinha')) || 
                      (textRef.textRange.characterAttributes.textFont == textFonts.getByName('Zalderdash')) ) {
                      if (textRef.textRange.characterAttributes.tracking >= 1) {
                      textRef.textRange.characterAttributes.ligature = false;
                      }
                  }
              }
          
          redraw();
          
          • 2. Re: Removing ligatures from certain fonts if tracking greater than 0
            CarlosCanto Adobe Community Professional & MVP

            that's ok, to optimize, pretty much you can make a variable out of any object that gets called repeatedly, for example characterAttributes, also, there's only one way to know if you need to redraw(), remove it and if you see that your code works, then it's not needed


            var docRef = app.activeDocument; 
            
            for (var w = 0; w < docRef.textFrames.length; w++) { 
                var textRef = docRef.textFrames[w];
               
                var charAttributes = textRef.textRange.characterAttributes;
                var textfont = charAttributes.textFont;
            
            
                if ((textfont == textFonts.getByName('Skitch')) || 
                    (textfont == textFonts.getByName('AmarelinhaBold')) || 
                    (textfont == textFonts.getByName('Amarelinha')) || 
                    (textfont == textFonts.getByName('Zalderdash')) ) { 
                    if (charAttributes.tracking >= 1) { 
                        charAttributes.ligature = false; 
                    } 
                } 
            } 
            
            • 3. Re: Removing ligatures from certain fonts if tracking greater than 0
              mondayze Level 1

              That looks way cleaner! Thanks for your help Carlos!

              • 4. Re: Removing ligatures from certain fonts if tracking greater than 0
                CarlosCanto Adobe Community Professional & MVP

                you're welcome, I think this can also help if you have lots of text frames, make variables for your fonts, outside of the loop

                 

                var docRef = app.activeDocument; 
                var skitchFont = textFonts.getByName('Skitch');
                
                

                 

                then use them inside the loop

                if ((textfont == skitchFont ||
                
                
                • 5. Re: Removing ligatures from certain fonts if tracking greater than 0
                  mondayze Level 1

                  Oh cool! Now I'm curious, is this to make the if statement in the loop cleaner or would this help performance?

                  • 6. Re: Removing ligatures from certain fonts if tracking greater than 0
                    CarlosCanto Adobe Community Professional & MVP

                    both, but mainly performance, it takes more time call a property of method (textFonts.getByName('Skitch')), than the variable in memory.

                    • 7. Re: Removing ligatures from certain fonts if tracking greater than 0
                      mondayze Level 1

                      Thanks again! Hey is there a way if a font isn't on the system it will skip it? I found if one of the fonts in the script aren't installed it will give me an error.

                      • 8. Re: Removing ligatures from certain fonts if tracking greater than 0
                        CarlosCanto Adobe Community Professional & MVP

                        this should take care of missing fonts, they'll get ignored

                         

                        var docRef = app.activeDocument; 
                        
                        
                        for (var w = 0; w < docRef.textFrames.length; w++) { 
                            var textRef = docRef.textFrames[w];
                           
                            var charAttributes = textRef.textRange.characterAttributes;
                            var textfont = charAttributes.textFont;
                           
                            try {
                                if ((textfont == textFonts.getByName('Skitch')) || 
                                    (textfont == textFonts.getByName('AmarelinhaBold')) || 
                                    (textfont == textFonts.getByName('Amarelinha')) || 
                                    (textfont == textFonts.getByName('Zalderdash')) ) { 
                                    if (charAttributes.tracking >= 1) { 
                                        charAttributes.ligature = false; 
                                    } 
                                }
                            }
                            catch (e) {};
                        }