3 Replies Latest reply on May 9, 2015 11:12 AM by oleh.melnyk
      • 1. Re: How can I get font family style
        [Jongware] Most Valuable Participant

        See this older question: How to get font classification (serif,sans,mono)...

         

        and the link to my Illustrator version of a script. The script shows what the designer put into the font, and so its main drawback is that some designers just ticked all "default" boxes. Still, it's a start.

        • 2. Re: How can I get font family style
          oleh.melnyk Level 3

          I forgot to mention that I already seen those script. I tried to modify it to fit my needs, so I'm able to get 10-digit array with PANOSE codes. But I don't understand how to convert it to what I need - "serif", "sans-serif", "monospaced", "script", etc?

           

           

          At first I was pretty sure that info I'm looking for is hiding behind first (zero - in programming) value (Family Kind), and all I need is to get table with values, like:

           

          switch(panose["Family Kind"]){

              case 0: return "serif"; break;

              case 1: return "sans-serif"; break;

              case 2: return "monospaced"; break;

              case 3: return "script"; break;

          ...

          }


          but looks like I was wrong... is there any way to convert panose codes to generic font family style name? Or this info is hiding under another file headers? I'm completely new to parsing binary files((

          • 3. Re: How can I get font family style
            oleh.melnyk Level 3

            This is what I'm working with:

             

            var font = "path/to/font/font.ttf"; // path to font here
            
            if(!File(font).exists){
                alert("Modify [var font] path in script"); exit();
            }
            
            // see more about getPanoseInfo() @ https://forums.adobe.com/thread/1101213
            function getPanoseInfo(file) {
                var f, hdr, numTable, t;
                var tableEntry, length;
                f = File(file);
                if (!f.open ("r")) return null;
                f.encoding = "BINARY";
                var hdr = getUlong(f);
                f.seek(0);
                var jump = f.read(f.length).indexOf('OS/2');
                if (jump == -1 || (hdr != 65536    // Microsoft Truetype
                    && hdr != 1330926671    // Adobe OTF ‘OTTO’ 
                    && hdr != 1953784678)) { //TTC
                    f.close();
                    return null;
                }
                f.seek(jump);
                tableEntry = f.read(16);
                length = (((((tableEntry.charCodeAt(12) << 8) +
                    tableEntry.charCodeAt(13)) << 8) +
                    tableEntry.charCodeAt(14)) << 8) +
                    tableEntry.charCodeAt(15);
                // suspicious length?
                if (length < 42 || length > 256) {
                    fclose (f);
                    return null;
                }
                // Locate OS/2 table in file
                offset = (((((tableEntry.charCodeAt(8) << 8) +
                    tableEntry.charCodeAt(9)) << 8) +
                    tableEntry.charCodeAt(10)) << 8) +
                    tableEntry.charCodeAt(11);
                // we can skip the first 32 bytes as these are not interesting (for now)
                f.seek (offset+32);
                var panose = [];
                for (t=0; t<10; t++)
                    panose.push (f.read(1).charCodeAt(0));
                f.close();
                return panose;
            }
            
            function getUshort (aFile){
                var result = aFile.read(2);
                return (result.charCodeAt(0)<<8) +
                result.charCodeAt(1);
            }
            
            function getUlong (aFile){
                var result = aFile.read(4);
                return ((((result.charCodeAt(0)<<8) +
                result.charCodeAt(1))<<8) +
                result.charCodeAt(2)<<8) +
                result.charCodeAt(3);
            }
            
            var panose = getPanoseInfo(font); // PANOSE: array with 10 digits here
            var fontParams = {
                "Family Kind": panose[0],
                "Serif Style": panose[1],
                "Weight": panose[2],
                "Proportion": panose[3],
                "Contrast": panose[4],
                "Stroke Variation": panose[5],
                "Arm Style": panose[6],
                "Letterform": panose[7],
                "Midline": panose[8],
                "X-height": panose[9]
            }
            
            /*
            "Family Kind":
                0-Any
                1-No Fit
                2-Latin Text
                3-Latin Hand Written
                4-Latin Decorative
                5-Latin Symbol
            
                See more @ http://web.archive.org/web/20140913211804/http://www.monotype.com/services/pan2#sthash.oLXEssPV.dpuf
            */
            
            var fontFamily;
            switch(fontParams["Family Kind"]){
                case 0:
                    fontFamily = "No Clasification";
                    break;
                 
                case 1:
                    fontFamily = "No assigned Font is similar";
                    break;
                 
                case 2: // also called as Text
                    /**
                        TODO: for now, most of fonts fall into this category: Serif, Sans Serif, Monospace, Modern, Iconic, Other... - need to differentiate them somehow!
                        Read more @ http://forum.high-logic.com/viewtopic.php?t=941 - there should be second digit (2.2 for Serif, 2.B for Sans Serif) that might help
                    */
                    fontFamily = "One of those: Serif, Sans Serif, Monospaces, Modern, Iconic, Other";
                    break;
                 
                case 3: // also called as Hand Written
                    fontFamily = "Script";
                    break;
                 
                case 4:
                    fontFamily = "Decorative";
                    break;
                 
                case 5:
                    fontFamily = "Symbol";
                    break;
            
                default:
                    fontFamily = fontParams["Family Kind"];
            }
            
            /*
            for(i in fontParams)
                alert(i+": "+fontParams[i]);
            */
            alert(fontFamily);
            

             

            The problem is that most of font families fall into 2 category: Serif, Sans Serif, Monospace, Modern, Iconic, Other, so need to find the way to to differentiate them somehow