Skip to content

Conversation

@rasamassen
Copy link

@rasamassen rasamassen commented Sep 13, 2025

Description

Create PreserveText

Checklist:

  • My CI is 🟢
  • I have covered by unit tests my new code (check build/coverage for coverage report)
  • I have updated the documentation to describe the changes
  • I have updated the changelog

@rasamassen rasamassen changed the title Create PreserveText.php RTF Writer: Create PreserveText.php Sep 13, 2025
@coveralls
Copy link

coveralls commented Sep 13, 2025

Coverage Status

coverage: 96.622% (-0.1%) from 96.757%
when pulling c58ea5e on rasamassen:preserveText
into 0ab0b49 on PHPOffice:master.

@rasamassen
Copy link
Author

The description of preserveText in (Samples)[https://github.com/PHPOffice/PHPWord/blob/master/docs/usage/elements/preservetext.md] suggests that preserveText can be used to add Fields. This feels odd since there is already a field element? My current commit adds fields as described.

But what is the point of preserveText? preserveText sounds like it's supposed to be used for adding things like whitespace and special characters (like braces and slashes), but text already does that just fine. Instead of "preserving" the text, it currently adds fields.

So though I've built this like described, I'm confused what the purpose of the element is?

@rasamassen rasamassen changed the title RTF Writer: Create PreserveText.php RTF Writer: PreserveText - Create Oct 4, 2025
oleibman added a commit to oleibman/PHPWord that referenced this pull request Nov 21, 2025
I made RTF usable some time ago. @rasamassen has recently done a lot of useful work to cover many missing areas. Since who knows when those changes will be merged, I intend to incorporate much of that work. I will do this with several pushes, each based on one or more of those changes. This one is based on PR PHPOffice#2824 (fixes issue PHPOffice#344), and PR PHPOffice#2826. Widow-orphan control may be affected by this change; based on comments in 2824, I have added a document-level widow-control used only by Rtf, but do not, as yet, use that value to do anything other than read/write an appropriate instruction in the file header.
@oleibman
Copy link
Contributor

You are correct that PreserveText isn't absolutely required, but it can make things a lot simpler.

$footer->addPreserveText('Page {PAGE} of {NUMPAGES}');

is much easier than adding a TextRun consisting of Text/Field/Text/Field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants