sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Can you get a list of OSX fonts somehow?

    Scheduled Pinned Locked Moved Developers' Forum
    110 Posts 6 Posters 13.9k Views 6 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thomthomT Offline
      thomthom
      last edited by

      b=["(\n Momo\n)", "(\n Trek\n)", "(\n \"Machine Tool Gothic\"\n)", "(\n \"Machine Tool SanSerif\"\n)"] c=b.map { |f| f[/[("\s]+([^"\n]+)[)"\s]+/m,1] }

      Returns:
      ["Momo", "Trek", "Machine Tool Gothic", "Machine Tool SanSerif"]

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • D Offline
        driven
        last edited by

        excellent Thomas,

        when I use it on /Library/Fonts/*.*tf I get a more complete list, but some are linked files so I get
        "could not find /Library/Fonts//儷宋."
        how do I filter those out? [if I can't resolve them]
        john

        learn from the mistakes of others, you may not live long enough to make them all yourself...

        1 Reply Last reply Reply Quote 0
        • D Offline
          driven
          last edited by

          ###################################################################### t=Time.now a=(find -d /Library/Fonts -name "*.t").split("\n").map { |f| f.gsub(" ", "\\ ")} b=(a.collect{|x| mdls -nullMarker missing -raw -name com_apple_ats_name_family #{x}}) c=b.map { |f| f[/[("\s]+([^"\n]+)[)"\s]+/m,1] }.uniq puts c, "\n v2", Time.now-t ######################################################################
          187 fonts from 1 Library in 7.147912 and I still have a couple of commas to remove...
          john

          learn from the mistakes of others, you may not live long enough to make them all yourself...

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            characters.png

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • D Offline
              driven
              last edited by

              `tt,
              that's your browser not recognising the UFT8 apple icon. IE sometimes will show the Windows icon.

              I use it as a line marker for mac only scripts I'm testing, so when I had 3 time now's I could find the end of each easily.
              john

              learn from the mistakes of others, you may not live long enough to make them all yourself...

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                I use Firefox.
                Firefox understands UTF-8. There's some conversion going on here that mangles the formatting.

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • D Offline
                  driven
                  last edited by

                  Link Preview Image
                  The Apple Logo in Unicode

                  favicon

                  (hea-www.harvard.edu)

                  @unknownuser said:

                  This is probably fine for Mac-only applications. But it is NOT appropriate, and even WRONG, and it will NOT work properly as a general web page character. The problem is that the unicode value used is one of several that is set aside for private use. That means that each operating system, or application, or implementation is free to use those unicode characters for anything they want. It just so happens that Apple has chosen to use unicode character U+F8FF (decimal value 63743, or on the web as either  or ) as the Apple Logo. But some Windows fonts put in a Windows logo. And some other fonts put in a Klingon Mummification glyph. Or elven script. Or anything they want. And if it isn't defined in your local font, you'll just see a square. So who knows what you might see when I put the character in right here: 

                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    Ah - a non-standard. That explains it.

                    Thomas Thomassen — SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      driven
                      last edited by

                      Found the problem, and a massive speed-up...
                      > t=Time.now fontList=(/opt/X11/bin/fc-list : file family | grep /Library/Fonts).split("\n").collect { |f| f.split(":")[1] }.collect { |f| f.split(",")[0] }.to_a.uniq.compact.sort[5..-1] fin=Time.now-t puts fontList.length puts fin, Time.now-t puts fontList puts Time.now-t 296 0.049741 0.056441 *...print fonts* 1.440642
                      however............ not everyone has X11
                      john

                      learn from the mistakes of others, you may not live long enough to make them all yourself...

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        driven
                        last edited by

                        But, the good news is brew install fontconfig will put it in 'usr/local/bin/fc-list' without all the X11 or hidden system fonts... speed on first run, slower, but still acceptable
                        then, the penny dropped that you no longer need grep or one of the collects, so
                        t=Time.now fontList=(/usr/local/bin/fc-list : family ).split("\n").collect { |f| f.split(",")[0] }.to_a.uniq.compact.sort fin=Time.now-t puts fontList.length puts fin, Time.now-t puts fontList puts fontList.length puts fin, Time.now-t 274 0.017442 0.023794 ...print fonts 1.363478
                        not to shabby
                        john

                        learn from the mistakes of others, you may not live long enough to make them all yourself...

                        1 Reply Last reply Reply Quote 0
                        • TIGT Offline
                          TIG Moderator
                          last edited by

                          So you HAVE got fc-list to work after all! 😄
                          Don't you need to include 'file' in the output as well as 'family' and grep for '.ttf' because 3dText needs a /ttf and the 'family only' way might also list .otf fonts etc too, which 3dText might baulk at ?
                          Something more like:
                          fontList=(/usr/local/bin/fc-list : file family | grep .ttf:).split("\n").collect{|f|f.split(": ")[1].split(",")[0]}.to_a.uniq.compact.sort
                          I'm not sure how you deal with the ".ttf:" - it perhaps needs some \ escaping ??
                          If the 'grep' inside the MAC OS side is slower than doing a 'next unless f=~/.ttf: /' on the Ruby side, then you can add it into the 'collect' block instead...

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • thomthomT Offline
                            thomthom
                            last edited by

                            You got data back from fc-list using SketchUp Ruby??? ... but using a full path, that's the only change?

                            Thomas Thomassen — SketchUp Monkey & Coding addict
                            List of my plugins and link to the CookieWare fund

                            1 Reply Last reply Reply Quote 0
                            • thomthomT Offline
                              thomthom
                              last edited by

                              fontList=(/usr/local/bin/fc-list : family ) returned nothing on my machine.

                              Thomas Thomassen — SketchUp Monkey & Coding addict
                              List of my plugins and link to the CookieWare fund

                              1 Reply Last reply Reply Quote 0
                              • D Offline
                                driven
                                last edited by

                                @tig said:

                                So you HAVE got fc-list to work after all! 😄
                                Don't you need to include 'file' in the output as well as 'family' and grep for '.ttf' because 3dText needs a /ttf and the 'family only' way might also list .otf fonts etc too, which 3dText might baulk at ?

                                YES... using fontList=(**/opt/X11/bin/fc-list** : file family | grep \/Library\/Fonts), but just to avoid X11 fonts, otherwise, all types [.ttf, otf, ttc] returned, work in SU [tested last weekend], so /Library/Fonts filter is OK.

                                @unknownuser said:

                                If the 'grep' inside the MAC OS side is slower than doing a 'next unless f=~/.ttf: /' on the Ruby side, then you can add it into the 'collect' block instead...

                                it's the core dump size that slows things down
                                IF YOU HAVE IT INSTALLED...
                                > t=Time.now fontList=(/opt/X11/bin/fc-list : file family `)
                                fin=Time.now-t
                                puts fontList.length
                                puts fin

                                138048
                                0.055793
                                nilBut,**%(#0040FF)[IF YOU HAVE IT INSTALLED...]** > t=Time.now
                                fontList=(/usr/local/bin/fc-list : file family )
                                fin=Time.now-t
                                puts fontList.length
                                puts fin

                                22832
                                0.073191
                                nil

                                t=Time.now
                                fontList=(/usr/local/bin/fc-list : family )
                                fin=Time.now-t
                                puts fontList.length
                                puts fin

                                5921
                                0.016585
                                nil`
                                now I've realised the full path bit, there may be other ways without using fc-list...
                                john

                                learn from the mistakes of others, you may not live long enough to make them all yourself...

                                1 Reply Last reply Reply Quote 0
                                • thomthomT Offline
                                  thomthom
                                  last edited by

                                  You are using these paths:

                                  /opt/X11/bin/fc-list
                                  /usr/local/bin/fc-list

                                  That didn't work for me (10.5). But this worked:
                                  /usr/X11/bin/fc-list

                                  Are any of the paths working across OSX versions?

                                  Thomas Thomassen — SketchUp Monkey & Coding addict
                                  List of my plugins and link to the CookieWare fund

                                  1 Reply Last reply Reply Quote 0
                                  • thomthomT Offline
                                    thomthom
                                    last edited by

                                    So, because I've had problems even getting the data I've ignored the fact that you've been also getting the filename and grepping out by path. What is the reason for this. So you only get fonts that works in SketchUp?

                                    Thomas Thomassen — SketchUp Monkey & Coding addict
                                    List of my plugins and link to the CookieWare fund

                                    1 Reply Last reply Reply Quote 0
                                    • thomthomT Offline
                                      thomthom
                                      last edited by

                                      This worked on my machine:

                                      <span class="syntaxdefault"><br />data&nbsp;</span><span class="syntaxkeyword">=&nbsp;(`</span><span class="syntaxstring">/usr/X11/bin/fc-list&nbsp;;&nbsp;file&nbsp;family&nbsp;|&nbsp;grep&nbsp;\/Library\/Fonts</span><span class="syntaxkeyword">`)<br /></span><span class="syntaxdefault">fonts&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">data</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">scan</span><span class="syntaxkeyword">(/[^;]+[;]\</span><span class="syntaxdefault">s</span><span class="syntaxkeyword">*(.*)/).</span><span class="syntaxdefault">flatten</span><span class="syntaxkeyword">!<br /></span><span class="syntaxdefault">fonts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">map</span><span class="syntaxkeyword">!&nbsp;{&nbsp;|</span><span class="syntaxdefault">string</span><span class="syntaxkeyword">|&nbsp;</span><span class="syntaxdefault">string</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">','</span><span class="syntaxkeyword">)&nbsp;}.</span><span class="syntaxdefault">flatten</span><span class="syntaxkeyword">!&nbsp;</span><span class="syntaxcomment">#&nbsp;Some&nbsp;lines&nbsp;include&nbsp;multiple&nbsp;fonts.<br />&nbsp;</span><span class="syntaxdefault"></span>
                                      

                                      😍

                                      Now it's just a matter of reliably finding the path on all the systems.

                                      Thomas Thomassen — SketchUp Monkey & Coding addict
                                      List of my plugins and link to the CookieWare fund

                                      1 Reply Last reply Reply Quote 0
                                      • thomthomT Offline
                                        thomthom
                                        last edited by

                                        <span class="syntaxdefault"><br />def&nbsp;get_osx_fonts<br />&nbsp;&nbsp;fc_list_locations&nbsp;</span><span class="syntaxkeyword">=&nbsp;[<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxstring">'/opt/X11/bin/fc-list'</span><span class="syntaxkeyword">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxstring">'/usr/local/bin/fc-list'</span><span class="syntaxkeyword">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxstring">'/usr/X11/bin/fc-list'<br />&nbsp;&nbsp;</span><span class="syntaxkeyword">]<br />&nbsp;&nbsp;</span><span class="syntaxdefault">fc_list&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">fc_list_locations</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">find&nbsp;</span><span class="syntaxkeyword">{&nbsp;|</span><span class="syntaxdefault">location</span><span class="syntaxkeyword">|&nbsp;</span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">exist</span><span class="syntaxkeyword">?(&nbsp;</span><span class="syntaxdefault">location&nbsp;</span><span class="syntaxkeyword">)&nbsp;}<br />&nbsp;&nbsp;if&nbsp;</span><span class="syntaxdefault">fc_list</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">nil</span><span class="syntaxkeyword">?<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">puts&nbsp;</span><span class="syntaxstring">'Warning;&nbsp;Could&nbsp;not&nbsp;find&nbsp;fc-list!'<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxkeyword">return&nbsp;[]<br />&nbsp;&nbsp;</span><span class="syntaxdefault">end<br />&nbsp;&nbsp;data&nbsp;</span><span class="syntaxkeyword">=&nbsp;(`</span><span class="syntaxstring">#{fc_list}&nbsp;;&nbsp;file&nbsp;family&nbsp;|&nbsp;grep&nbsp;\/Library\/Fonts</span><span class="syntaxkeyword">`)<br />&nbsp;&nbsp;</span><span class="syntaxdefault">fonts&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">data</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">scan</span><span class="syntaxkeyword">(/[^;]+[;]\</span><span class="syntaxdefault">s</span><span class="syntaxkeyword">*(.*)/).</span><span class="syntaxdefault">flatten</span><span class="syntaxkeyword">!<br />&nbsp;&nbsp;</span><span class="syntaxdefault">fonts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">map</span><span class="syntaxkeyword">!&nbsp;{&nbsp;|</span><span class="syntaxdefault">string</span><span class="syntaxkeyword">|&nbsp;</span><span class="syntaxdefault">string</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">','</span><span class="syntaxkeyword">)&nbsp;}.</span><span class="syntaxdefault">flatten</span><span class="syntaxkeyword">!&nbsp;</span><span class="syntaxcomment">#&nbsp;Some&nbsp;lines&nbsp;include&nbsp;multiple&nbsp;fonts.<br />&nbsp;&nbsp;</span><span class="syntaxdefault">fonts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">uniq</span><span class="syntaxkeyword">!<br />&nbsp;&nbsp;</span><span class="syntaxdefault">fonts</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">sort</span><span class="syntaxkeyword">!&nbsp;</span><span class="syntaxcomment">#&nbsp;(!)&nbsp;Not&nbsp;UTF-8&nbsp;compatible!&nbsp;But&nbsp;better&nbsp;than&nbsp;nothing.<br />&nbsp;&nbsp;</span><span class="syntaxdefault">fonts<br />end<br /></span>
                                        

                                        Thomas Thomassen — SketchUp Monkey & Coding addict
                                        List of my plugins and link to the CookieWare fund

                                        1 Reply Last reply Reply Quote 0
                                        • D Offline
                                          driven
                                          last edited by

                                          hi TT,
                                          I did PM before I saw this, I would split it into 3 conditional block

                                          the first would use /usr/local/bin/fc-list
                                          if you revisit http://sketchucation.com/forums/viewtopic.php?f=180&t=48761&p=443899#p441686 you'll see that you don't need to grep /usr/local/bin/fc-list, because it avoids the system and X11 fonts already.

                                          second choose last in find /**/bin/fc-list array, for the latest X11 version

                                          third default to 'FontBook' it's on every mac....

                                          john

                                          learn from the mistakes of others, you may not live long enough to make them all yourself...

                                          1 Reply Last reply Reply Quote 0
                                          • thomthomT Offline
                                            thomthom
                                            last edited by

                                            Isn't fc-list on every mac?

                                            Thomas Thomassen — SketchUp Monkey & Coding addict
                                            List of my plugins and link to the CookieWare fund

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 5
                                            • 6
                                            • 6 / 6
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement