gpt4 book ai didi

c# - WPF TextFormatter 中最后一行的完全对齐

转载 作者:太空狗 更新时间:2023-10-29 21:56:15 27 4
gpt4 key购买 nike

我正在使用 TextFormatter 制作 WPF 文本编辑器。我需要证明每个段落中的最后 行。

类似的东西:

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

如何做到这一点?

提前致谢!

最佳答案

在您的 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);
}
}

关于c# - WPF TextFormatter 中最后一行的完全对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52316389/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com