support for fontforge and its scripting language;
authorwenzelm
Thu Nov 22 17:34:37 2018 +0100 (19 months ago)
changeset 693284646fcb59121
parent 69327 264b44dce6be
child 69329 8bbde4dba926
support for fontforge and its scripting language;
etc/settings
src/Pure/Tools/fontforge.scala
src/Pure/build-jars
     1.1 --- a/etc/settings	Thu Nov 22 17:34:30 2018 +0100
     1.2 +++ b/etc/settings	Thu Nov 22 17:34:37 2018 +0100
     1.3 @@ -162,6 +162,7 @@
     1.4  ###
     1.5  
     1.6  ISABELLE_GNUPLOT="gnuplot"
     1.7 +ISABELLE_FONTFORGE="fontforge"
     1.8  
     1.9  #ISABELLE_MLTON="/usr/bin/mlton"
    1.10  #ISABELLE_SMLNJ="/usr/bin/sml"
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/Pure/Tools/fontforge.scala	Thu Nov 22 17:34:37 2018 +0100
     2.3 @@ -0,0 +1,54 @@
     2.4 +/*  Title:      Pure/Tools/fontforge.scala
     2.5 +    Author:     Makarius
     2.6 +
     2.7 +Support for fontforge and its scripting language:
     2.8 +https://github.com/fontforge/fontforge/blob/master/fontforge/scripting.c
     2.9 +*/
    2.10 +
    2.11 +package isabelle
    2.12 +
    2.13 +
    2.14 +import java.io.{File => JFile}
    2.15 +import java.util.Locale
    2.16 +
    2.17 +
    2.18 +object Fontforge
    2.19 +{
    2.20 +  /** scripting language **/
    2.21 +
    2.22 +  type Script = String
    2.23 +
    2.24 +
    2.25 +  /* concrete syntax */
    2.26 +
    2.27 +  def string(s: String): Script =
    2.28 +  {
    2.29 +    val quote = if (s.contains('"')) '\'' else '"'
    2.30 +
    2.31 +    def err(c: Char): Nothing =
    2.32 +      error("Bad character in fontforge string: \\u" +
    2.33 +        String.format(Locale.ROOT, "%04x", new Integer(c)))
    2.34 +
    2.35 +    def escape(c: Char): String =
    2.36 +    {
    2.37 +      if (c == '\u0000' || c == '\r' || c == quote) err(c)
    2.38 +      else if (c == '\n') "\\n"
    2.39 +      else if (c == '\\') "\\\\"
    2.40 +      else c.toString
    2.41 +    }
    2.42 +
    2.43 +    if (s.nonEmpty && s(0) == '\\') err('\\')
    2.44 +    s.iterator.map(escape(_)).mkString(quote.toString, "", quote.toString)
    2.45 +  }
    2.46 +
    2.47 +
    2.48 +  /* execute process */
    2.49 +
    2.50 +  def execute(script: Script, args: String = "", cwd: JFile = null): Process_Result =
    2.51 +    Isabelle_System.with_tmp_file("fontforge")(script_file =>
    2.52 +    {
    2.53 +      File.write(script_file, script)
    2.54 +      Isabelle_System.bash(File.bash_path(Path.explode("$ISABELLE_FONTFORGE")) +
    2.55 +        " -lang=ff -script " + File.bash_path(script_file) + " " + args)
    2.56 +    })
    2.57 +}
     3.1 --- a/src/Pure/build-jars	Thu Nov 22 17:34:30 2018 +0100
     3.2 +++ b/src/Pure/build-jars	Thu Nov 22 17:34:37 2018 +0100
     3.3 @@ -145,6 +145,7 @@
     3.4    Tools/debugger.scala
     3.5    Tools/doc.scala
     3.6    Tools/dump.scala
     3.7 +  Tools/fontforge.scala
     3.8    Tools/imports.scala
     3.9    Tools/main.scala
    3.10    Tools/mkroot.scala