+ /// <summary>
+ /// スクロールを試行する
+ /// </summary>
+ /// <param name="offset_x">X方向の移動量</param>
+ /// <param name="offset_y">Y方向の移動量</param>
+ /// <returns>成功すれば偽、そうでなければ真</returns>
+ public virtual bool TryScroll(double offset_x,double offset_y)
+ {
+ double x = this.Document.Src.X - offset_x;
+ if (x < 0)
+ return true;
+ var t = GetNearstRowAndOffsetY(this.Document.Src.Row, -this.Document.Src.OffsetY + offset_y);
+ if (t == null)
+ return true;
+ this.Document.Src = new SrcPoint(x, t.Item1, -t.Item2);
+ return false;
+ }
+
+ /// <summary>
+ /// srcRowを起点としてrect_heightが収まる行とオフセットYを求めます
+ /// </summary>
+ /// <param name="srcRow">起点となる行</param>
+ /// <param name="rect_hight">Y方向のバウンディングボックス</param>
+ /// <returns>失敗した場合、NULL。成功した場合、行とオフセットY</returns>
+ public Tuple<int,double> GetNearstRowAndOffsetY(int srcRow, double rect_hight)
+ {
+ if (rect_hight > 0)
+ {
+ for (int i = srcRow; i < this.Document.LayoutLines.Count; i++)
+ {
+ ITextLayout layout = this.Document.LayoutLines.GetLayout(i);
+
+ int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
+ int lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
+ double layoutHeight = layout.Height;
+
+ if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
+ continue;
+
+ if (rect_hight == 0)
+ return new Tuple<int, double>(i, 0);
+
+ if (rect_hight - layoutHeight < 0)
+ return new Tuple<int, double>(i, rect_hight);
+
+ rect_hight -= layoutHeight;
+ }
+ }
+ else if(rect_hight < 0)
+ {
+ for (int i = srcRow - 1; i >= 0; i--)
+ {
+ ITextLayout layout = this.Document.LayoutLines.GetLayout(i);
+
+ int lineHeadIndex = this.LayoutLines.GetIndexFromLineNumber(i);
+ int lineLength = this.LayoutLines.GetLengthFromLineNumber(i);
+ double layoutHeight = layout.Height;
+
+ if (this.LayoutLines.FoldingCollection.IsHidden(lineHeadIndex))
+ continue;
+
+ if(rect_hight == 0)
+ return new Tuple<int, double>(i, 0);
+
+ if (rect_hight + layoutHeight >= 0)
+ return new Tuple<int, double>(i, layoutHeight + rect_hight);
+
+ rect_hight += layoutHeight;
+ }
+ return new Tuple<int, double>(0, 0);
+ }
+ return null;
+ }
+