public void MakeSimpleRange() { ParaBox para; RootBox root = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para); InsertionPoint ip = root.SelectAtEnd(); InsertionPoint ip2 = new InsertionPoint(ip.Hookup, ip.StringPosition - 2, false); RangeSelection range = new RangeSelection(ip, ip2); Assert.AreEqual(ip, range.Anchor); Assert.AreEqual(ip2, range.DragEnd); Assert.That(range.EndBeforeAnchor, Is.True); Assert.That(range.Start, Is.EqualTo(ip2)); Assert.That(range.End, Is.EqualTo(ip)); StringBox first = para.FirstBox as StringBox; StringBox second = para.FirstBox.Next as StringBox; StringBox third = second.Next as StringBox; MockSegment seg3 = third.Segment as MockSegment; seg3.DrawRangeLeft = 17; seg3.DrawRangeRight = 23; PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, 10, 120, 128); range.Draw(m_gm.VwGraphics, ptrans); // All three segments should be invited to draw it, though only one will. // The top of rsSrc gets more negative each line; the destination rectangle where we actually draw keeps getting lower. // Remember the effect of 10 pixels of scroll offset. VerifyRangeSegmentDrawing(para, first, first.Segment as MockSegment, range, -4, -6, 4); VerifyRangeSegmentDrawing(para, second, second.Segment as MockSegment, range, -14, 4, 14); VerifyRangeSegmentDrawing(para, third, seg3, range, -24, 14, 24); }
// If the caller asks to find a break and passes the specified args, return a segment with the specified properties. internal void AddMockSeg(int ichMin, int ichLim, int len, int width, int ws, LgEndSegmentType est) { var seg = new MockSegment(len, width, ws, est); m_potentialSegs[new MockSegKey(ichMin, ichLim)] = seg; m_potentialSegsInOrder.Add(seg); }
public void DrawIP() { ParaBox para; RootBox root = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para); InsertionPoint ip = root.SelectAtEnd(); ip.Install(); Assert.AreEqual(ip, root.Selection); Assert.AreEqual(para, ip.Para, "IP should know about the paragraph it is in"); Assert.AreEqual(para.Source.Length, ip.StringPosition, "the IP should be at the end of the paragraph"); Assert.AreEqual(true, ip.AssociatePrevious, "selection at end should always associate previous in non-empty para"); StringBox third = para.FirstBox.Next.Next as StringBox; Assert.IsNotNull(third, "para with three simple lines should have three string boxes"); MockSegment seg3 = third.Segment as MockSegment; Assert.IsNotNull(seg3); PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, -10, 120, 128); ip.Draw(m_gm.VwGraphics, ptrans); StringBox first = para.FirstBox as StringBox; StringBox second = para.FirstBox.Next as StringBox; // All three segments should be invited to draw it, though only one will. var seg1 = first.Segment as MockSegment; VerifySegmentDrawing(para, first, seg1, -4); var seg2 = second.Segment as MockSegment; VerifySegmentDrawing(para, second, seg2, -14); VerifySegmentDrawing(para, third, seg3, -24); seg1.NextPosIpResult = new MockSegment.PositionsOfIpResults(); seg1.NextPosIpResult.PrimaryHere = false; seg2.NextPosIpResult = new MockSegment.PositionsOfIpResults(); seg2.NextPosIpResult.PrimaryHere = false; seg3.NextPosIpResult = new MockSegment.PositionsOfIpResults(); seg3.NextPosIpResult.RectPrimary = new Rect(5, 6, 7, 9); seg3.NextPosIpResult.PrimaryHere = true; Rectangle selRect = ip.GetSelectionLocation(m_gm.VwGraphics, ptrans); // All three should be asked for the position, though only the third returns a useful one. VerifySelLocation(para, first, seg1, -4); VerifySelLocation(para, second, seg2, -14); VerifySelLocation(para, third, seg3, -24); Assert.AreEqual(new Rectangle(5, 6, 2, 3), selRect); // The final thing that goes into drawing IPs is the Invalidate call. MockSite site = new MockSite(); site.m_transform = ptrans; site.m_vwGraphics = m_gm.VwGraphics; root.Site = site; ip.Invalidate(); Assert.IsNotNull(site.GraphicsHolder, "Invalidate should have created a Graphics holder"); Assert.IsTrue(site.GraphicsHolder.WasDisposed, "invalidate should have disposed of the Graphics Holder"); Assert.AreEqual(1, site.RectsInvalidated.Count, "invalidate should have invalidated one rectangle"); Assert.AreEqual(new Rectangle(5, 6, 2, 3), site.RectsInvalidated[0], "invalidate should have invalidated the selection rectangle"); }
public void FindBreakPoint(IVwGraphics vg, IVwTextSource _ts, IVwJustifier _vjus, int ichMin, int ichLim, int ichLimBacktrack, bool fNeedFinalBreak, bool fStartLine, int dxMaxWidth, LgLineBreak lbPref, LgLineBreak lbMax, LgTrailingWsHandling twsh, bool fParaRightToLeft, out ILgSegment segRet, out int dichLimSeg, out int dxWidth, out LgEndSegmentType est, ILgSegment _segPrev) { MockSegment seg; var key = new MockSegKey(ichMin, ichLim); if (lbPref != LgLineBreak.klbClipBreak && m_failOnPartialLine.Contains(key)) { // fail. segRet = null; dichLimSeg = 0; dxWidth = 0; est = LgEndSegmentType.kestNothingFit; return; } if (m_potentialSegs.TryGetValue(key, out seg)) { if (seg.Width < dxMaxWidth) // otherwise we meant it for the next line. { segRet = seg; dichLimSeg = seg.get_Lim(ichMin); dxWidth = seg.get_Width(ichMin, vg); est = seg.EndSegType; return; } } switch (OtherSegPolicy) { case UnexpectedSegments.DontFit: default: // to make compiler happy Assert.AreNotEqual(LgLineBreak.klbClipBreak, lbMax, "FindBreakPoint called with unexpected arguments."); // If we aren't pre-prepared for the requested break, assume nothing fits with these arguments. segRet = null; dichLimSeg = 0; dxWidth = 0; est = LgEndSegmentType.kestNothingFit; break; case UnexpectedSegments.MakeOneCharSeg: // Make a very narrow segment that will fit and allow more stuff. This will usually give a test failure if not intentional. seg = new MockSegment(1, 2, 1, LgEndSegmentType.kestOkayBreak); // If we aren't pre-prepared for the requested break, assume nothing fits with these arguments. segRet = seg; dichLimSeg = 1; dxWidth = 2; est = LgEndSegmentType.kestOkayBreak; break; } }
public void FindBreakPoint(IVwGraphics vg, IVwTextSource _ts, IVwJustifier _vjus, int ichMin, int ichLim, int ichLimBacktrack, bool fNeedFinalBreak, bool fStartLine, int dxMaxWidth, LgLineBreak lbPref, LgLineBreak lbMax, LgTrailingWsHandling twsh, bool fParaRightToLeft, out ILgSegment segRet, out int dichLimSeg, out int dxWidth, out LgEndSegmentType est, ILgSegment _segPrev) { MockSegment seg; var key = new MockSegKey(ichMin, ichLim); if (lbPref != LgLineBreak.klbClipBreak && m_failOnPartialLine.Contains(key)) { // fail. segRet = null; dichLimSeg = 0; dxWidth = 0; est = LgEndSegmentType.kestNothingFit; return; } if (m_potentialSegs.TryGetValue(key, out seg)) { if (seg.Width < dxMaxWidth) // otherwise we meant it for the next line. { segRet = seg; dichLimSeg = seg.get_Lim(ichMin); dxWidth = seg.get_Width(ichMin, vg); est = seg.EndSegType; return; } } switch(OtherSegPolicy) { case UnexpectedSegments.DontFit: default: // to make compiler happy Assert.AreNotEqual(LgLineBreak.klbClipBreak, lbMax, "FindBreakPoint called with unexpected arguments."); // If we aren't pre-prepared for the requested break, assume nothing fits with these arguments. segRet = null; dichLimSeg = 0; dxWidth = 0; est = LgEndSegmentType.kestNothingFit; break; case UnexpectedSegments.MakeOneCharSeg: // Make a very narrow segment that will fit and allow more stuff. This will usually give a test failure if not intentional. seg = new MockSegment(1, 2, 1, LgEndSegmentType.kestOkayBreak); // If we aren't pre-prepared for the requested break, assume nothing fits with these arguments. segRet = seg; dichLimSeg = 1; dxWidth = 2; est = LgEndSegmentType.kestOkayBreak; break; } }
private void VerifyRangeSegmentDrawing(ParaBox para, StringBox stringBox, MockSegment seg, RangeSelection range, int top, int ydTop, int bottom) { Assert.AreEqual(stringBox.IchMin, seg.LastDrawRangeCall.IchBase); Assert.AreEqual(m_gm.VwGraphics, seg.LastDrawRangeCall.Graphics); Assert.AreEqual(range.Start.StringPosition, seg.LastDrawRangeCall.IchMin); Assert.AreEqual(range.End.StringPosition, seg.LastDrawRangeCall.IchLim); ParaTests.VerifySimpleRect(seg.LastDrawRangeCall.RcSrc, -2, top, 96, 100); ParaTests.VerifySimpleRect(seg.LastDrawRangeCall.RcDst, 0, -10, 120, 128); Assert.AreEqual(ydTop, seg.LastDrawRangeCall.YdTop); Assert.AreEqual(bottom, seg.LastDrawRangeCall.YdBottom); Assert.AreEqual(seg.LastDrawRangeCall.On, true, "Should currently always pass true to segment drawRange On argument"); // The old Views code appears to always pass true for this argument, so we should too, until I figure out what it's // really supposed to be, if anything. Assert.AreEqual(true, seg.LastDrawRangeCall.IsLastLineOfSelection); }
private void VerifyRangeSegmentDrawing(ParaBox para, StringBox stringBox, MockSegment seg, RangeSelection range, int top, int ydTop, int bottom) { Assert.AreEqual(stringBox.IchMin, seg.LastDrawRangeCall.IchBase); Assert.AreEqual(m_gm.VwGraphics, seg.LastDrawRangeCall.Graphics); Assert.AreEqual(range.Start.StringPosition, seg.LastDrawRangeCall.IchMin); Assert.AreEqual(range.End.StringPosition, seg.LastDrawRangeCall.IchLim); ParaTests.VerifySimpleRect(seg.LastDrawRangeCall.RcSrc, -2, top, 96, 100); ParaTests.VerifySimpleRect(seg.LastDrawRangeCall.RcDst, 0, -10, 120, 128); Assert.AreEqual(ydTop, seg.LastDrawRangeCall.YdTop); Assert.AreEqual(bottom, seg.LastDrawRangeCall.YdBottom); Assert.AreEqual(seg.LastDrawRangeCall.On, true, "Should currently always pass true to segment drawRange On argument"); // The old Views code appears to always pass true for this argument, so we should too, until I figure out what it's // really supposed to be, if anything. Assert.AreEqual(true, seg.LastDrawRangeCall.IsLastLineOfSelection); }
public void SimpleString() { ParaBox para; RootBox root = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para); PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, -10, 120, 128); root.Paint(m_gm.VwGraphics, ptrans); ParaBox pb = root.FirstBox as ParaBox; Assert.IsNotNull(pb); StringBox first = pb.FirstBox as StringBox; Assert.IsNotNull(first); MockSegment seg1 = first.Segment as MockSegment; Assert.IsNotNull(seg1); Assert.AreEqual(m_gm.VwGraphics, seg1.LastDrawTextCall.vg); Assert.AreEqual(0, seg1.LastDrawTextCall.ichBase); VerifySimpleRect(seg1.LastDrawTextCall.rcSrc, -2, -4, 96, 100); VerifySimpleRect(seg1.LastDrawTextCall.rcDst, 0, 10, 120, 128); StringBox second = first.Next as StringBox; Assert.IsNotNull(second); MockSegment seg2 = second.Segment as MockSegment; Assert.IsNotNull(seg2); VerifySimpleRect(seg2.LastDrawTextCall.rcSrc, -2, -14, 96, 100); VerifySimpleRect(seg2.LastDrawTextCall.rcDst, 0, 10, 120, 128); StringBox third = second.Next as StringBox; Assert.IsNotNull(third); MockSegment seg3 = third.Segment as MockSegment; Assert.IsNotNull(seg3); VerifySimpleRect(seg3.LastDrawTextCall.rcSrc, -2, -24, 96, 100); VerifySimpleRect(seg3.LastDrawTextCall.rcDst, 0, 10, 120, 128); Assert.AreEqual(root, third.Root); }
// If the caller asks to find a break and passes the specified args, return a segment with the specified properties. internal void AddMockSeg(int ichMin, int ichLim, int len, int width, int ws, LgEndSegmentType est) { var seg = new MockSegment(len, width, ws, est); m_potentialSegs[new MockSegKey(ichMin, ichLim)] = seg; m_potentialSegsInOrder.Add(seg); }
private void VerifyRangeDrawingArgs(MockSegment.DrawRangeArgs args, StringBox stringBox, int ichMin, int ichLim, int top, int ydTop, int bottom) { Assert.AreEqual(stringBox.IchMin, args.IchBase); Assert.AreEqual(m_gm.VwGraphics, args.Graphics); Assert.That(args.IchMin, Is.EqualTo(ichMin)); Assert.That(args.IchLim, Is.EqualTo(ichLim)); ParaTests.VerifySimpleRect(args.RcSrc, -2, top, 96, 96); ParaTests.VerifySimpleRect(args.RcDst, 0, -10, 96, 96); Assert.AreEqual(ydTop, args.YdTop); Assert.AreEqual(bottom, args.YdBottom); Assert.AreEqual(args.On, true, "Should currently always pass true to segment drawRange On argument"); // The old Views code appears to always pass true for this argument, so we should too, until I figure out what it's // really supposed to be, if anything. Assert.AreEqual(true, args.IsLastLineOfSelection); }
private void VerifySegmentDrawing(ParaBox para, StringBox third, MockSegment.DrawInsertionPointArgs drawInsertionPointArgs, int top) { Assert.AreEqual(third.IchMin, drawInsertionPointArgs.IchBase); Assert.AreEqual(m_gm.VwGraphics, drawInsertionPointArgs.Graphics); Assert.AreEqual(true, drawInsertionPointArgs.AssocPrev, "assoc prev should match IP"); ParaTests.VerifySimpleRect(drawInsertionPointArgs.RcSrc, -2, top, 96, 100); ParaTests.VerifySimpleRect(drawInsertionPointArgs.RcDst, 0, 10, 120, 128); Assert.AreEqual(drawInsertionPointArgs.Ich, para.Source.Length); Assert.AreEqual(drawInsertionPointArgs.On, true, "Should currently always pass true to segment drawIP routine"); Assert.AreEqual(drawInsertionPointArgs.DrawMode, LgIPDrawMode.kdmNormal, "all drawing modes normal till we test BIDI with Graphite"); }
private void VerifySegmentDrawing(ParaBox para, StringBox third, MockSegment seg3, int top) { VerifySegmentDrawing(para, third, seg3.LastDrawIpCall, top); }
private void VerifySelLocation(ParaBox para, StringBox third, MockSegment.PositionsOfIpArgs positionsOfIpArgs, int top) { Assert.AreEqual(third.IchMin, positionsOfIpArgs.IchBase); Assert.AreEqual(m_gm.VwGraphics, positionsOfIpArgs.Graphics); Assert.AreEqual(true, positionsOfIpArgs.AssocPrev, "assoc prev should match IP"); ParaTests.VerifySimpleRect(positionsOfIpArgs.RcSrc, -2, top, 96, 100); ParaTests.VerifySimpleRect(positionsOfIpArgs.RcDst, 0, 10, 120, 128); Assert.AreEqual(positionsOfIpArgs.Ich, para.Source.Length); Assert.AreEqual(positionsOfIpArgs.DrawMode, LgIPDrawMode.kdmNormal, "all drawing modes normal till we test BIDI with Graphite"); }
private void VerifySelLocation(ParaBox para, StringBox third, MockSegment seg3, int top) { VerifySelLocation(para, third, seg3.LastPosIpCall, top); }
private void VerifySegmentDrawing(ParaBox para, StringBox third, MockSegment seg3, int top) { VerifySegmentDrawing(para, third, seg3.LastDrawIpCall, top); }
private void VerifySelLocation(ParaBox para, StringBox third, MockSegment seg3, int top) { VerifySelLocation(para, third, seg3.LastPosIpCall, top); }