本文整理汇总了C#中StringFormat.SetMeasurableCharacterRanges方法的典型用法代码示例。如果您正苦于以下问题:C# StringFormat.SetMeasurableCharacterRanges方法的具体用法?C# StringFormat.SetMeasurableCharacterRanges怎么用?C# StringFormat.SetMeasurableCharacterRanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringFormat
的用法示例。
在下文中一共展示了StringFormat.SetMeasurableCharacterRanges方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MeasureWordsSize
/// <summary>
/// Assigns words its width and height
/// </summary>
/// <param name="g"></param>
internal void MeasureWordsSize(Graphics g)
{
if (_wordsSizeMeasured) return;
//Measure white space if not yet done
if (float.IsNaN(_actualWordSpacing))
MeasureWordSpacing(g);
if (HtmlTag != null && HtmlTag.TagName.Equals("img", StringComparison.CurrentCultureIgnoreCase))
{
#region Measure image
CssBoxWord word = new CssBoxWord(this, CssValue.GetImage(GetAttribute("src")));
Words.Clear();
Words.Add(word);
#endregion
}
else
{
#region Measure text words
bool lastWasSpace = false;
foreach (CssBoxWord b in Words)
{
bool collapse = CssBoxWordSplitter.CollapsesWhiteSpaces(this);
if (CssBoxWordSplitter.EliminatesLineBreaks(this)) b.ReplaceLineBreaksAndTabs();
if (b.IsSpaces)
{
b.Height = FontLineSpacing;
if (b.IsTab)
{
b.Width = ActualWordSpacing * 4; //TODO: Configure tab size
}
else if (b.IsLineBreak)
{
b.Width = 0;
}
else
{
if (!(lastWasSpace && collapse))
{
b.Width = ActualWordSpacing * (collapse ? 1 : b.Text.Length);
}
}
lastWasSpace = true;
}
else
{
string word = b.Text;
CharacterRange[] measurable = { new CharacterRange(0, word.Length) };
StringFormat sf = new StringFormat();
sf.SetMeasurableCharacterRanges(measurable);
Region[] regions = g.MeasureCharacterRanges(word, ActualFont,
new RectangleF(0, 0, float.MaxValue, float.MaxValue),
sf);
SizeF s = regions[0].GetBounds(g).Size;
PointF p = regions[0].GetBounds(g).Location;
b.LastMeasureOffset = new PointF(p.X, p.Y);
b.Width = s.Width;// +p.X;
b.Height = s.Height;// +p.Y;
lastWasSpace = false;
}
}
#endregion
}
_wordsSizeMeasured = true;
}
示例2: WhiteSpace
/// <summary>
/// Gets the white space width of the specified box
/// </summary>
/// <param name="g"></param>
/// <param name="b"></param>
/// <returns></returns>
public static float WhiteSpace(Graphics g, CssBox b)
{
string space = " .";
float w = 0f;
float onError = 5f;
StringFormat sf = new StringFormat();
sf.SetMeasurableCharacterRanges(new CharacterRange[] { new CharacterRange(0, 1) });
Region[] regs = g.MeasureCharacterRanges(space, b.ActualFont, new RectangleF(0, 0, float.MaxValue, float.MaxValue), sf);
if (regs == null || regs.Length == 0) return onError;
w = regs[0].GetBounds(g).Width;
if (!(string.IsNullOrEmpty(b.WordSpacing) || b.WordSpacing == CssConstants.Normal))
{
w += CssValue.ParseLength(b.WordSpacing, 0, b);
}
return w;
}