void SetSelectionLocation(StringBox sbox, int left, int right) { var fakeSeg = (FakeSegment)sbox.Segment; fakeSeg.LeftPositionOfRangeResult = left; fakeSeg.RightPositionOfRangeResult = right; }
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"); }
private void VerifyRangeSegmentDrawing(ParaBox para, StringBox stringBox, RangeSelection range, int top, int ydTop, int bottom) { var seg = stringBox.Segment as FakeSegment; Assert.AreEqual(stringBox.IchMin, seg.LastDrawRangeCall.IchBase); Assert.AreEqual(m_gm.VwGraphics, seg.LastDrawRangeCall.Graphics); int startPosition = range.Start.StringPosition; if (range.Start.Para != stringBox.Container) // If we're painting this string box but it isn't in the start paragraph, { startPosition = 0; // the we paint from the start of it. } Assert.AreEqual(startPosition, seg.LastDrawRangeCall.IchMin); var endPosition = range.End.StringPosition; if (range.End.Para != stringBox.Container) // If we're painting this string box but it isn't in the end paragraph, { endPosition = ((ParaBox)stringBox.Container).Source.RenderText.Length; // then we paint to the end of the paragraph. } Assert.AreEqual(endPosition, seg.LastDrawRangeCall.IchLim); ParaTests.VerifySimpleRect(seg.LastDrawRangeCall.RcSrc, -2, top, 96, 96); ParaTests.VerifySimpleRect(seg.LastDrawRangeCall.RcDst, 0, 0, 96, 96); 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); }
/// <summary> /// Assuming the first box in the root is a paragraph, and its first box is a string box with a mock segment, return it. /// </summary> /// <param name="root"></param> /// <returns></returns> MockSegment FirstMockSegment(RootBox root) { ParaBox pb = root.FirstBox as ParaBox; StringBox first = pb.FirstBox as StringBox; return(first.Segment as MockSegment); }
/// <summary> /// Assuming the first box in the root is a paragraph, and its second box is a string box with a mock segment, return it. /// </summary> /// <param name="root"></param> /// <returns></returns> MockSegment SecondMockSegment(RootBox root) { ParaBox pb = root.FirstBox as ParaBox; StringBox second = pb.FirstBox.Next as StringBox; return(second.Segment as MockSegment); }
int IchMinOfSecondStringBox(RootBox root) { ParaBox pb = root.FirstBox as ParaBox; StringBox second = pb.FirstBox.Next as StringBox; return(second.IchMin); }
Point TopLeftOfSecondStringBox(RootBox root) { ParaBox pb = root.FirstBox as ParaBox; StringBox second = pb.FirstBox.Next as StringBox; return(second.TopLeft); }
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); }
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"); }
/// <summary> /// Find all letters that are not in the anagram /// </summary> /// <returns>Set of letters not in the anagram</returns> public StringBox CreateSetOfLettersNotInAnagram() { string allLettersA2Z = "abcdefghijklmnopqrstuvxyz"; string someMoreLettersSeenInWordList = "éÅöü'"; string allLettersExpectedInWordList = allLettersA2Z + someMoreLettersSeenInWordList; var lettersNotInAnagram1 = allLettersExpectedInWordList.Except(_anagram.DistinctDataWithoutSpace); string lettersNotInAnagram = String.Concat(lettersNotInAnagram1); _lettersNotInAnagram = new StringBox(lettersNotInAnagram); return(_lettersNotInAnagram); }
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"); }
protected override Box __TranslateWord(Expr expr, string op, Syntax.TType type) { /* This is really a hack :-( */ StringBox sb = new StringBox(expr, op, type); if (type == Syntax.TType.LargeOp && Array.BinarySearch(limitwordops, op) < 0) { return(new AtomBox(null, sb, null, null, Syntax.TType.LargeOp, AtomBox.LimitsType.NoLimits)); } else { return(sb); } }
protected override Box __Translate(WordSym s) { /* TODO: need to handle accent, format */ StringBox sb = new StringBox(s, s.Word, Syntax.TType.Ord); if (s.Subscript != new NullExpr()) { return(new AtomBox(null, sb, Translate(s.Subscript), null, Syntax.TType.Ord)); } else { return(sb); } }
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 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); }
public void DrawIPMultiRunPara() { var styles = new AssembledStyles(); RootBox root = new RootBoxFdo(styles); root.Builder.Show(Paragraph.Containing( Display.Of("first"), Display.Of("second"), Display.Of("third"))); SetupFakeRootSite(root); var layoutInfo = HookupTests.MakeLayoutInfo(int.MaxValue / 2, m_gm.VwGraphics, 55); root.Layout(layoutInfo); InsertionPoint ip = root.SelectAtEnd(); ip.Install(); var para = (ParaBox)root.FirstBox; Assert.AreEqual(ip, root.Selection); Assert.AreEqual(para, ip.Para, "IP should know about the paragraph it is in"); Assert.AreEqual("third".Length, ip.StringPosition, "IP position is relative to run"); Assert.AreEqual(true, ip.AssociatePrevious, "selection at end should always associate previous in non-empty para"); StringBox sbox = para.FirstBox as StringBox; Assert.That(sbox, Is.EqualTo(para.LastBox), "uniform text in infinite width should make one string box"); var seg = sbox.Segment as FakeSegment; Assert.IsNotNull(seg); PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, -10, 120, 128); ip.Draw(m_gm.VwGraphics, ptrans); VerifySegmentDrawing(para, sbox, seg.LastDrawIpCall, -4); seg.NextPosIpResult = new MockSegment.PositionsOfIpResults(); seg.NextPosIpResult.RectPrimary = new Rect(5, 6, 7, 9); seg.NextPosIpResult.PrimaryHere = true; Rectangle selRect = ip.GetSelectionLocation(m_gm.VwGraphics, ptrans); VerifySelLocation(para, sbox, seg.LastPosIpCall, -4); Assert.AreEqual(new Rectangle(5, 6, 2, 3), selRect); }
protected internal override void OnMouseUp(object sender, MouseEventArgs e) { base.OnMouseUp(sender, e); if (InUse) { if (_options == null) { _options = new TextToolForm(); _options.ShowDialog(); if (_options.DialogResult == DialogResult.OK && _options.Text.Length > 0) { var o = _options; StringBox textBox = new StringBox(_position1, _position2, o.Text, o.Font, o.TextColor); canvas.Add(textBox); canvas.Refresh(); canvas.Tool = Pointer.GetInstance(); } } else { var o = _options; StringBox textBox = new StringBox(_position1, _position2, o.Text, o.Font, o.TextColor); canvas.Add(textBox); canvas.Refresh(); canvas.Tool = Pointer.GetInstance(); } _selection = null; _options = null; InUse = false; canvas.Invalidate(); } }
public AnagramContainer(StringBox anagram, string[] md5Hashes) { _anagram = anagram; _md5Hashes = md5Hashes; }
private void ConsiderPairSpacing() { if (A == null || B == null) { return; } Box a = A.Final.Target; Box b = B.Final.Target; /* Do TeX atom type and spacing fixup rules from p 170 and appendix G */ Syntax.TType atype = GetTType(a), btype = GetTType(b); /* rule 20 */ int spacing = IBSpacing[(int)atype, (int)btype]; Trace.Assert(spacing != 5); Box space = null; switch (spacing) { case 0: // all the code for this case is *not* part of TeX's rule 20. It comes from p 169 and applies specifically to factorial // operators, so won't be correct for other possible uses of '!' if (atype == Syntax.TType.Ord && a is CharBox && ((CharBox)a).C == '!') { CharBox cb = b as CharBox; StringBox sb = b as StringBox; AtomBox ab = b as AtomBox; if ((btype == Syntax.TType.Ord && ((cb != null && (Char.IsLetter(cb.C) || Char.IsDigit(cb.C))) || (sb != null && (Char.IsLetter(sb.S, 0) || Char.IsDigit(sb.S, 0))))) || btype == Syntax.TType.Open) { space = ThinSkip(); } else if (btype == Syntax.TType.Ord && ab != null) { cb = ab.Nucleus as CharBox; sb = ab.Nucleus as StringBox; if ((cb != null && (Char.IsLetter(cb.C) || Char.IsDigit(cb.C))) || (sb != null && (Char.IsLetter(sb.S, 0) || Char.IsDigit(sb.S, 0)))) { space = ThinSkip(); } } } break; case 1: space = ThinSkip(); break; case 2: space = MedSkip(); break; case 3: space = ThickSkip(); break; case -1: space = DTThinSkip(); break; case -2: space = DTMedSkip(); break; case -3: space = DTThickSkip(); break; } /* apply the spacing */ if (space != null) { /* Find the lowest common ancestor */ int found = -1; for (int i = 0; i < A.P.Count && i < B.P.Count; i++) { if (A.P[i].Target != B.P[i].Target) { found = i; break; } } Trace.Assert(found != -1, "adjacent boxes are the same?"); Trace.Assert(A.P[found].B == B.P[found].B); Trace.Assert(A.P[found].GetType() == B.P[found].GetType()); List <Box> boxes; int ix; if (A.P[found] is HBoxLink) { HBoxLink hba = (HBoxLink)A.P[found]; HBoxLink hbb = (HBoxLink)B.P[found]; Trace.Assert(hba.I < hbb.I); for (int i = hba.I + 1; i < hbb.I; i++) { Trace.Assert(hba.HB.Boxes[i] is MuSkipBox || hba.HB.Boxes[i] is DTMuSkipBox); } boxes = hba.HB.Boxes; ix = hbb.I; } else { DelimitedBoxLink dba = (DelimitedBoxLink)A.P[found]; DelimitedBoxLink dbb = (DelimitedBoxLink)B.P[found]; boxes = dba.DB.Contents.Boxes; if (dba.Piece == DelimitedBoxLink.Which.Left) { Trace.Assert(dbb.Piece != DelimitedBoxLink.Which.Left); ix = 0; } else { Trace.Assert(dba.Piece == DelimitedBoxLink.Which.Contents); Trace.Assert(dbb.Piece == DelimitedBoxLink.Which.Right); ix = boxes.Count; } } SortedDictionary <int, Box> inserts; if (!_listBoxInserts.TryGetValue(boxes, out inserts)) { inserts = new SortedDictionary <int, Box>(); _listBoxInserts[boxes] = inserts; } inserts.Add(ix, space); } }
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 VerifyRangeSegmentDrawing(ParaBox para, StringBox stringBox, FakeSegment seg, int ichMin, int ichLim, int top, int ydTop, int bottom) { var args = seg.LastDrawRangeCall; VerifyRangeDrawingArgs(args, stringBox, ichMin, ichLim, top, ydTop, bottom); }
public StringPromptWindow() { InitializeComponent(); StringBox.Focus(); }
private void VerifyRangeSegmentQuery(ParaBox para, StringBox stringBox, FakeSegment seg, int ichMin, int ichLim, int top, int ydTop, int bottom) { var args = seg.LastPositionOfRangeArgs; VerifyRangeDrawingArgs(args, stringBox, ichMin, ichLim, top, ydTop, bottom); }
private void ClearSegmentDrawing(StringBox sbox) { var fakeSeg = (FakeSegment)sbox.Segment; fakeSeg.LastDrawRangeCall = null; }