本文整理汇总了C#中Font.GetMaxCharBounds方法的典型用法代码示例。如果您正苦于以下问题:C# Font.GetMaxCharBounds方法的具体用法?C# Font.GetMaxCharBounds怎么用?C# Font.GetMaxCharBounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Font
的用法示例。
在下文中一共展示了Font.GetMaxCharBounds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: resizeToFitText
/**
* Adjust the size of the TextShape so it encompasses the text inside it.
*
* @return a <code>Rectangle2D</code> that is the bounds of this <code>TextShape</code>.
*/
public Rectangle2D resizeToFitText(){
String txt = GetText();
if(txt == null || txt.Length == 0) return new Rectangle2D.Float();
RichTextRun rt = GetTextRun().GetRichTextRuns()[0];
int size = rt.GetFontSize();
int style = 0;
if (rt.IsBold()) style |= Font.BOLD;
if (rt.IsItalic()) style |= Font.ITALIC;
String fntname = rt.GetFontName();
Font font = new Font(fntname, style, size);
float width = 0, height = 0, leading = 0;
String[] lines = txt.split("\n");
for (int i = 0; i < lines.Length; i++) {
if(lines[i].Length == 0) continue;
TextLayout layout = new TextLayout(lines[i], font, _frc);
leading = Math.max(leading, layout.GetLeading());
width = Math.max(width, layout.GetAdvance());
height = Math.max(height, (height + (layout.GetDescent() + layout.GetAscent())));
}
// add one character to width
Rectangle2D charBounds = font.GetMaxCharBounds(_frc);
width += GetMarginLeft() + GetMarginRight() + charBounds.Width;
// add leading to height
height += GetMarginTop() + GetMarginBottom() + leading;
Rectangle2D anchor = GetAnchor2D();
anchor.SetRect(anchor.GetX(), anchor.GetY(), width, height);
SetAnchor(anchor);
return anchor;
}