Page 1 of 1


Posted: Mon May 15, 2017 5:40 am
by euanw
I'm trying to draw some text in my picture, I normally use a Rectangle and set the Text property, but this time I don't want a background to the text. What should I use? I also don't want a border, so setting the DrawStyle of the Rectangle to Edge isn't any good. I tried a PointText, but the font is all horrible, couldn't work out why.
I've attached the file showing the result using PointText. When I use a Rectangle with Text it looks nice

var label = new PointText();
label.Location = picture.PointDeviceToElement(new Vector(distanceFromLeftToRuler - tickLineLength - 10, heightInPixels));
label.Text = HTMLtoRTF.ConvertToUnicode(value);
label.TextAppearance = new Prodige.Drawing.Styles.TextAppearance() { SizeUnit = System.Drawing.GraphicsUnit.Millimeter, Size = 3f / picture.Scaling.X };
label.TextAppearance.HorizontalAlignment = System.Drawing.StringAlignment.Far;
label.TextAppearance.VerticalAlignment = System.Drawing.StringAlignment.Center;

What am I doing wrong?



Re: PointText

Posted: Tue May 16, 2017 9:07 am
by Frank Hileman
Hello Euan,

Usually when there is a problem like this, I try drawing an Element in the designer, where I can control all properties via the property grid. This is much faster than changing code and re-running the program.

In this case, I can think of only these potential problems:
  • The text created via your ConvertToUnicode method.
  • Some unequal scaling or a strange shearing transformation applied to the text. This scaling may be on the Element itself, or it may be at a higher level.
  • The font may be wacky.
  • The Elements are doubled? There is a strange effect as if things are drawn twice.
  • You are drawing into a transparent bitmap and then drawing that bitmap on another surface. There is a known flaw with the ClearText algorithm in GDI+ whereby the algorithm cuts "holes" in transparent bitmaps (sets pixel areas to have no opacity). This is most evident when using the TranslucentForm, but it can occur in other circumstances. In this case, the work around is to reduce the opacity of the TextAppearance color slightly (.99 or so). Such a small change in opacity fixes the bug.
I will try to recreate the text in the designer but I don't think I have enough information to see the problem. If you have a static Picture, that would be useful. Or a simple program.

Re: PointText

Posted: Tue May 16, 2017 9:37 am
by Frank Hileman
Hello Euan,

I could not reproduce the problem. I did note you are using Millimeters as a size unit. This is rare. I don't know if there is any bug with this unit, but world coordinates are generally the best unit, as they are independent of DPI.


Re: PointText

Posted: Thu May 18, 2017 4:01 am
by euanw
Hi Frank,

yes, it seemed to be related to the Millimeters size unit. All ok now