 #   $show  }                = SP.export()
 #...........................................................................................................
 OT                        = require 'opentype.js'
-
-
+path_precision            = 5
+SvgPath                   = require 'svgpath'
+SVGTTF                    = require '../main'
+
+
+#===========================================================================================================
+#
 #-----------------------------------------------------------------------------------------------------------
 @load_font = ( path ) -> OT.loadSync path
 

      warn "^xxx#3773^ no such glyph: 0x#{idx.toString 16}"
      continue
    debug "#{glyph.index} #{glyph.name ? './.'} 0x#{(glyph.unicode ? 0).toString 16} #{glyph.unicodes}"
  help ( @list_glyphs_in_font font ).join ''

#-----------------------------------------------------------------------------------------------------------
@list_glyphs_in_font = ( font_or_path ) ->
  if isa.text font_or_path
    return @list_glyphs_in_font @load_font font_or_path
  #.........................................................................................................
  font  = font_or_path
  R     = new Set()
  #.........................................................................................................
  for idx, glyph of font.glyphs.glyphs
    if glyph.name in [ '.notdef', ] or ( not glyph.unicode? ) or ( glyph.unicode < 0x20 )
      warn "skipping glyph #{rpr glyph.name}"
      continue
    unicodes  = glyph.unicodes
    unicodes  = [ glyph.unicode, ] if ( not unicodes? ) or ( unicodes.length is 0 )
    # debug rpr glyph
    # debug rpr unicodes
    for cid in unicodes
      # debug rpr cid
      R.add String.fromCodePoint cid
  #.........................................................................................................
  return [ R... ].sort()

#-----------------------------------------------------------------------------------------------------------
@demo_glyph_copying = ->
  fonts_home  = project_abspath '.', 'materials'
  filepath    = PATH.resolve PATH.join fonts_home, 'Sun-ExtA-excerpts.ttf'
  font        = @load_font filepath
  echo """<?xml version="1.0" encoding="utf-8"?><svg>"""
  for cid in [ 0x5e00 .. 0x5e01 ]
    chr   = String.fromCodePoint cid
    glyph = font.charToGlyph chr
    # debug ( k for k of glyph )
    # info glyph.getContours()
    path = glyph.getPath()
    # info path.toPathData 3 # precision
    echo '<!-- ^xxx#3422', "0x#{cid.toString 16} #{chr} -->"
    echo "<g>#{path.toSVG 3}</g>"
  echo """</svg>"""
  # debug font.toTables()
  path = '/tmp/myfont.ttf'
  whisper "^xxx#4763^ saving font to #{path}"
  # @save_font path, font
  help "^xxx#4763^ ok"

#-----------------------------------------------------------------------------------------------------------
@demo2 = ->

  font.download()

############################################################################################################
if require.main is module then do =>
  # await @demo()
  await @demo_glyph_copying()

