예제 #1
0
        public static Font Create(StyleInfo style)
        {
            Font font = new Font();

            if ((!style.IsFontFamilySet() && !style.IsFontSizeSet()) && ((!style.IsFontStretchSet() && !style.IsFontStyleSet()) && !style.IsFontWeightSet()))
            {
                return(null);
            }
            if ((style != null) && (style.FontFamily != null))
            {
                string familyName = FontHelper.GetEquivalentEnglishFontName(style.FontFamily.Source);
                font.FontFamily = new FontFamily(familyName);
            }
            font.FontSize    = style.FontSize;
            font.FontStretch = style.FontStretch;
            font.FontStyle   = style.FontStyle;
            font.FontWeight  = style.FontWeight;
            font.gdiCharSet  = 0;
            return(font);
        }
예제 #2
0
파일: EditingLayer.cs 프로젝트: Daoting/dt
        void ApplyEditorStyle(StyleInfo p_info, bool p_isFormula)
        {
            var cell = _editingCell.BindingCell;

            if (p_info.FontSize > 0.0)
            {
                Editor.FontSize = p_info.FontSize * _ownPanel.Excel.ZoomFactor;
            }
            else
            {
                Editor.ClearValue(TextBlock.FontSizeProperty);
            }

            Editor.FontStyle   = p_info.FontStyle;
            Editor.FontWeight  = p_info.FontWeight;
            Editor.FontStretch = p_info.FontStretch;

            if (p_info.IsFontFamilySet() && (p_info.FontFamily != null))
            {
                Editor.FontFamily = p_info.FontFamily;
            }
            else if (p_info.IsFontThemeSet())
            {
                string        fontTheme = p_info.FontTheme;
                IThemeSupport worksheet = cell.Worksheet;
                if (worksheet != null)
                {
                    Editor.FontFamily = worksheet.GetThemeFont(fontTheme);
                }
            }
            else
            {
                Editor.ClearValue(Control.FontFamilyProperty);
            }

            Brush foreground = null;

            if (p_info.IsForegroundSet())
            {
                foreground = p_info.Foreground;
            }
            else if (p_info.IsForegroundThemeColorSet())
            {
                string fname = p_info.ForegroundThemeColor;
                if ((!string.IsNullOrEmpty(fname) && (cell.Worksheet != null)) && (cell.Worksheet.Workbook != null))
                {
                    foreground = new SolidColorBrush(cell.Worksheet.Workbook.GetThemeColor(fname));
                }
            }
            if (foreground != null)
            {
                Editor.Foreground = foreground;
            }
            else
            {
                Editor.Foreground = BrushRes.BlackBrush;
            }

            Editor.VerticalContentAlignment = p_info.VerticalAlignment.ToVerticalAlignment();
            if (p_isFormula)
            {
                Editor.TextAlignment = Windows.UI.Xaml.TextAlignment.Left;
            }
            else if (!cell.ActualWordWrap)
            {
                switch (cell.ToHorizontalAlignment())
                {
                case HorizontalAlignment.Left:
                case HorizontalAlignment.Stretch:
                    Editor.TextAlignment = Windows.UI.Xaml.TextAlignment.Left;
                    break;

                case HorizontalAlignment.Center:
                    Editor.TextAlignment = Windows.UI.Xaml.TextAlignment.Center;
                    break;

                case HorizontalAlignment.Right:
                    Editor.TextAlignment = Windows.UI.Xaml.TextAlignment.Right;
                    break;
                }
            }
            else
            {
                Editor.TextAlignment = Windows.UI.Xaml.TextAlignment.Left;
            }

            Editor.SelectionStart = Editor.Text.Length;
            Editor.SelectAll();
        }