src/Pure/Admin/build_fonts.scala
author wenzelm
Sun, 09 Dec 2018 18:11:56 +0100
changeset 69437 1b64f82aaf76
parent 69436 1b406949981f
child 69795 4791988fcbc4
permissions -rw-r--r--
more mathematical glyphs from Isabelle2009-1/lib/fonts/IsabelleMono.sfd (still unused);
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
69437
1b64f82aaf76 more mathematical glyphs from Isabelle2009-1/lib/fonts/IsabelleMono.sfd (still unused);
wenzelm
parents: 69436
diff changeset
   111
    def isabelle_math_font: Seq[Int] =
1b64f82aaf76 more mathematical glyphs from Isabelle2009-1/lib/fonts/IsabelleMono.sfd (still unused);
wenzelm
parents: 69436
diff changeset
   112
      (0x21 to 0x2f) ++  // bang .. slash
1b64f82aaf76 more mathematical glyphs from Isabelle2009-1/lib/fonts/IsabelleMono.sfd (still unused);
wenzelm
parents: 69436
diff changeset
   113
      (0x3a to 0x40) ++  // colon .. atsign
1b64f82aaf76 more mathematical glyphs from Isabelle2009-1/lib/fonts/IsabelleMono.sfd (still unused);
wenzelm
parents: 69436
diff changeset
   114
      (0x5b to 0x5f) ++  // leftbracket .. underscore
1b64f82aaf76 more mathematical glyphs from Isabelle2009-1/lib/fonts/IsabelleMono.sfd (still unused);
wenzelm
parents: 69436
diff changeset
   115
      (0x7b to 0x7e) ++  // leftbrace .. tilde
1b64f82aaf76 more mathematical glyphs from Isabelle2009-1/lib/fonts/IsabelleMono.sfd (still unused);
wenzelm
parents: 69436
diff changeset
   116
      Seq(
1b64f82aaf76 more mathematical glyphs from Isabelle2009-1/lib/fonts/IsabelleMono.sfd (still unused);
wenzelm
parents: 69436
diff changeset
   117
        0xa9,  // copyright
1b64f82aaf76 more mathematical glyphs from Isabelle2009-1/lib/fonts/IsabelleMono.sfd (still unused);
wenzelm
parents: 69436
diff changeset
   118
        0xae,  // registered
1b64f82aaf76 more mathematical glyphs from Isabelle2009-1/lib/fonts/IsabelleMono.sfd (still unused);
wenzelm
parents: 69436
diff changeset
   119
      )
1b64f82aaf76 more mathematical glyphs from Isabelle2009-1/lib/fonts/IsabelleMono.sfd (still unused);
wenzelm
parents: 69436
diff changeset
   120
1b64f82aaf76 more mathematical glyphs from Isabelle2009-1/lib/fonts/IsabelleMono.sfd (still unused);
wenzelm
parents: 69436
diff changeset
   121
    val vacuous_font: Seq[Int] =
1b64f82aaf76 more mathematical glyphs from Isabelle2009-1/lib/fonts/IsabelleMono.sfd (still unused);
wenzelm
parents: 69436
diff changeset
   122
      Seq(0x3c)  // "<" as template
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   123
  }
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   124
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   125
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   126
  /* font families */
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   127
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   128
  sealed case class Family(
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   129
    plain: String = "",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   130
    bold: String = "",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   131
    italic: String = "",
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   132
    bold_italic: String = "")
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   133
  {
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   134
    val fonts: List[String] =
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   135
      proper_string(plain).toList :::
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   136
      proper_string(bold).toList :::
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   137
      proper_string(italic).toList :::
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   138
      proper_string(bold_italic).toList
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   139
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   140
    def get(index: Int): String = fonts(index % fonts.length)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   141
  }
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   142
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   143
  object Family
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   144
  {
69436
1b406949981f clarified names;
wenzelm
parents: 69395
diff changeset
   145
    def isabelle_symbols: Family =
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   146
      Family(
69436
1b406949981f clarified names;
wenzelm
parents: 69395
diff changeset
   147
        plain = "IsabelleSymbols.sfd",
1b406949981f clarified names;
wenzelm
parents: 69395
diff changeset
   148
        bold = "IsabelleSymbolsBold.sfd")
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   149
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   150
    def deja_vu_sans_mono: Family =
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   151
      Family(
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   152
        plain = "DejaVuSansMono.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   153
        bold = "DejaVuSansMono-Bold.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   154
        italic = "DejaVuSansMono-Oblique.ttf",
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   155
        bold_italic = "DejaVuSansMono-BoldOblique.ttf")
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   156
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   157
    def deja_vu_sans: Family =
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   158
      Family(
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   159
        plain = "DejaVuSans.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   160
        bold = "DejaVuSans-Bold.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   161
        italic = "DejaVuSans-Oblique.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   162
        bold_italic = "DejaVuSans-BoldOblique.ttf")
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   163
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   164
    def deja_vu_serif: Family =
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   165
      Family(
69332
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   166
        plain = "DejaVuSerif.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   167
        bold = "DejaVuSerif-Bold.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   168
        italic = "DejaVuSerif-Italic.ttf",
85ccc983748c clarified;
wenzelm
parents: 69331
diff changeset
   169
        bold_italic = "DejaVuSerif-BoldItalic.ttf")
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   170
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   171
    def vacuous: Family = Family(plain = "Vacuous.sfd")
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   172
  }
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   173
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   174
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   175
  /* build fonts */
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   176
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   177
  private def find_file(dirs: List[Path], name: String): Path =
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   178
  {
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   179
    val path = Path.explode(name)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   180
    dirs.collectFirst({ case dir if (dir + path).is_file => dir + path }) match {
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   181
      case Some(file) => file
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   182
      case None =>
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   183
        error(cat_lines(
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   184
          ("Failed to find font file " + path + " in directories:") ::
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   185
            dirs.map(dir => "  " + dir.toString)))
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   186
    }
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   187
  }
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   188
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   189
  val default_sources: List[Family] =
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   190
    List(Family.deja_vu_sans_mono, Family.deja_vu_sans, Family.deja_vu_serif)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   191
69372
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   192
  val default_target_dir: Path = Path.explode("isabelle_fonts")
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   193
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   194
  def build_fonts(
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   195
    sources: List[Family] = default_sources,
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   196
    source_dirs: List[Path] = Nil,
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   197
    target_prefix: String = "Isabelle",
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   198
    target_version: String = "",
69372
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   199
    target_dir: Path = default_target_dir,
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   200
    progress: Progress = No_Progress)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   201
  {
69372
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   202
    progress.echo("Directory " + target_dir)
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   203
    Isabelle_System.mkdirs(target_dir)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   204
69354
600727ff6889 clarified Admin resources;
wenzelm
parents: 69343
diff changeset
   205
    val font_dirs = source_dirs ::: List(Path.explode("~~/Admin/isabelle_fonts"))
600727ff6889 clarified Admin resources;
wenzelm
parents: 69343
diff changeset
   206
    for (dir <- font_dirs if !dir.is_dir) error("Bad source directory: " + dir)
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   207
69371
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
    // Isabelle fonts
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   210
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   211
    val targets =
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   212
      for { source <- sources; (source_font, index) <- source.fonts.zipWithIndex }
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   213
      yield {
69436
1b406949981f clarified names;
wenzelm
parents: 69395
diff changeset
   214
        val isabelle_file = find_file(font_dirs, Family.isabelle_symbols.get(index))
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   215
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   216
        val source_file = find_file(font_dirs, source_font)
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   217
        val source_names = Fontforge.font_names(source_file)
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   218
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   219
        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
   220
        val target_file = target_dir + target_names.ttf
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   221
69372
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   222
        progress.echo("Font " + target_file.toString + " ...")
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   223
        Fontforge.execute(
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   224
          Fontforge.commands(
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   225
            Fontforge.open(isabelle_file),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   226
            Fontforge.select(Range.isabelle_font),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   227
            Fontforge.copy,
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   228
            Fontforge.close,
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   229
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   230
            Fontforge.open(source_file),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   231
            Fontforge.select(Range.base_font),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   232
            Fontforge.select_invert,
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   233
            Fontforge.clear,
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   234
            Fontforge.select(Range.isabelle_font),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   235
            Fontforge.paste,
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   236
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   237
            target_names.set,
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   238
            Fontforge.generate(target_file),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   239
            Fontforge.close)
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   240
        ).check
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   241
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   242
        (target_file, index)
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   243
      }
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   244
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
    // Vacuous font
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   247
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   248
    {
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   249
      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
   250
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   251
      val target_names = Fontforge.font_names(vacuous_file)
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   252
      val target_file = target_dir + target_names.ttf
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   253
69372
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   254
      progress.echo("Font " + target_file.toString + " ...")
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   255
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   256
      val domain =
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   257
        (for ((target_file, index) <- targets if index == 0)
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   258
          yield Fontforge.font_domain(target_file)).flatten.toSet.toList.sorted
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   259
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   260
      Fontforge.execute(
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   261
        Fontforge.commands(
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   262
          Fontforge.open(vacuous_file),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   263
          Fontforge.select(Range.vacuous_font),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   264
          Fontforge.copy) +
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   265
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   266
        domain.map(code =>
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   267
            Fontforge.commands(
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   268
              Fontforge.select(Seq(code)),
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   269
              Fontforge.paste))
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   270
          .mkString("\n", "\n", "\n") +
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   271
69371
3539767d5c61 generate Vacuous font from domain of Isabelle fonts;
wenzelm
parents: 69354
diff changeset
   272
        Fontforge.commands(
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   273
          Fontforge.generate(target_file),
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   274
          Fontforge.close)
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   275
      ).check
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   276
    }
69373
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   277
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   278
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   279
    // etc/settings
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   280
69395
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents: 69374
diff changeset
   281
    val settings_path = Components.settings(target_dir)
69373
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   282
    Isabelle_System.mkdirs(settings_path.dir)
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   283
    File.write(settings_path,
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   284
      "# -*- shell-script -*- :mode=shellscript:\n\nisabelle_fonts \\\n" +
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   285
      (for ((path, _) <- targets)
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   286
        yield """  "$COMPONENT/""" + path.file_name + "\"").mkString(" \\\n") +
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   287
      """
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   288
69374
ab66951166f3 clarified "hidden" terminology;
wenzelm
parents: 69373
diff changeset
   289
isabelle_fonts_hidden "$COMPONENT/Vacuous.ttf"
69373
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   290
""")
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   291
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   292
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   293
    // README
2c0af1c2e723 generate full component;
wenzelm
parents: 69372
diff changeset
   294
    File.copy(Path.explode("~~/Admin/isabelle_fonts/README"), target_dir)
69336
14444ea196a0 support for build_fonts;
wenzelm
parents: 69332
diff changeset
   295
  }
69337
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   296
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   297
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   298
  /* Isabelle tool wrapper */
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   299
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   300
  val isabelle_tool =
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   301
    Isabelle_Tool("build_fonts", "construct Isabelle fonts", args =>
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   302
    {
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   303
      var source_dirs: List[Path] = Nil
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   304
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   305
      val getopts = Getopts("""
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   306
Usage: isabelle build_fonts [OPTIONS]
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   307
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   308
  Options are:
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   309
    -d DIR       additional source directory
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   310
69343
395c4fb15ea2 use "Isabelle DejaVu" fonts uniformly: Text Area, GUI elements, HTML output etc.;
wenzelm
parents: 69341
diff changeset
   311
  Construct Isabelle fonts from DejaVu font families and Isabelle symbols.
69337
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   312
""",
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   313
        "d:" -> (arg => source_dirs = source_dirs ::: List(Path.explode(arg))))
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   314
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   315
      val more_args = getopts(args)
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   316
      if (more_args.nonEmpty) getopts.usage()
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   317
69372
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   318
      val target_version = Date.Format("uuuuMMdd")(Date.now())
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   319
      val target_dir = Path.explode("isabelle_fonts-" + target_version)
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   320
69337
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   321
      val progress = new Console_Progress
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   322
69372
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   323
      build_fonts(source_dirs = source_dirs, target_dir = target_dir,
69de0f561824 clarified target_dir;
wenzelm
parents: 69371
diff changeset
   324
        target_version = target_version, progress = progress)
69337
aa94b3b5aa0b added Isabelle tool wrapper;
wenzelm
parents: 69336
diff changeset
   325
    })
69330
6a33b12f8573 support for construction of Isabelle fonts;
wenzelm
parents:
diff changeset
   326
}