Exemple #1
0
 public TextElemet(OoShapeObserver shape)
 {
     Shape = shape;
     if (shape != null)
     {
         Text              = shape.Text;
         ScreenPosition    = shape.GetRelativeScreenBoundsByDom();
         ObjectBoundingBox = BrailleTextView.MakeZoomBoundingBox(ScreenPosition, WindowManager.GetPrintZoomLevel());
         Matrix            = BrailleTextView.BrailleRenderer.RenderMatrix(ObjectBoundingBox.Width, Text);
         Position          = new Point(ObjectBoundingBox.X, ObjectBoundingBox.Y);
         Center            = new Point(ObjectBoundingBox.X + (ObjectBoundingBox.Width / 2), ObjectBoundingBox.Y + (ObjectBoundingBox.Height / 2));
     }
     else
     {
         Center            = Position = new Point();
         Matrix            = new bool[0, 0];
         ObjectBoundingBox = ScreenPosition = new Rectangle();
         Text = String.Empty;
     }
 }
Exemple #2
0
        private static void renderTextFieldInMatrix(ref bool[,] m, TextElemet text, int xOffset, int yOffset, double zoom)
        {
            if (m != null && !String.IsNullOrWhiteSpace(text.Text))
            {
                if (text.Matrix == null) // if no text was renderd --> render it
                {
                    text.Matrix = BrailleRenderer.RenderMatrix(dummyView, text.Text);
                    if (text.Matrix == null)
                    {
                        return;
                    }
                }

                bool[,] matrix = m;
                Rectangle startpoint = BrailleTextView.MakeZoomBoundingBox(text.ScreenPosition, zoom);
                // calculate the center point and from that the staring point
                startpoint.X += startpoint.Width / 2;
                startpoint.X -= text.Matrix.GetLength(1) / 2;

                startpoint.Y += startpoint.Height / 2;
                startpoint.Y -= text.Matrix.GetLength(0) / 2;

                // paint a spacing frame around the text

                Parallel.For(0, text.Matrix.GetLength(1) + 1, (i) =>
                {
                    int x = startpoint.X + xOffset - 1 + i;
                    if (x > 0 && matrix.GetLength(1) > x)
                    {
                        try
                        {
                            int y1 = startpoint.Y + yOffset - 1;
                            if (y1 > 0 && y1 < matrix.GetLength(0))
                            {
                                matrix[y1, x] = false;
                            }

                            int y2 = startpoint.Y + yOffset + text.Matrix.GetLength(0) - 1; // remove the -1 if underlining should be possible
                            if (y2 > 0 && y2 < matrix.GetLength(0))
                            {
                                matrix[y2, x] = false;
                            }
                        }
                        catch { }
                    }
                }
                             );

                Parallel.For(0, text.Matrix.GetLength(0), (j) =>
                {
                    int y = startpoint.Y + yOffset + j;

                    if (y > 0 && y < matrix.GetLength(0))
                    {
                        try
                        {
                            int x1 = startpoint.X + xOffset - 1;
                            if (x1 > 0 && x1 < matrix.GetLength(1))
                            {
                                matrix[y, x1] = false;
                            }
                        }
                        catch { }
                    }
                }
                             );

                // add the rendered text in the result

                Parallel.For(0, text.Matrix.GetLength(1), (i) =>
                {
                    int x = i + startpoint.X + xOffset;
                    if (x > 0 && matrix.GetLength(1) > x)
                    {
                        Parallel.For(0, text.Matrix.GetLength(0), (j) =>
                        {
                            int y = startpoint.Y + j + yOffset;
                            if (y > 0 && matrix.GetLength(0) > y)
                            {
                                try
                                {
                                    matrix[y, x] = text.Matrix[j, i];
                                }
                                catch { }
                            }
                        }
                                     );
                    }
                }
                             );
                m = matrix;
            }
        }