private void UpdateCachedPages() { Canvas canvas = new Canvas(); float posX = PADDING; float posY = m_Text.Font.Leading / 2.0f; for (int i = 0; i < m_CachedPages.Count; i++) { CachedPage prevPage = m_CachedPages[i]; int imageWidth = prevPage.Bitmap.PixelWidth; int imageHeight = prevPage.Bitmap.PixelHeight; int frameWidth = imageWidth - (PADDING * 2); prevPage.Bitmap = null; WriteableBitmap bmp = new WriteableBitmap(imageWidth, imageHeight); m_Text.ShowString(RenderGlyph, frameWidth, posX, posY, prevPage.StartIndex, m_LinesInPage, bmp); prevPage.Bitmap = bmp; } m_Drawn = true; }
private int GenerateCachedPages(double width) { ClearCachedPages(); float lineHeight = m_Text.Font.Leading; float posX = PADDING; float posY = lineHeight / 2.0f; float scale = Windows.Graphics.Display.DisplayProperties.LogicalDpi / 96.0f; int imageWidth = (int)(width - Padding.Right - Padding.Left); int imageHeight = GetMaxAllowedPixelsInAPage() / imageWidth; float frameWidth = imageWidth - (PADDING * 2); m_LinesInPage = (int)Math.Floor((imageHeight - (lineHeight)) / (lineHeight)); float pageHeight = lineHeight * m_LinesInPage; int countLines = 0; int totalLines = 0; int index = 0; int prevIndex = 0; for (int i = 0; index > -1; i++) { prevIndex = index; countLines = m_LinesInPage; index = m_Text.GetNextLineCharIndex(frameWidth, index, countLines); if (index < 0) { countLines = -index - 1; } imageHeight = (int)(lineHeight * (countLines + 1)); WriteableBitmap bmp = new WriteableBitmap((int)(imageWidth * scale), (int)(imageHeight * scale)); m_Text.ShowString(RenderGlyph, frameWidth, posX, posY, prevIndex, countLines, bmp); CachedPage page = new CachedPage(prevIndex, bmp, scale); m_CachedPages.Add(page); Image bmpView = page.BitmapView; bmpView.Margin = new Thickness(Padding.Left, Padding.Top + ((i * pageHeight) - posY), Padding.Right, Padding.Bottom); m_Grid.Children.Add(bmpView); totalLines += countLines; } m_Drawn = true; m_MeasuredHeight = (int)Math.Round((totalLines * lineHeight) + Padding.Top + Padding.Bottom); return(totalLines); }
private int CreateCachedPages(int width) { ClearCachedPages(); float lineHeight = this.Font.GetLeading(); m_PageHeight = CalculatePageHeight(width); m_LinesInPage = (int)Math.Floor((m_PageHeight - lineHeight) / lineHeight); int totalLines = 0; int index = 0; while (index > -1) { int prevIndex = index; index = m_Text.GetCharIndexAfterLines(index, m_LinesInPage); int measuredLines; int pageHeight; if (index < 0) { measuredLines = -index; pageHeight = (int)(lineHeight * (measuredLines + 1)); } else { measuredLines = m_LinesInPage; pageHeight = m_PageHeight; } WriteableBitmap bmp = new WriteableBitmap(width, pageHeight); m_Text.RenderText(RenderGlyph, prevIndex, m_LinesInPage, 0, (int)lineHeight, bmp); CachedPage page = new CachedPage(prevIndex, bmp); m_CachedPages.Add(page); totalLines += measuredLines; } return(totalLines); }
private int GenerateCachedPages(double width) { ClearCachedPages(); float lineHeight = m_Text.Font.Leading; float posX = PADDING; float posY = lineHeight / 2.0f; float scale = Windows.Graphics.Display.DisplayProperties.LogicalDpi / 96.0f; int imageWidth = (int)(width - Padding.Right - Padding.Left); int imageHeight = GetMaxAllowedPixelsInAPage() / imageWidth; float frameWidth = imageWidth - (PADDING * 2); m_LinesInPage = (int)Math.Floor((imageHeight - (lineHeight)) / (lineHeight)); float pageHeight = lineHeight * m_LinesInPage; int countLines = 0; int totalLines = 0; int index = 0; int prevIndex = 0; for (int i = 0; index > -1; i++) { prevIndex = index; countLines = m_LinesInPage; index = m_Text.GetNextLineCharIndex(frameWidth, index, countLines); if (index < 0) countLines = -index - 1; imageHeight = (int)(lineHeight * (countLines + 1)); WriteableBitmap bmp = new WriteableBitmap((int)(imageWidth * scale), (int)(imageHeight * scale)); m_Text.ShowString(RenderGlyph, frameWidth, posX, posY, prevIndex, countLines, bmp); CachedPage page = new CachedPage(prevIndex, bmp, scale); m_CachedPages.Add(page); Image bmpView = page.BitmapView; bmpView.Margin = new Thickness(Padding.Left, Padding.Top + ((i * pageHeight) - posY), Padding.Right, Padding.Bottom); m_Grid.Children.Add(bmpView); totalLines += countLines; } m_Drawn = true; m_MeasuredHeight = (int)Math.Round((totalLines * lineHeight) + Padding.Top + Padding.Bottom); return totalLines; }
private int CreateCachedPages(int width) { ClearCachedPages(); float lineHeight = this.Font.GetLeading(); m_PageHeight = CalculatePageHeight(width); m_LinesInPage = (int)Math.Floor((m_PageHeight - lineHeight) / lineHeight); int totalLines = 0; int index = 0; while (index > -1) { int prevIndex = index; index = m_Text.GetCharIndexAfterLines(index, m_LinesInPage); int measuredLines; int pageHeight; if (index < 0) { measuredLines = -index; pageHeight = (int)(lineHeight * (measuredLines + 1)); } else { measuredLines = m_LinesInPage; pageHeight = m_PageHeight; } WriteableBitmap bmp = new WriteableBitmap(width, pageHeight); m_Text.RenderText(RenderGlyph, prevIndex, m_LinesInPage, 0, (int)lineHeight, bmp); CachedPage page = new CachedPage(prevIndex, bmp); m_CachedPages.Add(page); totalLines += measuredLines; } return totalLines; }