Index: trunk/ab5.0/ablib/src/Classes/System/Drawing/Font.ab
===================================================================
--- trunk/ab5.0/ablib/src/Classes/System/Drawing/Font.ab	(revision 635)
+++ trunk/ab5.0/ablib/src/Classes/System/Drawing/Font.ab	(revision 698)
@@ -1,5 +1,4 @@
 Namespace System
 Namespace Drawing
-
 
 /**
@@ -8,177 +7,137 @@
 */
 
-Class FontFamily : End Class
-Class FontCollection : End Class
+Class FontCollection
+Public
+	nativeCollection As *GpFontCollection
+End Class
 
 Class Font
 	Implements System.IDisposable
 Public
-'	 friend class Graphics
-
-	Sub Font(/*IN*/ hdc As HDC)
+	Static Function FromHDC(/*IN*/ hdc As HDC) As Font
 		Dim font = 0 As *GpFont
-		lastResult = GdipCreateFontFromDC(hdc, font)
-		SetNativeFont(font)
-	End Sub
-
-	Sub Font(/*IN*/ hdc As HDC, /*IN const*/ ByRef logfont As LOGFONTA)
+		SetStatus(GdipCreateFontFromDC(hdc, font))
+		FromHDC = New Font(font)
+	End Function
+
+	Static Function FromLogFont(/*IN*/ hdc As HDC, /*IN const*/ ByRef logfont As LOGFONTA) As Font
 		Dim font = 0 As *GpFont
-		lastResult =GdipCreateFontFromLogfontA(hdc, logfont, font)
-		SetNativeFont(font)
-	End Sub
-
-	Sub Font(/*IN*/ hdc As HDC, /*IN const*/ ByRef logfont As LOGFONTW)
+		SetStatus(GdipCreateFontFromLogfontA(hdc, logfont, font))
+		FromLogFont = New Font(font)
+	End Function
+
+	Static Function FromLogFont(/*IN*/ hdc As HDC, /*IN const*/ ByRef logfont As LOGFONTW) As Font
 		Dim font = 0 As *GpFont
-		lastResult =GdipCreateFontFromLogfontW(hdc, logfont, font)
-		SetNativeFont(font)
-	End Sub
-
-	Sub Font(/*IN*/ hdc As HDC, /*IN const*/ hfont As HFONT)
+		SetStatus(GdipCreateFontFromLogfontW(hdc, logfont, font))
+		FromLogFont = New Font(font)
+	End Function
+
+	Static Function FromHFont(/*IN*/ hdc As HDC, /*IN const*/ hfont As HFONT) As Font
 		Dim font = 0 As *GpFont
 		If hfont <> 0 Then
 			Dim lf As LOGFONTA
-			If GetObjectA(hfont, sizeof (LOGFONTA), lf) <> 0 Then
-				lastResult = GdipCreateFontFromLogfontA(hdc, lf, font)
+			If GetObjectA(hfont, Len(lf), lf) <> 0 Then
+				SetStatus(GdipCreateFontFromLogfontA(hdc, lf, font))
 			Else
-				lastResult = GdipCreateFontFromDC(hdc, font)
+				SetStatus(GdipCreateFontFromDC(hdc, font))
 			End If
 		Else
-			lastResult = GdipCreateFontFromDC(hdc, font)
-		End If
-		SetNativeFont(font)
+			SetStatus(GdipCreateFontFromDC(hdc, font))
+		End If
+		FromHFont = New Font(font)
+	End Function
+
+	Sub Font(f As *GpFont)
+		nativeFont = f
 	End Sub
 
 	Sub Font(/*IN const*/ family As FontFamily, /*IN*/ emSize As Single)
-		Font(family, emSize, FontStyleRegular, UnitPoint)
-	End Sub
-
-	Sub Font(/*IN const*/ family As FontFamily,
-		/*IN*/ emSize As Single, /*IN*/ style As Long)
-
-		Font(family, emSize, style, UnitPoint)
+		initFont(family, emSize, FontStyle.Regular, GraphicsUnit.Point)
+	End Sub
+
+	Sub Font(/*IN const*/ family As FontFamily, /*IN*/ emSize As Single, /*IN*/ style As FontStyle)
+		initFont(family, emSize, style, GraphicsUnit.Point)
+	End Sub
+
+	Sub Font(/*IN const*/ family As FontFamily, /*IN*/ emSize As Single, /*IN*/ unit As GraphicsUnit)
+		initFont(family, emSize, FontStyle.Regular, unit)
 	End Sub
 
 	Sub Font(/*IN const*/ family As FontFamily, /*IN*/ emSize As Single,
-		/*IN*/ style As Long, /*IN*/ unit As GraphicsUnit)
-
-		Dim font = 0 As *GpFont
-		lastResult = GdipCreateFont(
-			family.NativeFamily, emSize, style, unit, font)
-		SetNativeFont(font)
+		/*IN*/ style As FontStyle, /*IN*/ unit As GraphicsUnit)
+
+		initFont(family, emSize, style, unit)
 	End Sub
 
 	Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single)
-		Font(familyName, emSize, FontStyleRegular, Unit.Point, ByVal 0)
+		initFromName(familyName, emSize, FontStyle.Regular, GraphicsUnit.Point, Nothing)
 	End Sub
 
 	Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single)
-		Font(familyName, emSize, FontStyleRegular, Unit.Point, ByVal 0)
+		initFromName(ToWCStr(familyName), emSize, FontStyle.Regular, GraphicsUnit.Point, Nothing)
+	End Sub
+
+	Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single, /*IN*/ style As FontStyle)
+		initFromName(familyName, emSize, style, GraphicsUnit.Point, Nothing)
+	End Sub
+
+	Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single, /*IN*/ style As FontStyle)
+		initFromName(ToWCStr(familyName), emSize, style, GraphicsUnit.Point, Nothing)
+	End Sub
+
+	Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single, /*IN*/ unit As GraphicsUnit)
+		initFromName(familyName, emSize, FontStyle.Regular, unit, Nothing)
+	End Sub
+
+	Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single, /*IN*/ unit As GraphicsUnit)
+		initFromName(ToWCStr(familyName), emSize, FontStyle.Regular, unit, Nothing)
 	End Sub
 
 	Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single,
-		 /*IN*/ style As Long)
-		Font(familyName, emSize, style, Unit.Point, ByVal 0)
+		 /*IN*/ style As FontStyle, /*IN*/ unit As GraphicsUnit)
+
+		initFromName(familyName, emSize, style, unit, Nothing)
 	End Sub
 
 	Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single,
-		 /*IN*/ style As Long)
-		Font(familyName, emSize, style, Unit.Point, ByVal 0)
+		 /*IN*/ style As FontStyle, /*IN*/ unit As GraphicsUnit)
+
+		initFromName(ToWCStr(familyName), emSize, style, unit, Nothing)
 	End Sub
 
 	Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single,
-		 /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit)
-		Font(familyName, emSize, style, unit, ByVal 0)
+		/*IN*/ style As FontStyle, /*IN*/ unit As GraphicsUnit,
+		/*IN const*/ fontCollection As FontCollection)
+
+		initFromName(familyName, emSize, style, unit, fontCollection)
 	End Sub
 
 	Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single,
-		 /*IN*/ style As Long, /*IN*/ unit As GraphicsUnit)
-		Font(familyName, emSize, style, unit, ByVal 0)
-	End Sub
-
-	Sub Font(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single,
-		/*IN*/ style As Long, /*IN*/ unit As GraphicsUnit,
-		/*IN const*/ ByRef fontCollection As FontCollection)
-
-		nativeFont = 0
-
-		Dim family As FontFamily(familyName, fontCollection)
-		Dim nativeFamily = family.NativeFamily As *GpFontFamily
-
-		lastResult = family.GetLastStatus()
-
-		If lastResult <> Ok Then
-			nativeFamily = FontFamily.GenericSansSerif()->NativeFamily
-			lastResult = FontFamily.GenericSansSerif()->lastResult
-			If lastResult <> Ok Then
-				Exit Sub
-			End If
-		End If
-
-		lastResult = GdipCreateFont(
-			nativeFamily, emSize, style, unit, nativeFont)
-
-		If lastResult <> Ok Then
-			nativeFamily = FontFamily.GenericSansSerif()->NativeFamily
-			lastResult = FontFamily.GenericSansSerif()->lastResult
-			If lastResult <> Ok Then
-				Exit Sub
-			End If
-
-			lastResult = GdipCreateFont(
-				nativeFamily, emSize, style, unit, nativeFont)
-		End If
-	End Sub
-
-	Sub Font(/*IN const*/ familyName As String, /*IN*/ emSize As Single,
-		/*IN*/ style As Long, /*IN*/ unit As GraphicsUnit,
+		/*IN*/ style As FontStyle, /*IN*/ unit As GraphicsUnit,
 		/*IN const*/ fontCollection As FontCollection)
-		Font(ToWCStr(familyName), emSize, style, unit, fontCollection)
-	End Sub
-
-	Const Function GetLogFontA(/*IN const*/ g As Graphics, /*OUT*/ ByRef lf As LOGFONTA) As Status
-		Dim nativeGraphics As *GpGraphics
-		If Not ActiveBasic.IsNothing(g) Then
-			nativeGraphics = g.nativeGraphics
-		End If
-		Return SetStatus(GdipGetLogFontA(nativeFont, nativeGraphics, lf))
-	End Function
-
-	Const Function GetLogFontW(/*IN const*/ g As Graphics, /*OUT*/ ByRef lf As LOGFONTW) As Status
-		Dim nativeGraphics As *GpGraphics
-		If Not ActiveBasic.IsNothing(g) Then
-			nativeGraphics = g.nativeGraphics
-		End If
-		Return SetStatus(GdipGetLogFontW(nativeFont, nativeGraphics, lf))
-	End Function
-
-	Const Function GetLogFont(/*IN const*/ g As Graphics, /*OUT*/ ByRef lf As LOGFONT) As Status
-		Dim nativeGraphics As *GpGraphics
-		If Not ActiveBasic.IsNothing(g) Then
-			nativeGraphics = g.nativeGraphics
-		End If
-#ifdef UNICODE
-		Return SetStatus(GdipGetLogFontW(nativeFont, nativeGraphics, lf))
-#else
-		Return SetStatus(GdipGetLogFontA(nativeFont, nativeGraphics, lf))
-#endif
-	End Function
+
+		initFromName(ToWCStr(familyName), emSize, style, unit, fontCollection)
+	End Sub
 
 	Const Function Clone() As Font
 		Dim cloneFont = 0 As *GpFont
 		SetStatus(GdipCloneFont(nativeFont, cloneFont))
-		Return New Font(cloneFont, lastResult)
-	End Function
+		Clone = New Font(cloneFont)
+	End Function
+
+	Sub Dispose()
+		If nativeFont <> 0 Then
+			GdipDeleteFont(nativeFont)
+		End If
+		nativeFont = 0
+	End Sub
 
 	Sub ~Font()
-		GdipDeleteFont(nativeFont)
-	End Sub
-
-	Const Function IsAvailable() As Boolean
-		Return nativeFont <> 0
-	End Function
-
-	Const Function Style() As Long
-		SetStatus(GdipGetFontStyle(nativeFont, Style))
-	End Function
+		Dispose()
+	End Sub
+
+'	Const Function Style() As FontStyle
+'		SetStatus(GdipGetFontStyle(nativeFont, Style))
+'	End Function
 
 	Const Function Size() As Single
@@ -186,16 +145,13 @@
 	End Function
 
-	Const Function SizeInPoints() As Single
-
-	Const Function Unit() As GraphicsUnit
-		SetStatus(GdipGetFontUnit(nativeFont, Unit))
-	End Function
-
-	Const Function LastStatus() As Status
-		Return lastResult
-	End Function
+'	Const Function SizeInPoints() As Single
+'	End Function
+
+'	Const Function Unit() As GraphicsUnit
+'		SetStatus(GdipGetFontUnit(nativeFont, Unit))
+'	End Function
 
 	Const Function Height() As Long
-		Return GetHeight() As Long
+		Height = GetHeight() As Long
 	End Function
 
@@ -205,8 +161,5 @@
 
 	Const Function GetHeight(/*IN const*/ g As Graphics) As Single
-		Dim nativeGraphics As *GpGraphics
-		If Not ActiveBasic.IsNothing(g) Then
-			nativeGraphics = g.NativeGraphics
-		End If
+		Dim nativeGraphics = getNativeGraphics(g)
 		SetStatus(GdipGetFontHeight(nativeFont, nativeGraphics, GetHeight))
 	End Function
@@ -216,16 +169,13 @@
 	End Function
 
-'	 Const Function FontFamily(/*OUT*/ ByRef family As FontFamily)
-'		If VarPtr(family) = 0 Then
-'			Return SetStatus(Status.InvalidParameter)
-'		End If
-'		Dim status = GdipGetFamily(nativeFont, family->nativeFamily)
-'		family->SetStatus(status)
-'		Return SetStatus(status)
+'	 Const Function FontFamily() As FontFamily
+'		Dim nativeFamily As *GpFamily
+'		SetStatus(GdipGetFamily(nativeFont, nativeFamily))
+'		FontFamily = New FontFamily(nativeFamily)
 '	End Function
 
 	Const Function Bold() As Boolean
 		Dim lf As LOGFONT
-		GetLogFont(0, lf)
+		ToLogFont(lf)
 		Return lf.lfWeight > FW_BOLD
 	End Function
@@ -233,5 +183,5 @@
 	Const Function GdiCharSet() As Byte
 		Dim lf As LOGFONT
-		GetLogFont(0, lf)
+		ToLogFont(lf)
 		Return lf.lfCharSet
 	End Function
@@ -239,42 +189,41 @@
 	'Const Function GdiVerticalFont() As Boolean
 
-	Const Function NativeFont() As *GpFont
-		Return nativeFont
-	End Function
-
 	'Const Function IsSystemFont() As Boolean
 
 	Const Function Italic() As Boolean
 		Dim lf As LOGFONT
-		GetLogFont(0, lf)
-		Return lf.lfItalic <> FALSE
+		ToLogFont(lf)
+		Italic = lf.lfItalic <> FALSE
 	End Function
 
 	Const Function Name() As String
-#ifdef UNICODE
-		Dim lf As LOGFONTW
-		GetLogFontW(0, lf)
-#else
-		Dim lf As LOGFONTA
-		GetLogFontA(0, lf)
-#endif
-		Return lf.lfFaceName
-	End Function
-
-	'Const Function SizeInPoint() As Boolean
+		Dim lf As LOGFONT
+		ToLogFont(lf)
+		Dim p = lf.lfFaceName As PCTSTR
+		Name = New String(p)
+	End Function
 
 	Const Function StrikeOut() As Boolean
 		Dim lf As LOGFONT
-		GetLogFont(0, lf)
-		Return lf.fdwStrikeOut <> FALSE
+		ToLogFont(lf)
+		StrikeOut = lf.lfStrikeOut <> FALSE
 	End Function
 
 	Const Function Style() As FontStyle
 		Dim lf As LOGFONT
-		GetLogFont(0, lf)
-		Return (((lf.lfWeight > FW_BOLD) And FontStyle.Bold) Or _
-			((lf.lfItatlic <> FALSE) And FontStyle.Italic) Or _
-			((lf.fdwStrikeOut <> FALSE) And FontStyle.Strickeout) Or _
-			((lf.fdwUnderline <> FALSE) And FontStyle.Underline)) As FontStyle
+		ToLogFont(lf)
+		Style = FontStyle.Regular
+		If lf.lfWeight > FW_BOLD Then
+			Style Or= FontStyle.Bold
+		End If
+		If lf.lfItalic <> FALSE Then
+			Style Or= FontStyle.Italic
+		End If
+		If lf.lfStrikeOut <> FALSE Then
+			Style Or= FontStyle.Strikeout
+		End If
+		If lf.lfUnderline <> FALSE Then
+			Style Or= FontStyle.Underline
+		End If
 	End Function
 
@@ -283,51 +232,80 @@
 	Const Function Underline() As Boolean
 		Dim lf As LOGFONT
-		GetLogFont(0, lf)
-		Return lf.fdwUnderline <> FALSE
+		ToLogFont(lf)
+		Underline = lf.lfUnderline <> FALSE
 	End Function
 
 	Override Function ToString() As String
-		Return Name
+		ToString = Name
 	End Function
 
 	Const Function ToHfont() As HFONT
 		Dim lf As LOGFONT
-		GetLogFont(ByVal 0, lf)
-		Return CreateFontIndirect(lf)
-	End Function
-
-	Const Sub ToLogFont(ByRef lf As LOGFONT)
-		GetLogFont(ByVal 0, lf)
-	End Sub
-
-	Const Sub ToLogFont(ByRef lf As LOGFONT, g As Graphics)
-		GetLogFont(g, lf)
-	End Sub
+		ToLogFont(lf)
+		ToHfont = CreateFontIndirect(lf)
+	End Function
+
+	Const Sub ToLogFont(/*OUT*/ ByRef lf As LOGFONTA, /*IN const*/ g As Graphics)
+		Dim nativeGraphics = getNativeGraphics(g)
+		SetStatus(GdipGetLogFontA(nativeFont, nativeGraphics, lf))
+	End Sub
+
+	Const Sub ToLogFont(/*OUT*/ ByRef lf As LOGFONTW, /*IN const*/ g As Graphics)
+		Dim nativeGraphics = getNativeGraphics(g)
+		SetStatus(GdipGetLogFontW(nativeFont, nativeGraphics, lf))
+	End Sub
+
+	Const Sub ToLogFont(ByRef lf As LOGFONTA)
+		ToLogFont(lf, Nothing)
+	End Sub
+
+	Const Sub ToLogFont(ByRef lf As LOGFONTW)
+		ToLogFont(lf, Nothing)
+	End Sub
+
+	Function NativeFont() As *GpFont
+		NativeFont = nativeFont
+	End Function
 
 Private
-'	Sub Font(ByRef f As Font)
-
-Protected
-	Sub Font(f As *GpFont, status As Status)
-		lastResult = status
-		SetNativeFont(f)
-	End Sub
-
-	Sub SetNativeFont(f As *GpFont)
-		nativeFont = f
-	End Sub
-
-	Const Function SetStatus(s As Status) As Status
-		If s <> Status.Ok Then
-			lastResult = s
-			Return s
+	Sub initFont(/*IN const*/ family As FontFamily, /*IN*/ emSize As Single,
+		/*IN*/ style As Long, /*IN*/ unit As GraphicsUnit)
+
+		If ActiveBasic.IsNothing(family) Then
+			Throw New ArgumentNullException("family")
+		End If
+		SetStatus(GdipCreateFont(family.NativeFamily, emSize, style, unit, nativeFont))
+	End Sub
+
+	Sub initFromName(/*IN const*/ familyName As PCWSTR, /*IN*/ emSize As Single,
+		/*IN*/ style As Long, /*IN*/ unit As GraphicsUnit, fontCollection As FontCollection)
+
+		nativeFont = 0
+		Dim family = Nothing As FontFamily
+		Dim nativeFamily = family.NativeFamily
+
+		Try
+			family = New FontFamily(familyName, fontCollection)
+		Catch e As Exception
+			nativeFamily = FontFamily.GenericSansSerif().NativeFamily
+		End Try
+
+		Try
+			SetStatus(GdipCreateFont(nativeFamily, emSize, style, unit, nativeFont))
+		Catch e As Exception
+			nativeFamily = FontFamily.GenericSansSerif().NativeFamily
+			SetStatus(GdipCreateFont(nativeFamily, emSize, style, unit, nativeFont))
+		End Try
+	End Sub
+
+	Static Function getNativeGraphics(g As Graphics) As *GpGraphics
+		If ActiveBasic.IsNothing(g) Then
+			getNativeGraphics = 0
 		Else
-			Return s
-		End If
-	End Function
-
-Protected
+			getNativeGraphics = g.NativeGraphics
+		End If
+	End Function
+
 	nativeFont As *GpFont
-	/*mutable*/ lastResult As Status
 End Class
 
