author | wenzelm |
Thu, 07 Nov 2024 11:46:21 +0100 | |
changeset 81381 | 76f74ac9edee |
parent 76610 | 6e2383488a55 |
child 81383 | 75a2c6af8a02 |
permissions | -rw-r--r-- |
55827 | 1 |
/* Title: Tools/jEdit/src/font_info.scala |
55825 | 2 |
Author: Makarius |
3 |
||
55827 | 4 |
Font information, derived from main jEdit view font. |
55825 | 5 |
*/ |
6 |
||
7 |
package isabelle.jedit |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
12 |
||
13 |
import java.awt.Font |
|
14 |
||
15 |
import org.gjt.sp.jedit.{jEdit, View} |
|
16 |
||
17 |
||
75393 | 18 |
object Font_Info { |
55825 | 19 |
/* size range */ |
20 |
||
21 |
val min_size = 5 |
|
22 |
val max_size = 250 |
|
23 |
||
73343
d0378baf7d06
tuned --- avoid deprecated conversions between certain number type;
wenzelm
parents:
73340
diff
changeset
|
24 |
def restrict_size(size: Float): Float = size max min_size.toFloat min max_size.toFloat |
55825 | 25 |
|
26 |
||
55827 | 27 |
/* main jEdit font */ |
55825 | 28 |
|
29 |
def main_family(): String = jEdit.getProperty("view.font") |
|
30 |
||
31 |
def main_size(scale: Double = 1.0): Float = |
|
32 |
restrict_size(jEdit.getIntegerProperty("view.fontsize", 16).toFloat * scale.toFloat) |
|
33 |
||
34 |
def main(scale: Double = 1.0): Font_Info = |
|
81381 | 35 |
Font_Info(main_family(), main_size(scale = scale)) |
55825 | 36 |
|
55827 | 37 |
|
38 |
/* incremental size change */ |
|
39 |
||
75393 | 40 |
object main_change { |
41 |
private def change_size(change: Float => Float): Unit = { |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
42 |
GUI_Thread.require {} |
55827 | 43 |
|
44 |
val size0 = main_size() |
|
45 |
val size = restrict_size(change(size0)).round |
|
46 |
if (size != size0) { |
|
47 |
jEdit.setIntegerProperty("view.fontsize", size) |
|
48 |
jEdit.propertiesChanged() |
|
49 |
jEdit.saveSettings() |
|
50 |
jEdit.getActiveView().getStatus.setMessageAndClear("Text font size: " + size) |
|
51 |
} |
|
52 |
} |
|
53 |
||
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
54 |
// owned by GUI thread |
55827 | 55 |
private var steps = 0 |
76610 | 56 |
private val delay = Delay.last(PIDE.session.input_delay, gui = true) { |
75394 | 57 |
change_size { size => |
75393 | 58 |
var i = size.round |
59 |
while (steps != 0 && i > 0) { |
|
60 |
if (steps > 0) { i += (i / 10) max 1; steps -= 1 } |
|
61 |
else { i -= (i / 10) max 1; steps += 1 } |
|
62 |
} |
|
63 |
steps = 0 |
|
64 |
i.toFloat |
|
75394 | 65 |
} |
55827 | 66 |
} |
67 |
||
75393 | 68 |
def step(i: Int): Unit = { |
55827 | 69 |
steps += i |
70 |
delay.invoke() |
|
71 |
} |
|
72 |
||
75393 | 73 |
def reset(size: Float): Unit = { |
55827 | 74 |
delay.revoke() |
75 |
steps = 0 |
|
76 |
change_size(_ => size) |
|
55825 | 77 |
} |
78 |
} |
|
57044 | 79 |
|
80 |
||
75839 | 81 |
/* zoom */ |
57044 | 82 |
|
75839 | 83 |
class Zoom extends GUI.Zoom { tooltip = "Zoom factor for output font size" } |
55825 | 84 |
} |
85 |
||
75393 | 86 |
sealed case class Font_Info(family: String, size: Float) { |
55825 | 87 |
def font: Font = new Font(family, Font.PLAIN, size.round) |
88 |
} |