2 * Copyright (C) 2013 FooProject
3 * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
13 namespace FooEditEngine
15 sealed class PrintableView : ViewBase
17 public PrintableView(Document doc, IPrintableTextRender r, Padding margin)
34 public override void Draw(Rectangle updateRect, bool force = false)
36 if (this.LayoutLines.Count == 0)
39 if (this.Hilighter != null)
40 this.Hilighter.Reset();
42 Point pos = this.render.TextArea.TopLeft;
45 int endRow = Math.Min(this.LayoutLines.Count - 1, Src.Row + this.LineCountOnScreen - 1);
47 Size lineNumberSize = new Size(this.render.LineNemberWidth, this.render.TextArea.Height);
49 IPrintableTextRender render = (IPrintableTextRender)this.render;
52 if (this.Header != null && this.Header != string.Empty)
54 this.render.DrawString(this.Header, pos.X, pos.Y, StringAlignment.Center,
55 new Size(render.TextArea.Width - this.GetRealtiveX(AreaType.TextArea),render.FooterHeight));
57 pos.Y += (int)render.HeaderHeight;
61 for (int i = Src.Row; i <= endRow; i++)
63 double lineHeight = this.LayoutLines.GetLayout(i).Height;
65 this.render.DrawOneLine(this.Document, this.LayoutLines,i, pos.X + this.render.TextArea.X, pos.Y);
67 if (this.Document.DrawLineNumber)
68 this.render.DrawString((i + 1).ToString(), this.PageBound.X + this.GetRealtiveX(AreaType.LineNumberArea), pos.Y, StringAlignment.Right, lineNumberSize);
74 if (this.Footer != null && this.Footer != string.Empty)
76 pos.Y = render.TextArea.Bottom;
77 this.render.DrawString(this.Footer, pos.X, pos.Y, StringAlignment.Center,
78 new Size(render.TextArea.Width - this.GetRealtiveX(AreaType.TextArea), render.FooterHeight));
84 public bool TryPageDown()
86 return base.TryScroll(this.Src.X, this.Src.Row + this.LineCountOnScreen);
89 protected override void CalculateClipRect()
91 double x, y, width, height;
93 if (this.Document.DrawLineNumber)
95 if (this.render.RightToLeft)
96 x = this.Padding.Left;
98 x = this.render.LineNemberWidth + this.render.emSize.Width + this.Padding.Left + this.LineNumberMargin;
99 width = this.PageBound.Width - this.render.LineNemberWidth - this.render.emSize.Width - this.Padding.Right - this.Padding.Left - this.LineNumberMargin;
103 x = this.Padding.Left;
104 width = this.PageBound.Width - this.Padding.Right - this.Padding.Left;
107 y = this.Padding.Top;
108 height = this.PageBound.Height - this.Padding.Bottom - this.Padding.Top;
116 IPrintableTextRender render = (IPrintableTextRender)this.render;
118 if (this.Footer != null && this.Footer != string.Empty)
119 height -= render.FooterHeight;
120 if (this.Header != null && this.Header != string.Empty)
121 height -= render.HeaderHeight;
123 this.render.TextArea = new Rectangle(x, y, width, height);
126 public override void CalculateLineCountOnScreen()
128 if (this.LayoutLines.Count == 0)
132 int i = this.Src.Row;
135 int row = i < this.LayoutLines.Count ? i : this.LayoutLines.Count - 1;
137 ITextLayout layout = this.LayoutLines.GetLayout(row);
139 double lineHeight = layout.Height;
143 if (y >= this.render.TextArea.Height)
146 this.LineCountOnScreen = Math.Max(i - this.Src.Row - 1, 0); //ループを抜けると+1されている
155 double GetRealtiveX(AreaType type)
159 case AreaType.LineNumberArea:
160 if (this.Document.DrawLineNumber == false)
161 throw new InvalidOperationException();
162 if (this.render.RightToLeft)
163 return this.PageBound.TopRight.X - this.render.LineNemberWidth;
165 return this.render.TextArea.X - this.render.LineNemberWidth - this.render.emSize.Width - this.LineNumberMargin;
166 case AreaType.TextArea:
167 return this.render.TextArea.X;
169 throw new ArgumentOutOfRangeException();