69355
|
1 |
/* Title: Pure/System/isabelle_system.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Fonts from the Isabelle system environment, notably the "Isabelle DejaVu"
|
|
5 |
collection.
|
|
6 |
*/
|
|
7 |
|
|
8 |
package isabelle
|
|
9 |
|
|
10 |
|
69360
|
11 |
import java.awt.Font
|
|
12 |
|
|
13 |
|
69355
|
14 |
object Isabelle_Fonts
|
|
15 |
{
|
69357
|
16 |
/* standard names */
|
|
17 |
|
|
18 |
val mono: String = "Isabelle DejaVu Sans Mono"
|
|
19 |
val sans: String = "Isabelle DejaVu Sans"
|
|
20 |
val serif: String = "Isabelle DejaVu Serif"
|
|
21 |
|
|
22 |
|
69360
|
23 |
/* environment entries */
|
69355
|
24 |
|
69363
|
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 |
|
69360
|
37 |
sealed case class Entry(path: Path, html: Boolean = false)
|
|
38 |
{
|
|
39 |
def bytes: Bytes = Bytes.read(path)
|
|
40 |
|
|
41 |
lazy val font: Font = Font.createFont(Font.TRUETYPE_FONT, path.file)
|
|
42 |
def family: String = font.getFamily
|
|
43 |
def name: String = font.getFontName
|
69363
|
44 |
def style: Int =
|
|
45 |
(if (is_bold) Font.BOLD else 0) +
|
|
46 |
(if (is_italic) Font.ITALIC else 0)
|
69355
|
47 |
|
69363
|
48 |
// educated guess for style: Font.createFont always produces Font.PLAIN
|
69360
|
49 |
private lazy val name_lowercase = Word.lowercase(name)
|
|
50 |
def is_bold: Boolean =
|
|
51 |
name_lowercase.containsSlice("bold")
|
|
52 |
def is_italic: Boolean =
|
69363
|
53 |
name_lowercase.containsSlice("italic") ||
|
|
54 |
name_lowercase.containsSlice("oblique")
|
69360
|
55 |
}
|
|
56 |
|
|
57 |
def make_entries(
|
|
58 |
getenv: String => String = Isabelle_System.getenv_strict(_),
|
|
59 |
html: Boolean = false): List[Entry] =
|
69355
|
60 |
{
|
69360
|
61 |
Path.split(getenv("ISABELLE_FONTS")).map(Entry(_)) :::
|
|
62 |
(if (html) Path.split(getenv("ISABELLE_FONTS_HTML")).map(Entry(_, html = true)) else Nil)
|
69355
|
63 |
}
|
69360
|
64 |
|
69363
|
65 |
private lazy val all_fonts: List[Entry] =
|
|
66 |
make_entries(html = true).sorted(Entry.Ordering)
|
69360
|
67 |
|
|
68 |
def fonts(html: Boolean = false): List[Entry] =
|
|
69 |
if (html) all_fonts else all_fonts.filter(entry => !entry.html)
|
69355
|
70 |
}
|