src/Pure/System/isabelle_system.scala
changeset 37367 8680677265c9
parent 37132 10ef4da1c314
child 38253 3d4e521014f7
equal deleted inserted replaced
37366:5c6695de35ba 37367:8680677265c9
    10 import java.util.Locale
    10 import java.util.Locale
    11 import java.io.{BufferedWriter, OutputStreamWriter, FileOutputStream,
    11 import java.io.{BufferedWriter, OutputStreamWriter, FileOutputStream,
    12   BufferedInputStream, FileInputStream, BufferedReader, InputStreamReader,
    12   BufferedInputStream, FileInputStream, BufferedReader, InputStreamReader,
    13   File, IOException}
    13   File, IOException}
    14 import java.awt.{GraphicsEnvironment, Font}
    14 import java.awt.{GraphicsEnvironment, Font}
       
    15 import java.awt.font.TextAttribute
    15 
    16 
    16 import scala.io.Source
    17 import scala.io.Source
    17 import scala.util.matching.Regex
    18 import scala.util.matching.Regex
    18 import scala.collection.mutable
    19 import scala.collection.mutable
    19 
    20 
   334 
   335 
   335 
   336 
   336   /* fonts */
   337   /* fonts */
   337 
   338 
   338   val font_family = getenv_strict("ISABELLE_FONT_FAMILY")
   339   val font_family = getenv_strict("ISABELLE_FONT_FAMILY")
       
   340   val font_family_default = "IsabelleText"
   339 
   341 
   340   def get_font(size: Int = 1, bold: Boolean = false): Font =
   342   def get_font(size: Int = 1, bold: Boolean = false): Font =
   341     new Font(font_family, if (bold) Font.BOLD else Font.PLAIN, size)
   343     new Font(font_family, if (bold) Font.BOLD else Font.PLAIN, size)
   342 
   344 
       
   345   def create_default_font(bold: Boolean = false): Font =
       
   346     if (bold)
       
   347       Font.createFont(Font.TRUETYPE_FONT,
       
   348         platform_file("$ISABELLE_HOME/lib/fonts/IsabelleTextBold.ttf"))
       
   349     else
       
   350       Font.createFont(Font.TRUETYPE_FONT,
       
   351         platform_file("$ISABELLE_HOME/lib/fonts/IsabelleText.ttf"))
       
   352 
   343   def install_fonts()
   353   def install_fonts()
   344   {
   354   {
   345     def create_font(bold: Boolean): Font =
   355     val ge = GraphicsEnvironment.getLocalGraphicsEnvironment()
   346     {
   356     ge.registerFont(create_default_font(bold = false))
   347       val name =
   357     ge.registerFont(create_default_font(bold = true))
   348         if (bold) "$ISABELLE_HOME/lib/fonts/IsabelleTextBold.ttf"
       
   349         else "$ISABELLE_HOME/lib/fonts/IsabelleText.ttf"
       
   350       Font.createFont(Font.TRUETYPE_FONT, platform_file(name))
       
   351     }
       
   352     def check_font() = get_font().getFamily == font_family
       
   353 
       
   354     if (!check_font()) {
       
   355       val font = create_font(false)
       
   356       val bold_font = create_font(true)
       
   357 
       
   358       val ge = GraphicsEnvironment.getLocalGraphicsEnvironment()
       
   359       ge.registerFont(font)
       
   360       // workaround strange problem with Apple's Java 1.6 font manager
       
   361       // FIXME does not quite work!?
       
   362       if (bold_font.getFamily == font_family) ge.registerFont(bold_font)
       
   363       if (!check_font()) error("Failed to install IsabelleText fonts")
       
   364     }
       
   365   }
   358   }
   366 }
   359 }