void OnListBoxSelectionChanged(object sender, SelectionChangedEventArgs args)
        {
            string fontFamily = (sender as ListBox).SelectedItem as string;

            if (fontFamily == null)
            {
                return;
            }

            foregroundTextBlock.FontFamily = new FontFamily(fontFamily);
            shadowTextBlock.FontFamily     = foregroundTextBlock.FontFamily;

            int index;

            if (writeFontCollection.FindFamilyName(fontFamily, out index))
            {
                WriteFontFamily writeFontFamily = writeFontCollection.GetFontFamily(index);
                WriteFont       writeFont       = writeFontFamily.GetFirstMatchingFont(FontWeights.Normal,
                                                                                       FontStretch.Normal,
                                                                                       FontStyle.Normal);
                WriteFontMetrics fontMetrics = writeFont.GetMetrics();

                double fractionAboveBaseline = (double)fontMetrics.Ascent /
                                               (fontMetrics.Ascent + fontMetrics.Descent + fontMetrics.LineGap);

                shadowTextBlock.RenderTransformOrigin = new Point(0, fractionAboveBaseline);
            }
        }
Esempio n. 2
0
        void OnListBoxSelectionChanged(object sender, SelectionChangedEventArgs args)
        {
            string fontFamily = (sender as ListBox).SelectedItem as string;

            if (fontFamily == null)
            {
                return;
            }

            txtblk.FontFamily = new FontFamily(fontFamily);

            int index;

            if (writeFontCollection.FindFamilyName(fontFamily, out index))
            {
                WriteFontFamily writeFontFamily = writeFontCollection.GetFontFamily(index);
                WriteFont       writeFont       = writeFontFamily.GetFirstMatchingFont(FontWeights.Normal,
                                                                                       FontStretch.Normal,
                                                                                       FontStyle.Normal);
                WriteFontMetrics fontMetrics = writeFont.GetMetrics();
                double           fontSize    = txtblk.FontSize;
                double           ascent      = fontSize * fontMetrics.Ascent / fontMetrics.DesignUnitsPerEm;
                double           capsHeight  = fontSize * fontMetrics.CapHeight / fontMetrics.DesignUnitsPerEm;
                double           xHeight     = fontSize * fontMetrics.XHeight / fontMetrics.DesignUnitsPerEm;
                double           descent     = fontSize * fontMetrics.Descent / fontMetrics.DesignUnitsPerEm;
                double           lineGap     = fontSize * fontMetrics.LineGap / fontMetrics.DesignUnitsPerEm;

                baselineLine.Y1   = baselineLine.Y2 = ascent;
                capsHeightLine.Y1 = capsHeightLine.Y2 = ascent - capsHeight;
                xHeightLine.Y1    = xHeightLine.Y2 = ascent - xHeight;
                descenderLine.Y1  = descenderLine.Y2 = ascent + descent;
                lineGapLine.Y1    = lineGapLine.Y2 = ascent + descent + lineGap;
            }
        }
        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;
            };
        }
Esempio 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);
        }
Esempio 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;
            };
        }
        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;
            };
        }
Esempio n. 7
0
        void OnListBoxSelectionChanged(object sender, SelectionChangedEventArgs args)
        {
            string fontFamily = (sender as ListBox).SelectedItem as string;

            if (fontFamily == null)
            {
                return;
            }

            txtblk.FontFamily = new FontFamily(fontFamily);

            int index;

            if (writeFontCollection.FindFamilyName(fontFamily, out index))
            {
                WriteFontFamily writeFontFamily = writeFontCollection.GetFontFamily(index);
                WriteFont       writeFont       = writeFontFamily.GetFirstMatchingFont(FontWeights.Normal,
                                                                                       FontStretch.Normal,
                                                                                       FontStyle.Normal);
                curMetrics = writeFont.GetMetrics();
                updateMetricLines();
            }
        }
        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"];
            }
        }