Beispiel #1
0
 public void BeginCappedLine(LineCapStyles startCap, Graphics.Size startSize, LineCapStyles endCap, Graphics.Size endSize,
                             SolidColor color, double width)
 {
     capLinePen = new Pen(new SolidColorBrush(color), width);
     capLinePen.StartLineCap = PlatformUtility.ToWPFLineCap(startCap);
     capLinePen.EndLineCap   = PlatformUtility.ToWPFLineCap(endCap);
 }
Beispiel #2
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));
        }
Beispiel #3
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 #4
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);
            }
        }
Beispiel #5
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));
            }
        }