110,537
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// Acquire a free TextFormatter context for complex line operation
/// </summary>
/// <param name="owner">object that becomes the owner of LS context once acquired</param>
/// <param name="ploc">matching PLOC</param>
/// <returns>Active LS context</returns>
/// <SecurityNotes>
/// Critical - this sets the owner of the context
/// Safe - this doesn't expose critical info
/// </SecurityNotes>
[SecurityCritical, SecurityTreatAsSafe]
internal TextFormatterContext AcquireContext(
object owner,
IntPtr ploc
)
{
Invariant.Assert(owner != null);
TextFormatterContext context = null;
int c;
int contextCount = _contextList.Count;
for (c = 0; c < contextCount; c++)
{
context = (TextFormatterContext)_contextList[c];
if (ploc == IntPtr.Zero)
{
if(context.Owner == null)
break;
}
else if (ploc == context.Ploc.Value)
{
// LS requires that we use the exact same context for line
// destruction or hittesting (part of the reason is that LS
// actually caches some run info in the context). So here
// we use the actual PLSC as the context signature so we
// locate the one we want.
Debug.Assert(context.Owner == null);
break;
}
}
if (c == contextCount)
{
if (contextCount == 0 || !_multipleContextProhibited)
{
// no free one exists, create a new one
context = new TextFormatterContext();
_contextList.Add(context);
}
else
{
// This instance of TextFormatter only allows a single context, reentering the
// same TextFormatter in this case is not allowed.
//
// This requirement is currently enforced only during optimal break computation.
// Client implementing nesting of optimal break content inside another must create
// a separate TextFormatter instance for each content in different nesting level.
throw new InvalidOperationException(SR.Get(SRID.TextFormatterReentranceProhibited));
}
}
Debug.Assert(context != null);
context.Owner = owner;
return context;
}
这个是微软的代码