equal
deleted
inserted
replaced
23 val default: Font_Metric = new Font_Metric() |
23 val default: Font_Metric = new Font_Metric() |
24 } |
24 } |
25 |
25 |
26 class Font_Metric( |
26 class Font_Metric( |
27 val font: Font = Font_Metric.default_font, |
27 val font: Font = Font_Metric.default_font, |
28 val context: FontRenderContext = Font_Metric.default_context, |
28 val context: FontRenderContext = Font_Metric.default_context) extends Pretty.Metric |
29 standard_margin: Double => Int = _ => Pretty.default_margin.toInt) extends Pretty.Metric |
|
30 { |
29 { |
31 override def toString: String = font.toString |
30 override def toString: String = font.toString |
|
31 override def hashCode: Int = font.hashCode |
|
32 |
|
33 override def equals(that: Any): Boolean = |
|
34 that match { |
|
35 case other: Font_Metric => font == other.font && context == other.context |
|
36 case _ => false |
|
37 } |
32 |
38 |
33 def string_bounds(str: String): Rectangle2D = font.getStringBounds(str, context) |
39 def string_bounds(str: String): Rectangle2D = font.getStringBounds(str, context) |
34 def string_width(str: String): Double = string_bounds(str).getWidth |
40 def string_width(str: String): Double = string_bounds(str).getWidth |
35 |
41 |
36 protected def sample: String = "mix" |
42 protected def sample: String = "mix" |
46 } |
52 } |
47 else s |
53 else s |
48 string_width(s1) / unit |
54 string_width(s1) / unit |
49 } |
55 } |
50 def average: Double = average_width / unit |
56 def average: Double = average_width / unit |
51 |
|
52 def make_margin(margin: Int, limit: Int = -1): Int = { |
|
53 val m = (margin * average).toInt |
|
54 (if (limit < 0) m else m min limit) max 20 |
|
55 } |
|
56 val margin: Int = make_margin(standard_margin(average_width)) |
|
57 |
|
58 override lazy val hashCode: Int = (font, context, margin).hashCode |
|
59 |
|
60 override def equals(that: Any): Boolean = |
|
61 that match { |
|
62 case other: Font_Metric => |
|
63 font == other.font && context == other.context && margin == other.margin |
|
64 case _ => false |
|
65 } |
|
66 } |
57 } |