代码之家  ›  专栏  ›  技术社区  ›  google dev

wpftextformatter中最后一行的完全对正

  •  6
  • google dev  · 技术社区  · 6 年前

    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
    

    如何做到这一点?

    提前谢谢!!

    1 回复  |  直到 6 年前
        1
  •  2
  •   codeDom    6 年前

    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);
        }
    }