private void DoPaint(Graphics gfx) { try { gfx.TextRenderingHint = TextRenderingHint.AntiAlias; fAcceptFontChange = false; SolidBrush brush = new SolidBrush(this.ForeColor); Font font = null; try { Rectangle clientRect = ClientRectangle; gfx.FillRectangle(new SolidBrush(BackColor), clientRect); int xOffset = fBorderWidth - -AutoScrollPosition.X; int yOffset = fBorderWidth - -AutoScrollPosition.Y; int lineHeight = 0; int line = -1; int chunksCount = fChunks.Count; for (int k = 0; k < chunksCount; k++) { BBTextChunk chunk = fChunks[k]; if (line != chunk.Line) { line = chunk.Line; xOffset = fBorderWidth - -AutoScrollPosition.X; yOffset += lineHeight; // this condition is dirty hack if (line >= 0 && line < fHeights.Count) { lineHeight = fHeights[line]; } } string ct = chunk.Text; if (!string.IsNullOrEmpty(ct)) { brush.Color = ((ColorHandler)chunk.Color).Handle; font = ProcessFont(font, chunk.Size, (sdFontStyle)chunk.Style); gfx.DrawString(ct, font, brush, xOffset, yOffset, fStrFormat); xOffset += chunk.Width; } } } finally { fAcceptFontChange = true; if (brush != null) { brush.Dispose(); } if (font != null) { font.Dispose(); } } } catch (Exception ex) { Logger.LogWrite("HyperView.DoPaint(): " + ex.Message); } }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); Point mpt = GetImageRelativeLocation(e.Location); mpt.Offset(-fBorderWidth, -fBorderWidth); fCurrentLink = null; int num = fChunks.Count; for (int i = 0; i < num; i++) { BBTextChunk chunk = fChunks[i]; if (string.IsNullOrEmpty(chunk.URL)) { continue; } if (chunk.HasCoord(mpt.X, mpt.Y)) { fCurrentLink = chunk; break; } } Cursor = (fCurrentLink == null) ? Cursors.Default : Cursors.Hand; }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); int xOffset = (fBorderWidth - -AutoScrollPosition.X); int yOffset = (fBorderWidth - -AutoScrollPosition.Y); fCurrentLink = null; int num = fChunks.Count; for (int i = 0; i < num; i++) { BBTextChunk chunk = fChunks[i]; if (string.IsNullOrEmpty(chunk.URL)) { continue; } if (chunk.HasCoord(e.X, e.Y, xOffset, yOffset)) { fCurrentLink = chunk; break; } } Cursor = (fCurrentLink == null) ? Cursors.Default : Cursors.Hand; }
private void DoPaint(Graphics gfx) { try { fAcceptFontChange = false; try { gfx.FillRectangle(new SolidBrush(BackgroundColor), Viewport); Font defFont = this.Font; int xOffset = fBorderWidth + ImageViewport.Left; int yOffset = fBorderWidth + ImageViewport.Top; int lineHeight = 0; int line = -1; int chunksCount = fChunks.Count; for (int k = 0; k < chunksCount; k++) { BBTextChunk chunk = fChunks[k]; if (line != chunk.Line) { line = chunk.Line; xOffset = fBorderWidth + ImageViewport.Left; yOffset += lineHeight; // this condition is dirty hack if (line >= 0 && line < fHeights.Count) { lineHeight = fHeights[line]; } } string ct = chunk.Text; if (!string.IsNullOrEmpty(ct)) { // FIXME: null?! IColor clr = chunk.Color; var chunkColor = (clr == null) ? TextColor : ((ColorHandler)chunk.Color).Handle; using (var brush = new SolidBrush(chunkColor)) { using (var font = new Font(defFont.FamilyName, chunk.Size, (sdFontStyle)chunk.Style)) { gfx.DrawText(font, brush, xOffset, yOffset, ct); } } xOffset += chunk.Width; } } } finally { fAcceptFontChange = true; } } catch (Exception ex) { Logger.LogWrite("HyperView.DoPaint(): " + ex.Message); } }
private void ShiftChunks(int startIndex, int chunksCount) { for (int m = startIndex; m < chunksCount; m++) { BBTextChunk mChunk = fChunks[m]; mChunk.Line += 1; } }
public HyperView() : base() { CenteredImage = false; fAcceptFontChange = true; fChunks = new List <BBTextChunk>(); fCurrentLink = null; fHeights = new List <int>(); fLines = new StringList(); fLines.OnChange += LinesChanged; fLinkColor = Colors.Blue; fTextSize = ExtSize.Empty; }
private void SplitChunk(BBTextChunk chunk, int index, string head, string tail, ref int chunksCount) { chunk.Text = head; if (!string.IsNullOrEmpty(tail)) { var newChunk = chunk.Clone(); newChunk.Text = tail; fChunks.Insert(index + 1, newChunk); chunksCount += 1; ShiftChunks(index + 1, chunksCount); } }
public HyperView() : base() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true); UpdateStyles(); BorderStyle = BorderStyle.Fixed3D; DoubleBuffered = true; TabStop = true; fAcceptFontChange = true; fChunks = new List <BBTextChunk>(); fCurrentLink = null; fHeights = new List <int>(); fLines = new StringList(); fLines.OnChange += LinesChanged; fLinkColor = Color.Blue; fTextSize = ExtSize.Empty; }
public HyperView() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true); UpdateStyles(); BorderStyle = BorderStyle.Fixed3D; DoubleBuffered = true; TabStop = true; fAcceptFontChange = true; fChunks = new List <BBTextChunk>(); fCurrentLink = null; fHeights = new List <int>(); fLines = new StringList(); fLines.OnChange += LinesChanged; fLinkColor = Color.Blue; fTextSize = ExtSize.Empty; fStrFormat = new StringFormat(StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap | StringFormatFlags.NoClip); fWordWrap = true; }
private void ArrangeText() { try { fAcceptFontChange = false; fHeights.Clear(); Graphics gfx = CreateGraphics(); //gfx.TextRenderingHint = TextRenderingHint.AntiAlias; try { int xPos = 0; int yPos = 0; int xMax = 0; int lineHeight = 0; string text = fLines.Text; Font defFont = this.Font; SizeF csz = this.ClientSize; SizeF zerosz = new SizeF(0f, 0f); var parser = new BBTextParser(AppHost.GfxProvider, defFont.SizeInPoints, new ColorHandler(fLinkColor), new ColorHandler(ForeColor)); parser.ParseText(fChunks, text); int line = -1; int chunksCount = fChunks.Count; int k = 0; while (k < chunksCount) { BBTextChunk chunk = fChunks[k]; bool recalcChunk = false; if (line != chunk.Line) { line = chunk.Line; if (line > 0) { yPos += lineHeight; fHeights.Add(lineHeight); } xPos = 0; lineHeight = 0; } int prevX = xPos; int prevY = yPos; string chunkStr = chunk.Text; if (!string.IsNullOrEmpty(chunkStr)) { using (var font = new Font(defFont.Name, chunk.Size, (sdFontStyle)chunk.Style, defFont.Unit)) { SizeF strSize = gfx.MeasureString(chunkStr, font, zerosz, fStrFormat); if (fWordWrap) { int wBound = xPos + 2 * fBorderWidth; if (wBound + strSize.Width > csz.Width) { int lastIndex = chunkStr.Length - 1; while (true) { int spPos = chunkStr.LastIndexOf(' ', lastIndex); if (spPos <= 0) { // the beginning of the chunk is reached and there are no more words to carry chunk.Text = chunkStr.Substring(0, lastIndex + 1); strSize = gfx.MeasureString(chunkStr, font, zerosz, fStrFormat); // the current chunk still does not fit into the area if (wBound + strSize.Width > csz.Width) { // this is not the only chunk on this line if (k > 0 && fChunks[k - 1].Line == chunk.Line) { // transfer the current chunk to the next line // and recount it again at the next iteration ShiftChunks(k, chunksCount); recalcChunk = true; } } break; } string newChunk = chunkStr.Substring(0, spPos); strSize = gfx.MeasureString(newChunk, font, zerosz, fStrFormat); if (wBound + strSize.Width < csz.Width) { var secondPart = chunk.Clone(); secondPart.Text = chunkStr.Substring(spPos + 1); secondPart.Line += 1; fChunks.Insert(k + 1, secondPart); chunksCount += 1; // shift next chunks ShiftChunks(k + 2, chunksCount); chunk.Text = newChunk; break; } else { lastIndex = spPos - 1; } } } } chunk.Width = (int)strSize.Width; xPos += chunk.Width; if (xMax < xPos) { xMax = xPos; } int h = (int)strSize.Height; if (lineHeight < h) { lineHeight = h; } } if (!string.IsNullOrEmpty(chunk.URL)) { chunk.LinkRect = ExtRect.CreateBounds(prevX, prevY, xPos - prevX, lineHeight); } } if (!recalcChunk) { k++; } } fTextSize = new ExtSize(xMax + 2 * fBorderWidth, yPos + 2 * fBorderWidth); } finally { gfx.Dispose(); fAcceptFontChange = true; AdjustViewport(fTextSize); } } catch (Exception ex) { Logger.LogWrite("HyperView.ArrangeText(): " + ex.Message); } }
private void DoPaint(Graphics gfx) { try { fAcceptFontChange = false; try { Rectangle clientRect = ClientRectangle; gfx.FillRectangle(new SolidBrush(BackColor), clientRect); Font defFont = this.Font; int xOffset = fBorderWidth - -AutoScrollPosition.X; int yOffset = fBorderWidth - -AutoScrollPosition.Y; int lineHeight = 0; int line = -1; int chunksCount = fChunks.Count; for (int k = 0; k < chunksCount; k++) { BBTextChunk chunk = fChunks[k]; if (line != chunk.Line) { line = chunk.Line; xOffset = fBorderWidth - -AutoScrollPosition.X; yOffset += lineHeight; // this condition is dirty hack if (line >= 0 && line < fHeights.Count) { lineHeight = fHeights[line]; } } int prevX = xOffset; int prevY = yOffset; string ct = chunk.Text; if (!string.IsNullOrEmpty(ct)) { var chunkColor = ((ColorHandler)chunk.Color).Handle; using (var brush = new SolidBrush(chunkColor)) { using (var font = new Font(defFont.Name, chunk.Size, (sdFontStyle)chunk.Style, defFont.Unit)) { gfx.DrawString(ct, font, brush, xOffset, yOffset); } } xOffset += chunk.Width; if (!string.IsNullOrEmpty(chunk.URL)) { chunk.LinkRect = ExtRect.CreateBounds(prevX, prevY, xOffset - prevX, lineHeight); } } } } finally { fAcceptFontChange = true; } } catch (Exception ex) { Logger.LogWrite("HyperView.DoPaint(): " + ex.Message); } }
private void ArrangeText() { try { fAcceptFontChange = false; fHeights.Clear(); Graphics gfx = CreateGraphics(); try { int xPos = 0; int yPos = 0; int xMax = 0; int lineHeight = 0; string text = fLines.Text; Font defFont = this.Font; var parser = new BBTextParser(AppHost.GfxProvider, defFont.SizeInPoints, new ColorHandler(fLinkColor), new ColorHandler(ForeColor)); parser.ParseText(fChunks, text); int line = -1; int chunksCount = fChunks.Count; for (int k = 0; k < chunksCount; k++) { BBTextChunk chunk = fChunks[k]; if (line != chunk.Line) { line = chunk.Line; if (line > 0) { yPos += lineHeight; fHeights.Add(lineHeight); } xPos = 0; lineHeight = 0; } if (!string.IsNullOrEmpty(chunk.Text)) { using (var font = new Font(defFont.Name, chunk.Size, (sdFontStyle)chunk.Style, defFont.Unit)) { SizeF strSize = gfx.MeasureString(chunk.Text, font); chunk.Width = (int)strSize.Width; xPos += chunk.Width; if (xMax < xPos) { xMax = xPos; } int h = (int)strSize.Height; if (lineHeight < h) { lineHeight = h; } } } } fTextSize = new ExtSize(xMax + 2 * fBorderWidth, yPos + 2 * fBorderWidth); } finally { gfx.Dispose(); fAcceptFontChange = true; AdjustViewport(fTextSize); } } catch (Exception ex) { Logger.LogWrite("HyperView.ArrangeText(): " + ex.Message); } }
private void ArrangeText() { try { fAcceptFontChange = false; fHeights.Clear(); try { int xPos = 0; int yPos = 0; int xMax = 0; int lineHeight = 0; string text = fLines.Text.Trim(); if (!string.IsNullOrEmpty(text)) { Font defFont = this.Font; var parser = new BBTextParser(AppHost.GfxProvider, defFont.Size, new ColorHandler(fLinkColor), new ColorHandler(TextColor)); parser.ParseText(fChunks, text); int line = -1; int chunksCount = fChunks.Count; for (int k = 0; k < chunksCount; k++) { BBTextChunk chunk = fChunks[k]; if (line != chunk.Line) { line = chunk.Line; if (line > 0) { yPos += lineHeight; fHeights.Add(lineHeight); } xPos = 0; lineHeight = 0; } int prevX = xPos; int prevY = yPos; if (!string.IsNullOrEmpty(chunk.Text)) { using (var font = new Font(defFont.FamilyName, chunk.Size, (sdFontStyle)chunk.Style)) { SizeF strSize = font.MeasureString(chunk.Text); chunk.Width = (int)strSize.Width; xPos += chunk.Width; if (xMax < xPos) { xMax = xPos; } int h = (int)strSize.Height; if (lineHeight < h) { lineHeight = h; } } if (!string.IsNullOrEmpty(chunk.URL)) { chunk.LinkRect = ExtRect.CreateBounds(prevX, prevY, xPos - prevX, lineHeight); } } } } fTextSize = new ExtSize(xMax + 2 * fBorderWidth, yPos + 2 * fBorderWidth); } finally { fAcceptFontChange = true; SetImageSize(fTextSize); } } catch (Exception ex) { Logger.LogWrite("HyperView.ArrangeText(): " + ex.Message); } }
private void DoPaint(Graphics gfx) { try { fAcceptFontChange = false; SolidBrush brush = new SolidBrush(this.TextColor); Font font = null; try { gfx.FillRectangle(new SolidBrush(BackgroundColor), Viewport); var scrollPos = ImageViewport; int xOffset = fBorderWidth + scrollPos.Left; int yOffset = fBorderWidth + scrollPos.Top; int lineHeight = 0; int line = -1; int chunksCount = fChunks.Count; for (int k = 0; k < chunksCount; k++) { BBTextChunk chunk = fChunks[k]; if (line != chunk.Line) { line = chunk.Line; xOffset = fBorderWidth + scrollPos.Left; yOffset += lineHeight; // this condition is dirty hack if (line >= 0 && line < fHeights.Count) { lineHeight = fHeights[line]; } } string ct = chunk.Text; if (!string.IsNullOrEmpty(ct)) { Color chunkColor = (chunk.Color == null) ? TextColor : ((ColorHandler)chunk.Color).Handle; if (brush != null) { brush.Dispose(); } brush = new SolidBrush(chunkColor); font = ProcessFont(font, chunk.Size, (EDFontStyle)chunk.Style); gfx.DrawText(font, brush, xOffset, yOffset, ct); xOffset += chunk.Width; } } } finally { fAcceptFontChange = true; if (brush != null) { brush.Dispose(); } if (font != null) { font.Dispose(); } } } catch (Exception ex) { Logger.WriteError("HyperView.DoPaint()", ex); } }
private void ArrangeText() { try { SuspendLayout(); fAcceptFontChange = false; fHeights.Clear(); try { int xPos = 0; int yPos = 0; int xMax = 0; int lineHeight = 0; string text = fLines.Text; Font defFont = this.Font; float maxWidth = this.ClientSize.Width - (2 * fBorderWidth); text = SysUtils.StripHTML(text); var parser = new BBTextParser(AppHost.GfxProvider, defFont.Size, new ColorHandler(fLinkColor), new ColorHandler(TextColor)); parser.ParseText(fChunks, text); int line = -1; int chunksCount = fChunks.Count; int k = 0; while (k < chunksCount) { BBTextChunk chunk = fChunks[k]; bool recalcChunk = false; if (line != chunk.Line) { line = chunk.Line; if (line > 0) { yPos += lineHeight; fHeights.Add(lineHeight); } xPos = 0; lineHeight = 0; } int prevX = xPos; int prevY = yPos; string chunkStr = chunk.Text; if (!string.IsNullOrEmpty(chunkStr)) { using (var font = new Font(defFont.FamilyName, chunk.Size, (EDFontStyle)chunk.Style)) { SizeF strSize = font.MeasureString(chunkStr); if (fWordWrap && xPos + strSize.Width > maxWidth) { int lastPos = 0, prevPos = 0; string tempStr, prevStr = string.Empty; int sliceType = -1; while (true) { tempStr = GetSlice(chunkStr, ref lastPos, ref sliceType); strSize = font.MeasureString(tempStr); if (xPos + strSize.Width <= maxWidth) { prevStr = tempStr; prevPos = lastPos; } else { if (sliceType == 0) { // first word if (xPos == 0) { string tail = chunkStr.Substring(lastPos); SplitChunk(chunk, k, tempStr, tail, ref chunksCount); } else { ShiftChunks(k, chunksCount); recalcChunk = true; } break; } else if (sliceType == 1 || sliceType == 2) { // middle or tail word string tail = chunkStr.Substring(prevPos); SplitChunk(chunk, k, prevStr, tail, ref chunksCount); break; } else if (sliceType == 3) { // one first and last word, nothing to do break; } } } } strSize = font.MeasureString(chunk.Text); chunk.Width = (int)strSize.Width; xPos += chunk.Width; if (xMax < xPos) { xMax = xPos; } int h = (int)strSize.Height; if (lineHeight < h) { lineHeight = h; } } if (!string.IsNullOrEmpty(chunk.URL)) { chunk.LinkRect = ExtRect.CreateBounds(prevX, prevY, xPos - prevX, lineHeight); } } if (!recalcChunk) { k++; } } fTextSize = new ExtSize(xMax + 2 * fBorderWidth, yPos + 2 * fBorderWidth); } finally { fAcceptFontChange = true; SetImageSize(fTextSize); ResumeLayout(); } } catch (Exception ex) { Logger.WriteError("HyperView.ArrangeText()", ex); } }