Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / System / Windows / FontWeight.cs / 1305600 / FontWeight.cs
//----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Description: FontWeight structure.
//
// History:
// 01/25/2005 mleonov - Converted FontWeight from enum to a value type and moved it to a separate file.
//
//---------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Diagnostics;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
namespace System.Windows
{
///
/// FontWeight structure describes the degree of blackness or thickness of strokes of characters in a font.
///
[TypeConverter(typeof(FontWeightConverter))]
[Localizability(LocalizationCategory.None)]
public struct FontWeight : IFormattable
{
internal FontWeight(int weight)
{
Debug.Assert(1 <= weight && weight <= 999);
// We want the default zero value of new FontWeight() to correspond to FontWeights.Normal.
// Therefore, the _weight value is shifted by 400 relative to the OpenType weight value.
_weight = weight - 400;
}
///
/// Creates a new FontWeight object that corresponds to the OpenType usWeightClass value.
///
/// An integer value between 1 and 999 that corresponds
/// to the usWeightClass definition in the OpenType specification.
/// A new FontWeight object that corresponds to the weightValue parameter.
// Important note: when changing this method signature please make sure to update FontWeightConverter accordingly.
public static FontWeight FromOpenTypeWeight(int weightValue)
{
if (weightValue < 1 || weightValue > 999)
throw new ArgumentOutOfRangeException("weightValue", SR.Get(SRID.ParameterMustBeBetween, 1, 999));
return new FontWeight(weightValue);
}
///
/// Obtains OpenType usWeightClass value that corresponds to the FontWeight object.
///
/// An integer value between 1 and 999 that corresponds
/// to the usWeightClass definition in the OpenType specification.
// Important note: when changing this method signature please make sure to update FontWeightConverter accordingly.
public int ToOpenTypeWeight()
{
return RealWeight;
}
///
/// Compares two font weight values and returns an indication of their relative values.
///
/// First object to compare.
/// Second object to compare.
/// A 32-bit signed integer indicating the lexical relationship between the two comparands.
/// When the return value is less than zero this means that left is less than right.
/// When the return value is zero this means that left is equal to right.
/// When the return value is greater than zero this means that left is greater than right.
///
public static int Compare(FontWeight left, FontWeight right)
{
return left._weight - right._weight;
}
///
/// Checks whether a font weight is less than another.
///
/// First object to compare.
/// Second object to compare.
/// True if left is less than right, false otherwise.
public static bool operator<(FontWeight left, FontWeight right)
{
return Compare(left, right) < 0;
}
///
/// Checks whether a font weight is less or equal than another.
///
/// First object to compare.
/// Second object to compare.
/// True if left is less or equal than right, false otherwise.
public static bool operator<=(FontWeight left, FontWeight right)
{
return Compare(left, right) <= 0;
}
///
/// Checks whether a font weight is greater than another.
///
/// First object to compare.
/// Second object to compare.
/// True if left is greater than right, false otherwise.
public static bool operator>(FontWeight left, FontWeight right)
{
return Compare(left, right) > 0;
}
///
/// Checks whether a font weight is greater or equal than another.
///
/// First object to compare.
/// Second object to compare.
/// True if left is greater or equal than right, false otherwise.
public static bool operator>=(FontWeight left, FontWeight right)
{
return Compare(left, right) >= 0;
}
///
/// Checks whether two font weight objects are equal.
///
/// First object to compare.
/// Second object to compare.
/// Returns true when the font weight values are equal for both objects,
/// and false otherwise.
public static bool operator==(FontWeight left, FontWeight right)
{
return Compare(left, right) == 0;
}
///
/// Checks whether two font weight objects are not equal.
///
/// First object to compare.
/// Second object to compare.
/// Returns false when the font weight values are equal for both objects,
/// and true otherwise.
public static bool operator!=(FontWeight left, FontWeight right)
{
return !(left == right);
}
///
/// Checks whether the object is equal to another FontWeight object.
///
/// FontWeight object to compare with.
/// Returns true when the object is equal to the input object,
/// and false otherwise.
public bool Equals(FontWeight obj)
{
return this == obj;
}
///
/// Checks whether an object is equal to another character hit object.
///
/// FontWeight object to compare with.
/// Returns true when the object is equal to the input object,
/// and false otherwise.
public override bool Equals(object obj)
{
if (!(obj is FontWeight))
return false;
return this == (FontWeight)obj;
}
///
/// Compute hash code for this object.
///
/// A 32-bit signed integer hash code.
public override int GetHashCode()
{
return RealWeight;
}
///
/// Creates a string representation of this object based on the current culture.
///
///
/// A string representation of this object.
///
public override string ToString()
{
// Delegate to the internal method which implements all ToString calls.
return ConvertToString(null, null);
}
///
/// Creates a string representation of this object based on the format string
/// and IFormatProvider passed in.
/// If the provider is null, the CurrentCulture is used.
/// See the documentation for IFormattable for more information.
///
///
/// A string representation of this object.
///
string IFormattable.ToString(string format, IFormatProvider provider)
{
// Delegate to the internal method which implements all ToString calls.
return ConvertToString(format, provider);
}
///
/// Creates a string representation of this object based on the format string
/// and IFormatProvider passed in.
/// If the provider is null, the CurrentCulture is used.
/// See the documentation for IFormattable for more information.
///
///
/// A string representation of this object.
///
private string ConvertToString(string format, IFormatProvider provider)
{
string convertedValue;
if (!FontWeights.FontWeightToString(RealWeight, out convertedValue))
{
// This can happen if _weight value is not a multiple of 100.
return RealWeight.ToString(provider);
}
return convertedValue;
}
///
/// We want the default zero value of new FontWeight() to correspond to FontWeights.Normal.
/// Therefore, _weight value is shifted by 400 relative to the OpenType weight value.
///
private int RealWeight
{
get
{
return _weight + 400;
}
}
private int _weight;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Description: FontWeight structure.
//
// History:
// 01/25/2005 mleonov - Converted FontWeight from enum to a value type and moved it to a separate file.
//
//---------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Diagnostics;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
namespace System.Windows
{
///
/// FontWeight structure describes the degree of blackness or thickness of strokes of characters in a font.
///
[TypeConverter(typeof(FontWeightConverter))]
[Localizability(LocalizationCategory.None)]
public struct FontWeight : IFormattable
{
internal FontWeight(int weight)
{
Debug.Assert(1 <= weight && weight <= 999);
// We want the default zero value of new FontWeight() to correspond to FontWeights.Normal.
// Therefore, the _weight value is shifted by 400 relative to the OpenType weight value.
_weight = weight - 400;
}
///
/// Creates a new FontWeight object that corresponds to the OpenType usWeightClass value.
///
/// An integer value between 1 and 999 that corresponds
/// to the usWeightClass definition in the OpenType specification.
/// A new FontWeight object that corresponds to the weightValue parameter.
// Important note: when changing this method signature please make sure to update FontWeightConverter accordingly.
public static FontWeight FromOpenTypeWeight(int weightValue)
{
if (weightValue < 1 || weightValue > 999)
throw new ArgumentOutOfRangeException("weightValue", SR.Get(SRID.ParameterMustBeBetween, 1, 999));
return new FontWeight(weightValue);
}
///
/// Obtains OpenType usWeightClass value that corresponds to the FontWeight object.
///
/// An integer value between 1 and 999 that corresponds
/// to the usWeightClass definition in the OpenType specification.
// Important note: when changing this method signature please make sure to update FontWeightConverter accordingly.
public int ToOpenTypeWeight()
{
return RealWeight;
}
///
/// Compares two font weight values and returns an indication of their relative values.
///
/// First object to compare.
/// Second object to compare.
/// A 32-bit signed integer indicating the lexical relationship between the two comparands.
/// When the return value is less than zero this means that left is less than right.
/// When the return value is zero this means that left is equal to right.
/// When the return value is greater than zero this means that left is greater than right.
///
public static int Compare(FontWeight left, FontWeight right)
{
return left._weight - right._weight;
}
///
/// Checks whether a font weight is less than another.
///
/// First object to compare.
/// Second object to compare.
/// True if left is less than right, false otherwise.
public static bool operator<(FontWeight left, FontWeight right)
{
return Compare(left, right) < 0;
}
///
/// Checks whether a font weight is less or equal than another.
///
/// First object to compare.
/// Second object to compare.
/// True if left is less or equal than right, false otherwise.
public static bool operator<=(FontWeight left, FontWeight right)
{
return Compare(left, right) <= 0;
}
///
/// Checks whether a font weight is greater than another.
///
/// First object to compare.
/// Second object to compare.
/// True if left is greater than right, false otherwise.
public static bool operator>(FontWeight left, FontWeight right)
{
return Compare(left, right) > 0;
}
///
/// Checks whether a font weight is greater or equal than another.
///
/// First object to compare.
/// Second object to compare.
/// True if left is greater or equal than right, false otherwise.
public static bool operator>=(FontWeight left, FontWeight right)
{
return Compare(left, right) >= 0;
}
///
/// Checks whether two font weight objects are equal.
///
/// First object to compare.
/// Second object to compare.
/// Returns true when the font weight values are equal for both objects,
/// and false otherwise.
public static bool operator==(FontWeight left, FontWeight right)
{
return Compare(left, right) == 0;
}
///
/// Checks whether two font weight objects are not equal.
///
/// First object to compare.
/// Second object to compare.
/// Returns false when the font weight values are equal for both objects,
/// and true otherwise.
public static bool operator!=(FontWeight left, FontWeight right)
{
return !(left == right);
}
///
/// Checks whether the object is equal to another FontWeight object.
///
/// FontWeight object to compare with.
/// Returns true when the object is equal to the input object,
/// and false otherwise.
public bool Equals(FontWeight obj)
{
return this == obj;
}
///
/// Checks whether an object is equal to another character hit object.
///
/// FontWeight object to compare with.
/// Returns true when the object is equal to the input object,
/// and false otherwise.
public override bool Equals(object obj)
{
if (!(obj is FontWeight))
return false;
return this == (FontWeight)obj;
}
///
/// Compute hash code for this object.
///
/// A 32-bit signed integer hash code.
public override int GetHashCode()
{
return RealWeight;
}
///
/// Creates a string representation of this object based on the current culture.
///
///
/// A string representation of this object.
///
public override string ToString()
{
// Delegate to the internal method which implements all ToString calls.
return ConvertToString(null, null);
}
///
/// Creates a string representation of this object based on the format string
/// and IFormatProvider passed in.
/// If the provider is null, the CurrentCulture is used.
/// See the documentation for IFormattable for more information.
///
///
/// A string representation of this object.
///
string IFormattable.ToString(string format, IFormatProvider provider)
{
// Delegate to the internal method which implements all ToString calls.
return ConvertToString(format, provider);
}
///
/// Creates a string representation of this object based on the format string
/// and IFormatProvider passed in.
/// If the provider is null, the CurrentCulture is used.
/// See the documentation for IFormattable for more information.
///
///
/// A string representation of this object.
///
private string ConvertToString(string format, IFormatProvider provider)
{
string convertedValue;
if (!FontWeights.FontWeightToString(RealWeight, out convertedValue))
{
// This can happen if _weight value is not a multiple of 100.
return RealWeight.ToString(provider);
}
return convertedValue;
}
///
/// We want the default zero value of new FontWeight() to correspond to FontWeights.Normal.
/// Therefore, _weight value is shifted by 400 relative to the OpenType weight value.
///
private int RealWeight
{
get
{
return _weight + 400;
}
}
private int _weight;
}
}
// 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
- DataRelationPropertyDescriptor.cs
- RequestCacheManager.cs
- EntityContainerEmitter.cs
- MarshalByRefObject.cs
- DiffuseMaterial.cs
- Pair.cs
- EncryptedXml.cs
- CornerRadius.cs
- UMPAttributes.cs
- RunClient.cs
- ObjectKeyFrameCollection.cs
- EntityDataSourceWrapperPropertyDescriptor.cs
- RegionData.cs
- RewritingValidator.cs
- dataSvcMapFileLoader.cs
- IisTraceWebEventProvider.cs
- ConnectionManagementSection.cs
- WebContext.cs
- ErrorFormatterPage.cs
- Highlights.cs
- ThicknessAnimation.cs
- QuaternionRotation3D.cs
- DictionaryEntry.cs
- DataRowComparer.cs
- SecurityAttributeGenerationHelper.cs
- FrameSecurityDescriptor.cs
- SqlSupersetValidator.cs
- PromptStyle.cs
- Cursors.cs
- SourceCollection.cs
- ImageAnimator.cs
- OnOperation.cs
- LoadedOrUnloadedOperation.cs
- FixedStringLookup.cs
- FontUnitConverter.cs
- LambdaCompiler.Binary.cs
- DataGridViewAdvancedBorderStyle.cs
- SelectionHighlightInfo.cs
- TextSelection.cs
- ParserExtension.cs
- HttpPostedFile.cs
- IsolatedStorageException.cs
- DataServiceExpressionVisitor.cs
- DataGridCaption.cs
- ToolStripGripRenderEventArgs.cs
- Token.cs
- OutputWindow.cs
- TypographyProperties.cs
- TypedElement.cs
- MimeTypeMapper.cs
- XPathNavigatorReader.cs
- DataErrorValidationRule.cs
- HorizontalAlignConverter.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- ListView.cs
- XmlJsonWriter.cs
- ImageSource.cs
- Transactions.cs
- LogLogRecord.cs
- XsdBuildProvider.cs
- SimpleWorkerRequest.cs
- ExecutionContext.cs
- VisualTransition.cs
- TripleDESCryptoServiceProvider.cs
- OdbcParameter.cs
- CodeIdentifier.cs
- ConcurrentDictionary.cs
- ApplyTemplatesAction.cs
- StylusPointDescription.cs
- recordstate.cs
- SafeNativeMethods.cs
- ConsumerConnectionPoint.cs
- UpdateRecord.cs
- DynamicDocumentPaginator.cs
- DependencyObjectProvider.cs
- FontInfo.cs
- ImportContext.cs
- ControlAdapter.cs
- IgnoreDeviceFilterElement.cs
- System.Data.OracleClient_BID.cs
- ToolStripHighContrastRenderer.cs
- WebPartAddingEventArgs.cs
- TemplateXamlParser.cs
- WindowsPrincipal.cs
- FormCollection.cs
- ToolStripControlHost.cs
- PackageRelationshipSelector.cs
- SerializationEventsCache.cs
- NativeMethodsCLR.cs
- QEncodedStream.cs
- StatusBarPanelClickEvent.cs
- DataGridViewCellPaintingEventArgs.cs
- FolderLevelBuildProvider.cs
- UnhandledExceptionEventArgs.cs
- NoResizeHandleGlyph.cs
- BCLDebug.cs
- PriorityBinding.cs
- AdjustableArrowCap.cs
- RelOps.cs
- ObjectDataSourceView.cs