{
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
{
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
{
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; } }
{
get
{
- return new Size(0, 0);
+ SizeF metrics = g.MeasureString("0", this.font, Int16.MaxValue, this.sf);
+ return new Size(metrics.Width, metrics.Height);
}
}
}
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)
{
}
- 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>();
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;