Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / MS / Internal / FontFace / TypefaceCollection.cs / 1305600 / TypefaceCollection.cs
//------------------------------------------------------------------------ // // Microsoft Windows Client Platform // Copyright (C) Microsoft Corporation, 2002 // // File: TypefaceCollection.cs // // Contents: Collection of typefaces // // Created: 5-15-2003 Michael Leonov (mleonov) // //----------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Windows; using System.Windows.Media; using MS.Internal.FontCache; using System.Globalization; using System.Security; using SR = MS.Internal.PresentationCore.SR; using SRID = MS.Internal.PresentationCore.SRID; namespace MS.Internal.FontFace { internal unsafe struct TypefaceCollection : ICollection{ private FontFamily _fontFamily; // setting _family and _familyTypefaceCollection are mutually exclusive. private Text.TextInterface.FontFamily _family; private FamilyTypefaceCollection _familyTypefaceCollection; public TypefaceCollection(FontFamily fontFamily, Text.TextInterface.FontFamily family) { _fontFamily = fontFamily; _family = family; _familyTypefaceCollection = null; } public TypefaceCollection(FontFamily fontFamily, FamilyTypefaceCollection familyTypefaceCollection) { _fontFamily = fontFamily; _familyTypefaceCollection = familyTypefaceCollection; _family = null; } #region ICollection Members public void Add(Typeface item) { throw new NotSupportedException(); } public void Clear() { throw new NotSupportedException(); } public bool Contains(Typeface item) { foreach (Typeface t in this) { if (t.Equals(item)) return true; } return false; } public void CopyTo(Typeface[] array, int arrayIndex) { if (array == null) { throw new ArgumentNullException("array"); } if (array.Rank != 1) { throw new ArgumentException(SR.Get(SRID.Collection_BadRank)); } // The extra "arrayIndex >= array.Length" check in because even if _collection.Count // is 0 the index is not allowed to be equal or greater than the length // (from the MSDN ICollection docs) if (arrayIndex < 0 || arrayIndex >= array.Length || (arrayIndex + Count) > array.Length) { throw new ArgumentOutOfRangeException("arrayIndex"); } foreach (Typeface t in this) { array[arrayIndex++] = t; } } public int Count { /// /// Critical - calls into critical Text.TextInterface.FontFamily property /// TreatAsSafe - Count is safe to expose /// [SecurityCritical, SecurityTreatAsSafe] get { Debug.Assert((_family != null && _familyTypefaceCollection == null)|| (_familyTypefaceCollection != null && _family == null)); if (_family != null) { return checked((int)_family.Count); } else { return _familyTypefaceCollection.Count; } } } public bool IsReadOnly { get { return true; } } public bool Remove(Typeface item) { throw new NotSupportedException(); } #endregion #region IEnumerableMembers public IEnumerator GetEnumerator() { return new Enumerator(this); } #endregion #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return new Enumerator(this); } #endregion private struct Enumerator : IEnumerator { public Enumerator(TypefaceCollection typefaceCollection) { _typefaceCollection = typefaceCollection; Debug.Assert((typefaceCollection._family != null && typefaceCollection._familyTypefaceCollection == null) || (typefaceCollection._familyTypefaceCollection != null && typefaceCollection._family == null)); if (typefaceCollection._family != null) { _familyEnumerator = ((IEnumerable )typefaceCollection._family).GetEnumerator(); _familyTypefaceEnumerator = null; } else { _familyTypefaceEnumerator = ((IEnumerable )typefaceCollection._familyTypefaceCollection).GetEnumerator(); _familyEnumerator = null; } } #region IEnumerator Members public Typeface Current { /// /// Critical - calls into critical Text.TextInterface.Font properties /// TreatAsSafe - data used to initialize the new Typeface is safe to expose /// [SecurityCritical, SecurityTreatAsSafe] get { if (_typefaceCollection._family != null) { Text.TextInterface.Font face = _familyEnumerator.Current; return new Typeface(_typefaceCollection._fontFamily, new FontStyle((int)face.Style), new FontWeight((int)face.Weight), new FontStretch((int)face.Stretch)); } else { FamilyTypeface familyTypeface = _familyTypefaceEnumerator.Current; return new Typeface(_typefaceCollection._fontFamily, familyTypeface.Style, familyTypeface.Weight, familyTypeface.Stretch); } } } #endregion #region IDisposable Members public void Dispose() {} #endregion #region IEnumerator Members object System.Collections.IEnumerator.Current { get { return ((IEnumerator)this).Current; } } public bool MoveNext() { if (_familyEnumerator != null) { return _familyEnumerator.MoveNext(); } else { return _familyTypefaceEnumerator.MoveNext(); } } public void Reset() { if (_typefaceCollection._family != null) { _familyEnumerator = ((IEnumerable )_typefaceCollection._family).GetEnumerator(); _familyTypefaceEnumerator = null; } else { _familyTypefaceEnumerator = ((IEnumerable )_typefaceCollection._familyTypefaceCollection).GetEnumerator(); _familyEnumerator = null; } } #endregion // setting _familyEnumerator and _familyTypefaceEnumerator are mutually exclusive. private IEnumerator _familyEnumerator; private IEnumerator _familyTypefaceEnumerator; private TypefaceCollection _typefaceCollection; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------ // // Microsoft Windows Client Platform // Copyright (C) Microsoft Corporation, 2002 // // File: TypefaceCollection.cs // // Contents: Collection of typefaces // // Created: 5-15-2003 Michael Leonov (mleonov) // //----------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Windows; using System.Windows.Media; using MS.Internal.FontCache; using System.Globalization; using System.Security; using SR = MS.Internal.PresentationCore.SR; using SRID = MS.Internal.PresentationCore.SRID; namespace MS.Internal.FontFace { internal unsafe struct TypefaceCollection : ICollection { private FontFamily _fontFamily; // setting _family and _familyTypefaceCollection are mutually exclusive. private Text.TextInterface.FontFamily _family; private FamilyTypefaceCollection _familyTypefaceCollection; public TypefaceCollection(FontFamily fontFamily, Text.TextInterface.FontFamily family) { _fontFamily = fontFamily; _family = family; _familyTypefaceCollection = null; } public TypefaceCollection(FontFamily fontFamily, FamilyTypefaceCollection familyTypefaceCollection) { _fontFamily = fontFamily; _familyTypefaceCollection = familyTypefaceCollection; _family = null; } #region ICollection Members public void Add(Typeface item) { throw new NotSupportedException(); } public void Clear() { throw new NotSupportedException(); } public bool Contains(Typeface item) { foreach (Typeface t in this) { if (t.Equals(item)) return true; } return false; } public void CopyTo(Typeface[] array, int arrayIndex) { if (array == null) { throw new ArgumentNullException("array"); } if (array.Rank != 1) { throw new ArgumentException(SR.Get(SRID.Collection_BadRank)); } // The extra "arrayIndex >= array.Length" check in because even if _collection.Count // is 0 the index is not allowed to be equal or greater than the length // (from the MSDN ICollection docs) if (arrayIndex < 0 || arrayIndex >= array.Length || (arrayIndex + Count) > array.Length) { throw new ArgumentOutOfRangeException("arrayIndex"); } foreach (Typeface t in this) { array[arrayIndex++] = t; } } public int Count { /// /// Critical - calls into critical Text.TextInterface.FontFamily property /// TreatAsSafe - Count is safe to expose /// [SecurityCritical, SecurityTreatAsSafe] get { Debug.Assert((_family != null && _familyTypefaceCollection == null)|| (_familyTypefaceCollection != null && _family == null)); if (_family != null) { return checked((int)_family.Count); } else { return _familyTypefaceCollection.Count; } } } public bool IsReadOnly { get { return true; } } public bool Remove(Typeface item) { throw new NotSupportedException(); } #endregion #region IEnumerableMembers public IEnumerator GetEnumerator() { return new Enumerator(this); } #endregion #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return new Enumerator(this); } #endregion private struct Enumerator : IEnumerator { public Enumerator(TypefaceCollection typefaceCollection) { _typefaceCollection = typefaceCollection; Debug.Assert((typefaceCollection._family != null && typefaceCollection._familyTypefaceCollection == null) || (typefaceCollection._familyTypefaceCollection != null && typefaceCollection._family == null)); if (typefaceCollection._family != null) { _familyEnumerator = ((IEnumerable )typefaceCollection._family).GetEnumerator(); _familyTypefaceEnumerator = null; } else { _familyTypefaceEnumerator = ((IEnumerable )typefaceCollection._familyTypefaceCollection).GetEnumerator(); _familyEnumerator = null; } } #region IEnumerator Members public Typeface Current { /// /// Critical - calls into critical Text.TextInterface.Font properties /// TreatAsSafe - data used to initialize the new Typeface is safe to expose /// [SecurityCritical, SecurityTreatAsSafe] get { if (_typefaceCollection._family != null) { Text.TextInterface.Font face = _familyEnumerator.Current; return new Typeface(_typefaceCollection._fontFamily, new FontStyle((int)face.Style), new FontWeight((int)face.Weight), new FontStretch((int)face.Stretch)); } else { FamilyTypeface familyTypeface = _familyTypefaceEnumerator.Current; return new Typeface(_typefaceCollection._fontFamily, familyTypeface.Style, familyTypeface.Weight, familyTypeface.Stretch); } } } #endregion #region IDisposable Members public void Dispose() {} #endregion #region IEnumerator Members object System.Collections.IEnumerator.Current { get { return ((IEnumerator)this).Current; } } public bool MoveNext() { if (_familyEnumerator != null) { return _familyEnumerator.MoveNext(); } else { return _familyTypefaceEnumerator.MoveNext(); } } public void Reset() { if (_typefaceCollection._family != null) { _familyEnumerator = ((IEnumerable )_typefaceCollection._family).GetEnumerator(); _familyTypefaceEnumerator = null; } else { _familyTypefaceEnumerator = ((IEnumerable )_typefaceCollection._familyTypefaceCollection).GetEnumerator(); _familyEnumerator = null; } } #endregion // setting _familyEnumerator and _familyTypefaceEnumerator are mutually exclusive. private IEnumerator _familyEnumerator; private IEnumerator _familyTypefaceEnumerator; private TypefaceCollection _typefaceCollection; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Shape.cs
- SslStream.cs
- ClientSponsor.cs
- AppDomainInfo.cs
- XmlSchemaInferenceException.cs
- DESCryptoServiceProvider.cs
- NameValueCollection.cs
- AttributeCollection.cs
- OuterGlowBitmapEffect.cs
- BrowserCapabilitiesCodeGenerator.cs
- PresentationSource.cs
- ConfigurationFileMap.cs
- BindingOperations.cs
- MenuItemBinding.cs
- CngKey.cs
- SafeRightsManagementQueryHandle.cs
- PropertyDescriptorComparer.cs
- PropertyIDSet.cs
- ScriptReferenceBase.cs
- ApplicationProxyInternal.cs
- PointLightBase.cs
- UInt64Converter.cs
- MessageQueueEnumerator.cs
- DataGridViewCellStateChangedEventArgs.cs
- MsiStyleLogWriter.cs
- XsdBuilder.cs
- UshortList2.cs
- ReferencedType.cs
- ThousandthOfEmRealDoubles.cs
- HtmlTitle.cs
- HttpHandlersSection.cs
- HMACMD5.cs
- OdbcReferenceCollection.cs
- HttpHandlerAction.cs
- MethodRental.cs
- ZipArchive.cs
- WizardStepBase.cs
- XmlJsonReader.cs
- EditingMode.cs
- Geometry.cs
- SecurityVersion.cs
- BinaryConverter.cs
- RegionInfo.cs
- UrlMappingCollection.cs
- GroupBoxAutomationPeer.cs
- StreamWithDictionary.cs
- CallInfo.cs
- LinearKeyFrames.cs
- ResourcePermissionBaseEntry.cs
- GeometryModel3D.cs
- compensatingcollection.cs
- HttpTransportManager.cs
- AlphaSortedEnumConverter.cs
- OptimizerPatterns.cs
- InkCanvasFeedbackAdorner.cs
- GestureRecognizer.cs
- DesignBindingConverter.cs
- NamespaceEmitter.cs
- XmlSchemaSimpleContentExtension.cs
- WindowsComboBox.cs
- UnsafeNativeMethods.cs
- CFGGrammar.cs
- CategoryAttribute.cs
- WmiPutTraceRecord.cs
- ToolStripDesignerAvailabilityAttribute.cs
- UntypedNullExpression.cs
- LayoutInformation.cs
- ModelTreeEnumerator.cs
- SchemaInfo.cs
- UIElementCollection.cs
- ErrorWebPart.cs
- CatalogZoneDesigner.cs
- PersonalizationProvider.cs
- ExpressionBuilder.cs
- CommandEventArgs.cs
- GroupedContextMenuStrip.cs
- XPathItem.cs
- StringSorter.cs
- DebugView.cs
- ValidatedControlConverter.cs
- Mouse.cs
- ChannelSinkStacks.cs
- HtmlInputButton.cs
- ReflectTypeDescriptionProvider.cs
- MetadataArtifactLoaderCompositeFile.cs
- RemotingServices.cs
- PatternMatcher.cs
- TimerElapsedEvenArgs.cs
- ZoneLinkButton.cs
- WebPartConnectionsCancelEventArgs.cs
- FormsAuthentication.cs
- ButtonBaseAutomationPeer.cs
- CompressedStack.cs
- SourceInterpreter.cs
- Section.cs
- CodeDomConfigurationHandler.cs
- PerformanceCounterCategory.cs
- MenuItemStyleCollection.cs
- HTTPNotFoundHandler.cs
- FieldDescriptor.cs