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.
    • D Offline
      driven
      last edited by

      @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 Reply Last reply Reply Quote 0
      • D Offline
        driven
        last edited by

        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 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          @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 Reply Last reply Reply Quote 0
          • D Offline
            driven
            last edited by

            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 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              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 Reply Last reply Reply Quote 0
              • D Offline
                driven
                last edited by

                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 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  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 Reply Last reply Reply Quote 0
                  • D Offline
                    driven
                    last edited by

                    @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 Reply Last reply Reply Quote 0
                    • TIGT Offline
                      TIG Moderator
                      last edited by

                      Why are you using "C*" in the unpack and pack - doesn't that extract a character as an unsigned integer.
                      Shouldn't it be "U*" - which extracts UTF-8 characters as unsigned integers ?

                      TIG

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

                        Because I actually want to see each byte. Not the Unicode ID.

                        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

                          @driven said:

                          the puts should read [0, 50, 100, 150, 200, 250] "2撖죺"

                          ?
                          Where are these numbers from?

                          Why are you expecting a NULL byte? (That's usually a string termination in C.)

                          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

                            I think this may be the root of my issues
                            if you unpack(C), then pack(U) sh*t happens

                            > a = "2撖죺".unpack('C*') b = a.pack('U*') c = puts a.inspect puts b.inspect [50, 230, 146, 150, 236, 163, 186] "2撖죺" nil
                            and visa-versa
                            > a = "2撖죺".unpack('U*') b = a.pack('C*') c = puts a.inspect puts b.inspect [50, 25750, 51450] "2\226\372" nil
                            I think the first is happening somewhere

                            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

                              font = Arial Unicode MS
                              SU Top again
                              WD bottom
                              look familiar

                              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

                                @thomthom said:

                                Where are these numbers from?

                                Link Preview Image
                                Pack and unpack bytes to strings

                                I need to write a function that "packs" an array of bytes (integers between 0 and 255) into a string. I also need to be able to perform the reverse operation, to get my byte array from the string t...

                                favicon

                                Code Review Stack Exchange (codereview.stackexchange.com)

                                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

                                  @driven said:

                                  @thomthom said:

                                  Where are these numbers from?

                                  Link Preview Image
                                  Pack and unpack bytes to strings

                                  I need to write a function that "packs" an array of bytes (integers between 0 and 255) into a string. I also need to be able to perform the reverse operation, to get my byte array from the string t...

                                  favicon

                                  Code Review Stack Exchange (codereview.stackexchange.com)

                                  That's from a questions that doesn't really make sense.

                                  Also:

                                  @unknownuser said:

                                  Seeing as JavaScript has 16-bit strings, I packed two bytes per character.

                                  Two byte per character isn't UTF-8.

                                  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

                                    I was looking for test code and only grabbed the example, I got there from the Stackoverflow 'fix' that referred back.

                                    Do these work as 3D Text on the PC...

                                    I ran the full gamete of unpack().pack() scenario's in console and a mismatch is the only way to get the same results as the straight input.
                                    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
                                    • Dan RathbunD Offline
                                      Dan Rathbun
                                      last edited by

                                      @thomthom said:

                                      fonts.sort! %(#008000)[# (!) Not UTF-8 compatible! But better than nothing.]

                                      (1) Since this will run only on Mac, which is Unicode aware, can't you pass the list to a command shell and use the shell's built-in sort filter ??

                                      For instance on WIN, in DOS command shell, you can filter output by piping it through the sort filter, thus:
                                      doc_list = %x(dir "~/documents/myproject" | sort)
                                      or similar.

                                      You'd need to build a plain text list from the array, each element being a line, separated by " \n"

                                      (2) Alternative ... build an array copy using pack, sort it, then & unpack back to strings.

                                      I think I'm late posting this... you guys are posting machines!

                                      I'm not here much anymore.

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

                                        If there is such a command then I'd guess that would work. But I'm not familiar with OSX terminal. Maybe John knows?

                                        I can also use JS to sort it - since I'm displaying the list in a WebDialog.

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

                                        1 Reply Last reply Reply Quote 0
                                        • Dan RathbunD Offline
                                          Dan Rathbun
                                          last edited by

                                          @thomthom said:

                                          But I'm not familiar with OSX terminal.

                                          Shell Scripting Primer: Command Line Primer

                                          tcsh(1) OS X Manual Page[*]

                                          Filename substitution

                                          If a word contains any of the characters *`', ?', `` [' or {`' or begins with the character ~`' it is a candidate for filename substitution, also known as globbing''. This word is then regarded as a pattern (glob-pattern''), and replaced with an alphabetically sorted list of file names which match the pattern.

                                          • Also do a Find on " ls-F", it is a built-in and supposed to be faster than " ls -F"

                                          OS X Manual Page: ls command Reference

                                          💭

                                          I'm not here much anymore.

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

                                            This is probably my last effort on this.... circles,
                                            but, I finally figured out find in Ruby Console, escapes, escapes, escapes...

                                            THE THIRD WAY... no Font Book... no fc-list... just plain old find >> mdls... not the fastest, but not too bad.
                                            inculed is Dan's tester, these all created 3D text from console, only Font Book and usr/local/bin/fc-list do that out of the can.

                                            a=(`find /System/Library/Fonts\ /Library/Fonts\ ~/Library/Fonts\ \\( -name "*.ttf" -o -name "*.otf" \\) -type f`).split("\n").map! { |f| f.gsub(" ", "\\ ")} #need this or something to catch spaces in filenames
                                            b=(a.collect{|x| `mdls  -name com_apple_ats_name_family -raw #{x}`}).map! { |f| f.split(",")[0]} #the other items in each array are unicode strings for other languages, if you want those use Font Book
                                            c=b.map { |f| f[/[("\s]+([^"\n]+)[)"\s]+/m,1] }.uniq!.sort![2..-1] #[0] is empty, [1] is a dot file, could remove them
                                            macFonts = c
                                            chunksize = 1
                                            chunk = 1
                                            limit = macFonts.length
                                            model = Sketchup.active_model
                                             
                                            fsize = 1.0
                                            linespacing = 1.2
                                             
                                            bold = false
                                            italic = false
                                            thick = 0.05
                                            filled = true
                                            quality = 0.0
                                             
                                            i = 0
                                             
                                            while i < limit
                                             
                                              begin
                                                #
                                                model.start_operation("3D Fontnames (#{chunk})")
                                                  #
                                                  chunksize.times do |n|
                                                    #
                                                    break if i == limit
                                                    #
                                                    item = macFonts[i]
                                                    grp = model.entities.add_group()
                                                    grp.entities.add_3d_text( "#{item}", TextAlignCenter, "#{item}",
                                                      bold, italic, fsize, quality, 0.0, filled, thick )
                                                    grp.name= item
                                                    grp.move!( Geom;;Transformation.new(Geom;;Vector3d.new(0,-(i*linespacing),0)) )
                                                    #
                                                    i += 1
                                                    #
                                                  end # chunk
                                                  #
                                                model.commit_operation()
                                                #
                                              rescue Exception => e
                                                puts("\n*** macFonts group Error! ***")
                                                puts("  i = #{i}")
                                                puts("  chunk = #{chunk}")
                                                puts("  font = #{macFonts[i]}\n")
                                                model.abort_operation()
                                                puts("Error #<#{e.class.name}; #{e.message}>")
                                                puts(e.backtrace) if $VERBOSE
                                                raise
                                              end
                                             
                                              chunk += 1
                                             
                                            end # while  
                                            

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

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

                                            Advertisement