Font


public ref class Font
{
public:

Handle fontHandle;

Font(double emSize,
     int style,
     unsigned unit)
{
 fontHandle = GdiPlus::CreateFont(Handle((void*)0),
                                  emSize,
                                  style,
                                  unit);
}

Font(FontFamily^ family,
     double emSize,
     int style,
     unsigned unit)
{
 fontHandle = GdiPlus::CreateFont(family->familyHandle,
                                  emSize,
                                  style,
                                  unit);
}

static operator Handle(Font^ font) {return font->fontHandle;}
 
static Font^ operator*(Transform^ transform, Font^ font)
{
  double Determinant = transform[0,0] * transform[1,1] -
                       transform[0,1] * transform[1,0];

  Determinant = Determinant > 0 ? Determinant : -Determinant;

  FontFamily^ family = gcnew FontFamily(font->fontHandle);

  return gcnew Font(family,
                    font->Size * (double)Math::Sqrt(Determinant),
                    (unsigned)font->Style,
                    (unsigned)font->Unit);
}

Font(String^ familyName,
     double emSize,
     int style,
     Unit unit)
{
 FontFamily^ family = gcnew FontFamily(familyName);
 
 fontHandle = GdiPlus::CreateFont(family->familyHandle,
                                  emSize,
                                  style,
                                  (unsigned)unit);
}

Font(String^ familyName,
     double emSize,
     int style,
     Unit unit,
     FontCollection^ fontCollection)
{
  FontFamily^ family = gcnew FontFamily(familyName, fontCollection);
 
  fontHandle = GdiPlus::CreateFont(family->familyHandle,
                                   emSize,
                                   style,
                                   (unsigned)unit);
}

Font::~Font()
{
 GdiPlus::DeleteFont(fontHandle);
}

// Operations

property int Style
{
	int get() {return GdiPlus::GetFontStyle(fontHandle);}
}

property double Size
{
	double get() {return GdiPlus::GetFontSize(fontHandle);}
}

property IPlusPlus::Drawing::Unit Unit
{
	IPlusPlus::Drawing::Unit get() {return (IPlusPlus::Drawing::Unit)GdiPlus::GetFontUnit(fontHandle);}
}

double GetHeight(Graphics^ graphics);

double GetHeight(double dpi)
{
 return GdiPlus::GetFontHeightGivenDotsPerInch(fontHandle, dpi);
}

Font(Font^ font)
{
  fontHandle = GdiPlus::CloneFont(font->fontHandle);
}

property FontFamily^ Family
{
	FontFamily^ get() {return gcnew FontFamily(GdiPlus::GetFamily(fontHandle));}
}

};

Details

Name Space IPlusPlus::Drawing
Assembly IPlusPlus.Drawing.dll