Esempio n. 1
0
        // ###############################################################################
        // ### C O N S T R U C T I O N   A N D   I N I T I A L I Z A T I O N
        // ###############################################################################

        #region Construction

        /// <summary>Initializing constructor.</summary>
        /// <param name="display">The display to initialize the font specifications for.<see cref="IntPtr"/></param>
        /// <param name="preferredCharSet">The preferred charset or empty string for no preference.
        /// Sort fonts with this charset to the top. <see cref="System.String"/> </param>
        public FontSpecificationList(IntPtr display, string preferredCharSet)
        {
            _preferredCharSet = preferredCharSet;

            TInt   numFonts   = 0;
            string fontFilter = "-*-*-*-*-*-*-*-*-*-*-*-*-*";
            //string fontFilter = "-*-*-*-*-*-*-0-0-0-0-*-*-*";
            //                   -1-2-3-4-5-6-7-8-9-A-B-C-D
            //                    1 = Foundry
            //                    2 = Family
            //                    3 = Weight
            //                    4 = Slant
            //                    5 = Width
            //                    6 = Extra
            //                    7 = Pixel
            //                    8 = TenthOfPoint
            //                    9 = Horz resolution
            //                    A = Vert resolution
            //                    B = Spacing
            //                    C = TenthOfAveragePixelWidth
            //                    D = Characterset
            IntPtr fontNameArray = X11lib.XListFonts(display, fontFilter, (TInt)20000, ref numFonts);

            for (int countFont = 0; countFont < (int)numFonts; countFont++)
            {
                IntPtr fontNameDeref = System.Runtime.InteropServices.Marshal.ReadIntPtr(fontNameArray, IntPtr.Size * countFont);
                string fontName      = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(fontNameDeref);
                if (!string.IsNullOrEmpty(fontName))
                {
                    _qualifiedFontNames.Add(fontName);
                    this.AddFontSpecification(fontName);

                    // This takes a lot of time!!!

                    /*
                     * IntPtr fontResourceId = X11lib.XLoadFont (display, fontName);
                     * if (fontResourceId != IntPtr.Zero)
                     * {
                     *      IntPtr fontStruct = X11lib.XQueryFont (display, fontResourceId);
                     *      if (fontStruct != IntPtr.Zero)
                     *      {
                     *              string name = "";
                     *              TUlong val = (TUlong)0;
                     *              TBoolean res = X11lib.XGetFontProperty (fontStruct, X11atoms.XA_FAMILY_NAME, ref val);
                     *              if (res == (TBoolean)1)
                     *              {
                     *                      IntPtr nameRef = X11lib.XGetAtomName (display, (IntPtr)val);
                     *                      if (nameRef != IntPtr.Zero)
                     *                      {
                     *                              name = System.Runtime.InteropServices.Marshal.PtrToStringAuto (nameRef);
                     *                              X11lib.XFree (nameRef);
                     *                      }
                     *              }
                     *              X11lib.XFreeFontInfo (IntPtr.Zero, fontStruct, (TInt)0);
                     *      }
                     *      //X11lib.XFreeFont (display, fontResourceId);
                     * }
                     */
                }
            }
            X11lib.XFreeFontNames(fontNameArray);
            fontNameArray = IntPtr.Zero;
            // http://coot.googlecode.com/svn/trunk/ccp4mg-utils/pygl/x11_font.cc

            _qualifiedFontNames.Sort();
            this.Sort();
        }