Beispiel #1
0
        private void CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        {
            if (_paint == null)
            {
                var display = Game.Activity.WindowManager.DefaultDisplay;
                var metrics = new DisplayMetrics();
                display.GetMetrics(metrics);

                _fontScaleFactor = metrics.ScaledDensity;

                _paint = new Paint(PaintFlags.AntiAlias);
                _paint.Color = Android.Graphics.Color.White;
                _paint.TextAlign = Paint.Align.Left;
                // _paint.LinearText = true;
            }

            _paint.TextSize = fontSize;

            var ext = System.IO.Path.GetExtension(fontName);
            if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
            {

				var path = System.IO.Path.Combine(CCContentManager.SharedContentManager.RootDirectory, fontName);
                var activity = Game.Activity;

                try
                {
                    var typeface = Typeface.CreateFromAsset(activity.Assets, path);
                    _paint.SetTypeface(typeface);
                }
                catch (Exception)
                {
                    _paint.SetTypeface(Typeface.Create(fontName, TypefaceStyle.Normal));
                }
            }
            else
            {
                _paint.SetTypeface(Typeface.Create(fontName, TypefaceStyle.Normal));
            }

            _fontMetrix = _paint.GetFontMetrics();
        }
Beispiel #2
0
        // ===========================================================
        // Constructors
        // ===========================================================

        public Font(Texture pTexture, Typeface pTypeface, float pSize, bool pAntiAlias, int pColor)
        {
            this.mTexture = pTexture;
            this.mTextureWidth = pTexture.GetWidth();
            this.mTextureHeight = pTexture.GetHeight();

            this.mPaint = new Paint();
            this.mPaint.SetTypeface(pTypeface);
            this.mPaint.Color = pColor;
            this.mPaint.TextSize = pSize;
            this.mPaint.AntiAlias = pAntiAlias;

            this.mBackgroundPaint = new Paint();
            this.mBackgroundPaint.Color = Color.Transparent;
            this.mBackgroundPaint.SetStyle(Style.Fill);

            this.mFontMetrics = this.mPaint.GetFontMetrics();
            this.mLineHeight = (int)FloatMath.Ceil(Math.Abs(this.mFontMetrics.Ascent) + Math.Abs(this.mFontMetrics.Descent));
            this.mLineGap = (int)(FloatMath.Ceil(this.mFontMetrics.Leading));
        }