Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / MS / Internal / FontCache / DWriteFactory.cs / 1407647 / DWriteFactory.cs
//---------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // Description: The DWriteFactory class represents a shared DWrite factory // object. // // History: // 08/08/2008 : [....] - Integrating with DWrite. // //--------------------------------------------------------------------------- using System; using System.Security; using System.Security.Permissions; using System.IO; using System.Collections.Generic; using System.Text; using System.Diagnostics; using MS.Internal.PresentationCore; namespace MS.Internal.FontCache { internal static class DWriteFactory { ////// Critical - Access security critical Factory.Create method. /// Safe - The parameters passed to Factory.Create are internal /// types created by this method. /// [SecuritySafeCritical] static DWriteFactory() { _factory = Text.TextInterface.Factory.Create( Text.TextInterface.FactoryType.Shared, new FontSourceCollectionFactory(), new FontSourceFactory()); Text.TextInterface.LocalizedErrorMsgs.EnumeratorNotStarted = SR.Get(SRID.Enumerator_NotStarted); Text.TextInterface.LocalizedErrorMsgs.EnumeratorReachedEnd = SR.Get(SRID.Enumerator_ReachedEnd); } internal static Text.TextInterface.Factory Instance { ////// Critical - Exposes security critical _factory member. /// [SecurityCritical] get { return _factory; } } internal static Text.TextInterface.FontCollection SystemFontCollection { ////// Critical - provides access to the system fonts collection which exposes the windows fonts. /// [SecurityCritical] get { if (_systemFontCollection == null) { lock(_systemFontCollectionLock) { if (_systemFontCollection == null) { _systemFontCollection = DWriteFactory.Instance.GetSystemFontCollection(); } } } return _systemFontCollection; } } ////// Critical - Access security critical WindowsFontsUriObject object. /// - The caller of this method should own the verification of /// the access permissions to the given Uri. /// [SecurityCritical] private static Text.TextInterface.FontCollection GetFontCollectionFromFileOrFolder(Uri fontCollectionUri, bool isFolder) { if (Text.TextInterface.Factory.IsLocalUri(fontCollectionUri)) { string localPath; if (!isFolder) { // get the parent directory of the file. localPath = Directory.GetParent(fontCollectionUri.LocalPath).FullName + Path.DirectorySeparatorChar; } else { localPath = fontCollectionUri.LocalPath; } // If the directory specifed is the windows fonts directory then no need to reenumerate system fonts. if (String.Compare(((localPath.Length > 0 && localPath[localPath.Length - 1] != Path.DirectorySeparatorChar) ? localPath + Path.DirectorySeparatorChar : localPath), Util.WindowsFontsUriObject.LocalPath, StringComparison.OrdinalIgnoreCase) == 0) { return SystemFontCollection; } // Perf Descision: // Create a new FontCollection that has all the fonts in the directory. // The user will most likely use other fonts in a custom fonts directory. // A typical scenario is that a user will store all the fonts his/her App needs // in one directory. If we were not to follow this approach then we would create // a FontCollection for every font the user demands which may hurt performance. else { return DWriteFactory.Instance.GetFontCollection(new Uri(localPath)); } } // This isn't a local path so we create a FontCollection that only holds the desired font. // We follow a different approach here, as opposed to local files, where we only load the file // requested since file download and network latency cost becomes higher and loading all fonts // in a network path might hurt perf instead. return DWriteFactory.Instance.GetFontCollection(fontCollectionUri); } ////// Critical - calls security critical GetFontCollectionFromFileOrFolder. /// - The caller of this method should own the verification of /// the access permissions to the given Uri. /// [SecurityCritical] internal static Text.TextInterface.FontCollection GetFontCollectionFromFolder(Uri fontCollectionUri) { return GetFontCollectionFromFileOrFolder(fontCollectionUri, true); } ////// Critical - calls security critical GetFontCollectionFromFileOrFolder. /// - The caller of this method should own the verification of /// the access permissions to the given Uri. /// [SecurityCritical] internal static Text.TextInterface.FontCollection GetFontCollectionFromFile(Uri fontCollectionUri) { return GetFontCollectionFromFileOrFolder(fontCollectionUri, false); } ////// Critical - This is the DWrite factory that can be used to get everything about fonts. /// [SecurityCritical] private static Text.TextInterface.Factory _factory; private static Text.TextInterface.FontCollection _systemFontCollection = null; private static object _systemFontCollectionLock = new object(); } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // Description: The DWriteFactory class represents a shared DWrite factory // object. // // History: // 08/08/2008 : [....] - Integrating with DWrite. // //--------------------------------------------------------------------------- using System; using System.Security; using System.Security.Permissions; using System.IO; using System.Collections.Generic; using System.Text; using System.Diagnostics; using MS.Internal.PresentationCore; namespace MS.Internal.FontCache { internal static class DWriteFactory { ////// Critical - Access security critical Factory.Create method. /// Safe - The parameters passed to Factory.Create are internal /// types created by this method. /// [SecuritySafeCritical] static DWriteFactory() { _factory = Text.TextInterface.Factory.Create( Text.TextInterface.FactoryType.Shared, new FontSourceCollectionFactory(), new FontSourceFactory()); Text.TextInterface.LocalizedErrorMsgs.EnumeratorNotStarted = SR.Get(SRID.Enumerator_NotStarted); Text.TextInterface.LocalizedErrorMsgs.EnumeratorReachedEnd = SR.Get(SRID.Enumerator_ReachedEnd); } internal static Text.TextInterface.Factory Instance { ////// Critical - Exposes security critical _factory member. /// [SecurityCritical] get { return _factory; } } internal static Text.TextInterface.FontCollection SystemFontCollection { ////// Critical - provides access to the system fonts collection which exposes the windows fonts. /// [SecurityCritical] get { if (_systemFontCollection == null) { lock(_systemFontCollectionLock) { if (_systemFontCollection == null) { _systemFontCollection = DWriteFactory.Instance.GetSystemFontCollection(); } } } return _systemFontCollection; } } ////// Critical - Access security critical WindowsFontsUriObject object. /// - The caller of this method should own the verification of /// the access permissions to the given Uri. /// [SecurityCritical] private static Text.TextInterface.FontCollection GetFontCollectionFromFileOrFolder(Uri fontCollectionUri, bool isFolder) { if (Text.TextInterface.Factory.IsLocalUri(fontCollectionUri)) { string localPath; if (!isFolder) { // get the parent directory of the file. localPath = Directory.GetParent(fontCollectionUri.LocalPath).FullName + Path.DirectorySeparatorChar; } else { localPath = fontCollectionUri.LocalPath; } // If the directory specifed is the windows fonts directory then no need to reenumerate system fonts. if (String.Compare(((localPath.Length > 0 && localPath[localPath.Length - 1] != Path.DirectorySeparatorChar) ? localPath + Path.DirectorySeparatorChar : localPath), Util.WindowsFontsUriObject.LocalPath, StringComparison.OrdinalIgnoreCase) == 0) { return SystemFontCollection; } // Perf Descision: // Create a new FontCollection that has all the fonts in the directory. // The user will most likely use other fonts in a custom fonts directory. // A typical scenario is that a user will store all the fonts his/her App needs // in one directory. If we were not to follow this approach then we would create // a FontCollection for every font the user demands which may hurt performance. else { return DWriteFactory.Instance.GetFontCollection(new Uri(localPath)); } } // This isn't a local path so we create a FontCollection that only holds the desired font. // We follow a different approach here, as opposed to local files, where we only load the file // requested since file download and network latency cost becomes higher and loading all fonts // in a network path might hurt perf instead. return DWriteFactory.Instance.GetFontCollection(fontCollectionUri); } ////// Critical - calls security critical GetFontCollectionFromFileOrFolder. /// - The caller of this method should own the verification of /// the access permissions to the given Uri. /// [SecurityCritical] internal static Text.TextInterface.FontCollection GetFontCollectionFromFolder(Uri fontCollectionUri) { return GetFontCollectionFromFileOrFolder(fontCollectionUri, true); } ////// Critical - calls security critical GetFontCollectionFromFileOrFolder. /// - The caller of this method should own the verification of /// the access permissions to the given Uri. /// [SecurityCritical] internal static Text.TextInterface.FontCollection GetFontCollectionFromFile(Uri fontCollectionUri) { return GetFontCollectionFromFileOrFolder(fontCollectionUri, false); } ////// Critical - This is the DWrite factory that can be used to get everything about fonts. /// [SecurityCritical] private static Text.TextInterface.Factory _factory; private static Text.TextInterface.FontCollection _systemFontCollection = null; private static object _systemFontCollectionLock = new object(); } } // 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
- Mapping.cs
- CustomError.cs
- SerialPinChanges.cs
- XmlRawWriter.cs
- TextContainer.cs
- RegexBoyerMoore.cs
- SQLSingleStorage.cs
- ServerValidateEventArgs.cs
- LogArchiveSnapshot.cs
- SortDescription.cs
- WebBrowsableAttribute.cs
- SafeBitVector32.cs
- NotImplementedException.cs
- TransformGroup.cs
- TextParaClient.cs
- ThreadPool.cs
- BamlResourceContent.cs
- XmlArrayItemAttribute.cs
- InlineCategoriesDocument.cs
- ContainsRowNumberChecker.cs
- AbandonedMutexException.cs
- BaseValidator.cs
- WebPartExportVerb.cs
- DataColumnChangeEvent.cs
- MessagingDescriptionAttribute.cs
- XamlDesignerSerializationManager.cs
- AsyncOperationManager.cs
- ValidationError.cs
- PassportPrincipal.cs
- HMACSHA384.cs
- CalculatedColumn.cs
- SimpleMailWebEventProvider.cs
- SafeEventLogWriteHandle.cs
- FrameworkTextComposition.cs
- RecognizedAudio.cs
- DbParameterHelper.cs
- AnnotationResourceChangedEventArgs.cs
- UpDownBase.cs
- ReferenceEqualityComparer.cs
- FileCodeGroup.cs
- UnsafeNativeMethods.cs
- TraceHandlerErrorFormatter.cs
- ButtonBaseAdapter.cs
- GeneratedContractType.cs
- DefaultBinder.cs
- AncestorChangedEventArgs.cs
- DataRowView.cs
- TextClipboardData.cs
- MarginsConverter.cs
- _ListenerAsyncResult.cs
- Int64Converter.cs
- AdPostCacheSubstitution.cs
- UnsafeNativeMethods.cs
- ListViewTableCell.cs
- NonClientArea.cs
- CodeTryCatchFinallyStatement.cs
- BigInt.cs
- FontWeight.cs
- XamlTemplateSerializer.cs
- SafeFileMappingHandle.cs
- StringAnimationBase.cs
- SafeRightsManagementSessionHandle.cs
- ToolStripContentPanel.cs
- EpmCustomContentDeSerializer.cs
- CompiledIdentityConstraint.cs
- TreeView.cs
- Control.cs
- Message.cs
- JoinSymbol.cs
- TextSegment.cs
- SamlSecurityTokenAuthenticator.cs
- PersonalizableAttribute.cs
- SevenBitStream.cs
- UnknownWrapper.cs
- SafePEFileHandle.cs
- VirtualDirectoryMapping.cs
- VariableQuery.cs
- CompiledXpathExpr.cs
- MaterialGroup.cs
- DiscoveryService.cs
- TableRowsCollectionEditor.cs
- BitVector32.cs
- DataGridViewHitTestInfo.cs
- XPathNavigatorReader.cs
- KeyGestureConverter.cs
- RoleManagerModule.cs
- SoapTypeAttribute.cs
- DataPagerField.cs
- FontEmbeddingManager.cs
- XsltContext.cs
- COM2FontConverter.cs
- UpdatePanelControlTrigger.cs
- SizeAnimationBase.cs
- SettingsSavedEventArgs.cs
- AsyncPostBackErrorEventArgs.cs
- PropertyGridView.cs
- TablePattern.cs
- FolderLevelBuildProviderCollection.cs
- ZipPackagePart.cs
- ToolConsole.cs