Skip to content
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

Advanced Text tool improvements and new features #431

Merged
merged 10 commits into from
Sep 13, 2022

Conversation

tannerhelland
Copy link
Owner

Solves #428 . Many thanks to @0lm for submitting a detailed feature request!

This pull request adds the following features to the advanced text tool.

  • Justified text alignment. Most photo editors do not expose this feature because it's complicated to implement, and native text renderers frequently do not support this at a library level. (For example, Windows provides no native way to draw justified text, whether via GDI or GDI+. DirectWrite finally supported this as of Windows 8, but alas that doesn't help me in PhotoDemon since I need to support XP/Vista/7, too!)

Anyway, long story short is that PhotoDemon's justified alignment is implemented manually. Please let me know if you encounter any oddities.

  • Justified text alignment supports multiple paragraphs in a single text layer, with custom control over last-line (trailing) behavior. Trailing line behavior has its own justification setting and it can be left/center/right/jully justified independent of the paragraph as a whole.

  • Text fill and outline can now rendered in either order (outline above fill, or fill above outline).

  • A new "smooth" antialias setting is now exposed, in additional to the previous "none", "normal", "crisp" settings. Note that Photoshop exposes an additional "strong" setting, but PhotoDemon's settings do not map 1:1 to Photoshop's by design, because PD exposes hinting as its own property (whereas Photoshop mixes that into its antialiasing settings). So if you're trying to match Photoshop settings - which alas is not 100% possible due to underlying font rendering differences - remember to play with both antialiasing AND hinting to achieve the look you want.

Relates to #428

I also cleaned up some other icons while here, so the resource size has actually shrunk slightly from its previous version.
This guarantees correct focus rect appearance when a control has been interacted with via both mouse *and* keyboard
Relates to #428

Because one text tool will support justified text (advanced text) and one will not (basic text), extra mapping code is needed to ensure text layers can still be converted between the two types.

This commit also adds the necessary UI for a new "justified" alignment, but the justification algorithm has *not* been implemented yet
...with whitespace characters.  (We can expand the line only in the whitespace locations.)

Relates to #428 .

The canonical best-case implementation of this feature would be the Knuth-Plass linebreaking algorithm:

https://eprg.org/G53DOC/pdfs/knuth-plass-breaking.pdf

I'd love to tackle that someday, but I've yet to fully wrap my brain around it.  Instead, this commit uses a straightforward greedy approach that was easy to slot into PD's existing line-breaking algorithm.

Still TODO:
+ justifying lines that have no whitespace chars
+ variable handling of the last line in a paragraph (the user should really have control over this, like Photoshop provides)
Relates to #428

- Lines with whitespace are now justified using whitespace only.
- Lines without whitespace are justified using inter-character spacing.
- A ton of weird edge-cases have been addressed and fixed (seriously, there are a lot of ways for justified text to go horribly wrong)

Next up is a UI for the user to select trailing line justification behavior.  (Photoshop allows the user to select between left/center/right/justified for just the trailing line, as a separate setting - and it's a nice feature.)

Still TODO is handling multi-paragraph text.  Technically the trailing line setting should apply to the trailing line of *each* paragraph in a text layer, but I want to get it working for *just* the last line of *all* paragraphs before I tackle that.
...now user-controllable, with full support for last-line alignment to the left, center, right, or fully justified like the preceding paragraph!

Relates to #428

Photoshop is the only other photo editor (at all, to my knowledge) that provides this level of control over text justification.  Most photo editors don't provide justified alignment at all, and even those that do (GIMP) fail to handle multi-paragraph text layers correctly.

All these cases are now handled correctly in PhotoDemon, and the user has full control over the process.  Big win for us, IMO  👍

(Also, the new setting can of course be persisted to/from PDI files, as expected.)
Relates to #428 .  Thank you to 0lm for the suggestion.

The advanced text tool now lets you render text in either fill > outline, or outline > fill order.  This can improve the clarity of filled+outlined text, especially at small font sizes and/or large outline stroke widths.
Relates to #428 .  Thank you to @0lm for the suggestion!

This new setting is primarily useful for softening glyph edges at large sizes; at small sizes, the aggressive edge sampling may be undesirable.

Note also that PhotoDemon exposes font hinting as a separate setting.  (In Photoshop, hinting is "merged" into the various antialiasing settings.)  This allows for a comprehensive range of glyph fit options by mixing both hinting *and* antialias settings in PD.
...by generating updated language files with new text tool phrases.
@tannerhelland tannerhelland merged commit 90eb363 into main Sep 13, 2022
@tannerhelland tannerhelland deleted the text-tool-improvements branch September 13, 2022 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant