2 using System.Collections.Generic;
5 namespace FooEditEngine.Windows
7 class PrintableTextLayout : ITextLayout
9 List<String> lines = new List<string>();
12 public PrintableTextLayout(Font font, Graphics g, StringFormat sf, double maxwidth,String str)
14 this.Disposed = false;
17 this.Height = font.Height;
19 if (maxwidth == LineToIndexTable.NONE_BREAK_LINE)
25 int fitlen, index = 0;
29 SizeF metrics = g.MeasureString(str.Substring(index), font, new SizeF((float)maxwidth, font.Height + 1), sf, out fitlen, out linesFilled);
30 if (metrics.Width > Width)
31 this.Width = metrics.Width;
32 this.Height += metrics.Height;
33 lines.Add(str.Substring(index, fitlen));
35 } while (index < str.Length);
60 public int GetIndexFromColPostion(double x)
65 public double GetWidthFromIndex(int index)
70 public double GetColPostionFromIndex(int index)
75 public int AlignIndexToNearestCluster(int index, AlignDirection flow)
85 public int GetIndexFromPostion(double x, double y)
87 throw new NotImplementedException();
90 public Point GetPostionFromIndex(int index)
92 throw new NotImplementedException();
95 public void Draw(Graphics g,double x, double y,System.Drawing.Color fore)
98 foreach(string line in this.lines)
100 g.DrawString(line, this.font, new SolidBrush(fore), new PointF((float)x, (float)posy), this.sf);
101 var size = g.MeasureString(line,this.font);
106 class PrintableTextRender : IPrintableTextRender
112 public PrintableTextRender(Font font, Graphics g)
115 this.sf = StringFormat.GenericTypographic;
116 this.sf.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
119 #pragma warning disable 0067
120 public event ChangedRenderResourceEventHandler ChangedRenderResource;
121 public event EventHandler ChangedRightToLeft;
122 #pragma warning restore 0067
124 public void BeginDraw(Graphics g)
128 this.sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
131 public void EndDraw()
135 public ITextLayout CreateLaytout(string str)
137 return new PrintableTextLayout(this.font,this.g,this.sf,(float)LineToIndexTable.NONE_BREAK_LINE ,str);
140 public float HeaderHeight { get { return this.font.Height; } }
142 public float FooterHeight { get { return this.font.Height; } }
144 const int LineNumberFiledLength = 6;
146 public double LineNemberWidth
150 int length = LineNumberFiledLength;
152 SizeF metrics = g.MeasureString("0", this.font, Int16.MaxValue, this.sf);
153 return metrics.Width * length;
157 public double FoldingWidth
165 public bool RightToLeft
171 public bool InsertMode
177 public Rectangle TextArea
187 SizeF metrics = g.MeasureString("0", this.font, Int16.MaxValue, this.sf);
188 return new Size(metrics.Width, metrics.Height);
192 public void DrawCachedBitmap(Rectangle rect)
196 public void CacheContent()
200 public bool IsVaildCache()
205 public void DrawLine(Point from, Point to)
209 public void DrawString(string str, double x, double y)
211 g.DrawString(str, this.font, new SolidBrush(this.Foreground), new PointF((float)x, (float)y), this.sf);
214 public void DrawCaret(Rectangle rect, bool transparent)
218 public void DrawFoldingMark(bool expand, double x, double y)
222 public void DrawString(string str, double x, double y, StringAlignment align, Size layoutRect,StringColorType colorType = StringColorType.Forground)
224 System.Drawing.StringAlignment old = this.sf.Alignment;
226 this.sf.Alignment = System.Drawing.StringAlignment.Center;
228 g.DrawString(str, this.font, new SolidBrush(this.Foreground), new RectangleF((float)x, (float)y, (float)layoutRect.Width, (float)layoutRect.Height), this.sf);
230 this.sf.Alignment = old;
233 public void DrawOneLine(Document doc,LineToIndexTable lti, int row, double x, double y)
235 PrintableTextLayout layout = (PrintableTextLayout)lti.GetLayout(row);
236 layout.Draw(g, x, y, this.Foreground);
239 public void BeginClipRect(Rectangle rect)
241 g.Clip = new Region(rect);
244 public void EndClipRect()
246 g.Clip = new Region();
249 public void FillRectangle(Rectangle rect, FillRectType type)
253 public void FillBackground(Rectangle rect)
257 public void DrawGripper(Point p, double radius)
259 //タッチには対応していないので実装する必要はない
260 throw new NotImplementedException();
263 public ITextLayout CreateLaytout(string str, SyntaxInfo[] syntaxCollection, IEnumerable<Marker> MarkerRanges, IEnumerable<Selection> Selections, double WrapWidth)
265 return new PrintableTextLayout(this.font, this.g, this.sf, WrapWidth, str);
268 public System.Drawing.Color Foreground
274 public int TabWidthChar
278 float[] tabstops = this.sf.GetTabStops(out taboffset);
279 if (tabstops.Length == 0)
281 return (int)tabstops[0];
283 set { this.sf.SetTabStops(0,new float[]{value});}
286 public bool ShowFullSpace
292 public bool ShowHalfSpace
304 public bool ShowLineBreak