我正在使用WPF文本编辑器TextFormatter.我需要证明每个段落的最后一行.
像这样的东西:
I need to justify the last line in each
paragraph I need to justify the last li
ne in each paragraph I need to justify
the last line in each paragraph I need
to justify the last line in
Run Code Online (Sandbox Code Playgroud)
如何实现这一目标?
提前致谢!!
在您的TextSource实现中,在GetTextRun函数中,在每个段落的末尾返回一个TextEmbeddedObject宽度非常宽且高度为 0 的对象。
这样你就可以强制最后一行是合理的。
class MyTextEmbeddedObject : TextEmbeddedObject
{
public override LineBreakCondition BreakBefore => LineBreakCondition.BreakAlways;
public override LineBreakCondition BreakAfter => LineBreakCondition.BreakRestrained;
public override bool HasFixedSize => true;
public override CharacterBufferReference CharacterBufferReference => throw new NotImplementedException();
public override int Length => 1;
public override TextRunProperties Properties => GenericTextParagraphProperties._defaultTextRunProperties;
public override Rect ComputeBoundingBox(bool rightToLeft, bool sideways)
{
throw new NotImplementedException();
}
public override void Draw(DrawingContext drawingContext, Point origin, bool rightToLeft, bool sideways)
{
throw new NotImplementedException();
}
public override TextEmbeddedObjectMetrics Format(double remainingParagraphWidth)
{
return new TextEmbeddedObjectMetrics(10000 /* very wide width */, 0, 0);
}
}
Run Code Online (Sandbox Code Playgroud)