protected override Size ArrangeOverride(Size finalSize)
        {
            double width  = finalSize.Width;
            double height = finalSize.Height;

            rectangle.Arrange(new Rect(0, 0, width, height));
            if (directImage != null)
            {
                if (directImage.d3dImage != null)
                {
                    directImage.SetImageSize((int)width, (int)height, 96);
                }
            }
            else
            {
                messageBlock.Arrange(new Rect(0, 0, width, height));
            }
            return(finalSize);
        }
        public TextBlock CalculateHeight(TextBlock currentTextBlock, double width)
        {
            var tb = new TextBlock {
                Text = currentTextBlock.Text, FontSize = currentTextBlock.FontSize
            };

            tb.MinWidth     = width;
            tb.MaxWidth     = width;
            tb.Width        = width;
            tb.MaxHeight    = Double.PositiveInfinity;
            tb.TextWrapping = TextWrapping.WrapWholeWords;
            //tb.Style = Style;

            tb.Measure(new Size(width, Double.PositiveInfinity));
            tb.Arrange(new Rect(0, 0, width, tb.DesiredSize.Height));
            tb.UpdateLayout();

            return(tb);
        }
Example #3
0
        private void BuildLanguageCodeComboBox()
        {
            double languageCodeComboBoxMaxWidth = -1;

            this.LanguageCodeComboBox.ItemSource = Config.CultureCodes.ConvertAll(x =>
            {
                CultureInfo info = new CultureInfo(x);
                TextBlock block  = new TextBlock()
                {
                    Text = (info.NativeName == info.DisplayName) ? info.NativeName : $"{info.NativeName} ({info.DisplayName})",
                };
                block.SetResourceReference(TextBlock.ForegroundProperty, "BlackBrush");
                block.Arrange(new Rect(block.DesiredSize));
                languageCodeComboBoxMaxWidth = Math.Max(languageCodeComboBoxMaxWidth, block.ActualWidth);
                return(block);
            });
            this.LanguageCodeComboBox.ComboBoxWidth = (languageCodeComboBoxMaxWidth == -1) ? 250 : languageCodeComboBoxMaxWidth + 40;
            this.LanguageCodeComboBox.SelectedIndex = Config.CultureCodes.IndexOf(Core.Option.LanguageCode);
        }
Example #4
0
        /// <inheritdoc />
        public Size MeasureText(string text, ITextPaint paint)
        {
            var textBlock = new TextBlock
            {
                VerticalAlignment   = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Text          = text,
                Foreground    = new SolidColorBrush(paint.Fill.ToSystemColor()),
                FontSize      = paint.TextStyle.FontSize,
                FontFamily    = new FontFamily(paint.TextStyle.FontFamily),
                TextAlignment = paint.TextStyle.Alignment.ToSystemTextAlignment(),
                Opacity       = paint.Opacity
            };

            textBlock.Measure(new global::System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
            textBlock.Arrange(new Rect(0, 0, textBlock.DesiredSize.Width, textBlock.DesiredSize.Height));

            return(new Size(Convert.ToSingle(textBlock.ActualWidth), Convert.ToSingle(textBlock.ActualHeight)));
        }
Example #5
0
        public static BitmapSource StringToBitmapSource(this string str, int fontSize, System.Windows.Media.Color foreground, System.Windows.Media.Color background)
        {
            TextBlock tbX = new TextBlock();

            tbX.FontFamily    = new System.Windows.Media.FontFamily("Consolas");
            tbX.Foreground    = new System.Windows.Media.SolidColorBrush(foreground);
            tbX.Background    = new System.Windows.Media.SolidColorBrush(background);
            tbX.TextAlignment = TextAlignment.Center;
            tbX.FontSize      = fontSize;
            tbX.FontStretch   = FontStretches.Normal;
            tbX.FontWeight    = FontWeights.Medium;
            tbX.Text          = str;
            var size = tbX.MeasureString();

            tbX.Width  = size.Width;
            tbX.Height = size.Height;
            tbX.Measure(new Size(size.Width, size.Height));
            tbX.Arrange(new Rect(new Size(size.Width, size.Height)));
            return(tbX.ToBitmapSource());
        }
Example #6
0
        private BitmapSource RenderTextToBitmap(string text, Brush textForegroundBrush)
        {
            var textBlock = new TextBlock()
            {
                Text = text,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                Foreground          = textForegroundBrush,
                FontSize            = 40
            };

            textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            textBlock.Arrange(new Rect(new Point(0, 0), textBlock.DesiredSize));

            // Render distancesPanel to Bitmap
            var bmp = new RenderTargetBitmap((int)textBlock.ActualWidth, (int)textBlock.ActualHeight, 96, 96, PixelFormats.Pbgra32);

            bmp.Render(textBlock);

            return(bmp);
        }
Example #7
0
 public Box(int id)
 {
     Id       = id;
     Position = new Point();
     Ellipse  = new Ellipse
     {
         Width  = 200,
         Height = 200,
         Fill   = null,
         Stroke = null
     };
     Text = new TextBlock
     {
         Text       = Id.ToString(),
         Foreground = new SolidColorBrush(Colors.WhiteSmoke),
         FontSize   = 150,
         FontWeight = FontWeights.Medium
     };
     Text.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
     Text.Arrange(new Rect(Text.DesiredSize));
 }
        private Grid GetAPIKeyControls(string s)
        {
            Grid      g = new Grid();
            TextBlock t = new TextBlock
            {
                Margin            = new Thickness(5, 5, 0, 0),
                Text              = s + " key",
                VerticalAlignment = VerticalAlignment.Top
            };

            t.Measure(new Size());
            t.Arrange(new Rect());

            TextBox tb = new TextBox
            {
                Height              = 20,
                Width               = 150,
                VerticalAlignment   = VerticalAlignment.Top,
                Margin              = new Thickness(5, 20, 0, 0),
                HorizontalAlignment = HorizontalAlignment.Left,
                Text = (s == "TVDB" ? settingsObj.TVDBKey : settingsObj.TMDBKey)
            };

            Button b = new Button
            {
                Width               = 75,
                Height              = 20,
                Margin              = new Thickness(0, 20, 5, 0),
                VerticalAlignment   = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Right,
                Content             = "Update"
            };

            b.Click += (sender, EventArgs) => { Update_Click(sender, EventArgs, tb.Text, s); };

            g.Children.Add(t);
            g.Children.Add(tb);
            g.Children.Add(b);
            return(g);
        }
        private void LoadYAxis(double actualHeight)
        {
            var yAxis = YAxis.Reverse().ToArray();

            var xHeight = (actualHeight - _xHeight) / (yAxis.Length - 0.5);

            if (canvasYAxis.Children.Count > yAxis.Length)
            {
                var count = canvasYAxis.Children.Count;
                for (int i = 0; i < count - yAxis.Length; i++)
                {
                    canvasYAxis.Children.RemoveAt(canvasYAxis.Children.Count - 1);
                }
            }
            for (int i = 0; i < canvasYAxis.Children.Count; i++)
            {
                var txt = canvasYAxis.Children[i] as TextBlock;
                txt.Text = yAxis[i];
                txt.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                txt.Arrange(new Rect(txt.DesiredSize));
                Canvas.SetTop(txt, xHeight * (i + 0.5) - txt.ActualHeight / 2);
            }
            for (int i = canvasYAxis.Children.Count; i < yAxis.Length; i++)
            {
                var txt = new TextBlock()
                {
                    Text = yAxis[i],
                };
                var fore = new Binding()
                {
                    Source = this, Path = new PropertyPath("Foreground"), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                };
                BindingOperations.SetBinding(txt, TextBlock.ForegroundProperty, fore);
                txt.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                txt.Arrange(new Rect(txt.DesiredSize));
                Canvas.SetRight(txt, 10);
                Canvas.SetTop(txt, xHeight * (i + 0.5) - txt.ActualHeight / 2);
                canvasYAxis.Children.Add(txt);
            }
        }
Example #10
0
        private void drawGraph()
        {
            getTemperaturePoints(out Point[] points, out Point[] points2);


            Path path = new Path()
            {
                StrokeThickness = 3, Data = getPath(points2), Opacity = 0.5d
            };

            path.SetResourceReference(Path.StrokeProperty, "PrimaryHueDarkForegroundBrush");
            canvasTemperature.Children.Add(path);

            Path path2 = new Path()
            {
                StrokeThickness = 3, Data = getPath(points)
            };

            path2.SetResourceReference(Path.StrokeProperty, "PrimaryHueDarkForegroundBrush");
            canvasTemperature.Children.Add(path2);


            for (int i = 0; i < points.Length; i++)
            {
                TextBlock text = new TextBlock()
                {
                    Text    = Component.Forecast[i].MainInfo.Temperature.ToString("F0") + Component.Forecast[i].TemperatureUnit,
                    Padding = new Thickness(2)
                };
                text.SetResourceReference(TextBlock.BackgroundProperty, "PrimaryHueDarkForegroundBrush");
                text.SetResourceReference(TextBlock.ForegroundProperty, "PrimaryHueDarkBrush");

                text.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                text.Arrange(new Rect(text.DesiredSize));

                Canvas.SetLeft(text, points[i].X - text.ActualWidth / 2);
                Canvas.SetTop(text, points[i].Y - text.ActualHeight / 2);
                canvasTemperature.Children.Add(text);
            }
        }
Example #11
0
        public static Point GetEllipseWidthAndHeightBasedOnText(string text, int minDistanceToText = 10)
        {
            /* Calculates the width and heigth of a Textblock and returns them as a Point
             * Where Point.X represents the width and Point.Y the height
             * "text" will be the text that is to be displayed and it is used to measure the size of the shapes
             * "minDistanceToText" is the minimum Distance between the TextBlock's Rect and the Ellipse's Rect
             */

            // Create a TextBlock
            TextBlock textBlock = new TextBlock()
            {
                Text = text
            };

            // Apply the TextBlocks Size based on it's text
            textBlock.Measure(new Size(Double.PositiveInfinity, double.PositiveInfinity));
            textBlock.Arrange(new Rect(textBlock.DesiredSize));

            // Calculate and return the width and height as a Point while also considering the minimum distance
            return(new Point(textBlock.ActualWidth + 2 * minDistanceToText,
                             textBlock.ActualHeight + 2 * minDistanceToText));
        }
        /// <summary>
        /// Updates the width of the text box.
        /// </summary>
        private static void UpdateTextBoxWidth(Control textBox, int width)
        {
            var text = string.Empty;

            for (int i = 0; i <= (width + 1); i++)
            {
                text += "0";
            }
            var textBlock = new TextBlock {
                Text         = text,
                TextWrapping = TextWrapping.Wrap,
                FontFamily   = textBox.FontFamily,
                FontStyle    = textBox.FontStyle,
                FontWeight   = textBox.FontWeight,
                FontStretch  = textBox.FontStretch,
                FontSize     = textBox.FontSize
            };

            textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            textBlock.Arrange(new Rect(textBlock.DesiredSize));
            textBox.Width = textBlock.ActualWidth;
        }
Example #13
0
 protected override Size ArrangeOverride(Size finalSize)
 {
     foreach (var cell in Children.OfType <ColHeaderCell>())
     {
         cell.Arrange(new Rect(cell.Col.Left, 0, cell.Col.Width, Res.RowOuterHeight));
     }
     if (_lastDrag > -1)
     {
         Cols   cols = Lv.Cols;
         double left = -10;
         if (_lastDrag > 0 && _lastDrag < cols.Count)
         {
             left = Lv.Cols[_lastDrag].Left - 10;
         }
         else if (_lastDrag == cols.Count)
         {
             left = cols.TotalWidth - 10;
         }
         _tbDrag.Arrange(new Rect(left, 0, 20, Res.RowOuterHeight));
     }
     return(finalSize);
 }
Example #14
0
        /// <inheritdoc />
        public void DrawText(Point location, string text, ITextPaint paint)
        {
            var textBlock = new TextBlock
            {
                VerticalAlignment   = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Text          = text,
                Foreground    = new SolidColorBrush(paint.Fill.ToSystemColor()),
                FontSize      = paint.TextStyle.FontSize,
                FontFamily    = new FontFamily(paint.TextStyle.FontFamily),
                Margin        = new Thickness(location.X, location.Y, 0, 0),
                TextAlignment = paint.TextStyle.Alignment.ToSystemTextAlignment(),
                Opacity       = paint.Opacity
            };

            textBlock.Measure(new global::System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
            textBlock.Arrange(new Rect(0, 0, textBlock.DesiredSize.Width, textBlock.DesiredSize.Height));

            textBlock.Margin = new Thickness(location.X, location.Y - textBlock.ActualHeight, 0, 0);

            Canvas.Children.Add(textBlock);
        }
Example #15
0
        private void OnPrint(object sender, RoutedEventArgs e)
        {
            var printDialog = new PrintDialog();

            if (printDialog.ShowDialog() == true)
            {
                // Create the text.
                var run = new Run("This is a test of the printing functionality in the Windows Presentation Foundation.");

                // Wrap it in a TextBlock.
                var visual = new TextBlock(run)
                {
                    Margin       = new Thickness(15),
                    TextWrapping = TextWrapping.Wrap
                };
                // Allow wrapping to fit the page width.

                // Scale the TextBlock in both dimensions.
                double zoom;
                if (double.TryParse(ScaleTextBox.Text, out zoom))
                {
                    visual.LayoutTransform = new ScaleTransform(zoom / 100, zoom / 100);

                    // Get the size of the page.
                    var pageSize = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight);

                    // Trigger the sizing of the element.
                    visual.Measure(pageSize);
                    visual.Arrange(new Rect(0, 0, pageSize.Width, pageSize.Height));

                    // Print the element.
                    printDialog.PrintVisual(visual, "A Scaled Drawing");
                }
                else
                {
                    MessageBox.Show("Invalid scale value.");
                }
            }
        }
        private void LoadXAxis(double actualWidth)
        {
            var yWidth = (actualWidth - _yWidth) / (XAxis.Length - 0.5);

            if (canvasXAxis.Children.Count > XAxis.Length)
            {
                var count = canvasXAxis.Children.Count;
                for (int i = 0; i < count - XAxis.Length; i++)
                {
                    canvasXAxis.Children.RemoveAt(canvasXAxis.Children.Count - 1);
                }
            }
            for (int i = 0; i < canvasXAxis.Children.Count; i++)
            {
                var txt = canvasXAxis.Children[i] as TextBlock;
                txt.Text = XAxisGap == 0 ? XAxis[i] : (i % (XAxisGap + 1) != 0 ? "" : XAxis[i]);
                txt.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                txt.Arrange(new Rect(txt.DesiredSize));
                Canvas.SetLeft(txt, yWidth * i + _yWidth - (txt.ActualWidth / 2));
            }
            for (int i = canvasXAxis.Children.Count; i < XAxis.Length; i++)
            {
                var txt = new TextBlock()
                {
                    Text = XAxis[i],
                };
                var fore = new Binding()
                {
                    Source = this, Path = new PropertyPath("Foreground"), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                };
                BindingOperations.SetBinding(txt, TextBlock.ForegroundProperty, fore);
                txt.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                txt.Arrange(new Rect(txt.DesiredSize));
                Canvas.SetTop(txt, 5);
                Canvas.SetLeft(txt, yWidth * i + _yWidth - (txt.ActualWidth / 2));
                canvasXAxis.Children.Add(txt);
            }
        }
Example #17
0
        private void Button_OnClick(object sender, RoutedEventArgs e)
        {
            PrintDialog printDialog = new PrintDialog();

            if (printDialog.ShowDialog() == true)
            {
                // Create the text.
                Run run = new Run("This is a test of the printing functionality " +
                                  "in the Windows Presentation Foundation.");

                // Wrap it in a TextBlock.
                TextBlock visual = new TextBlock();
                visual.Inlines.Add(run);

                // Use margin to get a page border.
                visual.Margin = new Thickness(15);

                // Allow wrapping to fit the page width.
                visual.TextWrapping = TextWrapping.Wrap;

                // Scale the TextBlock up in both dimensions by a factor of 5.
                // (In this case, increasing the font would have the same effect,
                // because the TextBlock is the only element.)
                visual.LayoutTransform = new ScaleTransform(5, 5);

                // Size the element.
                Size pageSize = new Size(printDialog.PrintableAreaWidth,
                                         printDialog.PrintableAreaHeight);

                visual.Measure(pageSize);

                visual.Arrange(new Rect(0, 0, pageSize.Width, pageSize.Height));

                // Print the element.
                printDialog.PrintVisual(visual, "A Scaled Drawing");
            }
        }
Example #18
0
        public static WriteableBitmap GetTextWriteableBitmap(string text, Orientation orientation = Orientation.Horizontal)
        {
            var txtBlock = new TextBlock();

            txtBlock.Text = text;

            // 1) get current dpi
            PresentationSource pSource = PresentationSource.FromVisual(Application.Current.MainWindow);
            Matrix             m       = pSource.CompositionTarget.TransformToDevice;
            double             _dpiX   = m.M11 * 96;
            double             _dpiY   = m.M22 * 96;

            txtBlock.Measure(new Size(double.MaxValue, double.MaxValue));
            txtBlock.Arrange(new Rect(new Point(0, 0), new Size(double.MaxValue, double.MaxValue)));
            var sz = txtBlock.DesiredSize;
            // 2) create RenderTargetBitmap
            var elementBitmap = new RenderTargetBitmap((int)sz.Width, (int)sz.Height, _dpiX, _dpiY, PixelFormats.Default);

            // 3) undo element transformation
            var drawingVisual = new DrawingVisual();

            using (var dc = drawingVisual.RenderOpen())
            {
                var visualBrush = new VisualBrush(txtBlock);
                dc.DrawRectangle(visualBrush, null, new Rect(new Point(0, 0), sz));
            }
            // 4) draw element
            elementBitmap.Render(drawingVisual);

            var wb = new WriteableBitmap(elementBitmap);

            if (orientation == Orientation.Vertical)
            {
                wb = wb.Rotate(270);
            }
            return(wb);
        }
Example #19
0
 protected override Size ArrangeOverride(Size finalSize)
 {
     _tbNumberOfCharacter.Arrange(new Rect(new Point(0, 0), finalSize));
     return(finalSize);
 }
Example #20
0
 public static double MeasureHeight(this TextBlock block)
 {
     block.Arrange(new Rect());
     return(block.ActualHeight);
 }
Example #21
0
 protected override Size ArrangeOverride(Size finalSize)
 {
     _tbPlaceholder.Arrange(new Rect(new Point(4, 2), finalSize));
     return(finalSize);
 }
        private void AddGridLineLables()
        {
            #region verticals

            foreach (var ln in FGridLines)
            {
                var inf = ln.Tag as GridlineInfo;

                if (inf == null)
                {
                    continue;
                }

                var f = inf.F;

                var pos = new Point(ln.X1, Math.Max(ln.Y1, ln.Y2));

                var txt = new TextBlock();
                //txt.Background = Brushes.White;
                //txt.RenderTransformOrigin = new Point(0.5, 0.5);
                //txt.LayoutTransform = new RotateTransform(90);

                txt.TextAlignment       = TextAlignment.Right;
                txt.HorizontalAlignment = HorizontalAlignment.Center;

                txt.Text = f.ToString();

                txt.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                txt.Arrange(new Rect(0, 0, 1000, 1000));

                Canvas.SetLeft(txt, pos.X - txt.ActualWidth / 2);
                Canvas.SetTop(txt, pos.Y);

                GridsCanvas.Children.Add(txt);
            }

            #endregion

            #region horizontals

            foreach (var ln in SvGridLines)
            {
                var inf = ln.Tag as GridlineInfo;

                if (inf == null)
                {
                    continue;
                }

                var sv = inf.Sv;

                var pos = new Point(ln.X1, Math.Min(ln.Y1, ln.Y2));

                var txt = new TextBlock();

                //txt.TextAlignment = TextAlignment.Left;
                txt.HorizontalAlignment = HorizontalAlignment.Center;
                txt.VerticalAlignment   = VerticalAlignment.Center;

                txt.Text = sv.ToString();

                txt.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                txt.Arrange(new Rect(0, 0, 1000, 1000));

                Canvas.SetLeft(txt, pos.X - txt.ActualWidth);
                Canvas.SetTop(txt, pos.Y - txt.ActualHeight / 2);

                GridsCanvas.Children.Add(txt);
            }

            #endregion

            #region Sas

            var maxLengthSd = SdGridLines.OrderBy(i => i.GetLength()).LastOrDefault();

            {
                foreach (var saln in SaGridLines)
                {
                    var seg1 =
                        new LineSegment2D(
                            new Epsi1on.MathAndGeometric.Geometry.Point2D(maxLengthSd.X1, maxLengthSd.Y1),
                            new Epsi1on.MathAndGeometric.Geometry.Point2D(maxLengthSd.X2, maxLengthSd.Y2));


                    var seg2 = new LineSegment2D(
                        new Epsi1on.MathAndGeometric.Geometry.Point2D(saln.X1, saln.Y1),
                        new Epsi1on.MathAndGeometric.Geometry.Point2D(saln.X2, saln.Y2));

                    var collisionStat = LineSegment2D.GetIntersection(seg1, seg2);

                    if (collisionStat.LocusType != LocusType.OnePointIntersection)
                    {
                        continue;
                    }

                    var collision = collisionStat.IntersectionPoint.Value;

                    var tb = new TextBlock();
                    tb.Text = ((GridlineInfo)saln.Tag).Sa.ToString();

                    Canvas.SetLeft(tb, collision.X);
                    Canvas.SetTop(tb, collision.Y);
                    tb.LayoutTransform = new RotateTransform(45);
                    tb.Background      = Brushes.White;

                    GridsCanvas.Children.Add(tb);
                }
            }

            #endregion

            #region Sds

            var maxLengthSa = SaGridLines.OrderBy(i => i.GetLength()).LastOrDefault();

            {
                foreach (var sdln in SdGridLines)
                {
                    var seg1 =
                        new LineSegment2D(
                            new Epsi1on.MathAndGeometric.Geometry.Point2D(maxLengthSa.X1, maxLengthSa.Y1),
                            new Epsi1on.MathAndGeometric.Geometry.Point2D(maxLengthSa.X2, maxLengthSa.Y2));


                    var seg2 = new LineSegment2D(
                        new Epsi1on.MathAndGeometric.Geometry.Point2D(sdln.X1, sdln.Y1),
                        new Epsi1on.MathAndGeometric.Geometry.Point2D(sdln.X2, sdln.Y2));

                    var collisionStat = LineSegment2D.GetIntersection(seg1, seg2);

                    if (collisionStat.LocusType != LocusType.OnePointIntersection)
                    {
                        continue;
                    }

                    var collision = collisionStat.IntersectionPoint.Value;

                    var tb = new TextBlock();
                    tb.Text = ((GridlineInfo)sdln.Tag).Sd.ToString();

                    //tb.TextAlignment = TextAlignment.Right;
                    tb.HorizontalAlignment = HorizontalAlignment.Left;
                    tb.VerticalAlignment   = VerticalAlignment.Center;

                    //tb.Text = f.ToString();

                    tb.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                    tb.Arrange(new Rect(0, 0, 1000, 1000));

                    Canvas.SetLeft(tb, collision.X);
                    //var hhh = ;
                    Canvas.SetTop(tb, collision.Y - tb.ActualHeight * 0.71);
                    //tb.RenderTransformOrigin = new Point(0, 0);
                    tb.RenderTransform = new RotateTransform(-45);
                    tb.Background      = Brushes.White;

                    GridsCanvas.Children.Add(tb);
                }
            }

            #endregion

            {
                //for acceleration
                var x = Math.Max(maxLengthSd.X1, maxLengthSd.X2);
                var y = Math.Min(maxLengthSd.Y1, maxLengthSd.Y2);

                var txt = new TextBlock();
                txt.Text                  = "Pseudo Acceleration m/s2";
                txt.LayoutTransform       = new RotateTransform(-45);
                txt.RenderTransformOrigin = new Point(0, 1);
                txt.HorizontalAlignment   = HorizontalAlignment.Left;
                txt.VerticalAlignment     = VerticalAlignment.Center;

                //tb.Text = f.ToString();

                txt.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                txt.Arrange(new Rect(0, 0, 1000, 1000));

                Canvas.SetLeft(txt, x - 0.7071 * txt.ActualWidth - 0.707 * txt.ActualHeight - 1.41 * txt.ActualHeight);
                Canvas.SetTop(txt, y);
                txt.Background = Brushes.White;
                GridsCanvas.Children.Add(txt);
            }



            {
                //for displacement
                var x = Math.Min(maxLengthSa.X1, maxLengthSa.X2);
                var y = Math.Min(maxLengthSa.Y1, maxLengthSa.Y2);

                var txt = new TextBlock();
                txt.Text            = "Displacement m";
                txt.LayoutTransform = new RotateTransform(45);
                Canvas.SetLeft(txt, x);
                Canvas.SetTop(txt, y + 14);
                txt.Background = Brushes.White;
                GridsCanvas.Children.Add(txt);
            }
        }
Example #23
0
        private static void GetCharacterBoundingBoxes_(MyScript.IInk.Text.Text text, TextSpan[] spans, List <Rectangle> rectangles, float dpiX, float dpiY)
        {
            var firstStyle = spans.First().Style;
            var textBlock  = new TextBlock();

            textBlock.FontFamily          = new FontFamily(firstStyle.FontFamily);
            textBlock.Padding             = new Thickness(0.0);
            textBlock.Margin              = new Thickness(0.0);
            textBlock.TextWrapping        = TextWrapping.NoWrap;
            textBlock.HorizontalAlignment = HorizontalAlignment.Left;
            textBlock.VerticalAlignment   = VerticalAlignment.Top;

            foreach (var textSpan in spans)
            {
                var fontFamily  = new FontFamily(textSpan.Style.FontFamily);
                var fontSize    = mm2px(textSpan.Style.FontSize, dpiY);
                var fontWeight  = FontWeight.FromOpenTypeWeight(textSpan.Style.FontWeight);
                var fontStretch = FontStretches.Normal;
                var fontStyle   = FontStyles.Normal;

                if (textSpan.Style.FontStyle.Equals("italic"))
                {
                    fontStyle = FontStyles.Italic;
                }
                else if (textSpan.Style.FontStyle.Equals("oblique"))
                {
                    fontStyle = FontStyles.Oblique;
                }

                if (textSpan.Style.FontWeight >= 700)
                {
                    fontWeight = FontWeights.Bold;
                }
                else if (textSpan.Style.FontWeight >= 400)
                {
                    fontWeight = FontWeights.Normal;
                }
                else
                {
                    fontWeight = FontWeights.Light;
                }

                // Process glyph one by one to generate one box per glyph
                for (int j = textSpan.BeginPosition; j < textSpan.EndPosition; ++j)
                {
                    var textRun = new Run(text.GetGlyphLabelAt(j));

                    textRun.FontFamily  = fontFamily;
                    textRun.FontSize    = fontSize;
                    textRun.FontWeight  = fontWeight;
                    textRun.FontStyle   = fontStyle;
                    textRun.FontStretch = fontStretch;

                    textBlock.Inlines.Add(textRun);
                }
            }

            textBlock.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
            textBlock.Arrange(new Rect(textBlock.DesiredSize));

            var baseline = (float)textBlock.BaselineOffset;
            var d        = VisualTreeHelper.GetDrawing(textBlock);

            WalkDrawingForText(d, rectangles, baseline, dpiX, dpiY);
        }
Example #24
0
 protected override Size ArrangeOverride(Size finalSize)
 {
     _titleFrame.Arrange(new Rect(0.0, 0.0, finalSize.Width, finalSize.Height));
     _titleContent.Arrange(new Rect(0.0, 0.0, finalSize.Width, finalSize.Height));
     return(base.ArrangeOverride(finalSize));
 }
Example #25
0
        /// <summary>
        /// Construct page with header and footer.
        /// </summary>
        /// <param name="pageNumber">The current page to transform.</param>
        /// <returns>The document page.</returns>
        private DocumentPage ConstructPageWithHeaderAndFooter(int pageNumber)
        {
            DocumentPage page0 = flowDocPaginator.GetPage(pageNumber);

            // Coming from WPFNotepad, the source document should always be a FlowDocument
            FlowDocument originalDocument = (FlowDocument)flowDocPaginator.Source;
            TextBlock    headerBlock      = null;
            TextBlock    footerBlock      = null;
            DocumentPage newPage          = null;

            if (originalPageSize == Size.Empty)
            {
                originalPageSize = ((IDocumentPaginatorSource)originalDocument).DocumentPaginator.PageSize;
            }

            Size newPageSize = originalPageSize;

            // Decrease the top and/or bottom margins to account for headers/footers
            if ((headerText != null) && (headerText.Length > 0))
            {
                string expandedHeaderText = GetExpandedText(headerText, originalDocument, pageNumber + 1);
                headerBlock                     = new TextBlock();
                headerBlock.Text                = expandedHeaderText;
                headerBlock.FontFamily          = SystemFonts.MenuFontFamily;
                headerBlock.FontSize            = 10;
                headerBlock.HorizontalAlignment = HorizontalAlignment.Center;

                headerBlock.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                headerBlock.Arrange(new Rect(headerBlock.DesiredSize));
                headerBlock.UpdateLayout();
                if (headerBlock.DesiredSize.Width > 0 && headerBlock.DesiredSize.Height > 0)
                {
                    newPageSize.Height -= headerBlock.DesiredSize.Height;
                }
            }

            if ((footerText != null) && (footerText.Length > 0))
            {
                string expandedFooterText = GetExpandedText(footerText, originalDocument, pageNumber + 1);
                footerBlock                     = new TextBlock();
                footerBlock.Text                = expandedFooterText;
                footerBlock.FontFamily          = SystemFonts.MenuFontFamily;
                footerBlock.FontSize            = 10;
                footerBlock.HorizontalAlignment = HorizontalAlignment.Center;

                footerBlock.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                footerBlock.Arrange(new Rect(footerBlock.DesiredSize));
                footerBlock.UpdateLayout();
                if (footerBlock.DesiredSize.Width > 0 && footerBlock.DesiredSize.Height > 0)
                {
                    newPageSize.Height -= footerBlock.DesiredSize.Height;
                }
            }

            // Get the original page with its reduced size
            flowDocPaginator.PageSize = newPageSize;
            DocumentPage page = flowDocPaginator.GetPage(pageNumber);

            if (page != DocumentPage.Missing)
            {
                // Create a Grid that will hold the header, the original page, and the footer
                Grid          grid   = new Grid();
                RowDefinition rowDef = new RowDefinition();
                rowDef.Height = new GridLength(0, GridUnitType.Auto);
                grid.RowDefinitions.Add(rowDef);

                rowDef        = new RowDefinition();
                rowDef.Height = new GridLength(0, GridUnitType.Star);
                grid.RowDefinitions.Add(rowDef);

                rowDef        = new RowDefinition();
                rowDef.Height = new GridLength(0, GridUnitType.Auto);
                grid.RowDefinitions.Add(rowDef);

                ColumnDefinition columnDef = new ColumnDefinition();
                grid.ColumnDefinitions.Add(columnDef);

                // The header and footer TextBlocks can be added to the grid
                // directly.  The Visual from the original DocumentPage needs
                // to be hosted in a container that derives from UIElement.
                if (headerBlock != null)
                {
                    headerBlock.Margin = new Thickness(0, originalDocument.PagePadding.Top, 0, 0);
                    Grid.SetRow(headerBlock, 0);
                    grid.Children.Add(headerBlock);
                }

                VisualContainer container = new VisualContainer();
                container.PageVisual = page.Visual;
                container.PageSize   = newPageSize;

                Grid.SetRow(container, 1);
                grid.Children.Add(container);

                if (footerBlock != null)
                {
                    footerBlock.Margin = new Thickness(0, 0, 0, originalDocument.PagePadding.Bottom);
                    Grid.SetRow(footerBlock, 2);
                    grid.Children.Add(footerBlock);
                }

                // Recalculate the children inside the Grid
                grid.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                grid.Arrange(new Rect(grid.DesiredSize));
                grid.UpdateLayout();


                // Return the new DocumentPage constructed from the Grid's Visual
                newPage = new DocumentPage(grid);
            }

            // Return the page.
            return(newPage);
        }
Example #26
0
 protected override Size ArrangeOverride(Size finalSize)
 {
     tb.Arrange(new Rect(new Point(), finalSize));
     return(finalSize);
 }
Example #27
0
 protected override Size ArrangeOverride(Size finalSize)
 {
     _mTextBlock.Arrange(new Rect(finalSize));
     return(finalSize);
 }
Example #28
0
 protected override WSize ArrangeOverride(WSize finalSize)
 {
     _textBlock.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height));
     return(finalSize);
 }
Example #29
0
 protected override Windows.Foundation.Size ArrangeOverride(Windows.Foundation.Size finalSize)
 {
     _textBlock.Arrange(new Windows.Foundation.Rect(0, 0, finalSize.Width, finalSize.Height));
     return(finalSize);
 }
Example #30
0
        public void Update()
        {
            Children.Clear();
            xc  = Width / 2.0;
            yc  = Height / 2.0;
            rad = scale * System.Math.Min(Width / 2.5, Height / 2.5);

            if (eLegend == Legends.LEGEND || eLegend == Legends.LEGEND_PERCENT)
            {
                rad *= 0.7;
                xc  -= 0.8 * (xc - rad);
            }

            double    angle = 0;
            double    x1 = rad, y1 = 0, x2, y2;
            Size      size = new Size(0, 0);
            Color     col  = Colors.White;
            Brush     brush;
            Ellipse   ellipse;
            Rectangle rectangle;
            TextBlock textblock;

            for (int i = 0; i < Count; i++)
            {
                double frac = startColor + (endColor - startColor) * i / (double)(Count);
                switch (eHSL)
                {
                case HSL.HUE:
                    col = (Color)ColorConverter.ConvertFromString(LDColours.HSLtoRGB(360 * frac, saturation, lightness));
                    break;

                case HSL.SATURATION:
                    col = (Color)ColorConverter.ConvertFromString(LDColours.HSLtoRGB(hue, frac, lightness));
                    break;

                case HSL.LIGHTNESS:
                    col = (Color)ColorConverter.ConvertFromString(LDColours.HSLtoRGB(hue, saturation, frac));
                    break;
                }
                brush = new SolidColorBrush(col);
                if (centralColour != "")
                {
                    GradientBrush gradientBrush = new GradientBrush("", new Primitive("1=" + centralColour + ";2=" + col.ToString() + ";"), "");
                    brush = gradientBrush.getBrush();
                }

                angle += 2 * System.Math.PI * Values[i] / Total;
                x2     = rad + rad * System.Math.Sin(angle);
                y2     = rad - rad * System.Math.Cos(angle);
                bool bLargeArc = (Values[i] / Total) > 0.5;

                switch (eStyle)
                {
                case Styles.PIE:
                {
                    PathSegmentCollection pathSegments = new PathSegmentCollection();
                    pathSegments.Add(new LineSegment(new Point(x1, y1), false));
                    pathSegments.Add(new ArcSegment(new Point(x2, y2), new Size(rad, rad), angle, bLargeArc, SweepDirection.Clockwise, false));
                    PathFigureCollection pathFigures = new PathFigureCollection();
                    pathFigures.Add(new PathFigure(new Point(rad, rad), pathSegments, true));
                    PathFigureCollection figCollection = new PathFigureCollection(pathFigures);

                    ellipse = new Ellipse {
                        Width = 2 * rad, Height = 2 * rad, Fill = brush
                    };
                    ellipse.Clip       = new PathGeometry(figCollection);
                    ellipse.Tag        = new Segment(xc, yc, rad, rad, Name, Labels[i]);
                    ellipse.MouseDown += new MouseButtonEventHandler(_ValueClickedEvent);
                    Children.Add(ellipse);
                    Chart.SetLeft(ellipse, xc - rad);
                    Chart.SetTop(ellipse, yc - rad);
                }
                break;

                case Styles.DOUGHNUT:
                {
                    PathFigureCollection figCollection;
                    if (bDualDoughnut)
                    {
                        double x1inner = x1 + (1 - LDChart.DoughnutFraction) * (rad - x1);
                        double y1inner = y1 + (1 - LDChart.DoughnutFraction) * (rad - y1);
                        double x2inner = x2 + (1 - LDChart.DoughnutFraction) * (rad - x2);
                        double y2inner = y2 + (1 - LDChart.DoughnutFraction) * (rad - y2);
                        PathSegmentCollection pathSegments = new PathSegmentCollection();
                        pathSegments.Add(new LineSegment(new Point(x1, y1), false));
                        pathSegments.Add(new ArcSegment(new Point(x2, y2), new Size(rad, rad), angle, bLargeArc, SweepDirection.Clockwise, false));
                        pathSegments.Add(new LineSegment(new Point(x2inner, y2inner), false));
                        pathSegments.Add(new ArcSegment(new Point(x1inner, y1inner), new Size(rad * LDChart.DoughnutFraction, rad * LDChart.DoughnutFraction), angle, bLargeArc, SweepDirection.Counterclockwise, false));
                        PathFigureCollection pathFigures = new PathFigureCollection();
                        pathFigures.Add(new PathFigure(new Point(x1inner, y1inner), pathSegments, true));
                        figCollection = new PathFigureCollection(pathFigures);
                    }
                    else
                    {
                        PathSegmentCollection pathSegments = new PathSegmentCollection();
                        pathSegments.Add(new LineSegment(new Point(x1, y1), false));
                        pathSegments.Add(new ArcSegment(new Point(x2, y2), new Size(rad, rad), angle, bLargeArc, SweepDirection.Clockwise, false));
                        PathFigureCollection pathFigures = new PathFigureCollection();
                        pathFigures.Add(new PathFigure(new Point(rad, rad), pathSegments, true));
                        figCollection = new PathFigureCollection(pathFigures);
                    }

                    ellipse = new Ellipse {
                        Width = 2 * rad, Height = 2 * rad, Fill = brush
                    };
                    ellipse.Clip       = new PathGeometry(figCollection);
                    ellipse.Tag        = new Segment(xc, yc, rad, rad, Name, Labels[i]);
                    ellipse.MouseDown += new MouseButtonEventHandler(_ValueClickedEvent);
                    Children.Add(ellipse);
                    Chart.SetLeft(ellipse, xc - rad);
                    Chart.SetTop(ellipse, yc - rad);
                }
                break;

                case Styles.BUBBLE:
                {
                    double sin = System.Math.Sin(System.Math.PI * Values[i] / Total);
                    double r   = rad * sin / (1.0 + sin);
                    angle -= System.Math.PI * Values[i] / Total;
                    double x = xc + (rad - r) * System.Math.Sin(angle);
                    double y = yc - (rad - r) * System.Math.Cos(angle);
                    angle  += System.Math.PI * Values[i] / Total;
                    ellipse = new Ellipse {
                        Width = 2 * r, Height = 2 * r, Fill = brush
                    };
                    ellipse.Tag        = new Segment(x, y, r, r, Name, Labels[i]);
                    ellipse.MouseDown += new MouseButtonEventHandler(_ValueClickedEvent);
                    Children.Add(ellipse);
                    Chart.SetLeft(ellipse, x - r);
                    Chart.SetTop(ellipse, y - r);
                }
                break;

                case Styles.BAR:
                {
                    double w = rad * (Values[i] - Min) / (Max - Min);
                    double h = rad / (double)Count;
                    double x = xc - rad + w;
                    double y = yc - rad + (2 * i + 1) * h;
                    rectangle = new Rectangle {
                        Width = 2 * w, Height = 2 * h, Fill = brush
                    };
                    rectangle.Tag        = new Segment(x, y, w, h, Name, Labels[i]);
                    rectangle.MouseDown += new MouseButtonEventHandler(_ValueClickedEvent);
                    Children.Add(rectangle);
                    Chart.SetLeft(rectangle, x - w);
                    Chart.SetTop(rectangle, y - h);
                }
                break;

                case Styles.COLUMN:
                {
                    double w = rad / (double)Count;
                    double h = rad * (Values[i] - Min) / (Max - Min);
                    double x = xc - rad + (2 * i + 1) * w;
                    double y = yc + rad - h;
                    rectangle = new Rectangle {
                        Width = 2 * w, Height = 2 * h, Fill = brush
                    };
                    rectangle.Tag        = new Segment(x, y, w, h, Name, Labels[i]);
                    rectangle.MouseDown += new MouseButtonEventHandler(_ValueClickedEvent);
                    Children.Add(rectangle);
                    Chart.SetLeft(rectangle, x - w);
                    Chart.SetTop(rectangle, y - h);
                }
                break;
                }

                brush = new SolidColorBrush(col);
                x1    = x2;
                y1    = y2;

                if (eLegend == Legends.OVERLAY || eLegend == Legends.PERCENT || eLegend == Legends.LEGEND_PERCENT)
                {
                    textblock = new TextBlock
                    {
                        Text       = eLegend == Legends.OVERLAY ? Labels[i] : string.Format("{0:F1}%", 100 * Values[i] / Total),
                        Foreground = foreground,
                        FontFamily = fontFamily,
                        FontSize   = fontSize,
                        FontWeight = fontWeight,
                        FontStyle  = fontStyle
                    };
                    if (bLegendBackground)
                    {
                        textblock.Background = brush;
                    }
                    textblock.FontSize  *= legendScale;
                    textblock.MouseDown += new MouseButtonEventHandler(_ValueClickedEvent);
                    Children.Add(textblock);
                    textblock.Measure(size);
                    textblock.Arrange(new Rect(size));
                    angle -= System.Math.PI * Values[i] / Total;
                    double w = textblock.ActualWidth / 2.0;
                    double h = textblock.ActualHeight / 2.0;
                    if (eStyle == Styles.PIE)
                    {
                        x2 = xc + 0.67 * rad * System.Math.Sin(angle);
                        y2 = yc - 0.67 * rad * System.Math.Cos(angle);
                    }
                    else if (eStyle == Styles.DOUGHNUT)
                    {
                        x2 = xc + (1 + LDChart.DoughnutFraction) / 2.0 * rad * System.Math.Sin(angle);
                        y2 = yc - (1 + LDChart.DoughnutFraction) / 2.0 * rad * System.Math.Cos(angle);
                    }
                    else if (eStyle == Styles.BUBBLE)
                    {
                        double sin = System.Math.Sin(System.Math.PI * Values[i] / Total);
                        double r   = rad * sin / (1.0 + sin);
                        x2 = xc + (rad - r) * System.Math.Sin(angle);
                        y2 = yc - (rad - r) * System.Math.Cos(angle);
                    }
                    else if (eStyle == Styles.BAR)
                    {
                        //x2 = xc - rad + rad * (Values[i] - Min) / (Max - Min);
                        x2 = xc - rad + w + 5;
                        y2 = yc - rad + (2 * i + 1) * rad / (double)Count;
                    }
                    else if (eStyle == Styles.COLUMN)
                    {
                        x2 = xc - rad + (2 * i + 1) * rad / (double)Count;
                        //y2 = yc + rad - rad * (Values[i] - Min) / (Max - Min);
                        y2 = yc + rad - w - 5;
                        RotateTransform rotateTransform = new RotateTransform();
                        rotateTransform.CenterX   = w;
                        rotateTransform.CenterY   = h;
                        rotateTransform.Angle     = -90;
                        textblock.RenderTransform = rotateTransform;
                    }
                    angle        += System.Math.PI * Values[i] / Total;
                    textblock.Tag = new Segment(x2, y2, w, h, Name, Labels[i]);
                    Chart.SetLeft(textblock, x2 - w);
                    Chart.SetTop(textblock, y2 - h);
                    Canvas.SetZIndex(textblock, 1);
                }

                if (eLegend == Legends.LEGEND || eLegend == Legends.LEGEND_PERCENT)
                {
                    rectangle = new Rectangle {
                        Width = 10 * legendScale, Height = 10 * legendScale, Fill = brush
                    };
                    Children.Add(rectangle);
                    x2 = 2 * xc;
                    y2 = (Width - 15 * Count * legendScale) / 2 + 15 * i * legendScale;
                    Chart.SetLeft(rectangle, x2);
                    Chart.SetTop(rectangle, y2);
                    Canvas.SetZIndex(rectangle, 1);

                    textblock = new TextBlock
                    {
                        Text       = Labels[i],
                        Foreground = foreground,
                        FontFamily = fontFamily,
                        FontSize   = fontSize,
                        FontWeight = fontWeight,
                        FontStyle  = fontStyle
                    };
                    if (bLegendBackground)
                    {
                        textblock.Background = brush;
                    }
                    textblock.FontSize *= legendScale;
                    Children.Add(textblock);
                    textblock.Measure(size);
                    textblock.Arrange(new Rect(size));
                    Chart.SetLeft(textblock, x2 + 15 * legendScale);
                    Chart.SetTop(textblock, y2 + 5 * legendScale - textblock.ActualHeight / 2.0);
                    Canvas.SetZIndex(textblock, 1);
                }
            }

            if (eStyle == Styles.DOUGHNUT && !bDualDoughnut)
            {
                ellipse = new Ellipse {
                    Width = 2 * LDChart.DoughnutFraction * rad, Height = 2 * LDChart.DoughnutFraction * rad, Fill = Background
                };
                Children.Add(ellipse);
                Chart.SetLeft(ellipse, xc - LDChart.DoughnutFraction * rad);
                Chart.SetTop(ellipse, yc - LDChart.DoughnutFraction * rad);
            }
        }