src/Pure/Admin/build_fonts.scala
changeset 69372 69de0f561824
parent 69371 3539767d5c61
child 69373 2c0af1c2e723
equal deleted inserted replaced
69371:3539767d5c61 69372:69de0f561824
   177   }
   177   }
   178 
   178 
   179   val default_sources: List[Family] =
   179   val default_sources: List[Family] =
   180     List(Family.deja_vu_sans_mono, Family.deja_vu_sans, Family.deja_vu_serif)
   180     List(Family.deja_vu_sans_mono, Family.deja_vu_sans, Family.deja_vu_serif)
   181 
   181 
       
   182   val default_target_dir: Path = Path.explode("isabelle_fonts")
       
   183 
   182   def build_fonts(
   184   def build_fonts(
   183     sources: List[Family] = default_sources,
   185     sources: List[Family] = default_sources,
   184     source_dirs: List[Path] = Nil,
   186     source_dirs: List[Path] = Nil,
   185     target_prefix: String = "Isabelle",
   187     target_prefix: String = "Isabelle",
   186     target_version: String = "",
   188     target_version: String = "",
   187     target_dir: Path = Path.current,
   189     target_dir: Path = default_target_dir,
   188     progress: Progress = No_Progress)
   190     progress: Progress = No_Progress)
   189   {
   191   {
       
   192     progress.echo("Directory " + target_dir)
   190     Isabelle_System.mkdirs(target_dir)
   193     Isabelle_System.mkdirs(target_dir)
   191 
   194 
   192     val font_dirs = source_dirs ::: List(Path.explode("~~/Admin/isabelle_fonts"))
   195     val font_dirs = source_dirs ::: List(Path.explode("~~/Admin/isabelle_fonts"))
   193     for (dir <- font_dirs if !dir.is_dir) error("Bad source directory: " + dir)
   196     for (dir <- font_dirs if !dir.is_dir) error("Bad source directory: " + dir)
   194 
   197 
   204         val source_names = Fontforge.font_names(source_file)
   207         val source_names = Fontforge.font_names(source_file)
   205 
   208 
   206         val target_names = source_names.update(prefix = target_prefix, version = target_version)
   209         val target_names = source_names.update(prefix = target_prefix, version = target_version)
   207         val target_file = target_dir + target_names.ttf
   210         val target_file = target_dir + target_names.ttf
   208 
   211 
   209         progress.echo("Creating " + target_file.toString + " ...")
   212         progress.echo("Font " + target_file.toString + " ...")
   210         Fontforge.execute(
   213         Fontforge.execute(
   211           Fontforge.commands(
   214           Fontforge.commands(
   212             Fontforge.open(isabelle_file),
   215             Fontforge.open(isabelle_file),
   213             Fontforge.select(Range.isabelle_font),
   216             Fontforge.select(Range.isabelle_font),
   214             Fontforge.copy,
   217             Fontforge.copy,
   236       val vacuous_file = find_file(font_dirs, Family.vacuous.get(0))
   239       val vacuous_file = find_file(font_dirs, Family.vacuous.get(0))
   237 
   240 
   238       val target_names = Fontforge.font_names(vacuous_file)
   241       val target_names = Fontforge.font_names(vacuous_file)
   239       val target_file = target_dir + target_names.ttf
   242       val target_file = target_dir + target_names.ttf
   240 
   243 
   241       progress.echo("Creating " + target_file.toString + " ...")
   244       progress.echo("Font " + target_file.toString + " ...")
   242 
   245 
   243       val domain =
   246       val domain =
   244         (for ((target_file, index) <- targets if index == 0)
   247         (for ((target_file, index) <- targets if index == 0)
   245           yield Fontforge.font_domain(target_file)).flatten.toSet.toList.sorted
   248           yield Fontforge.font_domain(target_file)).flatten.toSet.toList.sorted
   246 
   249 
   268 
   271 
   269   val isabelle_tool =
   272   val isabelle_tool =
   270     Isabelle_Tool("build_fonts", "construct Isabelle fonts", args =>
   273     Isabelle_Tool("build_fonts", "construct Isabelle fonts", args =>
   271     {
   274     {
   272       var source_dirs: List[Path] = Nil
   275       var source_dirs: List[Path] = Nil
   273       var target_dir = Path.current
       
   274 
   276 
   275       val getopts = Getopts("""
   277       val getopts = Getopts("""
   276 Usage: isabelle build_fonts [OPTIONS]
   278 Usage: isabelle build_fonts [OPTIONS]
   277 
   279 
   278   Options are:
   280   Options are:
   279     -D DIR       target directory (default ".")
       
   280     -d DIR       additional source directory
   281     -d DIR       additional source directory
   281 
   282 
   282   Construct Isabelle fonts from DejaVu font families and Isabelle symbols.
   283   Construct Isabelle fonts from DejaVu font families and Isabelle symbols.
   283 """,
   284 """,
   284         "D:" -> (arg => target_dir = Path.explode(arg)),
       
   285         "d:" -> (arg => source_dirs = source_dirs ::: List(Path.explode(arg))))
   285         "d:" -> (arg => source_dirs = source_dirs ::: List(Path.explode(arg))))
   286 
   286 
   287       val more_args = getopts(args)
   287       val more_args = getopts(args)
   288       if (more_args.nonEmpty) getopts.usage()
   288       if (more_args.nonEmpty) getopts.usage()
   289 
   289 
       
   290       val target_version = Date.Format("uuuuMMdd")(Date.now())
       
   291       val target_dir = Path.explode("isabelle_fonts-" + target_version)
       
   292 
   290       val progress = new Console_Progress
   293       val progress = new Console_Progress
   291 
   294 
   292       build_fonts(source_dirs = source_dirs, target_dir = target_dir, progress = progress)
   295       build_fonts(source_dirs = source_dirs, target_dir = target_dir,
       
   296         target_version = target_version, progress = progress)
   293     })
   297     })
   294 }
   298 }