Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / System / Windows / Media / FontEmbeddingManager.cs / 1305600 / FontEmbeddingManager.cs
//----------------------------------------------------------------------------
//
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
//
// Description: The FontEmbeddingManager class handles physical and composite font embedding.
//
// See spec at http://avalon/text/DesignDocsAndSpecs/Font%20embedding%20APIs.htm
//
//
// History:
// 01/27/2004 : mleonov - Created
//
//---------------------------------------------------------------------------
using System;
using System.Text;
using System.IO;
using System.Globalization;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using MS.Internal.FontCache;
using MS.Internal.FontFace;
using MS.Internal.Shaping;
using System.Security;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
// Allow suppression of presharp warnings
#pragma warning disable 1634, 1691
namespace System.Windows.Media
{
///
/// The FontEmbeddingManager class handles physical and composite font embedding.
///
public class FontEmbeddingManager
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
///
/// Creates a new instance of font usage manager.
///
public FontEmbeddingManager()
{
_collectedGlyphTypefaces = new Dictionary>(_uriComparer);
}
#endregion Constructors
//------------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
#region Public Methods
///
/// Collects information about glyph typeface and index used by a glyph run.
///
/// Glyph run to obtain typeface and index information from.
public void RecordUsage(GlyphRun glyphRun)
{
if (glyphRun == null)
throw new ArgumentNullException("glyphRun");
// Suppress PRESharp parameter validation warning about glyphRun.GlyphTypeface because
// GlyphRun.GlyphTypeface property cannot be null.
#pragma warning suppress 56506
Uri glyphTypeface = glyphRun.GlyphTypeface.FontUri;
Dictionary glyphSet;
if (_collectedGlyphTypefaces.ContainsKey(glyphTypeface))
glyphSet = _collectedGlyphTypefaces[glyphTypeface];
else
glyphSet = _collectedGlyphTypefaces[glyphTypeface] = new Dictionary();
foreach(ushort glyphIndex in glyphRun.GlyphIndices)
{
glyphSet[glyphIndex] = true;
}
}
///
/// Returns the collection of glyph typefaces used by the previously added glyph runs.
///
/// The collection of glyph typefaces used by the previously added glyph runs.
[CLSCompliant(false)]
public ICollection GlyphTypefaceUris
{
get
{
return _collectedGlyphTypefaces.Keys;
}
}
///
/// Obtain the list of glyphs used by the glyph typeface specified by a Uri.
///
/// Specifies the Uri of a glyph typeface to obtain usage data for.
/// A collection of glyph indices recorded previously.
///
/// Glyph typeface Uri does not point to a previously recorded glyph typeface.
///
[CLSCompliant(false)]
public ICollection GetUsedGlyphs(Uri glyphTypeface)
{
Dictionary glyphsUsed = _collectedGlyphTypefaces[glyphTypeface];
if (glyphsUsed == null)
{
throw new ArgumentException(SR.Get(SRID.GlyphTypefaceNotRecorded), "glyphTypeface");
}
return glyphsUsed.Keys;
}
#endregion Public Methods
private class UriComparer : IEqualityComparer
{
#region IEqualityComparer Members
public bool Equals(Uri x, Uri y)
{
// We don't use Uri.Equals because it doesn't compare Fragment parts,
// and we use Fragment part to store font face index.
return String.Equals(x.ToString(), y.ToString(), StringComparison.OrdinalIgnoreCase);
}
public int GetHashCode(Uri obj)
{
return obj.GetHashCode();
}
#endregion
}
//------------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Fields
///
/// bool values in the dictionary don't matter,
/// we'll switch to Set class when it becomes available.
///
private Dictionary> _collectedGlyphTypefaces;
private static UriComparer _uriComparer = new UriComparer();
#endregion Private Fields
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------------
//
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
//
// Description: The FontEmbeddingManager class handles physical and composite font embedding.
//
// See spec at http://avalon/text/DesignDocsAndSpecs/Font%20embedding%20APIs.htm
//
//
// History:
// 01/27/2004 : mleonov - Created
//
//---------------------------------------------------------------------------
using System;
using System.Text;
using System.IO;
using System.Globalization;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using MS.Internal.FontCache;
using MS.Internal.FontFace;
using MS.Internal.Shaping;
using System.Security;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
// Allow suppression of presharp warnings
#pragma warning disable 1634, 1691
namespace System.Windows.Media
{
///
/// The FontEmbeddingManager class handles physical and composite font embedding.
///
public class FontEmbeddingManager
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
///
/// Creates a new instance of font usage manager.
///
public FontEmbeddingManager()
{
_collectedGlyphTypefaces = new Dictionary>(_uriComparer);
}
#endregion Constructors
//------------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
#region Public Methods
///
/// Collects information about glyph typeface and index used by a glyph run.
///
/// Glyph run to obtain typeface and index information from.
public void RecordUsage(GlyphRun glyphRun)
{
if (glyphRun == null)
throw new ArgumentNullException("glyphRun");
// Suppress PRESharp parameter validation warning about glyphRun.GlyphTypeface because
// GlyphRun.GlyphTypeface property cannot be null.
#pragma warning suppress 56506
Uri glyphTypeface = glyphRun.GlyphTypeface.FontUri;
Dictionary glyphSet;
if (_collectedGlyphTypefaces.ContainsKey(glyphTypeface))
glyphSet = _collectedGlyphTypefaces[glyphTypeface];
else
glyphSet = _collectedGlyphTypefaces[glyphTypeface] = new Dictionary();
foreach(ushort glyphIndex in glyphRun.GlyphIndices)
{
glyphSet[glyphIndex] = true;
}
}
///
/// Returns the collection of glyph typefaces used by the previously added glyph runs.
///
/// The collection of glyph typefaces used by the previously added glyph runs.
[CLSCompliant(false)]
public ICollection GlyphTypefaceUris
{
get
{
return _collectedGlyphTypefaces.Keys;
}
}
///
/// Obtain the list of glyphs used by the glyph typeface specified by a Uri.
///
/// Specifies the Uri of a glyph typeface to obtain usage data for.
/// A collection of glyph indices recorded previously.
///
/// Glyph typeface Uri does not point to a previously recorded glyph typeface.
///
[CLSCompliant(false)]
public ICollection GetUsedGlyphs(Uri glyphTypeface)
{
Dictionary glyphsUsed = _collectedGlyphTypefaces[glyphTypeface];
if (glyphsUsed == null)
{
throw new ArgumentException(SR.Get(SRID.GlyphTypefaceNotRecorded), "glyphTypeface");
}
return glyphsUsed.Keys;
}
#endregion Public Methods
private class UriComparer : IEqualityComparer
{
#region IEqualityComparer Members
public bool Equals(Uri x, Uri y)
{
// We don't use Uri.Equals because it doesn't compare Fragment parts,
// and we use Fragment part to store font face index.
return String.Equals(x.ToString(), y.ToString(), StringComparison.OrdinalIgnoreCase);
}
public int GetHashCode(Uri obj)
{
return obj.GetHashCode();
}
#endregion
}
//------------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Fields
///
/// bool values in the dictionary don't matter,
/// we'll switch to Set class when it becomes available.
///
private Dictionary> _collectedGlyphTypefaces;
private static UriComparer _uriComparer = new UriComparer();
#endregion Private Fields
}
}
// 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
- WebPartRestoreVerb.cs
- DbParameterCollectionHelper.cs
- XmlSchemaAttributeGroupRef.cs
- Rectangle.cs
- NullableBoolConverter.cs
- MemberBinding.cs
- MetafileHeaderWmf.cs
- SystemIcmpV4Statistics.cs
- TextBoxLine.cs
- DataQuery.cs
- TypeReference.cs
- ImplicitInputBrush.cs
- TextParagraphProperties.cs
- Formatter.cs
- ResourceAttributes.cs
- OracleParameter.cs
- DataGridClipboardHelper.cs
- ProviderUtil.cs
- LogRecordSequence.cs
- CodeEventReferenceExpression.cs
- MetabaseSettingsIis7.cs
- PersonalizationProviderCollection.cs
- WebReferencesBuildProvider.cs
- DataObject.cs
- CompositionAdorner.cs
- SqlRecordBuffer.cs
- BrowserCapabilitiesFactory35.cs
- BitVector32.cs
- WebPartTracker.cs
- PropertyGridCommands.cs
- FullTrustAssemblyCollection.cs
- MetadataSource.cs
- LongValidator.cs
- SecurityState.cs
- ComponentResourceKey.cs
- CacheChildrenQuery.cs
- SqlRemoveConstantOrderBy.cs
- FilteredReadOnlyMetadataCollection.cs
- GB18030Encoding.cs
- SecUtil.cs
- DynamicValidatorEventArgs.cs
- NativeMethods.cs
- RangeBaseAutomationPeer.cs
- handlecollector.cs
- DataGridRow.cs
- ObsoleteAttribute.cs
- TraceUtility.cs
- IndexOutOfRangeException.cs
- Math.cs
- HtmlInputSubmit.cs
- ImageSourceConverter.cs
- MetafileHeaderWmf.cs
- BehaviorEditorPart.cs
- XD.cs
- OwnerDrawPropertyBag.cs
- Polygon.cs
- X509ChainElement.cs
- JsonWriter.cs
- ExpressionConverter.cs
- httpserverutility.cs
- BitConverter.cs
- DataTemplate.cs
- ContentPosition.cs
- XmlReflectionImporter.cs
- HttpModuleCollection.cs
- mongolianshape.cs
- Section.cs
- URLEditor.cs
- StorageInfo.cs
- Multiply.cs
- TreeIterators.cs
- ScalarRestriction.cs
- HebrewNumber.cs
- WindowsHyperlink.cs
- QilTypeChecker.cs
- MediaSystem.cs
- ProxyWebPart.cs
- FileDialogPermission.cs
- DataGridrowEditEndingEventArgs.cs
- EntityDataSourceStatementEditor.cs
- FloaterParagraph.cs
- FixedBufferAttribute.cs
- ErrorFormatterPage.cs
- Internal.cs
- DataGridViewCellLinkedList.cs
- WindowsAuthenticationModule.cs
- TokenizerHelper.cs
- DataObjectFieldAttribute.cs
- EmptyEnumerable.cs
- HtmlGenericControl.cs
- ToolboxItemCollection.cs
- webclient.cs
- RectangleF.cs
- ToolStripActionList.cs
- CommonObjectSecurity.cs
- SourceFileBuildProvider.cs
- PinnedBufferMemoryStream.cs
- Tracking.cs
- RequestQueryProcessor.cs
- Rotation3DAnimation.cs