Ejemplo n.º 1
0
        /// <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));
            }
        }
Ejemplo n.º 2
0
        public static X11lib.XChar2b[] StringToXChar2bArray(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(new X11lib.XChar2b[0]);
            }

            char[]           buffer = text.ToCharArray();
            X11lib.XChar2b[] result = new X11lib.XChar2b[text.Length];
            for (int charIndex = 0; charIndex < buffer.Length; charIndex++)
            {
                result[charIndex].byte1 = (X11.TUchar) 0;
                result[charIndex].byte2 = (X11.TUchar)buffer[charIndex];
            }
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>Determine the index of indicated character within a 2 byte (0...65.536) character array.</summary>
        /// <param name="text">The 2 byte (0...65.536) character array to find the index in.<see cref="X11lib.XChar2b[]"/></param>
        /// <param name="character">The character to find the index for.<see cref="X11lib.XChar2b"/></param>
        /// <returns>The zero-based index on success, or -1 otherwise.<see cref="System.Int32"/></returns>
        public static int IndexOfXChar2bArray(X11lib.XChar2b[] text, X11lib.XChar2b character)
        {
            if (text.Length == 0)
            {
                return(-1);
            }

            for (int charIndex = 0; charIndex < text.Length; charIndex++)
            {
                if (text[charIndex] == character)
                {
                    return(charIndex);
                }
            }

            return(-1);
        }
Ejemplo n.º 4
0
        /// <summary>Concatenate two 4 byte (0...4.294.967.296) character array.</summary>
        /// <param name="text1">The first 4 byte (0...4.294.967.296) character array to concatenate.<see cref="X11lib.XChar2b[]"/></param>
        /// <param name="text2">The second 4 byte (0...4.294.967.296) character array to concatenate.<see cref="X11lib.XChar2b[]"/></param>
        /// <returns>The concatenated array on success, or an empty array otherwise.<see cref="X11lib.XChar2b[]"/></returns>
        /// <remarks>A tailing null character of text1 will be overwritten by the forst character of text2.</remarks>
        /// <remarks>Not required character of the result will be set to null characters.</remarks>
        public static X11lib.XChar2b[] AddXChar2bArray(X11lib.XChar2b[] text1, X11lib.XChar2b[] text2)
        {
            if (text1.Length == 0)
            {
                return(text2);
            }
            if (text2.Length == 0)
            {
                return(text1);
            }

            X11lib.XChar2b[] result = new X11lib.XChar2b[text1.Length + text2.Length];
            int charIndex1;

            for (charIndex1 = 0; charIndex1 < text1.Length; charIndex1++)
            {
                if (charIndex1 == text1.Length && text1[charIndex1].byte1 == 0 && text1[charIndex1].byte2 == 0)
                {
                    charIndex1++;
                    break;
                }
                else
                {
                    result[charIndex1] = text1[charIndex1];
                }
            }
            for (int charIndex2 = 0; charIndex1 + charIndex2 < result.Length; charIndex2++)
            {
                if (charIndex2 < text2.Length)
                {
                    result[charIndex1 + charIndex2] = text2[charIndex2];
                }
                else
                {
                    result[charIndex1 + charIndex2].byte1 = 0;
                    result[charIndex1 + charIndex2].byte2 = 0;
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>Extract a sub-array from a 2 byte (0...65.536) character array.</summary>
        /// <param name="text">The 2 byte (0...65.536) character array to extract a sub-array from.<see cref="X11lib.XChar2b[]"/></param>
        /// <param name="start">The index of the first character to extract.<see cref="System.Int32"/></param>
        /// <param name="length">The number of characters to extract, or -1 for all characters up to the end.<see cref="System.Int32"/></param>
        /// <returns>The extracted sub-array on success, or an empty array otherwise.<see cref="X11lib.XChar2b[]"/></returns>
        public static X11lib.XChar2b[] SubXChar2bArray(X11lib.XChar2b[] text, int start, int length)
        {
            if (start >= text.Length)
            {
                return(new X11lib.XChar2b[0]);
            }
            if (length <= 0)
            {
                length = text.Length;
            }

            int realLength = (length > 0 && start + length < text.Length ? length : text.Length - start);

            X11lib.XChar2b[] result = new X11lib.XChar2b[realLength];
            for (int charIndex = 0; charIndex < realLength; charIndex++)
            {
                result[charIndex] = text[start + charIndex];
            }

            return(result);
        }
Ejemplo n.º 6
0
 /// <summary>Initialize a new X11.Text.StyleChar instance.</summary>
 /// <param name="c16">The character of a styled character.<see cref="X11lib.XChar2b"/></param>
 /// <param name="styleIndex">The style of a styled character.<see cref="System.Int32"/></param>
 public TStyleChar(X11lib.XChar2b c16, int styleIndex)
 {
     _c          = X11.X11Utils.CharToWchar(X11.X11Utils.XChar2bToChar(c16));
     _styleIndex = styleIndex;
 }
Ejemplo n.º 7
0
        /// <summary>Test whether 'text', starting at 'startIndex', matches the 'predicate'.</summary>
        //// <param name="text">The string to test.<see cref="X11lib.XChar2b[]"/></param>
        /// <param name="startIndex">The index to start the test.<see cref="System.Int32"/></param>
        /// <param name="predicate">The mask string to compare to. Accepts '?' as single-char joker and '*' as multi-char joker.<see cref="X11lib.XChar2b[]"/></param>
        /// <returns>The matching string if substring matches predicate, or string.Empty otherwise.<see cref="X11lib.XChar2b[]"/></returns>
        public static X11lib.XChar2b[] SubstringMatch(X11lib.XChar2b[] text, int startIndex, X11lib.XChar2b[] predicate)
        {
            if (text == null)
            {
                return(new X11lib.XChar2b[0]);
            }
            if (predicate == null)
            {
                return(new X11lib.XChar2b[0]);
            }


            if (text.Length - startIndex < predicate.Length)
            {
                return(new X11lib.XChar2b[0]);
            }

            List <X11lib.XChar2b> result = new List <X11lib.XChar2b> ();

            X11lib.XChar2b asteric = new X11lib.XChar2b('*');
            X11lib.XChar2b qmark   = new X11lib.XChar2b('?');

            for (int index = 0; index < predicate.Length; index++)
            {
                // [1] Either current char matches the predicate's current mask char.
                if (text[startIndex + index] == predicate[index] ||
                    predicate[index] == asteric /* '*' = Multi-char joker! */ ||
                    predicate[index] == qmark /* '?' = Single-char joker! */)
                {
                    result.Add(text[startIndex + index]);
                }
                // [2] Or the predicate's current mask char is a multi-char joker.
                else if (index > 0 && predicate[index - 1] == asteric /* '*' = Multi-char joker! */)
                {
                    // [A] Either multi-char joker represents a sub-string length of 0 characters.
                    if (text[startIndex + index - 1] == predicate[index])
                    {
                        index--;
                    }
                    // [B] Or the multi-char joker represents a sub-string length of >= 1 character(s).
                    else
                    {
                        do
                        {
                            // [a] Either current char matches the predicate's current mask char.
                            if (text[startIndex + index] == predicate[index])
                            {
                                result.Add(text[startIndex + index]);
                                break;
                            }
                            // [b] Or the current char isn't the last char and matches the predicate's last joker.
                            if (startIndex + index < text.Length - 1)
                            {
                                result.Add(text[startIndex + index]);
                                startIndex++;
                            }
                            // [c] Or the current char don't match at all.
                            else
                            {
                                return(new X11lib.XChar2b[0]);
                            }
                        } while (true);
                    }
                }
                // [3] Or the current char don't match at all.
                else
                {
                    return(new X11lib.XChar2b[0]);
                }
            }
            return(result.ToArray());
        }
Ejemplo n.º 8
0
 /// <summary>Convert a 2 byte (0...65.536) character into a C# character (2 byte (0...65.536) character).</summary>
 /// <param name="text">The 2 byte (0...65.536) character to convert.<see cref="X11lib.XChar2b[]"/></param>
 /// <returns>The C# character (2 byte (0...65.536) character).<see cref="System.Char"/></returns>
 public static char XChar2bToChar(X11lib.XChar2b c)
 {
     return((char)((((int)c.byte1) << 8) + (int)(c.byte2)));
 }