protected virtual void parseString (string expression, Font font, Point offset, Color color, IILTextRenderer renderer, ref Size size, ref List<ILRenderQueueItem> queue) { int pos = 0; string key, itemText; RectangleF bmpSize = new RectangleF(); int curHeigth = 0, curWidth = 0; Bitmap itemBMP = null; int lineHeight = 0, lineWidth = 0; Size itemSize = Size.Empty; while (pos < expression.Length) { itemText = expression.Substring(pos++,1); key = ILHashCreator.Hash(font,itemText); if (renderer.TryGetSize(key, ref itemSize)) { queue.Add(new ILRenderQueueItem(key,offset,color)); if (itemSize.Height > lineHeight) lineHeight = itemSize.Height; lineWidth += (int)itemSize.Width; } else { lock (this) { itemBMP = transformItem(itemText,font,out bmpSize); renderer.Cache(key,itemBMP,bmpSize); queue.Add(new ILRenderQueueItem(key,offset,color)); // update size if (bmpSize.Height > lineHeight) lineHeight = (int)bmpSize.Height; lineWidth += (int)bmpSize.Width; } } } size.Width += ((curWidth>lineWidth)?curWidth:lineWidth); size.Height = curHeigth + lineHeight; }
internal ILTexMarkerShape (ILPanel panel, string expression) :base (panel) { m_expression = expression; m_interpreter = new ILSimpleTexInterpreter(); m_font = new Font(FontFamily.GenericSansSerif,10.0f); m_maxLabelsDrawn = 50; m_valueFormat = "f"; m_renderer = panel.TextRendererManager.GetDefault(CoordSystem.World3D); }
internal ILTexMarkerShape(ILPanel panel, string expression) : base(panel) { m_expression = expression; m_interpreter = new ILSimpleTexInterpreter(); m_font = new Font(FontFamily.GenericSansSerif, 10.0f); m_maxLabelsDrawn = 50; m_valueFormat = "f"; m_renderer = panel.TextRendererManager.GetDefault(CoordSystem.World3D); }
/// <summary> /// Transforms an expression into render queue definition /// </summary> /// <param name="expression">expression to be transformed</param> /// <param name="font">font may used for transformation</param> /// <param name="color">standard color used for transformation</param> /// <param name="renderer">IILTextRenderer instance used for caching (and later rendering)</param> /// <returns>render queue, later used to render the visual representation of the expression</returns> /// <remarks>the expression may contain markups. See the online help at http://ilnumerics.net /// for a detailed descriptioin of known symbols and their syntax.</remarks> public ILRenderQueue Transform(string expression, Font font, Color color, IILTextRenderer renderer) { List <ILRenderQueueItem> ret = new List <ILRenderQueueItem>(); Size size = Size.Empty; m_normalFont = font; parseString(expression, font, new Point(), color, renderer, ref size, ref ret); return(new ILRenderQueue(expression, ret, size)); }
/// <summary> /// draws a fringe around the render output in fringe color /// </summary> /// <param name="m_renderer"></param> /// <param name="m_rendererQueue"></param> /// <param name="dest"></param> /// <param name="textOrientation"></param> /// <param name="m_color"></param> private void drawFringed(IILTextRenderer m_renderer, object m_rendererQueue, Point dest, TextOrientation textOrientation, Color m_color) { m_renderer.ColorOverride = m_fringeColor; for (int i = 0; i < m_fringeOffsets.Dimensions[0]; i++) { m_renderer.Draw(m_renderQueue , new Point(dest.X + m_fringeOffsets.GetValue(i, 0), dest.Y + m_fringeOffsets.GetValue(i, 1)) , TextOrientation.Horizontal, m_fringeColor); } m_renderer.ColorOverride = Color.Empty; m_renderer.Draw(m_renderQueue, dest, TextOrientation.Horizontal, m_color); }
/// <summary> /// Dispose off this element's ressources /// </summary> internal void Dispose() { if (m_renderer != null) { m_renderer.CacheCleared -= m_renderer_CacheCleared; if (m_renderer is IDisposable) { (m_renderer as IDisposable).Dispose(); } m_renderer = null; } }
protected virtual void parseString(string expression, Font font, Point offset, Color color, IILTextRenderer renderer, ref Size size, ref List <ILRenderQueueItem> queue) { int pos = 0; string key, itemText; RectangleF bmpSize = new RectangleF(); int curHeigth = 0, curWidth = 0; Bitmap itemBMP = null; int lineHeight = 0, lineWidth = 0; Size itemSize = Size.Empty; while (pos < expression.Length) { itemText = expression.Substring(pos++, 1); key = ILHashCreator.Hash(font, itemText); if (renderer.TryGetSize(key, ref itemSize)) { queue.Add(new ILRenderQueueItem(key, offset, color)); if (itemSize.Height > lineHeight) { lineHeight = itemSize.Height; } lineWidth += (int)itemSize.Width; } else { lock (this) { itemBMP = transformItem(itemText, font, out bmpSize); renderer.Cache(key, itemBMP, bmpSize); queue.Add(new ILRenderQueueItem(key, offset, color)); // update size if (bmpSize.Height > lineHeight) { lineHeight = (int)bmpSize.Height; } lineWidth += (int)bmpSize.Width; } } } size.Width += ((curWidth > lineWidth)?curWidth:lineWidth); size.Height = curHeigth + lineHeight; }
/// <summary> /// Create a new ILRenderer instance, matching the current graphics device /// </summary> /// <param name="typeName">full class name of the new text renderer</param> /// <param name="assembly">assembly hosting the textrenderer, null for executing assembly</param> /// <returns>newly created ILRenderer instance from assembly</returns> public IILTextRenderer CreateInstance(string typeName, Assembly assembly) { if (typeName == null) { throw new ILArgumentException("The type must be a valid ILTextRenderer!"); } string key = (assembly == null) ? typeName : assembly.FullName + "|" + typeName; if (m_rendererCache.ContainsKey(key)) { return(m_rendererCache[key]); } if (assembly == null) { assembly = Assembly.GetExecutingAssembly(); } Type type = assembly.GetType(typeName); if (type == null || type.GetInterface("IILTextRenderer") == null) { throw new ILArgumentException(String.Format( "The type '{0}' was not found in assembly {1} or is not a valid IILTextRenderer!" , typeName, assembly)); } queryAddRenderer(type); if (!m_rendererCollection.ContainsKey(key)) { throw new ILArgumentException("The renderer could not be loaded. Make sure, to specify the correct assembly and the type is properly decorated by the ILRendererAttribute!"); } IILTextRenderer ret = (IILTextRenderer)type.InvokeMember( typeName, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, new object[] { m_panel }); if (!m_rendererCache.ContainsKey(typeName)) { m_rendererCache[typeName] = ret; } return(ret); }
/// <summary> /// [abstract] Create a new labeling element /// </summary> /// <param name="panel">panel hosting the element</param> /// <param name="font">default font for the element</param> /// <param name="color">default color for the element</param> /// <param name="coordSystem">world / screen rendering method</param> public ILLabelingElement(ILPanel panel, Font font, Color color, CoordSystem coordSystem) { if (font != null) { m_font = font; } else { m_font = new System.Drawing.Font( System.Drawing.FontFamily.GenericSansSerif, 10.0f); } m_color = color; m_orientation = TextOrientation.Horizontal; m_renderQueue = null; m_size = Size.Empty; m_expression = string.Empty; // init interpreter & renderer m_renderer = panel.TextRendererManager.GetDefault(coordSystem); m_renderer.CacheCleared += new EventHandler(m_renderer_CacheCleared); m_interpreter = new ILSimpleTexInterpreter(); }
/// <summary> /// Transforms an expression into render queue definition /// </summary> /// <param name="expression">expression to be transformed</param> /// <param name="font">font may used for transformation</param> /// <param name="color">standard color used for transformation</param> /// <param name="renderer">IILTextRenderer instance used for caching (and later rendering)</param> /// <returns>render queue, later used to render the visual representation of the expression</returns> /// <remarks>the expression may contain markups. See the online help at http://ilnumerics.net /// for a detailed descriptioin of known symbols and their syntax.</remarks> public ILRenderQueue Transform(string expression, Font font, Color color, IILTextRenderer renderer) { List<ILRenderQueueItem> ret = new List<ILRenderQueueItem>(); Size size = Size.Empty; m_normalFont = font; parseString(expression,font,new Point(),color,renderer,ref size,ref ret); return new ILRenderQueue(expression, ret, size); }
/// <summary> /// draws a fringe around the render output in fringe color /// </summary> /// <param name="m_renderer"></param> /// <param name="m_rendererQueue"></param> /// <param name="dest"></param> /// <param name="textOrientation"></param> /// <param name="m_color"></param> private void drawFringed(IILTextRenderer m_renderer, object m_rendererQueue, Point dest, TextOrientation textOrientation, Color m_color) { m_renderer.ColorOverride = m_fringeColor; for (int i = 0; i < m_fringeOffsets.Dimensions[0]; i++) { m_renderer.Draw(m_renderQueue , new Point(dest.X + m_fringeOffsets.GetValue(i,0), dest.Y + m_fringeOffsets.GetValue(i,1)) , TextOrientation.Horizontal, m_fringeColor); } m_renderer.ColorOverride = Color.Empty; m_renderer.Draw(m_renderQueue, dest, TextOrientation.Horizontal, m_color); }
protected override void parseString(string expression, Font font, Point offset, Color color, IILTextRenderer renderer, ref Size size, ref List <ILRenderQueueItem> queue) { int pos = 0; string key, itemText; RectangleF bmpSize = new RectangleF(); int curHeigth = 0, curWidth = 0; Bitmap itemBMP = null; int lineHeight = 0, lineWidth = 0; Size itemSize = Size.Empty; while (pos < expression.Length) { itemText = expression.Substring(pos++, 1); #region special position control sequences if (itemText == "\r") { queue.Add(new ILRenderQueueItem(itemText, 0, 0, color)); if (curWidth < lineWidth) { curWidth = lineWidth; } lineWidth = 0; continue; } else if (itemText == "\n") { queue.Add(new ILRenderQueueItem(itemText, 0, 0, color)); curHeigth += lineHeight; lineHeight = 0; if (curWidth < lineWidth) { curWidth = lineWidth; } lineWidth = 0; continue; #endregion } else if (itemText == "\\") { #region font control if (pos < expression.Length - 2) { #region test for font control sequences: \it,\bf,\rm if (expression[pos] == 'i' && expression[pos + 1] == 't') { font = new Font(font, font.Style | FontStyle.Italic); pos += 2; continue; } else if (expression[pos] == 'b' && expression[pos + 1] == 'f') { font = new Font(font, font.Style | FontStyle.Bold); pos += 2; continue; } else if (expression[pos] == 'r' && expression[pos + 1] == 'm') { font = new Font(font, FontStyle.Regular); pos += 2; continue; } #endregion #region fontname,-size,-color if (parseKeyword(expression, ref pos, Keywords.Reset)) { color = Color.Empty; font = m_normalFont; offset = new Point(0, 0); continue; } string parameter = ""; if (parseKeywordArgumented(expression, ref pos, Keywords.Fontname, ref parameter)) { font = new Font(parameter, font.Size, font.Style, font.Unit); continue; } if (parseKeywordArgumented(expression, ref pos, Keywords.Fontsize, ref parameter)) { int newSize; if (!int.TryParse(parameter, out newSize)) { continue; } if (parameter.StartsWith("+") && newSize > 0) { newSize += (int)font.Size; if (newSize > 40) { newSize = 40; } } else if (parameter.StartsWith("-") && -newSize < font.Size) { newSize = (int)font.Size + newSize; } if (newSize > 0 && newSize < 40) { offset.Y += (int)Math.Round(font.Size - newSize); font = new Font(font.Name, newSize, font.Style, font.Unit); } continue; } if (parseKeywordArgumented(expression, ref pos, Keywords.Color, ref parameter)) { parseColor(parameter, ref color); continue; } #endregion } #endregion //if (pos < expression.Length - "size".Length) #region handle predefined symbols TextSymbols symbol = matchSymbol(expression, ref pos); if (symbol != TextSymbols.nothing) { itemText = TranslateSymbol(symbol); if (String.IsNullOrEmpty(itemText)) { continue; } } #endregion #region lower- upper indices } else if (pos < expression.Length && itemText == "_") { int end; if (pos < expression.Length - 1 && expression[pos] == '{') { pos++; // find end brace & remove end = expression.IndexOf('}', pos) - 1; if (end > 0 && end < expression.Length) { parseString( expression.Substring(pos, end - pos + 1), new Font(font.Name, font.Size * 0.7f, font.Style, font.Unit), new Point(offset.X, offset.Y + (int)(0.3f * font.Height)), color, renderer, ref size, ref queue); pos = end + 2; continue; } } // cache next char only parseString( expression.Substring(pos++, 1), new Font(font.Name, font.Size * 0.7f, font.Style, font.Unit), new Point(offset.X, offset.Y + (int)(0.3f * font.Height)), color, renderer, ref size, ref queue); continue; } else if (pos < expression.Length && itemText == "^") { int end; //offset.Y += 0.8f * font.Height; if (pos < expression.Length - 1 && expression[pos] == '{') { pos++; // find end brace & remove end = expression.IndexOf('}', pos) - 1; if (end > 0 && end < expression.Length) { parseString( expression.Substring(pos, end - pos + 1), new Font(font.Name, font.Size * 0.7f, font.Style, font.Unit), new Point(offset.X, offset.Y - (int)(0.2f * font.Height)), color, renderer, ref size, ref queue); pos = end + 2; continue; } } // cache next char only parseString( expression.Substring(pos++, 1), new Font(font.Name, font.Size * 0.7f, font.Style, font.Unit), new Point(offset.X, offset.Y - (int)(0.2f * font.Height)) , color, renderer, ref size, ref queue); continue; #endregion } key = ILHashCreator.Hash(font, itemText); if (renderer.TryGetSize(key, ref itemSize)) { queue.Add(new ILRenderQueueItem(key, offset, color)); if (itemSize.Height > lineHeight) { lineHeight = itemSize.Height; } lineWidth += (int)itemSize.Width; } else { lock (this) { itemBMP = transformItem(itemText, font, out bmpSize); renderer.Cache(key, itemBMP, bmpSize); queue.Add(new ILRenderQueueItem(key, offset, color)); // update size if (bmpSize.Height > lineHeight) { lineHeight = (int)bmpSize.Height; } lineWidth += (int)bmpSize.Width; } } } size.Width += ((curWidth > lineWidth)?curWidth:lineWidth); size.Height = curHeigth + lineHeight; }
protected override void parseString (string expression, Font font, Point offset, Color color, IILTextRenderer renderer, ref Size size, ref List<ILRenderQueueItem> queue) { int pos = 0; string key, itemText; RectangleF bmpSize = new RectangleF(); int curHeigth = 0, curWidth = 0; Bitmap itemBMP = null; int lineHeight = 0, lineWidth = 0; Size itemSize = Size.Empty; while (pos < expression.Length) { itemText = expression.Substring(pos++,1); #region special position control sequences if (itemText == "\r") { queue.Add(new ILRenderQueueItem(itemText,0,0, color)); if (curWidth < lineWidth) curWidth = lineWidth; lineWidth = 0; continue; } else if (itemText == "\n") { queue.Add(new ILRenderQueueItem(itemText,0,0, color)); curHeigth += lineHeight; lineHeight = 0; if (curWidth < lineWidth) curWidth = lineWidth; lineWidth = 0; continue; #endregion } else if (itemText == "\\") { #region font control if (pos < expression.Length - 2) { #region test for font control sequences: \it,\bf,\rm if (expression[pos] == 'i' && expression[pos+1] == 't') { font = new Font(font,font.Style | FontStyle.Italic); pos += 2; continue; } else if (expression[pos] == 'b' && expression[pos+1] == 'f') { font = new Font(font,font.Style | FontStyle.Bold); pos += 2; continue; } else if (expression[pos] == 'r' && expression[pos+1] == 'm') { font = new Font(font,FontStyle.Regular); pos += 2; continue; } #endregion #region fontname,-size,-color if (parseKeyword(expression,ref pos,Keywords.Reset)) { color = Color.Empty; font = m_normalFont; offset = new Point(0,0); continue; } string parameter = ""; if (parseKeywordArgumented(expression,ref pos,Keywords.Fontname,ref parameter)) { font = new Font(parameter,font.Size,font.Style,font.Unit); continue; } if (parseKeywordArgumented(expression,ref pos,Keywords.Fontsize,ref parameter)) { int newSize; if (!int.TryParse(parameter,out newSize)) continue; if (parameter.StartsWith("+") && newSize > 0 ) { newSize += (int)font.Size; if (newSize > 40) newSize = 40; } else if (parameter.StartsWith("-") && -newSize < font.Size) { newSize = (int)font.Size + newSize; } if (newSize > 0 && newSize < 40) { offset.Y += (int)Math.Round(font.Size - newSize); font = new Font(font.Name,newSize,font.Style,font.Unit); } continue; } if (parseKeywordArgumented(expression,ref pos,Keywords.Color,ref parameter)) { parseColor(parameter, ref color); continue; } #endregion } #endregion //if (pos < expression.Length - "size".Length) #region handle predefined symbols TextSymbols symbol = matchSymbol(expression,ref pos); if (symbol != TextSymbols.nothing) { itemText = TranslateSymbol(symbol); if (String.IsNullOrEmpty (itemText)) continue; } #endregion #region lower- upper indices } else if (pos < expression.Length && itemText == "_") { int end; if (pos < expression.Length-1 && expression[pos] == '{') { pos ++; // find end brace & remove end = expression.IndexOf('}',pos)-1; if (end > 0 && end < expression.Length) { parseString( expression.Substring(pos,end-pos+1), new Font(font.Name,font.Size * 0.7f,font.Style,font.Unit), new Point(offset.X,offset.Y + (int)(0.3f * font.Height)), color, renderer, ref size, ref queue); pos = end+2; continue; } } // cache next char only parseString( expression.Substring(pos++,1), new Font(font.Name,font.Size * 0.7f,font.Style,font.Unit), new Point(offset.X,offset.Y + (int)(0.3f * font.Height)), color, renderer, ref size, ref queue); continue; } else if (pos < expression.Length && itemText == "^") { int end; //offset.Y += 0.8f * font.Height; if (pos < expression.Length-1 && expression[pos] == '{') { pos ++; // find end brace & remove end = expression.IndexOf('}',pos)-1; if (end > 0 && end < expression.Length) { parseString( expression.Substring(pos,end-pos+1), new Font(font.Name,font.Size * 0.7f,font.Style,font.Unit), new Point(offset.X,offset.Y - (int)(0.2f * font.Height)), color, renderer, ref size, ref queue); pos = end+2; continue; } } // cache next char only parseString( expression.Substring(pos++,1), new Font(font.Name,font.Size * 0.7f,font.Style,font.Unit), new Point(offset.X,offset.Y - (int)(0.2f * font.Height)) ,color, renderer, ref size, ref queue); continue; #endregion } key = ILHashCreator.Hash(font,itemText); if (renderer.TryGetSize(key, ref itemSize)) { queue.Add(new ILRenderQueueItem(key,offset,color)); if (itemSize.Height > lineHeight) lineHeight = itemSize.Height; lineWidth += (int)itemSize.Width; } else { lock (this) { itemBMP = transformItem(itemText,font,out bmpSize); renderer.Cache(key,itemBMP,bmpSize); queue.Add(new ILRenderQueueItem(key,offset,color)); // update size if (bmpSize.Height > lineHeight) lineHeight = (int)bmpSize.Height; lineWidth += (int)bmpSize.Width; } } } size.Width += ((curWidth>lineWidth)?curWidth:lineWidth); size.Height = curHeigth + lineHeight; }
/// <summary> /// [abstract] Create a new labeling element /// </summary> /// <param name="panel">panel hosting the element</param> /// <param name="font">default font for the element</param> /// <param name="color">default color for the element</param> /// <param name="coordSystem">world / screen rendering method</param> public ILLabelingElement (ILPanel panel, Font font, Color color, CoordSystem coordSystem) { if (font != null) { m_font = font; } else { m_font = new System.Drawing.Font( System.Drawing.FontFamily.GenericSansSerif,10.0f); } m_color = color; m_orientation = TextOrientation.Horizontal; m_renderQueue = null; m_size = Size.Empty; m_expression = string.Empty; // init interpreter & renderer m_renderer = panel.TextRendererManager.GetDefault(coordSystem); m_renderer.CacheCleared += new EventHandler(m_renderer_CacheCleared); m_interpreter = new ILSimpleTexInterpreter(); }