2

I'm trying to get true type font glyph outlines using sample code from here.

There are some small errors in the code, including the fact that it only considers the whole part of the fixed point values that represent point positions of the glyphs.

There seem to be lots of examples of converting floating point values to fixed, but not vice-versa. How can I convert the whole FIXED value to a floating point value?

mskfisher
  • 3,291
  • 4
  • 35
  • 48
Toby Wilson
  • 1,467
  • 5
  • 19
  • 42
  • 1
    possible duplicate of [Fixed Point to Floating Point and Backwards](http://stackoverflow.com/questions/2574487/fixed-point-to-floating-point-and-backwards) – Hogan Apr 20 '11 at 10:35
  • 1
    do you mean like from `int` to `double` .. isn't that already done by implicit conversion.. – Shekhar_Pro Apr 20 '11 at 10:36
  • @Hogan Not really since that only tells if it's safe and not how to do it in C#. – Jonas Elfström Apr 20 '11 at 12:27

1 Answers1

3

I guess it's a

public struct FIXED
{
    public short fract;
    public short value;
}

that you want to convert to floating point. Such fixed-point numbers can be converted like this

var fix = new FIXED { value = 42, fract = 16384 };
double floating = fix.value + (double)fix.fract / 65536;

I divide by 65536 because a short is 16 bits (2^16). It's actually kind of strange that's it a short and not a ushort since a fraction can't be negative.

Jonas Elfström
  • 30,834
  • 6
  • 70
  • 106
  • Had already tried this; it's either not correct for this type or there's some crazy stuff going on in the fonts that I'm not taking into account. – Toby Wilson Apr 20 '11 at 12:37
  • Further reading indicates you're correct. There must be some crazy hinting shizzle going on in the fonts I'm using. – Toby Wilson Apr 20 '11 at 12:51