Commit bf0e73f6 authored by h2b's avatar h2b

Wrong derivation of new font fixed.

parent 71ef8ae4
......@@ -77,7 +77,7 @@ trait AwtScreenDriver extends ScreenDriver {
val h = metrics.getHeight
def dimension (c: Char): (Int, Int) = (metrics.charWidth(c), h)
def dimension (s: String): (Int, Int) = (metrics.stringWidth(s), h)
def derived (newFont: Font): Font with FontMetrics = this
def derived (font: Font): Font with FontMetrics = newFont(font.size, font.emphasis)
}
f
}
......
......@@ -29,17 +29,25 @@ class AwtScreenDriverTest extends FunSuite {
private val awt = Screen.awt(Pixel(500, 500), 250, 250, "Test screen")
test("Font metrics") {
val f0 = awt.activeFont
println(f0.dimension('X'))
println(f0.dimension("abc"))
var p = Pixel(-250, 200)
for (s Font.Size.values) {
awt.drawText(p, "abc")
p -= Pixel(0, 30)
awt.activeFont = f0.derived(Font(s))
println(s + ": X→" + awt.activeFont.dimension('X'),
"abc→" + awt.activeFont.dimension("abc"))
}
}
}
object AwtScreenDriverTest extends App {
private val awt = Screen.awt(Pixel(500, 500), 250, 250, "Test screen")
awt.activeColor = Color.Yellow
println("Default: X→" + awt.activeFont.dimension('X') +
"abc→" + awt.activeFont.dimension("abc"))
val f0 = awt.activeFont
var p = Pixel(50, 0)
for (s Font.Size.values) {
p += Pixel(0, 30)
awt.activeFont = f0.derived(Font(s))
println(s + ": X→" + awt.activeFont.dimension('X') +
"abc→" + awt.activeFont.dimension("abc"))
awt.drawText(p, "XabcX")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment