/// <summary>Calculate the average character width of indicated font data.</summary> /// <param name="x11display">The display pointer, that specifies the connection to the X server.<see cref="IntPtr"/></param> /// <param name="x11gc">The crapchics context to use for drawing.<see cref="IntPtr"/></param> /// <param name="fontData">The font data to calculate the average character width for.<see cref="X11FontData"/></param> /// <returns>The average character width of indicated font data.<see cref="System.Int32"/></returns> public static int AverageCharacterWidth(IntPtr x11display, IntPtr x11gc, X11FontData fontData) { if (fontData == null) { SimpleLog.LogLine(TraceEventType.Error, CLASS_NAME + "::AverageCharacterWidth () Argument null: fontData"); return(0); } if (fontData.UseFontset) { X11lib.XRectangle overallInc = new X11lib.XRectangle(); X11lib.XRectangle overallLogical = new X11lib.XRectangle(); X11.TWchar[] text = new X11.TWchar[] { (X11.TWchar) 'X', (X11.TWchar) ' ', (X11.TWchar) 'i' }; X11lib.XwcTextExtents(fontData.FontResourceId, text, (X11.TInt)text.Length, ref overallInc, ref overallLogical); return((int)(((int)overallLogical.width + 2) / 3)); } else { TInt direction = 0; TInt fontAscent = 0; TInt fontDescent = 0; X11lib.XCharStruct xCharStruct = new X11lib.XCharStruct(); X11lib.XChar2b[] text = new X11lib.XChar2b[] { new X11lib.XChar2b('X'), new X11lib.XChar2b(' '), new X11lib.XChar2b('i') }; X11lib.XSetFont(x11display, x11gc, fontData.FontResourceId); X11lib.XQueryTextExtents16(x11display, fontData.FontResourceId, text, (X11.TInt)text.Length, ref direction, ref fontAscent, ref fontDescent, ref xCharStruct); return((int)(((int)xCharStruct.width + 2) / 3)); } }
/// <summary> Measure the text using the default font of indicated graphics context. </summary> /// <param name="display"> The display pointer, that specifies the connection to the X server. <see cref="IntPtr"/> </param> /// <param name="gc"> The crapchics context to use for measuring. <see cref="IntPtr"/> </param> /// <param name="text"> The text to measure. <see cref="X11.TChar[]"/> </param> /// <returns> The measured size of the indicated text. <see cref="TSize"/> </returns> public virtual TSize MeasureTextLine(IntPtr display, IntPtr gc, X11.TChar[] text) { TSize result = new TSize(5, 5); if (display == IntPtr.Zero) { Console.WriteLine(CLASS_NAME + "::MeasureTextLine () ERROR: Argument null: display"); return(result); } if (gc == IntPtr.Zero) { Console.WriteLine(CLASS_NAME + "::MeasureTextLine () ERROR: Argument null: gc"); return(result); } TInt gcID = X11lib.XGContextFromGC(gc); if (gcID != 0) { TInt direction = 0; TInt fontAscent = 0; TInt fontDescent = 0; X11lib.XCharStruct xCharStruct = new X11lib.XCharStruct(); X11lib.XQueryTextExtents(display, gcID, text, (X11.TInt)text.Length, ref direction, ref fontAscent, ref fontDescent, ref xCharStruct); result.Width = (int)xCharStruct.width; result.Height = (int)fontAscent + (int)fontDescent; } else { Console.WriteLine(CLASS_NAME + "::MeasureTextLine () ERROR: Cannot investigate default font ressource ID of underlaying graphics context."); } return(result); }