public void UpdateCellRenderFont(Cell cell, Core.UpdateFontReason reason) { var sheet = cell.Worksheet; if (sheet == null) { return; } var style = cell.InnerStyle; var fontStyle = StyleUtility.CreateFontStyle(style); // unknown bugs happened here (several times) // cell.Style is null (cell.Style.FontSize is zero) if (style.FontSize <= 0) { style.FontSize = 6f; } float fontSize = (float)Math.Round(style.FontSize * sheet.renderScaleFactor, 1); var renderFont = cell.RenderFont; if (renderFont == null || renderFont.Name != style.FontName || renderFont.Size != fontSize || renderFont.Style != (System.Drawing.FontStyle)fontStyle) { cell.RenderFont = this.resourceManager.GetFont(style.FontName, fontSize, (System.Drawing.FontStyle)fontStyle); } }
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)); }
public void UpdateCellRenderFont(ReoGridCell cell, Core.UpdateFontReason reason) { if (reason == Core.UpdateFontReason.FontChanged) { if (cell.renderFont != null) { lock (cell.renderFont) { cell.renderFont.Dispose(); } } cell.renderFont = Typeface.Create(cell.InnerStyle.FontName, GetTypefaceStyle(cell.InnerStyle.fontStyles)); } }
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)); } }