Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / MS / Internal / Shaping / GlyphingCache.cs / 1305600 / GlyphingCache.cs
//---------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // Description: High level glyphing cache // // History: 5-19-2005 garyyang created // //--------------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Windows.Media; using System.Windows.Media.TextFormatting; using MS.Internal; using MS.Internal.TextFormatting; namespace MS.Internal.Shaping { ////// GlyphingCache stores the runtime state of shaping engines and the mapping between Unicode scalar /// value and the physical font being used to display it. This class is not thread-safe. The client is /// responsible for synchronizing access from multiple threads. It is generally recommended that the client /// manages a single instance of this class per text formatting session. /// /// It currently only caches one key-value pair: /// o Typeface - TypefaceMap /// /// This pair is cached in SizeLimitedCache which implement LRU algorithm through /// a linked list. When cache is full, the least used entry in the cache will be replaced /// by the latest entry. /// internal class GlyphingCache { private SizeLimitedCache_sizeLimitedCache; internal GlyphingCache(int capacity) { _sizeLimitedCache = new SizeLimitedCache (capacity); } internal void GetShapeableText( Typeface typeface, CharacterBufferReference characterBufferReference, int stringLength, TextRunProperties textRunProperties, CultureInfo digitCulture, bool isRightToLeftParagraph, IList shapeableList, IShapeableTextCollector collector, TextFormattingMode textFormattingMode ) { if (!typeface.Symbol) { Lookup(typeface).GetShapeableText( characterBufferReference, stringLength, textRunProperties, digitCulture, isRightToLeftParagraph, shapeableList, collector, textFormattingMode ); } else { // It's a non-Unicode ("symbol") font, where code points have non-standard meanings. We // therefore want to bypass the usual itemization and font linking. Instead, just map // everything to the default script and first GlyphTypeface. ShapeTypeface shapeTypeface = new ShapeTypeface( typeface.TryGetGlyphTypeface(), null // device font ); collector.Add( shapeableList, new CharacterBufferRange(characterBufferReference, stringLength), textRunProperties, new MS.Internal.Text.TextInterface.ItemProps(), shapeTypeface, 1.0, // scale in Em false, // null shape textFormattingMode ); } } /// /// Look up the font mapping data for a typeface. /// private TypefaceMap Lookup(Typeface key) { TypefaceMap typefaceMap = _sizeLimitedCache.Get(key); if (typefaceMap == null) { typefaceMap = new TypefaceMap( key.FontFamily, key.FallbackFontFamily, key.CanonicalStyle, key.CanonicalWeight, key.CanonicalStretch, key.NullFont ); _sizeLimitedCache.Add( key, typefaceMap, false // is not permanent in the cache. ); } return typefaceMap; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // Description: High level glyphing cache // // History: 5-19-2005 garyyang created // //--------------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Windows.Media; using System.Windows.Media.TextFormatting; using MS.Internal; using MS.Internal.TextFormatting; namespace MS.Internal.Shaping { ////// GlyphingCache stores the runtime state of shaping engines and the mapping between Unicode scalar /// value and the physical font being used to display it. This class is not thread-safe. The client is /// responsible for synchronizing access from multiple threads. It is generally recommended that the client /// manages a single instance of this class per text formatting session. /// /// It currently only caches one key-value pair: /// o Typeface - TypefaceMap /// /// This pair is cached in SizeLimitedCache which implement LRU algorithm through /// a linked list. When cache is full, the least used entry in the cache will be replaced /// by the latest entry. /// internal class GlyphingCache { private SizeLimitedCache_sizeLimitedCache; internal GlyphingCache(int capacity) { _sizeLimitedCache = new SizeLimitedCache (capacity); } internal void GetShapeableText( Typeface typeface, CharacterBufferReference characterBufferReference, int stringLength, TextRunProperties textRunProperties, CultureInfo digitCulture, bool isRightToLeftParagraph, IList shapeableList, IShapeableTextCollector collector, TextFormattingMode textFormattingMode ) { if (!typeface.Symbol) { Lookup(typeface).GetShapeableText( characterBufferReference, stringLength, textRunProperties, digitCulture, isRightToLeftParagraph, shapeableList, collector, textFormattingMode ); } else { // It's a non-Unicode ("symbol") font, where code points have non-standard meanings. We // therefore want to bypass the usual itemization and font linking. Instead, just map // everything to the default script and first GlyphTypeface. ShapeTypeface shapeTypeface = new ShapeTypeface( typeface.TryGetGlyphTypeface(), null // device font ); collector.Add( shapeableList, new CharacterBufferRange(characterBufferReference, stringLength), textRunProperties, new MS.Internal.Text.TextInterface.ItemProps(), shapeTypeface, 1.0, // scale in Em false, // null shape textFormattingMode ); } } /// /// Look up the font mapping data for a typeface. /// private TypefaceMap Lookup(Typeface key) { TypefaceMap typefaceMap = _sizeLimitedCache.Get(key); if (typefaceMap == null) { typefaceMap = new TypefaceMap( key.FontFamily, key.FallbackFontFamily, key.CanonicalStyle, key.CanonicalWeight, key.CanonicalStretch, key.NullFont ); _sizeLimitedCache.Add( key, typefaceMap, false // is not permanent in the cache. ); } return typefaceMap; } } } // 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
- WebUtil.cs
- EditorAttributeInfo.cs
- Camera.cs
- DecoderNLS.cs
- NameObjectCollectionBase.cs
- SubclassTypeValidator.cs
- SqlBinder.cs
- MSHTMLHostUtil.cs
- ClientSideProviderDescription.cs
- TreeNode.cs
- BoundsDrawingContextWalker.cs
- InputScope.cs
- LoopExpression.cs
- RegisteredExpandoAttribute.cs
- XpsFilter.cs
- DataGridItem.cs
- SynchronizedKeyedCollection.cs
- XmlStringTable.cs
- AssemblyBuilder.cs
- TempFiles.cs
- WorkflowTransactionService.cs
- Socket.cs
- MimeFormatExtensions.cs
- TreeBuilderBamlTranslator.cs
- MDIWindowDialog.cs
- Highlights.cs
- SessionStateContainer.cs
- MimeWriter.cs
- EncodingNLS.cs
- XamlHttpHandlerFactory.cs
- ThreadBehavior.cs
- AppDomainAttributes.cs
- Vector3D.cs
- COM2Properties.cs
- BuildProvidersCompiler.cs
- WinFormsSecurity.cs
- DiscreteKeyFrames.cs
- MailWebEventProvider.cs
- QilFactory.cs
- EarlyBoundInfo.cs
- XPathPatternBuilder.cs
- VisualCollection.cs
- SwitchLevelAttribute.cs
- AspNetRouteServiceHttpHandler.cs
- LineInfo.cs
- TextRunCacheImp.cs
- DataRowExtensions.cs
- UrlMappingsModule.cs
- TimeoutException.cs
- EditableTreeList.cs
- DocumentCollection.cs
- WebServiceErrorEvent.cs
- ScrollEvent.cs
- StylusPointDescription.cs
- PageVisual.cs
- XmlUrlResolver.cs
- HttpRuntimeSection.cs
- ApplicationBuildProvider.cs
- KnownBoxes.cs
- PrivateFontCollection.cs
- SetStoryboardSpeedRatio.cs
- FileDialogCustomPlacesCollection.cs
- ByteArrayHelperWithString.cs
- CheckPair.cs
- XmlSchemaSimpleTypeList.cs
- DataGridViewComponentPropertyGridSite.cs
- XmlSchemaComplexContentExtension.cs
- SchemaTableColumn.cs
- EntityDesignPluralizationHandler.cs
- TransformerConfigurationWizardBase.cs
- GroupItem.cs
- TileModeValidation.cs
- DaylightTime.cs
- CustomCategoryAttribute.cs
- Rfc4050KeyFormatter.cs
- WebPartVerb.cs
- KeyGesture.cs
- ComponentCollection.cs
- ErrorHandler.cs
- PrintPageEvent.cs
- documentsequencetextcontainer.cs
- CellQuery.cs
- PeerTransportListenAddressConverter.cs
- SQLInt64Storage.cs
- CustomError.cs
- NativeMethodsOther.cs
- TdsParserStaticMethods.cs
- ListView.cs
- FixedBufferAttribute.cs
- graph.cs
- WebEventCodes.cs
- DummyDataSource.cs
- Visual3D.cs
- EmptyEnumerator.cs
- AssemblyAttributesGoHere.cs
- ScriptRegistrationManager.cs
- XslCompiledTransform.cs
- DefaultExpressionVisitor.cs
- Transform3DCollection.cs
- StrokeNodeOperations2.cs