src/Pure/Admin/build_fonts.scala
author wenzelm
Wed, 28 Nov 2018 11:06:58 +0100
changeset 69354 600727ff6889
parent 69343 395c4fb15ea2
child 69371 3539767d5c61
permissions -rw-r--r--
clarified Admin resources; tuned comments;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
69339
6baa37cbf70b clarified module name (again);
wenzelm
parents: 69338
diff changeset
     1
/*  Title:      Pure/Admin/build_fonts.scala
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
     3
69354
600727ff6889 clarified Admin resources;
wenzelm
parents: 69343
diff changeset
     4
Build standard Isabelle fonts: DejaVu base + Isabelle symbols.
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
     5
*/
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
     6
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
     7
package isabelle
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
     8
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
     9
69339
6baa37cbf70b clarified module name (again);
wenzelm
parents: 69338
diff changeset
    10
object Build_Fonts
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    11
{
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    12
  /* relevant codepoint ranges */
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    13
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    14
  object Range
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    15
  {
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
    16
    def base_font: Seq[Int] =
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    17
      (0x0020 to 0x007e) ++  // ASCII
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    18
      (0x00a0 to 0x024f) ++  // Latin Extended-A/B
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    19
      (0x0400 to 0x04ff) ++  // Cyrillic
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    20
      (0x0600 to 0x06ff) ++  // Arabic
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    21
      Seq(
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    22
        0x2018,  // single quote
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    23
        0x2019,  // single quote
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    24
        0x201a,  // single quote
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    25
        0x201c,  // double quote
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    26
        0x201d,  // double quote
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    27
        0x201e,  // double quote
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    28
        0x2039,  // single guillemet
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    29
        0x203a,  // single guillemet
69331
85cafb6e4db0 tuned comments -- based on history;
wenzelm
parents: 69330
diff changeset
    30
        0x204b,  // FOOTNOTE
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    31
        0x20ac,  // Euro
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    32
        0xfb01,  // ligature fi
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    33
        0xfb02,  // ligature fl
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    34
        0xfffd,  // replacement character
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    35
      )
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    36
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
    37
    def isabelle_font: Seq[Int] =
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    38
      Seq(
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    39
        0x05,  // X
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    40
        0x06,  // Y
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    41
        0x07,  // EOF
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    42
        0x7f,  // DEL
69341
6aa24ccd8049 proper superscript "-1", based on "Deja Vu Sans Condensed" U+207b/U+00b9, with bold version via "Change Weight / Embolden by 80 em units";
wenzelm
parents: 69339
diff changeset
    43
        0xaf,  // INVERSE
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    44
        0xac,  // logicalnot
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    45
        0xb0,  // degree
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    46
        0xb1,  // plusminus
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    47
        0xb7,  // periodcentered
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    48
        0xd7,  // multiply
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    49
        0xf7,  // divide
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    50
      ) ++
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    51
      (0x0370 to 0x03ff) ++  // Greek (pseudo math)
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
    52
      (0x0590 to 0x05ff) ++  // Hebrew (non-mono)
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    53
      Seq(
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    54
        0x2010,  // hyphen
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    55
        0x2013,  // dash
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    56
        0x2014,  // dash
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    57
        0x2015,  // dash
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    58
        0x2020,  // dagger
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    59
        0x2021,  // double dagger
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    60
        0x2022,  // bullet
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    61
        0x2026,  // ellipsis
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    62
        0x2030,  // perthousand
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    63
        0x2032,  // minute
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    64
        0x2033,  // second
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    65
        0x2038,  // caret
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    66
        0x20cd,  // currency symbol
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    67
      ) ++
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    68
      (0x2100 to 0x214f) ++  // Letterlike Symbols
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    69
      (0x2190 to 0x21ff) ++  // Arrows
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    70
      (0x2200 to 0x22ff) ++  // Mathematical Operators
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    71
      (0x2300 to 0x23ff) ++  // Miscellaneous Technical
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    72
      Seq(
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    73
        0x2423,  // graphic for space
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    74
        0x2500,  // box drawing
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    75
        0x2501,  // box drawing
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    76
        0x2508,  // box drawing
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    77
        0x2509,  // box drawing
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    78
        0x2550,  // box drawing
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    79
      ) ++
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    80
      (0x25a0 to 0x25ff) ++  // Geometric Shapes
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    81
      Seq(
69331
85cafb6e4db0 tuned comments -- based on history;
wenzelm
parents: 69330
diff changeset
    82
        0x261b,  // ACTION
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    83
        0x2660,  // spade suit
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    84
        0x2661,  // heart suit
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    85
        0x2662,  // diamond suit
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    86
        0x2663,  // club suit
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    87
        0x266d,  // musical flat
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    88
        0x266e,  // musical natural
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    89
        0x266f,  // musical sharp
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    90
        0x2756,  // UNDEFINED
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    91
        0x2759,  // BOLD
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    92
        0x27a7,  // DESCR
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    93
        0x27e6,  // left white square bracket
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    94
        0x27e7,  // right white square bracket
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    95
        0x27e8,  // left angle bracket
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    96
        0x27e9,  // right angle bracket
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    97
      ) ++
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    98
      (0x27f0 to 0x27ff) ++  // Supplemental Arrows-A
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
    99
      (0x2900 to 0x297f) ++  // Supplemental Arrows-B
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   100
      (0x2980 to 0x29ff) ++  // Miscellaneous Mathematical Symbols-B
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   101
      (0x2a00 to 0x2aff) ++  // Supplemental Mathematical Operators
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   102
      Seq(0x2b1a) ++  // VERBATIM
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   103
      (0x1d400 to 0x1d7ff) ++  // Mathematical Alphanumeric Symbols
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   104
      Seq(
69331
85cafb6e4db0 tuned comments -- based on history;
wenzelm
parents: 69330
diff changeset
   105
        0x1f310,  // globe with meridians (Symbola font)
85cafb6e4db0 tuned comments -- based on history;
wenzelm
parents: 69330
diff changeset
   106
        0x1f4d3,  // notebook (Symbola font)
85cafb6e4db0 tuned comments -- based on history;
wenzelm
parents: 69330
diff changeset
   107
        0x1f5c0,  // folder (Symbola font)
85cafb6e4db0 tuned comments -- based on history;
wenzelm
parents: 69330
diff changeset
   108
        0x1f5cf,  // page (Symbola font)
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   109
      )
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   110
  }
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   111
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   112
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   113
  /* font families */
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   114
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   115
  sealed case class Family(
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   116
    plain: String = "",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   117
    bold: String = "",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   118
    italic: String = "",
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   119
    bold_italic: String = "")
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   120
  {
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   121
    val fonts: List[String] =
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   122
      proper_string(plain).toList :::
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   123
      proper_string(bold).toList :::
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   124
      proper_string(italic).toList :::
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   125
      proper_string(bold_italic).toList
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   126
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   127
    def get(index: Int): String = fonts(index % fonts.length)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   128
  }
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   129
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   130
  object Family
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   131
  {
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   132
    def isabelle_text: Family =
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   133
      Family(
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   134
        plain = "IsabelleText.sfd",
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   135
        bold = "IsabelleTextBold.sfd")
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   136
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   137
    def deja_vu_sans_mono: Family =
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   138
      Family(
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   139
        plain = "DejaVuSansMono.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   140
        bold = "DejaVuSansMono-Bold.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   141
        italic = "DejaVuSansMono-Oblique.ttf",
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   142
        bold_italic = "DejaVuSansMono-BoldOblique.ttf")
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   143
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   144
    def deja_vu_sans: Family =
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   145
      Family(
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   146
        plain = "DejaVuSans.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   147
        bold = "DejaVuSans-Bold.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   148
        italic = "DejaVuSans-Oblique.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   149
        bold_italic = "DejaVuSans-BoldOblique.ttf")
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   150
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   151
    def deja_vu_serif: Family =
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   152
      Family(
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   153
        plain = "DejaVuSerif.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   154
        bold = "DejaVuSerif-Bold.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   155
        italic = "DejaVuSerif-Italic.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   156
        bold_italic = "DejaVuSerif-BoldItalic.ttf")
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   157
  }
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   158
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   159
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   160
  /* build fonts */
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   161
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   162
  private def find_file(dirs: List[Path], name: String): Path =
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   163
  {
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   164
    val path = Path.explode(name)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   165
    dirs.collectFirst({ case dir if (dir + path).is_file => dir + path }) match {
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   166
      case Some(file) => file
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   167
      case None =>
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   168
        error(cat_lines(
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   169
          ("Failed to find font file " + path + " in directories:") ::
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   170
            dirs.map(dir => "  " + dir.toString)))
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   171
    }
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   172
  }
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   173
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   174
  val default_sources: List[Family] =
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   175
    List(Family.deja_vu_sans_mono, Family.deja_vu_sans, Family.deja_vu_serif)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   176
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   177
  def build_fonts(
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   178
    sources: List[Family] = default_sources,
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   179
    source_dirs: List[Path] = Nil,
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   180
    target_prefix: String = "Isabelle",
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   181
    target_version: String = "",
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   182
    target_dir: Path = Path.current,
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   183
    progress: Progress = No_Progress)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   184
  {
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   185
    Isabelle_System.mkdirs(target_dir)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   186
69354
600727ff6889 clarified Admin resources;
wenzelm
parents: 69343
diff changeset
   187
    val font_dirs = source_dirs ::: List(Path.explode("~~/Admin/isabelle_fonts"))
600727ff6889 clarified Admin resources;
wenzelm
parents: 69343
diff changeset
   188
    for (dir <- font_dirs if !dir.is_dir) error("Bad source directory: " + dir)
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   189
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   190
    for { source <- sources; (source_font, index) <- source.fonts.zipWithIndex } {
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   191
      val isabelle_file = find_file(font_dirs, Family.isabelle_text.get(index))
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   192
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   193
      val source_file = find_file(font_dirs, source_font)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   194
      val source_names = Fontforge.font_names(source_file)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   195
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   196
      val target_names = source_names.update(prefix = target_prefix, version = target_version)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   197
      val target_file = target_dir + target_names.ttf
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   198
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   199
      progress.echo("Creating " + target_file.toString + " ...")
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   200
      Fontforge.execute(
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   201
        Fontforge.commands(
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   202
          Fontforge.open(isabelle_file),
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   203
          Fontforge.select(Range.isabelle_font),
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   204
          Fontforge.copy,
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   205
          Fontforge.close,
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   206
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   207
          Fontforge.open(source_file),
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   208
          Fontforge.select(Range.base_font),
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   209
          Fontforge.select_invert,
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   210
          Fontforge.clear,
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   211
          Fontforge.select(Range.isabelle_font),
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   212
          Fontforge.paste,
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   213
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   214
          target_names.set,
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   215
          Fontforge.generate(target_file),
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   216
          Fontforge.close)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   217
      ).check
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   218
    }
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   219
  }
69337
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   220
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   221
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   222
  /* Isabelle tool wrapper */
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   223
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   224
  val isabelle_tool =
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   225
    Isabelle_Tool("build_fonts", "construct Isabelle fonts", args =>
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   226
    {
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   227
      var source_dirs: List[Path] = Nil
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   228
      var target_dir = Path.current
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   229
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   230
      val getopts = Getopts("""
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   231
Usage: isabelle build_fonts [OPTIONS]
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   232
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   233
  Options are:
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   234
    -D DIR       target directory (default ".")
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   235
    -d DIR       additional source directory
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   236
69343
395c4fb15ea2 use "Isabelle DejaVu" fonts uniformly: Text Area, GUI elements, HTML output etc.;
wenzelm
parents: 69341
diff changeset
   237
  Construct Isabelle fonts from DejaVu font families and Isabelle symbols.
69337
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   238
""",
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   239
        "D:" -> (arg => target_dir = Path.explode(arg)),
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   240
        "d:" -> (arg => source_dirs = source_dirs ::: List(Path.explode(arg))))
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   241
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   242
      val more_args = getopts(args)
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   243
      if (more_args.nonEmpty) getopts.usage()
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   244
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   245
      val progress = new Console_Progress
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   246
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   247
      build_fonts(source_dirs = source_dirs, target_dir = target_dir, progress = progress)
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   248
    })
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   249
}