9

For some reason if I add a string to GraphicsPath using AddString the font is going to be smaller than it looks like in the Font Dialog.

  SizeF sz = g.MeasureString(Text, new Font(Font.FontFamily, (int)(Font.Size - (Font.Size / 7)), Font.Style), new PointF(0, 0), StringFormat.GenericDefault);

  this.Size = new Size((int)sz.Width, (int)sz.Height);
  //These are not the same
  fontpath.AddString(this.Text, this.Font.FontFamily,(int)this.Font.Style, this.Font.Size, new Point(0, 0),StringFormat.GenericDefault);

Does anyone know why it might be doing that?

Kristina
  • 15,859
  • 29
  • 111
  • 181

2 Answers2

22

Assuming your Font.Size's unit is Point, you should convert the size that you passed to AddString to emSize (The height of the em square box that bounds the character).

float emSize = graphics.DpiY * font.Size / 72;
idursun
  • 6,261
  • 1
  • 37
  • 51
  • 3
    Why assume the point unit when there is `Font.SizeInPoints`? Also what does "convert to emSize" mean? Em size is not a unit. Why not tell people that `AddString` expects the pixel unit (which I assume because of your formula that converts points to pixels)? – user764754 Mar 26 '16 at 19:28
  • 1
    Clarifying on the above comment, `emSize` is provided here because that is the "unit" expected as an argument to `Path::AddString()`. "em" is a unit in typography referring to a size relative to a capital "M". See [this Wikipedia article](https://en.wikipedia.org/wiki/Em_(typography)) for more info. – Richard Hauer Jul 31 '21 at 07:04
2
float emSize = graphics.DpiY * font.SizeInPoints / 72;
Stiffels
  • 357
  • 2
  • 4