src/Pure/System/isabelle_fonts.scala
changeset 69363 0675481ce575
parent 69360 dc9a39c3f75d
child 69364 91dbade9a5fa
equal deleted inserted replaced
69362:77c93eaf6cb7 69363:0675481ce575
    20   val serif: String = "Isabelle DejaVu Serif"
    20   val serif: String = "Isabelle DejaVu Serif"
    21 
    21 
    22 
    22 
    23   /* environment entries */
    23   /* environment entries */
    24 
    24 
       
    25   object Entry
       
    26   {
       
    27     object Ordering extends scala.math.Ordering[Entry]
       
    28     {
       
    29       def compare(entry1: Entry, entry2: Entry): Int =
       
    30         entry1.family compare entry2.family match {
       
    31           case 0 => entry1.style compare entry2.style
       
    32           case ord => ord
       
    33         }
       
    34     }
       
    35   }
       
    36 
    25   sealed case class Entry(path: Path, html: Boolean = false)
    37   sealed case class Entry(path: Path, html: Boolean = false)
    26   {
    38   {
    27     def bytes: Bytes = Bytes.read(path)
    39     def bytes: Bytes = Bytes.read(path)
    28 
    40 
    29     lazy val font: Font = Font.createFont(Font.TRUETYPE_FONT, path.file)
    41     lazy val font: Font = Font.createFont(Font.TRUETYPE_FONT, path.file)
    30     def family: String = font.getFamily
    42     def family: String = font.getFamily
    31     def name: String = font.getFontName
    43     def name: String = font.getFontName
       
    44     def style: Int =
       
    45       (if (is_bold) Font.BOLD else 0) +
       
    46       (if (is_italic) Font.ITALIC else 0)
    32 
    47 
    33     // educated guessing
    48     // educated guess for style: Font.createFont always produces Font.PLAIN
    34     private lazy val name_lowercase = Word.lowercase(name)
    49     private lazy val name_lowercase = Word.lowercase(name)
    35     def is_bold: Boolean =
    50     def is_bold: Boolean =
    36       name_lowercase.containsSlice("bold")
    51       name_lowercase.containsSlice("bold")
    37     def is_italic: Boolean =
    52     def is_italic: Boolean =
    38       name_lowercase.containsSlice("italic") || name_lowercase.containsSlice("oblique")
    53       name_lowercase.containsSlice("italic") ||
       
    54       name_lowercase.containsSlice("oblique")
    39   }
    55   }
    40 
    56 
    41   def make_entries(
    57   def make_entries(
    42     getenv: String => String = Isabelle_System.getenv_strict(_),
    58     getenv: String => String = Isabelle_System.getenv_strict(_),
    43     html: Boolean = false): List[Entry] =
    59     html: Boolean = false): List[Entry] =
    44   {
    60   {
    45     Path.split(getenv("ISABELLE_FONTS")).map(Entry(_)) :::
    61     Path.split(getenv("ISABELLE_FONTS")).map(Entry(_)) :::
    46     (if (html) Path.split(getenv("ISABELLE_FONTS_HTML")).map(Entry(_, html = true)) else Nil)
    62     (if (html) Path.split(getenv("ISABELLE_FONTS_HTML")).map(Entry(_, html = true)) else Nil)
    47   }
    63   }
    48 
    64 
    49   private lazy val all_fonts: List[Entry] = make_entries(html = true)
    65   private lazy val all_fonts: List[Entry] =
       
    66     make_entries(html = true).sorted(Entry.Ordering)
    50 
    67 
    51   def fonts(html: Boolean = false): List[Entry] =
    68   def fonts(html: Boolean = false): List[Entry] =
    52     if (html) all_fonts else all_fonts.filter(entry => !entry.html)
    69     if (html) all_fonts else all_fonts.filter(entry => !entry.html)
    53 }
    70 }