[Mono-bugs] [Bug 77496][Blo] New - MeasureCharacterRanges inconsistent with actual position

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue Feb 7 16:08:11 EST 2006


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by pkwan at advsofteng.net.

http://bugzilla.ximian.com/show_bug.cgi?id=77496

--- shadow/77496	2006-02-07 16:08:11.000000000 -0500
+++ shadow/77496.tmp.31711	2006-02-07 16:08:11.000000000 -0500
@@ -0,0 +1,121 @@
+Bug#: 77496
+Product: Mono: Class Libraries
+Version: 1.1
+OS: GNU/Linux [Other]
+OS Details: Fedore 4 and Gentoo (kernel 2.6.14) and probably other Linux too
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Blocker
+Component: Sys.Drawing.
+AssignedTo: jordi at ximian.com                            
+ReportedBy: pkwan at advsofteng.net               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: MeasureCharacterRanges inconsistent with actual position
+
+Please fill in this template when reporting a bug, unless you know what 
+you are doing.
+
+Description of Problem:
+
+When drawing text using Graphics.DrawString, the position of the text as 
+reported by MeasureCharacterRanges is different from the actual position 
+rendered. This cause problems in softwares that need to know the positions 
+of the text for automatic layout.
+
+Steps to reproduce the problem:
+
+1. Run the ASP.NET page below. This page is modified by code published in 
+Microsoft's web site to explain how to use MeasureCharacterRanges. It 
+draws text on a Bitmap object, then draws the bounding rectangle to the 
+text.
+
+Actual Results:
+
+In Microsoft.NET, the bounding rectangle correctly bounds the text. In 
+Mono, part of the text is outside the bounding rectangle. The bounding 
+rectangle appears to be in a reasonably correct position, so the text 
+position is incorrect.
+
+Expected Results:
+
+That the bounding rectangle should bound that text, and that the top edge 
+of the rectangle should be close to the top edge of the bitmap, as the 
+text is drawn at (0, 0).
+
+How often does this happen? 
+
+Always in Mono 1.1.13_2 and also seen in Mono 1.1.12.
+
+Additional Information:
+
+Test code as follows:
+
+
+<%@ Page language="c#" Debug="true" %>
+<%@ Import Namespace="System.Drawing" %>
+<%@ Import Namespace="System.Drawing.Text" %>
+<%@ Import Namespace="System.Drawing.Imaging" %>
+<%
+// Set up string.
+string measureString = "ABpqr and xyz123 ranges";
+Font stringFont = new Font("Arial", 12.0F);
+
+// Set character ranges to measure
+CharacterRange[] characterRanges = { new CharacterRange(0, 5), new 
+CharacterRange(10, 6) };
+
+// Create rectangle for layout.
+float x = 0F;
+float y = 0F;
+float width = 250.0F;
+float height = 35.0F;
+RectangleF layoutRect = new RectangleF(x, y, width, height);
+
+// Set string format.
+StringFormat stringFormat = new StringFormat();
+stringFormat.SetMeasurableCharacterRanges(characterRanges);
+
+// Draw to bitmap
+Bitmap b = new Bitmap((int)width, (int)height);
+b.SetResolution(96, 96);
+Graphics g = Graphics.FromImage(b);
+g.DrawString(measureString, stringFont, Brushes.Black, x, y, stringFormat);
+
+// Measure two ranges in string.
+Region[] stringRegions = new Region[2];
+stringRegions = g.MeasureCharacterRanges(measureString, stringFont, 
+layoutRect, stringFormat);
+
+// Draw rectangle for first measured range.
+RectangleF measureRect1 = stringRegions[0].GetBounds(g);
+g.DrawRectangle(new Pen(Color.Red, 1), Rectangle.Round(measureRect1));
+
+// Draw rectangle for second measured range.
+RectangleF measureRect2 = stringRegions[1].GetBounds(g);
+g.DrawRectangle(new Pen(Color.Blue, 1), Rectangle.Round(measureRect2));
+
+//Render pixels in bitmap as cells in HTML table below
+%>
+<TABLE CELLSPACING='0' CELLPADDING='0' BORDER='1'><TR><TH></TH>
+<% for (int i = 0; i < b.Width; ++i) { %><TH WIDTH="20" 
+BGCOLOR='#DDDDDD'><%=i%></TH><% } %>
+<%
+	for (int i = 0; i < b.Height; ++i)
+	{
+%>
+<TR><TD BGCOLOR='#DDDDDD'><%=i%></TD>
+<%
+        for (int j = 0; j < b.Width; ++j)
+        {        
+%>
+<TD bgcolor='<%=b.GetPixel(j, i).A == 0 ? "#FFFFFF" : "#000000"%
+>'>&nbsp;</TD>
+<%
+        }
+    }
+%>
+</TABLE>


More information about the mono-bugs mailing list