Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / MS / Internal / FontFace / FontDifferentiator.cs / 1305600 / FontDifferentiator.cs
//---------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // Description: FontDifferentiator class handles parsing font family and face names // and adjusting stretch, weight and style values. // // History: // 11/10/2005 : mleonov - Started integration from a prototype application created by DBrown. // 1/21/2009 : [....] - removed unused code. // //--------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Globalization; using System.Text; using System.Windows; using System.Windows.Markup; // for XmlLanguage namespace MS.Internal.FontFace { ////// FontDifferentiator class handles parsing font family and face names /// and adjusting stretch, weight and style values. /// internal static class FontDifferentiator { internal static IDictionaryConstructFaceNamesByStyleWeightStretch( FontStyle style, FontWeight weight, FontStretch stretch) { string faceName = BuildFaceName(style, weight, stretch); // Default comparer calls CultureInfo.Equals, which works for our purposes. Dictionary faceNames = new Dictionary (1); faceNames.Add(XmlLanguage.GetLanguage("en-us"), faceName); return faceNames; } private static string BuildFaceName( FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch ) { string parsedStyleName = null; string parsedWeightName = null; string parsedStretchName = null; string regularFaceName = "Regular"; if (fontWeight != FontWeights.Normal) parsedWeightName = ((IFormattable)fontWeight).ToString(null, CultureInfo.InvariantCulture); if (fontStretch != FontStretches.Normal) parsedStretchName = ((IFormattable)fontStretch).ToString(null, CultureInfo.InvariantCulture); if (fontStyle != FontStyles.Normal) parsedStyleName = ((IFormattable)fontStyle).ToString(null, CultureInfo.InvariantCulture); // Build correct face string. // Set the initial capacity to be able to hold the word "Regular". StringBuilder faceNameBuilder = new StringBuilder(7); if (parsedStretchName != null) { faceNameBuilder.Append(parsedStretchName); } if (parsedWeightName != null) { if (faceNameBuilder.Length > 0) { faceNameBuilder.Append(" "); } faceNameBuilder.Append(parsedWeightName); } if (parsedStyleName != null) { if (faceNameBuilder.Length > 0) { faceNameBuilder.Append(" "); } faceNameBuilder.Append(parsedStyleName); } if (faceNameBuilder.Length == 0) { faceNameBuilder.Append(regularFaceName); } return faceNameBuilder.ToString(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // Description: FontDifferentiator class handles parsing font family and face names // and adjusting stretch, weight and style values. // // History: // 11/10/2005 : mleonov - Started integration from a prototype application created by DBrown. // 1/21/2009 : [....] - removed unused code. // //--------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Globalization; using System.Text; using System.Windows; using System.Windows.Markup; // for XmlLanguage namespace MS.Internal.FontFace { /// /// FontDifferentiator class handles parsing font family and face names /// and adjusting stretch, weight and style values. /// internal static class FontDifferentiator { internal static IDictionaryConstructFaceNamesByStyleWeightStretch( FontStyle style, FontWeight weight, FontStretch stretch) { string faceName = BuildFaceName(style, weight, stretch); // Default comparer calls CultureInfo.Equals, which works for our purposes. Dictionary faceNames = new Dictionary (1); faceNames.Add(XmlLanguage.GetLanguage("en-us"), faceName); return faceNames; } private static string BuildFaceName( FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch ) { string parsedStyleName = null; string parsedWeightName = null; string parsedStretchName = null; string regularFaceName = "Regular"; if (fontWeight != FontWeights.Normal) parsedWeightName = ((IFormattable)fontWeight).ToString(null, CultureInfo.InvariantCulture); if (fontStretch != FontStretches.Normal) parsedStretchName = ((IFormattable)fontStretch).ToString(null, CultureInfo.InvariantCulture); if (fontStyle != FontStyles.Normal) parsedStyleName = ((IFormattable)fontStyle).ToString(null, CultureInfo.InvariantCulture); // Build correct face string. // Set the initial capacity to be able to hold the word "Regular". StringBuilder faceNameBuilder = new StringBuilder(7); if (parsedStretchName != null) { faceNameBuilder.Append(parsedStretchName); } if (parsedWeightName != null) { if (faceNameBuilder.Length > 0) { faceNameBuilder.Append(" "); } faceNameBuilder.Append(parsedWeightName); } if (parsedStyleName != null) { if (faceNameBuilder.Length > 0) { faceNameBuilder.Append(" "); } faceNameBuilder.Append(parsedStyleName); } if (faceNameBuilder.Length == 0) { faceNameBuilder.Append(regularFaceName); } return faceNameBuilder.ToString(); } } } // 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
- MarkerProperties.cs
- ToolStripButton.cs
- AsymmetricKeyExchangeFormatter.cs
- ThicknessAnimation.cs
- CodeIdentifiers.cs
- XmlDocument.cs
- EventMappingSettingsCollection.cs
- ActionItem.cs
- ByteStreamGeometryContext.cs
- WinCategoryAttribute.cs
- BrowserPolicyValidator.cs
- HuffModule.cs
- PassportAuthenticationModule.cs
- HtmlTableCellCollection.cs
- PrimitiveXmlSerializers.cs
- GlyphTypeface.cs
- EntityDataSourceQueryBuilder.cs
- ControlUtil.cs
- FontWeightConverter.cs
- MultiAsyncResult.cs
- PostBackTrigger.cs
- XmlTypeMapping.cs
- XmlDictionaryReaderQuotas.cs
- OracleException.cs
- CFStream.cs
- AttachInfo.cs
- QilNode.cs
- AssemblyBuilder.cs
- ItemContainerGenerator.cs
- SpanIndex.cs
- MemberCollection.cs
- PropertyDescriptor.cs
- DispatchOperation.cs
- ToolStripArrowRenderEventArgs.cs
- GeometryCollection.cs
- FrameworkName.cs
- XhtmlBasicImageAdapter.cs
- GrammarBuilderPhrase.cs
- FixedStringLookup.cs
- errorpatternmatcher.cs
- MetadataItem_Static.cs
- indexingfiltermarshaler.cs
- PackageFilter.cs
- NativeMethods.cs
- SerializerWriterEventHandlers.cs
- SessionSwitchEventArgs.cs
- OdbcConnectionPoolProviderInfo.cs
- CompositeActivityMarkupSerializer.cs
- GlobalAllocSafeHandle.cs
- ListBox.cs
- HttpCachePolicyWrapper.cs
- HttpModulesSection.cs
- ObjectList.cs
- DATA_BLOB.cs
- PropertyNames.cs
- ActivationServices.cs
- SingleStorage.cs
- XmlSerializer.cs
- TextEditorParagraphs.cs
- FormViewPageEventArgs.cs
- TransformerInfo.cs
- DataPagerCommandEventArgs.cs
- TextBreakpoint.cs
- ExceptionUtil.cs
- CheckBoxBaseAdapter.cs
- userdatakeys.cs
- AssemblyInfo.cs
- ExchangeUtilities.cs
- XmlAttribute.cs
- BuildManager.cs
- SerialPinChanges.cs
- ManipulationInertiaStartingEventArgs.cs
- BindingOperations.cs
- SQLBytesStorage.cs
- ThicknessKeyFrameCollection.cs
- LZCodec.cs
- ApplicationTrust.cs
- ClientBuildManagerCallback.cs
- SamlAuthenticationStatement.cs
- TableChangeProcessor.cs
- DynamicILGenerator.cs
- OdbcCommandBuilder.cs
- InstanceHandleConflictException.cs
- RunInstallerAttribute.cs
- MetadataUtilsSmi.cs
- FontDialog.cs
- RequestStatusBarUpdateEventArgs.cs
- CodeCastExpression.cs
- DictionaryManager.cs
- DaylightTime.cs
- XmlUnspecifiedAttribute.cs
- ProgressBar.cs
- WindowsListViewGroup.cs
- ThreadStartException.cs
- SynchronizationLockException.cs
- OdbcCommandBuilder.cs
- HashCoreRequest.cs
- SqlNode.cs
- FontResourceCache.cs
- TimeSpanMinutesConverter.cs