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;
46 IPrintableTextRender render = (IPrintableTextRender)this.render;
49 if (this.Header != null && this.Header != string.Empty)
51 this.render.DrawString(this.Header, pos.X, pos.Y, StringAlignment.Center,
52 new Size(render.TextArea.Width - this.GetRealtiveX(AreaType.TextArea), render.FooterHeight));
53 pos.Y += (int)render.HeaderHeight;
57 Rectangle contentArea = new Rectangle(pos.X, pos.Y, this.PageBound.Width, this.render.TextArea.Height);
58 this.render.BeginClipRect(contentArea);
60 Size lineNumberSize = new Size(this.render.LineNemberWidth, this.render.TextArea.Height);
61 for (int i = Src.Row; pos.Y <= this.render.TextArea.Bottom; i++)
63 if (i >= this.LayoutLines.Count)
66 double layoutHeight = this.LayoutLines.GetLayout(i).Height;
68 this.render.DrawOneLine(this.Document, this.LayoutLines, i, pos.X + this.render.TextArea.X, pos.Y + this.Src.OffsetY);
69 if (this.Document.DrawLineNumber)
70 this.render.DrawString((i + 1).ToString(), this.PageBound.X + this.GetRealtiveX(AreaType.LineNumberArea), pos.Y + this.Src.OffsetY, StringAlignment.Right, lineNumberSize);
72 pos.Y += layoutHeight;
76 this.render.EndClipRect();
79 if (this.Footer != null && this.Footer != string.Empty)
81 pos.Y = render.TextArea.Bottom;
82 this.render.DrawString(this.Footer, pos.X, pos.Y, StringAlignment.Center,
83 new Size(render.TextArea.Width - this.GetRealtiveX(AreaType.TextArea), render.FooterHeight));
89 public bool TryPageDown()
91 double alignedPage = (int)(this.render.TextArea.Height / this.render.emSize.Height) * this.render.emSize.Height;
92 return base.TryScroll(this.Src.X, alignedPage);
95 protected override void CalculateClipRect()
97 double x, y, width, height;
99 if (this.Document.DrawLineNumber)
101 if (this.render.RightToLeft)
102 x = this.Padding.Left;
104 x = this.render.LineNemberWidth + this.render.emSize.Width + this.Padding.Left + this.LineNumberMargin;
105 width = this.PageBound.Width - this.render.LineNemberWidth - this.render.emSize.Width - this.Padding.Right - this.Padding.Left - this.LineNumberMargin;
109 x = this.Padding.Left;
110 width = this.PageBound.Width - this.Padding.Right - this.Padding.Left;
113 y = this.Padding.Top;
114 height = this.PageBound.Height - this.Padding.Bottom - this.Padding.Top;
122 IPrintableTextRender render = (IPrintableTextRender)this.render;
124 if (this.Footer != null && this.Footer != string.Empty)
125 height -= render.FooterHeight;
126 if (this.Header != null && this.Header != string.Empty)
127 height -= render.HeaderHeight;
129 this.render.TextArea = new Rectangle(x, y, width, height);
132 public override void CalculateLineCountOnScreen()
142 double GetRealtiveX(AreaType type)
146 case AreaType.LineNumberArea:
147 if (this.Document.DrawLineNumber == false)
148 throw new InvalidOperationException();
149 if (this.render.RightToLeft)
150 return this.PageBound.TopRight.X - this.render.LineNemberWidth;
152 return this.render.TextArea.X - this.render.LineNemberWidth - this.render.emSize.Width - this.LineNumberMargin;
153 case AreaType.TextArea:
154 return this.render.TextArea.X;
156 throw new ArgumentOutOfRangeException();