Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Core / CSharp / MS / Internal / FontCache / TypefaceMetricsCache.cs / 1 / TypefaceMetricsCache.cs
//----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Description: TypefaceMetricsCache
//
// History: 5-25-2005 garyyang, Created.
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Security;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using MS.Internal.FontFace;
using MS.Internal.Shaping;
namespace MS.Internal.FontCache
{
///
/// TypefaceMetricsCache caches managed objects related to a Font's realization. It caches the 3 kinds of
/// key-value pairs currently:
/// o Friendly name - canonical name
/// o FontFamilyIdentifier - First IFontFamily
/// o Typeface - CachedTypeface
///
/// The cache lives in managed space to save working set by allowing multiple instances of FontFamily
/// and Typeface to share the same IFontFamily and ITypefaceMetrics object.
/// For example: in MSNBAML, there are 342 typeface objects and they are canonicalized to only 5
/// ITypefaceMetrics.
///
/// When cache is full, a new instance of the hashtable will be created and the old one will be discarded.
/// Hence, it is important that the cached object do not keep a pointer to the hashtable to ensure obsolete cached
/// values are properly GC'ed.
///
internal static class TypefaceMetricsCache
{
///
/// Readonly lookup from the cache.
///
internal static object ReadonlyLookup(object key)
{
return _hashTable[key];
}
///
/// The method adds values into the cache. It uses lock to synchronize access.
///
internal static void Add(object key, object value)
{
// Hashtable allows for one writer and multiple reader at the same time. So we don't have
// read-write confict. In heavy threading environment, the worst is adding
// the same value more than once.
lock(_lock)
{
if (_hashTable.Count >= MaxCacheCapacity)
{
// when cache is full, we just renew the cache.
_hashTable = new Hashtable(MaxCacheCapacity);
}
_hashTable[key] = value;
}
}
private static Hashtable _hashTable = new Hashtable(MaxCacheCapacity);
private static object _lock = new object();
private const int MaxCacheCapacity = 64; // Maximum cache capacity
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Description: TypefaceMetricsCache
//
// History: 5-25-2005 garyyang, Created.
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Security;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using MS.Internal.FontFace;
using MS.Internal.Shaping;
namespace MS.Internal.FontCache
{
///
/// TypefaceMetricsCache caches managed objects related to a Font's realization. It caches the 3 kinds of
/// key-value pairs currently:
/// o Friendly name - canonical name
/// o FontFamilyIdentifier - First IFontFamily
/// o Typeface - CachedTypeface
///
/// The cache lives in managed space to save working set by allowing multiple instances of FontFamily
/// and Typeface to share the same IFontFamily and ITypefaceMetrics object.
/// For example: in MSNBAML, there are 342 typeface objects and they are canonicalized to only 5
/// ITypefaceMetrics.
///
/// When cache is full, a new instance of the hashtable will be created and the old one will be discarded.
/// Hence, it is important that the cached object do not keep a pointer to the hashtable to ensure obsolete cached
/// values are properly GC'ed.
///
internal static class TypefaceMetricsCache
{
///
/// Readonly lookup from the cache.
///
internal static object ReadonlyLookup(object key)
{
return _hashTable[key];
}
///
/// The method adds values into the cache. It uses lock to synchronize access.
///
internal static void Add(object key, object value)
{
// Hashtable allows for one writer and multiple reader at the same time. So we don't have
// read-write confict. In heavy threading environment, the worst is adding
// the same value more than once.
lock(_lock)
{
if (_hashTable.Count >= MaxCacheCapacity)
{
// when cache is full, we just renew the cache.
_hashTable = new Hashtable(MaxCacheCapacity);
}
_hashTable[key] = value;
}
}
private static Hashtable _hashTable = new Hashtable(MaxCacheCapacity);
private static object _lock = new object();
private const int MaxCacheCapacity = 64; // Maximum cache capacity
}
}
// 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
- PeerInvitationResponse.cs
- TextOutput.cs
- Win32Exception.cs
- InfoCardSymmetricCrypto.cs
- CompoundFileStorageReference.cs
- GridItem.cs
- Label.cs
- OdbcConnectionHandle.cs
- CutCopyPasteHelper.cs
- OneWayBindingElement.cs
- RegularExpressionValidator.cs
- StsCommunicationException.cs
- ToolboxItemCollection.cs
- PerformanceCountersElement.cs
- CodeIndexerExpression.cs
- DataSourceCache.cs
- BinHexEncoder.cs
- String.cs
- PathTooLongException.cs
- ResourceCodeDomSerializer.cs
- WebEncodingValidatorAttribute.cs
- XhtmlStyleClass.cs
- EmptyEnumerable.cs
- OleDbFactory.cs
- BuildResultCache.cs
- SystemUdpStatistics.cs
- ChtmlMobileTextWriter.cs
- ValidationEventArgs.cs
- RenderingBiasValidation.cs
- PaintValueEventArgs.cs
- HttpWriter.cs
- BitStream.cs
- SamlConstants.cs
- BitArray.cs
- InputMethodStateChangeEventArgs.cs
- OdbcTransaction.cs
- DateTimeValueSerializerContext.cs
- DeviceContext.cs
- InitializationEventAttribute.cs
- Filter.cs
- ContextMenuStripActionList.cs
- ToolStripArrowRenderEventArgs.cs
- ToolStripItemClickedEventArgs.cs
- ObjectStorage.cs
- ParameterCollection.cs
- TextViewDesigner.cs
- DrawingAttributesDefaultValueFactory.cs
- BaseTemplateCodeDomTreeGenerator.cs
- ResourceType.cs
- BinaryConverter.cs
- InvokeCompletedEventArgs.cs
- DbMetaDataFactory.cs
- TextEditorSpelling.cs
- LineServicesCallbacks.cs
- TemplateControlParser.cs
- InvokeMethodActivity.cs
- TypeElement.cs
- EncryptedPackageFilter.cs
- SslStreamSecurityElement.cs
- input.cs
- TemplateControlCodeDomTreeGenerator.cs
- StateWorkerRequest.cs
- EdmConstants.cs
- HtmlMeta.cs
- TextDecorationUnitValidation.cs
- SafeReversePInvokeHandle.cs
- ResourceExpressionEditorSheet.cs
- FontDriver.cs
- ConditionalAttribute.cs
- StickyNoteHelper.cs
- UserUseLicenseDictionaryLoader.cs
- PassportAuthenticationModule.cs
- StylusButtonEventArgs.cs
- ExeConfigurationFileMap.cs
- WebPartDisplayModeCollection.cs
- AcceleratedTokenProvider.cs
- EastAsianLunisolarCalendar.cs
- RegularExpressionValidator.cs
- AxWrapperGen.cs
- EntityCommandDefinition.cs
- GeometryValueSerializer.cs
- Paragraph.cs
- PhonemeConverter.cs
- XhtmlBasicValidatorAdapter.cs
- Win32SafeHandles.cs
- SQLMoneyStorage.cs
- CodeCatchClauseCollection.cs
- AuthenticationServiceManager.cs
- RNGCryptoServiceProvider.cs
- RegexMatchCollection.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- BooleanExpr.cs
- OdbcDataReader.cs
- WSHttpBindingElement.cs
- CreateUserErrorEventArgs.cs
- DiagnosticTraceSource.cs
- EnumType.cs
- DataSourceCache.cs
- SudsWriter.cs
- SqlXml.cs