forked from andlabs/libui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.osxdrawtext
43 lines (40 loc) · 1.62 KB
/
stats.osxdrawtext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
diff --git a/darwin/drawtext.m b/darwin/drawtext.m
index a84b68b..c95bbde 100644
--- a/darwin/drawtext.m
+++ b/darwin/drawtext.m
@@ -108,7 +108,7 @@ static CFAttributedStringRef attrstrToCoreFoundation(uiAttributedString *s, uiDr
boundsNoLeading = CTLineGetBoundsWithOptions(line, kCTLineBoundsExcludeTypographicLeading);
// this is equivalent to boundsNoLeading.size.height + boundsNoLeading.origin.y (manually verified)
- ascent = bounds.size.height + bounds.origin.y;
+if(i!=5) ascent = bounds.size.height + bounds.origin.y;
descent = -boundsNoLeading.origin.y;
// TODO does this preserve leading sign?
leading = -bounds.origin.y - descent;
@@ -119,11 +119,20 @@ static CFAttributedStringRef attrstrToCoreFoundation(uiAttributedString *s, uiDr
if (leading > 0)
leading = floor(leading + 0.5);
+NSLog(@"line %d", (int)i);
+NSLog(@"ypos %g", ypos);
+if (i>0) {
+NSLog(@"expected Y: %g", metrics[i - 1].Y - metrics[i - 1].Height);
+}
+
metrics[i].X = origins[i].x;
metrics[i].Y = origins[i].y - descent - leading;
metrics[i].Width = bounds.size.width;
metrics[i].Height = ascent + descent + leading;
+NSLog(@"o %g a %g d %g l %g", origins[i].y, ascent, descent, leading);
+NSLog(@"actual Y: %g height: %g", metrics[i].Y, metrics[i].Height);
+
metrics[i].BaselineY = origins[i].y;
metrics[i].Ascent = ascent;
metrics[i].Descent = descent;
@@ -148,7 +157,7 @@ static CFAttributedStringRef attrstrToCoreFoundation(uiAttributedString *s, uiDr
metrics[i].BaselineY = size.height - metrics[i].BaselineY;
// TODO also adjust by metrics[i].Height?
}
-
+NSLog(@"===");
uiFree(origins);
return metrics;
}