Beispiel #1
0
        public void UpdateCellRenderFont(Cell cell, Core.UpdateFontReason reason)
        {
            var sheet = cell.Worksheet;

            if (sheet == null || sheet.controlAdapter == null)
            {
                return;
            }

            var controlStyle = sheet.controlAdapter.ControlStyle;

            double dpi      = PlatformUtility.GetDPI();
            double fontSize = cell.InnerStyle.FontSize * sheet.renderScaleFactor * dpi / 72.0;

            if (cell.formattedText == null || cell.formattedText.Text != cell.InnerDisplay)
            {
                SolidColor textColor;

                if (!cell.RenderColor.IsTransparent)
                {
                    textColor = cell.RenderColor;
                }
                else if (cell.InnerStyle.HasStyle(PlainStyleFlag.TextColor))
                {
                    // cell text color, specified by SetRangeStyle
                    textColor = cell.InnerStyle.TextColor;
                }
                else if (!controlStyle.TryGetColor(ControlAppearanceColors.GridText, out textColor))
                {
                    // default cell text color
                    textColor = SolidColor.Black;
                }

                cell.formattedText = new System.Windows.Media.FormattedText(cell.InnerDisplay,
                                                                            System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight,
                                                                            base.resourceManager.GetTypeface(cell.InnerStyle.FontName),
                                                                            fontSize,
                                                                            base.resourceManager.GetBrush(textColor));
            }
            else
            {
                cell.formattedText.SetFontFamily(cell.InnerStyle.FontName);
                cell.formattedText.SetFontSize(fontSize);
            }

            cell.formattedText.SetFontWeight(
                cell.InnerStyle.Bold ? System.Windows.FontWeights.Bold : System.Windows.FontWeights.Normal);

            cell.formattedText.SetFontStyle(PlatformUtility.ToWPFFontStyle(cell.InnerStyle.fontStyles));

            cell.formattedText.SetTextDecorations(PlatformUtility.ToWPFFontDecorations(cell.InnerStyle.fontStyles));
        }
Beispiel #2
0
        public void UpdateCellRenderFont(Cell cell, Core.UpdateFontReason reason)
        {
            var sheet = cell.Worksheet;

            if (sheet == null || sheet.controlAdapter == null)
            {
                return;
            }

            double dpi      = PlatformUtility.GetDPI();
            double fontSize = cell.InnerStyle.FontSize * sheet.renderScaleFactor * dpi / 72.0;

            if (cell.formattedText == null || cell.formattedText.Text != cell.InnerDisplay)
            {
                SolidColor textColor = DecideTextColor(cell);

                cell.formattedText = new System.Windows.Media.FormattedText(cell.InnerDisplay,
                                                                            System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight,
                                                                            base.resourceManager.GetTypeface(cell.InnerStyle.FontName),
                                                                            fontSize,
                                                                            base.resourceManager.GetBrush(textColor));
            }
            else if (reason == Core.UpdateFontReason.FontChanged || reason == Core.UpdateFontReason.ScaleChanged)
            {
                cell.formattedText.SetFontFamily(cell.InnerStyle.FontName);
                cell.formattedText.SetFontSize(fontSize);
            }
            else if (reason == Core.UpdateFontReason.TextColorChanged)
            {
                SolidColor textColor = DecideTextColor(cell);
                cell.formattedText.SetForegroundBrush(resourceManager.GetBrush(textColor));
            }

            var ft = cell.formattedText;

            if (reason == Core.UpdateFontReason.FontChanged || reason == Core.UpdateFontReason.ScaleChanged)
            {
                ft.SetFontWeight(
                    cell.InnerStyle.Bold ? System.Windows.FontWeights.Bold : System.Windows.FontWeights.Normal);

                ft.SetFontStyle(PlatformUtility.ToWPFFontStyle(cell.InnerStyle.fontStyles));

                ft.SetTextDecorations(PlatformUtility.ToWPFFontDecorations(cell.InnerStyle.fontStyles));
            }
        }