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
        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.º 3
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.º 4
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.º 5
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"];
            }
        }