src/Pure/System/isabelle_fonts.scala
changeset 75393 87ebf5a50283
parent 73340 0ffcad1f6130
child 77570 98b4a9902582
equal deleted inserted replaced
75388:b3ca4a6ed74b 75393:87ebf5a50283
     9 
     9 
    10 
    10 
    11 import java.awt.{Font, GraphicsEnvironment}
    11 import java.awt.{Font, GraphicsEnvironment}
    12 
    12 
    13 
    13 
    14 object Isabelle_Fonts
    14 object Isabelle_Fonts {
    15 {
       
    16   /* standard names */
    15   /* standard names */
    17 
    16 
    18   val mono: String = "Isabelle DejaVu Sans Mono"
    17   val mono: String = "Isabelle DejaVu Sans Mono"
    19   val sans: String = "Isabelle DejaVu Sans"
    18   val sans: String = "Isabelle DejaVu Sans"
    20   val serif: String = "Isabelle DejaVu Serif"
    19   val serif: String = "Isabelle DejaVu Serif"
    21 
    20 
    22 
    21 
    23   /* environment entries */
    22   /* environment entries */
    24 
    23 
    25   object Entry
    24   object Entry {
    26   {
    25     object Ordering extends scala.math.Ordering[Entry] {
    27     object Ordering extends scala.math.Ordering[Entry]
       
    28     {
       
    29       def compare(entry1: Entry, entry2: Entry): Int =
    26       def compare(entry1: Entry, entry2: Entry): Int =
    30         entry1.family compare entry2.family match {
    27         entry1.family compare entry2.family match {
    31           case 0 => entry1.style compare entry2.style
    28           case 0 => entry1.style compare entry2.style
    32           case ord => ord
    29           case ord => ord
    33         }
    30         }
    34     }
    31     }
    35   }
    32   }
    36 
    33 
    37   sealed case class Entry(path: Path, hidden: Boolean = false)
    34   sealed case class Entry(path: Path, hidden: Boolean = false) {
    38   {
       
    39     lazy val bytes: Bytes = Bytes.read(path)
    35     lazy val bytes: Bytes = Bytes.read(path)
    40     lazy val font: Font = Font.createFont(Font.TRUETYPE_FONT, path.file)
    36     lazy val font: Font = Font.createFont(Font.TRUETYPE_FONT, path.file)
    41 
    37 
    42     def family: String = font.getFamily
    38     def family: String = font.getFamily
    43     def name: String = font.getFontName
    39     def name: String = font.getFontName
    54       name_lowercase.containsSlice("oblique")
    50       name_lowercase.containsSlice("oblique")
    55   }
    51   }
    56 
    52 
    57   def make_entries(
    53   def make_entries(
    58     getenv: String => String = Isabelle_System.getenv_strict(_),
    54     getenv: String => String = Isabelle_System.getenv_strict(_),
    59     hidden: Boolean = false): List[Entry] =
    55     hidden: Boolean = false
    60   {
    56   ): List[Entry] = {
    61     Path.split(getenv("ISABELLE_FONTS")).map(Entry(_)) :::
    57     Path.split(getenv("ISABELLE_FONTS")).map(Entry(_)) :::
    62     (if (hidden) Path.split(getenv("ISABELLE_FONTS_HIDDEN")).map(Entry(_, hidden = true)) else Nil)
    58     (if (hidden) Path.split(getenv("ISABELLE_FONTS_HIDDEN")).map(Entry(_, hidden = true)) else Nil)
    63   }
    59   }
    64 
    60 
    65   private lazy val all_fonts: List[Entry] =
    61   private lazy val all_fonts: List[Entry] =
    69     if (hidden) all_fonts else all_fonts.filter(entry => !entry.hidden)
    65     if (hidden) all_fonts else all_fonts.filter(entry => !entry.hidden)
    70 
    66 
    71 
    67 
    72   /* system init */
    68   /* system init */
    73 
    69 
    74   def init(): Unit =
    70   def init(): Unit = {
    75   {
       
    76     val ge = GraphicsEnvironment.getLocalGraphicsEnvironment()
    71     val ge = GraphicsEnvironment.getLocalGraphicsEnvironment()
    77     for (entry <- fonts()) ge.registerFont(entry.font)
    72     for (entry <- fonts()) ge.registerFont(entry.font)
    78   }
    73   }
    79 }
    74 }