private static void AllocateLongTextSpace(ViewLayoutContext context,
Graphics g,
StandardContentMemento memento,
IPaletteContent paletteContent,
IContentValues contentValues,
PaletteState state,
Rectangle displayRect,
RightToLeft rtl,
int spacingGap,
ref Size[,] allocation,
bool composition)
{
// By default, we cannot draw the text
memento.DrawLongText = false;
// Get the defined text for display
string longText = contentValues.GetLongText();
// Is there any text to be drawn?
if ((longText != null) && (longText.Length > 0))
{
// If the text is not allowed to span multiple lines
if (paletteContent.GetContentLongTextMultiLine(state) == InheritBool.False)
{
// Replace any carriage returns and newlines with just spaces
longText = longText.Replace("\r\n", " ");
longText = longText.Replace("\n", " ");
longText = longText.Replace("\r", " ");
}
// Convert from alignment enums to integers
int alignHIndex = RightToLeftIndex(rtl, paletteContent.GetContentLongTextH(state));
int alignVIndex = (int)paletteContent.GetContentLongTextV(state);
// Cache the rendering hint used
memento.LongTextHint = CommonHelper.PaletteTextHintToRenderingHint(paletteContent.GetContentLongTextHint(state));
memento.LongTextTrimming = paletteContent.GetContentLongTextTrim(state);
bool fontChanged = false;
Font textFont = paletteContent.GetContentLongTextFont(state);
// Get the appropriate font to use in the caption area
if (paletteContent.GetContentStyle() == PaletteContentStyle.HeaderForm)
{
Font captionFont = ContentFontForButtonForm(context, textFont);
fontChanged = (captionFont != textFont);
textFont = captionFont;
}
// Get a pixel accurate measure of text drawing space needed
memento.LongTextMemento = AccurateText.MeasureString(g,
rtl,
longText,
textFont,
memento.LongTextTrimming,
paletteContent.GetContentLongTextMultiLineH(state),
paletteContent.GetContentLongTextPrefix(state),
memento.LongTextHint,
composition,
fontChanged);
// Space required for long text starts with the text width itself
Size requiredSpace = memento.LongTextMemento.Size;
// Find the space available given our required alignment
if (AllocateAlignmentSpace(alignHIndex, alignVIndex,
allocation, displayRect,
spacingGap, memento.LongTextTrimming,
ref requiredSpace))
{
// Cache the actual draw size of the text
memento.LongTextRect.Size = requiredSpace;
// Mark the memento to draw the long text
memento.DrawLongText = true;
}
}
}