Index: FL/Fl_Text_Display.H
===================================================================
--- FL/Fl_Text_Display.H	(revision 8140)
+++ FL/Fl_Text_Display.H	(working copy)
@@ -279,6 +279,17 @@
   int wrapped_column(int row, int column) const;
   int wrapped_row(int row) const;
   void wrap_mode(int wrap, int wrap_margin);
+
+  /**
+   Sets the width of the line number area.  Set to 0 to hide line numbers.
+   \param width The line number area width (pixels).
+  */
+  void linenumber_width( int width );
+
+  /**
+   Returns the width of the line number area in pixels.
+   */
+  int linenumber_width();
   
   virtual void resize(int X, int Y, int W, int H);
 
Index: src/Fl_PostScript.cxx
===================================================================
--- src/Fl_PostScript.cxx	(revision 8140)
+++ src/Fl_PostScript.cxx	(working copy)
@@ -1097,8 +1097,9 @@
 void Fl_PostScript_Graphics_Driver::rtl_draw(const char* str, int n, int x, int y) {
   const char *last = str + n;
   const char *str2 = str;
-  unsigned unis[n + 1];
-  char out[n + 1];
+  unsigned int *unis = new unsigned int[n + 1];
+  char *out = new char[n + 1];
+  
   int u = 0, len;
   char *p = out;
   double w = fl_width(str, n);
@@ -1111,6 +1112,9 @@
     p += len;
     }
   transformed_draw(out, p - out, x - w, y);
+
+  delete [] unis;
+  delete [] out;
 }
 
 struct matrix {double a, b, c, d, x, y;};
Index: src/Fl_Text_Display.cxx
===================================================================
--- src/Fl_Text_Display.cxx	(revision 8140)
+++ src/Fl_Text_Display.cxx	(working copy)
@@ -409,6 +409,13 @@
     }
   }
   
+  // apd: adjust text area render width for line number area
+  if (mLineNumWidth != 0)
+  {
+    text_area.x += mLineNumWidth;
+    text_area.w -= mLineNumWidth;
+  }
+
   // user request to change viewport
   if (mTopLineNumHint != mTopLineNum || mHorizOffsetHint != mHorizOffset)
     scroll_(mTopLineNumHint, mHorizOffsetHint);
@@ -467,9 +474,6 @@
   for ( line = firstLine; line <= lastLine; line++ )
     draw_vline( line, left, left + width, 0, INT_MAX );
   
-  /* draw the line numbers if exposed area includes them */
-  if (mLineNumWidth != 0 && left <= mLineNumLeft + mLineNumWidth)
-    draw_line_numbers(false);
   
   fl_pop_clip();
 }
@@ -708,7 +712,19 @@
 }
 
 
+void Fl_Text_Display::linenumber_width( int width )
+{
+  if (width < 0 || width > 150) return;
+  mLineNumWidth = width;
+  resize(x(), y(), w(), h());
+}
 
+int Fl_Text_Display::linenumber_width()
+{
+  return mLineNumWidth;
+}
+
+
 /**
  \brief Inserts "text" at the current cursor location.  
  
@@ -1513,7 +1529,10 @@
       //                ( origCursorPos <= endDispPos || endDispPos == buf->length() ) )
     }
     
-    if (linesInserted > 1) textD->draw_line_numbers(false);
+    if (linesInserted > 1) 	{
+		//apd: textD->draw_line_numbers(false); can't do this b/c not called from virtual draw();
+	//	textD->damage( ::FL_DAMAGE_EXPOSE );
+	}
   } else {
     endDispPos = buf->next_char(textD->mLastChar);
     // CET - FIXME   if ( origCursorPos >= pos )
@@ -1522,8 +1541,12 @@
      have changed. If only one line is altered, line numbers cannot
      be affected (the insertion or removal of a line break always 
      results in at least two lines being redrawn). */
-    textD->draw_line_numbers(false);
+
+	// apd:  see above
+    //textD->draw_line_numbers(false);
+	textD->damage( ::FL_DAMAGE_EXPOSE );
   }
+  
   IS_UTF8_ALIGNED2(buf, startDispPos)
   IS_UTF8_ALIGNED2(buf, endDispPos)
   
@@ -2620,8 +2643,6 @@
   textD->scroll(textD->mTopLineNum, b->value());
 }
 
-
-
 /**
  \brief Refresh the line number area.  
  
@@ -2631,7 +2652,62 @@
  
  This function is not used.
  */
-void Fl_Text_Display::draw_line_numbers(bool /*clearAll*/) {
+void Fl_Text_Display::draw_line_numbers(bool clearAlxl) {
+  int Y, line, visLine, nCols, lineStart;
+  char lineNumString[16];
+  int lineHeight = mMaxsize;
+  int charWidth = TMPFONTWIDTH;
+    
+  /* Don't draw if lineNumWidth == 0 (line numbers are hidden), or widget is
+     not yet realized */
+  if (mLineNumWidth == 0 || !visible_r())
+      return;
+  
+  /* Make sure we reset the clipping range for the line numbers GC, because
+     the GC may be shared (eg, if the line numbers and text have the same
+     color) and therefore the clipping ranges may be invalid. */
+  int xoff = Fl::box_dx(box());
+
+  ::fl_push_clip( 
+	  x()+xoff, 
+	  y()+Fl::box_dy(box()), 
+	  mLineNumWidth-xoff, 
+	  h()-Fl::box_dh(box()) - (mHScrollBar->visible()?mHScrollBar->h():0) );
+  
+  // Erase background
+  ::fl_color( 240,240,240 );
+  ::fl_rectf( x(), y(), mLineNumWidth, h() );
+  
+  // Draw separator line
+  //::fl_color( 180,180,180 );
+  //::fl_line(x()+mLineNumWidth-1, y(), x()+mLineNumWidth-1, y()+h());
+
+  // Draw text
+  ::fl_font(textfont(), textsize());
+
+  /* Draw the line numbers, aligned to the text */
+  nCols = mLineNumWidth / charWidth - 1;
+  Y = y();
+  line = get_absolute_top_line_number();
+  
+  int last_y = y();
+  ::fl_color( 110,110,110 );
+  for (visLine=0; visLine < mNVisibleLines; visLine++) {
+    lineStart = mLineStarts[visLine];
+    if (lineStart != -1 && (lineStart==0 || buffer()->char_at(lineStart-1)=='\n')) {
+      //int lineNumStringLen = sprintf(lineNumString, "%*d", nCols, line);
+	  int lineNumStringLen = sprintf(lineNumString, "%d", line);
+      ::fl_draw( lineNumString, lineNumStringLen, x()+xoff+LEFT_MARGIN+1, (Y + mMaxsize));
+	  last_y = Y;
+      line++;
+    } else {
+      if (visLine == 0)
+        line++;
+    }
+    Y += lineHeight;
+  }
+  
+  fl_pop_clip();
 #if 0
   int y, line, visLine, nCols, lineStart;
   char lineNumString[12];
@@ -3355,9 +3431,9 @@
   if (!buffer()) { draw_box(); return; }
   
   fl_push_clip(x(),y(),w(),h());	// prevent drawing outside widget area
-  
+ 
   // draw the non-text, non-scrollbar areas.
-  if (damage() & FL_DAMAGE_ALL) {
+  if (damage() & FL_DAMAGE_ALL) { 
     //    printf("drawing all (box = %d)\n", box());
     // draw the box()
     int W = w(), H = h();
@@ -3429,6 +3505,10 @@
       // Draw the whole area...
       draw_text(text_area.x, text_area.y, text_area.w, text_area.h);
     }
+
+	// draw the line numbers
+	draw_line_numbers(true);
+	
   }
   else if (damage() & FL_DAMAGE_SCROLL) {
     // draw some lines of text
Index: test/editor.cxx
===================================================================
--- test/editor.cxx	(revision 8140)
+++ test/editor.cxx	(working copy)
@@ -777,6 +777,7 @@
     w->editor->textfont(FL_COURIER);
     w->editor->textsize(TS);
   //w->editor->wrap_mode(Fl_Text_Editor::WRAP_AT_BOUNDS, 250);
+	w->editor->linenumber_width(50);
     w->editor->buffer(textbuf);
     w->editor->highlight_data(stylebuf, styletable,
                               sizeof(styletable) / sizeof(styletable[0]),
