Exemple #1
0
        public override FieldFont Process(FontDescription input, ContentProcessorContext context)
        {
            var msdfgen = Path.Combine(Directory.GetCurrentDirectory(), this.ExternalPath);
            var objPath = Path.Combine(Directory.GetCurrentDirectory(), "obj");

            if (File.Exists(msdfgen))
            {
                var glyphs = new FieldGlyph[input.Characters.Count];

                Atlas = new AtlasBuilder(input.Characters.Count, (int)Resolution);
                // Generate a distance field for each character using msdfgen
                Parallel.For(
                    0,
                    input.Characters.Count,
                    i =>
                {
                    var c     = input.Characters[i];
                    glyphs[i] = CreateFieldGlyphForCharacter(c, input, msdfgen, objPath);
                });

                var kerning = ReadKerningInformation(input.Path, input.Characters);
                return(new FieldFont(input.Path, glyphs.Where(x => x != null).ToArray(), kerning, this.Range, Atlas.Finish()));
            }

            throw new FileNotFoundException(
                      "Could not find msdfgen. Check your content processor parameters",
                      msdfgen);
        }
Exemple #2
0
        private FieldGlyph CreateFieldGlyphForCharacter(char c, FontDescription input, string msdfgen, string objPath)
        {
            var metrics    = CreateDistanceFieldForCharacter(input, msdfgen, objPath, c);
            var path       = GetOuputPath(objPath, input, c);
            int atlasIndex = 0;

            try
            {
                using (var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                    atlasIndex = Atlas.AddChar(c, stream);
            } catch (Exception)
            {
                return(null);
            }
            File.Delete(path);
            var glyph = new FieldGlyph(c, atlasIndex, metrics);

            return(glyph);
        }
Exemple #3
0
        public void Draw(GraphicsDevice gd, string text, Vector2 pos, Color color, Vector2 scale, Matrix?mat)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            var point = new Vector2(0, 0);
            var atlas = GetAtlas(gd);

            var wv = Matrix.CreateScale(scale.X, scale.Y, 1)
                     * Matrix.CreateTranslation(pos.X, pos.Y, 0);

            if (mat != null)
            {
                wv = wv * mat.Value;

                wv.Decompose(out var scale2, out var quat, out var trans);
                scale.X = scale2.X;
                scale.Y = scale2.Y;
            }

            var wvp    = wv * Matrix.CreateOrthographicOffCenter(new Rectangle(0, 0, gd.Viewport.Width, gd.Viewport.Height), -0.1f, 1f);
            var effect = MSDFEffect;

            var itemW = 1f / Font.Atlas.Width;
            var itemH = 1f / Font.Atlas.Height;

            var textureWidth  = Font.Atlas.GlyphSize;
            var textureHeight = Font.Atlas.GlyphSize;

            var cutUX = itemW / textureWidth;
            var cutUY = itemH / textureHeight;

            var cut2UX = cutUX * 2;
            var cut2UY = cutUY * 2;

            var uW = itemW - 2 * cutUX;
            var uH = itemH - 2 * cutUY;

            var cutX = 1f / textureWidth;
            var cutY = 1f / textureHeight;

            var atlasWidth = Font.Atlas.Width;
            var pairs      = Font.StringToPair;

            effect.Parameters["WorldViewProjection"].SetValue(wvp);
            effect.Parameters["PxRange"].SetValue(this.Font.PxRange);
            effect.Parameters["TextureSize"].SetValue(new Vector2(Atlas.Width, Atlas.Height));
            effect.Parameters["Color"].SetValue(color.ToVector4());
            effect.Parameters["GlyphTexture"].SetValue(Atlas);

            effect.CurrentTechnique = effect.Techniques[0];

            var verts = new List <MSDFFontVert>();
            var inds  = new List <int>();

            FieldGlyph next = null;

            if (text.Length > 0)
            {
                var c = text[0];
                next = Font.GetGlyph(c);
                if (next == null && c != '\r')
                {
                    next = Font.GetGlyph(Fallback);
                }
            }
            for (int i = 0; i < text.Length; i++)
            {
                var glyph = next;
                if (glyph == null)
                {
                    if (i + 1 >= text.Length)
                    {
                        break;
                    }
                    var c = text[i + 1];
                    next = Font.GetGlyph(c);
                    if (next == null && c != '\r')
                    {
                        next = Font.GetGlyph(Fallback);
                    }
                    continue;
                }

                var mscale      = glyph.Metrics.Scale;
                var glyphHeight = (textureHeight - 2) / mscale;
                var glyphWidth  = (textureWidth - 2) / mscale;

                var left   = point.X - glyph.Metrics.Translation.X + 1 / mscale;
                var bottom = point.Y + glyph.Metrics.Translation.Y + YOff / VectorScale - 1 / mscale;

                var right = left + glyphWidth;
                var top   = bottom - glyphHeight;

                var tx = (glyph.AtlasIndex % atlasWidth) * itemW + cutUX;
                var ty = (glyph.AtlasIndex / atlasWidth) * itemH + cutUY;

                var derivative = (new Vector2(uW / (right - left), uH / (bottom - top)) / scale) / 2;

                if (!char.IsWhiteSpace(glyph.Character))
                {
                    RenderQuad(inds, verts, new Vector2(left, bottom), new Vector2(right, top), new Vector2(tx, ty + uH), new Vector2(tx + uW, ty), derivative);
                }

                point.X += glyph.Metrics.Advance;

                if (i < text.Length - 1)
                {
                    var c = text[i + 1];
                    next = Font.GetGlyph(c);
                    if (next == null && c != '\r')
                    {
                        next = Font.GetGlyph(Fallback);
                    }

                    if (next != null)
                    {
                        KerningPair pair;
                        if (pairs.TryGetValue(new string(new char[] { glyph.Character, next.Character }), out pair))
                        {
                            point.X += pair.Advance;
                        }
                    }
                }
            }

            effect.CurrentTechnique.Passes[0].Apply();
            if (verts.Count == 0)
            {
                return;
            }

            gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, verts.ToArray(), 0, verts.Count, inds.ToArray(), 0, inds.Count / 3);
        }
Exemple #4
0
        public Vector2 MeasureString(string text)
        {
            var pairs = Font.StringToPair;

            if (string.IsNullOrEmpty(text))
            {
                return(new Vector2(0, Height / VectorScale));
            }

            var size = new Vector2(0, Height / VectorScale);

            FieldGlyph next = null;

            if (text.Length > 0)
            {
                var c = text[0];
                next = Font.GetGlyph(c);
                if (next == null && c != '\r')
                {
                    next = Font.GetGlyph(Fallback);
                }
            }
            for (int i = 0; i < text.Length; i++)
            {
                var glyph = next;
                if (next == null)
                {
                    if (i + 1 >= text.Length)
                    {
                        break;
                    }
                    var c = text[i + 1];
                    next = Font.GetGlyph(c);
                    if (next == null && c != '\r')
                    {
                        next = Font.GetGlyph(Fallback);
                    }
                    continue;
                }

                size.X += glyph.Metrics.Advance;

                if (i < text.Length - 1)
                {
                    var c = text[i + 1];
                    next = Font.GetGlyph(c);
                    if (next == null && c != '\r')
                    {
                        next = Font.GetGlyph(Fallback);
                    }

                    if (next != null)
                    {
                        KerningPair pair;
                        if (pairs.TryGetValue(new string(new char[] { glyph.Character, next.Character }), out pair))
                        {
                            size.X += pair.Advance;
                        }
                    }
                }
            }

            return(size);
        }
        public void LinkEveryController()
        {
            //obvious question - "why":
            //this is for mono ahead of time compilation. By referencing everything here,
            //we make sure these classes and generic variants are AOT compiled

            var load  = new LoadingScreen();
            var loadc = new LoadingScreenController(null, null, null);


            var screen = new PersonSelectionEdit();
            var t      = new TerrainController(null, null, null, null, null);
            var n      = new Network.Network(null, null, null, null);
            var v      = new Credits();
            var cd     = new Common.DataService.ClientDataService(null, null, null);
            var c      = new CoreGameScreen();
            var cc     = new CoreGameScreenController(null, null, null, null, null);
            var s      = new SandboxGameScreen();
            var ps     = new PersonSelection(null, null);
            var psc    = new PersonSelectionController(null, null, null, null);
            var cl1    = new Server.Clients.AuthClient("");
            var cl2    = new Server.Clients.CityClient("");
            var cl3    = new Server.Clients.ApiClient("");
            var ls     = new LoginScreen(null);
            var lc     = new LoginController(null, null);
            var lr     = new Regulators.LoginRegulator(null, null, null);

            var seled    = new PersonSelectionEditController(null, null);
            var casr     = new Regulators.CreateASimRegulator(null);
            var purch    = new Regulators.PurchaseLotRegulator(null);
            var conn     = new Regulators.LotConnectionRegulator(null, null, null);
            var t2       = new Regulators.CityConnectionRegulator(null, null, null, null, Kernel, null);
            var neigh    = new Regulators.GenericActionRegulator <NhoodRequest, NhoodResponse>(null);
            var bulletin = new Regulators.GenericActionRegulator <BulletinRequest, BulletinResponse>(null);
            var regu     = new Regulators.RegulatorsModule();

            var prov = new CacheProvider();
            var clip = new AuthClientProvider(null);
            var citp = new CityClientProvider(null);
            var ar   = new Server.Clients.AriesClient(null);
            var tso  = new cTSOSerializerProvider(null);
            var ser  = new Server.Protocol.Voltron.DataService.cTSOSerializer(null);
            var mods = new ModelSerializerProvider(null);
            var dbs  = new Common.DatabaseService.DatabaseService(null);
            var cds  = new Common.DataService.ClientDataService(null, null, null);

            var arp  = new Server.Protocol.Aries.AriesProtocolDecoder(null);
            var are  = new Server.Protocol.Aries.AriesProtocolEncoder(null);
            var serc = new Common.Serialization.SerializationContext(null, null);

            var ff   = new FieldFont();
            var fa   = new FieldAtlas();
            var fg   = new FieldGlyph();
            var kp   = new KerningPair();
            var met  = new Metrics();
            var dict = new Dictionary <char, FieldGlyph>();

            var packets = new object[]
            {
                new ClientOnlinePDU(),
                new HostOnlinePDU(),
                new SetIgnoreListPDU(),
                new SetIgnoreListResponsePDU(),
                new SetInvinciblePDU(),
                new RSGZWrapperPDU(),
                new TransmitCreateAvatarNotificationPDU(),
                new DataServiceWrapperPDU(),
                new DBRequestWrapperPDU(),
                new OccupantArrivedPDU(),
                new ClientByePDU(),
                new ServerByePDU(),
                new FindPlayerPDU(),
                new FindPlayerResponsePDU(),
                new ChatMsgPDU(),
                new AnnouncementMsgPDU(),

                new MessagingWindowController(null, null, null),
                new Controllers.Panels.SecureTradeController(null, null),
                new GizmoSearchController(null, null, null),
                new GizmoTop100Controller(null, null, null, null, null),
                new LotAdmitController(null, null, null),
                new GizmoController(null, null, null),
                new PersonPageController(null, null, null),
                new LotPageController(null, null),
                new BookmarksController(null, null, null),
                new RelationshipDialogController(null, null, null, null),
                new InboxController(null, null, null, null),
                new JoinLotProgressController(null, null),
                new DisconnectController(null, null, null, null, null),
                new GenericSearchController(null, null),
                new NeighPageController(null, null),
                new RatingListController(null, null, null),
                new RatingSummaryController(null, null, null),
                new NeighborhoodActionController(null),

                ImmutableList.Create <uint>(),
                ImmutableList.Create <JobLevel>(),
                ImmutableList.Create <Relationship>(),
                ImmutableList.Create <Bookmark>(),
                ImmutableList.Create <bool>(),

                new cTSOGenericData(),
            };
        }
Exemple #6
0
 public MSDFGlyph(FieldGlyph glyph, MSDFFont font)
 {
     Glyph = glyph;
     Font  = font;
 }