Beispiel #1
0
        void UpdateFontFamilyAndSize(DependencyObject target)
        {
            FontFamily fontFamily;
            FontWeight fontWeight          = FontWeights.Normal;
            bool       fOverrideFontWeight = false;
            double     scaleFactor;

            var service  = GetInstance();
            var fontType = GetFontType(target);

            if (service.GetOverrideFontApiValues())
            {
                fontFamily          = new FontFamily(service.GetFontFamilyOverride());
                scaleFactor         = service.GetFontScaleFactorOverride(fontType) / 100.0;
                fontWeight          = service.GetFontWeightOverride();
                fOverrideFontWeight = true;
            }
            else
            {
                var languageFont = service.GetLanguageFont(fontType);
                fontFamily  = new FontFamily(languageFont.FontFamily);
                scaleFactor = languageFont.ScaleFactor / 100.0;
            }

            double sizeToUse = GetFontSize(target) * scaleFactor;

            var control = target as Control;

            if (control != null)
            {
                control.FontFamily = fontFamily;
                if (fOverrideFontWeight)
                {
                    control.FontWeight = fontWeight;
                }
                if (sizeToUse != 0.0)
                {
                    control.FontSize = sizeToUse;
                }
                else
                {
                    control.ClearValue(Control.FontSizeProperty);
                }
            }
            else
            {
                var textBlock = target as TextBlock;
                if (textBlock != null)
                {
                    textBlock.FontFamily = fontFamily;
                    if (fOverrideFontWeight)
                    {
                        textBlock.FontWeight = fontWeight;
                    }
                    if (sizeToUse != 0.0)
                    {
                        textBlock.FontSize = sizeToUse;
                    }
                    else
                    {
                        textBlock.ClearValue(TextBlock.FontSizeProperty);
                    }
                }
                else
                {
                    RichTextBlock richTextBlock = (target as RichTextBlock);
                    if (richTextBlock != null)
                    {
                        richTextBlock.FontFamily = fontFamily;
                        if (fOverrideFontWeight)
                        {
                            richTextBlock.FontWeight = fontWeight;
                        }
                        if (sizeToUse != 0.0)
                        {
                            richTextBlock.FontSize = sizeToUse;
                        }
                        else
                        {
                            richTextBlock.ClearValue(RichTextBlock.FontSizeProperty);
                        }
                    }
                    else
                    {
                        TextElement textElement = (target as TextElement);
                        if (textElement != null)
                        {
                            textElement.FontFamily = fontFamily;
                            if (fOverrideFontWeight)
                            {
                                textElement.FontWeight = fontWeight;
                            }
                            if (sizeToUse != 0.0)
                            {
                                textElement.FontSize = sizeToUse;
                            }
                            else
                            {
                                textElement.ClearValue(TextElement.FontSizeProperty);
                            }
                        }
                    }
                }
            }
        }