support both hinted and unhinted fonts;
authorwenzelm
Sat Apr 06 22:05:25 2019 +0200 (5 months ago)
changeset 7007254dc58086351
parent 70071 9a03e9d5f336
child 70073 6b0e4ba2062c
support both hinted and unhinted fonts;
Admin/components/components.sha1
Admin/components/main
NEWS
src/Pure/Admin/build_fonts.scala
src/Tools/jEdit/etc/options
     1.1 --- a/Admin/components/components.sha1	Fri Apr 05 23:45:35 2019 +0200
     1.2 +++ b/Admin/components/components.sha1	Sat Apr 06 22:05:25 2019 +0200
     1.3 @@ -81,6 +81,7 @@
     1.4  f249bc2c85bd2af9eee509de17187a766b74ab86  isabelle_fonts-20181129.tar.gz
     1.5  928b5320073d04d93bcc5bc4347b6d01632b9d45  isabelle_fonts-20190210.tar.gz
     1.6  dfcdf9a757b9dc36cee87f82533b43c58ba84abe  isabelle_fonts-20190309.tar.gz
     1.7 +95e3acf038df7fdeeacd8b4769930e6f57bf3692  isabelle_fonts-20190406.tar.gz
     1.8  0b2206f914336dec4923dd0479d8cee4b904f544  jdk-11+28.tar.gz
     1.9  3e05213cad47dbef52804fe329395db9b4e57f39  jdk-11.0.2+9.tar.gz
    1.10  71d19df63816e9be1c4c5eb44aea7a44cfadb319  jdk-11.tar.gz
     2.1 --- a/Admin/components/main	Fri Apr 05 23:45:35 2019 +0200
     2.2 +++ b/Admin/components/main	Sat Apr 06 22:05:25 2019 +0200
     2.3 @@ -4,7 +4,7 @@
     2.4  csdp-6.x
     2.5  cvc4-1.5-4
     2.6  e-2.0-2
     2.7 -isabelle_fonts-20190309
     2.8 +isabelle_fonts-20190406
     2.9  jdk-11.0.2+9
    2.10  jedit_build-20190224
    2.11  jfreechart-1.5.0
     3.1 --- a/NEWS	Fri Apr 05 23:45:35 2019 +0200
     3.2 +++ b/NEWS	Sat Apr 06 22:05:25 2019 +0200
     3.3 @@ -90,10 +90,16 @@
     3.4  storage directory for "isabelle build". Option "-n" is now clearly
     3.5  separated from option "-s".
     3.6  
     3.7 +* Isabelle DejaVu fonts are available with hinting by default, which is
     3.8 +relevant for low-resolution displays. This may be disabled via system
     3.9 +option "isabelle_fonts_hinted = false" in
    3.10 +$ISABELLE_HOME_USER/etc/settings -- it occasionally yields better
    3.11 +results.
    3.12 +
    3.13  * OpenJDK 11 has quite different font rendering, with better glyph
    3.14  shapes and improved sub-pixel anti-aliasing. In some situations results
    3.15 -might be *worse* than Oracle Java 8, though. A decent HiDPI display is
    3.16 -recommended.
    3.17 +might be *worse* than Oracle Java 8, though -- a proper HiDPI / UHD
    3.18 +display is recommended.
    3.19  
    3.20  
    3.21  *** Document preparation ***
     4.1 --- a/src/Pure/Admin/build_fonts.scala	Fri Apr 05 23:45:35 2019 +0200
     4.2 +++ b/src/Pure/Admin/build_fonts.scala	Sat Apr 06 22:05:25 2019 +0200
     4.3 @@ -174,15 +174,19 @@
     4.4    }
     4.5  
     4.6  
     4.7 -  /* auto-hinting */
     4.8 +  /* hinting */
     4.9 +
    4.10    // see https://www.freetype.org/ttfautohint/doc/ttfautohint.html
    4.11 -
    4.12 -  def auto_hint(source: Path, target: Path)
    4.13 +  private def auto_hint(source: Path, target: Path)
    4.14    {
    4.15      Isabelle_System.bash("ttfautohint -i " +
    4.16        File.bash_path(source) + " " + File.bash_path(target)).check
    4.17    }
    4.18  
    4.19 +  private def hinted_path(hinted: Boolean): Path =
    4.20 +    if (hinted) Path.basic("ttf-hinted") else Path.basic("ttf")
    4.21 +
    4.22 +  private val hinting = List(false, true)
    4.23  
    4.24  
    4.25    /* build fonts */
    4.26 @@ -210,11 +214,10 @@
    4.27      target_prefix: String = "Isabelle",
    4.28      target_version: String = "",
    4.29      target_dir: Path = default_target_dir,
    4.30 -    unhinted: Boolean = false,
    4.31      progress: Progress = No_Progress)
    4.32    {
    4.33      progress.echo("Directory " + target_dir)
    4.34 -    Isabelle_System.mkdirs(target_dir)
    4.35 +    hinting.foreach(hinted => Isabelle_System.mkdirs(target_dir + hinted_path(hinted)))
    4.36  
    4.37      val font_dirs = source_dirs ::: List(Path.explode("~~/Admin/isabelle_fonts"))
    4.38      for (dir <- font_dirs if !dir.is_dir) error("Bad source directory: " + dir)
    4.39 @@ -231,35 +234,38 @@
    4.40          val source_names = Fontforge.font_names(source_file)
    4.41  
    4.42          val target_names = source_names.update(prefix = target_prefix, version = target_version)
    4.43 -        val target_file = target_dir + target_names.ttf
    4.44  
    4.45 -        progress.echo("Font " + target_file.toString + " ...")
    4.46          Isabelle_System.with_tmp_file("font", "ttf")(tmp_file =>
    4.47          {
    4.48 -          if (unhinted) File.copy(source_file, tmp_file)
    4.49 -          else auto_hint(source_file, tmp_file)
    4.50 +          for (hinted <- hinting) {
    4.51 +            val target_file = target_dir + hinted_path(hinted) + target_names.ttf
    4.52 +            progress.echo("Font " + target_file.toString + " ...")
    4.53  
    4.54 -          Fontforge.execute(
    4.55 -            Fontforge.commands(
    4.56 -              Fontforge.open(isabelle_file),
    4.57 -              Fontforge.select(Range.isabelle_font),
    4.58 -              Fontforge.copy,
    4.59 -              Fontforge.close,
    4.60 +            if (hinted) auto_hint(source_file, tmp_file)
    4.61 +            else File.copy(source_file, tmp_file)
    4.62  
    4.63 -              Fontforge.open(tmp_file),
    4.64 -              Fontforge.select(Range.base_font),
    4.65 -              Fontforge.select_invert,
    4.66 -              Fontforge.clear,
    4.67 -              Fontforge.select(Range.isabelle_font),
    4.68 -              Fontforge.paste,
    4.69 +            Fontforge.execute(
    4.70 +              Fontforge.commands(
    4.71 +                Fontforge.open(isabelle_file),
    4.72 +                Fontforge.select(Range.isabelle_font),
    4.73 +                Fontforge.copy,
    4.74 +                Fontforge.close,
    4.75  
    4.76 -              target_names.set,
    4.77 -              Fontforge.generate(target_file),
    4.78 -              Fontforge.close)
    4.79 -          ).check
    4.80 +                Fontforge.open(tmp_file),
    4.81 +                Fontforge.select(Range.base_font),
    4.82 +                Fontforge.select_invert,
    4.83 +                Fontforge.clear,
    4.84 +                Fontforge.select(Range.isabelle_font),
    4.85 +                Fontforge.paste,
    4.86 +
    4.87 +                target_names.set,
    4.88 +                Fontforge.generate(target_file),
    4.89 +                Fontforge.close)
    4.90 +            ).check
    4.91 +          }
    4.92          })
    4.93  
    4.94 -        (target_file, index)
    4.95 +        (target_names.ttf, index)
    4.96        }
    4.97  
    4.98  
    4.99 @@ -269,13 +275,14 @@
   4.100        val vacuous_file = find_file(font_dirs, Family.vacuous.get(0))
   4.101  
   4.102        val target_names = Fontforge.font_names(vacuous_file)
   4.103 -      val target_file = target_dir + target_names.ttf
   4.104 +      val target_file = target_dir + hinted_path(false) + target_names.ttf
   4.105  
   4.106        progress.echo("Font " + target_file.toString + " ...")
   4.107  
   4.108        val domain =
   4.109 -        (for ((target_file, index) <- targets if index == 0)
   4.110 -          yield Fontforge.font_domain(target_file)).flatten.toSet.toList.sorted
   4.111 +        (for ((name, index) <- targets if index == 0)
   4.112 +          yield Fontforge.font_domain(target_dir + hinted_path(false) + name))
   4.113 +        .flatten.toSet.toList.sorted
   4.114  
   4.115        Fontforge.execute(
   4.116          Fontforge.commands(
   4.117 @@ -300,13 +307,22 @@
   4.118  
   4.119      val settings_path = Components.settings(target_dir)
   4.120      Isabelle_System.mkdirs(settings_path.dir)
   4.121 +
   4.122 +    def fonts_settings(hinted: Boolean): String =
   4.123 +      "\n  isabelle_fonts \\\n" +
   4.124 +      (for ((target, _) <- targets) yield
   4.125 +        """    "$COMPONENT/""" + hinted_path(hinted).file_name + "/" + target.file_name + "\"")
   4.126 +      .mkString(" \\\n")
   4.127 +
   4.128      File.write(settings_path,
   4.129 -      "# -*- shell-script -*- :mode=shellscript:\n\nisabelle_fonts \\\n" +
   4.130 -      (for ((path, _) <- targets)
   4.131 -        yield """  "$COMPONENT/""" + path.file_name + "\"").mkString(" \\\n") +
   4.132 -      """
   4.133 +      """# -*- shell-script -*- :mode=shellscript:
   4.134  
   4.135 -isabelle_fonts_hidden "$COMPONENT/Vacuous.ttf"
   4.136 +if grep "isabelle_fonts_hinted.*=.*true" "$ISABELLE_HOME_USER/etc/preferences" >/dev/null 2>/dev/null
   4.137 +then""" + fonts_settings(true) + """
   4.138 +else""" + fonts_settings(false) + """
   4.139 +fi
   4.140 +
   4.141 +isabelle_fonts_hidden "$COMPONENT/""" + hinted_path(false).file_name + """/Vacuous.ttf"
   4.142  """)
   4.143  
   4.144  
   4.145 @@ -321,19 +337,16 @@
   4.146      Isabelle_Tool("build_fonts", "construct Isabelle fonts", args =>
   4.147      {
   4.148        var source_dirs: List[Path] = Nil
   4.149 -      var unhinted = false
   4.150  
   4.151        val getopts = Getopts("""
   4.152  Usage: isabelle build_fonts [OPTIONS]
   4.153  
   4.154    Options are:
   4.155      -d DIR       additional source directory
   4.156 -    -u           unhinted font (bypass ttfautohint)
   4.157  
   4.158    Construct Isabelle fonts from DejaVu font families and Isabelle symbols.
   4.159  """,
   4.160 -        "d:" -> (arg => source_dirs = source_dirs ::: List(Path.explode(arg))),
   4.161 -        "u" -> (_ => unhinted = true))
   4.162 +        "d:" -> (arg => source_dirs = source_dirs ::: List(Path.explode(arg))))
   4.163  
   4.164        val more_args = getopts(args)
   4.165        if (more_args.nonEmpty) getopts.usage()
   4.166 @@ -344,6 +357,6 @@
   4.167        val progress = new Console_Progress
   4.168  
   4.169        build_fonts(source_dirs = source_dirs, target_dir = target_dir,
   4.170 -        target_version = target_version, unhinted = unhinted, progress = progress)
   4.171 +        target_version = target_version, progress = progress)
   4.172      })
   4.173  }
     5.1 --- a/src/Tools/jEdit/etc/options	Fri Apr 05 23:45:35 2019 +0200
     5.2 +++ b/src/Tools/jEdit/etc/options	Sat Apr 06 22:05:25 2019 +0200
     5.3 @@ -39,6 +39,9 @@
     5.4  public option jedit_text_overview : bool = true
     5.5    -- "paint text overview column"
     5.6  
     5.7 +public option isabelle_fonts_hinted : bool = true
     5.8 +  -- "use hinted Isabelle DejaVu fonts (change requires restart)"
     5.9 +
    5.10  
    5.11  section "Indentation"
    5.12