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

[WordTextBox] Add additional features #188

Merged
merged 32 commits into from
Feb 2, 2024

Conversation

TopperDEL
Copy link
Contributor

@TopperDEL TopperDEL commented Jan 9, 2024

This PR adds the following features:

  • Use Paragraph instead of StdBlock (so that text within a TextBox is no "variable" anymore)
  • Allow changing the insets of the TextBox so that there is no gap between the text of the TextBox and its border
  • Allow the TextBox to be set to "AutoFitText" or not
  • Allow the text to be multiline by respecting the page breaks
  • Added Wrapping functionality including inline
  • Added ability to convert inline to other wrapping types and vice versa (keep in mind that some properties are lost then or go to their defaults)
  • Fixes wrong paragraph being returned when AddImage is used

Breaking change:

  • Changes WrapTextImage.InFrontText to WrapTextImage.InFrontOfText to match Word naming

TopperDEL and others added 10 commits January 9, 2024 14:37
Updated WordTextBox constructors and methods to support an enumerated type for text wrapping options, replacing the boolean flag. Introduced WrapTextImage? property and adjusted internal behavior to use new text wrapping representation, enhancing the flexibility and readability of text wrapping logic in TextBox elements. Removed obsolete code paths that previously handled the boolean wrap logic.
Rework the handling of image wrapping in Word documents by removing the ineffective WrapTextImage enum handlers and consolidating the wrap logic within WordWrapTextImage utility class. This change streamlines the wrapping functionality, improves maintainability, and prepares for future extension. Removed redundant code blocks and corrected typo for WrapTextImage.InFrontOfText. The updated utility class now provides clearer abstraction and better separation of concerns, paving the way for implementing wrap setting functionality.
Updated the AddTextBox method to accept WrapTextImage enum, replacing the less descriptive boolean parameter for text wrapping. This change enables more robust text wrapping options and improves readability by explicitly stating the wrapping style in the method signature.
Introduced an optional parameter to specify the text wrapping style when adding text boxes. Default wrap style set to 'Square' to maintain backward compatibility and enhance layout flexibility without breaking existing implementations.
Fixed a typo in the enumeration used to specify image wrapping style in the document, changing `WrapTextImage.InFrontText` to the correct `WrapTextImage.InFrontOfText`. This ensures that images wrap as intended when placed over text.
Corrected the enum value for image text wrapping from `InFrontText` to `InFrontOfText`, ensuring consistency across image wrapping functionality tests and method calls. This change aligns the code with the correct terminology, improving code clarity and preventing potential misinterpretations that could arise from using an inaccurate enum value.
@PrzemyslawKlys
Copy link
Member

I've reworked your code a bit and removed boolean and instead created proper Wrapping functionality that is identical to the one in image. Anchor implements 90% of wrapping but we're missing Inline for both TextBox and Images.

I've moved all the logic around wrapping to separate class, as I guess we will need to somehow expose other parameters of wrapping that are visible in WrapThrough and WrapTight and potentially in WrapTopBottom.

I am not sure how to do this, as I'm too noobish on classes, but maybe I'll figure it out.

This PR needs tests written before it can be commited + Add method in sections.

- Updated the AddParagraphAfterSelf method to accept an optional parameter, allowing reuse of an existing paragraph for appending, thereby enhancing flexibility when manipulating document structures.
- Introduced a new overload for AddParagraph in WordSection, enabling creation with a designated run flag for finer control over paragraph styling and rendering.
- Included a new method for adding textboxes with specified text and wrapping style to enrich content formatting capabilities within document sections.
- Adjusted AddHorizontalLine and AddHyperLink methods to explicitly pass an empty string to AddParagraph, ensuring consistent method behavior.

These changes collectively improve the document modification API, offering users more control and ease when adding and customizing various document elements. The functionality could directly address feature requests or bug fixes, though references to specific issues are not provided.
Added an overloaded constructor to the WordTextBox class to allow creating a text box with an existing WordParagraph object. This enables better reuse of paragraph instances and facilitates more flexible text box creation workflows.
Modified the `AddTextBox` method to default the text wrapping to 'Square', streamlining the text box creation process by reducing the need to specify common wrapping styles manually. This enhancement aims to improve usability for cases where the 'Square' wrapping style is frequently used.
@PrzemyslawKlys
Copy link
Member

  • Added some testing, but should be more tests on the new features that were added
  • Added option to add textbox per section

@TopperDEL
Copy link
Contributor Author

Awesome @PrzemyslawKlys! I've been in another project for over a week, but I'll come back to this one soon. Will try what you made and see where I may help. Thanks!

Text box image wrapping now supports a `Drawing` object, enabling more precise wrap configuration. The `WrapText` property has been updated to utilize `Drawing`, ensuring better control over how text wraps around images. Additionally, two new methods, `ConvertInlineToAnchor` and `ConvertAnchorToInline`, have been introduced to facilitate conversion between inline and anchored text boxes, accommodating various text flow scenarios. This addresses layout customization needs for complex document structures.
@PrzemyslawKlys
Copy link
Member

  • Added inline with text so that it works properly now
  • Added ability to convert from inline to anchor and back (as inline doesn't have some properties it removes them from anchor, and vice versa - as inline doesn't have some properties during conversion to anchor defaults are applied).
  • Fixed AddImage returning wrong paragraph which would cause issues in some cases
  • Improved testing

@PrzemyslawKlys PrzemyslawKlys merged commit 7566bad into EvotecIT:ImproveTextBox Feb 2, 2024
3 checks passed
@TopperDEL TopperDEL deleted the ImproveTextBox branch February 2, 2024 11:18
@TopperDEL
Copy link
Contributor Author

Do you plan to create a new release with these changes?

@PrzemyslawKlys
Copy link
Member

Sure, probably before Monday. I want to play with some other stuff.

@PrzemyslawKlys
Copy link
Member

Something went terribly wrong with this PR, as even tho merge went in, it didn't went in with your or my changes?

@PrzemyslawKlys
Copy link
Member

Ok i see it went into different branch

@PrzemyslawKlys
Copy link
Member

You've built on top of different branch - here's new PR to master

@TopperDEL
Copy link
Contributor Author

Sorry for the confusion! I forked your repo and create a branch for it, if I remember correctly.

@PrzemyslawKlys
Copy link
Member

Not your fault. It was mine. I was just super scared i lost everything 😂

@TopperDEL
Copy link
Contributor Author

I feel you! 😂

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.

2 participants