Example #1
0
        public bool Add(ulong id, IFontModel font)
        {
            if (_fonts.ContainsKey(id))
            {
                _frameworkMessenger.Report("FontCollection: Unable to add font, ulong exists in collection");
                return(false);
            }

            _fonts.Add(id, font);
            return(true);
        }
Example #2
0
        private float MeasureString(string text, float fontSize, IFontModel font)
        {
            var fnt = font.SubFontAtSize(fontSize);

            var length = 0.0f;

            for (var c = 0; c < text.Length; c++)
            {
                var ch = text[c];

                if (fnt.Characters.ContainsKey(ch))
                {
                    length += fnt.Characters[ch].XAdvance;
                }
            }
            length *= fontSize / fnt.Size;
            return(length);
        }
Example #3
0
 public Font(IFontModel model)
 {
     this.mModel = model;
 }
Example #4
0
 public void SetFont(IFontModel font)
 {
     copy((XMLFontModel)font);
 }
Example #5
0
 private void ReleaseFontResources(IFontModel font)
 {
     font?.ReleaseReources(_gpuSurfaceManager);
 }
Example #6
0
 internal Font(IFontModel model)
 {
     mModel = model;
 }
Example #7
0
        private void DrawString(ulong stage,
                                ref CoordinateSpace target,
                                ref string text,
                                Colour colour,
                                ref float fontSize,
                                ref Vector2 position,
                                ref TextJustify justify,
                                ref float depth,
                                ref int layer,
                                IFontModel fntFamily,
                                ref bool usKerningsWhereAvaliable)
        {
            if (fntFamily == null)
            {
                return;
            }

            var fnt = fntFamily.SubFontAtSize(fontSize);

            var lineHeight = fontSize * (fnt.LineHeight / fnt.Size);

            float strLength = 0.0f;

            if (justify == TextJustify.Centre || justify == TextJustify.Right)
            {
                strLength = _fontManager.MeasureStringLength(text, fontSize, fntFamily);
            }

            var x_curr = position.X;
            var y_curr = position.Y + (0.5f * fontSize);
            var scalar = fontSize / fnt.Size;

            if (justify == TextJustify.Right || justify == TextJustify.Centre)
            {
                switch (justify)
                {
                case TextJustify.Right:
                    x_curr -= strLength;
                    break;

                case TextJustify.Centre:
                    x_curr -= 0.5f * strLength;
                    break;
                }
            }

            var startx = (int)x_curr; //this forces pixel line ups.. maybe this is a toggle later

            for (var c = 0; c < text.Length; c++)
            {
                var ch = text[c];

                //Deal with specials (f***s up string measure and justify for now)
                switch (ch)
                {
                case '\n':
                    x_curr  = startx;
                    y_curr -= lineHeight;
                    continue;

                case '\t':
                    x_curr += fontSize;
                    continue;
                }

                int xPosKerningAdjust = 0;
                if (usKerningsWhereAvaliable && c != 0 && fnt.HasKernings)
                {
                    var lastCh = text[c - 1];

                    if (fnt.Kernings.ContainsKey(lastCh))
                    {
                        var d0 = fnt.Kernings[lastCh];
                        if (d0.ContainsKey(ch))
                        {
                            xPosKerningAdjust = d0[ch];
                        }
                    }
                }

                FontCharacter chr;

                if (fnt.Characters.ContainsKey(ch))
                {
                    chr = fnt.Characters[ch];
                }
                else
                {
                    chr = fnt.Characters['?'];
                }

                var page = chr.Page;

                var tex = fnt.Textures[page].Id;
                var ww  = chr.Width * scalar;
                var hh  = chr.Height * scalar;

                var x0 = x_curr + (scalar * (chr.XOffset + xPosKerningAdjust));
                var x1 = x0 + ww;
                var y0 = y_curr - (scalar * chr.YOffset);
                var y1 = y0 - hh;

                var xt0 = chr.X0;
                var yt0 = chr.Y0;
                var xt1 = chr.X1;
                var yt1 = chr.Y1;

                Draw(stage,
                     target,
                     FillType.Textured,
                     new Vertex2D[]
                {
                    new Vertex2D {
                        Position = new Vector2(x0, y0), TexCoord0 = new Vector2(xt0, yt0), TexCoord1 = Vector2.Zero, TexWeighting = 1.0f, Colour = Colour.White
                    },
                    new Vertex2D {
                        Position = new Vector2(x1, y0), TexCoord0 = new Vector2(xt1, yt0), TexCoord1 = Vector2.Zero, TexWeighting = 1.0f, Colour = Colour.White
                    },
                    new Vertex2D {
                        Position = new Vector2(x0, y1), TexCoord0 = new Vector2(xt0, yt1), TexCoord1 = Vector2.Zero, TexWeighting = 1.0f, Colour = Colour.White
                    },
                    new Vertex2D {
                        Position = new Vector2(x1, y1), TexCoord0 = new Vector2(xt1, yt1), TexCoord1 = Vector2.Zero, TexWeighting = 1.0f, Colour = Colour.White
                    },
                },
                     new int[]
                {
                    0, 1, 2, 2, 1, 3
                },
                     colour,
                     tex,
                     0UL,
                     TextureCoordinateMode.Mirror,
                     TextureCoordinateMode.Mirror,
                     depth,
                     layer);

                x_curr += scalar * chr.XAdvance;
            }
        }
 public void SetFont(IFontModel font)
 {
     this.SetFont((XMLFontModel)font);
 }