public Stmt(TextLines InLines, StmtTraits InTraits) { string stmtText = InLines.ToString(); StmtWordListCursor csr = FirstPass_Common(stmtText, InTraits); Parse_Common(stmtText, csr, InTraits); }
static void Main(string[] args) { //Load the PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("../../../../../../Data/Invoice.pdf"); // Get the first page of the loaded PDF document PdfPageBase page = loadedDocument.Pages[0]; TextLines lineCollection = new TextLines(); // Extract text from the first page with bounds page.ExtractText(out lineCollection); RectangleF textBounds = new RectangleF(474, 161, 50, 9); string invoiceNumer = ""; //Get the text provided in the bounds foreach (TextLine txtLine in lineCollection) { foreach (TextWord word in txtLine.WordCollection) { if (textBounds.IntersectsWith(word.Bounds)) { invoiceNumer = word.Text; break; } } } //Close the PDF document loadedDocument.Close(true); File.WriteAllText("data.txt", invoiceNumer); }
// --------------------------- ScanNextWord ------------------------------- public static TextLinesWordCursor ScanNextWord( TextLines Lines, TextLinesWordCursor CurrentWord) { TextLinesWordCursor res = null; TextLinesCursor csr = null; TextLinesScanResults sr = null; // calc scan start position csr = ScanWord_CalcStartBx(Lines, CurrentWord); // advance past whitespace if ((csr.Position != RelativePosition.None) && (csr.Position != RelativePosition.End)) { sr = Lines.ScanNotEqual( csr, CurrentWord.TextTraits.WhitespacePatterns, ScannerEndOfLineConsider.ContinueScan); csr = sr.Pos; } // got the start of something. scan for the delimeter ( could be the current char ) if (csr.Position == RelativePosition.At) { //ScanWord_IsolateWord(InBoundedString, Bx, ref results, InCurrentWord.TextTraits); } return(res); }
protected override void SetupRender() { _textClass = new List <TextClass>(); _text = TextMode == TextMode.Normal || TextSource == TextSource.MarkCollection ? TextLines.Where(x => !String.IsNullOrEmpty(x)).ToList() : SplitTextIntoCharacters(TextLines); if (TextSource != TextSource.None) { SetupMarks(); } if (TargetPositioning == TargetPositioningType.Locations) { // Adjust the font size for Location support, default will ensure when swicthing between string and location that the Font will be the same visual size. // Font is further adjusted using the scale text slider. double newFontSize = ((StringCount - ((StringCount - Font.Size) / 100) * 100)) * ((double)BufferHt / StringCount); _font = new Font(Font.FontFamily.Name, (int)newFontSize, Font.Style); _newFontSize = _font.Size; return; } double scaleFactor = ScalingTools.GetScaleFactor(); _font = new Font(Font.FontFamily, Font.Size / (float)scaleFactor, Font.Style); _newFontSize = _font.Size; }
// ----------------------- ScanWord_CalcStartBx --------------------------- // calc start position from which to start scan to the next word. private static TextLinesCursor ScanWord_CalcStartBx( TextLines InLines, TextLinesWordCursor InWord) { // TextLinesNode linesNode = null; TextLinesCursor bx = null; switch (InWord.Position) { case RelativePosition.Begin: bx = InLines.PosBgn(); break; case RelativePosition.Before: break; case RelativePosition.After: break; case RelativePosition.End: bx = InLines.PosEnd(); break; case RelativePosition.None: break; case RelativePosition.At: break; default: break; } return(bx); }
static List <LocationContainerImpl.WithContent> ConvertLocationsWidthContent(HidemaruLspClient_BackEndContract.ILocationContainer locations) { var result = new List <LocationContainerImpl.WithContent>(); { var option = new TextLines.Option(); for (long i = 0; i < locations.Length; ++i) { var UserData = new LocationContainerImpl.WithContent(locations.Item(i)); result.Add(UserData); var location = locations.Item(i); option.Add( new Uri(location.uri).AbsolutePath, location.range.start.line, UserData); } foreach (var fileContent in TextLines.Gather(option).Values) { foreach (var lineContent in fileContent) { ((LocationContainerImpl.WithContent)lineContent.UserData).text = lineContent.Text; } } } return(result); }
private void RefreshExcludePatterns() { TextLines excludeFromScans = new TextLines(this.options.ExcludeFromCommentScans); List <Regex> currentPatterns = new List <Regex>(); foreach (string pattern in excludeFromScans.Lines.Where(line => !string.IsNullOrEmpty(line)).Distinct()) { if (!this.excludePatternsCache.TryGetValue(pattern, out Regex regex)) { try { regex = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.CultureInvariant); this.excludePatternsCache.Add(pattern, regex); } catch (ArgumentException ex) { // The pattern isn't a valid regular expression. MainPackage.LogException(ex); } } if (regex != null) { currentPatterns.Add(regex); } } lock (this.backgroundExcludePatterns) { this.backgroundExcludePatterns.Clear(); this.backgroundExcludePatterns.AddRange(currentPatterns); } }
[InlineData(TwoLines, 12, 1)] // End public void LineIndexContainingOffsetInText(string text, int charOffset, int expectedLine) { var lines = new TextLines(text); var line = lines.LineIndexContainingOffset(charOffset); Assert.Equal(expectedLine, line); }
/// <inheritdoc/> public void Clear() { TextLines.Clear(); Text.Clear(); CaretIndex = 0; _historyIndex = -1; InvalidateArrange(); }
public void LineCount(string text, int expectedLineCount) { var lines = new TextLines(text); var lineCount = lines.Count; Assert.Equal(expectedLineCount, lineCount); }
/// <summary> /// Gets the start visual column from the specified text line. /// </summary> public int GetTextLineVisualStartColumn(TextLine textLine) { if (!TextLines.Contains(textLine)) { throw new ArgumentException("textLine is not a line in this VisualLine"); } return(TextLines.TakeWhile(tl => tl != textLine).Sum(tl => tl.Length)); }
public FileEncryptionData(List <string> fileContentLines) : this() { _initVector = Convert.FromBase64String(fileContentLines.First()); if (fileContentLines.Count > 1) { TextLines.AddRange(fileContentLines.Skip(1)); } }
public void LineIndexContainingOffsetOutsideOfText(string text) { var lines = new TextLines(text); Assert.Throws <ArgumentOutOfRangeException>(() => lines.LineIndexContainingOffset(-5)); Assert.Throws <ArgumentOutOfRangeException>(() => lines.LineIndexContainingOffset(-1)); Assert.Throws <ArgumentOutOfRangeException>(() => lines.LineIndexContainingOffset(text.Length + 1)); Assert.Throws <ArgumentOutOfRangeException>(() => lines.LineIndexContainingOffset(text.Length + 42)); }
public void AddTextOnCurrentPosition(string text) { if (IsInsertMode && CurrentChar < TextLines[CurrentString].Length) { TextLines.RemoveInLine(CurrentString, CurrentChar, Math.Min(text.Length, TextLines[CurrentString].Length - CurrentChar)); } TextLines.InsertInLine(CurrentString, text, CurrentChar); CurrentPosition.Chr += text.Length; }
public object Clone() { var l = new TextLines { Part = Part }; l.Text.AddRange(Text); return(l); }
/// <summary> /// Computes the visual lines from the console text lines. /// </summary> /// <remarks> /// Text lines are split into several lines if they are larger than _numberOfColumns /// or if they contain '\n'. /// </remarks> private void WrapLines() { _wrappedLines.Clear(); // Temporarily, add text that is currently entered to the text lines. TextLines.Add(Prompt + Text); // Go through TextLines and split lines at if they are to large or contains newlines // characters. StringBuilder builder = new StringBuilder(); foreach (string line in TextLines) { builder.Clear(); int lineLength = line.Length; if (lineLength == 0) { // Empty line. _wrappedLines.Add(string.Empty); continue; } // Go through line character by character. for (int i = 0; i < lineLength; i++) { char c = line[i]; if (c == '\n') // ----- A newline character. { _wrappedLines.Add(builder.ToString()); builder.Clear(); } else if (builder.Length < _numberOfColumns) // ----- A character that fits onto the line. { builder.Append(c); if (i == lineLength - 1) { // Finish line if this is the last character. _wrappedLines.Add(builder.ToString()); builder.Clear(); } } else if (builder.Length >= _numberOfColumns) // ----- Reached the console column limit. { // Wrap line. _wrappedLines.Add(builder.ToString()); builder.Clear(); i--; // Handle the character again in the next loop. } } } // Remove the temporarily added current text. TextLines.RemoveAt(TextLines.Count - 1); }
/// <summary> /// 删除指定位置的文字,从(0,0)开始 /// </summary> /// <param name="startLine"></param> /// <param name="startCol"></param> /// <param name="endLine"></param> /// <param name="endCol"></param> public void DeleteText(int startLine, int startCol, int endLine, int endCol) { EditPoint editPoint = GetEditPoint(startLine, startCol); if (editPoint != null) { object tp; TextLines.CreateTextPoint(endLine, endCol, out tp); editPoint.Delete(tp as TextPoint); } }
/// <summary> /// 获得整个TextView的TextSpan信息,(坐标从0,0开始) /// </summary> /// <returns></returns> public TextSpan GetWholeTextSpan() { var span = new TextSpan(); span.iStartIndex = span.iStartLine = 0; if (TextLines != null) { TextLines.GetLastLineIndex(out span.iEndLine, out span.iEndIndex); } return(span); }
public static TextLinesWordCursor ScanFirstWord( TextLines InLines, TextTraits InTraits) { TextLinesWordCursor csr = new TextLinesWordCursor(); csr.Position = RelativePosition.Begin; csr.TextTraits = InTraits; TextLinesWordCursor res = ScanNextWord(InLines, csr); return(res); }
public bool DeleteSelectedText() { if (SelectedText.IsEmpty) { return(false); } TextLines.DeleteInBounds(SelectedText); CurrentPosition = new TextPosition(SelectedText.RealStart); SelectedText.Invalidate(); return(true); }
/// <summary> /// 获得指定位置的编辑点,从(0,0)开始 /// </summary> /// <param name="line"></param> /// <param name="col"></param> /// <returns></returns> public EditPoint GetEditPoint(int line, int col) { if (TextLines != null) { object editPoint; TextLines.CreateEditPoint(line, col, out editPoint); if (editPoint != null) { return(editPoint as EditPoint); } } return(null); }
public void NewLineFromCurrentPosition() { TextLines.InsertLine( CurrentString + 1, CurrentChar < TextLines[CurrentString].Length ? TextLines[CurrentString].Substring(CurrentChar) : string.Empty); if (CurrentChar < TextLines[CurrentString].Length) { TextLines.RemoveInLine(CurrentString, CurrentChar); } CurrentPosition.Str++; CurrentPosition.Chr = 0; }
private void LimitText() { // Limit entries in TextLines and entries in command history. while (TextLines.Count > MaxLines) { TextLines.RemoveAt(0); InvalidateArrange(); } while (History.Count > MaxHistoryEntries) { History.RemoveAt(0); InvalidateArrange(); } }
/// <summary> /// Draws the text layout. /// </summary> /// <param name="context">The drawing context.</param> /// <param name="origin">The origin.</param> public void Draw(DrawingContext context, Point origin) { if (!TextLines.Any()) { return; } var (currentX, currentY) = origin; foreach (var textLine in TextLines) { textLine.Draw(context, new Point(currentX + textLine.Start, currentY)); currentY += textLine.Height; } }
/// <summary> /// Draws the text layout. /// </summary> /// <param name="context">The drawing context.</param> /// <param name="origin">The origin.</param> public void Draw(IDrawingContextImpl context, Point origin) { if (!TextLines.Any()) { return; } var currentY = origin.Y; foreach (var textLine in TextLines) { textLine.Draw(context, new Point(origin.X, currentY)); currentY += textLine.LineMetrics.Size.Height; } }
public void DeleteAfterCurrentPosition() { if (CurrentChar == TextLines[CurrentString].Length) { if (CurrentString == TextLines.Count - 1) { return; } var nextString = CurrentString + 1; TextLines.AddInLine(CurrentString, TextLines[nextString]); TextLines.RemoveLineAt(nextString); } else { TextLines.RemoveInLine(CurrentString, CurrentChar, 1); } }
public bool Equals(Entity?other) { if (other is null) { return(false); } return(SomeText == other.SomeText && ThisIsNumber == other.ThisIsNumber && ThisIsFloatingPointNumber.Equals(ThisIsFloatingPointNumber) && SomeLogicalStatement == other.SomeLogicalStatement && TextLines is not null && other.TextLines is not null && TextLines.SequenceEqual(other.TextLines) && MultipleNumbers is not null && other.MultipleNumbers is not null && MultipleNumbers.SequenceEqual(other.MultipleNumbers) && MultipleRealNumbers is not null && other.MultipleRealNumbers is not null && MultipleRealNumbers.SequenceEqual(other.MultipleRealNumbers) && BunchOfStatements is not null && other.BunchOfStatements is not null && BunchOfStatements.SequenceEqual(other.BunchOfStatements)); }
// -------------------- ScanWord_IsolatexWord --------------------------- private static TextLinesWordCursor ScanWord_IsolatexWord( TextLines InLines, TextLinesCursor InBxCsr, TextTraits InTraits) { TextLinesWordCursor tlwc = null; TextLinesCursor csr = null; TextLinesCursor endcsr = null; ScanPatternResults spr = null; csr = new TextLinesCursor(InBxCsr); char ch1 = InBxCsr.CursorChar; // look ahead to see if this word is braced. if (IsOpenQuoteChar(ch1) == false) { spr = ScanEqualAny(csr.LineData, csr.LineOx, csr.LineData.Length - 1, InTraits.NonWordPatterns); } else { spr = new ScanPatternResults(-1); } // the rule is only braced words can span multiple lines. so if the word is // not braced, it can be parsed by the more general purpose IsolatexWord method. if ((IsOpenQuoteChar(ch1) == true) || (InTraits.IsOpenBraceChar(spr.FoundChar.Value) == false)) { ScanBoundedString bs = new ScanBoundedString(csr.LineData); WordCursor wc = new WordCursor(); wc.SetTraits(InTraits); ScanWord_IsolateWord(bs, csr.LineOx, ref wc, InTraits); endcsr = new TextLinesCursor(csr.LinesNode, wc.ScanEx, AcRelativePosition.At); tlwc = new TextLinesWordCursor(wc, csr, endcsr); } else { } return(tlwc); }
/// <summary> /// Draws the text layout. /// </summary> /// <param name="context">The drawing context.</param> /// <param name="origin">The origin.</param> public void Draw(DrawingContext context, Point origin) { if (!TextLines.Any()) { return; } var currentY = origin.Y; foreach (var textLine in TextLines) { var offsetX = TextLine.GetParagraphOffsetX(textLine.LineMetrics.Size.Width, Size.Width, _paragraphProperties.TextAlignment); textLine.Draw(context, new Point(origin.X + offsetX, currentY)); currentY += textLine.LineMetrics.Size.Height; } }
public void DeleteBeforeCurrentPosition() { if (CurrentChar == 0) { if (CurrentString == 0) { return; } var newPosition = TextLines[CurrentString - 1].Length; TextLines.AddInLine(CurrentString - 1, TextLines[CurrentString]); TextLines.RemoveLineAt(CurrentString); CurrentPosition.Str--; CurrentPosition.Chr = newPosition; } else { TextLines.RemoveInLine(CurrentString, CurrentChar - 1, 1); CurrentPosition.Chr--; } }