private void HandleWordSpan(PegNode node, StyleContext context, StructuralGlyph parent)
            {
                int posBeg    = node.match_.posBeg_;
                int posEnd    = node.match_.posEnd_;
                var childNode = node.child_;

                string str = string.Empty;

                if (null == childNode) // no escape sequences
                {
                    str = _sourceText.Substring(posBeg, posEnd - posBeg);
                }
                else // at least one child node (Esc seq)
                {
                    int beg = posBeg;
                    int end = childNode.match_.posBeg_;
                    while (childNode != null)
                    {
                        str      += _sourceText.Substring(beg, end - beg);
                        str      += _sourceText.Substring(childNode.match_.posBeg_ + 1, 1);
                        beg       = childNode.match_.posEnd_;
                        childNode = childNode.next_;
                        end       = null != childNode ? childNode.match_.posBeg_ : posEnd;
                    }
                    str += _sourceText.Substring(beg, end - beg);
                }
                parent.Add(new TextGlyph(str, context));
            }
            private void HandleSentence(PegNode node, StyleContext context, StructuralGlyph parent)
            {
                var line = new GlyphLine();

                parent.Add(line);
                if (node.child_ != null)
                {
                    VisitNode(node.child_, context, line);
                }
            }
            private void HandleEscSeq2(PegNode node, StyleContext context, StructuralGlyph parent)
            {
                int posBeg    = node.match_.posBeg_;
                var childNode = node.child_;

                if (childNode == null)
                {
                    throw new ArgumentNullException("childNode");
                }

                string escHeader = _sourceText.Substring(posBeg, childNode.match_.posBeg_ - posBeg);

                switch (escHeader.ToLowerInvariant())
                {
                case @"\=(":
                {
                    var newParent = new SubSuperScript
                    {
                        Style = context
                    };
                    parent.Add(newParent);

                    var newContext = context.Clone();
                    newContext.ScaleFont(0.65);
                    VisitNode(childNode, newContext, newParent);
                }
                break;

                case @"\p(":
                {
                    double val;
                    string s1         = GetText(childNode).Trim();
                    var    newContext = context.Clone();
                    string numberString;

                    if (s1.EndsWith("%"))
                    {
                        numberString = s1.Substring(0, s1.Length - 1);
                        if (double.TryParse(numberString, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val))
                        {
                            newContext.BaseFontId = context.BaseFontId.WithSize(context.BaseFontId.Size * val / 100);
                            newContext.ScaleFont(val / 100);
                        }
                    }
                    else if (Altaxo.Serialization.LengthUnit.TryParse(s1, out var lengthUnit, out numberString) &&
                             double.TryParse(numberString, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val)
                             )
                    {
                        double newSize = val * (double)(lengthUnit.UnitInMeter / Altaxo.Serialization.LengthUnit.Point.UnitInMeter);
                        newContext.BaseFontId = context.BaseFontId.WithSize(newSize);
                        newContext.FontId     = context.FontId.WithSize(newSize);
                    }
			private void HandleEscSeq3(PegNode node, StyleContext context, StructuralGlyph parent)
			{
				int posBeg = node.match_.posBeg_;
				var childNode = node.child_;

				if (childNode == null)
					throw new ArgumentNullException("childNode");

				string escHeader = _sourceText.Substring(posBeg, childNode.match_.posBeg_ - posBeg);

				switch (escHeader.ToLowerInvariant())
				{
					case @"\%(":
						{
							string s1 = GetText(childNode);
							string s2 = GetText(childNode.next_);
							string s3 = GetText(childNode.next_.next_);
							int plotNumber, plotLayer;
							if (int.TryParse(s1, out plotLayer) && int.TryParse(s2, out plotNumber))
							{
								var label = new PlotName(context, plotNumber, plotLayer);
								label.SetPropertyColumnName(s3);
								parent.Add(label);
							}
						}
						break;
				}
			}
			private void HandleEscSeq2(PegNode node, StyleContext context, StructuralGlyph parent)
			{
				int posBeg = node.match_.posBeg_;
				var childNode = node.child_;

				if (childNode == null)
					throw new ArgumentNullException("childNode");

				string escHeader = _sourceText.Substring(posBeg, childNode.match_.posBeg_ - posBeg);

				switch (escHeader.ToLowerInvariant())
				{
					case @"\=(":
						{
							var newParent = new SubSuperScript();
							newParent.Style = context;
							parent.Add(newParent);

							var newContext = context.Clone();
							newContext.ScaleFont(0.65);
							VisitNode(childNode, newContext, newParent);
						}
						break;

					case @"\p(":
						{
							double val;
							string s1 = GetText(childNode).Trim();
							var newContext = context.Clone();
							string numberString;
							Altaxo.Serialization.LengthUnit lengthUnit;

							if (s1.EndsWith("%"))
							{
								numberString = s1.Substring(0, s1.Length - 1);
								if (double.TryParse(numberString, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val))
								{
									newContext.BaseFontId = context.BaseFontId.WithSize(context.BaseFontId.Size * val / 100);
									newContext.ScaleFont(val / 100);
								}
							}
							else if (Altaxo.Serialization.LengthUnit.TryParse(s1, out lengthUnit, out numberString) &&
								double.TryParse(numberString, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val)
								)
							{
								double newSize = val * (double)(lengthUnit.UnitInMeter / Altaxo.Serialization.LengthUnit.Point.UnitInMeter);
								newContext.BaseFontId = context.BaseFontId.WithSize(newSize);
								newContext.FontId = context.FontId.WithSize(newSize);
							}
							else if (double.TryParse(s1, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val)
								)
							{
								double newSize = val;
								newContext.BaseFontId = context.BaseFontId.WithSize(newSize);
								newContext.FontId = context.FontId.WithSize(newSize);
							}
							VisitNode(childNode.next_, newContext, parent);
						}
						break;

					case @"\c(":
						{
							string s1 = GetText(childNode).Trim();
							var newContext = context.Clone();
							var conv = new ColorConverter();

							try
							{
								object result = conv.ConvertFromInvariantString(s1);
								newContext.brush = new SolidBrush((Color)result);
							}
							catch (Exception)
							{
							}

							VisitNode(childNode.next_, newContext, parent);
						}
						break;

					case @"\l(":
						{
							string s1 = GetText(childNode);
							string s2 = GetText(childNode.next_);
							int plotNumber, plotLayer;
							if (int.TryParse(s1, out plotLayer) && int.TryParse(s2, out plotNumber))
							{
								parent.Add(new PlotSymbol(context, plotNumber, plotLayer));
							}
						}
						break;

					case @"\%(":
						{
							string s1 = GetText(childNode);
							string s2 = GetText(childNode.next_);
							int plotNumber, plotLayer;
							if (int.TryParse(s1, out plotLayer) && int.TryParse(s2, out plotNumber))
							{
								parent.Add(new PlotName(context, plotNumber, plotLayer));
							}
							else if (int.TryParse(s1, out plotNumber))
							{
								var label = new PlotName(context, plotNumber);
								label.SetPropertyColumnName(s2);
								parent.Add(label);
							}
						}
						break;
				}
			}
			private void HandleEscSeq1(PegNode node, StyleContext context, StructuralGlyph parent)
			{
				int posBeg = node.match_.posBeg_;
				var childNode = node.child_;

				if (childNode == null)
					throw new ArgumentNullException("childNode");

				string escHeader = _sourceText.Substring(posBeg, childNode.match_.posBeg_ - posBeg);

				switch (escHeader.ToLowerInvariant())
				{
					case @"\id(":
						{
							const string DefPropertyHead = "$Property[\"";
							const string DefPropertyTail = "\"]";

							string s = GetText(childNode).Trim();
							if (s == "$DI")
							{
								parent.Add(new DocumentIdentifier(context));
							}
							else if (s.StartsWith(DefPropertyHead) && s.EndsWith(DefPropertyTail))
							{
								string propertyName = s.Substring(DefPropertyHead.Length, s.Length - DefPropertyHead.Length - DefPropertyTail.Length);
								if (!string.IsNullOrEmpty(propertyName))
									parent.Add(new ValueOfProperty(context, propertyName));
							}
						}
						break;

					case @"\g(":
						{
							var newContext = context.Clone();
							newContext.SetFont(context.FontId.WithFamily("Symbol"));
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\i(":
						{
							var newContext = context.Clone();
							newContext.MergeFontStyle(FontXStyle.Italic);
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\b(":
						{
							var newContext = context.Clone();
							newContext.MergeFontStyle(FontXStyle.Bold);
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\u(":
						{
							var newContext = context.Clone();
							newContext.MergeFontStyle(FontXStyle.Underline);
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\s(":
						{
							var newContext = context.Clone();
							newContext.MergeFontStyle(FontXStyle.Strikeout);
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\n(":
						{
							var newContext = context.Clone();
							newContext.SetFontStyle(FontXStyle.Regular);
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\+(":
						{
							var newParent = new Superscript();
							newParent.Style = context;
							parent.Add(newParent);

							var newContext = context.Clone();
							newContext.ScaleFont(0.65);
							VisitNode(childNode, newContext, newParent);
						}
						break;

					case @"\-(":
						{
							var newParent = new Subscript();
							newParent.Style = context;
							parent.Add(newParent);

							var newContext = context.Clone();
							newContext.ScaleFont(0.65);
							VisitNode(childNode, newContext, newParent);
						}
						break;

					case @"\l(":
						{
							string s = GetText(childNode);
							int plotNumber;
							if (int.TryParse(s, out plotNumber))
							{
								parent.Add(new PlotSymbol(context, plotNumber));
							}
						}
						break;

					case @"\%(":
						{
							string s = GetText(childNode);
							int plotNumber;
							if (int.TryParse(s, out plotNumber))
							{
								parent.Add(new PlotName(context, plotNumber));
							}
						}
						break;

					case @"\ad(":
						{
							var newParent = new DotOverGlyph();
							newParent.Style = context;
							parent.Add(newParent);
							VisitNode(childNode, context, newParent);
						}
						break;

					case @"\ab(":
						{
							var newParent = new BarOverGlyph();
							newParent.Style = context;
							parent.Add(newParent);
							VisitNode(childNode, context, newParent);
						}
						break;
				}
			}
			private void HandleSentence(PegNode node, StyleContext context, StructuralGlyph parent)
			{
				var line = new GlyphLine();
				parent.Add(line);
				if (node.child_ != null)
					VisitNode(node.child_, context, line);
			}
			private void HandleTab(StructuralGlyph parent)
			{
				parent.Add(new TabGlpyh());
			}
			private void HandleWordSpan(PegNode node, StyleContext context, StructuralGlyph parent)
			{
				int posBeg = node.match_.posBeg_;
				int posEnd = node.match_.posEnd_;
				var childNode = node.child_;

				string str = string.Empty;
				if (null == childNode) // no escape sequences
				{
					str = _sourceText.Substring(posBeg, posEnd - posBeg);
				}
				else // at least one child node (Esc seq)
				{
					int beg = posBeg;
					int end = childNode.match_.posBeg_;
					while (childNode != null)
					{
						str += _sourceText.Substring(beg, end - beg);
						str += _sourceText.Substring(childNode.match_.posBeg_ + 1, 1);
						beg = childNode.match_.posEnd_;
						childNode = childNode.next_;
						end = null != childNode ? childNode.match_.posBeg_ : posEnd;
					}
					str += _sourceText.Substring(beg, end - beg);
				}
				parent.Add(new TextGlyph(str, context));
			}
Beispiel #10
0
            private void HandleEscSeq1(PegNode node, StyleContext context, StructuralGlyph parent)
            {
                int posBeg    = node.match_.posBeg_;
                var childNode = node.child_;

                if (childNode == null)
                {
                    throw new ArgumentNullException("childNode");
                }

                string escHeader = _sourceText.Substring(posBeg, childNode.match_.posBeg_ - posBeg);

                switch (escHeader.ToLowerInvariant())
                {
                case @"\id(":
                {
                    const string DefPropertyHead = "$Property[\"";
                    const string DefPropertyTail = "\"]";

                    string s = GetText(childNode).Trim();
                    if (s == "$DI")
                    {
                        parent.Add(new DocumentIdentifier(context));
                    }
                    else if (s.StartsWith(DefPropertyHead) && s.EndsWith(DefPropertyTail))
                    {
                        string propertyName = s.Substring(DefPropertyHead.Length, s.Length - DefPropertyHead.Length - DefPropertyTail.Length);
                        if (!string.IsNullOrEmpty(propertyName))
                        {
                            parent.Add(new ValueOfProperty(context, propertyName));
                        }
                    }
                }
                break;

                case @"\g(":
                {
                    var newContext = context.Clone();
                    newContext.SetFont(context.FontId.WithFamily("Symbol"));
                    VisitNode(childNode, newContext, parent);
                }
                break;

                case @"\i(":
                {
                    var newContext = context.Clone();
                    newContext.MergeFontStyle(FontXStyle.Italic);
                    VisitNode(childNode, newContext, parent);
                }
                break;

                case @"\b(":
                {
                    var newContext = context.Clone();
                    newContext.MergeFontStyle(FontXStyle.Bold);
                    VisitNode(childNode, newContext, parent);
                }
                break;

                case @"\u(":
                {
                    var newContext = context.Clone();
                    newContext.MergeFontStyle(FontXStyle.Underline);
                    VisitNode(childNode, newContext, parent);
                }
                break;

                case @"\s(":
                {
                    var newContext = context.Clone();
                    newContext.MergeFontStyle(FontXStyle.Strikeout);
                    VisitNode(childNode, newContext, parent);
                }
                break;

                case @"\n(":
                {
                    var newContext = context.Clone();
                    newContext.SetFontStyle(FontXStyle.Regular);
                    VisitNode(childNode, newContext, parent);
                }
                break;

                case @"\+(":
                {
                    var newParent = new Superscript
                    {
                        Style = context
                    };
                    parent.Add(newParent);

                    var newContext = context.Clone();
                    newContext.ScaleFont(0.65);
                    VisitNode(childNode, newContext, newParent);
                }
                break;

                case @"\-(":
                {
                    var newParent = new Subscript
                    {
                        Style = context
                    };
                    parent.Add(newParent);

                    var newContext = context.Clone();
                    newContext.ScaleFont(0.65);
                    VisitNode(childNode, newContext, newParent);
                }
                break;

                case @"\l(":
                {
                    string s = GetText(childNode);
                    if (int.TryParse(s, out var plotNumber))
                    {
                        parent.Add(new PlotSymbol(context, plotNumber));
                    }
                }
                break;

                case @"\%(":
                {
                    string s = GetText(childNode);
                    if (int.TryParse(s, out var plotNumber))
                    {
                        parent.Add(new PlotName(context, plotNumber));
                    }
                }
                break;

                case @"\ad(":
                {
                    var newParent = new DotOverGlyph
                    {
                        Style = context
                    };
                    parent.Add(newParent);
                    VisitNode(childNode, context, newParent);
                }
                break;

                case @"\ab(":
                {
                    var newParent = new BarOverGlyph
                    {
                        Style = context
                    };
                    parent.Add(newParent);
                    VisitNode(childNode, context, newParent);
                }
                break;
                }
            }
Beispiel #11
0
 private void HandleTab(StructuralGlyph parent)
 {
     parent.Add(new TabGlpyh());
 }