public void PaintParaBox() { AssembledStyles styles = new AssembledStyles(); var clientRuns = new List<IClientRun>(); BlockBox box0 = new BlockBox(styles, Color.Red, 72000, 36000); clientRuns.Add(box0); BlockBox box1 = new BlockBox(styles, Color.Blue, 36000, 18000); clientRuns.Add(box1); BlockBox box2 = new BlockBox(styles, Color.Red, 24000, 18000); clientRuns.Add(box2); BlockBox box3 = new BlockBox(styles, Color.Red, 72000, 36000); clientRuns.Add(box3); BlockBox box4 = new BlockBox(styles, Color.Red, 36000, 36000); clientRuns.Add(box4); TextSource source = new TextSource(clientRuns, null); ParaBox para = new ParaBox(styles, source); RootBox root = new RootBox(styles); root.AddBox(para); MockGraphics graphics = new MockGraphics(); LayoutInfo layoutArgs = ParaBuilderTests.MakeLayoutInfo(100, graphics); root.Layout(layoutArgs); PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96); root.Paint(graphics, ptrans); Assert.AreEqual(5, graphics.RectanglesDrawn.Count); VerifyRect(2, 2, 96, 48, graphics, 0, Color.Red); VerifyRect(2, 48+2, 48, 24, graphics, 1, Color.Blue); VerifyRect(2+48, 48 + 2, 32, 24, graphics, 2, Color.Red); VerifyRect(2, 24 + 48 + 2, 96, 48, graphics, 3, Color.Red); VerifyRect(2, 48 + 24 + 48 + 2, 48, 48, graphics, 4, Color.Red); }
public void TokenizationFinalEOF() { var s = new TextSource(""); var t = new HtmlTokenizer(s, null); var token = t.Get(); Assert.AreEqual(HtmlTokenType.EndOfFile, token.Type); }
internal static void ClearSelected(TextSource ts) { var tb = ts.CurrentTB; Place start = tb.Selection.Start; Place end = tb.Selection.End; int fromLine = Math.Min(end.iLine, start.iLine); int toLine = Math.Max(end.iLine, start.iLine); int fromChar = tb.Selection.FromX; int toChar = tb.Selection.ToX; if (fromLine < 0) return; // if (fromLine == toLine) ts[fromLine].RemoveRange(fromChar, toChar - fromChar); else { ts[fromLine].RemoveRange(fromChar, ts[fromLine].Count - fromChar); ts[toLine].RemoveRange(0, toChar); ts.RemoveLine(fromLine + 1, toLine - fromLine - 1); InsertCharCommand.MergeLines(fromLine, ts); } // tb.Selection.Start = new Place(fromChar, fromLine); // ts.NeedRecalc(new TextSource.TextChangedEventArgs(fromLine, toLine)); }
public void EmptyXmlDocumentTokenization() { var s = new TextSource(""); var t = CreateTokenizer(s); var e = t.Get(); Assert.IsInstanceOf<XmlEndOfFileToken>(e); }
/// <summary> /// See 8.2.4 Tokenization /// </summary> /// <param name="source">The source code manager.</param> /// <param name="events">The event aggregator to use.</param> public HtmlTokenizer(TextSource source, IEventAggregator events) : base(source, events) { _state = HtmlParseMode.PCData; _acceptsCharacterData = false; _lastStartTag = String.Empty; }
public override INode Clone(Boolean deep = true) { var source = new TextSource(Source.Text); var node = new HtmlDocument(Context, source); CloneDocument(node, deep); return node; }
public void TokenizationTagNameDetection() { var s = new TextSource("<span>"); var t = new HtmlTokenizer(s, null); var token = t.Get(); Assert.AreEqual("span", ((HtmlTagToken)token).Name); }
public void TokenizationTagSelfClosingDetected() { var s = new TextSource("<img />"); var t = new HtmlTokenizer(s, null); var token = t.Get(); Assert.AreEqual(true, ((HtmlTagToken)token).IsSelfClosing); }
/// <summary> /// Sets a new default stylesheet defined by the provided string. /// </summary> /// <param name="sourceCode">The source for a new base stylesheet.</param> /// <returns>The CSSOM of the parsed source.</returns> public ICssStyleSheet SetDefault(String sourceCode) { var parser = new CssParser(_options); var source = new TextSource(sourceCode); var sheet = new CssStyleSheet(parser, default(String), default(ICssStyleSheet)); _default = Parse(parser, sheet, source).Result; return _default; }
public void ValidXmlDeclarationOnlyVersion() { var s = new TextSource("<?xml version=\"1.0\"?>"); var t = CreateTokenizer(s); var e = t.Get(); Assert.AreEqual(XmlTokenType.Declaration, e.Type); Assert.AreEqual("1.0", ((XmlDeclarationToken)e).Version); }
public void TokenizationStartTagDetection() { var s = new TextSource("<p>"); var t = new HtmlTokenizer(s, null); var token = t.Get(); Assert.AreEqual(HtmlTokenType.StartTag, token.Type); Assert.AreEqual("p", ((HtmlTagToken)token).Name); }
public void TokenizationBogusCommentQuestionMark() { var s = new TextSource("<?>"); var t = new HtmlTokenizer(s, null); var token = t.Get(); Assert.AreEqual(HtmlTokenType.Comment, token.Type); Assert.AreEqual("?", token.Data); }
public void TokenizationBogusCommentEmpty() { var s = new TextSource("<!>"); var t = new HtmlTokenizer(s, null); var token = t.Get(); Assert.AreEqual(HtmlTokenType.Comment, token.Type); Assert.AreEqual(String.Empty, token.Data); }
public void TokenizationBogusCommentClosingTag() { var s = new TextSource("</ >"); var t = new HtmlTokenizer(s, null); var token = t.Get(); Assert.AreEqual(HtmlTokenType.Comment, token.Type); Assert.AreEqual(" ", token.Data); }
public void XmlTokenizerStringToken() { var s = new TextSource("teststring\r"); var t = new XmlTokenizer(s, null); var e = t.Get(); Assert.AreEqual(XmlTokenType.Character, e.Type); var x = (XmlCharacterToken)e; Assert.AreEqual("teststring\n", x.Data); }
/// <summary> /// See 8.2.4 Tokenization /// </summary> /// <param name="source">The source code manager.</param> /// <param name="resolver">The entity resolver to use.</param> public HtmlTokenizer(TextSource source, IEntityProvider resolver) : base(source) { State = HtmlParseMode.PCData; IsAcceptingCharacterData = false; IsStrictMode = false; _lastStartTag = String.Empty; _resolver = resolver; }
public void TokenizationLongerCharacterReference() { var content = "&abcdefghijklmnopqrstvwxyzABCDEFGHIJKLMNOPQRSTV;"; var s = new TextSource(content); var t = new HtmlTokenizer(s, null); var token = t.Get(); Assert.AreEqual(HtmlTokenType.Character, token.Type); Assert.AreEqual(content, token.Data); }
public BaseTokenizer(TextSource source) { StringBuffer = Pool.NewStringBuilder(); _columns = new Stack<UInt16>(); _source = source; _current = Symbols.Null; _column = 0; _row = 1; }
public void StringsInSource() { ITsString tss = tsf.MakeString("abc def", wsEn); AssembledStyles styles = new AssembledStyles(); TssClientRun clientRun = new TssClientRun(tss, styles); var clientRuns = new List<IClientRun>(); clientRuns.Add(clientRun); TextSource ts = new TextSource(clientRuns); }
public Reader(TextSource textSource, TextRenderer textRenderer, double maxWPM) { this.maxWPM = maxWPM; this.textRenderer = textRenderer; this.textSource = textSource; this.wordTimer = new Timer(START_WORD_INTERVAL); wordTimer.Elapsed += new ElapsedEventHandler(wordTimerHandler); }
/// <summary> /// Constructor /// </summary> /// <param name="ts">Underlaying TextSource</param> /// <param name="iLines">List of line indices to be removed</param> public RemoveLinesCommand(TextSource ts, List<int> iLines) : base(ts) { //sort iLines iLines.Sort(); // this.iLines = iLines; lastSel = sel = new RangeInfo(ts.CurrentTB.Selection); }
public void OneCommentInXmlDocument() { var c = "My comment"; var s = new TextSource("<!--" + c + "-->"); var t = CreateTokenizer(s); var e = t.Get(); Assert.AreEqual(XmlTokenType.Comment, e.Type); Assert.AreEqual(c, ((XmlCommentToken)e).Data); }
public static int FindEndOfFoldingBlock(TextSource lines, int iStartLine, int maxLines, FindEndOfFoldingBlockStrategy strategy) { //find end of block int i; string marker = lines[iStartLine].FoldingStartMarker; var stack = new Stack<string>(); switch (strategy) { case FindEndOfFoldingBlockStrategy.Strategy1: for (i = iStartLine /*+1*/; i < lines.Count; i++) { if (lines.LineHasFoldingStartMarker(i)) stack.Push(lines[i].FoldingStartMarker); if (lines.LineHasFoldingEndMarker(i)) { string m = lines[i].FoldingEndMarker; while (stack.Count > 0 && stack.Pop() != m) { // empty block } if (stack.Count == 0) return i; } maxLines--; if (maxLines < 0) return i; } break; case FindEndOfFoldingBlockStrategy.Strategy2: for (i = iStartLine /*+1*/; i < lines.Count; i++) { if (lines.LineHasFoldingEndMarker(i)) { string m = lines[i].FoldingEndMarker; while (stack.Count > 0 && stack.Pop() != m) ; if (stack.Count == 0) return i; } if (lines.LineHasFoldingStartMarker(i)) stack.Push(lines[i].FoldingStartMarker); maxLines--; if (maxLines < 0) return i; } break; } //return -1; return lines.Count - 1; }
public BaseTokenizer(TextSource source, IEventAggregator events) { _stringBuffer = Pool.NewStringBuilder(); _events = events; _columns = new Stack<UInt16>(); _source = source; _current = Symbols.Null; _column = 0; _row = 1; }
internal static void InsertText(string insertedText, TextSource ts, bool normalizeEOL=false) { var tb = ts.CurrentTB; try { tb.Selection.BeginUpdate(); char cc = '\x0'; if (ts.Count == 0) { InsertCharCommand.InsertLine(ts); tb.Selection.Start = Place.Empty; } tb.ExpandBlock(tb.Selection.Start.iLine); if (normalizeEOL) { // The EOL characters in insertedText have to be converted to the EOL characters in the TextSource. switch (tb.DefaultEolFormat) { case EolFormat.LF: // \r\n -> \n // \r -> \n insertedText = insertedText.Replace("\r\n", "\n").Replace("\r", "\n"); break; case EolFormat.CRLF: // \r[^\n] (a \r not followed by a \n) // [^\r]\n (a \n not preceeded by a \r) // yikes, I don't want to use a Regex for this. Let's normalize to \n and then to \r\n insertedText = insertedText.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n"); break; case EolFormat.CR: // \r\n -> \r // \n -> \r insertedText = insertedText.Replace("\r\n", "\r").Replace("\n", "\r"); break; case EolFormat.None: default: // The entire text is replaced, keep the EOL characters the way they are. // Make sure to call FastColoredTextbox.TryDeriveEolFormat(...) break; } } foreach (char c in insertedText) { InsertCharCommand.InsertChar(c, ref cc, ts); } ts.NeedRecalc(new TextSource.TextSourceTextChangedEventArgs(0, 1)); } finally { tb.Selection.EndUpdate(); } }
public void ValidXmlDeclarationVersionAndEncoding() { var s = new TextSource("<?xml version=\"1.1\" encoding=\"utf-8\" ?>"); var t = CreateTokenizer(s); var e = t.Get(); Assert.AreEqual(XmlTokenType.Declaration, e.Type); var x = (XmlDeclarationToken)e; Assert.AreEqual("1.1", x.Version); Assert.IsFalse(x.IsEncodingMissing); Assert.AreEqual("utf-8", x.Encoding); }
public void ValidXmlDeclarationEverything() { var s = new TextSource("<?xml version='1.0' encoding='ISO-8859-1' standalone=\"yes\" ?>"); var t = CreateTokenizer(s); var e = t.Get(); Assert.AreEqual(XmlTokenType.Declaration, e.Type); var x = (XmlDeclarationToken)e; Assert.AreEqual("1.0", x.Version); Assert.IsFalse(x.IsEncodingMissing); Assert.AreEqual("ISO-8859-1", x.Encoding); Assert.AreEqual(true, x.Standalone); }
public void OneDoctypeInXmlDocument() { var s = new TextSource("<!DOCTYPE root_element SYSTEM \"DTD_location\">"); var t = CreateTokenizer(s); var e = t.Get(); Assert.AreEqual(XmlTokenType.Doctype, e.Type); var d = (XmlDoctypeToken)e; Assert.IsFalse(d.IsNameMissing); Assert.AreEqual("root_element", d.Name); Assert.IsFalse(d.IsSystemIdentifierMissing); Assert.AreEqual("DTD_location", d.SystemIdentifier); }
/// <summary> /// Gets absolute text position from line and char position /// </summary> /// <param name="lines"></param> /// <param name="point">Line and char position</param> /// <returns>Point of char</returns> public static int PlaceToPosition(TextSource lines, Place point) { if (point.iLine < 0 || point.iLine >= lines.Count || point.iChar >= lines[point.iLine].Count + Environment.NewLine.Length) return -1; int result = 0; for (int i = 0; i < point.iLine; i++) result += lines[i].Count + Environment.NewLine.Length; result += point.iChar; return result; }
/// <summary> /// Loads the document in the provided context from the given response. /// </summary> /// <param name="context">The browsing context.</param> /// <param name="response">The response to consider.</param> /// <param name="source">The source to use.</param> /// <param name="cancelToken">Token for cancellation.</param> /// <returns>The task that builds the document.</returns> internal async static Task<SvgDocument> LoadAsync(IBrowsingContext context, IResponse response, TextSource source, CancellationToken cancelToken) { var contentType = response.Headers.GetOrDefault(HeaderNames.ContentType, MimeTypes.Svg); var document = new SvgDocument(context, source); var parser = new XmlDomBuilder(document); document.ContentType = contentType; document.Referrer = response.Headers.GetOrDefault(HeaderNames.Referer, String.Empty); document.DocumentUri = response.Address.Href; document.Cookie = response.Headers.GetOrDefault(HeaderNames.SetCookie, String.Empty); document.ReadyState = DocumentReadyState.Loading; await parser.ParseAsync(default(XmlParserOptions), cancelToken).ConfigureAwait(false); return document; }
public SelectCommand(TextSource ts) : base(ts) { }
/// <summary> /// Creates a new tokenizer for XML documents. /// </summary> /// <param name="source">The source code manager.</param> /// <param name="resolver">The entity resolver to use.</param> public XmlTokenizer(TextSource source, IEntityProvider resolver) : base(source) { _resolver = resolver; }
public void RenderRuns() { string part0 = "abc def"; AssembledStyles styles = new AssembledStyles().WithWs(wsEn); StringClientRun clientRun0 = new StringClientRun(part0, styles); var clientRuns = new List <IClientRun>(); clientRuns.Add(clientRun0); string part0a = " frn"; StringClientRun clientRun0a = new StringClientRun(part0a, styles.WithWs(wsFrn)); clientRuns.Add(clientRun0a); // Run 1 string part1 = " ghijk"; // english string part2 = " lmno"; // french ITsString tss = tsf.MakeString(part1, wsEn); ITsStrBldr bldr = tss.GetBldr(); bldr.Replace(bldr.Length, bldr.Length, part2, ttpFrn); TssClientRun clientRun1 = new TssClientRun(bldr.GetString(), styles); clientRuns.Add(clientRun1); // Run 2a string part2a = " french insert"; string part2b = " insert"; // english ITsString tssInsert = tsf.MakeString(part2b, wsEn); bldr = tssInsert.GetBldr(); bldr.Replace(0, 0, part2a, ttpFrn); TssClientRun clientRun2b = new TssClientRun(bldr.GetString(), styles); clientRuns.Add(clientRun2b); // IRuntem 2 string part3 = " pq"; string part4 = "\xfffc"; StringClientRun clientRun2 = new StringClientRun(part3 + part4, styles); clientRuns.Add(clientRun2); // Run 3 string part5 = "more french"; string part6 = "\xfffc"; StringClientRun clientRun3 = new StringClientRun(part5 + part6, styles.WithWs(wsFrn)); clientRuns.Add(clientRun3); // Run 4 string part7 = "English"; StringClientRun clientRun4 = new StringClientRun(part7, styles.WithWs(wsFrn)); clientRuns.Add(clientRun4); BlockBox box = new BlockBox(styles.WithWs(wsFrn), Color.Red, 72000, 36000); TextSource source = new TextSource(clientRuns, (run, offset) => (run == clientRun2 ? new StringClientRun(orcText, run.UniformRunStyles(0).WithWs(wsFrn)) : (IClientRun)box)); List <IRenderRun> renderRuns = source.RenderRuns; VerifyRenderRun(renderRuns[0], 0, part0.Length, "first - en"); int len = part0.Length; VerifyRenderRun(renderRuns[1], len, part0a.Length, "0a - frn"); len += part0a.Length; VerifyRenderRun(renderRuns[2], len, part1.Length, "part1 - en"); len += part1.Length; VerifyRenderRun(renderRuns[3], len, part2.Length + part2a.Length, "part2 & 2a (french)"); len += part2.Length + part2a.Length; VerifyRenderRun(renderRuns[4], len, part2b.Length + part3.Length, "2b and 2 (Eng)"); len += part2b.Length + part3.Length; VerifyRenderRun(renderRuns[5], len, orcText.Length + part5.Length, "orc + other french"); len += orcText.Length + part5.Length; VerifyRenderRun(renderRuns[6], len, 1, "single box"); len += 1; VerifyRenderRun(renderRuns[7], len, part7.Length, "run with same props as preceding box"); Assert.AreEqual(8, renderRuns.Count); }
/// <summary> /// Injects the Blazor boot code and supporting config data at a user-designated /// script tag identified with a <c>type</c> of <c>blazor-boot</c>. /// </summary> /// <remarks> /// <para> /// If a matching script tag is found, then it will be adjusted to inject /// supporting configuration data, including a <c>src</c> attribute that /// will load the Blazor client-side library. Any existing attribute /// names that match the boot config data will be overwritten, but other /// user-supplied attributes will be left intact. This allows, for example, /// to designate asynchronous loading or deferred running of the script /// reference. /// </para><para> /// If no matching script tag is found, it is assumed that the user is /// responsible for completing the Blazor boot process. /// </para> /// </remarks> public static string GetIndexHtmlContents( string htmlTemplate, string assemblyName, string assemblyEntryPoint, IEnumerable <string> assemblyReferences, IEnumerable <EmbeddedResourceInfo> embeddedContent, bool linkerEnabled) { var resultBuilder = new StringBuilder(); // Search for a tag of the form <script type="boot-blazor"></script>, and replace // it with a fully-configured Blazor boot script tag var textSource = new TextSource(htmlTemplate); var currentRangeStartPos = 0; var isInBlazorBootTag = false; var resumeOnNextToken = false; var result = string.Empty; foreach (var token in textSource.Tokenize(HtmlEntityService.Resolver)) { var tokenCharIndex = token.Position.Position - 1; if (resumeOnNextToken) { resumeOnNextToken = false; currentRangeStartPos = tokenCharIndex; } switch (token.Type) { case HtmlTokenType.StartTag: { // Only do anything special if this is a Blazor boot tag var tag = token.AsTag(); if (IsBlazorBootTag(tag)) { // First, emit the original source text prior to this special tag, since // we want that to be unchanged resultBuilder.Append(htmlTemplate, currentRangeStartPos, tokenCharIndex - currentRangeStartPos); // Instead of emitting the source text for this special tag, emit a fully- // configured Blazor boot script tag AppendScriptTagWithBootConfig( resultBuilder, assemblyName, assemblyEntryPoint, assemblyReferences, linkerEnabled, tag.Attributes); // Emit tags to reference any specified JS/CSS files AppendReferenceTags( resultBuilder, embeddedContent.Where(c => c.Kind == EmbeddedResourceKind.Css).Select(c => c.RelativePath), "<link rel=\"stylesheet\" href=\"{0}\" />"); AppendReferenceTags( resultBuilder, embeddedContent.Where(c => c.Kind == EmbeddedResourceKind.JavaScript).Select(c => c.RelativePath), "<script src=\"{0}\" defer></script>"); // Set a flag so we know not to emit anything else until the special // tag is closed isInBlazorBootTag = true; } break; } case HtmlTokenType.EndTag: // If this is an end tag corresponding to the Blazor boot script tag, we // can switch back into the mode of emitting the original source text if (isInBlazorBootTag) { isInBlazorBootTag = false; resumeOnNextToken = true; } break; case HtmlTokenType.EndOfFile: // Finally, emit any remaining text from the original source file var remainingLength = htmlTemplate.Length - currentRangeStartPos; if (remainingLength > 0) { resultBuilder.Append(htmlTemplate, currentRangeStartPos, remainingLength); } result = resultBuilder.ToString(); break; } } return(result); }
private TextPosition(TextSource source, int index) { m_source = source; m_index = index; }
private void Awake() { text_source = GetComponent <TextSource>(); }
public Scanner(TextSource source) { this.Source = source; this.Reset(); }
public void StringChangedTests() { string part0 = "abc"; AssembledStyles styles = new AssembledStyles().WithWs(wsEn); StringClientRun clientRun0 = new StringClientRun(part0, styles); var clientRuns = new List <IClientRun>(); clientRuns.Add(clientRun0); TextSource source = new TextSource(clientRuns); List <IRenderRun> renderRuns = source.RenderRuns; VerifyRenderRun(renderRuns[0], 0, 3, "initial state has all in one run"); var clientRun1 = new StringClientRun("abcd", styles); var output1 = source.ClientRunChanged(0, clientRun1); Assert.AreEqual(1, output1.NewSource.RenderRuns.Count, "replacing single run with simple string should produce single render run."); VerifyRenderRun(output1.NewSource.RenderRuns[0], 0, 4, "replacing client run should make a new source with modified single run"); Assert.AreEqual(3, output1.StartChange); Assert.AreEqual(0, output1.DeleteCount); Assert.AreEqual(1, output1.InsertCount); // try changing the middle of three runs, from a simple one to a complex one. clientRuns = new List <IClientRun>(); clientRuns.Add(clientRun0); string part2 = "def"; var clientRun2 = new StringClientRun(part2, styles); clientRuns.Add(clientRun2); string part3 = " mnop"; var clientRun3 = new StringClientRun(part3, styles); clientRuns.Add(clientRun3); source = new TextSource(clientRuns, MockInterpretOrc); string part4 = "q\xfffc"; var clientRun4 = new StringClientRun(part4, styles); var output2 = source.ClientRunChanged(1, clientRun4); Assert.AreEqual(3, output2.NewSource.RenderRuns.Count, "three render runs because ORC interprets as french string."); VerifyRenderRun(output2.NewSource.RenderRuns[0], 0, part0.Length + 1, "first run up to ORC"); VerifyRenderRun(output2.NewSource.RenderRuns[1], part0.Length + 1, orcText.Length, "second run is French from ORC"); VerifyRenderRun(output2.NewSource.RenderRuns[2], part0.Length + 1 + orcText.Length, part3.Length, "third run is stuff after ORC"); VerifyFetch(output2.NewSource, 0, output2.NewSource.Length, part0 + "q" + orcText + part3); Assert.AreEqual(part0.Length, output2.StartChange); Assert.AreEqual(part2.Length, output2.DeleteCount); Assert.AreEqual(1 + orcText.Length, output2.InsertCount); // Now do a variation where some of the new run survives at each end. // To catch a tricky special case, we want to replace some regular text with an ORC // that expands to the same thing. var bldr = tsf.MakeString("de" + orcText, wsEn).GetBldr(); bldr.SetIntPropValues(2, 2 + orcText.Length, (int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, wsFrn); var clientRunFakeOrc = new TssClientRun(bldr.GetString(), styles); clientRuns = new List <IClientRun>(); clientRuns.Add(clientRun0); clientRuns.Add(clientRunFakeOrc); clientRuns.Add(clientRun3); source = new TextSource(clientRuns, MockInterpretOrc); string partDeqOrc = "deq\xfffc"; var clientRun5 = new StringClientRun(partDeqOrc, styles); var output3 = source.ClientRunChanged(1, clientRun5); Assert.AreEqual(3, output3.NewSource.RenderRuns.Count, "three render runs because ORC interprets as french string."); VerifyRenderRun(output3.NewSource.RenderRuns[0], 0, part0.Length + 3, "first run up to ORC"); VerifyRenderRun(output3.NewSource.RenderRuns[1], part0.Length + 3, orcText.Length, "second run is French from ORC"); VerifyRenderRun(output3.NewSource.RenderRuns[2], part0.Length + 3 + orcText.Length, part3.Length, "third run is stuff after ORC"); VerifyFetch(output3.NewSource, 0, output3.NewSource.Length, part0 + "deq" + orcText + part3); // This should be interpreted as inserting the "q" after the "de" and before the orc text. Assert.AreEqual(part0.Length + 2, output3.StartChange); Assert.AreEqual(0, output3.DeleteCount); Assert.AreEqual(1, output3.InsertCount); // special case where nothing changes. clientRuns = new List <IClientRun>(); clientRuns.Add(clientRun0); clientRuns.Add(clientRun2); source = new TextSource(clientRuns, MockInterpretOrc); var output4 = source.ClientRunChanged(1, clientRun2); Assert.AreEqual(1, output4.NewSource.RenderRuns.Count, "two client runs collapse to one render"); VerifyRenderRun(output4.NewSource.RenderRuns[0], 0, part0.Length + part2.Length, "run has expected length"); VerifyFetch(output4.NewSource, 0, output4.NewSource.Length, part0 + part2); Assert.AreEqual(part0.Length, output4.StartChange); Assert.AreEqual(0, output4.DeleteCount); Assert.AreEqual(0, output4.InsertCount); }
internal XmlDocument(IBrowsingContext context, TextSource source) : base(context ?? BrowsingContext.New(), source) { ContentType = MimeTypeNames.Xml; }
private HtmlDocument CreateDocument(TextSource textSource) { var document = new HtmlDocument(_context, textSource); return(document); }
/// <summary> /// Constructor /// </summary> /// <param name="ts">Underlaying textbox</param> /// <param name="insertedText">Text for inserting</param> public InsertTextCommand(TextSource ts, string insertedText) : base(ts) { InsertedText = insertedText; }
/// <summary> /// CSS Tokenization /// </summary> /// <param name="source">The source code manager.</param> /// <param name="events">The event aggregator to use.</param> public CssTokenizer(TextSource source, IEventAggregator events) : base(source, events) { _valueMode = false; }
/// <summary> /// Creates a new Dtd parser that uses the given container /// as the result for parsing the given source. /// </summary> /// <param name="container">The container to use.</param> /// <param name="source">The source to parse.</param> public DtdParser(DtdContainer container, TextSource source) { _tokenizer = new DtdTokenizer(container, source); _result = container; _src = source; }
public SelectCommand(TextSource textSource) : base(textSource) { /* Empty */ }
HtmlDocument CreateDocument(Stream source) { var textSource = new TextSource(source, _context.Configuration.DefaultEncoding()); return(CreateDocument(textSource)); }
public UndoableCommand(TextSource ts) { this.ts = ts; sel = new RangeInfo(ts.CurrentTB.Selection); }
public override void Execute() { TextSource.OnTextChanging(ref InsertedText); InsertText(InsertedText, TextSource); base.Execute(); }
static CssTokenizer CreateTokenizer(Stream sourceCode) { var source = new TextSource(sourceCode); return(new CssTokenizer(source)); }
static HtmlTokenizer CreateTokenizer(TextSource source) { return(new HtmlTokenizer(source, null, HtmlEntityService.Resolver)); }
public void MultiUniformRuns() { // Run 0 string part0 = "abc def"; AssembledStyles styles = new AssembledStyles().WithWs(wsEn); StringClientRun clientRun0 = new StringClientRun(part0, styles); var clientRuns = new List <IClientRun>(); clientRuns.Add(clientRun0); // Run 1 string part1 = " ghijk"; string part2 = " lmno"; ITsString tss = tsf.MakeString(part2, wsEn); ITsStrBldr bldr = tss.GetBldr(); bldr.Replace(0, 0, part1, ttpFrn); TssClientRun clientRun1 = new TssClientRun(bldr.GetString(), styles); clientRuns.Add(clientRun1); // Run 2 string part3 = " pq"; string part4 = "\xfffc"; string part5 = "r"; StringClientRun clientRun2 = new StringClientRun(part3 + part4 + part5, styles); clientRuns.Add(clientRun2); TextSource source = new TextSource(clientRuns, MockInterpretOrc); MapRun[] runs = source.Runs; Assert.AreEqual(6, runs.Length); VerifyRun(0, clientRun0, 0, 0, part0, runs[0], "first run of complex source (abcdef)"); int len = part0.Length; VerifyRun(len, clientRun1, len, 0, part1, runs[1], "2nd run of complex source( ghijk)"); len += part1.Length; VerifyRun(len, clientRun1, len, 0, 1, part2, runs[2], "3rd run of complex source( lmno)"); len += part2.Length; VerifyRun(len, clientRun2, len, 0, part3, runs[3], "4th run of complex source (pq)"); len += part3.Length; int orcPos = len; VerifyRun(len, clientRun2, len, part3.Length, orcText, runs[4], "5th run of complex source (orc->xyz)"); int render = len + orcText.Length; len += 1; VerifyRun(len, clientRun2, render, part3.Length + part4.Length, part5, runs[5], "6th run of complex source(r)"); len += part5.Length; render += part5.Length; Assert.AreEqual(render, source.Length, "Length of complex source"); // LogToRen Assert.AreEqual(0, source.LogToRen(0)); Assert.AreEqual(1, source.LogToRen(1)); Assert.AreEqual(part1.Length - 1, source.LogToRen(part1.Length - 1)); Assert.AreEqual(part1.Length, source.LogToRen(part1.Length)); Assert.AreEqual(part1.Length + 1, source.LogToRen(part1.Length + 1)); Assert.AreEqual(orcPos - 1, source.LogToRen(orcPos - 1)); Assert.AreEqual(orcPos, source.LogToRen(orcPos)); int delta = orcText.Length - 1; Assert.AreEqual(orcPos + 1 + delta, source.LogToRen(orcPos + 1)); Assert.AreEqual(len + delta, source.LogToRen(len)); Assert.AreEqual(len - 1 + delta, source.LogToRen(len - 1)); //RenToLog Assert.AreEqual(0, source.RenToLog(0)); Assert.AreEqual(1, source.RenToLog(1)); Assert.AreEqual(part1.Length - 1, source.RenToLog(part1.Length - 1)); Assert.AreEqual(part1.Length, source.RenToLog(part1.Length)); Assert.AreEqual(part1.Length + 1, source.RenToLog(part1.Length + 1)); Assert.AreEqual(orcPos - 1, source.RenToLog(orcPos - 1)); Assert.AreEqual(orcPos, source.RenToLog(orcPos)); Assert.AreEqual(orcPos, source.RenToLog(orcPos + orcText.Length - 1)); Assert.AreEqual(orcPos + 1, source.RenToLog(orcPos + orcText.Length)); Assert.AreEqual(len, source.RenToLog(len + delta)); Assert.AreEqual(len - 1, source.RenToLog(len + delta - 1)); // Fetch VerifyFetch(source, 0, 0, ""); VerifyFetch(source, 0, 1, "a"); VerifyFetch(source, 0, part0.Length, part0); VerifyFetch(source, orcPos, orcPos + orcText.Length, orcText); VerifyFetch(source, part0.Length, part0.Length + part1.Length, part1); VerifyFetch(source, part0.Length + part1.Length - 2, part0.Length + part1.Length + 2, part1.Substring(part1.Length - 2) + part2.Substring(0, 2)); VerifyFetch(source, part0.Length, part0.Length + part1.Length + part2.Length + 1, part1 + part2 + part3.Substring(0, 1)); VerifyFetch(source, orcPos + orcText.Length - 1, orcPos + orcText.Length + 1, orcText.Substring(orcText.Length - 1) + part5); // GetCharProps. (This test is too restrictive. In several cases, a larger range could be returned. OTOH it is weak // in only verifying the writing system to check the properties returned.) VerifyCharProps(source, 0, wsEn, 0, part0.Length, "props at 0 in complex string"); VerifyCharProps(source, 2, wsEn, 0, part0.Length, "props in middle of first run in complex string"); VerifyCharProps(source, part0.Length - 1, wsEn, 0, part0.Length, "props of last char of first run in complex string"); VerifyCharProps(source, part0.Length, wsFrn, part0.Length, part0.Length + part1.Length, "props at start of second run in complex string"); VerifyCharProps(source, orcPos - 1, wsEn, orcPos - part3.Length, orcPos, "props of last char before ORC"); VerifyCharProps(source, orcPos, wsFrn, orcPos, orcPos + orcText.Length, "props of first char of ORC expansion"); VerifyCharProps(source, orcPos + 1, wsFrn, orcPos, orcPos + orcText.Length, "props of mid char of ORC expansion"); VerifyCharProps(source, orcPos + orcText.Length - 1, wsFrn, orcPos, orcPos + orcText.Length, "props of last char of ORC expansion"); VerifyCharProps(source, orcPos + orcText.Length, wsEn, orcPos + orcText.Length, orcPos + orcText.Length + part5.Length, "props of first char after ORC expansion"); }
private HtmlDocument CreateDocument(String source) { var textSource = new TextSource(source); return(CreateDocument(textSource)); }
public MarkdownDocument(IBrowsingContext context, TextSource source) : base(context, source) { }
public CommandManager(TextSource ts) { history = new LimitedStack <UndoableCommand>(MaxHistoryLength); TextSource = ts; UndoRedoStackIsEnabled = true; }
public TextLine FormatLine(TextSource textSource, int firstCharIndex, double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak) { return(formatter.FormatLine(textSource, firstCharIndex, paragraphWidth, paragraphProperties, previousLineBreak)); }
/// <summary> /// Parses the source html to css boxes tree structure. /// </summary> /// <param name="source">the html source to parse</param> public static HtmlDocument ParseDocument(LayoutFarm.HtmlBoxes.HtmlHost htmlHost, TextSource snapSource) { HtmlParser parser = GetHtmlParser(); //------------------------ HtmlDocument newdoc = new HtmlDocument(htmlHost); parser.Parse(snapSource, newdoc, newdoc.RootNode); FreeHtmlParser(parser); return(newdoc); }
private void Error(Exception exception) { ReportError(TextSource.GetText("Error.Twitter") + ": " + exception.Message); IsSearching = false; }
/// <summary> /// Takes a stream and transforms it to a stylesheet. /// </summary> public ICssStyleSheet ParseStylesheet(Stream content) { var source = new TextSource(content); return(ParseStylesheet(source)); }
public void EmptyRuns() { // Run 0 string part0 = ""; AssembledStyles styles = new AssembledStyles().WithWs(wsEn); StringClientRun clientRun0 = new StringClientRun(part0, styles); var clientRuns = new List <IClientRun>(); clientRuns.Add(clientRun0); // We want an empty run if it's the only thing in the paragraph. TextSource source = new TextSource(clientRuns, MockInterpretOrc); MapRun[] runs = source.Runs; Assert.AreEqual(1, runs.Length); VerifyRun(0, clientRun0, 0, 0, "", runs[0], "first run of empty source"); Assert.AreEqual(0, source.Length, "length of empty source"); VerifyCharProps(source, 0, wsEn, 0, 0, "props at 0 in empty string"); // We don't want an empty run adjacent to a non-empty one. string part1 = "abc"; StringClientRun clientRun1 = new StringClientRun(part1, styles); clientRuns.Add(clientRun1); source = new TextSource(clientRuns, MockInterpretOrc); runs = source.Runs; Assert.AreEqual(1, runs.Length); VerifyRun(0, clientRun1, 0, 0, part1, runs[0], "first run of (empty, abc) source"); Assert.AreEqual(part1.Length, source.Length, "length of (empty, abc) source"); // (empty, box) keeps empty BlockBox box = new BlockBox(styles, Color.Red, 72000, 36000); clientRuns[1] = box; source = new TextSource(clientRuns, MockInterpretOrc); runs = source.Runs; Assert.AreEqual(2, runs.Length); VerifyRun(0, clientRun0, 0, 0, "", runs[0], "first run of (empty, box) source"); VerifyRun(0, box, 0, 0, "\xfffc", runs[1], "2nd run of (empty, box) source"); Assert.AreEqual(1, source.Length, "length of (empty, box) source"); // Two adjacent empty strings produce a single run for the first client run. clientRuns.RemoveAt(1); StringClientRun clientRun1e = new StringClientRun(part0, styles); clientRuns.Add(clientRun1e); source = new TextSource(clientRuns, MockInterpretOrc); runs = source.Runs; Assert.AreEqual(1, runs.Length); VerifyRun(0, clientRun0, 0, 0, "", runs[0], "first run of (empty, empty) source"); Assert.AreEqual(0, source.Length, "length of (empty, empty) source"); // (something,empty) keeps the something. clientRuns[0] = clientRun1; source = new TextSource(clientRuns, MockInterpretOrc); runs = source.Runs; Assert.AreEqual(1, runs.Length); VerifyRun(0, clientRun1, 0, 0, part1, runs[0], "first run of (abc, empty) source"); Assert.AreEqual(part1.Length, source.Length, "length of (abc, empty) source"); // (box, empty) keeps empty clientRuns[0] = box; source = new TextSource(clientRuns, MockInterpretOrc); runs = source.Runs; Assert.AreEqual(2, runs.Length); VerifyRun(0, box, 0, 0, "\xfffc", runs[0], "first run of (box, empty) source"); VerifyRun(1, clientRun1e, 1, 0, "", runs[1], "2nd run of (box, empty) source"); Assert.AreEqual(1, source.Length, "length of (box, empty) source"); }
internal async Task <CssStyleSheet> ParseStylesheetAsync(CssStyleSheet sheet, TextSource source) { await source.PrefetchAll(CancellationToken.None).ConfigureAwait(false); var tokenizer = CreateTokenizer(source, _config); var start = tokenizer.GetCurrentPosition(); var builder = new CssBuilder(tokenizer, this); var document = sheet.GetDocument() as Document; var tasks = new List <Task>(); var end = builder.CreateRules(sheet); var range = new TextRange(start, end); sheet.SourceCode = new TextView(range, source); foreach (var rule in sheet.Rules) { if (rule.Type == CssRuleType.Charset) { continue; } else if (rule.Type != CssRuleType.Import) { break; } else { var import = (CssImportRule)rule; tasks.Add(import.LoadStylesheetFrom(document)); } } await TaskEx.WhenAll(tasks).ConfigureAwait(false); return(sheet); }
/// <summary> /// Factory method for creating a <see cref="TextSource"/> from <see cref="FileContent"/>. /// </summary> protected static TextSource CreateTextSource(FileContent content) { return(TextSource.FromCharArray(content.Content, content.Length)); }