/// <returns>逆転しているなら真を返す</returns>
public bool IsReverseSelect()
{
- int index = this.View.LayoutLines.GetIndexFromTextPoint(this.View.CaretPostion);
+ int index = this.View.LayoutLines.GetIndexFromTextPoint(this.Document.CaretPostion);
return index < this.AnchorIndex;
}
/// </summary>
public void AdjustCaret()
{
- int row = this.View.CaretPostion.row;
+ int row = this.Document.CaretPostion.row;
if (row > this.View.LayoutLines.Count - 1)
row = this.View.LayoutLines.Count - 1;
- int col = this.View.CaretPostion.col;
+ int col = this.Document.CaretPostion.col;
if (col > 0 && col > this.View.LayoutLines[row].Length)
col = this.View.LayoutLines[row].Length;
this.JumpCaret(row, col);
void AlignNearestWord(bool MoveFlow)
{
- string str = this.View.LayoutLines[this.View.CaretPostion.row];
- while (this.View.CaretPostion.col > 0 &&
- this.View.CaretPostion.col < str.Length &&
- str[this.View.CaretPostion.col] != Document.NewLine)
+ string str = this.View.LayoutLines[this.Document.CaretPostion.row];
+ while (this.Document.CaretPostion.col > 0 &&
+ this.Document.CaretPostion.col < str.Length &&
+ str[this.Document.CaretPostion.col] != Document.NewLine)
{
- if (!Util.IsWordSeparator(str[this.View.CaretPostion.col]))
+ if (!Util.IsWordSeparator(str[this.Document.CaretPostion.col]))
{
this.MoveCaretHorizontical(MoveFlow);
}
if (this.Document.FireUpdateEvent == false)
throw new InvalidOperationException("");
- TextPoint CaretPostion = this.View.CaretPostion;
+ TextPoint CaretPostion = this.Document.CaretPostion;
int index = this.View.GetIndexFromLayoutLine(CaretPostion);
if (index == this.Document.Length)
if (this.Document.FireUpdateEvent == false)
throw new InvalidOperationException("");
- TextPoint CurrentPostion = this.View.CaretPostion;
+ TextPoint CurrentPostion = this.Document.CaretPostion;
if (CurrentPostion.row == 0 && CurrentPostion.col == 0)
return;
string GetIndentSpace(int col_index)
{
- int space_count = this.View.TabStops - (col_index % this.View.TabStops);
+ int space_count = this.Document.TabStops - (col_index % this.Document.TabStops);
return new string(Enumerable.Repeat(' ',space_count).ToArray());
}
/// <param name="fromTip"></param>
public void DoInputString(string str,bool fromTip = false)
{
- TextPoint CaretPos = this.View.CaretPostion;
+ TextPoint CaretPos = this.Document.CaretPostion;
if (str == "\t" && this.IndentMode == IndentMode.Space)
str = this.GetIndentSpace(CaretPos.col);
if (this.Document.FireUpdateEvent == false)
throw new InvalidOperationException("");
- int index = this.View.GetIndexFromLayoutLine(this.View.CaretPostion);
+ int index = this.View.GetIndexFromLayoutLine(this.Document.CaretPostion);
int length = 0;
if (this.View.InsertMode == false && index < this.Document.Length && this.Document[index] != Document.NewLine)
{
/// </remarks>
void SelectWithMoveCaret(bool isSelected)
{
- if (this.View.CaretPostion.col < 0 || this.View.CaretPostion.row < 0)
+ if (this.Document.CaretPostion.col < 0 || this.Document.CaretPostion.row < 0)
return;
if (this.Document.FireUpdateEvent == false)
throw new InvalidOperationException("");
- int CaretPostion = this.View.GetIndexFromLayoutLine(this.View.CaretPostion);
+ int CaretPostion = this.View.GetIndexFromLayoutLine(this.Document.CaretPostion);
SelectCollection Selections = this.View.Selections;
if (isSelected)
{
bool HittedCaret = false;
TextPoint tp = this.View.GetTextPointFromPostion(p);
- if (tp == this.View.CaretPostion)
+ if (tp == this.Document.CaretPostion)
{
HittedCaret = true;
}
if (this.Document.FireUpdateEvent == false)
throw new InvalidOperationException("");
int delta = isMoveNext ? 0 : -1;
- int prevcol = this.View.CaretPostion.col;
- int col = this.View.CaretPostion.col + delta;
- string lineString = this.View.LayoutLines[this.View.CaretPostion.row];
- if (col < 0 || this.View.CaretPostion.row >= this.View.LayoutLines.Count)
+ int prevcol = this.Document.CaretPostion.col;
+ int col = this.Document.CaretPostion.col + delta;
+ string lineString = this.View.LayoutLines[this.Document.CaretPostion.row];
+ if (col < 0 || this.Document.CaretPostion.row >= this.View.LayoutLines.Count)
{
- if (this.View.CaretPostion.row == 0)
+ if (this.Document.CaretPostion.row == 0)
{
col = 0;
return;
}
this.MoveCaretVertical(false);
this.View.AdjustCaretAndSrc(AdjustFlow.Row); //この段階で調整しないとスクロールされない
- col = this.View.LayoutLines.GetLengthFromLineNumber(this.View.CaretPostion.row) - 1; //最終行以外はすべて改行コードが付くはず
+ col = this.View.LayoutLines.GetLengthFromLineNumber(this.Document.CaretPostion.row) - 1; //最終行以外はすべて改行コードが付くはず
}
else if (col >= lineString.Length || lineString[col] == Document.NewLine)
{
- if (this.View.CaretPostion.row < this.View.LayoutLines.Count - 1)
+ if (this.Document.CaretPostion.row < this.View.LayoutLines.Count - 1)
{
this.MoveCaretVertical(true);
this.View.AdjustCaretAndSrc(AdjustFlow.Row); //この段階で調整しないとスクロールされない
else
{
AlignDirection direction = isMoveNext ? AlignDirection.Forward : AlignDirection.Back;
- col = this.View.LayoutLines.GetLayout(this.View.CaretPostion.row).AlignIndexToNearestCluster(col, direction);
+ col = this.View.LayoutLines.GetLayout(this.Document.CaretPostion.row).AlignIndexToNearestCluster(col, direction);
}
- this.View.JumpCaret(this.View.CaretPostion.row, col,false);
+ this.View.JumpCaret(this.Document.CaretPostion.row, col,false);
}
/// <summary>
if (this.Document.FireUpdateEvent == false)
throw new InvalidOperationException("");
- TextPoint nextPoint = this.GetTextPointAfterMoveLine(isMoveNext ? 1 : -1, this.View.CaretPostion);
+ TextPoint nextPoint = this.GetTextPointAfterMoveLine(isMoveNext ? 1 : -1, this.Document.CaretPostion);
this.View.JumpCaret(nextPoint.row, nextPoint.col,false);
}
void View_PageBoundChanged(object sender, EventArgs e)
{
- if (this.View.LineBreak == LineBreakMethod.PageBound && this.View.PageBound.Width - this.View.LineBreakingMarginWidth > 0)
+ if (this.Document.LineBreak == LineBreakMethod.PageBound && this.View.PageBound.Width - this.View.LineBreakingMarginWidth > 0)
this.View.PerfomLayouts();
this.AdjustCaret();
}
{
if (e.type == ResourceType.Font)
{
- if (this.View.LineBreak == LineBreakMethod.PageBound)
+ if (this.Document.LineBreak == LineBreakMethod.PageBound)
this.View.PerfomLayouts();
this.AdjustCaret();
}
}
/// <summary>
- /// ルーラーを表示しないなら真、そうでないなら偽
- /// </summary>
- public bool HideRuler
- {
- get { return this.Document.HideRuler; }
- set
- {
- this.Document.HideRuler = value;
- }
- }
-
- /// <summary>
/// キャレットがある領域を示す
/// </summary>
public Point CaretLocation
}
/// <summary>
- /// レイアウト行のどこにキャレットがあるかを表す
- /// </summary>
- public TextPoint CaretPostion
- {
- get { return this.Document.CaretPostion; }
- private set { this.Document.CaretPostion = value; }
- }
-
- /// <summary>
/// ヒットテストを行う
/// </summary>
/// <param name="x">x座標</param>
Rectangle background = this.PageBound;
render.FillBackground(background);
- if (this.HideRuler == false)
+ if (this.Document.HideRuler == false)
this.DrawRuler();
- this.DrawLineMarker(this.CaretPostion.row);
+ this.DrawLineMarker(this.Document.CaretPostion.row);
Point pos = this.render.TextArea.TopLeft;
pos.X -= this.Src.X;
this.render.DrawOneLine(this.LayoutLines, i, pos.X, pos.Y, selectRange);
- if (this.DrawLineNumber)
+ if (this.Document.DrawLineNumber)
{
this.render.DrawString((i + 1).ToString(), this.PageBound.X + this.GetRealtiveX(AreaType.LineNumberArea), pos.Y, StringAlignment.Right, lineNumberSize,StringColorType.LineNumber);
}
IEditorRender render = (IEditorRender)base.render;
- int row = this.CaretPostion.row;
+ int row = this.Document.CaretPostion.row;
double lineHeight = this.LayoutLines.GetLayout(row).Height;
- double charWidth = this.LayoutLines.GetLayout(row).GetWidthFromIndex(this.CaretPostion.col);
+ double charWidth = this.LayoutLines.GetLayout(row).GetWidthFromIndex(this.Document.CaretPostion.col);
if (this.InsertMode || charWidth == 0)
{
return;
IEditorRender render = (IEditorRender)base.render;
Point p = this.CaretLocation;
- double height = this.LayoutLines.GetLayout(this.CaretPostion.row).Height;
+ double height = this.LayoutLines.GetLayout(this.Document.CaretPostion.row).Height;
double width = this.render.TextArea.Width;
render.FillRectangle(new Rectangle(this.PageBound.X + this.render.TextArea.X, this.CaretLocation.Y, width, height), FillRectType.LineMarker);
}
}
}
- this.CaretPostion = new TextPoint(row, col);
+ this.Document.CaretPostion = new TextPoint(row, col);
}
/// <summary>
}
bool result = false;
- TextPoint tp = this.CaretPostion;
+ TextPoint tp = this.Document.CaretPostion;
double x = this.CaretLocation.X;
double y = this.CaretLocation.Y;
IEditorRender render = (IEditorRender)base.render;
double x, y, width, height;
- if (this.DrawLineNumber)
+ if (this.Document.DrawLineNumber)
{
if (this.Document.RightToLeft)
x = this.Padding.Left;
y = this.Padding.Top;
height = this.PageBound.Height - this.Padding.Top - this.Padding.Bottom;
- if (this.HideRuler == false)
+ if (this.Document.HideRuler == false)
{
double rulerHeight = this.render.emSize.Height + LineMarkerThickness;
y += rulerHeight;
case AreaType.UpdateArea:
if (this.Document.RightToLeft)
return this.PageBound.TopRight.X - UpdateAreaTotalWidth;
- if (this.DrawLineNumber)
+ if (this.Document.DrawLineNumber)
return this.render.TextArea.X - this.render.LineNemberWidth - this.LineNumberMargin - render.FoldingWidth - UpdateAreaTotalWidth;
else
return this.render.TextArea.X - render.FoldingWidth - UpdateAreaTotalWidth;
case AreaType.FoldingArea:
if (this.Document.RightToLeft)
return this.PageBound.TopRight.X - render.FoldingWidth;
- if (this.DrawLineNumber)
+ if (this.Document.DrawLineNumber)
return this.render.TextArea.X - this.render.LineNemberWidth - this.LineNumberMargin - render.FoldingWidth;
else
return this.render.TextArea.X - render.FoldingWidth;
case AreaType.LineNumberArea:
- if (this.DrawLineNumber == false)
+ if (this.Document.DrawLineNumber == false)
throw new InvalidOperationException();
if (this.Document.RightToLeft)
return this.PageBound.TopRight.X - UpdateAreaTotalWidth - render.FoldingWidth - this.render.LineNemberWidth;
this.render.DrawOneLine(this.LayoutLines,i, pos.X + this.render.TextArea.X, pos.Y, null);
- if (this.DrawLineNumber)
+ if (this.Document.DrawLineNumber)
this.render.DrawString((i + 1).ToString(), this.PageBound.X + this.GetRealtiveX(AreaType.LineNumberArea), pos.Y, StringAlignment.Right, lineNumberSize);
pos.Y += lineHeight;
{
double x, y, width, height;
- if (this.DrawLineNumber)
+ if (this.Document.DrawLineNumber)
{
if (this.render.RightToLeft)
x = this.Padding.Left;
switch (type)
{
case AreaType.LineNumberArea:
- if (this.DrawLineNumber == false)
+ if (this.Document.DrawLineNumber == false)
throw new InvalidOperationException();
if (this.render.RightToLeft)
return this.PageBound.TopRight.X - this.render.LineNemberWidth;
public event EventHandler PageBoundChanged;
/// <summary>
- /// マーカーパターンセット
- /// </summary>
- public MarkerPatternSet MarkerPatternSet
- {
- get { return this.Document.MarkerPatternSet; }
- }
-
- /// <summary>
- /// URLをハイパーリンクとして表示するなら真。そうでないなら偽
- /// </summary>
- public bool UrlMark
- {
- get { return this.Document.UrlMark; }
- set
- {
- this.Document.UrlMark = value;
- }
- }
-
- /// <summary>
/// テキストレンダラ―
/// </summary>
public ITextRender render
get { return this._LongestWidth; }
}
- /// <summary>
- /// 桁折り処理の方法を指定する
- /// </summary>
- /// <remarks>
- /// 変更した場合、呼び出し側で再描写とレイアウトの再構築を行う必要があります
- /// </remarks>
- public LineBreakMethod LineBreak
- {
- get
- {
- return this.Document.LineBreak;
- }
- set
- {
- this.Document.LineBreak = value;
- }
- }
-
- /// <summary>
- /// 折り返し行う文字数。実際に折り返しが行われる幅はem単位×この値となります
- /// </summary>
- public int LineBreakCharCount
- {
- get
- {
- return this.Document.LineBreakCharCount;
- }
- set
- {
- this.Document.LineBreakCharCount = value;
- }
- }
-
public double LineNumberMargin
{
get
}
/// <summary>
- /// タブの幅
- /// </summary>
- /// <remarks>変更した場合、呼び出し側で再描写する必要があります</remarks>
- public int TabStops
- {
- get { return this.Document.TabStops; }
- set { this.Document.TabStops = value; }
- }
-
- /// <summary>
/// すべてのレイアウト行を破棄し、再度レイアウトをやり直す
/// </summary>
public virtual void PerfomLayouts()
set { this._Src = value; }
}
- /// <summary>
- /// 行番号を表示するかどうか
- /// </summary>
- public bool DrawLineNumber
- {
- get { return this.Document.DrawLineNumber; }
- set
- {
- this.Document.DrawLineNumber = value;
- }
- }
-
public virtual void Draw(Rectangle updateRect)
{
}
IList<LineToIndexTableData> LayoutLines_SpilitStringByPixelbase(object sender, SpilitStringEventArgs e)
{
double WrapWidth;
- if (this.LineBreak == LineBreakMethod.PageBound)
+ if (this.Document.LineBreak == LineBreakMethod.PageBound)
WrapWidth = this.render.TextArea.Width - LineBreakingMarginWidth; //余白を残さないと欠ける
else
- WrapWidth = this.render.emSize.Width * this.LineBreakCharCount;
+ WrapWidth = this.render.emSize.Width * this.Document.LineBreakCharCount;
- if (WrapWidth < 0 && this.LineBreak != LineBreakMethod.None)
+ if (WrapWidth < 0 && this.Document.LineBreak != LineBreakMethod.None)
throw new InvalidOperationException();
int startIndex = e.index;
this.View = new EditView(this.Document, this.Render, new Padding(5, GripperView.HitAreaWidth, GripperView.HitAreaWidth / 2, GripperView.HitAreaWidth));
this.View.SrcChanged += View_SrcChanged;
this.View.InsertMode = this.InsertMode;
- this.View.DrawLineNumber = this.DrawLineNumber;
+ this.Document.DrawLineNumber = this.DrawLineNumber;
this.View.HideCaret = !this.DrawCaret;
this.View.HideLineMarker = !this.DrawCaretLine;
- this.View.HideRuler = !this.DrawRuler;
- this.View.UrlMark = this.MarkURL;
- this.View.TabStops = this.TabChars;
+ this.Document.HideRuler = !this.DrawRuler;
+ this.Document.UrlMark = this.MarkURL;
+ this.Document.TabStops = this.TabChars;
this._Controller = new Controller(this.Document, this.View);
this._Controller.SelectionChanged += Controller_SelectionChanged;
if (isControlPressed)
this._Controller.JumpToHead(isShiftPressed);
else
- this.Controller.JumpToLineHead(this.View.CaretPostion.row,isShiftPressed);
+ this.Controller.JumpToLineHead(this.Document.CaretPostion.row,isShiftPressed);
this.Refresh();
isMovedCaret = true;
break;
if (isControlPressed)
this._Controller.JumpToEnd(isShiftPressed);
else
- this.Controller.JumpToLineEnd(this.View.CaretPostion.row,isShiftPressed);
+ this.Controller.JumpToLineEnd(this.Document.CaretPostion.row,isShiftPressed);
this.Refresh();
isMovedCaret = true;
break;
//こうしないと選択できなくなってしまう
this.nowCaretMove = true;
SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
- SetValue(CaretPostionPropertyKey, this.View.CaretPostion);
+ SetValue(CaretPostionPropertyKey, this.Document.CaretPostion);
this.nowCaretMove = false;
this.View.SelectGrippers.BottomLeft.MoveByIndex(this.View, this.Controller.SelectionStart);
this.View.SelectGrippers.BottomRight.MoveByIndex(this.View, this.Controller.SelectionStart + this.Controller.SelectionLength);
if (e.Property.Equals(InsertModeProperty))
source.View.InsertMode = source.InsertMode;
if (e.Property.Equals(TabCharsProperty))
- source.View.TabStops = source.TabChars;
+ source.Document.TabStops = source.TabChars;
if (e.Property.Equals(RectSelectModeProperty))
source._Controller.RectSelection = source.RectSelectMode;
if (e.Property.Equals(DrawCaretProperty))
source.View.HideLineMarker = !source.DrawCaretLine;
if (e.Property.Equals(DrawLineNumberProperty))
{
- source.View.DrawLineNumber = source.DrawLineNumber;
- source._Controller.JumpCaret(source.View.CaretPostion.row, source.View.CaretPostion.col);
+ source.Document.DrawLineNumber = source.DrawLineNumber;
+ source._Controller.JumpCaret(source.Document.CaretPostion.row, source.Document.CaretPostion.col);
}
if(e.Property.Equals(MagnificationPowerPropertyKey))
source.Render.FontSize = source.FontSize * source.MagnificationPower;
if (e.Property.Equals(LineMarkerProperty))
source.Render.LineMarker = D2DRenderBase.ToColor4(source.LineMarker);
if (e.Property.Equals(MarkURLProperty))
- source.View.UrlMark = source.MarkURL;
+ source.Document.UrlMark = source.MarkURL;
if (e.Property.Equals(ShowFullSpaceProperty))
source.Render.ShowFullSpace = source.ShowFullSpace;
if (e.Property.Equals(ShowHalfSpaceProperty))
if (e.Property.Equals(ShowLineBreakProperty))
source.Render.ShowLineBreak = source.ShowLineBreak;
if (e.Property.Equals(LineBreakProperty))
- source.View.LineBreak = source.LineBreakMethod;
+ source.Document.LineBreak = source.LineBreakMethod;
if (e.Property.Equals(LineBreakCharCountProperty))
- source.View.LineBreakCharCount = source.LineBreakCharCount;
+ source.Document.LineBreakCharCount = source.LineBreakCharCount;
if (e.Property.Equals(UpdateAreaProperty))
source.Render.UpdateArea = D2DRenderBase.ToColor4(source.UpdateArea);
if (e.Property.Equals(LineNumberProperty))
}
if (e.Property.Equals(DrawRulerProperty))
{
- source.View.HideRuler = !source.DrawRuler;
- source._Controller.JumpCaret(source.View.CaretPostion.row, source.View.CaretPostion.col);
+ source.Document.HideRuler = !source.DrawRuler;
+ source._Controller.JumpCaret(source.Document.CaretPostion.row, source.Document.CaretPostion.col);
}
}
#endregion
{
get
{
- return this.View.MarkerPatternSet;
+ return this.Document.MarkerPatternSet;
}
}
-/*\r
- * Copyright (C) 2013 FooProject\r
- * * 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
- * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\r
-\r
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of \r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\r
-\r
-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
- */\r
-using System;\r
-using Windows.Graphics.Display;\r
-using Windows.Graphics.Printing;\r
-using System.Runtime.InteropServices;\r
-using Windows.UI;\r
-using FooEditEngine.Metro;\r
-\r
-namespace FooEditEngine\r
-{\r
- /// <summary>\r
- /// イベントデータ\r
- /// </summary>\r
- public sealed class ParseCommandEventArgs\r
- {\r
- /// <summary>\r
- /// 印刷中のページ番号\r
- /// </summary>\r
- public int PageNumber;\r
- /// <summary>\r
- /// ページ範囲内で許容されている最大の番号\r
- /// </summary>\r
- public int MaxPageNumber;\r
- /// <summary>\r
- /// 処理前の文字列\r
- /// </summary>\r
- public string Original;\r
- /// <summary>\r
- /// コンストラクター\r
- /// </summary>\r
- /// <param name="nowPage">印刷中のページ番号</param>\r
- /// <param name="maxPage">印刷すべき最大のページ番号</param>\r
- /// <param name="org">処理前の文字列</param>\r
- public ParseCommandEventArgs(int nowPage, int maxPage, string org)\r
- {\r
- this.PageNumber = nowPage;\r
- this.MaxPageNumber = maxPage;\r
- this.Original = org;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// コマンド処理用デリゲート\r
- /// </summary>\r
- /// <param name="sender">送信元のクラス</param>\r
- /// <param name="e">イベントデータ</param>\r
- /// <returns>処理後の文字列</returns>\r
- public delegate string ParseCommandHandler(object sender, ParseCommandEventArgs e);\r
-\r
-\r
- sealed class PrintableViewFactory\r
- {\r
- Windows.UI.Color foreground, comment, keyword1, keyword2, literal, url;\r
- string fontName;\r
- double fontSize;\r
- LineBreakMethod lineBreakMethod;\r
- int lineBreakCharCount, tabCount;\r
- Document document;\r
- bool urlMark;\r
- IHilighter hilighter;\r
- float displayDpi;\r
- Padding padding;\r
- public PrintableViewFactory(FooTextBox textbox,Padding padding)\r
- {\r
- this.foreground = textbox.Foreground;\r
- this.comment = textbox.Comment;\r
- this.keyword1 = textbox.Keyword1;\r
- this.keyword2 = textbox.Keyword2;\r
- this.literal = textbox.Literal;\r
- this.url = textbox.URL;\r
- this.fontName = textbox.FontFamily.Source;\r
- this.fontSize = textbox.FontSize;\r
- this.tabCount = textbox.TabChars;\r
- this.document = textbox.Document;\r
- this.lineBreakMethod = textbox.LineBreakMethod;\r
- this.lineBreakCharCount = textbox.LineBreakCharCount;\r
- this.drawLineNumber = textbox.DrawLineNumber;\r
- this.urlMark = textbox.MarkURL;\r
- this.hilighter = textbox.Hilighter;\r
- this.displayDpi = DisplayInformation.GetForCurrentView().LogicalDpi;\r
- this.padding = padding;\r
- this.EnableHilight = true;\r
- }\r
- public D2DPrintRender CreateRender(PrintPageDescription pagedesc, IPrintDocumentPackageTarget docPackageTarget)\r
- {\r
- D2DPrintRender render;\r
- Size size = new Size(pagedesc.ImageableRect.Width, pagedesc.ImageableRect.Height);\r
- render = new D2DPrintRender(this.fontName, this.fontSize, size, Math.Min(pagedesc.DpiX, pagedesc.DpiY), docPackageTarget);\r
- render.Foreground = D2DRenderBase.ToColor4(this.foreground);\r
- render.Comment = D2DRenderBase.ToColor4(this.comment);\r
- render.Keyword1 = D2DRenderBase.ToColor4(this.keyword1);\r
- render.Keyword2 = D2DRenderBase.ToColor4(this.keyword2);\r
- render.Literal = D2DRenderBase.ToColor4(this.literal);\r
- render.Url = D2DRenderBase.ToColor4(this.url);\r
- return render;\r
- }\r
- public D2DPrintPreviewRender CreateRender(PrintPageDescription pagedesc)\r
- {\r
- D2DPrintPreviewRender render;\r
- Size size = new Size(pagedesc.ImageableRect.Width, pagedesc.ImageableRect.Height);\r
- render = new D2DPrintPreviewRender(this.fontName, this.fontSize, size, this.displayDpi);\r
- render.Foreground = D2DRenderBase.ToColor4(this.foreground);\r
- render.Comment = D2DRenderBase.ToColor4(this.comment);\r
- render.Keyword1 = D2DRenderBase.ToColor4(this.keyword1);\r
- render.Keyword2 = D2DRenderBase.ToColor4(this.keyword2);\r
- render.Literal = D2DRenderBase.ToColor4(this.literal);\r
- render.Url = D2DRenderBase.ToColor4(this.url);\r
- return render;\r
- }\r
- public PrintableView CreateView(PrintPageDescription pagedesc, IPrintableTextRender render, string header, string footer)\r
- {\r
- Document documentSnap = new Document(this.document);\r
- documentSnap.LayoutLines.Render = render;\r
- PrintableView view = new PrintableView(documentSnap, render,padding);\r
- view.TabStops = this.tabCount;\r
- view.LineBreak = this.lineBreakMethod == LineBreakMethod.None ? LineBreakMethod.PageBound : this.lineBreakMethod;\r
- view.LineBreakCharCount = this.lineBreakCharCount;\r
- view.DrawLineNumber = this.drawLineNumber;\r
- view.Header = header;\r
- view.Footer = footer;\r
- view.UrlMark = this.urlMark;\r
- view.PageBound = new Rectangle(pagedesc.ImageableRect.X, pagedesc.ImageableRect.Y, pagedesc.ImageableRect.Width, pagedesc.ImageableRect.Height);\r
- view.Hilighter = this.EnableHilight ? this.hilighter : null;\r
- view.PerfomLayouts();\r
-\r
- return view;\r
- }\r
-\r
- public bool drawLineNumber\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- public bool EnableHilight\r
- {\r
- get;\r
- set;\r
- }\r
- }\r
-\r
- sealed class DocumentSource : IPrintDocumentPageSource, IPrintPreviewPageCollection, IPrintDocumentSource,IPrintPreviewSource\r
- {\r
- IPrintPreviewDxgiPackageTarget dxgiPreviewTarget;\r
- bool paginateCalled = false;\r
- Size imageRect;\r
- PrintableViewFactory factory;\r
- D2DPrintPreviewRender previewRender;\r
- PrintableView previewView;\r
- int maxPreviePageCount;\r
-\r
- public ParseCommandHandler ParseHF;\r
- public string Header = string.Empty;\r
- public string Fotter = string.Empty;\r
-\r
- public DocumentSource(FooTextBox textbox,Padding padding)\r
- {\r
- this.factory = new PrintableViewFactory(textbox, padding);\r
- }\r
-\r
- internal enum SyntaxHilightApplibility\r
- {\r
- Apply,\r
- NoApply,\r
- }\r
-\r
- [DisplayPrintOptionResourceID("SyntaxHilight")]\r
- internal SyntaxHilightApplibility EnableHilight\r
- {\r
- get\r
- {\r
- return this.factory.EnableHilight ? SyntaxHilightApplibility.Apply : SyntaxHilightApplibility.NoApply;\r
- }\r
- set\r
- {\r
- this.factory.EnableHilight = value == SyntaxHilightApplibility.Apply;\r
- }\r
- }\r
-\r
- internal enum LineNumberVisiblity\r
- {\r
- Visible,\r
- Hidden\r
- }\r
-\r
- [DisplayPrintOptionResourceID("ShowLineNumber")]\r
- internal LineNumberVisiblity ShowLineNumber\r
- {\r
- get\r
- {\r
- return this.factory.drawLineNumber ? LineNumberVisiblity.Visible : LineNumberVisiblity.Hidden;\r
- }\r
- set\r
- {\r
- this.factory.drawLineNumber = value == LineNumberVisiblity.Visible;\r
- }\r
- }\r
-\r
- public void GetPreviewPageCollection(IPrintDocumentPackageTarget docPackageTarget, out IPrintPreviewPageCollection docPageCollection)\r
- {\r
- Guid guid = new Guid(PreviewPackageIds.IID_PREVIEWPACKAGETARGET_DXGI);\r
- IntPtr target;\r
- docPackageTarget.GetPackageTarget(guid, guid, out target);\r
- this.dxgiPreviewTarget = (IPrintPreviewDxgiPackageTarget)Marshal.GetObjectForIUnknown(target);\r
- docPageCollection = (IPrintPreviewPageCollection)this;\r
- }\r
-\r
- public void MakeDocument(object printTaskOptions, IPrintDocumentPackageTarget docPackageTarget)\r
- {\r
- PrintTaskOptions options = (PrintTaskOptions)printTaskOptions;\r
- PrintPageDescription pagedesc = options.GetPageDescription(1);\r
-\r
- D2DPrintRender render = this.factory.CreateRender(pagedesc, docPackageTarget);\r
- PrintableView view = this.factory.CreateView(pagedesc, render, this.Header, this.Fotter);\r
-\r
- bool result = false;\r
- int currentPage = 0;\r
-\r
- while (!result)\r
- {\r
- if(!string.IsNullOrEmpty(this.Header))\r
- view.Header = this.ParseHF(this, new ParseCommandEventArgs(currentPage, this.maxPreviePageCount, this.Header));\r
- if (!string.IsNullOrEmpty(this.Fotter))\r
- view.Footer = this.ParseHF(this, new ParseCommandEventArgs(currentPage, this.maxPreviePageCount, this.Fotter));\r
-\r
- render.BegineDraw();\r
- view.Draw(view.PageBound);\r
- render.EndDraw();\r
- result = view.TryPageDown();\r
- currentPage++;\r
- }\r
-\r
- render.Dispose();\r
- view.Dispose();\r
- }\r
-\r
- public void Paginate(uint currentJobPage, object printTaskOptions)\r
- {\r
- PrintTaskOptions options = (PrintTaskOptions)printTaskOptions;\r
- PrintPageDescription pagedesc = options.GetPageDescription(currentJobPage);\r
-\r
- this.imageRect = new Size(pagedesc.ImageableRect.Width, pagedesc.ImageableRect.Height);\r
-\r
- this.previewRender = this.factory.CreateRender(pagedesc);\r
- this.previewView = this.factory.CreateView(pagedesc, this.previewRender, this.Header, this.Fotter);\r
-\r
- int maxPage = 1;\r
- while (!this.previewView.TryPageDown())\r
- maxPage++;\r
-\r
- this.dxgiPreviewTarget.SetJobPageCount(PageCountType.FinalPageCount, (uint)maxPage);\r
-\r
- this.dxgiPreviewTarget.InvalidatePreview();\r
-\r
- this.maxPreviePageCount = maxPage;\r
-\r
- this.paginateCalled = true;\r
- }\r
-\r
- public void InvalidatePreview()\r
- {\r
- this.dxgiPreviewTarget.InvalidatePreview();\r
- }\r
-\r
- public void MakePage(uint desiredJobPage, float width, float height)\r
- {\r
- if (width <= 0 || height <= 0)\r
- throw new COMException("", 0x70057/*E_INVALIDARG*/);\r
- if (!this.paginateCalled)\r
- return;\r
- if (desiredJobPage == 0xFFFFFFFF)\r
- desiredJobPage = 1;\r
-\r
- this.previewView.TryScroll(0, 0); //元に戻さないとページ番号が変わった時に正しく動作しない\r
-\r
- for (int i = 1; i < desiredJobPage; i++)\r
- this.previewView.TryPageDown();\r
-\r
- if (!string.IsNullOrEmpty(this.Header))\r
- this.previewView.Header = this.ParseHF(this, new ParseCommandEventArgs((int)desiredJobPage, this.maxPreviePageCount, this.Header));\r
- if (!string.IsNullOrEmpty(this.Fotter))\r
- this.previewView.Footer = this.ParseHF(this, new ParseCommandEventArgs((int)desiredJobPage, this.maxPreviePageCount, this.Fotter));\r
-\r
- this.previewRender.Resize(width, height);\r
- this.previewRender.SetScale((float)(this.previewView.PageBound.Width / width)); //BeginDraw()で倍率が1に戻る\r
-\r
- this.previewRender.BegineDraw();\r
- this.previewView.Draw(this.previewView.PageBound);\r
- this.previewRender.EndDraw(this.dxgiPreviewTarget,desiredJobPage);\r
- }\r
-\r
- public void Dispose()\r
- {\r
- if (this.previewView != null)\r
- this.previewView.Dispose();\r
- if (this.previewRender != null)\r
- this.previewRender.Dispose();\r
- }\r
- }\r
-}\r
+/*
+ * Copyright (C) 2013 FooProject
+ * * 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
+ * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+using System;
+using Windows.Graphics.Display;
+using Windows.Graphics.Printing;
+using System.Runtime.InteropServices;
+using Windows.UI;
+using FooEditEngine.Metro;
+
+namespace FooEditEngine
+{
+ /// <summary>
+ /// イベントデータ
+ /// </summary>
+ public sealed class ParseCommandEventArgs
+ {
+ /// <summary>
+ /// 印刷中のページ番号
+ /// </summary>
+ public int PageNumber;
+ /// <summary>
+ /// ページ範囲内で許容されている最大の番号
+ /// </summary>
+ public int MaxPageNumber;
+ /// <summary>
+ /// 処理前の文字列
+ /// </summary>
+ public string Original;
+ /// <summary>
+ /// コンストラクター
+ /// </summary>
+ /// <param name="nowPage">印刷中のページ番号</param>
+ /// <param name="maxPage">印刷すべき最大のページ番号</param>
+ /// <param name="org">処理前の文字列</param>
+ public ParseCommandEventArgs(int nowPage, int maxPage, string org)
+ {
+ this.PageNumber = nowPage;
+ this.MaxPageNumber = maxPage;
+ this.Original = org;
+ }
+ }
+
+ /// <summary>
+ /// コマンド処理用デリゲート
+ /// </summary>
+ /// <param name="sender">送信元のクラス</param>
+ /// <param name="e">イベントデータ</param>
+ /// <returns>処理後の文字列</returns>
+ public delegate string ParseCommandHandler(object sender, ParseCommandEventArgs e);
+
+
+ sealed class PrintableViewFactory
+ {
+ Windows.UI.Color foreground, comment, keyword1, keyword2, literal, url;
+ string fontName;
+ double fontSize;
+ LineBreakMethod lineBreakMethod;
+ int lineBreakCharCount, tabCount;
+ Document document;
+ bool urlMark;
+ IHilighter hilighter;
+ float displayDpi;
+ Padding padding;
+ public PrintableViewFactory(FooTextBox textbox,Padding padding)
+ {
+ this.foreground = textbox.Foreground;
+ this.comment = textbox.Comment;
+ this.keyword1 = textbox.Keyword1;
+ this.keyword2 = textbox.Keyword2;
+ this.literal = textbox.Literal;
+ this.url = textbox.URL;
+ this.fontName = textbox.FontFamily.Source;
+ this.fontSize = textbox.FontSize;
+ this.tabCount = textbox.TabChars;
+ this.document = textbox.Document;
+ this.lineBreakMethod = textbox.LineBreakMethod;
+ this.lineBreakCharCount = textbox.LineBreakCharCount;
+ this.drawLineNumber = textbox.DrawLineNumber;
+ this.urlMark = textbox.MarkURL;
+ this.hilighter = textbox.Hilighter;
+ this.displayDpi = DisplayInformation.GetForCurrentView().LogicalDpi;
+ this.padding = padding;
+ this.EnableHilight = true;
+ }
+ public D2DPrintRender CreateRender(PrintPageDescription pagedesc, IPrintDocumentPackageTarget docPackageTarget)
+ {
+ D2DPrintRender render;
+ Size size = new Size(pagedesc.ImageableRect.Width, pagedesc.ImageableRect.Height);
+ render = new D2DPrintRender(this.fontName, this.fontSize, size, Math.Min(pagedesc.DpiX, pagedesc.DpiY), docPackageTarget);
+ render.Foreground = D2DRenderBase.ToColor4(this.foreground);
+ render.Comment = D2DRenderBase.ToColor4(this.comment);
+ render.Keyword1 = D2DRenderBase.ToColor4(this.keyword1);
+ render.Keyword2 = D2DRenderBase.ToColor4(this.keyword2);
+ render.Literal = D2DRenderBase.ToColor4(this.literal);
+ render.Url = D2DRenderBase.ToColor4(this.url);
+ return render;
+ }
+ public D2DPrintPreviewRender CreateRender(PrintPageDescription pagedesc)
+ {
+ D2DPrintPreviewRender render;
+ Size size = new Size(pagedesc.ImageableRect.Width, pagedesc.ImageableRect.Height);
+ render = new D2DPrintPreviewRender(this.fontName, this.fontSize, size, this.displayDpi);
+ render.Foreground = D2DRenderBase.ToColor4(this.foreground);
+ render.Comment = D2DRenderBase.ToColor4(this.comment);
+ render.Keyword1 = D2DRenderBase.ToColor4(this.keyword1);
+ render.Keyword2 = D2DRenderBase.ToColor4(this.keyword2);
+ render.Literal = D2DRenderBase.ToColor4(this.literal);
+ render.Url = D2DRenderBase.ToColor4(this.url);
+ return render;
+ }
+ public PrintableView CreateView(PrintPageDescription pagedesc, IPrintableTextRender render, string header, string footer)
+ {
+ Document documentSnap = new Document(this.document);
+ documentSnap.LayoutLines.Render = render;
+ PrintableView view = new PrintableView(documentSnap, render,padding);
+ view.Header = header;
+ view.Footer = footer;
+ view.PageBound = new Rectangle(pagedesc.ImageableRect.X, pagedesc.ImageableRect.Y, pagedesc.ImageableRect.Width, pagedesc.ImageableRect.Height);
+ view.Hilighter = this.EnableHilight ? this.hilighter : null;
+ documentSnap.DrawLineNumber = this.drawLineNumber;
+ view.PerfomLayouts();
+
+ return view;
+ }
+
+ public bool drawLineNumber
+ {
+ get;
+ set;
+ }
+
+ public bool EnableHilight
+ {
+ get;
+ set;
+ }
+ }
+
+ sealed class DocumentSource : IPrintDocumentPageSource, IPrintPreviewPageCollection, IPrintDocumentSource,IPrintPreviewSource
+ {
+ IPrintPreviewDxgiPackageTarget dxgiPreviewTarget;
+ bool paginateCalled = false;
+ Size imageRect;
+ PrintableViewFactory factory;
+ D2DPrintPreviewRender previewRender;
+ PrintableView previewView;
+ int maxPreviePageCount;
+
+ public ParseCommandHandler ParseHF;
+ public string Header = string.Empty;
+ public string Fotter = string.Empty;
+
+ public DocumentSource(FooTextBox textbox,Padding padding)
+ {
+ this.factory = new PrintableViewFactory(textbox, padding);
+ }
+
+ internal enum SyntaxHilightApplibility
+ {
+ Apply,
+ NoApply,
+ }
+
+ [DisplayPrintOptionResourceID("SyntaxHilight")]
+ internal SyntaxHilightApplibility EnableHilight
+ {
+ get
+ {
+ return this.factory.EnableHilight ? SyntaxHilightApplibility.Apply : SyntaxHilightApplibility.NoApply;
+ }
+ set
+ {
+ this.factory.EnableHilight = value == SyntaxHilightApplibility.Apply;
+ }
+ }
+
+ internal enum LineNumberVisiblity
+ {
+ Visible,
+ Hidden
+ }
+
+ [DisplayPrintOptionResourceID("ShowLineNumber")]
+ internal LineNumberVisiblity ShowLineNumber
+ {
+ get
+ {
+ return this.factory.drawLineNumber ? LineNumberVisiblity.Visible : LineNumberVisiblity.Hidden;
+ }
+ set
+ {
+ this.factory.drawLineNumber = value == LineNumberVisiblity.Visible;
+ }
+ }
+
+ public void GetPreviewPageCollection(IPrintDocumentPackageTarget docPackageTarget, out IPrintPreviewPageCollection docPageCollection)
+ {
+ Guid guid = new Guid(PreviewPackageIds.IID_PREVIEWPACKAGETARGET_DXGI);
+ IntPtr target;
+ docPackageTarget.GetPackageTarget(guid, guid, out target);
+ this.dxgiPreviewTarget = (IPrintPreviewDxgiPackageTarget)Marshal.GetObjectForIUnknown(target);
+ docPageCollection = (IPrintPreviewPageCollection)this;
+ }
+
+ public void MakeDocument(object printTaskOptions, IPrintDocumentPackageTarget docPackageTarget)
+ {
+ PrintTaskOptions options = (PrintTaskOptions)printTaskOptions;
+ PrintPageDescription pagedesc = options.GetPageDescription(1);
+
+ D2DPrintRender render = this.factory.CreateRender(pagedesc, docPackageTarget);
+ PrintableView view = this.factory.CreateView(pagedesc, render, this.Header, this.Fotter);
+
+ bool result = false;
+ int currentPage = 0;
+
+ while (!result)
+ {
+ if(!string.IsNullOrEmpty(this.Header))
+ view.Header = this.ParseHF(this, new ParseCommandEventArgs(currentPage, this.maxPreviePageCount, this.Header));
+ if (!string.IsNullOrEmpty(this.Fotter))
+ view.Footer = this.ParseHF(this, new ParseCommandEventArgs(currentPage, this.maxPreviePageCount, this.Fotter));
+
+ render.BegineDraw();
+ view.Draw(view.PageBound);
+ render.EndDraw();
+ result = view.TryPageDown();
+ currentPage++;
+ }
+
+ render.Dispose();
+ view.Dispose();
+ }
+
+ public void Paginate(uint currentJobPage, object printTaskOptions)
+ {
+ PrintTaskOptions options = (PrintTaskOptions)printTaskOptions;
+ PrintPageDescription pagedesc = options.GetPageDescription(currentJobPage);
+
+ this.imageRect = new Size(pagedesc.ImageableRect.Width, pagedesc.ImageableRect.Height);
+
+ this.previewRender = this.factory.CreateRender(pagedesc);
+ this.previewView = this.factory.CreateView(pagedesc, this.previewRender, this.Header, this.Fotter);
+
+ int maxPage = 1;
+ while (!this.previewView.TryPageDown())
+ maxPage++;
+
+ this.dxgiPreviewTarget.SetJobPageCount(PageCountType.FinalPageCount, (uint)maxPage);
+
+ this.dxgiPreviewTarget.InvalidatePreview();
+
+ this.maxPreviePageCount = maxPage;
+
+ this.paginateCalled = true;
+ }
+
+ public void InvalidatePreview()
+ {
+ this.dxgiPreviewTarget.InvalidatePreview();
+ }
+
+ public void MakePage(uint desiredJobPage, float width, float height)
+ {
+ if (width <= 0 || height <= 0)
+ throw new COMException("", 0x70057/*E_INVALIDARG*/);
+ if (!this.paginateCalled)
+ return;
+ if (desiredJobPage == 0xFFFFFFFF)
+ desiredJobPage = 1;
+
+ this.previewView.TryScroll(0, 0); //元に戻さないとページ番号が変わった時に正しく動作しない
+
+ for (int i = 1; i < desiredJobPage; i++)
+ this.previewView.TryPageDown();
+
+ if (!string.IsNullOrEmpty(this.Header))
+ this.previewView.Header = this.ParseHF(this, new ParseCommandEventArgs((int)desiredJobPage, this.maxPreviePageCount, this.Header));
+ if (!string.IsNullOrEmpty(this.Fotter))
+ this.previewView.Footer = this.ParseHF(this, new ParseCommandEventArgs((int)desiredJobPage, this.maxPreviePageCount, this.Fotter));
+
+ this.previewRender.Resize(width, height);
+ this.previewRender.SetScale((float)(this.previewView.PageBound.Width / width)); //BeginDraw()で倍率が1に戻る
+
+ this.previewRender.BegineDraw();
+ this.previewView.Draw(this.previewView.PageBound);
+ this.previewRender.EndDraw(this.dxgiPreviewTarget,desiredJobPage);
+ }
+
+ public void Dispose()
+ {
+ if (this.previewView != null)
+ this.previewView.Dispose();
+ if (this.previewRender != null)
+ this.previewRender.Dispose();
+ }
+ }
+}
-/*\r
- * Copyright (C) 2013 FooProject\r
- * * 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
- * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\r
-\r
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of \r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\r
-\r
-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
- */\r
-using System;\r
-using System.Threading.Tasks;\r
-using System.Printing;\r
-using System.Windows;\r
-using System.Windows.Xps;\r
-using Shapes = System.Windows.Shapes;\r
-using System.Collections.Generic;\r
-using System.Windows.Controls;\r
-using System.Windows.Documents;\r
-using System.Windows.Documents.Serialization;\r
-using System.Windows.Media;\r
-\r
-namespace FooEditEngine.WPF\r
-{\r
- /// <summary>\r
- /// イベントデータ\r
- /// </summary>\r
- public sealed class ParseCommandEventArgs\r
- {\r
- /// <summary>\r
- /// 印刷中のページ番号\r
- /// </summary>\r
- public int PageNumber;\r
- /// <summary>\r
- /// ページ範囲内で許容されている最大の番号\r
- /// </summary>\r
- public int MaxPageNumber;\r
- /// <summary>\r
- /// 処理前の文字列\r
- /// </summary>\r
- public string Original;\r
- /// <summary>\r
- /// コンストラクター\r
- /// </summary>\r
- /// <param name="nowPage">印刷中のページ番号</param>\r
- /// <param name="maxPage">印刷すべき最大のページ番号</param>\r
- /// <param name="org">処理前の文字列</param>\r
- public ParseCommandEventArgs(int nowPage,int maxPage,string org)\r
- {\r
- this.PageNumber = nowPage;\r
- this.MaxPageNumber = maxPage;\r
- this.Original = org;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// コマンド処理用デリゲート\r
- /// </summary>\r
- /// <param name="sender">送信元のクラス</param>\r
- /// <param name="e">イベントデータ</param>\r
- /// <returns>処理後の文字列</returns>\r
- public delegate string ParseCommandHandler(object sender,ParseCommandEventArgs e);\r
-\r
- /// <summary>\r
- /// 印刷用のクラス\r
- /// </summary>\r
- public class FooPrintText\r
- {\r
- /// <summary>\r
- /// コンストラクター\r
- /// </summary>\r
- public FooPrintText()\r
- {\r
- this.ParseHF = new ParseCommandHandler((s, e) => { return e.Original; });\r
- }\r
-\r
- /// <summary>\r
- /// 印刷する最小のページ番号\r
- /// </summary>\r
- public int StartPage\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 印刷する最大のページ番号\r
- /// </summary>\r
- public int EndPage\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 印刷する領域の大きさ\r
- /// </summary>\r
- public System.Windows.Rect PageRect\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 対象となるドキュメント\r
- /// </summary>\r
- public Document Document\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// レタリング時のフロー方向を示す\r
- /// </summary>\r
- public FlowDirection FlowDirection\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 行番号を表示するかどうか\r
- /// </summary>\r
- public bool DrawLineNumber\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// ハイパーリンクに下線を引くなら真\r
- /// </summary>\r
- public bool MarkURL\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// デフォルトの文字ブラシ\r
- /// </summary>\r
- public System.Windows.Media.Color Foreground\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// URLを表すブラシ\r
- /// </summary>\r
- public System.Windows.Media.Color URL\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// キーワード1を表すブラシ\r
- /// </summary>\r
- public System.Windows.Media.Color Keyword1\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// キーワード2を表すブラシ\r
- /// </summary>\r
- public System.Windows.Media.Color Keyword2\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// コメントを表すブラシ\r
- /// </summary>\r
- public System.Windows.Media.Color Comment\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 文字リテラルを表すブラシ\r
- /// </summary>\r
- public System.Windows.Media.Color Litral\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 印刷に使用するフォント\r
- /// </summary>\r
- public FontFamily Font\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// フォントサイズ\r
- /// </summary>\r
- public double FontSize\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 折り返しの方法を指定する\r
- /// </summary>\r
- public LineBreakMethod LineBreakMethod\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 折り返した時の文字数を指定する\r
- /// </summary>\r
- public int LineBreakCharCount\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// ヘッダー\r
- /// </summary>\r
- public string Header\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// フッター\r
- /// </summary>\r
- public string Footer\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// シンタックスハイライター\r
- /// </summary>\r
- public IHilighter Hilighter\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 余白\r
- /// </summary>\r
- public Padding Padding\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// ヘッダーやフッターを処理する\r
- /// </summary>\r
- public ParseCommandHandler ParseHF;\r
-\r
- /// <summary>\r
- /// 印刷する\r
- /// </summary>\r
- /// <param name="pd">プリントダイアログ</param>\r
- public void Print(PrintDialog pd)\r
- {\r
- if (this.Font == null || this.Document == null)\r
- throw new InvalidOperationException();\r
-\r
- WPFRender render = new WPFRender(this.Font, this.FontSize);\r
- render.Foreground = this.Foreground;\r
- render.Comment = this.Comment;\r
- render.Keyword1 = this.Keyword1;\r
- render.Keyword2 = this.Keyword2;\r
- render.Literal = this.Litral;\r
- render.Url = this.URL;\r
- render.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;\r
- render.Printing = true;\r
- PrintableView view = new PrintableView(this.Document, render,this.Padding);\r
- view.LineBreak = this.LineBreakMethod;\r
- view.LineBreakCharCount = this.LineBreakCharCount;\r
- view.DrawLineNumber = this.DrawLineNumber;\r
- view.Header = this.Header;\r
- view.Footer = this.Footer;\r
- view.UrlMark = this.MarkURL;\r
- view.PageBound = this.PageRect;\r
- view.Hilighter = this.Hilighter;\r
- view.PerfomLayouts();\r
-\r
- try\r
- {\r
- FixedDocument fd = new FixedDocument();\r
- fd.DocumentPaginator.PageSize = this.PageRect.Size;\r
- \r
- int currentPage = 0;\r
-\r
- bool result = false;\r
-\r
- while (!result)\r
- {\r
- if (this.EndPage != -1 && currentPage > this.EndPage)\r
- break;\r
-\r
- if (this.StartPage == -1 || currentPage >= this.StartPage)\r
- {\r
- PageContent pc = new PageContent();\r
- \r
- FixedPage fp = new FixedPage();\r
- fp.Width = this.PageRect.Width;\r
- fp.Height = this.PageRect.Height;\r
-\r
- pc.Child = fp;\r
-\r
- view.Header = this.ParseHF(this, new ParseCommandEventArgs(currentPage, this.EndPage, this.Header));\r
- view.Footer = this.ParseHF(this, new ParseCommandEventArgs(currentPage, this.EndPage, this.Footer));\r
-\r
- DrawingVisual dv = new DrawingVisual();\r
-\r
- using (DrawingContext dc = dv.RenderOpen())\r
- {\r
- render.SetDrawingContext(dc);\r
- view.Draw(view.PageBound);\r
- }\r
-\r
- VisualHost host = new VisualHost();\r
- host.AddVisual(dv);\r
-\r
- fp.Children.Add(host);\r
-\r
- fd.Pages.Add(pc);\r
- }\r
- result = view.TryPageDown();\r
- currentPage++;\r
- }\r
-\r
- pd.PrintDocument(fd.DocumentPaginator,"");\r
- }\r
- catch (PrintingCanceledException)\r
- {\r
- }\r
- finally\r
- {\r
- view.Dispose();\r
- }\r
- }\r
- }\r
-\r
- class VisualHost : FrameworkElement\r
- {\r
- private List<Visual> fVisuals;\r
-\r
- public VisualHost()\r
- {\r
- fVisuals = new List<Visual>();\r
- }\r
-\r
- protected override Visual GetVisualChild(int index)\r
- {\r
- return fVisuals[index];\r
- }\r
-\r
- protected override int VisualChildrenCount\r
- {\r
- get { return fVisuals.Count; }\r
- }\r
-\r
- public void AddVisual(Visual visual)\r
- {\r
- fVisuals.Add(visual);\r
- base.AddVisualChild(visual);\r
- }\r
-\r
- public void RemoveVisual(Visual visual)\r
- {\r
- fVisuals.Remove(visual);\r
- base.RemoveVisualChild(visual);\r
- }\r
- }\r
-}\r
+/*
+ * Copyright (C) 2013 FooProject
+ * * 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
+ * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+using System;
+using System.Threading.Tasks;
+using System.Printing;
+using System.Windows;
+using System.Windows.Xps;
+using Shapes = System.Windows.Shapes;
+using System.Collections.Generic;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Documents.Serialization;
+using System.Windows.Media;
+
+namespace FooEditEngine.WPF
+{
+ /// <summary>
+ /// イベントデータ
+ /// </summary>
+ public sealed class ParseCommandEventArgs
+ {
+ /// <summary>
+ /// 印刷中のページ番号
+ /// </summary>
+ public int PageNumber;
+ /// <summary>
+ /// ページ範囲内で許容されている最大の番号
+ /// </summary>
+ public int MaxPageNumber;
+ /// <summary>
+ /// 処理前の文字列
+ /// </summary>
+ public string Original;
+ /// <summary>
+ /// コンストラクター
+ /// </summary>
+ /// <param name="nowPage">印刷中のページ番号</param>
+ /// <param name="maxPage">印刷すべき最大のページ番号</param>
+ /// <param name="org">処理前の文字列</param>
+ public ParseCommandEventArgs(int nowPage,int maxPage,string org)
+ {
+ this.PageNumber = nowPage;
+ this.MaxPageNumber = maxPage;
+ this.Original = org;
+ }
+ }
+
+ /// <summary>
+ /// コマンド処理用デリゲート
+ /// </summary>
+ /// <param name="sender">送信元のクラス</param>
+ /// <param name="e">イベントデータ</param>
+ /// <returns>処理後の文字列</returns>
+ public delegate string ParseCommandHandler(object sender,ParseCommandEventArgs e);
+
+ /// <summary>
+ /// 印刷用のクラス
+ /// </summary>
+ public class FooPrintText
+ {
+ /// <summary>
+ /// コンストラクター
+ /// </summary>
+ public FooPrintText()
+ {
+ this.ParseHF = new ParseCommandHandler((s, e) => { return e.Original; });
+ }
+
+ /// <summary>
+ /// 印刷する最小のページ番号
+ /// </summary>
+ public int StartPage
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 印刷する最大のページ番号
+ /// </summary>
+ public int EndPage
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 印刷する領域の大きさ
+ /// </summary>
+ public System.Windows.Rect PageRect
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 対象となるドキュメント
+ /// </summary>
+ public Document Document
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// レタリング時のフロー方向を示す
+ /// </summary>
+ public FlowDirection FlowDirection
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 行番号を表示するかどうか
+ /// </summary>
+ public bool DrawLineNumber
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// ハイパーリンクに下線を引くなら真
+ /// </summary>
+ public bool MarkURL
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// デフォルトの文字ブラシ
+ /// </summary>
+ public System.Windows.Media.Color Foreground
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// URLを表すブラシ
+ /// </summary>
+ public System.Windows.Media.Color URL
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// キーワード1を表すブラシ
+ /// </summary>
+ public System.Windows.Media.Color Keyword1
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// キーワード2を表すブラシ
+ /// </summary>
+ public System.Windows.Media.Color Keyword2
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// コメントを表すブラシ
+ /// </summary>
+ public System.Windows.Media.Color Comment
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 文字リテラルを表すブラシ
+ /// </summary>
+ public System.Windows.Media.Color Litral
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 印刷に使用するフォント
+ /// </summary>
+ public FontFamily Font
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// フォントサイズ
+ /// </summary>
+ public double FontSize
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 折り返しの方法を指定する
+ /// </summary>
+ public LineBreakMethod LineBreakMethod
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 折り返した時の文字数を指定する
+ /// </summary>
+ public int LineBreakCharCount
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// ヘッダー
+ /// </summary>
+ public string Header
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// フッター
+ /// </summary>
+ public string Footer
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// シンタックスハイライター
+ /// </summary>
+ public IHilighter Hilighter
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 余白
+ /// </summary>
+ public Padding Padding
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// ヘッダーやフッターを処理する
+ /// </summary>
+ public ParseCommandHandler ParseHF;
+
+ /// <summary>
+ /// 印刷する
+ /// </summary>
+ /// <param name="pd">プリントダイアログ</param>
+ public void Print(PrintDialog pd)
+ {
+ if (this.Font == null || this.Document == null)
+ throw new InvalidOperationException();
+
+ WPFRender render = new WPFRender(this.Font, this.FontSize);
+ render.Foreground = this.Foreground;
+ render.Comment = this.Comment;
+ render.Keyword1 = this.Keyword1;
+ render.Keyword2 = this.Keyword2;
+ render.Literal = this.Litral;
+ render.Url = this.URL;
+ render.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft;
+ render.Printing = true;
+ PrintableView view = new PrintableView(this.Document, render,this.Padding);
+ view.Header = this.Header;
+ view.Footer = this.Footer;
+ view.PageBound = this.PageRect;
+ view.Hilighter = this.Hilighter;
+ view.PerfomLayouts();
+
+ try
+ {
+ FixedDocument fd = new FixedDocument();
+ fd.DocumentPaginator.PageSize = this.PageRect.Size;
+
+ int currentPage = 0;
+
+ bool result = false;
+
+ while (!result)
+ {
+ if (this.EndPage != -1 && currentPage > this.EndPage)
+ break;
+
+ if (this.StartPage == -1 || currentPage >= this.StartPage)
+ {
+ PageContent pc = new PageContent();
+
+ FixedPage fp = new FixedPage();
+ fp.Width = this.PageRect.Width;
+ fp.Height = this.PageRect.Height;
+
+ pc.Child = fp;
+
+ view.Header = this.ParseHF(this, new ParseCommandEventArgs(currentPage, this.EndPage, this.Header));
+ view.Footer = this.ParseHF(this, new ParseCommandEventArgs(currentPage, this.EndPage, this.Footer));
+
+ DrawingVisual dv = new DrawingVisual();
+
+ using (DrawingContext dc = dv.RenderOpen())
+ {
+ render.SetDrawingContext(dc);
+ view.Draw(view.PageBound);
+ }
+
+ VisualHost host = new VisualHost();
+ host.AddVisual(dv);
+
+ fp.Children.Add(host);
+
+ fd.Pages.Add(pc);
+ }
+ result = view.TryPageDown();
+ currentPage++;
+ }
+
+ pd.PrintDocument(fd.DocumentPaginator,"");
+ }
+ catch (PrintingCanceledException)
+ {
+ }
+ finally
+ {
+ view.Dispose();
+ }
+ }
+ }
+
+ class VisualHost : FrameworkElement
+ {
+ private List<Visual> fVisuals;
+
+ public VisualHost()
+ {
+ fVisuals = new List<Visual>();
+ }
+
+ protected override Visual GetVisualChild(int index)
+ {
+ return fVisuals[index];
+ }
+
+ protected override int VisualChildrenCount
+ {
+ get { return fVisuals.Count; }
+ }
+
+ public void AddVisual(Visual visual)
+ {
+ fVisuals.Add(visual);
+ base.AddVisualChild(visual);
+ }
+
+ public void RemoveVisual(Visual visual)
+ {
+ fVisuals.Remove(visual);
+ base.RemoveVisualChild(visual);
+ }
+ }
+}
this.View = new EditView(this.Document, this.Render, new Padding(5, 5, 5, 5));
this.View.SrcChanged += View_SrcChanged;
this.View.InsertMode = this.InsertMode;
- this.View.DrawLineNumber = this.DrawLineNumber;
+ this.Document.DrawLineNumber = this.DrawLineNumber;
this.View.HideCaret = !this.DrawCaret;
this.View.HideLineMarker = !this.DrawCaretLine;
- this.View.HideRuler = !this.DrawRuler;
- this.View.UrlMark = this.MarkURL;
- this.View.TabStops = this.TabChars;
+ this.Document.HideRuler = !this.DrawRuler;
+ this.Document.UrlMark = this.MarkURL;
+ this.Document.TabStops = this.TabChars;
this._Controller = new Controller(this.Document, this.View);
this._Controller.SelectionChanged += new EventHandler(Controller_SelectionChanged);
if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
this._Controller.JumpToHead(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
else
- this._Controller.JumpToLineHead(this.View.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
+ this._Controller.JumpToLineHead(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
this.Refresh();
movedCaret = true;
break;
if (this.IsPressedModifierKey(modiferKeys, ModifierKeys.Control))
this._Controller.JumpToEnd(this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
else
- this._Controller.JumpToLineEnd(this.View.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
+ this._Controller.JumpToLineEnd(this.Document.CaretPostion.row, this.IsPressedModifierKey(modiferKeys, ModifierKeys.Shift));
this.Refresh();
movedCaret = true;
break;
bool updateAll = this.View.LayoutLines.HilightAll() || this.View.LayoutLines.GenerateFolding();
- ITextLayout layout = this.View.LayoutLines.GetLayout(this.View.CaretPostion.row);
- double width = layout.GetWidthFromIndex(this.View.CaretPostion.col);
+ ITextLayout layout = this.View.LayoutLines.GetLayout(this.Document.CaretPostion.row);
+ double width = layout.GetWidthFromIndex(this.Document.CaretPostion.col);
if (width == 0.0)
width = this.View.CaretWidthOnInsertMode;
double height = layout.Height;
//こうしないと選択できなくなってしまう
this.nowCaretMove = true;
SetValue(SelectionProperty, new TextRange(this._Controller.SelectionStart, this._Controller.SelectionLength));
- SetValue(CaretPostionProperty, this.View.CaretPostion);
+ SetValue(CaretPostionProperty, this.Document.CaretPostion);
this.nowCaretMove = false;
if(this.textStore.IsLocked() == false)
this.textStore.NotifySelectionChanged();
this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
break;
case "LineBreakMethod":
- this.View.LineBreak = this.LineBreakMethod;
+ this.Document.LineBreak = this.LineBreakMethod;
break;
case "LineBreakCharCount":
- this.View.LineBreakCharCount = this.LineBreakCharCount;
+ this.Document.LineBreakCharCount = this.LineBreakCharCount;
break;
case "InsertMode":
this.View.InsertMode = this.InsertMode;
break;
case "TabChars":
- this.View.TabStops = this.TabChars;
+ this.Document.TabStops = this.TabChars;
break;
case "RectSelectMode":
this._Controller.RectSelection = this.RectSelectMode;
this.View.HideLineMarker = !this.DrawCaretLine;
break;
case "DrawLineNumber":
- this.View.DrawLineNumber = this.DrawLineNumber;
- this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);
+ this.Document.DrawLineNumber = this.DrawLineNumber;
+ this._Controller.JumpCaret(this.Document.CaretPostion.row, this.Document.CaretPostion.col);
break;
case "FontFamily":
this.Render.FontFamily = this.FontFamily;
this.Render.LineMarker = D2DRender.ToColor4(this.LineMarker);
break;
case "MarkURL":
- this.View.UrlMark = this.MarkURL;
+ this.Document.UrlMark = this.MarkURL;
break;
case "ShowFullSpace":
this.Render.ShowFullSpace = this.ShowFullSpace;
this.horizontalScrollBar.FlowDirection = this.FlowDirection;
break;
case "DrawRuler":
- this.View.HideRuler = !this.DrawRuler;
- this._Controller.JumpCaret(this.View.CaretPostion.row, this.View.CaretPostion.col);
+ this.Document.HideRuler = !this.DrawRuler;
+ this._Controller.JumpCaret(this.Document.CaretPostion.row, this.Document.CaretPostion.col);
break;
case "UpdateArea":
this.Render.UpdateArea = D2DRender.ToColor4(this.UpdateArea);
{
get
{
- return this.View.MarkerPatternSet;
+ return this.Document.MarkerPatternSet;
}
}
Document doc = new Document();
doc.LayoutLines.Render = render;
DummyView view = new DummyView(doc, render);
- view.MarkerPatternSet.Add(MarkerIDs.Defalut, dog);
+ doc.MarkerPatternSet.Add(MarkerIDs.Defalut, dog);
doc.Clear();
doc.Append(str);
IEnumerable<Marker> actual = doc.Markers.Get(MarkerIDs.Defalut);
-/*\r
- * Copyright (C) 2013 FooProject\r
- * * 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
- * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\r
-\r
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of \r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\r
-\r
-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
- */\r
-using System;\r
-using System.Drawing;\r
-using System.Drawing.Printing;\r
-\r
-namespace FooEditEngine.Windows\r
-{\r
- /// <summary>\r
- /// イベントデータ\r
- /// </summary>\r
- public class ParseCommandEventArgs\r
- {\r
- /// <summary>\r
- /// ページ番号\r
- /// </summary>\r
- public int PageNumber;\r
- /// <summary>\r
- /// プリンターの設定\r
- /// </summary>\r
- public PrinterSettings PrinterSetting;\r
- /// <summary>\r
- /// 処理前の文字列\r
- /// </summary>\r
- public string Original;\r
- /// <summary>\r
- /// コンストラクター\r
- /// </summary>\r
- /// <param name="nowPage">印刷中のページ番号</param>\r
- /// <param name="setting">プリンターの設定</param>\r
- /// <param name="org">処理前の文字列</param>\r
- public ParseCommandEventArgs(int nowPage,PrinterSettings setting,string org)\r
- {\r
- this.PageNumber = nowPage;\r
- this.PrinterSetting = setting;\r
- this.Original = org;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// コマンド処理用デリゲート\r
- /// </summary>\r
- /// <param name="sender">送信元のクラス</param>\r
- /// <param name="e">イベントデータ</param>\r
- /// <returns>処理後の文字列</returns>\r
- public delegate string ParseCommandHandler(object sender,ParseCommandEventArgs e);\r
-\r
- /// <summary>\r
- /// 印刷用のクラス\r
- /// </summary>\r
- public class FooPrintText\r
- {\r
- PrintableView view;\r
- PrintableTextRender render;\r
- int PageNumber;\r
-\r
- /// <summary>\r
- /// コンストラクター\r
- /// </summary>\r
- public FooPrintText()\r
- {\r
- this.PrintDocument = new PrintDocument();\r
- this.PrintDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);\r
- this.PrintDocument.EndPrint += new PrintEventHandler(PrintDocument_EndPrint);\r
- this.ParseHF = new ParseCommandHandler((s, e) => { return e.Original; });\r
- }\r
-\r
- /// <summary>\r
- /// 対象となるドキュメント\r
- /// </summary>\r
- public Document Document\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// プリントドキュメント\r
- /// </summary>\r
- public PrintDocument PrintDocument\r
- {\r
- get;\r
- private set;\r
- }\r
-\r
- /// <summary>\r
- /// 右から左に表示するなら真\r
- /// </summary>\r
- public bool RightToLeft\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 行番号を表示するかどうか\r
- /// </summary>\r
- public bool DrawLineNumber\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 印刷に使用するフォント\r
- /// </summary>\r
- public Font Font\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 折り返しの方法を指定する\r
- /// </summary>\r
- public LineBreakMethod LineBreakMethod\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 折り返した時の文字数を指定する\r
- /// </summary>\r
- public int LineBreakCharCount\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// ヘッダー\r
- /// </summary>\r
- public string Header\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// フッター\r
- /// </summary>\r
- public string Footer\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 余白\r
- /// </summary>\r
- public Padding Padding\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 前景色\r
- /// </summary>\r
- public System.Drawing.Color Foreground\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// ヘッダーやフッターを処理する\r
- /// </summary>\r
- public ParseCommandHandler ParseHF;\r
-\r
- void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)\r
- {\r
- if (this.Font == null || this.Document == null)\r
- throw new InvalidOperationException();\r
-\r
- if (view == null)\r
- {\r
- this.render = new PrintableTextRender(this.Font, e.Graphics);\r
- this.render.Foreground = this.Foreground;\r
- this.render.RightToLeft = this.RightToLeft;\r
- this.view = new PrintableView(this.Document, this.render,this.Padding);\r
- this.view.DrawLineNumber = this.DrawLineNumber;\r
- this.view.TabStops = 4;\r
- this.view.PageBound = e.MarginBounds;\r
- this.view.LineBreak = this.LineBreakMethod;\r
- this.view.LineBreakCharCount = this.LineBreakCharCount;\r
- this.PageNumber = 1;\r
- this.view.PerfomLayouts();\r
- }\r
-\r
- if (e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages)\r
- {\r
- for (; this.PageNumber < e.PageSettings.PrinterSettings.FromPage; this.PageNumber++)\r
- {\r
- if (this.view.TryPageDown())\r
- return;\r
- }\r
- }\r
-\r
- this.view.Header = this.ParseHF(this, new ParseCommandEventArgs(this.PageNumber, e.PageSettings.PrinterSettings,this.Header));\r
- this.view.Footer = this.ParseHF(this, new ParseCommandEventArgs(this.PageNumber, e.PageSettings.PrinterSettings, this.Footer));\r
-\r
- this.render.BeginDraw(e.Graphics);\r
-\r
- this.view.Draw(e.MarginBounds);\r
-\r
- e.HasMorePages = !this.view.TryPageDown();\r
-\r
- this.render.EndDraw();\r
-\r
- this.PageNumber++;\r
-\r
- if (e.HasMorePages && e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages && this.PageNumber > e.PageSettings.PrinterSettings.ToPage)\r
- e.HasMorePages = false;\r
- }\r
-\r
- void PrintDocument_EndPrint(object sender, PrintEventArgs e)\r
- {\r
- this.view.Dispose();\r
- this.view = null;\r
- this.render = null;\r
- }\r
-\r
- }\r
-}\r
+/*
+ * Copyright (C) 2013 FooProject
+ * * 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
+ * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+using System;
+using System.Drawing;
+using System.Drawing.Printing;
+
+namespace FooEditEngine.Windows
+{
+ /// <summary>
+ /// イベントデータ
+ /// </summary>
+ public class ParseCommandEventArgs
+ {
+ /// <summary>
+ /// ページ番号
+ /// </summary>
+ public int PageNumber;
+ /// <summary>
+ /// プリンターの設定
+ /// </summary>
+ public PrinterSettings PrinterSetting;
+ /// <summary>
+ /// 処理前の文字列
+ /// </summary>
+ public string Original;
+ /// <summary>
+ /// コンストラクター
+ /// </summary>
+ /// <param name="nowPage">印刷中のページ番号</param>
+ /// <param name="setting">プリンターの設定</param>
+ /// <param name="org">処理前の文字列</param>
+ public ParseCommandEventArgs(int nowPage,PrinterSettings setting,string org)
+ {
+ this.PageNumber = nowPage;
+ this.PrinterSetting = setting;
+ this.Original = org;
+ }
+ }
+
+ /// <summary>
+ /// コマンド処理用デリゲート
+ /// </summary>
+ /// <param name="sender">送信元のクラス</param>
+ /// <param name="e">イベントデータ</param>
+ /// <returns>処理後の文字列</returns>
+ public delegate string ParseCommandHandler(object sender,ParseCommandEventArgs e);
+
+ /// <summary>
+ /// 印刷用のクラス
+ /// </summary>
+ public class FooPrintText
+ {
+ PrintableView view;
+ PrintableTextRender render;
+ int PageNumber;
+
+ /// <summary>
+ /// コンストラクター
+ /// </summary>
+ public FooPrintText()
+ {
+ this.PrintDocument = new PrintDocument();
+ this.PrintDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);
+ this.PrintDocument.EndPrint += new PrintEventHandler(PrintDocument_EndPrint);
+ this.ParseHF = new ParseCommandHandler((s, e) => { return e.Original; });
+ }
+
+ /// <summary>
+ /// 対象となるドキュメント
+ /// </summary>
+ public Document Document
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// プリントドキュメント
+ /// </summary>
+ public PrintDocument PrintDocument
+ {
+ get;
+ private set;
+ }
+
+ /// <summary>
+ /// 右から左に表示するなら真
+ /// </summary>
+ public bool RightToLeft
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 行番号を表示するかどうか
+ /// </summary>
+ public bool DrawLineNumber
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 印刷に使用するフォント
+ /// </summary>
+ public Font Font
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 折り返しの方法を指定する
+ /// </summary>
+ public LineBreakMethod LineBreakMethod
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 折り返した時の文字数を指定する
+ /// </summary>
+ public int LineBreakCharCount
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// ヘッダー
+ /// </summary>
+ public string Header
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// フッター
+ /// </summary>
+ public string Footer
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 余白
+ /// </summary>
+ public Padding Padding
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 前景色
+ /// </summary>
+ public System.Drawing.Color Foreground
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// ヘッダーやフッターを処理する
+ /// </summary>
+ public ParseCommandHandler ParseHF;
+
+ void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
+ {
+ if (this.Font == null || this.Document == null)
+ throw new InvalidOperationException();
+
+ if (view == null)
+ {
+ this.render = new PrintableTextRender(this.Font, e.Graphics);
+ this.render.Foreground = this.Foreground;
+ this.render.RightToLeft = this.RightToLeft;
+ this.view = new PrintableView(this.Document, this.render,this.Padding);
+ this.view.PageBound = e.MarginBounds;
+ this.PageNumber = 1;
+ this.view.PerfomLayouts();
+ }
+
+ if (e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages)
+ {
+ for (; this.PageNumber < e.PageSettings.PrinterSettings.FromPage; this.PageNumber++)
+ {
+ if (this.view.TryPageDown())
+ return;
+ }
+ }
+
+ this.view.Header = this.ParseHF(this, new ParseCommandEventArgs(this.PageNumber, e.PageSettings.PrinterSettings,this.Header));
+ this.view.Footer = this.ParseHF(this, new ParseCommandEventArgs(this.PageNumber, e.PageSettings.PrinterSettings, this.Footer));
+
+ this.render.BeginDraw(e.Graphics);
+
+ this.view.Draw(e.MarginBounds);
+
+ e.HasMorePages = !this.view.TryPageDown();
+
+ this.render.EndDraw();
+
+ this.PageNumber++;
+
+ if (e.HasMorePages && e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages && this.PageNumber > e.PageSettings.PrinterSettings.ToPage)
+ e.HasMorePages = false;
+ }
+
+ void PrintDocument_EndPrint(object sender, PrintEventArgs e)
+ {
+ this.view.Dispose();
+ this.view = null;
+ this.render = null;
+ }
+
+ }
+}
{
get
{
- return this.View.MarkerPatternSet;
+ return this.Document.MarkerPatternSet;
}
}
{
get
{
- return this.View.DrawLineNumber;
+ return this.Document.DrawLineNumber;
}
set
{
- this.View.DrawLineNumber = value;
+ this.Document.DrawLineNumber = value;
this.JumpCaret(this.CaretPostion.row,this.CaretPostion.col);
}
}
{
get
{
- return !this.View.HideRuler;
+ return !this.Document.HideRuler;
}
set
{
- this.View.HideRuler = !value;
+ this.Document.HideRuler = !value;
this.JumpCaret(this.CaretPostion.row, this.CaretPostion.col);
}
}
{
get
{
- return this.View.LineBreak;
+ return this.Document.LineBreak;
}
set
{
- this.View.LineBreak = value;
+ this.Document.LineBreak = value;
}
}
{
get
{
- return this.View.LineBreakCharCount;
+ return this.Document.LineBreakCharCount;
}
set
{
- this.View.LineBreakCharCount = value;
+ this.Document.LineBreakCharCount = value;
}
}
{
get
{
- return this.View.UrlMark;
+ return this.Document.UrlMark;
}
set
{
- this.View.UrlMark = value;
+ this.Document.UrlMark = value;
}
}
[DefaultValue(4)]
public int TabStops
{
- get { return this.View.TabStops; }
+ get { return this.Document.TabStops; }
set {
- this.View.TabStops = value;
+ this.Document.TabStops = value;
this.View.AdjustCaretAndSrc();
this.TabStopChange(this, null);
}
[BrowsableAttribute(false)]
public TextPoint CaretPostion
{
- get { return this.View.CaretPostion; }
+ get { return this.Document.CaretPostion; }
}
/// <summary>
if (e.Control)
this.Controller.JumpToHead(e.Shift);
else
- this.Controller.JumpToLineHead(this.View.CaretPostion.row, e.Shift);
+ this.Controller.JumpToLineHead(this.Document.CaretPostion.row, e.Shift);
this.Refresh();
break;
case Keys.End:
if (e.Control)
this.Controller.JumpToEnd(e.Shift);
else
- this.Controller.JumpToLineEnd(this.View.CaretPostion.row, e.Shift);
+ this.Controller.JumpToLineEnd(this.Document.CaretPostion.row, e.Shift);
this.Refresh();
break;
case Keys.Tab:
void Timer_Tick(object sender,EventArgs e)
{
- if (this.View.CaretPostion.row >= this.View.LayoutLines.Count || DesignMode)
+ if (this.Document.CaretPostion.row >= this.View.LayoutLines.Count || DesignMode)
return;
- ITextLayout layout = this.View.LayoutLines.GetLayout(this.View.CaretPostion.row);
+ ITextLayout layout = this.View.LayoutLines.GetLayout(this.Document.CaretPostion.row);
Size redrawSize = new Size();
- redrawSize.Width = layout.GetWidthFromIndex(this.View.CaretPostion.col);
+ redrawSize.Width = layout.GetWidthFromIndex(this.Document.CaretPostion.col);
if (redrawSize.Width == 0.0)
redrawSize.Width = this.View.CaretWidthOnInsertMode;
redrawSize.Height = layout.Height;