Hi,

I've re-written my previous patches since they were causing some little 
rendering glitches.

Here's a simple screenshot of Ink.app with a 20,20 inset.

http://sophos.ca/crap/ink.gif

I will continue to work on the text related classes in order to make them 
work better. I plan to work on 'dead keys' support, on 'carriage return' 
problems and other stuff.

Thanks a lot,

Ludo

-- 
Live as if you were to die tomorrow.
Learn as if you were to live forever.
 - Gandhi




--- /tmp/gui/Source/GSSimpleLayoutManager.m     Sun Sep 23 18:09:48 2001
+++ GSSimpleLayoutManager.m     Thu Nov  1 12:31:49 2001
@@ -273,7 +273,13 @@
 
   if (![_textStorage length] || ![_lineLayoutInformation count])
     {
-      return NSMakeRect(0, 0, 0, 12);
+      NSTextContainer *aTextContainer = [self textContainerForGlyphAtIndex: index
+                                             effectiveRange: lineFragmentRange];
+      
+      NSSize inset = [[aTextContainer textView] textContainerInset];
+
+      
+      return NSMakeRect(inset.width, inset.height, 0, 12);
     }
     
   currentInfo = [_lineLayoutInformation 
@@ -292,11 +298,15 @@
   unsigned start;
   _GNULineLayoutInfo *currentInfo;
   
+  NSTextContainer *aTextContainer = [self textContainerForGlyphAtIndex: index
+                                         effectiveRange: NULL];
+  NSSize inset = [[aTextContainer textView] textContainerInset];
+
   if (![_textStorage length] || ![_lineLayoutInformation count])
     {
-      return NSMakePoint(0, 0);
+      return NSMakePoint(inset.width, inset.height);
     }
-    
+  
   currentInfo = [_lineLayoutInformation 
                    objectAtIndex: [self lineLayoutIndexForGlyphIndex: 
                                             index]];
@@ -310,7 +320,7 @@
 
   /* NB: As per specs, we return the location relative to the glyph's
      line fragment rectangle */
-  return NSMakePoint(x, 0);
+  return NSMakePoint(x, inset.height);
 }
 
 - (NSRect)boundingRectForGlyphRange:(NSRange)aRange 
@@ -319,10 +329,11 @@
   _GNULineLayoutInfo *currentInfo;
   unsigned i1, i2;
   NSRect rect1;
-
+  
   if (![_textStorage length] || ![_lineLayoutInformation count])
     {
-      return NSMakeRect(0, 0, 0, 12);
+      NSSize inset = [[aTextContainer textView] textContainerInset];
+      return NSMakeRect(inset.width, inset.height, 0, 12);
     }
 
   i1 = [self lineLayoutIndexForGlyphIndex: aRange.location];
@@ -361,6 +372,8 @@
 {
   //FIXME: This currently ignores most of its arguments
 
+  NSSize inset = [[aTextContainer textView] textContainerInset];
+
   if (!rectCount)
       return _rects;
 
@@ -387,7 +400,7 @@
                                  width - startRect.origin.x,
                                  startRect.size.height);
          // second line
-         _rects[1] = NSMakeRect (0, endRect.origin.y, endRect.origin.x,
+         _rects[1] = NSMakeRect (inset.width, endRect.origin.y, endRect.origin.x - 
+inset.width,
                                  endRect.size.height);
          *rectCount = 2;
        }
@@ -400,11 +413,11 @@
                                  width - startRect.origin.x,
                                  startRect.size.height);
          // intermediate lines
-         _rects[1] = NSMakeRect (0, NSMaxY(startRect),
-                                 width,
+         _rects[1] = NSMakeRect (inset.width, NSMaxY(startRect),
+                                 width - inset.width,
                                  endRect.origin.y - NSMaxY (startRect));
          // last line
-         _rects[2] = NSMakeRect (0, endRect.origin.y, endRect.origin.x,
+         _rects[2] = NSMakeRect (inset.width, endRect.origin.y, endRect.origin.x - 
+inset.width,
                                  endRect.size.height);
          *rectCount = 3;
        }
@@ -502,10 +515,16 @@
   NSRect rect = [self boundingRectForGlyphRange: glyphRange 
                      inTextContainer: aTextContainer];
 
+  // We draw the background even outside the inset
+  rect.origin.y -= containerOrigin.y;
+  rect.size.width += 2 * containerOrigin.x;
+  rect.size.height += 2 * containerOrigin.y;
+
   /* FIXME: Which means that the following <which assumes we are
      drawing in a text view> can't be correct */
   // clear area under text
   [[[aTextContainer textView] backgroundColor] set];
+  
   NSRectFill(rect);
 }
 
@@ -691,9 +710,14 @@
   NSRect rect;
   float x;
 
+  NSTextContainer *aTextContainer = [self textContainerForGlyphAtIndex: index
+                                         effectiveRange: NULL];
+  
+  NSSize inset = [[aTextContainer textView] textContainerInset];
+
   if (![_textStorage length] || ![_lineLayoutInformation count])
     {
-      return NSMakeRect(0, 0, width, 12);
+      return NSMakeRect(inset.width, inset.height, width, 12);
     }
 
   currentInfo = [_lineLayoutInformation lastObject];
@@ -870,6 +894,10 @@
   // for optimization detection
   NSMutableArray *ghostArray = nil;
 
+  NSSize inset = [[aTextContainer textView] textContainerInset];
+  drawingPoint.x = inset.width;
+  drawingPoint.y = inset.height;
+  
   if (maxLines)
     {
       int insertionLineIndex = [self lineLayoutIndexForGlyphIndex:
@@ -911,9 +939,9 @@
       // If there is no text add one empty box
       [_lineLayoutInformation
          addObject: [_GNULineLayoutInfo
-                        lineLayoutWithRange: NSMakeRange (0, 0)
-                        rect: NSMakeRect (0, 0, width, 12)
-                        usedRect: NSMakeRect (0, 0, 0, 12)]];
+                      lineLayoutWithRange: NSMakeRange (0,0)
+                      rect: NSMakeRect (inset.width, inset.height, width, 12)
+                      usedRect: NSMakeRect (inset.width, inset.height, 1, 12)]];
       return NSMakeRange(0,1);
     }
       
@@ -970,7 +998,7 @@
 
          if (NSIsEmptyRect(remainingRect))
            {
-             fragmentRect = NSMakeRect (0, drawingPoint.y, HUGE, HUGE);
+             fragmentRect = NSMakeRect (inset.width, drawingPoint.y, HUGE, HUGE);
            }
          else 
            {
@@ -1089,11 +1117,14 @@
                  scannerPosition += eol.length;
                  usedLineRect.size.width += 1;
                  // FIXME: This should use the real font size!!
-                 if (usedLineRect.size.height == 0)
+                 if (usedLineRect.size.height < 12)
                    {
                      usedLineRect.size.height = 12;
                    }
                }
+
+             // We remove the inset for our rect for our last line
+             usedLineRect.size.width -= inset.width;
            }
          
          lineGlyphRange = NSMakeRange (startingLineCharIndex,
@@ -1119,7 +1150,7 @@
          currentLineIndex++;
          startingLineCharIndex = NSMaxRange(lineGlyphRange);
          drawingPoint.y += usedLineRect.size.height;
-         drawingPoint.x = 0;
+         drawingPoint.x = inset.width;
          
          RELEASE(pool);
          
--- /tmp/gui/Source/NSTextView.m        Tue Oct 30 20:09:07 2001
+++ NSTextView.m        Thu Nov  1 11:49:08 2001
@@ -229,6 +229,7 @@
 
   [self setTypingAttributes: [isa defaultTypingAttributes]];
 
+  [self setTextContainerInset: NSMakeSize(0,0)];
   [self setBackgroundColor: [NSColor textBackgroundColor]];
 
   [aTextContainer setTextView: self];
@@ -1037,11 +1038,13 @@
   _textContainerOrigin.x += usedRect.origin.x;
   
   /* First get the pure text container origin */
-  _textContainerOrigin.y = NSMaxY (_bounds);
-  _textContainerOrigin.y -= _textContainerInset.height;
-  _textContainerOrigin.y -= textContainerSize.height;
+  //_textContainerOrigin.y = NSMaxY (_bounds);
+  //_textContainerOrigin.y -= _textContainerInset.height;
+  //_textContainerOrigin.y -= textContainerSize.height;
   /* Then move to the used rect origin */
-  _textContainerOrigin.y += usedRect.origin.y;
+  //_textContainerOrigin.y += usedRect.origin.y;
+  
+  _textContainerOrigin.y = _textContainerInset.height;
 }
 
 - (NSLayoutManager*) layoutManager
@@ -1099,6 +1102,7 @@
                            color: (NSColor*)color
                         turnedOn: (BOOL)flag
 {
+
   if (_window == nil)
     {
       return;
@@ -1537,14 +1541,14 @@
   
   rect = [_layoutManager lineFragmentRectForGlyphAtIndex: glyphIndex 
                         effectiveRange: NULL];
-  
+
   if ([self selectionAffinity] != NSSelectionAffinityUpstream)
     {
       /* Standard case - draw the insertion point just before the
         associated glyph index */
       NSPoint loc = [_layoutManager locationForGlyphAtIndex: glyphIndex];
       
-      rect.origin.x += loc.x;      
+      rect.origin.x += loc.x;
     }
   else /* _affinity == NSSelectionAffinityUpstream - non standard */
     {
@@ -1584,7 +1588,6 @@
     }  
 
   _insertionPointRect = rect;
-
   
   /* Remember horizontal position of insertion point */
   _originalInsertPoint = _insertionPointRect.origin.x;
@@ -2116,6 +2119,7 @@
      possible) */
 
   startPoint = [self convertPoint: [theEvent locationInWindow] fromView: nil];
+
   startIndex = [self characterIndexForPoint: startPoint];
 
   if ([_textStorage containsAttachments])

Reply via email to