Skip to content

Commit

Permalink
New font measure interface
Browse files Browse the repository at this point in the history
  • Loading branch information
praeclarum committed Apr 30, 2012
1 parent 355299c commit 9bf0e10
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/CoreGraphicsGraphics.cs
Expand Up @@ -501,8 +501,6 @@ public void MeasureText (CGContext c, Font f)
var sz = c.TextPosition.X - mmWidth; var sz = c.TextPosition.X - mmWidth;


if (sz < 0.1f) { if (sz < 0.1f) {
// BAD FONT SIZE Why does this happen? I don't know
// Console.WriteLine ("BAD FONT MEASUREMENT");
Widths = null; Widths = null;
return; return;
} }
Expand All @@ -517,20 +515,20 @@ public CoreGraphicsFontMetrics ()
{ {
} }


public int StringWidth (string str) public int StringWidth (string str, int startIndex, int length)
{ {
if (str == null) return 0; if (str == null) return 0;


var n = str.Length; var end = startIndex + str.Length;
if (n == 0) return 0; if (end <= 0) return 0;


if (Widths == null) { if (Widths == null) {
return 0; return 0;
} }


var w = 0.0f; var w = 0.0f;


for (var i = 0; i < n; i++) { for (var i = startIndex; i < end; i++) {
var ch = (int)str[i]; var ch = (int)str[i];
if (ch < Widths.Length) { if (ch < Widths.Length) {
w += Widths[ch]; w += Widths[ch];
Expand Down

0 comments on commit 9bf0e10

Please sign in to comment.