/// <summary> /// Tests whether the glyph height of the capital letter X using the selected font is larger than the default glyph height. /// </summary> /// <returns>Returns false if the user cancels the operation.</returns> private bool TestGlyphSize() { Grid testGrid = new Grid(); int fontSize = Math.Max(FontSettings.FontSize, FontSettings.KanjiFontSize); Run testRun = new Run { Text = "X", FontFamily = FontSettings.FontFamily, FontSize = fontSize, FontWeight = FontSettings.FontWeight, Foreground = Brushes.Red }; TextBlock testText = new TextBlock(testRun) { Margin = new Thickness(GlyphHorizontalMargin, 0, GlyphHorizontalMargin, 0), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; testGrid.Children.Add(testText); testGrid.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); testGrid.Arrange(new Rect(testGrid.DesiredSize)); BitmapSource glyphBitmap = BitmapFunctions.CaptureScreen(testGrid, 96.0, 96.0); Rect innerRect = DetectInnerRectFromPixels(glyphBitmap, new Rect(0.0, 0.0, testGrid.ActualWidth, testGrid.ActualHeight)); //if (testGrid.ActualHeight > GlyphHeight) if (innerRect.Height > GlyphHeight) { int newGlyphHeight = (int)Math.Ceiling(innerRect.Height); /*string message = Properties.Resources.Error_Generation_GlyphSizeTooLargeMessage + * Environment.NewLine + Environment.NewLine + * string.Format(Properties.Resources.Error_Generation_GlyphSizeConfirmation, newGlyphHeight); * * var answer = MessageBox.Show( * message, * Properties.Resources.Error_Generation_GlyphSizeTooLargeTitle, * MessageBoxButton.YesNo, * MessageBoxImage.Information); * * if (answer == MessageBoxResult.No) * return false; * else*/ GlyphHeight = newGlyphHeight; } return(true); }
private void AddInnerRect(string glyph, Grid glyphGrid, TextBlock innerText, double x, double y) { Rect innerRect; BitmapSource glyphBitmap = BitmapFunctions.CaptureScreen(glyphGrid, 96.0, 96.0); if (string.IsNullOrWhiteSpace(glyph) || glyphBitmap == null || !UseAccurateInnerRects) { double innerWidth = innerText.ActualWidth + SpacingAdjustment; if (innerWidth < 0) { innerWidth = 0; } innerRect = CreateInnerRect( x: x, y: y, outerHeight: OuterRects[glyph].Height, innerWidth: innerWidth, innerHeight: innerText.ActualHeight); } else { innerRect = DetectInnerRectFromPixels(glyphBitmap, OuterRects[glyph]); // Create new outer rect to keep horizontal margin constant OuterRects[glyph] = new Rect( innerRect.X - GlyphHorizontalMargin, OuterRects[glyph].Y, innerRect.Width + (GlyphHorizontalMargin * 2), OuterRects[glyph].Height); RectCanvas.Children.RemoveAt(RectCanvas.Children.Count - 1); CreateOuterRectangleForCanvas(glyph, OuterRects[glyph]); } /*if(inner.Height > DefaultGlyphHeight) * { * var answer = MessageBox.Show( * "The glyph height for the selected font is larger than the default (52 pixels).\n\n", * "Glyph Size Too Large"); * }*/ Brush rectBrush = Brushes.DarkViolet; Rect outer = OuterRects[glyph]; // Check if the inner rect is larger than the outer if (innerRect.Top < outer.Top || innerRect.Left < outer.Left || innerRect.Bottom > outer.Bottom || innerRect.Right > outer.Right) { if (!RectErrorMessageShown) { //MessageBox.Show(Properties.Resources.Error_Generation_OverlappingBoundingRects, Properties.Resources.Error_Warning); RectErrorMessageShown = true; } // Resize the width of the inner rect to fit inside the outer if (innerRect.Right > outer.Right) { innerRect = new Rect( innerRect.X, innerRect.Y, innerRect.Width - (outer.Right - innerRect.Right), innerRect.Height); } rectBrush = Brushes.Red; } InnerRects.Add(glyph, innerRect); CreateInnerRectangleForCanvas(innerRect, rectBrush); }