summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2016-01-13 17:57:23 -0500
committerPietro Gagliardi <[email protected]>2016-01-13 17:57:23 -0500
commitb59d586ecf8e9f6f5725798a62e9877e1451287f (patch)
treef948b5dc2f158ce842c21c678bb34a4e7814326c
parent182e8545d639097eee59e6f84253a2a421d1152c (diff)
Added font metrics.
-rw-r--r--draw.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/draw.go b/draw.go
index b52f348..633aa46 100644
--- a/draw.go
+++ b/draw.go
@@ -97,6 +97,18 @@ package ui
// free(text);
// return layout;
// }
+// static uiDrawTextFontMetrics *newFontMetrics(void)
+// {
+// uiDrawTextFontMetrics *m;
+//
+// m = (uiDrawTextFontMetrics *) malloc(sizeof (uiDrawTextFontMetrics));
+// // TODO
+// return m;
+// }
+// static void freeFontMetrics(uiDrawTextFontMetrics *m)
+// {
+// free(m);
+// }
import "C"
// BUG(andlabs): Ideally, all the drawing APIs should be in another package ui/draw (they all have the "uiDraw" prefix in C to achieve a similar goal of avoiding confusing programmers via namespace pollution); managing the linkage of the libui shared library itself across multiple packages is likely going to be a pain, though. (Custom controls implemented using libui won't have this issue, as they *should* only need libui present when linking the shared object, not when linking the Go wrapper. I'm not sure; I'd have to find out first.)
@@ -702,6 +714,45 @@ func (f *Font) Describe() *FontDescriptor {
panic("TODO unimplemented")
}
+// FontMetrics holds various measurements about a Font.
+// All metrics are in the same point units used for drawing.
+type FontMetrics struct {
+ // Ascent is the ascent of the font; that is, the distance from
+ // the top of the character cell to the baseline.
+ Ascent float64
+
+ // Descent is the descent of the font; that is, the distance from
+ // the baseline to the bottom of the character cell. The sum of
+ // Ascent and Descent is the height of the character cell (and
+ // thus, the maximum height of a line of text).
+ Descent float64
+
+ // Leading is the amount of space the font designer suggests
+ // to have between lines (between the bottom of the first line's
+ // character cell and the top of the second line's character cell).
+ // This is a suggestion; it is chosen by the font designer to
+ // improve legibility.
+ Leading float64
+
+ // TODO figure out what these are
+ UnderlinePos float64
+ UnderlineThickness float64
+}
+
+// Metrics returns metrics about the given Font.
+func (f *Font) Metrics() *FontMetrics {
+ m := new(FontMetrics)
+ mm := C.newFontMetrics()
+ C.uiDrawTextFontGetMetrics(f.f, mm)
+ m.Ascent = float64(mm.Ascent)
+ m.Descent = float64(mm.Descent)
+ m.Leading = float64(mm.Leading)
+ m.UnderlinePos = float64(mm.UnderlinePos)
+ m.UnderlineThickness = float64(mm.UnderlineThickness)
+ C.freeFontMetrics(mm)
+ return m
+}
+
// TextLayout is the entry point for formatting a block of text to be
// drawn onto a DrawContext.
//