Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
15
Documents.Reports.GraphicsProxy DrawString for multi-line strings increments y position of each line by measured height of entire multi-line string instead of a single line height
posted

The GraphicsProxy adds too much space between each line for multi-line strings. I'm using version 17.2.20172.2006. 

Passing in string "a\r\nb" ends up looking like "a\r\n\r\nb" (Shown in PDF). The method in question is below. Any ideas?

0434.TestGraphicsProxy.pdf

		public void DrawString(string s, System.Drawing.Font font, System.Drawing.Brush brush, float x, float y, System.Drawing.StringFormat format)
        {
			if (s == null) throw new ArgumentNullException("s");
			if (font == null) throw new ArgumentNullException("font");
			if (brush == null) throw new ArgumentNullException("brush");

			_graphics.Font = GetFont(font);
			_graphics.Brush = GetBrush(brush);

			float h = _memoryGraphics.MeasureString(s, font).Height;

			CharBuffer cb = new CharBuffer();

			foreach (char ch in s)
			{
				if (ch == '\r') continue;

				if (ch == '\n')
				{
					if (cb.Count > 0)
					{
						_graphics.DrawString(x, y, cb.ToString());
						cb.Clear();
					}

					y += h;
				}
				else
				{
					cb.Add(ch);
				}
			}

			if (cb.Count > 0) _graphics.DrawString(x, y, cb.ToString());
        }

Parents Reply Children