Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Core / CSharp / System / Windows / Media / textformatting / TextCharacters.cs / 1 / TextCharacters.cs
//------------------------------------------------------------------------
//
// Microsoft Windows Client Platform
// Copyright (C) Microsoft Corporation, 2004
//
// File: TextCharacters.cs
//
// Contents: Implementation of text symbol for characters
//
// Spec: http://team/sites/Avalon/Specs/Text%20Formatting%20API.doc
//
// Created: 1-2-2004 Worachai Chaoweeraprasit (wchao)
//
//-----------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Globalization;
using System.Collections;
using System.Collections.Generic;
using System.Security;
using System.Windows;
using MS.Internal;
using MS.Internal.Shaping;
using MS.Internal.TextFormatting;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
namespace System.Windows.Media.TextFormatting
{
///
/// A specialized TextSymbols implemented by TextFormatter to produces
/// a collection of TextCharacterShape – each represents a collection of
/// character glyphs from distinct physical typeface.
///
public class TextCharacters : TextRun, ITextSymbols, IShapeableTextCollector
{
private CharacterBufferReference _characterBufferReference;
private int _length;
private TextRunProperties _textRunProperties;
#region Constructors
///
/// Construct a run of text content from character array
///
public TextCharacters(
char[] characterArray,
int offsetToFirstChar,
int length,
TextRunProperties textRunProperties
) :
this(
new CharacterBufferReference(characterArray, offsetToFirstChar),
length,
textRunProperties
)
{}
///
/// Construct a run for text content from string
///
public TextCharacters(
string characterString,
TextRunProperties textRunProperties
) :
this(
characterString,
0, // offserToFirstChar
(characterString == null) ? 0 : characterString.Length,
textRunProperties
)
{}
///
/// Construct a run for text content from string
///
public TextCharacters(
string characterString,
int offsetToFirstChar,
int length,
TextRunProperties textRunProperties
) :
this(
new CharacterBufferReference(characterString, offsetToFirstChar),
length,
textRunProperties
)
{}
///
/// Construct a run for text content from unsafe character string
///
///
/// Critical: This manipulates unsafe pointers and calls into the critical CharacterBufferReference ctor.
/// PublicOK: The caller needs unmanaged code permission in order to pass unsafe pointers to us.
///
[SecurityCritical]
[CLSCompliant(false)]
public unsafe TextCharacters(
char* unsafeCharacterString,
int length,
TextRunProperties textRunProperties
) :
this(
new CharacterBufferReference(unsafeCharacterString, length),
length,
textRunProperties
)
{}
///
/// Internal constructor of TextContent
///
private TextCharacters(
CharacterBufferReference characterBufferReference,
int length,
TextRunProperties textRunProperties
)
{
if (length <= 0)
{
throw new ArgumentOutOfRangeException("length", SR.Get(SRID.ParameterMustBeGreaterThanZero));
}
if (textRunProperties == null)
{
throw new ArgumentNullException("textRunProperties");
}
if (textRunProperties.Typeface == null)
{
throw new ArgumentNullException("textRunProperties.Typeface");
}
if (textRunProperties.CultureInfo == null)
{
throw new ArgumentNullException("textRunProperties.CultureInfo");
}
if (textRunProperties.FontRenderingEmSize <= 0)
{
throw new ArgumentOutOfRangeException("textRunProperties.FontRenderingEmSize", SR.Get(SRID.ParameterMustBeGreaterThanZero));
}
_characterBufferReference = characterBufferReference;
_length = length;
_textRunProperties = textRunProperties;
}
#endregion
#region TextRun implementation
///
/// Character buffer
///
public sealed override CharacterBufferReference CharacterBufferReference
{
get { return _characterBufferReference; }
}
///
/// Character length of the run
///
///
public sealed override int Length
{
get { return _length; }
}
///
/// A set of properties shared by every characters in the run
///
public sealed override TextRunProperties Properties
{
get { return _textRunProperties; }
}
#endregion
#region ITextSymbols implementation
///
/// Break a run of text into individually shape items.
/// Shape items are delimited by
/// Change of writing system
/// Change of glyph typeface
///
IList ITextSymbols.GetTextShapeableSymbols(
GlyphingCache glyphingCache,
CharacterBufferReference characterBufferReference,
int length,
bool rightToLeft,
CultureInfo digitCulture,
TextModifierScope textModifierScope
)
{
if (characterBufferReference.CharacterBuffer == null)
{
throw new ArgumentNullException("characterBufferReference.CharacterBuffer");
}
int offsetToFirstChar = characterBufferReference.OffsetToFirstChar - _characterBufferReference.OffsetToFirstChar;
Debug.Assert(characterBufferReference.CharacterBuffer == _characterBufferReference.CharacterBuffer);
Debug.Assert(offsetToFirstChar >= 0 && offsetToFirstChar < _length);
if ( length < 0
|| offsetToFirstChar + length > _length)
{
length = _length - offsetToFirstChar;
}
// Get the actual text run properties in effect, after invoking any
// text modifiers that may be in scope.
TextRunProperties textRunProperties = _textRunProperties;
if (textModifierScope != null)
{
textRunProperties = textModifierScope.ModifyProperties(textRunProperties);
}
if (!rightToLeft)
{
// Fast loop early out for run with all non-complex characters
// which can be optimized by not going thru shaping engine.
int nominalLength;
if (textRunProperties.Typeface.CheckFastPathNominalGlyphs(
new CharacterBufferRange(characterBufferReference, length),
textRunProperties.FontRenderingEmSize,
double.MaxValue, // widthMax
true, // keepAWord
digitCulture != null,
CultureMapper.GetSpecificCulture(textRunProperties.CultureInfo),
out nominalLength
) && length == nominalLength)
{
return new TextShapeableCharacters[]
{
new TextShapeableCharacters(
new CharacterBufferRange(characterBufferReference, nominalLength),
textRunProperties,
textRunProperties.FontRenderingEmSize,
new Item(ScriptID.Default, ItemFlags.Default),
null, // shapeTypeface (no shaping required)
false // nullShape
)
};
}
}
IList shapeables = new List(2);
glyphingCache.GetShapeableText(
textRunProperties.Typeface,
characterBufferReference,
length,
textRunProperties,
digitCulture,
rightToLeft,
shapeables,
this as IShapeableTextCollector
);
return shapeables;
}
#endregion
#region IShapeableTextCollector implementation
///
/// Add shapeable text object to the list
///
void IShapeableTextCollector.Add(
IList shapeables,
CharacterBufferRange characterBufferRange,
TextRunProperties textRunProperties,
Item textItem,
ShapeTypeface shapeTypeface,
double emScale,
bool nullShape
)
{
Debug.Assert(shapeables != null);
shapeables.Add(
new TextShapeableCharacters(
characterBufferRange,
textRunProperties,
textRunProperties.FontRenderingEmSize * emScale,
textItem,
shapeTypeface,
nullShape
)
);
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------
//
// Microsoft Windows Client Platform
// Copyright (C) Microsoft Corporation, 2004
//
// File: TextCharacters.cs
//
// Contents: Implementation of text symbol for characters
//
// Spec: http://team/sites/Avalon/Specs/Text%20Formatting%20API.doc
//
// Created: 1-2-2004 Worachai Chaoweeraprasit (wchao)
//
//-----------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Globalization;
using System.Collections;
using System.Collections.Generic;
using System.Security;
using System.Windows;
using MS.Internal;
using MS.Internal.Shaping;
using MS.Internal.TextFormatting;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
namespace System.Windows.Media.TextFormatting
{
///
/// A specialized TextSymbols implemented by TextFormatter to produces
/// a collection of TextCharacterShape – each represents a collection of
/// character glyphs from distinct physical typeface.
///
public class TextCharacters : TextRun, ITextSymbols, IShapeableTextCollector
{
private CharacterBufferReference _characterBufferReference;
private int _length;
private TextRunProperties _textRunProperties;
#region Constructors
///
/// Construct a run of text content from character array
///
public TextCharacters(
char[] characterArray,
int offsetToFirstChar,
int length,
TextRunProperties textRunProperties
) :
this(
new CharacterBufferReference(characterArray, offsetToFirstChar),
length,
textRunProperties
)
{}
///
/// Construct a run for text content from string
///
public TextCharacters(
string characterString,
TextRunProperties textRunProperties
) :
this(
characterString,
0, // offserToFirstChar
(characterString == null) ? 0 : characterString.Length,
textRunProperties
)
{}
///
/// Construct a run for text content from string
///
public TextCharacters(
string characterString,
int offsetToFirstChar,
int length,
TextRunProperties textRunProperties
) :
this(
new CharacterBufferReference(characterString, offsetToFirstChar),
length,
textRunProperties
)
{}
///
/// Construct a run for text content from unsafe character string
///
///
/// Critical: This manipulates unsafe pointers and calls into the critical CharacterBufferReference ctor.
/// PublicOK: The caller needs unmanaged code permission in order to pass unsafe pointers to us.
///
[SecurityCritical]
[CLSCompliant(false)]
public unsafe TextCharacters(
char* unsafeCharacterString,
int length,
TextRunProperties textRunProperties
) :
this(
new CharacterBufferReference(unsafeCharacterString, length),
length,
textRunProperties
)
{}
///
/// Internal constructor of TextContent
///
private TextCharacters(
CharacterBufferReference characterBufferReference,
int length,
TextRunProperties textRunProperties
)
{
if (length <= 0)
{
throw new ArgumentOutOfRangeException("length", SR.Get(SRID.ParameterMustBeGreaterThanZero));
}
if (textRunProperties == null)
{
throw new ArgumentNullException("textRunProperties");
}
if (textRunProperties.Typeface == null)
{
throw new ArgumentNullException("textRunProperties.Typeface");
}
if (textRunProperties.CultureInfo == null)
{
throw new ArgumentNullException("textRunProperties.CultureInfo");
}
if (textRunProperties.FontRenderingEmSize <= 0)
{
throw new ArgumentOutOfRangeException("textRunProperties.FontRenderingEmSize", SR.Get(SRID.ParameterMustBeGreaterThanZero));
}
_characterBufferReference = characterBufferReference;
_length = length;
_textRunProperties = textRunProperties;
}
#endregion
#region TextRun implementation
///
/// Character buffer
///
public sealed override CharacterBufferReference CharacterBufferReference
{
get { return _characterBufferReference; }
}
///
/// Character length of the run
///
///
public sealed override int Length
{
get { return _length; }
}
///
/// A set of properties shared by every characters in the run
///
public sealed override TextRunProperties Properties
{
get { return _textRunProperties; }
}
#endregion
#region ITextSymbols implementation
///
/// Break a run of text into individually shape items.
/// Shape items are delimited by
/// Change of writing system
/// Change of glyph typeface
///
IList ITextSymbols.GetTextShapeableSymbols(
GlyphingCache glyphingCache,
CharacterBufferReference characterBufferReference,
int length,
bool rightToLeft,
CultureInfo digitCulture,
TextModifierScope textModifierScope
)
{
if (characterBufferReference.CharacterBuffer == null)
{
throw new ArgumentNullException("characterBufferReference.CharacterBuffer");
}
int offsetToFirstChar = characterBufferReference.OffsetToFirstChar - _characterBufferReference.OffsetToFirstChar;
Debug.Assert(characterBufferReference.CharacterBuffer == _characterBufferReference.CharacterBuffer);
Debug.Assert(offsetToFirstChar >= 0 && offsetToFirstChar < _length);
if ( length < 0
|| offsetToFirstChar + length > _length)
{
length = _length - offsetToFirstChar;
}
// Get the actual text run properties in effect, after invoking any
// text modifiers that may be in scope.
TextRunProperties textRunProperties = _textRunProperties;
if (textModifierScope != null)
{
textRunProperties = textModifierScope.ModifyProperties(textRunProperties);
}
if (!rightToLeft)
{
// Fast loop early out for run with all non-complex characters
// which can be optimized by not going thru shaping engine.
int nominalLength;
if (textRunProperties.Typeface.CheckFastPathNominalGlyphs(
new CharacterBufferRange(characterBufferReference, length),
textRunProperties.FontRenderingEmSize,
double.MaxValue, // widthMax
true, // keepAWord
digitCulture != null,
CultureMapper.GetSpecificCulture(textRunProperties.CultureInfo),
out nominalLength
) && length == nominalLength)
{
return new TextShapeableCharacters[]
{
new TextShapeableCharacters(
new CharacterBufferRange(characterBufferReference, nominalLength),
textRunProperties,
textRunProperties.FontRenderingEmSize,
new Item(ScriptID.Default, ItemFlags.Default),
null, // shapeTypeface (no shaping required)
false // nullShape
)
};
}
}
IList shapeables = new List(2);
glyphingCache.GetShapeableText(
textRunProperties.Typeface,
characterBufferReference,
length,
textRunProperties,
digitCulture,
rightToLeft,
shapeables,
this as IShapeableTextCollector
);
return shapeables;
}
#endregion
#region IShapeableTextCollector implementation
///
/// Add shapeable text object to the list
///
void IShapeableTextCollector.Add(
IList shapeables,
CharacterBufferRange characterBufferRange,
TextRunProperties textRunProperties,
Item textItem,
ShapeTypeface shapeTypeface,
double emScale,
bool nullShape
)
{
Debug.Assert(shapeables != null);
shapeables.Add(
new TextShapeableCharacters(
characterBufferRange,
textRunProperties,
textRunProperties.FontRenderingEmSize * emScale,
textItem,
shapeTypeface,
nullShape
)
);
}
#endregion
}
}
// 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
- PropertyChangingEventArgs.cs
- XamlTemplateSerializer.cs
- WindowsGraphics2.cs
- Trace.cs
- ComMethodElementCollection.cs
- CompatibleComparer.cs
- WebBrowserEvent.cs
- StorageMappingItemLoader.cs
- AccessKeyManager.cs
- CodeTypeOfExpression.cs
- WebPartHelpVerb.cs
- ToolConsole.cs
- StateRuntime.cs
- RulePatternOps.cs
- SmtpSection.cs
- MimeTextImporter.cs
- InvalidProgramException.cs
- AssociatedControlConverter.cs
- SimpleHandlerBuildProvider.cs
- ThumbAutomationPeer.cs
- DesignerForm.cs
- TaskFormBase.cs
- GetWinFXPath.cs
- Serializer.cs
- DictionaryMarkupSerializer.cs
- HttpCachePolicyElement.cs
- MultilineStringConverter.cs
- ItemList.cs
- TypedAsyncResult.cs
- DbConnectionStringCommon.cs
- TraceSection.cs
- SiteOfOriginPart.cs
- AlternateView.cs
- IntSecurity.cs
- QuaternionValueSerializer.cs
- MemoryRecordBuffer.cs
- FilterElement.cs
- DbConnectionPoolGroupProviderInfo.cs
- Transactions.cs
- _PooledStream.cs
- MimePart.cs
- MimeTextImporter.cs
- ReceiveContext.cs
- PageSettings.cs
- UITypeEditor.cs
- MeasureData.cs
- SoapInteropTypes.cs
- Column.cs
- HideDisabledControlAdapter.cs
- MatrixTransform.cs
- XdrBuilder.cs
- EventWaitHandle.cs
- OdbcError.cs
- XmlElement.cs
- WebConfigurationHostFileChange.cs
- CompilationRelaxations.cs
- DbFunctionCommandTree.cs
- WinHttpWebProxyFinder.cs
- RequestChannelBinder.cs
- CurrencyManager.cs
- DataGridViewImageCell.cs
- TabPage.cs
- AsymmetricKeyExchangeDeformatter.cs
- SystemBrushes.cs
- HttpCapabilitiesEvaluator.cs
- PathGeometry.cs
- SafeHandles.cs
- PolyQuadraticBezierSegment.cs
- FormsIdentity.cs
- RouteParameter.cs
- BindingMemberInfo.cs
- LambdaCompiler.Expressions.cs
- CalendarDay.cs
- XMLSyntaxException.cs
- IdentityReference.cs
- HtmlTernaryTree.cs
- tibetanshape.cs
- ListViewDeletedEventArgs.cs
- ViewgenGatekeeper.cs
- ProcessProtocolHandler.cs
- BitmapDecoder.cs
- ToolStripLocationCancelEventArgs.cs
- TableAutomationPeer.cs
- UnsafeNativeMethods.cs
- ManipulationLogic.cs
- BaseProcessor.cs
- DbConnectionOptions.cs
- DataGridTextBoxColumn.cs
- AudioFileOut.cs
- ExpandSegment.cs
- ApplicationFileParser.cs
- SqlClientWrapperSmiStreamChars.cs
- ReadOnlyCollectionBase.cs
- DelimitedListTraceListener.cs
- AvTraceDetails.cs
- PathFigureCollection.cs
- FilteredAttributeCollection.cs
- RecordConverter.cs
- ToolStripDropTargetManager.cs
- AssemblyAssociatedContentFileAttribute.cs