sketchucation logo sketchucation
    • 登入
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    Can you get a list of OSX fonts somehow?

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    110 貼文 6 Posters 15.5k 瀏覽 6 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • D 離線
      driven
      最後由 編輯

      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 條回覆 最後回覆 回覆 引用 0
      • D 離線
        driven
        最後由 編輯

        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 條回覆 最後回覆 回覆 引用 0
        • TIGT 離線
          TIG Moderator
          最後由 編輯

          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 條回覆 最後回覆 回覆 引用 0
          • thomthomT 離線
            thomthom
            最後由 編輯

            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 條回覆 最後回覆 回覆 引用 0
            • thomthomT 離線
              thomthom
              最後由 編輯

              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 條回覆 最後回覆 回覆 引用 0
              • D 離線
                driven
                最後由 編輯

                @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 條回覆 最後回覆 回覆 引用 0
                • thomthomT 離線
                  thomthom
                  最後由 編輯

                  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 條回覆 最後回覆 回覆 引用 0
                  • thomthomT 離線
                    thomthom
                    最後由 編輯

                    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 條回覆 最後回覆 回覆 引用 0
                    • thomthomT 離線
                      thomthom
                      最後由 編輯

                      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 條回覆 最後回覆 回覆 引用 0
                      • thomthomT 離線
                        thomthom
                        最後由 編輯

                        <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 條回覆 最後回覆 回覆 引用 0
                        • D 離線
                          driven
                          最後由 編輯

                          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 條回覆 最後回覆 回覆 引用 0
                          • thomthomT 離線
                            thomthom
                            最後由 編輯

                            Isn't fc-list on every mac?

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

                            1 條回覆 最後回覆 回覆 引用 0
                            • D 離線
                              driven
                              最後由 編輯

                              @thomthom said:

                              Isn't fc-list on every mac?

                              TT... don't you read PM's or the posts... [I am laughing]

                              reminds me of when you answer some of your 'clients'

                              The whole reason I went round in circles is fc=list has never been 'standard' on a mac.

                              a lot of people use to have xcode and it came with that as part of fontconfig for X11,

                              or if you have Wings3D, Gimp, Inkscape or Imagemagics you'd have it, so a few SU'ers will. but they all have FontBook it's a mac core app....

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

                              1 條回覆 最後回覆 回覆 引用 0
                              • D 離線
                                driven
                                最後由 編輯

                                TO RECAP
                                This is the fastest I can get a usable list from X11
                                if I remove .split[-2] from fontPath it uses /usr/local/bin and is twice as fast, same result... so the one could be used for any fc-list installed, without hardcoding a path.

                                 fontPath=(`find /*/*/bin/fc-list`).split[-2]
                                fontList=(`#{fontPath}  ; file family | grep \/Library\/Fonts`).split("\n").collect { |f| f.split(";")[1] }.collect { |f| f.split(",")[0].strip}.to_a.uniq.compact.sort[5..-5]
                                

                                the .sort[5..-5] cleans out the dot files at top and some other cruft the the bottom...
                                john
                                EDIT: I missed a .strip that stop them running... leading whitespace.
                                on test a couple are getting through that shouldn't
                                *** macFonts group Error! *** i = 38 chunk = 4 font = Bitstream Charter Error #<TypeError: reference to deleted Group> Error: #<TypeError: (eval):282:inname=': reference to deleted Group>
                                (eval):299
                                (eval):282
                                (eval):274:in times' (eval):274

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

                                1 條回覆 最後回覆 回覆 引用 0
                                • thomthomT 離線
                                  thomthom
                                  最後由 編輯

                                  @driven said:

                                  TT... don't you read PM's or the posts... [I am laughing]

                                  I've become so confused on this whole topic. 😕

                                  @driven said:

                                  This is the fastest I can get a usable list from X11

                                  fontPath=(find ///bin/fc-list).split[-2]
                                  That command was very slow on my mac.

                                  @driven said:

                                  the .sort[5..-5] cleans out the dot files at top and some other cruft the the bottom...
                                  Can you be sure this is the same on all machines? I'm hesitant to use magic numbers.

                                  OSX is giving me headackes in regard to this plugin. I'm tempted to just drop it all together. Taking too much time.

                                  At the moment I'm looking at first attempting fc-list, if it's installed. (Might have to do a search - so I have to cache that.) Then fall back to AppleScript and FontBook - also slow so it also needs a cache list (meaning the list won't automatically keep in sync.)

                                  sigh

                                  And that's not including the crashing...

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

                                  1 條回覆 最後回覆 回覆 引用 0
                                  • D 離線
                                    driven
                                    最後由 編輯

                                    TT, maybe you want to move this, but
                                    I was looking for a UFT8 font filter and came across a simple test code for checking console encoding.

                                    I thought Ruby Console was UFT8, but it's not?

                                    I made a little test script, and ran it both from console and from plugins.
                                    same result from both...

                                    >  msg = (`perl -Mcharnames=;full -CS -wle 'print "\N{EURO SIGN}"'`).to_s
                                     puts msg
                                     rply = (`locale`).to_s
                                     puts rply
                                     result = UI.messagebox msg, MB_YESNO
                                     if result == 6 # Yes
                                       UI.messagebox("Sketchup dosen't use UFT8, it uses \n" + rply)
                                     end
                                    N{EURO SIGN}
                                    LANG=
                                    LC_COLLATE="C"
                                    LC_CTYPE="C"
                                    LC_MESSAGES="C"
                                    LC_MONETARY="C"
                                    LC_NUMERIC="C"
                                    LC_TIME="C"
                                    LC_ALL=
                                    1
                                    

                                    for comparison Terminal.app results

                                    %(#008000)[johns_iMac at upstairs in ~
                                    $ locale
                                    LANG="en_US"
                                    LC_COLLATE="en_US.UTF-8"
                                    LC_CTYPE="en_US.UTF-8"
                                    LC_MESSAGES="en_US.UTF-8"
                                    LC_MONETARY="en_US.UTF-8"
                                    LC_NUMERIC="en_US.UTF-8"
                                    LC_TIME="en_US.UTF-8"
                                    LC_ALL="en_US.UTF-8"
                                    johns_iMac at upstairs in ~
                                    $ perl -Mcharnames=:full -CS -wle 'print "\N{EURO SIGN}"'
                                    €]
                                    john

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

                                    1 條回覆 最後回覆 回覆 引用 0
                                    • thomthomT 離線
                                      thomthom
                                      最後由 編輯

                                      It's UTF-8.

                                      Test example:
                                      'ø'.unpack('C*')

                                      Returns:
                                      [195, 184]

                                      Which is the correct byte values in UTF-8 encoding.

                                      195 indicate the Latin1 page 184 points to ø on that page.

                                      Don't know what the data you got from them commands where. But just by looking at the test data byte per byte you can tell it's UTF-8.

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

                                      1 條回覆 最後回覆 回覆 引用 0
                                      • D 離線
                                        driven
                                        最後由 編輯

                                        yes that does return correctly,
                                        which is why I can't understand why some thing get lost in transition...
                                        same font Stix(NON-Unicde)
                                        Top happens from Ruby Console as well as WebDialogs
                                        Bellow is the Built in Tool
                                        john

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

                                        1 條回覆 最後回覆 回覆 引用 0
                                        • thomthomT 離線
                                          thomthom
                                          最後由 編輯

                                          hm... I've not have any problems with it.

                                          Do you see this in the 3d text plugin I sent you?

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

                                          1 條回覆 最後回覆 回覆 引用 0
                                          • D 離線
                                            driven
                                            最後由 編輯

                                            @thomthom said:

                                            Do you see this in the 3d text plugin I sent you?

                                            Top one... I was being discrete

                                            ` > a = "2撖죺".unpack('C*')
                                            b = a.pack('C*')
                                            c = puts a.inspect
                                            puts b.inspect

                                            [50, 230, 146, 150, 236, 163, 186]
                                            "2撖죺"
                                            nil`
                                            the puts should read [0, 50, 100, 150, 200, 250] "2撖죺"

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

                                            1 條回覆 最後回覆 回覆 引用 0
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 5
                                            • 6
                                            • 6 / 6
                                            • 第一個貼文
                                              最後的貼文
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement