Exemplo n.º 1
0
        public MainPage()
        {
            this.InitializeComponent();

            writeFactory        = new WriteFactory();
            writeFontCollection = writeFactory.GetSystemFontCollection();
            int count = writeFontCollection.GetFontFamilyCount();

            string[] fonts = new string[count];

            for (int i = 0; i < count; i++)
            {
                WriteFontFamily writeFontFamily = writeFontCollection.GetFontFamily(i);

                WriteLocalizedStrings writeLocalizedStrings = writeFontFamily.GetFamilyNames();

                int nameCount = writeLocalizedStrings.GetCount();
                int index;

                if (writeLocalizedStrings.FindLocaleName("en-us", out index))
                {
                    fonts[i] = writeLocalizedStrings.GetString(index);
                }
            }

            lstbox.ItemsSource = fonts;

            Loaded += (sender, args) =>
            {
                lstbox.SelectedIndex = 0;
            };
        }
Exemplo n.º 2
0
 private void Dispose()
 {
     RoundStroke?.Dispose();
     HardStroke?.Dispose();
     DefaultText?.Dispose();
     WriteFactory?.Dispose();
     Context?.Dispose();
     Handle?.Dispose();
     Factory?.Dispose();
 }
Exemplo n.º 3
0
        public void TestMethod1()
        {
            var writeFactory = new WriteFactory();
            // 獲得系統字體集合資訊。
            var writeFontCollection = writeFactory.GetSystemFontCollection();
            var count        = writeFontCollection.GetFontFamilyCount();
            var fontFamilies = new FontFamily[count];

            for (var i = 0; i < count; i++)
            {
                var writeFontFamily       = writeFontCollection.GetFontFamily(i);
                var writeLocalizedStrings = writeFontFamily.GetFamilyNames();
                // 以名稱實例化字體。
                fontFamilies[i] = new FontFamily(writeLocalizedStrings.GetString(0));
            }

            Assert.IsFalse(count < 0);
        }
Exemplo n.º 4
0
        public EditorPageViewModule()
        {
            // 初始化字型
            var writeFactory = new WriteFactory();
            WriteFontCollection writeFontCollection = writeFactory.GetSystemFontCollection();
            var count        = writeFontCollection.GetFontFamilyCount();
            var fontFamilies = new FontFamily[count];

            for (var i = 0; i < count; i++)
            {
                WriteFontFamily       writeFontFamily       = writeFontCollection.GetFontFamily(i);
                WriteLocalizedStrings writeLocalizedStrings = writeFontFamily.GetFamilyNames();
                if (writeLocalizedStrings.FindLocaleName("en-us", out var index))
                {
                    fontFamilies[i] = new FontFamily(writeLocalizedStrings.GetString(index));
                }
                else
                {
                    fontFamilies[i] = new FontFamily(writeLocalizedStrings.GetString(0));
                }
            }
            var fontItems = fontFamilies.
                            OrderBy(fontFamily => fontFamily.Source).
                            Select(fontFamily =>
                                   new StackPanel {
                Tag      = fontFamily.Source,
                Children =
                {
                    new TextBlock {
                        Text       = fontFamily.Source,
                        FontFamily = fontFamily
                    },
                    new TextBlock {
                        Text = fontFamily.Source
                    }
                }
            });

            FontCollection = new ObservableCollection <StackPanel>(fontItems);
        }
Exemplo n.º 5
0
        public MainPage()
        {
            this.InitializeComponent();

            ContentTextBox.Text  = "Type quick!";
            txtblk.Text          = "Type quick!";
            FontSizeTextBox.Text = "192";
            txtblk.FontSize      = 192;

            writeFactory        = new WriteFactory();
            writeFontCollection = writeFactory.GetSystemFontCollection();
            int           count = writeFontCollection.GetFontFamilyCount();
            List <string> fonts = new List <string>();

            for (int i = 0; i < count; i++)
            {
                WriteFontFamily writeFontFamily = writeFontCollection.GetFontFamily(i);

                WriteLocalizedStrings writeLocalizedStrings = writeFontFamily.GetFamilyNames();

                int nameCount = writeLocalizedStrings.GetCount();
                int index;

                if (writeLocalizedStrings.FindLocaleName("en-us", out index))
                {
                    fonts.Add(writeLocalizedStrings.GetString(index));
                }
            }

            // Sort alphabetically
            fonts = fonts.OrderBy(item => item).ToList();

            lstbox.ItemsSource = fonts;

            Loaded += (sender, args) =>
            {
                lstbox.SelectedIndex = 0;
            };
        }
Exemplo n.º 6
0
        public TextBlockRenderer(SpriteRenderer sprite, [CanBeNull] IFontCollectionProvider collection, string fontName, FontWeight fontWeight,
                                 FontStyle fontStyle, FontStretch fontStretch, float fontSize, int kerningAdjustment = 0)
        {
            AssertDevice();
            IncRefCount();
            Sprite            = sprite;
            FontSize          = fontSize;
            KerningAdjustment = kerningAdjustment;

            Monitor.Enter(sprite.Device);
            try {
                _rtp = new RenderTargetProperties {
                    HorizontalDpi       = 96,
                    VerticalDpi         = 96,
                    Type                = RenderTargetType.Default,
                    PixelFormat         = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied),
                    MinimumFeatureLevel = FeatureLevel.Direct3D10
                };

                if (collection != null)
                {
                    var c = collection.GetCollection(WriteFactory);
                    if (c.FindFamilyName(fontName) == -1)
                    {
                        fontName = c[0].FamilyNames.get_String(0);
                    }
                    Font = WriteFactory.CreateTextFormat(fontName, c, fontWeight, fontStyle, fontStretch, fontSize,
                                                         CultureInfo.CurrentCulture.Name);
                }
                else
                {
                    Font = WriteFactory.CreateTextFormat(fontName, fontWeight, fontStyle, fontStretch, fontSize, CultureInfo.CurrentCulture.Name);
                }
            } finally {
                Monitor.Exit(sprite.Device);
            }

            CreateCharTable(0);
        }
Exemplo n.º 7
0
        public MainPage()
        {
            this.InitializeComponent();

            ContentTextBox.Text = "Type quick!";
            txtblk.Text = "Type quick!";
            FontSizeTextBox.Text = "192";
            txtblk.FontSize = 192;

            writeFactory = new WriteFactory();
            writeFontCollection = writeFactory.GetSystemFontCollection();
            int count = writeFontCollection.GetFontFamilyCount();
            List<string> fonts = new List<string>();

            for (int i = 0; i < count; i++)
            {
                WriteFontFamily writeFontFamily = writeFontCollection.GetFontFamily(i);

                WriteLocalizedStrings writeLocalizedStrings = writeFontFamily.GetFamilyNames();

                int nameCount = writeLocalizedStrings.GetCount();
                int index;

                if (writeLocalizedStrings.FindLocaleName("en-us", out index))
                {
                    fonts.Add(writeLocalizedStrings.GetString(index));
                }
            }

            // Sort alphabetically
            fonts = fonts.OrderBy(item => item).ToList();

            lstbox.ItemsSource = fonts;

            Loaded += (sender, args) =>
            {
                lstbox.SelectedIndex = 0;
            };
        }
Exemplo n.º 8
0
        async void OnLoaded(object sender, RoutedEventArgs args)
        {
            // Get fonts from DirectXWrapper library
            WriteFactory        writeFactory        = new WriteFactory();
            WriteFontCollection writeFontCollection =
                writeFactory.GetSystemFontCollection();

            int count = writeFontCollection.GetFontFamilyCount();

            string[] fonts = new string[count];

            for (int i = 0; i < count; i++)
            {
                WriteFontFamily writeFontFamily =
                    writeFontCollection.GetFontFamily(i);

                WriteLocalizedStrings writeLocalizedStrings =
                    writeFontFamily.GetFamilyNames();
                int index;

                if (writeLocalizedStrings.FindLocaleName("en-us", out index))
                {
                    fonts[i] = writeLocalizedStrings.GetString(index);
                }
                else
                {
                    fonts[i] = writeLocalizedStrings.GetString(0);
                }
            }

            Array.Sort <string>(fonts);
            fontFamilyComboBox.ItemsSource = fonts;

            // Load current document
            StorageFolder localFolder = ApplicationData.Current.LocalFolder;

            try
            {
                StorageFile storageFile = await localFolder.CreateFileAsync("RichTextEditor.rtf",
                                                                            CreationCollisionOption.OpenIfExists);

                IRandomAccessStream stream = await storageFile.OpenAsync(FileAccessMode.Read);

                richEditBox.Document.LoadFromStream(TextSetOptions.FormatRtf, stream);
            }
            catch
            {
                // Ignore exceptions here
            }

            // Load selection settings
            IPropertySet propertySet = ApplicationData.Current.LocalSettings.Values;

            if (propertySet.ContainsKey("SelectionStart"))
            {
                richEditBox.Document.Selection.StartPosition = (int)propertySet["SelectionStart"];
            }

            if (propertySet.ContainsKey("SelectionEnd"))
            {
                richEditBox.Document.Selection.EndPosition = (int)propertySet["SelectionEnd"];
            }
        }