Exemplo n.º 1
0
        internal static Graphics.Size MeasureText(DrawingContext dc, string text, string fontName, double fontSize, Drawing.Text.FontStyles style)
        {
            ResourcePoolManager resManager = dc.Renderer.ResourcePoolManager;

            FormattedText ft = new FormattedText(text, System.Threading.Thread.CurrentThread.CurrentCulture,
                                                 FlowDirection.LeftToRight, resManager.GetTypeface(fontName),
                                                 fontSize * PlatformUtility.GetDPI() / 72.0, null);

            return(new Graphics.Size(ft.Width, ft.Height));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        public void DrawText(string text, string fontName, double size, SolidColor color, Rectangle rect, ReoGridHorAlign halign, ReoGridVerAlign valign)
        {
            if (rect.Width > 0 && rect.Height > 0 && !string.IsNullOrEmpty(text))
            {
                FormattedText ft = new FormattedText(text, System.Threading.Thread.CurrentThread.CurrentCulture,
                                                     FlowDirection.LeftToRight, this.resourceManager.GetTypeface(fontName),
                                                     size * PlatformUtility.GetDPI() / 72.0,
                                                     this.resourceManager.GetBrush(color));

                ft.MaxTextWidth  = rect.Width;
                ft.MaxTextHeight = rect.Height;

                switch (halign)
                {
                default:
                    break;

                case ReoGridHorAlign.Left:
                    ft.TextAlignment = TextAlignment.Left;
                    break;

                case ReoGridHorAlign.Center:
                    ft.TextAlignment = TextAlignment.Center;
                    break;

                case ReoGridHorAlign.Right:
                    ft.TextAlignment = TextAlignment.Right;
                    break;
                }

                switch (valign)
                {
                default:
                    break;

                case ReoGridVerAlign.Middle:
                    rect.Y += (rect.Height - ft.Height) / 2;
                    break;

                case ReoGridVerAlign.Bottom:
                    rect.Y += (rect.Height - ft.Height);
                    break;
                }

                g.DrawText(ft, rect.Location);
            }
        }
Exemplo n.º 4
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));
            }
        }