/// <summary> /// Renders the titles that will result in more than one line. /// Workaround function. Breaks long strings into parts of length CharsPerLine. /// So the MatrixBrailleRenderer will not break strings unpredictable, resulting in /// spaces after or between broken parts. --> Causes CursorPosition to fail /// </summary> /// <param name="view">The view.</param> /// <returns></returns> private bool[,] renderMultiLineTitle(IViewBoxModel view, EditField_DialogEntry entry, int LineContentWidth, int LineCount, int CharsPerLine) { if (brailleRenderer == null) { brailleRenderer = new Renderer.MatrixBrailleRenderer(Renderer.RenderingProperties.IGNORE_LAST_LINESPACE | Renderer.RenderingProperties.RETURN_REAL_WIDTH); } bool[,] completeMatrix = brailleRenderer.RenderMatrix(view.ContentBox.Width, entry.Title); //bool[,] completeMatrix = emptyMatrix; //if (view != null && entry != null && entry.Title != null) //{ // List<string> titleParts = new List<string>(); // /*Cut string into CharsPerLine-long bits*/ // for (int i = 0; i < LineCount; i++) // { // if (entry.Title.Length > i * CharsPerLine + CharsPerLine) // titleParts.Add(entry.Title.Substring(i * CharsPerLine, CharsPerLine)); // else // { // if (entry.Title.Length >= i * CharsPerLine) // titleParts.Add(entry.Title.Substring(i * CharsPerLine)); // else break; // } // } // List<bool[,]> boolTitleParts = new List<bool[,]>(); // int dimensiony = CHAR_HEIGHT; // int dimensionx = LineContentWidth; // int index = 0; // /*Backup because entry's own renderer will be used. Renderer uses title for rendering.*/ // string titleBackup = Entry.Title; // /*Render all string parts seperately*/ // foreach (var item in titleParts) // { // if (index > 0) dimensiony = INTER_LINE_HEIGHT + CHAR_HEIGHT + dimensiony; // Entry.Title = item; // boolTitleParts.Add(renderDialogEntry(view)); // index++; // } // Entry.Title = titleBackup; // completeMatrix = new bool[dimensiony, dimensionx]; // index = 0; // /*Join all seperate rendered string parts into one Matrix*/ // foreach (var item in boolTitleParts) // { // for (int i = 0; i < item.GetLength(0); i++) // { // if(i < completeMatrix.GetLength(0)) // for (int j = 0; j < item.GetLength(1); j++) // { // try // { // if (j < completeMatrix.GetLength(1)) // { // if (index == 0) // completeMatrix[i, j] = item[i, j]; // else // { // completeMatrix[i + (index * (INTER_CHAR_WIDTH + CHAR_HEIGHT)), j] = item[i, j]; // } // } // } // catch (Exception e) // { // System.Diagnostics.Debug.WriteLine(e.ToString()); // } // } // } // index++; // } //} return(completeMatrix); }
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; } }