OSDN Git Service

読み込み時に行分割を行わず、レタリング時に行分割を行うようにした
[fooeditengine/FooEditEngine.git] / Windows / FooEditEngine / PrintableTextRender.cs
index 69706ae..72281c1 100644 (file)
@@ -6,14 +6,38 @@ namespace FooEditEngine.Windows
 {
     class PrintableTextLayout : ITextLayout
     {
-        public PrintableTextLayout(Font font)
+        List<String> lines = new List<string>();
+        Font font;
+        StringFormat sf;
+        public PrintableTextLayout(Font font, Graphics g, StringFormat sf, double maxwidth,String str)
         {
             this.Disposed = false;
+            this.sf = sf;
+            this.font = font;
             this.Height = font.Height;
+
+            if (maxwidth == LineToIndexTable.NONE_BREAK_LINE)
+            {
+                lines.Add(str);
+                return;
+            }
+
+            int fitlen, index = 0;
+            do
+            {
+                int linesFilled;
+                SizeF metrics = g.MeasureString(str.Substring(index), font, new SizeF((float)maxwidth, font.Height + 1), sf, out fitlen, out linesFilled);
+                if (metrics.Width > Width)
+                    this.Width = metrics.Width;
+                this.Height += metrics.Height;
+                lines.Add(str.Substring(index, fitlen));
+                index += fitlen;
+            } while (index < str.Length);
         }
         public double Width
         {
-            get { return 0; }
+            get;
+            private set;
         }
 
         public double Height
@@ -57,6 +81,27 @@ namespace FooEditEngine.Windows
         {
             this.Disposed = true;
         }
+
+        public int GetIndexFromPostion(double x, double y)
+        {
+            throw new NotImplementedException();
+        }
+
+        public Point GetPostionFromIndex(int index)
+        {
+            throw new NotImplementedException();
+        }
+
+        public void Draw(Graphics g,double x, double y,System.Drawing.Color fore)
+        {
+            double posy = y;
+            foreach(string line in this.lines)
+            {
+                g.DrawString(line, this.font, new SolidBrush(fore), new PointF((float)x, (float)posy), this.sf);
+                var size = g.MeasureString(line,this.font);
+                posy += size.Height;
+            }
+        }
     }
     class PrintableTextRender : IPrintableTextRender
     {
@@ -89,7 +134,7 @@ namespace FooEditEngine.Windows
 
         public ITextLayout CreateLaytout(string str)
         {
-            return new PrintableTextLayout(this.font);
+            return new PrintableTextLayout(this.font,this.g,this.sf,(float)LineToIndexTable.NONE_BREAK_LINE ,str);
         }
 
         public float HeaderHeight { get { return this.font.Height; } }
@@ -139,7 +184,8 @@ namespace FooEditEngine.Windows
         {
             get
             {
-                return new Size(0, 0);
+                SizeF metrics = g.MeasureString("0", this.font, Int16.MaxValue, this.sf);
+                return new Size(metrics.Width, metrics.Height);
             }
         }
 
@@ -185,16 +231,19 @@ namespace FooEditEngine.Windows
         }
 
         public void DrawOneLine(Document doc,LineToIndexTable lti, int row, double x, double y)
-        {           
-            g.DrawString(lti[row], this.font, new SolidBrush(this.Foreground), new RectangleF((float)x, (float)y, (float)this.TextArea.Width, (float)this.TextArea.Height), this.sf);
+        {
+            PrintableTextLayout layout = (PrintableTextLayout)lti.GetLayout(row);
+            layout.Draw(g, x, y, this.Foreground);
         }
 
         public void BeginClipRect(Rectangle rect)
         {
+            g.Clip = new Region(rect);
         }
 
         public void EndClipRect()
         {
+            g.Clip = new Region();
         }
 
         public void FillRectangle(Rectangle rect, FillRectType type)
@@ -205,11 +254,6 @@ namespace FooEditEngine.Windows
         {
         }
 
-        public ITextLayout CreateLaytout(string str, SyntaxInfo[] syntaxCollection, IEnumerable<Marker> MarkerRanges, IEnumerable<Selection> Selections)
-        {
-            return new PrintableTextLayout(this.font);
-        }
-
         public List<LineToIndexTableData> BreakLine(Document doc, LineToIndexTable layoutLineCollection, int startIndex, int endIndex, double maxwidth)
         {
             List<LineToIndexTableData> output = new List<LineToIndexTableData>();
@@ -253,6 +297,11 @@ namespace FooEditEngine.Windows
             throw new NotImplementedException();
         }
 
+        public ITextLayout CreateLaytout(string str, SyntaxInfo[] syntaxCollection, IEnumerable<Marker> MarkerRanges, IEnumerable<Selection> Selections, double WrapWidth)
+        {
+            return new PrintableTextLayout(this.font, this.g, this.sf, WrapWidth, str);
+        }
+
         public System.Drawing.Color Foreground
         {
             get;