Example #1
0
        /// <summary>Load resources here.</summary>
        /// <param name="e">Not used.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.Keyboard.KeyDown += KeyDown;


            /*
             * QFontBuilderConfiguration config = new QFontBuilderConfiguration();
             * config.PageWidth = 1024;
             * config.PageHeight = 1024;
             * config.GlyphMargin = 6;
             * QFont.CreateTextureFontFiles("BURNSTOW.TTF", 120, config, "metalFont");
             */


            heading2 = QFont.FromQFontFile("woodenFont.qfont", 1.0f, new QFontLoaderConfiguration(true));

            var builderConfig = new QFontBuilderConfiguration(true);

            builderConfig.ShadowConfig.blurRadius  = 1;                                         //reduce blur radius because font is very small
            builderConfig.TextGenerationRenderHint = TextGenerationRenderHint.ClearTypeGridFit; //best render hint for this font
            mainText = new QFont("Fonts/times.ttf", 14, builderConfig);


            heading1 = new QFont("Fonts/HappySans.ttf", 72, new QFontBuilderConfiguration(true));


            controlsText = new QFont("Fonts/HappySans.ttf", 32, new QFontBuilderConfiguration(true));


            codeText = new QFont("Fonts/Comfortaa-Regular.ttf", 12, FontStyle.Regular);

            heading1.Options.Colour           = new Color4(0.2f, 0.2f, 0.2f, 1.0f);
            mainText.Options.Colour           = new Color4(0.1f, 0.1f, 0.1f, 1.0f);
            mainText.Options.DropShadowActive = false;
            codeText.Options.Colour           = new Color4(0.0f, 0.0f, 0.4f, 1.0f);

            QFontBuilderConfiguration config2 = new QFontBuilderConfiguration();

            config2.SuperSampleLevels = 1;
            //   font = new QFont("Fonts/times.ttf", 16,config2);
            //   font.Options.Colour = new Color4(0.1f, 0.1f, 0.1f, 1.0f);
            //   font.Options.CharacterSpacing = 0.1f;


            monoSpaced = new QFont("Fonts/Anonymous.ttf", 10);
            monoSpaced.Options.Colour = new Color4(0.1f, 0.1f, 0.1f, 1.0f);

            Console.WriteLine(" Monospaced : " + monoSpaced.IsMonospacingActive);


            GL.ClearColor(1.0f, 1.0f, 1.0f, 0.0f);
            GL.Disable(EnableCap.DepthTest);
        }
Example #2
0
        static void InitializeWorker()
        {
            try
            {
                heading2 = QFont.FromQFontFile("AltData/QuickFont/woodenFont.qfont", 1.0f, new QFontLoaderConfiguration(true));

                var builderConfig = new QFontBuilderConfiguration(true);
                builderConfig.ShadowConfig.blurRadius  = 1;                                         //reduce blur radius because font is very small
                builderConfig.TextGenerationRenderHint = TextGenerationRenderHint.ClearTypeGridFit; //best render hint for this font

                //mainText = new QFont("AltData/QuickFont/Fonts/times.ttf", 14, builderConfig);
                mainText = new QFont("AltData/Fonts/Open-Sans/OpenSans-Regular.ttf", 14, builderConfig);


                heading1 = new QFont("AltData/QuickFont/Fonts/HappySans.ttf", 72, new QFontBuilderConfiguration(true));


                controlsText = new QFont("AltData/QuickFont/Fonts/HappySans.ttf", 32, new QFontBuilderConfiguration(true));


                codeText = new QFont("AltData/QuickFont/Fonts/Comfortaa-Regular.ttf", 12, FontStyle.Regular);

                heading1.Options.Colour           = Color.LimeGreen * 1.2;
                mainText.Options.Colour           = Color.White;
                mainText.Options.DropShadowActive = false;
                codeText.Options.Colour           = ColorR.Yellow;

                QFontBuilderConfiguration config2 = new QFontBuilderConfiguration();
                config2.SuperSampleLevels = 1;
                //   font = new QFont("Fonts/times.ttf", 16,config2);
                //   font.Options.Colour = new Color4(0.1, 0.1, 0.1, 1.0f);
                //   font.Options.CharacterSpacing = 0.1f;


                monoSpaced = new QFont("AltData/QuickFont/Fonts/Anonymous.ttf", 10);
                monoSpaced.Options.Colour = Color.WhiteSmoke;    // new ColorR(0.1, 0.1, 0.1);

                //Console.WriteLine(" Monospaced : " + monoSpaced.IsMonospacingActive);
            }
            catch
            {
            }
            finally
            {
                m_Initialized = true;
#if !UNITY_WEBPLAYER
                m_InitializeThread = null;
#endif
            }
        }
Example #3
0
        public void SetUpFont(int textsize, string fontfilepath = null)
        {
            var builderConfig = new QFontBuilderConfiguration(false);

            builderConfig.ShadowConfig             = null;
            builderConfig.TextGenerationRenderHint = TextGenerationRenderHint.ClearTypeGridFit;


            if (fontfilepath.Contains(".qfont"))
            {
                currentFont = QFont.FromQFontFile(fontfilepath, textsize / 24f, new QFontLoaderConfiguration());
            }
            else
            {
                currentFont  = new QFont(fontfilepath, textsize, builderConfig);
                fontFilePath = fontfilepath;
            }

            textSize = textsize;  //set the get only property for record keeping
        }
Example #4
0
        /// <summary>
        /// Initializes a new <see cref="Font" /> instance using the specified builder configuration.
        /// </summary>
        /// <param name="name">
        /// Name to use for identifying this font, must be unique.
        /// Can be set to null to allow the constructor to auto-generate a name for the font.
        /// </param>
        /// <param name="file">Path to the font file (TTF or qfont).</param>
        /// <param name="size">Size (in points) to use for this font.</param>
        /// <param name="type">
        /// The type of font. This will be detected by the file extension,
        /// but can be manually specified to control the fallback type used if
        /// one was not detected from the file name
        /// </param>
        /// <param name="fontConstructionConfig">The <see cref="FontConstructionConfig" /> containing relevant font build/load configurations.</param>
        public Font(string name, string file, int size, FontType type, FontConstructionConfig fontConstructionConfig)
        {
            _file = file;
            _size = size;

            var ext = Path.GetExtension(_file);

            if (string.IsNullOrEmpty(ext))
            {
                throw new EngineException("Failed to get file extension of font file!",
                                          new IOException("System.IO.Path.GetExtension returned null or empty for specified file."));
            }

            // Disable resharper warning, we are checking for null, resharper doesn't like IsNullOrEmpty
            // ReSharper disable PossibleNullReferenceException
            ext = ext.TrimStart('.').ToLower();
            // ReSharper restore PossibleNullReferenceException

            switch (ext)
            {
            case "ttf":
                type = FontType.TTF;
                break;

            case "qfont":
                type = FontType.QFont;
                break;
            }

            _type = type;

            QFont font;

            switch (_type)
            {
            case FontType.TTF:
                if (fontConstructionConfig.BuildConfig == null)
                {
                    throw new EngineException("Builder configuration was null but requested font type requires a builder config!",
                                              new ArgumentException("BuildConfig was null.", "fontConstructionConfig"));
                }
                font = new QFont(_file, _size, fontConstructionConfig.BuildConfig);
                break;

            case FontType.QFont:
                if (fontConstructionConfig.LoadConfig == null)
                {
                    throw new EngineException("Loader configuration was null but requested font type requires a loader config!",
                                              new ArgumentException("LoadConfig was null.", "fontConstructionConfig"));
                }
                font = QFont.FromQFontFile(_file, fontConstructionConfig.LoadConfig);
                break;

            default:
                throw new EngineException("Unsupported font type: " + _type,
                                          new ArgumentException("Font type unsupported.", "type"));
            }

            if (font == null)
            {
                throw new EngineException("Font failed to initialize!",
                                          new ArgumentException("Font failed to initialize.", "file"));
            }

            _qfont = font;

            _name = name ?? GetDefaultName(file, size);
        }