-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Porting TextBlock, Inlines, Flow Layout from WPF #5461
Conversation
…illibald/Avalonia into feature/WPFTextFormatterCompat
/// <summary> | ||
/// Defines the <see cref="FontFamily"/> property. | ||
/// </summary> | ||
public static readonly AttachedProperty<FontFamily> FontFamilyProperty = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are defined on TextElement so we should inherit them from there
@@ -548,5 +602,13 @@ public bool MoveNext() | |||
return !(Current is TextEndOfLine); | |||
} | |||
} | |||
|
|||
private static LineBreakEnumerator GetLineBreakEnumerator(TextRun run) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason behind this change?
There is something about those synthetic characters. When I add a LineBreak to the TextBlock it always uses TextSourceLength=2 for the LineBreak. I think we need to treat LineBreak etc. as actual text. |
Yes, that is extremely weird. In this branch, my current hack was to actually define |
TextSourceLength is just meant for querying runs from the text source |
I think WPF treats |
We probably want to fire up a WPF application and test |
This can be used to investigate WPF's behavior |
I think we don't have to process a synthetic LineBreak like WPF does. We can just introduce a flat |
@Gillibald Do you mean EndOfParagraph? I think the hickup in TextBlock was not about end of line, rather EndOfParagraph. |
TextEndOfParagraph is a TextEndOfLine. For TextBlock |
I am talking specifically about this: https://github.com/dotnet/wpf/blob/master/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextBlock.cs#L1406 |
Y that implicitly looks at the last run in the line. If it is a TextEndOfParagraph this is true. I don't think that synthetic runs should contribute to the text metrics. |
I think the problem was that it looks at the It feels convoluted. |
Y we don't need to mimic that. Just hold a flag in the text line metric that indicates synthetic characters (TextEndOfLine). Adding synthetic characters to the NewLineLength is a hack. |
4f409ea
to
9a27555
Compare
Hi @Gillibald and @shartte, curious how far this is away from working as I have some use of inlines in my old WPF project I would like to port. Esp inlines on TextBlock. Is it still active? Are we close to being able to
Also, I'm curious why the Avalonia implementation of TextBlock is not just exactly a copy WPF's implementation? Did you guys write all the controls from scratch? I would have thought it would be the same. |
Our API surface is 95% but you can't just take WPF's code and it magically works. WPF is heavily reliant on DIrectWrite and isn't very portable. So the challenge here is to reimplement everything underneath WPF's API to make everything else portable. This PR will be continued early next year |
Yes, we rewrite all the controls from scratch. Avalonia started in late 2013 but WPF wasn't open sourced until late 2018 so for the first 5 years of the project we couldn't use WPF sources. |
@Gillibald this PR has a lot of conflicts by now. Is it worth keeping open? |
We can close it. I need to rework most of it. |
Should I interpret this closure as meaning that AvaloniaEdit does not currently support rich text? |
This work was about porting WPF's text tree and in some extend bringing FlowDocument to Avalonia. It was an attempt of multiple and was closed because it wasn't in a state we could move further. Avalonia now supports proper whitespace handling via XamlX and also has inlines support. We will most likely port WPF's text tree and other parts of FlowDocument in the near future. This is highly reliant on demand and funding. |
Sorry for being off-topic but I'd just like to throw this idea in here. It's going to be a huge task but if you ever get to it, please consider to keep an option open for some features that were lacking in the original WPF and finally rendered it unusable for my purpose:
IsHyphenationEnabled was restricted to only four languages: English, Spanish, French, and German. It is related to the spell-checking dictionaries which could be extended for extra jargon but did not allow adding any full dictionary. If this feature would have been available at that time it would have entirely removed Adobe InDesign from my workflow. It's probably far out of scope, but if you could ever get Avalonia to natively render PDF, your audience would instantly increase. This is a feature that some Winforms and WPF users have wanted for decades. There are many commercial solutions (most of them not native .Net). The best open source PDF in .Net that I am aware of is PdfSharp which is far from mature. Bottom line: If you could bring typesetting and native PDF into scope I think there would be allot more demand and possibly funding from a wider audience outside the cross-platform-ui domain... |
As requested by @Gillibald, a branch for discussing work on porting the inline work from WPF.