2 * Copyright (C) 2013 FooProject
\r
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
\r
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
\r
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
\r
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/>.
\r
13 namespace FooEditEngine
\r
15 sealed class PrintableView : ViewBase
\r
17 public PrintableView(Document doc, IPrintableTextRender r, Padding margin)
\r
18 : base (doc,r,margin)
\r
22 public string Header
\r
28 public string Footer
\r
34 public override void Draw(Rectangle updateRect)
\r
36 if (this.LayoutLines.Count == 0)
\r
39 if (this.Hilighter != null)
\r
40 this.Hilighter.Reset();
\r
42 Point pos = this.render.TextArea.TopLeft;
\r
45 int endRow = Math.Min(this.LayoutLines.Count - 1, Src.Row + this.LineCountOnScreen - 1);
\r
47 Size lineNumberSize = new Size(this.render.LineNemberWidth, this.render.TextArea.Height);
\r
49 IPrintableTextRender render = (IPrintableTextRender)this.render;
\r
52 if (this.Header != null && this.Header != string.Empty)
\r
54 this.render.DrawString(this.Header, pos.X, pos.Y, StringAlignment.Center,
\r
55 new Size(render.TextArea.Width - this.GetRealtiveX(AreaType.TextArea),render.FooterHeight));
\r
57 pos.Y += (int)render.HeaderHeight;
\r
61 for (int i = Src.Row; i <= endRow; i++)
\r
63 double lineHeight = this.LayoutLines.GetLayout(i).Height;
\r
65 this.render.DrawOneLine(this.LayoutLines,i, pos.X + this.render.TextArea.X, pos.Y, null);
\r
67 if (this.DrawLineNumber)
\r
68 this.render.DrawString((i + 1).ToString(), this.PageBound.X + this.GetRealtiveX(AreaType.LineNumberArea), pos.Y, StringAlignment.Right, lineNumberSize);
\r
70 pos.Y += lineHeight;
\r
74 if (this.Footer != null && this.Footer != string.Empty)
\r
76 pos.Y = render.TextArea.Bottom;
\r
77 this.render.DrawString(this.Footer, pos.X, pos.Y, StringAlignment.Center,
\r
78 new Size(render.TextArea.Width - this.GetRealtiveX(AreaType.TextArea), render.FooterHeight));
\r
82 public bool TryPageDown()
\r
84 return base.TryScroll(this.Src.X, this.Src.Row + this.LineCountOnScreen);
\r
87 protected override void CalculateClipRect()
\r
89 double x, y, width, height;
\r
91 if (this.DrawLineNumber)
\r
93 if (this.render.RightToLeft)
\r
94 x = this.Padding.Left;
\r
96 x = this.render.LineNemberWidth + this.render.emSize.Width + this.Padding.Left + this.LineNumberMargin;
\r
97 width = this.PageBound.Width - this.render.LineNemberWidth - this.render.emSize.Width - this.Padding.Right - this.Padding.Left - this.LineNumberMargin;
\r
101 x = this.Padding.Left;
\r
102 width = this.PageBound.Width - this.Padding.Right - this.Padding.Left;
\r
105 y = this.Padding.Top;
\r
106 height = this.PageBound.Height - this.Padding.Bottom - this.Padding.Top;
\r
114 IPrintableTextRender render = (IPrintableTextRender)this.render;
\r
116 if (this.Footer != null && this.Footer != string.Empty)
\r
117 height -= render.FooterHeight;
\r
118 if (this.Header != null && this.Header != string.Empty)
\r
119 height -= render.HeaderHeight;
\r
121 this.render.TextArea = new Rectangle(x, y, width, height);
\r
124 public override void CalculateLineCountOnScreen()
\r
126 if (this.LayoutLines.Count == 0)
\r
130 int i = this.Src.Row;
\r
133 int row = i < this.LayoutLines.Count ? i : this.LayoutLines.Count - 1;
\r
135 ITextLayout layout = this.LayoutLines.GetLayout(row);
\r
137 double lineHeight = layout.Height;
\r
141 if (y >= this.render.TextArea.Height)
\r
144 this.LineCountOnScreen = Math.Max(i - this.Src.Row - 1, 0); //ループを抜けると+1されている
\r
153 double GetRealtiveX(AreaType type)
\r
157 case AreaType.LineNumberArea:
\r
158 if (this.DrawLineNumber == false)
\r
159 throw new InvalidOperationException();
\r
160 if (this.render.RightToLeft)
\r
161 return this.PageBound.TopRight.X - this.render.LineNemberWidth;
\r
163 return this.render.TextArea.X - this.render.LineNemberWidth - this.render.emSize.Width - this.LineNumberMargin;
\r
164 case AreaType.TextArea:
\r
165 return this.render.TextArea.X;
\r
167 throw new ArgumentOutOfRangeException();
\r