Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CommonUI / System / Drawing / Advanced / PrivateFontCollection.cs / 1305376 / PrivateFontCollection.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Drawing.Text {
using System.Diagnostics;
using System;
using System.Drawing;
using System.Drawing.Internal;
using System.Runtime.InteropServices;
using System.ComponentModel;
using Microsoft.Win32;
using System.Security;
using System.Security.Permissions;
using System.Globalization;
using System.Runtime.Versioning;
///
///
/// Encapsulates a collection of objecs.
///
public sealed class PrivateFontCollection : FontCollection {
///
///
///
/// Initializes a new instance of the class.
///
///
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Process)]
public PrivateFontCollection() {
nativeFontCollection = IntPtr.Zero;
int status = SafeNativeMethods.Gdip.GdipNewPrivateFontCollection(out nativeFontCollection);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
///
///
///
/// Cleans up Windows resources for this
/// .
///
///
protected override void Dispose(bool disposing) {
if (nativeFontCollection != IntPtr.Zero) {
try{
#if DEBUG
int status =
#endif
SafeNativeMethods.Gdip.GdipDeletePrivateFontCollection(out nativeFontCollection);
#if DEBUG
Debug.Assert(status == SafeNativeMethods.Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
#endif
}
catch( Exception ex ){
if( ClientUtils.IsSecurityOrCriticalException( ex ) ) {
throw;
}
Debug.Fail( "Exception thrown during Dispose: " + ex.ToString() );
}
finally{
nativeFontCollection = IntPtr.Zero;
}
}
base.Dispose(disposing);
}
///
///
///
/// Adds a font from the specified file to
/// this .
///
///
public void AddFontFile (string filename) {
IntSecurity.DemandReadFileIO(filename);
int status = SafeNativeMethods.Gdip.GdipPrivateAddFontFile(new HandleRef(this, nativeFontCollection), filename);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
// Register private font with GDI as well so pure GDI-based controls (TextBox, Button for instance) can access it.
SafeNativeMethods.AddFontFile( filename );
}
//
public void AddMemoryFont (IntPtr memory, int length) {
IntSecurity.ObjectFromWin32Handle.Demand();
int status = SafeNativeMethods.Gdip.GdipPrivateAddMemoryFont(new HandleRef(this, nativeFontCollection), new HandleRef(null, memory), length);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Drawing.Text {
using System.Diagnostics;
using System;
using System.Drawing;
using System.Drawing.Internal;
using System.Runtime.InteropServices;
using System.ComponentModel;
using Microsoft.Win32;
using System.Security;
using System.Security.Permissions;
using System.Globalization;
using System.Runtime.Versioning;
///
///
/// Encapsulates a collection of objecs.
///
public sealed class PrivateFontCollection : FontCollection {
///
///
///
/// Initializes a new instance of the class.
///
///
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Process)]
public PrivateFontCollection() {
nativeFontCollection = IntPtr.Zero;
int status = SafeNativeMethods.Gdip.GdipNewPrivateFontCollection(out nativeFontCollection);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
///
///
///
/// Cleans up Windows resources for this
/// .
///
///
protected override void Dispose(bool disposing) {
if (nativeFontCollection != IntPtr.Zero) {
try{
#if DEBUG
int status =
#endif
SafeNativeMethods.Gdip.GdipDeletePrivateFontCollection(out nativeFontCollection);
#if DEBUG
Debug.Assert(status == SafeNativeMethods.Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
#endif
}
catch( Exception ex ){
if( ClientUtils.IsSecurityOrCriticalException( ex ) ) {
throw;
}
Debug.Fail( "Exception thrown during Dispose: " + ex.ToString() );
}
finally{
nativeFontCollection = IntPtr.Zero;
}
}
base.Dispose(disposing);
}
///
///
///
/// Adds a font from the specified file to
/// this .
///
///
public void AddFontFile (string filename) {
IntSecurity.DemandReadFileIO(filename);
int status = SafeNativeMethods.Gdip.GdipPrivateAddFontFile(new HandleRef(this, nativeFontCollection), filename);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
// Register private font with GDI as well so pure GDI-based controls (TextBox, Button for instance) can access it.
SafeNativeMethods.AddFontFile( filename );
}
//
public void AddMemoryFont (IntPtr memory, int length) {
IntSecurity.ObjectFromWin32Handle.Demand();
int status = SafeNativeMethods.Gdip.GdipPrivateAddMemoryFont(new HandleRef(this, nativeFontCollection), new HandleRef(null, memory), length);
if (status != SafeNativeMethods.Gdip.Ok)
throw SafeNativeMethods.Gdip.StatusException(status);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RelatedPropertyManager.cs
- DataTableNewRowEvent.cs
- HostVisual.cs
- Animatable.cs
- WebPartDisplayModeCancelEventArgs.cs
- ObjectFullSpanRewriter.cs
- EndpointConfigContainer.cs
- InstanceCreationEditor.cs
- ClientTargetSection.cs
- BulletedListEventArgs.cs
- SqlComparer.cs
- ServiceDescriptions.cs
- FileClassifier.cs
- LogEntryHeaderDeserializer.cs
- SymDocumentType.cs
- CardSpacePolicyElement.cs
- SchemaLookupTable.cs
- Scripts.cs
- WebZone.cs
- GridViewCellAutomationPeer.cs
- DbConnectionFactory.cs
- FrameAutomationPeer.cs
- ComPlusDiagnosticTraceSchemas.cs
- CultureTable.cs
- AssemblyGen.cs
- ToolConsole.cs
- GraphicsPathIterator.cs
- XomlCompilerResults.cs
- XmlArrayAttribute.cs
- QueryCacheKey.cs
- Pair.cs
- DelayedRegex.cs
- CommentAction.cs
- RefreshPropertiesAttribute.cs
- CloseSequence.cs
- TableDesigner.cs
- SerializationInfoEnumerator.cs
- ECDiffieHellmanPublicKey.cs
- DocumentSchemaValidator.cs
- MailMessage.cs
- OdbcTransaction.cs
- DataGridViewButtonColumn.cs
- ComplexLine.cs
- OrderedEnumerableRowCollection.cs
- FastEncoderWindow.cs
- PointAnimation.cs
- SettingsPropertyValue.cs
- Fonts.cs
- arabicshape.cs
- Int16AnimationBase.cs
- _NTAuthentication.cs
- CngProperty.cs
- baseshape.cs
- AnnotationComponentChooser.cs
- TextTreeInsertUndoUnit.cs
- COM2ExtendedUITypeEditor.cs
- SoapMessage.cs
- OutputCacheSection.cs
- DataList.cs
- EventMap.cs
- IDispatchConstantAttribute.cs
- ISAPIRuntime.cs
- ResXBuildProvider.cs
- XamlSerializationHelper.cs
- WebServiceParameterData.cs
- AuthStoreRoleProvider.cs
- XmlArrayAttribute.cs
- LabelLiteral.cs
- ActivityIdHeader.cs
- UniqueConstraint.cs
- EventWaitHandleSecurity.cs
- PrimitiveDataContract.cs
- SystemNetworkInterface.cs
- GridSplitterAutomationPeer.cs
- PointValueSerializer.cs
- ControlLocalizer.cs
- AsyncOperationManager.cs
- TaskbarItemInfo.cs
- RegexMatchCollection.cs
- ArcSegment.cs
- TryExpression.cs
- InternalBufferManager.cs
- ConfigurationFileMap.cs
- XomlCompilerParameters.cs
- SizeChangedEventArgs.cs
- Profiler.cs
- DataControlPagerLinkButton.cs
- ValueSerializerAttribute.cs
- ConfigsHelper.cs
- ScriptingProfileServiceSection.cs
- FirstMatchCodeGroup.cs
- EventlogProvider.cs
- BuildProvider.cs
- BoundConstants.cs
- Utils.cs
- SettingsSection.cs
- PassportAuthentication.cs
- MexBindingElement.cs
- GridViewRow.cs
- ReadOnlyCollectionBase.cs