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
- UrlEncodedParameterWriter.cs
- RoleManagerModule.cs
- ComponentGuaranteesAttribute.cs
- LinkLabel.cs
- DocumentViewerBase.cs
- ChameleonKey.cs
- PluralizationService.cs
- WSFederationHttpBindingCollectionElement.cs
- SafeWaitHandle.cs
- XPathSelfQuery.cs
- TabPanel.cs
- PrivilegeNotHeldException.cs
- DefaultClaimSet.cs
- ParserExtension.cs
- SAPIEngineTypes.cs
- HandleCollector.cs
- Pens.cs
- UserInitiatedNavigationPermission.cs
- TypeSystem.cs
- BamlResourceContent.cs
- ManifestSignedXml.cs
- CodeArrayCreateExpression.cs
- PixelFormat.cs
- NameObjectCollectionBase.cs
- AttributeProviderAttribute.cs
- XPathMultyIterator.cs
- ConnectionStringEditor.cs
- BinaryConverter.cs
- Vector3DCollectionConverter.cs
- CellTreeNodeVisitors.cs
- DrawToolTipEventArgs.cs
- CustomGrammar.cs
- OdbcCommand.cs
- ConfigurationCollectionAttribute.cs
- Tokenizer.cs
- SafeTimerHandle.cs
- QilCloneVisitor.cs
- TypeToken.cs
- XmlSchemaSimpleTypeList.cs
- DSGeneratorProblem.cs
- UICuesEvent.cs
- BooleanExpr.cs
- NamespaceCollection.cs
- CodeExpressionStatement.cs
- RegexInterpreter.cs
- LinqDataSourceView.cs
- SecurityKeyType.cs
- ProxyWebPartConnectionCollection.cs
- ContentPropertyAttribute.cs
- Shared.cs
- ToolStripItemRenderEventArgs.cs
- _SSPISessionCache.cs
- RMEnrollmentPage1.cs
- DoubleCollectionValueSerializer.cs
- DockPatternIdentifiers.cs
- CompensatableTransactionScopeActivity.cs
- OperationResponse.cs
- StickyNoteHelper.cs
- WindowsStatic.cs
- HyperLinkDataBindingHandler.cs
- CompiledXpathExpr.cs
- InstanceOwnerQueryResult.cs
- AppSecurityManager.cs
- FacetValues.cs
- ClientRoleProvider.cs
- QuaternionAnimation.cs
- MultiPropertyDescriptorGridEntry.cs
- AccessDataSourceView.cs
- ImageAttributes.cs
- BamlReader.cs
- HttpRequest.cs
- SqlColumnizer.cs
- InstalledVoice.cs
- DataControlCommands.cs
- Preprocessor.cs
- TreeNodeCollection.cs
- RemotingException.cs
- LocalizabilityAttribute.cs
- AvtEvent.cs
- PrintPageEvent.cs
- EmptyEnumerator.cs
- DeviceContexts.cs
- EventLog.cs
- Version.cs
- EnumConverter.cs
- InfoCardClaimCollection.cs
- ImportCatalogPart.cs
- CustomErrorCollection.cs
- DBDataPermission.cs
- ContentFileHelper.cs
- FormsAuthenticationUserCollection.cs
- Mappings.cs
- XmlSchemaValidator.cs
- BitHelper.cs
- ArrangedElementCollection.cs
- RankException.cs
- SqlConnectionPoolGroupProviderInfo.cs
- BooleanConverter.cs
- DataGridViewBindingCompleteEventArgs.cs
- ControlCommandSet.cs