public FrameworkElement CreateTextElement(IClassificationFormatMap classificationFormatMap, TextClassifierContext context, string contentType, TextElementFlags flags) { if (classificationFormatMap == null) { throw new ArgumentNullException(nameof(classificationFormatMap)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } if (contentType == null) { throw new ArgumentNullException(nameof(contentType)); } var ct = contentTypeRegistryService.GetContentType(contentType); if (ct == null) { throw new ArgumentException($"Invalid content type: {contentType}"); } ITextClassifierAggregator aggregator; if (!toAggregator.TryGetValue(ct, out aggregator)) { toAggregator.Add(ct, aggregator = textClassifierAggregatorService.Create(ct)); } try { tagsList.AddRange(aggregator.GetTags(context)); return(TextElementFactory.Create(classificationFormatMap, context.Text, tagsList, flags)); } finally { tagsList.Clear(); } }
public FrameworkElement CreateTextElement(TreeViewNodeClassifierContext context, string contentType, bool filterOutNewLines, bool useNewFormatter) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (contentType == null) { throw new ArgumentNullException(nameof(contentType)); } var ct = contentTypeRegistryService.GetContentType(contentType); if (ct == null) { throw new ArgumentException($"Invalid content type: {contentType}"); } ITextClassifierAggregator aggregator; if (!toAggregator.TryGetValue(ct, out aggregator)) { toAggregator.Add(ct, aggregator = textClassifierAggregatorService.Create(ct)); } try { tagsList.AddRange(aggregator.GetTags(context)); return(TextElementFactory.Create(classificationFormatMap, context.Text, tagsList, useNewFormatter: useNewFormatter, filterOutNewLines: filterOutNewLines)); } finally { tagsList.Clear(); } }
private AbstractTextElement WrapAsTextElement(Type type, object value) { if (typeof(PonyTextStructureBase).IsAssignableFrom(type)) { return(GetText(value as PonyTextStructureBase)); } TypeCode tcode = Type.GetTypeCode(type); switch (tcode) { case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: case TypeCode.Char: case TypeCode.String: return(TextElementFactory.CreateTextElement(TextElementType.TextUnit, value.ToString())); default: throw new PreProcessorException( $"Unable to find a suitable translation from {tcode} ({type.FullName})" + $"to AbstractTextElement"); } }
public override void EvaluateInternal(PonyTextContext textContext) { foreach (var directive in textDirectives) { textContext.WriteTextElement(TextElementFactory.CreateTextElement(TextElementType.Paragraph)); directive.Evaluate(textContext); } }
public override void EvaluateInternal(PonyTextContext textContext) { var textElement = TextElementFactory.CreateTextElement(TextElementType.Paragraph); PonyTextContext ctx = new DerivedTextContext(textContext, textElement); foreach (var item in structureBases) { item.Evaluate(ctx); } textContext.WriteTextElement(textElement); }
public override int GetHashCode() { int hc = 0; hc ^= TextElementFactory.GetHashCode(); hc ^= Version; hc ^= ClassificationFormatMap.GetHashCode(); hc ^= Text.GetHashCode(); hc ^= Tags.Length == 0 ? 0 : Tags[0].Span.GetHashCode() ^ Tags[0].ClassificationType.GetHashCode(); hc ^= (int)TextElementFlags; // Opacity isn't used return(hc); }
protected override void OnPreProcessInternal(PonyTextStructureBase[] args) { string title = args[0].GetUnderlyingObject() as string; AbstractTextElement text = TextElementFactory.CreateTextElement(TextElementType.Paragraph, title); text.CustomProperty.SetProperty(RenderSettingField.HORIZONTAL_ALIGN, RenderSettingField.ALIGN_VH_MID); text.CustomProperty.SetProperty(RenderSettingField.VERTICAL_ALIGN, RenderSettingField.ALIGN_VH_MID); text.CustomProperty.SetProperty(RenderSettingField.TEXT_FONTSIZE, "26"); if (args.Length == 2) { text.CustomProperty.Merge(CreatePrimitiveMapping(args[1])); } WriteText(text); }
protected override void OnPreProcessInternal(PonyTextStructureBase[] args) { string format = (string)args[0].GetUnderlyingObject(); StringBuilder sb = new StringBuilder(); sbyte currentState = 0; for (int i = 0, j = 1; i < format.Length; i++) { char c = format[i]; switch (c) { case '\\': currentState = transitionTable[currentState, 1]; break; case '#': currentState = transitionTable[currentState, 2]; break; default: currentState = transitionTable[currentState, 0]; break; } if (currentState == 0) { sb.Append(c); } else if (currentState == 2) { if (j >= args.Length) { throw new PreProcessorException("Not enough arguments for doing formating"); } if (sb.Length > 0) { WriteText(TextElementFactory.CreateTextElement(TextElementType.TextUnit, sb.ToString())); sb.Clear(); } WriteText(GetText(args[j])); j++; } else if (currentState == -1) { throw new PreProcessorException( $"Invalid format for format template string: \"{format}\". " + $"At character '{c}' column {i + 1}"); } } }
protected override void OnPreProcessInternal(PonyTextStructureBase[] args) { AbstractTextElement abstractText = TextElementFactory.CreateTextElement(TextElementType.TextUnit); PropertyConfiguration configuration = abstractText.CustomProperty; if (args.Length == 2) { configuration.Merge(CreatePrimitiveMapping(args[1])); } string path = ctx.Metadata.GetAbsolutePath(args[0].GetUnderlyingObject() as string); configuration.SetProperty("utype", "img"); configuration.SetProperty("path", path); WriteText(abstractText); }
protected AbstractTextElement GetText(PonyTextStructureBase structureBase) { if (structureBase.StructureType == StructureType.NumberStruct || structureBase.StructureType == StructureType.LiteralStruct) { string obj = structureBase.GetUnderlyingObject().ToString(); return(TextElementFactory.CreateTextElement(TextElementType.TextUnit, obj)); } // else if (structureBase.StructureType == StructureType.MarcoStruct) { // PonyTextMarcoStruct marcoStruct = structureBase as PonyTextMarcoStruct; // return GetText(ctx.MacroTable.GetMarco(marcoStruct.MarcoName)); // } else if (structureBase.StructureType == StructureType.MapStruct) { throw new PreProcessorException($"Not support type."); } else if (structureBase.StructureType == StructureType.DirectiveStruct) { PonyTextContext newCtx = new DerivedTextContext(ctx, TextElementFactory.CreateTextElement(TextElementType.TextElementCollection)); structureBase.Evaluate(newCtx); TextElementCollection elementCollection = (TextElementCollection)newCtx.GetCurrentContext(); if (elementCollection.getDocument().Count == 1) { return(elementCollection.getDocument()[0]); } return(elementCollection); } else { PonyTextContext newCtx = new DerivedTextContext(ctx, TextElementFactory.CreateTextElement(TextElementType.TextElementCollection)); structureBase.Evaluate(newCtx); return(newCtx.GetCurrentContext()); } }
protected void WriteTextLiteral(string literal, bool avaliableInRenderSatge = false) { AbstractTextElement textElement = TextElementFactory.CreateTextElement(TextElementType.TextUnit, literal); WriteText(textElement, avaliableInRenderSatge); }
public override void EvaluateInternal(PonyTextContext textContext) { textContext.WriteTextElement(TextElementFactory.CreateTextElement(TextElementType.TextUnit, num.ToString())); }