Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / MS / Internal / Text / SimpleLine.cs / 1 / SimpleLine.cs
//----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// File: SimpleLine.cs
//
// Description: Text line formatter.
//
// History:
// 09/10/2003 : grzegorz - created.
//
//---------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.TextFormatting;
namespace MS.Internal.Text
{
// ---------------------------------------------------------------------
// Text line formatter.
// ---------------------------------------------------------------------
internal sealed class SimpleLine : Line
{
// ------------------------------------------------------------------
//
// TextSource Implementation
//
// -----------------------------------------------------------------
#region TextSource Implementation
// ------------------------------------------------------------------
// Get a text run at specified text source position.
// ------------------------------------------------------------------
public override TextRun GetTextRun(int dcp)
{
Debug.Assert(dcp >= 0, "Character index must be non-negative.");
TextRun run;
// There is only one run of text.
if (dcp < _content.Length)
{
// LineLayout may ask for dcp != 0. This case may only happen during partial
// validation of TextRunCache.
// Example:
// 1) TextRunCache and LineMetrics array were created during measure process.
// 2) Before OnRender is called somebody invalidates render only property.
// This invalidates TextRunCache.
// 3) Before OnRender is called InputHitTest is invoked. Because LineMetrics
// array is valid, we don't have to recreate all lines. There is only
// need to recreate the N-th line (line that has been hit).
// During line recreation LineLayout will not refetch all runs from the
// beginning of TextBlock control - it will ask for the run at the beginning
// of the current line.
// For this reason set 'offsetToFirstChar' to 'dcp' value.
run = new TextCharacters(_content, dcp, _content.Length - dcp, _textProps);
}
else
{
run = new TextEndOfParagraph(_syntheticCharacterLength);
}
return run;
}
// -----------------------------------------------------------------
// Get text immediately before specified text source position.
// ------------------------------------------------------------------
public override TextSpan GetPrecedingText(int dcp)
{
Debug.Assert(dcp >= 0, "Character index must be non-negative.");
CharacterBufferRange charString = CharacterBufferRange.Empty;
CultureInfo culture = null;
if (dcp > 0)
{
charString = new CharacterBufferRange(
_content,
0,
Math.Min(dcp, _content.Length)
);
culture = _textProps.CultureInfo;
}
return new TextSpan (
dcp,
new CultureSpecificCharacterBufferRange(culture, charString)
);
}
///
/// TextFormatter to map a text source character index to a text effect character index
///
/// text source character index
/// the text effect index corresponding to the text effect character index
public override int GetTextEffectCharacterIndexFromTextSourceCharacterIndex(
int textSourceCharacterIndex
)
{
return textSourceCharacterIndex;
}
#endregion TextSource Implementation
//-------------------------------------------------------------------
//
// Internal Methods
//
//-------------------------------------------------------------------
#region Internal Methods
// -----------------------------------------------------------------
// Constructor.
//
// owner - owner of the line.
// ------------------------------------------------------------------
internal SimpleLine(System.Windows.Controls.TextBlock owner, string content, TextRunProperties textProps) : base(owner)
{
Debug.Assert(content != null);
_content = content;
_textProps = textProps;
}
#endregion Internal Methods
//-------------------------------------------------------------------
//
// Private Fields
//
//--------------------------------------------------------------------
#region Private Fields
// ------------------------------------------------------------------
// Content of the line.
// -----------------------------------------------------------------
private readonly string _content;
// ------------------------------------------------------------------
// Text properties.
// -----------------------------------------------------------------
private readonly TextRunProperties _textProps;
#endregion Private Fields
}
}
// 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: SimpleLine.cs
//
// Description: Text line formatter.
//
// History:
// 09/10/2003 : grzegorz - created.
//
//---------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.TextFormatting;
namespace MS.Internal.Text
{
// ---------------------------------------------------------------------
// Text line formatter.
// ---------------------------------------------------------------------
internal sealed class SimpleLine : Line
{
// ------------------------------------------------------------------
//
// TextSource Implementation
//
// -----------------------------------------------------------------
#region TextSource Implementation
// ------------------------------------------------------------------
// Get a text run at specified text source position.
// ------------------------------------------------------------------
public override TextRun GetTextRun(int dcp)
{
Debug.Assert(dcp >= 0, "Character index must be non-negative.");
TextRun run;
// There is only one run of text.
if (dcp < _content.Length)
{
// LineLayout may ask for dcp != 0. This case may only happen during partial
// validation of TextRunCache.
// Example:
// 1) TextRunCache and LineMetrics array were created during measure process.
// 2) Before OnRender is called somebody invalidates render only property.
// This invalidates TextRunCache.
// 3) Before OnRender is called InputHitTest is invoked. Because LineMetrics
// array is valid, we don't have to recreate all lines. There is only
// need to recreate the N-th line (line that has been hit).
// During line recreation LineLayout will not refetch all runs from the
// beginning of TextBlock control - it will ask for the run at the beginning
// of the current line.
// For this reason set 'offsetToFirstChar' to 'dcp' value.
run = new TextCharacters(_content, dcp, _content.Length - dcp, _textProps);
}
else
{
run = new TextEndOfParagraph(_syntheticCharacterLength);
}
return run;
}
// -----------------------------------------------------------------
// Get text immediately before specified text source position.
// ------------------------------------------------------------------
public override TextSpan GetPrecedingText(int dcp)
{
Debug.Assert(dcp >= 0, "Character index must be non-negative.");
CharacterBufferRange charString = CharacterBufferRange.Empty;
CultureInfo culture = null;
if (dcp > 0)
{
charString = new CharacterBufferRange(
_content,
0,
Math.Min(dcp, _content.Length)
);
culture = _textProps.CultureInfo;
}
return new TextSpan (
dcp,
new CultureSpecificCharacterBufferRange(culture, charString)
);
}
///
/// TextFormatter to map a text source character index to a text effect character index
///
/// text source character index
/// the text effect index corresponding to the text effect character index
public override int GetTextEffectCharacterIndexFromTextSourceCharacterIndex(
int textSourceCharacterIndex
)
{
return textSourceCharacterIndex;
}
#endregion TextSource Implementation
//-------------------------------------------------------------------
//
// Internal Methods
//
//-------------------------------------------------------------------
#region Internal Methods
// -----------------------------------------------------------------
// Constructor.
//
// owner - owner of the line.
// ------------------------------------------------------------------
internal SimpleLine(System.Windows.Controls.TextBlock owner, string content, TextRunProperties textProps) : base(owner)
{
Debug.Assert(content != null);
_content = content;
_textProps = textProps;
}
#endregion Internal Methods
//-------------------------------------------------------------------
//
// Private Fields
//
//--------------------------------------------------------------------
#region Private Fields
// ------------------------------------------------------------------
// Content of the line.
// -----------------------------------------------------------------
private readonly string _content;
// ------------------------------------------------------------------
// Text properties.
// -----------------------------------------------------------------
private readonly TextRunProperties _textProps;
#endregion Private Fields
}
}
// 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
- HighlightVisual.cs
- DesignerInterfaces.cs
- reliableinputsessionchannel.cs
- ModifierKeysConverter.cs
- IntegerValidatorAttribute.cs
- sqlpipe.cs
- Dictionary.cs
- DynamicQueryableWrapper.cs
- EnumMember.cs
- DiagnosticsConfigurationHandler.cs
- DropSource.cs
- TextTreeExtractElementUndoUnit.cs
- TextParaClient.cs
- EventEntry.cs
- MailMessageEventArgs.cs
- FormatSettings.cs
- XmlIncludeAttribute.cs
- TextEffect.cs
- SystemIPv6InterfaceProperties.cs
- InvalidDataContractException.cs
- RunClient.cs
- ListChangedEventArgs.cs
- FamilyMap.cs
- WebConfigurationManager.cs
- mediaeventshelper.cs
- SortExpressionBuilder.cs
- DataMemberAttribute.cs
- LineSegment.cs
- RightsManagementEncryptedStream.cs
- FastEncoder.cs
- DbReferenceCollection.cs
- CompiledXpathExpr.cs
- CollectionChangedEventManager.cs
- ConfigXmlWhitespace.cs
- RequestNavigateEventArgs.cs
- EditorAttribute.cs
- _SingleItemRequestCache.cs
- BaseDataList.cs
- CacheDependency.cs
- ExecutionContext.cs
- CodeAccessSecurityEngine.cs
- ButtonBaseAutomationPeer.cs
- AnnouncementClient.cs
- dataobject.cs
- DBConcurrencyException.cs
- LocatorManager.cs
- TextParagraphProperties.cs
- ZipIOLocalFileHeader.cs
- SystemGatewayIPAddressInformation.cs
- XmlUtil.cs
- AuthenticationModuleElementCollection.cs
- UmAlQuraCalendar.cs
- LogicalExpressionEditor.cs
- AsymmetricKeyExchangeFormatter.cs
- ProcessHost.cs
- DbParameterHelper.cs
- File.cs
- AndCondition.cs
- EditorBrowsableAttribute.cs
- Encoder.cs
- SecurityDocument.cs
- AssertFilter.cs
- FileDialog.cs
- ScaleTransform3D.cs
- SiteOfOriginContainer.cs
- TextBoxView.cs
- MutableAssemblyCacheEntry.cs
- SimpleType.cs
- EventProxy.cs
- SmtpReplyReaderFactory.cs
- newinstructionaction.cs
- GAC.cs
- IteratorFilter.cs
- WebPartDisplayModeCollection.cs
- QilChoice.cs
- EncryptedPackageFilter.cs
- BindingGroup.cs
- RPIdentityRequirement.cs
- DataTableReader.cs
- HMACRIPEMD160.cs
- FileUtil.cs
- RepeatButton.cs
- ProcessThread.cs
- Semaphore.cs
- InfoCardClaimCollection.cs
- ApplicationException.cs
- TypeContext.cs
- FixUp.cs
- DiscoveryClientChannelFactory.cs
- MouseEventArgs.cs
- CustomSignedXml.cs
- NetworkInterface.cs
- InlineUIContainer.cs
- InfoCardRSACryptoProvider.cs
- DemultiplexingDispatchMessageFormatter.cs
- RTLAwareMessageBox.cs
- LinqDataSourceStatusEventArgs.cs
- LogicalExpr.cs
- JavaScriptObjectDeserializer.cs
- ParameterElement.cs