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 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.
//----------------------------------------------------------------------------
//
// 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
- GeneralTransform.cs
- ParserExtension.cs
- AgileSafeNativeMemoryHandle.cs
- BaseDataListPage.cs
- ResourceDescriptionAttribute.cs
- JoinGraph.cs
- CapabilitiesAssignment.cs
- DesignerCalendarAdapter.cs
- sqlinternaltransaction.cs
- CompiledQuery.cs
- FormViewInsertEventArgs.cs
- ActivityMarkupSerializer.cs
- Properties.cs
- xdrvalidator.cs
- ElementAtQueryOperator.cs
- QilExpression.cs
- OSEnvironmentHelper.cs
- DataObjectCopyingEventArgs.cs
- Crc32.cs
- ModuleBuilder.cs
- InvalidFilterCriteriaException.cs
- SecurityElement.cs
- ScaleTransform.cs
- DataSourceSelectArguments.cs
- ProfilePropertySettingsCollection.cs
- HtmlMeta.cs
- CodeComment.cs
- SecurityRequiresReviewAttribute.cs
- CodeDirectoryCompiler.cs
- InfoCardSymmetricAlgorithm.cs
- XmlAttributes.cs
- ControlCollection.cs
- _CommandStream.cs
- GregorianCalendar.cs
- DataBoundLiteralControl.cs
- DefaultHttpHandler.cs
- Int32AnimationUsingKeyFrames.cs
- XmlSerializationGeneratedCode.cs
- GridViewSortEventArgs.cs
- ColumnClickEvent.cs
- FileLoadException.cs
- SetterBaseCollection.cs
- _ShellExpression.cs
- Visual.cs
- ZoneButton.cs
- StrokeNodeOperations.cs
- Filter.cs
- Cursors.cs
- VisualProxy.cs
- ToolTip.cs
- Int32Animation.cs
- ListContractAdapter.cs
- CheckBoxField.cs
- OleServicesContext.cs
- DispatcherBuilder.cs
- _NestedSingleAsyncResult.cs
- LineServices.cs
- ThreadAbortException.cs
- Utils.cs
- AssemblyNameUtility.cs
- MergeLocalizationDirectives.cs
- SchemaTableColumn.cs
- BuildDependencySet.cs
- DataRecordInternal.cs
- DataBoundLiteralControl.cs
- HeaderLabel.cs
- __FastResourceComparer.cs
- XmlNodeChangedEventArgs.cs
- XpsPartBase.cs
- LoggedException.cs
- PropertySourceInfo.cs
- OLEDB_Enum.cs
- EnumerableRowCollection.cs
- Privilege.cs
- DataGridColumnReorderingEventArgs.cs
- XmlnsDictionary.cs
- HostingEnvironmentException.cs
- ProfileManager.cs
- MarginCollapsingState.cs
- LoginCancelEventArgs.cs
- ColorAnimationBase.cs
- SqlGatherProducedAliases.cs
- PeerCollaborationPermission.cs
- WebPartConnectionsCancelVerb.cs
- DrawingVisual.cs
- QueryOperationResponseOfT.cs
- SqlInfoMessageEvent.cs
- WebPartZoneCollection.cs
- propertyentry.cs
- ReflectionUtil.cs
- XmlDocumentSerializer.cs
- ExecutionContext.cs
- localization.cs
- XamlSerializationHelper.cs
- DesignerActionListCollection.cs
- ParentQuery.cs
- WmpBitmapDecoder.cs
- DbParameterHelper.cs
- Parallel.cs
- CompositeDataBoundControl.cs