Example #1
0
        private void onExportedObjectSelected(ExportedObjectSelectedMessage message)
        {
            string extension = Path.GetExtension(message.Filename)?.ToLowerInvariant();

            switch (extension)
            {
            case ".ogg": {
                Task.Run(() => playSound(new FileStream(message.Filename, FileMode.Open), resetToken())).FireAndForget();

                break;
            }

            case ".dds": {
                DdsFile image = new DdsFile(message.Filename);

                viewModel.MipMaps = null;

                viewModel.Texture = image.BitmapSource;

                break;
            }

            default: {
                break;
            }
            }
        }
Example #2
0
        private void onExportedObjectSelected(ExportedObjectSelectedMessage message)
        {
            string extension = Path.GetExtension(message.Filename)?.ToLowerInvariant();

            switch (extension)
            {
            case ".ogg":
            {
                Task.Run(() => playSound(new FileStream(message.Filename, FileMode.Open), resetToken())).FireAndForget();

                break;
            }

            case ".dds":
            {
                DdsFile image = new DdsFile(message.Filename);

                viewModel.MipMaps = null;

                viewModel.Texture = image.BitmapSource;

                break;
            }

            case ".ttf":
            case ".otf":
            {
                using (MemoryStream fontms = new MemoryStream(File.ReadAllBytes(message.Filename)))
                {
                    var fontfamilies = FontConversion.Load(fontms);
                    var fontfamily   = fontfamilies.Families.First();

                    using (Bitmap b = new Bitmap(600, 400))
                    {
                        using (Graphics g = Graphics.FromImage(b))
                        {
                            g.Clear(Color.White);         // White background
                            using (Font font = new Font(fontfamily, 24, FontStyle.Regular, GraphicsUnit.Pixel))
                            {
                                using (Font arial = new Font(new FontFamily("Arial"), 24, FontStyle.Regular, GraphicsUnit.Pixel))
                                {
                                    using (SolidBrush solidBrush = new SolidBrush(Color.Black))
                                    {
                                        g.DrawString(String.Format("{0}, {1}, {2}px", font.Name, font.Style, 24), arial, solidBrush, new RectangleF(10, 10, 600, 600));
                                    }
                                }
                                using (SolidBrush solidBrush = new SolidBrush(Color.Black))
                                {
                                    g.DrawString("abcdefghijklmnopqrstuvwxyz", font, solidBrush, new RectangleF(10, 36, 600, 600));
                                    g.DrawString("ABCDEFGHIJKLMNOPQRSTUVWXYZ", font, solidBrush, new RectangleF(10, 62, 600, 600));
                                    g.DrawString("1234567890", font, solidBrush, new RectangleF(10, 88, 600, 600));
                                    g.DrawString("The quick brown fox jumps over the lazy dog.", font, solidBrush, new RectangleF(10, 114, 600, 600));
                                }
                            }
                            using (Font font = new Font(fontfamily, 48, FontStyle.Regular, GraphicsUnit.Pixel))
                            {
                                using (SolidBrush solidBrush = new SolidBrush(Color.Black))
                                {
                                    g.DrawString("The quick brown fox jumps over the lazy dog.", font, solidBrush, new RectangleF(10, 166, 600, 600));
                                }
                            }
                        }
                        viewModel.Texture = BitmapConversion.ToWpfBitmap(b);
                    }
                }
                break;
            }
            }
        }