src/Pure/Admin/build_fonts.scala
author wenzelm
Thu, 29 Nov 2018 14:43:11 +0100
changeset 69372 69de0f561824
parent 69371 3539767d5c61
child 69373 2c0af1c2e723
permissions -rw-r--r--
clarified target_dir;
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
      )
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   110
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   111
      val vacuous_font: Seq[Int] =
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   112
        Seq(0x3c)  // "<" as template
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   113
  }
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   114
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   115
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   116
  /* font families */
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   117
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   118
  sealed case class Family(
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   119
    plain: String = "",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   120
    bold: String = "",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   121
    italic: String = "",
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   122
    bold_italic: String = "")
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   123
  {
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   124
    val fonts: List[String] =
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   125
      proper_string(plain).toList :::
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   126
      proper_string(bold).toList :::
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   127
      proper_string(italic).toList :::
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   128
      proper_string(bold_italic).toList
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   129
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   130
    def get(index: Int): String = fonts(index % fonts.length)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   131
  }
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   132
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   133
  object Family
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   134
  {
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   135
    def isabelle_text: Family =
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   136
      Family(
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   137
        plain = "IsabelleText.sfd",
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   138
        bold = "IsabelleTextBold.sfd")
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   139
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   140
    def deja_vu_sans_mono: Family =
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   141
      Family(
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   142
        plain = "DejaVuSansMono.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   143
        bold = "DejaVuSansMono-Bold.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   144
        italic = "DejaVuSansMono-Oblique.ttf",
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   145
        bold_italic = "DejaVuSansMono-BoldOblique.ttf")
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   146
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   147
    def deja_vu_sans: Family =
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   148
      Family(
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   149
        plain = "DejaVuSans.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   150
        bold = "DejaVuSans-Bold.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   151
        italic = "DejaVuSans-Oblique.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   152
        bold_italic = "DejaVuSans-BoldOblique.ttf")
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   153
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   154
    def deja_vu_serif: Family =
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   155
      Family(
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   156
        plain = "DejaVuSerif.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   157
        bold = "DejaVuSerif-Bold.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   158
        italic = "DejaVuSerif-Italic.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   159
        bold_italic = "DejaVuSerif-BoldItalic.ttf")
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   160
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   161
    def vacuous: Family = Family(plain = "Vacuous.sfd")
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   162
  }
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   163
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   164
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   165
  /* build fonts */
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   166
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   167
  private def find_file(dirs: List[Path], name: String): Path =
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   168
  {
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   169
    val path = Path.explode(name)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   170
    dirs.collectFirst({ case dir if (dir + path).is_file => dir + path }) match {
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   171
      case Some(file) => file
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   172
      case None =>
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   173
        error(cat_lines(
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   174
          ("Failed to find font file " + path + " in directories:") ::
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   175
            dirs.map(dir => "  " + dir.toString)))
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   176
    }
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   177
  }
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   178
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   179
  val default_sources: List[Family] =
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   180
    List(Family.deja_vu_sans_mono, Family.deja_vu_sans, Family.deja_vu_serif)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   181
69372
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   182
  val default_target_dir: Path = Path.explode("isabelle_fonts")
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   183
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   184
  def build_fonts(
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   185
    sources: List[Family] = default_sources,
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   186
    source_dirs: List[Path] = Nil,
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   187
    target_prefix: String = "Isabelle",
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   188
    target_version: String = "",
69372
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   189
    target_dir: Path = default_target_dir,
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   190
    progress: Progress = No_Progress)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   191
  {
69372
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   192
    progress.echo("Directory " + target_dir)
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   193
    Isabelle_System.mkdirs(target_dir)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   194
69354
600727ff6889 clarified Admin resources;
wenzelm
parents: 69343
diff changeset
   195
    val font_dirs = source_dirs ::: List(Path.explode("~~/Admin/isabelle_fonts"))
600727ff6889 clarified Admin resources;
wenzelm
parents: 69343
diff changeset
   196
    for (dir <- font_dirs if !dir.is_dir) error("Bad source directory: " + dir)
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   197
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   198
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   199
    // Isabelle fonts
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   200
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   201
    val targets =
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   202
      for { source <- sources; (source_font, index) <- source.fonts.zipWithIndex }
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   203
      yield {
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   204
        val isabelle_file = find_file(font_dirs, Family.isabelle_text.get(index))
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   205
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   206
        val source_file = find_file(font_dirs, source_font)
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   207
        val source_names = Fontforge.font_names(source_file)
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   208
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   209
        val target_names = source_names.update(prefix = target_prefix, version = target_version)
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   210
        val target_file = target_dir + target_names.ttf
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   211
69372
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   212
        progress.echo("Font " + target_file.toString + " ...")
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   213
        Fontforge.execute(
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   214
          Fontforge.commands(
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   215
            Fontforge.open(isabelle_file),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   216
            Fontforge.select(Range.isabelle_font),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   217
            Fontforge.copy,
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   218
            Fontforge.close,
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   219
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   220
            Fontforge.open(source_file),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   221
            Fontforge.select(Range.base_font),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   222
            Fontforge.select_invert,
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   223
            Fontforge.clear,
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   224
            Fontforge.select(Range.isabelle_font),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   225
            Fontforge.paste,
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   226
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   227
            target_names.set,
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   228
            Fontforge.generate(target_file),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   229
            Fontforge.close)
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   230
        ).check
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   231
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   232
        (target_file, index)
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   233
      }
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   234
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   235
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   236
    // Vacuous font
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   237
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   238
    {
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   239
      val vacuous_file = find_file(font_dirs, Family.vacuous.get(0))
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   240
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   241
      val target_names = Fontforge.font_names(vacuous_file)
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   242
      val target_file = target_dir + target_names.ttf
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   243
69372
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   244
      progress.echo("Font " + target_file.toString + " ...")
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   245
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   246
      val domain =
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   247
        (for ((target_file, index) <- targets if index == 0)
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   248
          yield Fontforge.font_domain(target_file)).flatten.toSet.toList.sorted
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   249
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   250
      Fontforge.execute(
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   251
        Fontforge.commands(
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   252
          Fontforge.open(vacuous_file),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   253
          Fontforge.select(Range.vacuous_font),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   254
          Fontforge.copy) +
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   255
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   256
        domain.map(code =>
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   257
            Fontforge.commands(
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   258
              Fontforge.select(Seq(code)),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   259
              Fontforge.paste))
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   260
          .mkString("\n", "\n", "\n") +
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   261
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   262
        Fontforge.commands(
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   263
          Fontforge.generate(target_file),
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   264
          Fontforge.close)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   265
      ).check
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   266
    }
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   267
  }
69337
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   268
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   269
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   270
  /* Isabelle tool wrapper */
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   271
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   272
  val isabelle_tool =
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   273
    Isabelle_Tool("build_fonts", "construct Isabelle fonts", args =>
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   274
    {
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   275
      var source_dirs: List[Path] = Nil
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   276
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   277
      val getopts = Getopts("""
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   278
Usage: isabelle build_fonts [OPTIONS]
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   279
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   280
  Options are:
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   281
    -d DIR       additional source directory
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   282
69343
395c4fb15ea2 use "Isabelle DejaVu" fonts uniformly: Text Area, GUI elements, HTML output etc.;
wenzelm
parents: 69341
diff changeset
   283
  Construct Isabelle fonts from DejaVu font families and Isabelle symbols.
69337
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   284
""",
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   285
        "d:" -> (arg => source_dirs = source_dirs ::: List(Path.explode(arg))))
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   286
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   287
      val more_args = getopts(args)
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   288
      if (more_args.nonEmpty) getopts.usage()
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   289
69372
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   290
      val target_version = Date.Format("uuuuMMdd")(Date.now())
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   291
      val target_dir = Path.explode("isabelle_fonts-" + target_version)
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   292
69337
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   293
      val progress = new Console_Progress
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   294
69372
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   295
      build_fonts(source_dirs = source_dirs, target_dir = target_dir,
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   296
        target_version = target_version, progress = progress)
69337
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   297
    })
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   298
}