public void SplitEmptyTest() { var result = TextSplitHelper.SplitText(string.Empty, -1, 0, 1000, 1000).ToArray(); Assert.IsNotNull(result); Assert.AreEqual(0, result.Length); }
public void SplitMultipleLines4() { var result = TextSplitHelper.SplitText("12345 67890 ABCDE FGHI 1234567890ABCDEFGHIJK 134567 89 0123456", invertStart: -1, invertLength: 0, maxLength: 11, maxLengthFirstLine: 11).ToArray(); Assert.IsNotNull(result); Assert.AreEqual(5, result.Length); Assert.AreEqual("12345 67890", result[0].Text); Assert.IsFalse(result[0].Inverted); Assert.AreEqual(0, result[0].LineNo); Assert.AreEqual(" ABCDE FGHI", result[1].Text); Assert.IsFalse(result[1].Inverted); Assert.AreEqual(1, result[1].LineNo); Assert.AreEqual(" 1234567890ABCDEFGHIJK", result[2].Text); Assert.IsFalse(result[2].Inverted); Assert.AreEqual(2, result[2].LineNo); Assert.AreEqual(" 134567 89", result[3].Text); Assert.IsFalse(result[3].Inverted); Assert.AreEqual(3, result[3].LineNo); Assert.AreEqual(" 0123456", result[4].Text); Assert.IsFalse(result[4].Inverted); Assert.AreEqual(4, result[4].LineNo); }
public void SplitMultipleInvertedLines4() { var result = TextSplitHelper.SplitText("OOOOO OOOOO OOIII IIII IIIIIIIIIIIIIIII IIIOO OO OOOOOOO", invertStart: 14, invertLength: 29, maxLength: 11, maxLengthFirstLine: 11).ToArray(); Assert.IsNotNull(result); Assert.AreEqual(7, result.Length); Assert.AreEqual("OOOOO OOOOO", result[0].Text); Assert.IsFalse(result[0].Inverted); Assert.AreEqual(0, result[0].LineNo); Assert.AreEqual(" OO", result[1].Text); Assert.IsFalse(result[1].Inverted); Assert.AreEqual(1, result[1].LineNo); Assert.AreEqual("III IIII", result[2].Text); Assert.IsTrue(result[2].Inverted); Assert.AreEqual(1, result[2].LineNo); Assert.AreEqual(" IIIIIIIIIIIIIIII", result[3].Text); Assert.IsTrue(result[3].Inverted); Assert.AreEqual(2, result[3].LineNo); Assert.AreEqual(" III", result[4].Text); Assert.IsTrue(result[4].Inverted); Assert.AreEqual(3, result[4].LineNo); Assert.AreEqual("OO OO", result[5].Text); Assert.IsFalse(result[5].Inverted); Assert.AreEqual(3, result[5].LineNo); Assert.AreEqual(" OOOOOOO", result[6].Text); Assert.IsFalse(result[6].Inverted); Assert.AreEqual(4, result[6].LineNo); }
public void SplitMixInvertedAndNewLine() { var result = TextSplitHelper.SplitText("OOOII IIOOO OOOOO OOOOO", invertStart: 3, invertLength: 5, maxLength: 5, maxLengthFirstLine: 5).ToArray(); Assert.IsNotNull(result); Assert.AreEqual("OOO", result[0].Text); Assert.IsFalse(result[0].Inverted); Assert.AreEqual(0, result[0].LineNo); Assert.AreEqual("II", result[1].Text); Assert.IsTrue(result[1].Inverted); Assert.AreEqual(0, result[1].LineNo); Assert.AreEqual(" II", result[2].Text); Assert.IsTrue(result[2].Inverted); Assert.AreEqual(1, result[2].LineNo); Assert.AreEqual("OOO", result[3].Text); Assert.IsFalse(result[3].Inverted); Assert.AreEqual(1, result[3].LineNo); Assert.AreEqual(" OOOOO", result[4].Text); Assert.IsFalse(result[4].Inverted); Assert.AreEqual(2, result[4].LineNo); Assert.AreEqual(" OOOOO", result[5].Text); Assert.IsFalse(result[5].Inverted); Assert.AreEqual(3, result[5].LineNo); Assert.AreEqual(6, result.Length); }
public void SplitOneCharTest() { var result = TextSplitHelper.SplitText("A", -1, 0, 1000, 1000).ToArray(); Assert.IsNotNull(result); Assert.AreEqual(1, result.Length); Assert.AreEqual("A", result[0].Text); Assert.IsFalse(result[0].Inverted); Assert.AreEqual(0, result[0].LineNo); }
public void SplitInvertedNothing1() { var result = TextSplitHelper.SplitText("12345 67890 ABCDE", 0, 17, 1000, 1000).ToArray(); Assert.IsNotNull(result); Assert.AreEqual(1, result.Length); Assert.AreEqual("12345 67890 ABCDE", result[0].Text); Assert.IsTrue(result[0].Inverted); Assert.AreEqual(0, result[0].LineNo); }
public void SplitMultipleLines2() { var result = TextSplitHelper.SplitText("12345 67890 ABCDE", -1, 0, 15, 15).ToArray(); Assert.IsNotNull(result); Assert.AreEqual(2, result.Length); Assert.AreEqual("12345 67890", result[0].Text); Assert.AreEqual(" ABCDE", result[1].Text); Assert.IsFalse(result[0].Inverted); Assert.IsFalse(result[1].Inverted); Assert.AreEqual(0, result[0].LineNo); Assert.AreEqual(1, result[1].LineNo); }
public void SplitInvertedTest1() { var result = TextSplitHelper.SplitText("1234567890ABCDE", 10, 5, 1000, 1000).ToArray(); Assert.IsNotNull(result); Assert.AreEqual(2, result.Length); Assert.AreEqual("1234567890", result[0].Text); Assert.IsFalse(result[0].Inverted); Assert.AreEqual(0, result[0].LineNo); Assert.AreEqual("ABCDE", result[1].Text); Assert.IsTrue(result[1].Inverted); Assert.AreEqual(0, result[1].LineNo); }
protected override async Task <PaintContext> PaintInternal(PaintContext paintContext, bool cursorBlinkOn, XmlCursor cursor, IGraphics gfx, PaintModes paintMode, int depth) { paintContext.PaintPosX += 3; var actualText = ToolboxXml.TextFromNodeCleaned(XmlNode); var selection = this.CalculateStartAndEndOfSelection(actualText, cursor); var actualPaintData = LastPaintingDataText.CalculateActualPaintData(paintContext, cursorBlinkOn, this.XmlNode, actualText, this.Config.FontTextNode.Height, cursor, selection.Start, selection.Length); var alreadyUnpainted = false; switch (paintMode) { case PaintModes.ForcePaintNoUnPaintNeeded: alreadyUnpainted = true; this.lastPaintData = null; break; case PaintModes.ForcePaintAndUnpaintBefore: alreadyUnpainted = true; this.lastPaintData = null; this.UnPaint(gfx); break; case PaintModes.OnlyPaintWhenChanged: if (!actualPaintData.Equals(lastPaintData)) { this.lastPaintData = null; } break; } if (this.lastPaintData != null && this.lastPaintContextResult != null) { return(lastPaintContextResult.Clone()); } this.lastPaintData = actualPaintData; this.cursorPaintPos = null; if (lastFontHeight != this.Config.FontTextNode.Height) { lastFontHeight = this.Config.FontTextNode.Height; lastCalculatedFontWidth = await this.xmlEditor.NativePlatform.Gfx.MeasureDisplayStringWidthAsync("W", this.Config.FontTextNode); } paintContext.HeightActualRow = Math.Max(paintContext.HeightActualRow, this.Config.MinLineHeight); int marginY = (paintContext.HeightActualRow - this.Config.FontTextNode.Height) / 2; const int charMarginRight = 2; var textPartsRaw = TextSplitHelper.SplitText( text: actualText, invertStart: selection.Start, invertLength: selection.Length, maxLength: (int)((paintContext.LimitRight - paintContext.LimitLeft) / lastCalculatedFontWidth) - charMarginRight, maxLengthFirstLine: (int)((paintContext.LimitRight - paintContext.PaintPosX) / lastCalculatedFontWidth) - charMarginRight) .ToArray(); var newTextParts = this.GetTextLinesFromTextParts(textPartsRaw, paintContext, cursorBlinkOn, cursor, lastCalculatedFontWidth).ToArray(); // Now draw the content, if necessary wrap to several text parts and lines for (int i = 0; i < newTextParts.Length; i++) { var newPart = newTextParts[i]; var oldPart = (this.textParts != null && i < this.textParts.Length) ? this.textParts[i] : null; if (alreadyUnpainted == false && newPart.Equals(oldPart)) { // no need to paint the text part again } else { // draw the inverted background if (!alreadyUnpainted && oldPart != null) { gfx.UnPaintRectangle(oldPart.Rectangle); } if (newPart.Inverted || this.colorBackground != this.Config.ColorBackground) { gfx.AddJob(new JobDrawRectangle { Batchable = true, Layer = GfxJob.Layers.TagBackground, Rectangle = newPart.Rectangle, FillColor = newPart.Inverted ? this.colorBackground.InvertedColor : this.colorBackground, }); } // draw the text gfx.AddJob(new JobDrawString { Batchable = false, Layer = GfxJob.Layers.Text, Text = newPart.Text, Color = newPart.Inverted ? this.colorText.InvertedColor : this.colorText, X = newPart.Rectangle.X, Y = newPart.Rectangle.Y + marginY, Font = Config.FontTextNode });; } paintContext.PaintPosY = newPart.Rectangle.Y; paintContext.PaintPosX = newPart.Rectangle.X + newPart.Rectangle.Width; paintContext.FoundMaxX = Math.Max(paintContext.FoundMaxX, paintContext.PaintPosX); } if (this.textParts != null) // unpaint old text parts out of new parts range { for (int i = newTextParts.Length; i < this.textParts.Length; i++) { gfx.UnPaintRectangle(this.textParts[i].Rectangle); } } this.textParts = newTextParts; paintContext.PaintPosX += 2; this.lastPaintContextResult = paintContext.Clone(); return(paintContext.Clone()); }