I'm making a WPF text-editor using TextFormatter
. I need to justify the last line in each paragraph.
Something like that:
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
how to make this happen?
Thanks in advance!!
In other words, we can’t give you a script that reads just the last line of a text file. But here’s a script that will make it look like you read just the last line of a text file: Set objFSO = CreateObject(“Scripting.FileSystemObject”) Set objFile = objFSO.OpenTextFile(“C:\Scripts\Test.txt”, ForReading)
If you create a new document, put some text in it (which should appear as Align left by default) and then click the Control Bar button for Justify with Last Line Aligned Left, does it work? Fixed by manually deleting all hard returns in pasted paragrahp.
As soon as an instance of the text formatter is created, the line creation process is started by calling the FormatLine method. TextFormatter calls back to the text source to retrieve the text and formatting parameters for the runs of text that form a line. In the following example, the process of formatting a text store is shown.
At the most advanced level, WPF provides an extensible text formatting engine to control every aspect of text presentation, such as text store management, text run formatting management, and embedded object management. This topic provides an introduction to WPF text formatting.
In your TextSource
implementation, in GetTextRun
function, at the end of each paragraph return an TextEmbeddedObject
object with very wide width, and with height 0.
This way you will force the last line to be justified.
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With