Esempio n. 1
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;
            }
        }
        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. 3
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();
            }
        }