Code:
/ 4.0 / 4.0 / untmp / 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 IDictionary ConstructFaceNamesByStyleWeightStretch(
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
- AppDomain.cs
- DoubleConverter.cs
- DataGridViewCheckBoxColumn.cs
- ClientTarget.cs
- DataSysAttribute.cs
- GridViewColumn.cs
- ObjectItemLoadingSessionData.cs
- Size.cs
- FontUnitConverter.cs
- TreeViewDataItemAutomationPeer.cs
- SmiEventSink.cs
- TabItem.cs
- DataGridTable.cs
- XmlSerializerFactory.cs
- Int32Converter.cs
- QueryCacheManager.cs
- HttpAsyncResult.cs
- input.cs
- Viewport2DVisual3D.cs
- DataGridViewRowConverter.cs
- ConnectionPoint.cs
- Button.cs
- DetailsViewPageEventArgs.cs
- TextCharacters.cs
- TreeViewTemplateSelector.cs
- SystemSounds.cs
- ChildrenQuery.cs
- MatrixAnimationBase.cs
- XmlResolver.cs
- RuntimeVariablesExpression.cs
- WorkflowDesigner.cs
- PreloadedPackages.cs
- webclient.cs
- DesignerActionVerbItem.cs
- MatrixCamera.cs
- DES.cs
- XmlSerializationGeneratedCode.cs
- ExclusiveNamedPipeTransportManager.cs
- EventHandlerList.cs
- OleDbInfoMessageEvent.cs
- XmlSchemaChoice.cs
- Label.cs
- prefixendpointaddressmessagefilter.cs
- LinqToSqlWrapper.cs
- FrameworkName.cs
- HttpResponseInternalWrapper.cs
- Rss20FeedFormatter.cs
- HexParser.cs
- RTTrackingProfile.cs
- WpfGeneratedKnownTypes.cs
- XPathEmptyIterator.cs
- AutoResetEvent.cs
- CacheSection.cs
- RootDesignerSerializerAttribute.cs
- keycontainerpermission.cs
- ViewRendering.cs
- Metadata.cs
- AlternateViewCollection.cs
- BooleanConverter.cs
- PackageDigitalSignatureManager.cs
- CompositeActivityValidator.cs
- TransformerTypeCollection.cs
- PresentationTraceSources.cs
- ProxyElement.cs
- MembershipAdapter.cs
- SymDocumentType.cs
- RTLAwareMessageBox.cs
- MembershipValidatePasswordEventArgs.cs
- XMLSchema.cs
- NetDataContractSerializer.cs
- cookieexception.cs
- XPathDocumentNavigator.cs
- XmlSerializationReader.cs
- ContextInformation.cs
- CharacterBuffer.cs
- SoapDocumentServiceAttribute.cs
- ConfigXmlWhitespace.cs
- PointCollection.cs
- RelationshipEndCollection.cs
- HttpCapabilitiesBase.cs
- SoapMessage.cs
- SystemGatewayIPAddressInformation.cs
- MissingMethodException.cs
- TextCharacters.cs
- WrappedIUnknown.cs
- ConversionContext.cs
- DefaultAsyncDataDispatcher.cs
- AddressingProperty.cs
- InternalReceiveMessage.cs
- KeyValuePair.cs
- PropertyGeneratedEventArgs.cs
- DataGridRow.cs
- XPathDocumentBuilder.cs
- ExceptionRoutedEventArgs.cs
- XmlSchemaNotation.cs
- MultiPageTextView.cs
- BitmapEffect.cs
- BasePropertyDescriptor.cs
- MessageBox.cs
- SpinLock.cs