5 Replies Latest reply on Feb 24, 2010 6:15 AM by Vinoth Jaguva

    Minumum and Maximum pointsize in the active document with font name

    Vinoth Jaguva Level 1

      hi

       

      How to find the font with point size in active document and how to get the minimum point size and maximum point size used in the active document with font name

      Thanks in Advance.

        • 1. Re: Minumum and Maximum pointsize in the active document with font name
          [Jongware] Most Valuable Participant

          ?

           

          (thoughtfully added because it appeared to be missing in your post.)

           

          I believe TextStyleRanges can gather all that information for you. To check an entire document, you will have to iterate over all its stories; with these stories, iterate over the text style ranges. For a minimum and maximum (per font? not totally clear) you can use the size of the very first text style range you find, then compare all next ones to these.

           

          Apart from a question mark, there are a few more important things missing from your post. InDesign version? Language? Platform? Are you willing to pay for a complete working script, written & tested by a professional, or are you trying to write something yourself and got stuck? If so, what do you have so far?

          • 2. Re: Minumum and Maximum pointsize in the active document with font name
            Vinoth Jaguva Level 1

            hi

             

            Thanks for your Quick Reply.

             

            Find below the answer as required.

             

            Indesign Version CS3

            Language english

            Platform windows/mac

             

            find below the script

             

            ================================================

            myAllFonts = app.fonts;
            _UsedAllFonts = new Array;
            for(p=0;p<=app.documents[0].pages.length-1;p++){
            UsedFonts = new Array;
            _UsedFonts = new Array;
            UsedFonts_ = new Array;
            for(t=app.documents[0].pages[p].textFrames.length-1;t>=0;t--){
              myRanges = app.documents[0].pages[p].textFrames[t].textStyleRanges;
               for(i=myRanges.length-1;i>=0;i--){
                var FontStyle;
                if(myRanges[i].fontStyle !=""){
                 FontStyle = "\t"+myRanges[i].fontStyle;
                }
                else{
                 FontStyle = "";
                }
                if(myRanges[i].appliedFont != ""){
                 UsedFonts.push(myRanges[i].appliedFont.fontFamily+FontStyle);
                }
               }
               UsedFonts_ = UsedFonts_.concat(UsedFonts);
               UsedFonts = UniteSame(UsedFonts_);
            }
            _UsedFonts = UniteSame(UsedFonts);
            //
            _UsedAllFonts = _UsedAllFonts.concat(_UsedFonts);
            _UsedAllFonts = UniteSame(_UsedAllFonts);
            //
            UsedFontss = _UsedFonts.join(",");
            //
            try{
              myTextFrame = app.documents[0].pages[p].textFrames.item("EveryPage"+(p+1));
              myTextFrame.contents = UsedFontss;                  
              myTextFrameProp(myTextFrame);
            }  
            catch(e){                                                 
              myTextFrame = app.documents[0].pages[p].textFrames.add();
              myTextFrame.geometricBounds = new Array(-40, 0, 0.001, app.documents[0].documentPreferences.pageWidth);
              myTextFrame.label = "EveryPage"+(p+1);
              myTextFrame.contents = UsedFontss;
              myTextFrameProp(myTextFrame);
            }
            }
            //
            UsedAllFonts = UniteSame(_UsedAllFonts);
            UsedAllFontss = UsedAllFonts.join(",");
            //
            try{
            myTextFrameA = app.documents[0].pages[0].textFrames.item("All");
            myTextFrameA.textFramePreferences.verticalJustification = VerticalJustification.bottomAlign;
            myTextFrameA.contents = UsedAllFontss;                                    
            myTextFrameProp(myTextFrameA);                    
            }
            catch(e){                                                                 
            myTextFrameA = app.documents[0].pages[0].textFrames.add();
            myTextFrameA.textFramePreferences.verticalJustification = VerticalJustification.bottomAlign;                                            
            myTextFrameA.geometricBounds = new Array(app.documents[0].documentPreferences.pageHeight+40, 0, app.documents[0].documentPreferences.pageHeight-0.001, app.documents[0].documentPreferences.pageWidth);
            myTextFrameA.label = "All";
            myTextFrameA.contents = UsedAllFontss;                                                                  
            myTextFrameProp(myTextFrameA);
            }
            alert(myTextFrameA.contents);
            alert("Done!");
            function myTextFrameProp(myTextFrameA){
            myTextA = myTextFrameA.texts.item(0);//words[-1];                                                      
            myTextA.appliedFont = "Arial";                                                                       
            myTextA.pointSize = "14pt";                                                                          
            myTextA.leading = "16pt";
            myTextA.fillColor = app.documents[0].swatches.item("Black");                                                                             
            myTextA.justification = Justification.leftJustified;
            }

            function UniteSame(A) {
            var x,y;
            for ( x=0;x<=A.length-1; x++){
              for ( y=A.length-1;y>=0; y--){
                if ((A[x] == A[y])&&(y!=x)){
                  A.splice(y,1);
                }
              }
            }
            return(A.sort());
            }

            ===================================================

            • 3. Re: Minumum and Maximum pointsize in the active document with font name
              [Jongware] Most Valuable Participant

              Okay, that does look good (without testing it). Does it do its job?

               

              I think it can be made a bit more efficiently by not running over all text frames, but rather over all stories in the document -- a small change, the rest can stay the same.

               

              You can also try turning the gathering of used data around. It appears you are now pushing every item immediately into your array, then weed out duplicates. (For my thoughts on the latter, see below!) It might be quicker and more memory-efficient to scan your present array to see if the new item is already in there, and only push when it's not. (Bonus points for a binary tree implementation -- the fastest possible way! But a linear search on the entire array, or on a sorted array and bailing out if you go "past" the current item, may be fast enough.)

               

              (On Weeding out duplicates; you might want to skip this, as it won't be necessary for the above:)

              Your function UniteSame sorts out and removes duplicates by comparing every item to every other one; then it sorts the array. An alternative can be to

               

              1. Sort the array

              2. Create a new empty one

              3. Push an item of the original onto the new one.

              4. Skip items of the original list while they are the same as the bottom one of the new list.

              5. Until you run out of items.

              • 4. Re: Minumum and Maximum pointsize in the active document with font name
                [Jongware] Most Valuable Participant

                Here is a fast script that gathers all font names -- notice my version of removeDups, it uses a quick-and-dirty removeDups.

                I didn't try, but it should be possible to add point sizes as well.

                 

                var completelist = app.activeDocument.stories.everyItem().textStyleRanges.everyItem().appliedFont;
                var shortlist = removeDups (completelist);
                resultFrame = app.activeDocument.textFrames.add();
                resultFrame.geometricBounds = [ "0mm","0mm", "200mm", "200mm" ];
                resultFrame.insertionPoints[0].appliedFont = "Times New Roman";
                resultFrame.insertionPoints[0].pointSize = 8;
                resultFrame.contents = shortlist.join('\r');
                function removeDups (sourceArray)
                {
                 var tmpArray = new Array;
                 var a;
                 tmpArray.push (sourceArray.pop().name);
                 while (sourceArray.length)
                 {
                  var nextVal = sourceArray.pop().name;
                  for (a=0; a<tmpArray.length; a++)
                  {
                   if (nextVal <= tmpArray[a])
                   {
                    if (nextVal < tmpArray[a])
                    {
                     tmpArray.splice(a,0, nextVal);
                    }
                    break;
                   }
                  }
                  if (a == tmpArray.length)
                   tmpArray.push (nextVal);
                 }
                 return tmpArray;
                }
                
                • 5. Re: Minumum and Maximum pointsize in the active document with font name
                  Vinoth Jaguva Level 1

                  Hi

                   

                  Thanks for your reply, I was tried with your customized script, but I am unable to find the solution. I have a another option that, the indd files will be convert as inx file from that we can try to get the font size, kindly advise on this.