diff dwt/graphics/TextLayout.d @ 60:62202ce0039f

Updated and fixed many modules to 3.514
author Jacob Carlborg <doob@me.com>
date Mon, 22 Dec 2008 15:10:19 +0100
parents cfa563df4fdd
children 1a0129cab08e
line wrap: on
line diff
--- a/dwt/graphics/TextLayout.d	Tue Dec 09 21:52:21 2008 +0100
+++ b/dwt/graphics/TextLayout.d	Mon Dec 22 15:10:19 2008 +0100
@@ -50,7 +50,7 @@
 import dwt.graphics.Region;
 import dwt.graphics.Resource;
 import dwt.graphics.TextStyle;
-import dwt.internal.c.Carbon;
+import Carbon = dwt.internal.c.Carbon;
 import dwt.internal.cocoa.NSText;
 import dwt.internal.objc.cocoa.Cocoa;
 
@@ -94,7 +94,7 @@
     int[] lineOffsets;
     NSRect[] lineBounds;
     
-    static final int UNDERLINE_THICK = 1 << 16;
+    static const int UNDERLINE_THICK = 1 << 16;
 
     static class StyleItem {
         TextStyle style;
@@ -149,10 +149,10 @@
     if (peaks is 0 && right - left > 2) {
         peaks = 1;
     }
-    int length = ((2 * peaks) + 1) * 2;
-    if (length < 0) return new float[0];
+    int length_ = ((2 * peaks) + 1) * 2;
+    if (length_ < 0) return new float[0];
     
-    float[] coordinates = new float[length];
+    float[] coordinates = new float[length_];
     for (int i = 0; i < peaks; i++) {
         int index = 4 * i;
         coordinates[index] = left + (width * i);
@@ -160,8 +160,8 @@
         coordinates[index+2] = coordinates[index] + width / 2;
         coordinates[index+3] = top;
     }
-    coordinates[length-2] = left + (width * peaks);
-    coordinates[length-1] = bottom;
+    coordinates[length_-2] = left + (width * peaks);
+    coordinates[length_-1] = bottom;
     return coordinates;
 }
 
@@ -186,16 +186,16 @@
     textStorage.addAttribute(OS.NSFontAttributeName, defaultFont.handle, range);
     
     NSMutableParagraphStyle paragraph = cast(NSMutableParagraphStyle)(new NSMutableParagraphStyle()).alloc().init();
-    NSTextAlignment align_ = NSLeftTextAlignment;
+    NSTextAlignment align_ = OS.NSLeftTextAlignment;
     if (justify) {
-        align_ = NSJustifiedTextAlignment;
+        align_ = OS.NSJustifiedTextAlignment;
     } else {
         switch (alignment) {
             case DWT.CENTER:
-                align_ = NSCenterTextAlignment;
+                align_ = OS.NSCenterTextAlignment;
                 break;
             case DWT.RIGHT:
-                align_ = NSRightTextAlignment;
+                align_ = OS.NSRightTextAlignment;
         }
     }
     paragraph.setAlignment(align_);
@@ -287,6 +287,7 @@
     int numberOfLines;
     NSUInteger numberOfGlyphs = layoutManager.numberOfGlyphs(), index;
     NSRangePointer rangePtr = cast(NSRangePointer) OS.malloc(NSRange.sizeof);
+    NSRange lineRange = NSRange();
     for (numberOfLines = 0, index = 0; index < numberOfGlyphs; numberOfLines++){
         layoutManager.lineFragmentUsedRectForGlyphAtIndex(index, rangePtr, true);
         OS.memmove(&lineRange, rangePtr, NSRange.sizeof);
@@ -297,7 +298,7 @@
     NSRect[] bounds = new NSRect[numberOfLines];
     for (numberOfLines = 0, index = 0; index < numberOfGlyphs; numberOfLines++){
         bounds[numberOfLines] = layoutManager.lineFragmentUsedRectForGlyphAtIndex(index, rangePtr, true);
-        if (numberOfLines < bounds.length - 1) bounds[numberOfLines].height -= spacing;
+        if (numberOfLines < bounds.length - 1) bounds[numberOfLines].height = bounds[numberOfLines].height - spacing;
         OS.memmove(&lineRange, rangePtr, NSRange.sizeof);
         offsets[numberOfLines] = cast(int)/*64*/lineRange.location;
         index = lineRange.location + lineRange.length;
@@ -415,7 +416,7 @@
             selectionColor = NSColor.colorWithDeviceRed(selectionBackground.handle[0], selectionBackground.handle[1], selectionBackground.handle[2], selectionBackground.handle[3]);
         }
         if (hasSelection) {
-            selectionRange = NSRange();
+            selectionRange = &NSRange();
             selectionRange.location = selectionStart;
             selectionRange.length = selectionEnd - selectionStart + 1;
         layoutManager.addTemporaryAttribute(OS.NSBackgroundColorAttributeName, selectionColor, *selectionRange);
@@ -478,7 +479,7 @@
                                     path.setLineWidth(2f);
                                     path.setLineCapStyle(OS.NSRoundLineCapStyle);
                                     path.setLineJoinStyle(OS.NSRoundLineJoinStyle);
-                                    path.setLineDash([1, 3f], 2, 0);
+                                    path.setLineDash([1f, 3f].ptr, 2, cast(Carbon.CGFloat) 0);
                                     point.x = underlineX;
                                     point.y = underlineY + 0.5f;
                                     path.moveToPoint(point);
@@ -525,25 +526,25 @@
                             if (range.length > 0) {
                                 gc.handle.saveGraphicsState();
                                 NSRect rect = layoutManager.boundingRectForGlyphRange(range, textContainer);
-                                rect.x += pt.x + 0.5f;
-                                rect.y += pt.y + 0.5f;
-                                rect.width -= 0.5f;
-                                rect.height -= 0.5f;
-                                float[] color = null;
+                                rect.x = rect.x + pt.x + 0.5f;
+                                rect.y = rect.y + pt.y + 0.5f;
+                                rect.width = rect.width - 0.5f;
+                                rect.height = rect.height - 0.5f;
+                                Carbon.CGFloat[] color = null;
                                 if (style.borderColor !is null) color = style.borderColor.handle;
                                 if (color is null && style.foreground !is null) color = style.foreground.handle;
                                 if (color !is null) {
                                     NSColor.colorWithDeviceRed(color[0], color[1], color[2], color[3]).setStroke();
                                 }
                                 int width = 1;
-                                float[] dashes = null;
+                                Carbon.CGFloat[] dashes = null;
                                 switch (style.borderStyle) {
                                 case DWT.BORDER_SOLID:  break;
                                 case DWT.BORDER_DASH: dashes = width !is 0 ? GC.LINE_DASH : GC.LINE_DASH_ZERO; break;
                                 case DWT.BORDER_DOT: dashes = width !is 0 ? GC.LINE_DOT : GC.LINE_DOT_ZERO; break;
                                 }
                                 NSBezierPath path = NSBezierPath.bezierPath();
-                                path.setLineDash(dashes, dashes !is null ? dashes.length : 0, 0);
+                                path.setLineDash(dashes.ptr, dashes !is null ? dashes.length : 0, 0);
                                 path.appendBezierPathWithRect(rect);
                                 path.stroke();
                                 gc.handle.restoreGraphicsState();
@@ -970,7 +971,7 @@
         if (length is 0) return new Point(0, 0);
         offset = translateOffset(offset);
     NSUInteger glyphIndex = layoutManager.glyphIndexForCharacterAtIndex(offset);
-    NSRect rect = layoutManager.lineFragmentUsedRectForGlyphAtIndex_effectiveRange_(glyphIndex, null);
+    NSRect rect = layoutManager.lineFragmentUsedRectForGlyphAtIndex(glyphIndex, null);
         NSPoint point = layoutManager.locationForGlyphAtIndex(glyphIndex);
         if (trailing) {
         NSRange range = NSRange();
@@ -1119,7 +1120,7 @@
     NSPoint pt = NSPoint();
         pt.x = x;
         pt.y = y;
-    CGFloat partialFration;
+    Carbon.CGFloat partialFration;
     NSUInteger glyphIndex = layoutManager.glyphIndexForPoint(pt, textContainer, &partialFration);
         NSUInteger offset = layoutManager.characterIndexForGlyphAtIndex(glyphIndex);
     if (trailing !is null) trailing[0] = cast(int) Math.round(partialFration);