Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / Text / TextProperties.cs / 1305600 / TextProperties.cs
//----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// File: TextProperties.cs
//
// Description: Text run properties provider.
//
// History:
// 04/25/2003 : [....] - moving from Avalon branch.
//
//---------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.TextFormatting;
namespace MS.Internal.Text
{
// ---------------------------------------------------------------------
// Text run properties provider.
// ---------------------------------------------------------------------
internal sealed class TextProperties : TextRunProperties
{
// ------------------------------------------------------------------
//
// TextRunProperties Implementation
//
// -----------------------------------------------------------------
#region TextRunProperties Implementation
// ------------------------------------------------------------------
// Typeface used to format and display text.
// ------------------------------------------------------------------
public override Typeface Typeface { get { return _typeface; } }
// -----------------------------------------------------------------
// Em size of font used to format and display text.
// ------------------------------------------------------------------
public override double FontRenderingEmSize
{
get
{
double emSize = _fontSize;
// Make sure that TextFormatter limitations are not exceeded.
TextDpi.EnsureValidLineOffset(ref emSize);
return emSize;
}
}
// -----------------------------------------------------------------
// Em size of font to determine subtle change in font hinting.
// -----------------------------------------------------------------
public override double FontHintingEmSize { get { return 12.0; } }
// -----------------------------------------------------------------
// Text decorations.
// ------------------------------------------------------------------
public override TextDecorationCollection TextDecorations { get { return _textDecorations; } }
// -----------------------------------------------------------------
// Text foreground bursh.
// ------------------------------------------------------------------
public override Brush ForegroundBrush { get { return _foreground; } }
// ------------------------------------------------------------------
// Text background brush.
// -----------------------------------------------------------------
public override Brush BackgroundBrush { get { return _backgroundBrush; } }
// ------------------------------------------------------------------
// Text vertical alignment.
// -----------------------------------------------------------------
public override BaselineAlignment BaselineAlignment { get { return _baselineAlignment; } }
// -----------------------------------------------------------------
// Text culture info.
// -----------------------------------------------------------------
public override CultureInfo CultureInfo { get { return _cultureInfo; } }
// ------------------------------------------------------------------
// Number substitution
// -----------------------------------------------------------------
public override NumberSubstitution NumberSubstitution { get { return _numberSubstitution; } }
// ------------------------------------------------------------------
// Typography properties
// ------------------------------------------------------------------
public override TextRunTypographyProperties TypographyProperties{ get { return _typographyProperties; } }
// -----------------------------------------------------------------
// TextEffects property
// ------------------------------------------------------------------
public override TextEffectCollection TextEffects { get { return _textEffects; } }
#endregion TextRunProperties Implementation
// -----------------------------------------------------------------
// Constructor.
// -----------------------------------------------------------------
internal TextProperties(FrameworkElement target, bool isTypographyDefaultValue)
{
// if none of the number substitution properties have changed, initialize the
// _numberSubstitution field to a known default value
if (!target.HasNumberSubstitutionChanged)
{
_numberSubstitution = FrameworkElement.DefaultNumberSubstitution;
}
InitCommon(target);
if (!isTypographyDefaultValue)
{
_typographyProperties = TextElement.GetTypographyProperties(target);
}
else
{
_typographyProperties = Typography.Default;
}
_baselineAlignment = BaselineAlignment.Baseline;
}
internal TextProperties(DependencyObject target, StaticTextPointer position, bool inlineObjects, bool getBackground)
{
// if none of the number substitution properties have changed, we may be able to
// initialize the _numberSubstitution field to a known default value
FrameworkContentElement fce = target as FrameworkContentElement;
if (fce != null)
{
if (!fce.HasNumberSubstitutionChanged)
{
_numberSubstitution = FrameworkContentElement.DefaultNumberSubstitution;
}
}
else
{
FrameworkElement fe = target as FrameworkElement;
if (fe != null && !fe.HasNumberSubstitutionChanged)
{
_numberSubstitution = FrameworkElement.DefaultNumberSubstitution;
}
}
InitCommon(target);
_typographyProperties = GetTypographyProperties(target);
if (!inlineObjects)
{
_baselineAlignment = DynamicPropertyReader.GetBaselineAlignment(target);
if (!position.IsNull)
{
TextDecorationCollection highlightDecorations = GetHighlightTextDecorations(position);
if (highlightDecorations != null)
{
// Highlights (if present) take precedence over property value TextDecorations.
_textDecorations = highlightDecorations;
}
}
if (getBackground)
{
_backgroundBrush = DynamicPropertyReader.GetBackgroundBrush(target);
}
}
else
{
_baselineAlignment = DynamicPropertyReader.GetBaselineAlignmentForInlineObject(target);
_textDecorations = DynamicPropertyReader.GetTextDecorationsForInlineObject(target, _textDecorations);
if (getBackground)
{
_backgroundBrush = DynamicPropertyReader.GetBackgroundBrushForInlineObject(position);
}
}
}
// Copy constructor, with override for default TextDecorationCollection value.
internal TextProperties(TextProperties source, TextDecorationCollection textDecorations)
{
_backgroundBrush = source._backgroundBrush;
_typeface = source._typeface;
_fontSize = source._fontSize;
_foreground = source._foreground;
_textEffects = source._textEffects;
_cultureInfo = source._cultureInfo;
_numberSubstitution = source._numberSubstitution;
_typographyProperties = source._typographyProperties;
_baselineAlignment = source._baselineAlignment;
_textDecorations = textDecorations;
}
// assigns values to all fields except for _typographyProperties, _baselineAlignment,
// and _background, which are set appropriately in each constructor
private void InitCommon(DependencyObject target)
{
_typeface = DynamicPropertyReader.GetTypeface(target);
_fontSize = (double)target.GetValue(TextElement.FontSizeProperty);
_foreground = (Brush) target.GetValue(TextElement.ForegroundProperty);
_textEffects = DynamicPropertyReader.GetTextEffects(target);
_cultureInfo = DynamicPropertyReader.GetCultureInfo(target);
_textDecorations = DynamicPropertyReader.GetTextDecorations(target);
// as an optimization, we may have already initialized _numberSubstitution to a default
// value if none of the NumberSubstitution dependency properties have changed
if (_numberSubstitution == null)
{
_numberSubstitution = DynamicPropertyReader.GetNumberSubstitution(target);
}
}
// Gathers text decorations set on scoping highlights.
// If no highlight properties are found, returns null
private static TextDecorationCollection GetHighlightTextDecorations(StaticTextPointer highlightPosition)
{
TextDecorationCollection textDecorations = null;
Highlights highlights = highlightPosition.TextContainer.Highlights;
if (highlights == null)
{
return textDecorations;
}
//
// Speller
//
textDecorations = highlights.GetHighlightValue(highlightPosition, LogicalDirection.Forward, typeof(SpellerHighlightLayer)) as TextDecorationCollection;
//
// IME composition
//
//
#if UNUSED_IME_HIGHLIGHT_LAYER
TextDecorationCollection imeTextDecorations = highlights.GetHighlightValue(highlightPosition, LogicalDirection.Forward, typeof(FrameworkTextComposition)) as TextDecorationCollection;
if (imeTextDecorations != null)
{
textDecorations = imeTextDecorations;
}
#endif
return textDecorations;
}
// -----------------------------------------------------------------
// Retrieve typography properties from specified element.
// ------------------------------------------------------------------
private static TypographyProperties GetTypographyProperties(DependencyObject element)
{
Debug.Assert(element != null);
TextBlock tb = element as TextBlock;
if (tb != null)
{
if(!tb.IsTypographyDefaultValue)
{
return TextElement.GetTypographyProperties(element);
}
else
{
return Typography.Default;
}
}
TextBox textBox = element as TextBox;
if (textBox != null)
{
if (!textBox.IsTypographyDefaultValue)
{
return TextElement.GetTypographyProperties(element);
}
else
{
return Typography.Default;
}
}
TextElement te = element as TextElement;
if (te != null)
{
return te.TypographyPropertiesGroup;
}
FlowDocument fd = element as FlowDocument;
if (fd != null)
{
return fd.TypographyPropertiesGroup;
}
// return default typography properties group
return Typography.Default;
}
// -----------------------------------------------------------------
// Typeface.
// ------------------------------------------------------------------
private Typeface _typeface;
// ------------------------------------------------------------------
// Font size.
// -----------------------------------------------------------------
private double _fontSize;
// ------------------------------------------------------------------
// Foreground brush.
// -----------------------------------------------------------------
private Brush _foreground;
// -----------------------------------------------------------------
// Text effects flags.
// -----------------------------------------------------------------
private TextEffectCollection _textEffects;
// ------------------------------------------------------------------
// Text decorations.
// -----------------------------------------------------------------
private TextDecorationCollection _textDecorations;
// ------------------------------------------------------------------
// Baseline alignment.
// ------------------------------------------------------------------
private BaselineAlignment _baselineAlignment;
// -----------------------------------------------------------------
// Text background brush.
// ------------------------------------------------------------------
private Brush _backgroundBrush;
// -----------------------------------------------------------------
// Culture info.
// -----------------------------------------------------------------
private CultureInfo _cultureInfo;
// -----------------------------------------------------------------
// Number Substitution
// ------------------------------------------------------------------
private NumberSubstitution _numberSubstitution;
// -----------------------------------------------------------------
// Typography properties group.
// ------------------------------------------------------------------
private TextRunTypographyProperties _typographyProperties;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// File: TextProperties.cs
//
// Description: Text run properties provider.
//
// History:
// 04/25/2003 : [....] - moving from Avalon branch.
//
//---------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.TextFormatting;
namespace MS.Internal.Text
{
// ---------------------------------------------------------------------
// Text run properties provider.
// ---------------------------------------------------------------------
internal sealed class TextProperties : TextRunProperties
{
// ------------------------------------------------------------------
//
// TextRunProperties Implementation
//
// -----------------------------------------------------------------
#region TextRunProperties Implementation
// ------------------------------------------------------------------
// Typeface used to format and display text.
// ------------------------------------------------------------------
public override Typeface Typeface { get { return _typeface; } }
// -----------------------------------------------------------------
// Em size of font used to format and display text.
// ------------------------------------------------------------------
public override double FontRenderingEmSize
{
get
{
double emSize = _fontSize;
// Make sure that TextFormatter limitations are not exceeded.
TextDpi.EnsureValidLineOffset(ref emSize);
return emSize;
}
}
// -----------------------------------------------------------------
// Em size of font to determine subtle change in font hinting.
// -----------------------------------------------------------------
public override double FontHintingEmSize { get { return 12.0; } }
// -----------------------------------------------------------------
// Text decorations.
// ------------------------------------------------------------------
public override TextDecorationCollection TextDecorations { get { return _textDecorations; } }
// -----------------------------------------------------------------
// Text foreground bursh.
// ------------------------------------------------------------------
public override Brush ForegroundBrush { get { return _foreground; } }
// ------------------------------------------------------------------
// Text background brush.
// -----------------------------------------------------------------
public override Brush BackgroundBrush { get { return _backgroundBrush; } }
// ------------------------------------------------------------------
// Text vertical alignment.
// -----------------------------------------------------------------
public override BaselineAlignment BaselineAlignment { get { return _baselineAlignment; } }
// -----------------------------------------------------------------
// Text culture info.
// -----------------------------------------------------------------
public override CultureInfo CultureInfo { get { return _cultureInfo; } }
// ------------------------------------------------------------------
// Number substitution
// -----------------------------------------------------------------
public override NumberSubstitution NumberSubstitution { get { return _numberSubstitution; } }
// ------------------------------------------------------------------
// Typography properties
// ------------------------------------------------------------------
public override TextRunTypographyProperties TypographyProperties{ get { return _typographyProperties; } }
// -----------------------------------------------------------------
// TextEffects property
// ------------------------------------------------------------------
public override TextEffectCollection TextEffects { get { return _textEffects; } }
#endregion TextRunProperties Implementation
// -----------------------------------------------------------------
// Constructor.
// -----------------------------------------------------------------
internal TextProperties(FrameworkElement target, bool isTypographyDefaultValue)
{
// if none of the number substitution properties have changed, initialize the
// _numberSubstitution field to a known default value
if (!target.HasNumberSubstitutionChanged)
{
_numberSubstitution = FrameworkElement.DefaultNumberSubstitution;
}
InitCommon(target);
if (!isTypographyDefaultValue)
{
_typographyProperties = TextElement.GetTypographyProperties(target);
}
else
{
_typographyProperties = Typography.Default;
}
_baselineAlignment = BaselineAlignment.Baseline;
}
internal TextProperties(DependencyObject target, StaticTextPointer position, bool inlineObjects, bool getBackground)
{
// if none of the number substitution properties have changed, we may be able to
// initialize the _numberSubstitution field to a known default value
FrameworkContentElement fce = target as FrameworkContentElement;
if (fce != null)
{
if (!fce.HasNumberSubstitutionChanged)
{
_numberSubstitution = FrameworkContentElement.DefaultNumberSubstitution;
}
}
else
{
FrameworkElement fe = target as FrameworkElement;
if (fe != null && !fe.HasNumberSubstitutionChanged)
{
_numberSubstitution = FrameworkElement.DefaultNumberSubstitution;
}
}
InitCommon(target);
_typographyProperties = GetTypographyProperties(target);
if (!inlineObjects)
{
_baselineAlignment = DynamicPropertyReader.GetBaselineAlignment(target);
if (!position.IsNull)
{
TextDecorationCollection highlightDecorations = GetHighlightTextDecorations(position);
if (highlightDecorations != null)
{
// Highlights (if present) take precedence over property value TextDecorations.
_textDecorations = highlightDecorations;
}
}
if (getBackground)
{
_backgroundBrush = DynamicPropertyReader.GetBackgroundBrush(target);
}
}
else
{
_baselineAlignment = DynamicPropertyReader.GetBaselineAlignmentForInlineObject(target);
_textDecorations = DynamicPropertyReader.GetTextDecorationsForInlineObject(target, _textDecorations);
if (getBackground)
{
_backgroundBrush = DynamicPropertyReader.GetBackgroundBrushForInlineObject(position);
}
}
}
// Copy constructor, with override for default TextDecorationCollection value.
internal TextProperties(TextProperties source, TextDecorationCollection textDecorations)
{
_backgroundBrush = source._backgroundBrush;
_typeface = source._typeface;
_fontSize = source._fontSize;
_foreground = source._foreground;
_textEffects = source._textEffects;
_cultureInfo = source._cultureInfo;
_numberSubstitution = source._numberSubstitution;
_typographyProperties = source._typographyProperties;
_baselineAlignment = source._baselineAlignment;
_textDecorations = textDecorations;
}
// assigns values to all fields except for _typographyProperties, _baselineAlignment,
// and _background, which are set appropriately in each constructor
private void InitCommon(DependencyObject target)
{
_typeface = DynamicPropertyReader.GetTypeface(target);
_fontSize = (double)target.GetValue(TextElement.FontSizeProperty);
_foreground = (Brush) target.GetValue(TextElement.ForegroundProperty);
_textEffects = DynamicPropertyReader.GetTextEffects(target);
_cultureInfo = DynamicPropertyReader.GetCultureInfo(target);
_textDecorations = DynamicPropertyReader.GetTextDecorations(target);
// as an optimization, we may have already initialized _numberSubstitution to a default
// value if none of the NumberSubstitution dependency properties have changed
if (_numberSubstitution == null)
{
_numberSubstitution = DynamicPropertyReader.GetNumberSubstitution(target);
}
}
// Gathers text decorations set on scoping highlights.
// If no highlight properties are found, returns null
private static TextDecorationCollection GetHighlightTextDecorations(StaticTextPointer highlightPosition)
{
TextDecorationCollection textDecorations = null;
Highlights highlights = highlightPosition.TextContainer.Highlights;
if (highlights == null)
{
return textDecorations;
}
//
// Speller
//
textDecorations = highlights.GetHighlightValue(highlightPosition, LogicalDirection.Forward, typeof(SpellerHighlightLayer)) as TextDecorationCollection;
//
// IME composition
//
//
#if UNUSED_IME_HIGHLIGHT_LAYER
TextDecorationCollection imeTextDecorations = highlights.GetHighlightValue(highlightPosition, LogicalDirection.Forward, typeof(FrameworkTextComposition)) as TextDecorationCollection;
if (imeTextDecorations != null)
{
textDecorations = imeTextDecorations;
}
#endif
return textDecorations;
}
// -----------------------------------------------------------------
// Retrieve typography properties from specified element.
// ------------------------------------------------------------------
private static TypographyProperties GetTypographyProperties(DependencyObject element)
{
Debug.Assert(element != null);
TextBlock tb = element as TextBlock;
if (tb != null)
{
if(!tb.IsTypographyDefaultValue)
{
return TextElement.GetTypographyProperties(element);
}
else
{
return Typography.Default;
}
}
TextBox textBox = element as TextBox;
if (textBox != null)
{
if (!textBox.IsTypographyDefaultValue)
{
return TextElement.GetTypographyProperties(element);
}
else
{
return Typography.Default;
}
}
TextElement te = element as TextElement;
if (te != null)
{
return te.TypographyPropertiesGroup;
}
FlowDocument fd = element as FlowDocument;
if (fd != null)
{
return fd.TypographyPropertiesGroup;
}
// return default typography properties group
return Typography.Default;
}
// -----------------------------------------------------------------
// Typeface.
// ------------------------------------------------------------------
private Typeface _typeface;
// ------------------------------------------------------------------
// Font size.
// -----------------------------------------------------------------
private double _fontSize;
// ------------------------------------------------------------------
// Foreground brush.
// -----------------------------------------------------------------
private Brush _foreground;
// -----------------------------------------------------------------
// Text effects flags.
// -----------------------------------------------------------------
private TextEffectCollection _textEffects;
// ------------------------------------------------------------------
// Text decorations.
// -----------------------------------------------------------------
private TextDecorationCollection _textDecorations;
// ------------------------------------------------------------------
// Baseline alignment.
// ------------------------------------------------------------------
private BaselineAlignment _baselineAlignment;
// -----------------------------------------------------------------
// Text background brush.
// ------------------------------------------------------------------
private Brush _backgroundBrush;
// -----------------------------------------------------------------
// Culture info.
// -----------------------------------------------------------------
private CultureInfo _cultureInfo;
// -----------------------------------------------------------------
// Number Substitution
// ------------------------------------------------------------------
private NumberSubstitution _numberSubstitution;
// -----------------------------------------------------------------
// Typography properties group.
// ------------------------------------------------------------------
private TextRunTypographyProperties _typographyProperties;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Table.cs
- HwndSubclass.cs
- PseudoWebRequest.cs
- Clipboard.cs
- AppDomainFactory.cs
- RelatedView.cs
- MimeMultiPart.cs
- ConstraintCollection.cs
- ExternalException.cs
- DataViewSetting.cs
- DayRenderEvent.cs
- ApplicationFileParser.cs
- BinHexDecoder.cs
- HttpProtocolReflector.cs
- RawMouseInputReport.cs
- GACIdentityPermission.cs
- ClonableStack.cs
- XmlWriter.cs
- SqlBulkCopyColumnMapping.cs
- OverflowException.cs
- SynchronizationLockException.cs
- RegisteredExpandoAttribute.cs
- Stylesheet.cs
- OpCellTreeNode.cs
- ISCIIEncoding.cs
- InitializerFacet.cs
- BamlTreeNode.cs
- Profiler.cs
- _NegoStream.cs
- Mouse.cs
- UrlPropertyAttribute.cs
- DataTableNewRowEvent.cs
- ColumnHeaderCollectionEditor.cs
- RequestContext.cs
- DataObjectAttribute.cs
- DynamicRenderer.cs
- _CookieModule.cs
- HwndSourceParameters.cs
- ListViewUpdateEventArgs.cs
- MembershipValidatePasswordEventArgs.cs
- SafeProcessHandle.cs
- Sql8ExpressionRewriter.cs
- SnapshotChangeTrackingStrategy.cs
- ActivityExecutorDelegateInfo.cs
- SchemaTypeEmitter.cs
- PartialCachingAttribute.cs
- ValidatedControlConverter.cs
- RoleManagerModule.cs
- BaseServiceProvider.cs
- safex509handles.cs
- ReceiveCompletedEventArgs.cs
- FormatVersion.cs
- ObjectStateFormatter.cs
- SapiGrammar.cs
- ControlBindingsConverter.cs
- XmlEntity.cs
- PerspectiveCamera.cs
- ImageKeyConverter.cs
- PlacementWorkspace.cs
- AxisAngleRotation3D.cs
- Int64KeyFrameCollection.cs
- CallbackCorrelationInitializer.cs
- PackageRelationshipCollection.cs
- VisualCollection.cs
- InternalPermissions.cs
- DrawingContext.cs
- ServiceContractAttribute.cs
- MessageQueueCriteria.cs
- ContentElement.cs
- WizardPanel.cs
- ListViewDataItem.cs
- ClientScriptItemCollection.cs
- _TransmitFileOverlappedAsyncResult.cs
- ProviderIncompatibleException.cs
- SinglePageViewer.cs
- TextSerializer.cs
- HttpRequestTraceRecord.cs
- DbExpressionRules.cs
- PageAdapter.cs
- ExitEventArgs.cs
- SettingsPropertyValue.cs
- RSAOAEPKeyExchangeDeformatter.cs
- SystemTcpConnection.cs
- XmlSchemaAnnotated.cs
- HitTestResult.cs
- RecordConverter.cs
- SiteMapDataSource.cs
- DependencyPropertyKind.cs
- DataGridViewCellFormattingEventArgs.cs
- HiddenFieldPageStatePersister.cs
- BrushConverter.cs
- TraceContext.cs
- IconConverter.cs
- _DisconnectOverlappedAsyncResult.cs
- DbConnectionPool.cs
- ADMembershipProvider.cs
- LineServices.cs
- GridViewHeaderRowPresenterAutomationPeer.cs
- ViewBox.cs
- SoapAttributeAttribute.cs