TextFragment.h
1 #pragma once
2 // Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved.
3 
4 #include <system/eventhandler.h>
5 #include <system/array.h>
6 
7 #include "Aspose.PDF.Cpp/Text/TextState.h"
8 #include "Aspose.PDF.Cpp/Text/TextSegmentCollection.h"
9 #include "Aspose.PDF.Cpp/Generator/BaseParagraph.h"
10 #include "Aspose.PDF.Cpp/aspose_pdf_api_defs.h"
11 
12 namespace Aspose
13 {
14 namespace Pdf
15 {
16 namespace Annotations
17 {
18 class TextMarkupAnnotation;
19 } // namespace Annotations
20 class ApsToPdfConverter;
21 class Cell;
22 class Cells;
23 namespace Drawing
24 {
25 class Graph;
26 class Line;
27 } // namespace Drawing
28 namespace Engine
29 {
30 namespace CommonData
31 {
32 namespace Text
33 {
34 namespace Segmenting
35 {
36 class PhysicalTextSegment;
37 class SegmentsGroupState;
38 class TextSegmenter;
39 } // namespace Segmenting
40 } // namespace Text
41 } // namespace CommonData
42 namespace IO
43 {
44 namespace ConvertStrategies
45 {
46 class SearchablePdfConvertStrategy;
47 } // namespace ConvertStrategies
48 } // namespace IO
49 } // namespace Engine
50 namespace Facades
51 {
52 class PdfContentEditor;
53 } // namespace Facades
54 class FlowConverter;
55 class Heading;
56 enum class HorizontalAlignment;
57 class Hyperlink;
58 class Image;
59 class Note;
60 class Page;
61 class PageGenerator;
62 namespace PdfToMarkdown
63 {
64 class ContentModelTools;
65 class HeuristicHeaderDetector;
66 class OutlinesHeaderDetector;
67 class PageContentModel;
68 class PageLayoutViewer;
69 class TableContentModel;
70 } // namespace PdfToMarkdown
71 namespace Plugins
72 {
73 class TocGenerator;
74 } // namespace Plugins
75 class Rectangle;
76 class Table;
77 namespace Tests
78 {
79 namespace PDFUA
80 {
81 class PDFUA_CreatingTests;
82 } // namespace PDFUA
83 class RegressionTests_v19_1;
84 class RegressionTests_v24_03;
85 } // namespace Tests
86 namespace Text
87 {
88 class Font;
89 class MarkupParagraph;
90 class MarkupSection;
91 class PageMarkup;
92 class Position;
93 class TableAbsorber;
94 class TabStop;
95 class TabStops;
96 class TextBuilder;
97 class TextFragmentAbsorber;
98 class TextFragmentCollection;
99 class TextFragmentState;
100 class TextParagraph;
101 class TextPostReplaceFixer;
102 class TextReplaceOptions;
103 class TextSegment;
104 } // namespace Text
105 class TextStamp;
106 enum class VerticalAlignment;
107 class XForm;
108 } // namespace Pdf
109 } // namespace Aspose
110 namespace System
111 {
112 namespace Collections
113 {
114 namespace Generic
115 {
116 template <typename> class List;
117 } // namespace Generic
118 } // namespace Collections
119 class EventArgs;
120 namespace Xml
121 {
122 class XmlReader;
123 class XmlTextWriter;
124 } // namespace Xml
125 } // namespace System
126 
127 namespace Aspose {
128 
129 namespace Pdf {
130 
131 namespace Text {
132 
173 class ASPOSE_PDF_SHARED_CLASS TextFragment : public Aspose::Pdf::BaseParagraph
174 {
175  typedef TextFragment ThisType;
177 
178  typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
179  ASPOSE_PDF_SHARED_RTTI_INFO_DECL();
180 
181  friend class Aspose::Pdf::ApsToPdfConverter;
184  friend class Aspose::Pdf::Engine::IO::ConvertStrategies::SearchablePdfConvertStrategy;
189  friend class Aspose::Pdf::Text::TextPostReplaceFixer;
190  friend class Aspose::Pdf::Heading;
191  friend class Aspose::Pdf::Image;
192  friend class Aspose::Pdf::PageGenerator;
195  friend class Aspose::Pdf::Page;
197  friend class Aspose::Pdf::Cell;
198  friend class Aspose::Pdf::Cells;
203  friend class Aspose::Pdf::XForm;
204  friend class Aspose::Pdf::Table;
206  friend class Aspose::Pdf::PdfToMarkdown::HeuristicHeaderDetector;
207  friend class Aspose::Pdf::PdfToMarkdown::OutlinesHeaderDetector;
208  friend class Aspose::Pdf::PdfToMarkdown::PageContentModel;
209  friend class Aspose::Pdf::PdfToMarkdown::PageLayoutViewer;
210  friend class Aspose::Pdf::PdfToMarkdown::TableContentModel;
211  friend class Aspose::Pdf::PdfToMarkdown::ContentModelTools;
212  friend class Aspose::Pdf::FlowConverter;
213  friend class Aspose::Pdf::Tests::PDFUA::PDFUA_CreatingTests;
214  friend class Aspose::Pdf::Tests::RegressionTests_v19_1;
215  friend class Aspose::Pdf::Tests::RegressionTests_v24_03;
216 
217 protected:
218 
224  {
228  NoAdjustment,
232  KeepOriginalPosition,
236  AdjustOnTextFragmentPosition
237  };
238 
239 
240 public:
241 
245  ASPOSE_PDF_SHARED_API const System::SharedPtr<TextReplaceOptions>& get_ReplaceOptions() const;
253  ASPOSE_PDF_SHARED_API System::String get_Text();
261  ASPOSE_PDF_SHARED_API void set_Text(System::String value);
265  ASPOSE_PDF_SHARED_API Aspose::Pdf::VerticalAlignment get_VerticalAlignment() override;
269  ASPOSE_PDF_SHARED_API void set_VerticalAlignment(Aspose::Pdf::VerticalAlignment value) override;
273  ASPOSE_PDF_SHARED_API Aspose::Pdf::HorizontalAlignment get_HorizontalAlignment() override;
277  ASPOSE_PDF_SHARED_API void set_HorizontalAlignment(Aspose::Pdf::HorizontalAlignment value) override;
281  ASPOSE_PDF_SHARED_API void set_Hyperlink(System::SharedPtr<Aspose::Pdf::Hyperlink> value) override;
297  ASPOSE_PDF_SHARED_API System::SharedPtr<TextFragmentState> get_TextState();
311  ASPOSE_PDF_SHARED_API System::SharedPtr<TextSegmentCollection> get_Segments() const;
325  ASPOSE_PDF_SHARED_API void set_Segments(System::SharedPtr<TextSegmentCollection> value);
334  ASPOSE_PDF_SHARED_API System::SharedPtr<Aspose::Pdf::Text::Position> get_Position();
343  ASPOSE_PDF_SHARED_API void set_Position(System::SharedPtr<Aspose::Pdf::Text::Position> value);
348  ASPOSE_PDF_SHARED_API System::SharedPtr<Aspose::Pdf::Text::Position> get_BaselinePosition();
353  ASPOSE_PDF_SHARED_API void set_BaselinePosition(System::SharedPtr<Aspose::Pdf::Text::Position> value);
357  ASPOSE_PDF_SHARED_API System::SharedPtr<Aspose::Pdf::Rectangle> get_Rectangle();
364  ASPOSE_PDF_SHARED_API System::SharedPtr<Aspose::Pdf::Page> get_Page() const;
371  ASPOSE_PDF_SHARED_API System::SharedPtr<XForm> get_Form() const;
375  ASPOSE_PDF_SHARED_API int32_t get_WrapLinesCount() const;
379  ASPOSE_PDF_SHARED_API void set_WrapLinesCount(int32_t value);
383  ASPOSE_PDF_SHARED_API System::SharedPtr<Note> get_EndNote() const;
387  ASPOSE_PDF_SHARED_API void set_EndNote(System::SharedPtr<Note> value);
391  ASPOSE_PDF_SHARED_API System::SharedPtr<Note> get_FootNote() const;
395  ASPOSE_PDF_SHARED_API void set_FootNote(System::SharedPtr<Note> value);
396 
400  ASPOSE_PDF_SHARED_API TextFragment();
405  ASPOSE_PDF_SHARED_API TextFragment(System::SharedPtr<TabStops> tabStops);
411  ASPOSE_PDF_SHARED_API TextFragment(System::String text);
417  ASPOSE_PDF_SHARED_API TextFragment(System::String text, System::SharedPtr<TabStops> tabStops);
418 
425  ASPOSE_PDF_SHARED_API System::SharedPtr<TextSegmentCollection> IsolateTextSegments(int32_t startIndex, int32_t length);
430  ASPOSE_PDF_SHARED_API System::SharedPtr<System::Object> Clone() override;
435  virtual ASPOSE_PDF_SHARED_API System::SharedPtr<System::Object> CloneWithSegments();
436 
437 protected:
438 
439  Aspose::Pdf::Text::TextState::AttachState get_AttachedState() const;
440  void set_AttachedState(Aspose::Pdf::Text::TextState::AttachState value);
444  ASPOSE_PDF_SHARED_API void set_ReplaceOptions(System::SharedPtr<TextReplaceOptions> value);
445  System::String get_McName() const;
446  int32_t get_McId() const;
447 
449 
467  ASPOSE_PDF_SHARED_API void set_TextState(System::SharedPtr<TextFragmentState> value);
471  System::SharedPtr<TextFragmentCollection> get_Fragments() const;
475  void set_Fragments(System::SharedPtr<TextFragmentCollection> value);
479  ASPOSE_PDF_SHARED_API void set_Rectangle(System::SharedPtr<Aspose::Pdf::Rectangle> value);
486  ASPOSE_PDF_SHARED_API void set_Page(System::SharedPtr<Aspose::Pdf::Page> value);
494  bool get_IsPositionChanged() const;
495 
502  void SetEncodedTextProperties(System::SharedPtr<Font> font, System::String text, System::ArrayPtr<int32_t> indices);
511  void IsolateToSingleSegment();
516  void IsolateToText();
517  static System::SharedPtr<Aspose::Pdf::Rectangle> GetGroupRectangle(System::SharedPtr<TextSegmentCollection> segments, int32_t firstSegmentBeginIndex, int32_t lastSegmentEndIndex, bool measureLastTechnicalSpacings);
518  System::SharedPtr<Aspose::Pdf::Rectangle> ComputeUnderlineRectangle();
519  System::ArrayPtr<System::SharedPtr<Aspose::Pdf::Engine::CommonData::Text::Segmenting::PhysicalTextSegment>> GetAttachedPhysicalSegmentsArray(int32_t& firstSegmentIndex, int32_t& lastSegmentIndex);
520  void ResetTabstops();
529  bool IsMultiline();
538  bool IsMultilineOrSubscript();
539 
540  TextFragment(System::String text, System::SharedPtr<TextSegmentCollection> segments);
541 
542  MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(TextFragment, CODEPORTING_ARGS(System::String text, System::SharedPtr<TextSegmentCollection> segments));
543 
545 
546  MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(TextFragment, CODEPORTING_ARGS(System::SharedPtr<Aspose::Pdf::Engine::CommonData::Text::Segmenting::TextSegmenter> segmenter, System::String text, System::SharedPtr<TextSegmentCollection> segments));
547  void SyncVerticalAlignment(Aspose::Pdf::VerticalAlignment verticalAlignment);
548  void SyncHorizontalAlignment(Aspose::Pdf::HorizontalAlignment horizontalAlignment1);
583  void SetMarkedContentProperties(System::String name, int32_t id);
584  void Assign(System::SharedPtr<TextFragment> fragment);
585  void AssignWithSegments(System::SharedPtr<TextFragment> fragment);
586  ASPOSE_PDF_SHARED_API void Serialize(System::SharedPtr<System::Xml::XmlTextWriter> writer) override;
587  ASPOSE_PDF_SHARED_API void Deserialize(System::SharedPtr<System::Xml::XmlReader> reader) override;
588 
589  virtual ASPOSE_PDF_SHARED_API ~TextFragment();
590 
591 private:
592 
593  System::String text;
604  System::SharedPtr<Note> endNote;
605  System::SharedPtr<Note> footNote;
606  bool isTextChanged;
607  bool isPositionChanged;
608  int32_t wrapLinesCount;
609  System::SharedPtr<TextReplaceOptions> pr_ReplaceOptions;
610  System::String pr_McName;
611 
612  void set_McName(System::String value);
613 
614  int32_t mcId;
615 
616  void set_McId(int32_t value);
617 
619 
624  void InitializeDetachedFragment(System::String text);
629  void InitializeDetachedFragment(System::String text, System::SharedPtr<TabStops> tabStops);
630  void ApplyTabstops(System::SharedPtr<TextSegment> segment);
632  System::SharedPtr<TabStop> GetNextTabStop(double currentPosition, double tabDefault);
636  void InitializeAttachedFragment(System::String text, System::SharedPtr<TextSegmentCollection> segments);
642  void RegisterSegment(System::SharedPtr<TextSegment> textSegment);
644  void OnSegmentPositionChanged(System::SharedPtr<System::Object> sender, System::SharedPtr<System::EventArgs> args);
645  void OnSegmentTextChanged(System::SharedPtr<System::Object> sender, System::SharedPtr<System::EventArgs> args);
646  void UpdateTextWithSegments();
647  void ReComputeRectangle();
648  void ComputeRectangle();
649  void SetTextMultiline(System::String text);
650  double GetTextWidth();
651  double GetIsolatedTextWidth(double originalWidth);
652  void ApplyPostRelaceAdjustment(double beforeReplacementTextWidth);
653  void AdjustNextSegment(double xIndent, double yIndent);
654 
655 };
656 
657 } // namespace Text
658 } // namespace Pdf
659 } // namespace Aspose
660 
661 
Represents graph - graphics generator paragraph.
Definition: Graph.h:53
VerticalAlignment
Enumeration of possible vertical alignment values.
Definition: VerticalAlignment.h:16
String class used across the library. Is a substitute for C# System.String when translating code...
Definition: string.h:121
class ASPOSECPP_SHARED_CLASS List
Definition: ienumerable.h:17
Represents a cells collection of row.
Definition: Cells.h:43
Represents fragment of Pdf text.
Definition: TextFragment.h:173
Represents line.
Definition: Line.h:43
SegmentAdjustmentMethod
The method to use to adjust the position of a trailing physical segment (created when isolating a tex...
Definition: TextFragment.h:223
Definition: Artifact.h:67
Represents text paragraphs as multiline text object.
Definition: TextParagraph.h:86
Represents an absorber object of text fragments. Performs text search and provides access to search r...
Definition: TextFragmentAbsorber.h:81
HorizontalAlignment
Describes horizontal alignment.
Definition: HorizontalAlignment.h:16
Definition: signed_info.h:13
Represents heading.
Definition: Heading.h:58
Represents a markup section - the rectangular region of a page that contains text and can be visually...
Definition: MarkupSection.h:45
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: fwd.h:22
means saving in XML format
Appends text object to Pdf page.
Definition: TextBuilder.h:77
System::EventHandler OnRectChanged
Definition: TextFragment.h:448
Represents Aspose.PDF TocGenerator plugin.
Definition: TocGenerator.h:33
Class representing page of PDF document.
Definition: Page.h:364
Definition: AFRelationship.h:4
Subclass of System::SmartPtr which sets itself to weak mode at construction. Please note that this cl...
Definition: TextFragmentState.h:69
Defies a method that enables object cloning - creating a copy of an object. Objects of this class sho...
Definition: icloneable.h:15
Represents textual stamp.
Definition: TextStamp.h:69
Represents a cell of the table&#39;s row.
Definition: Cell.h:65
AttachState
Enum for attached state of the objects
Definition: TextState.h:174
List forward declaration.
Definition: Artifact.h:74
The coordinates are in the page coordinate context.
Represents a paragraph.
Definition: MarkupParagraph.h:52
Don&#39;t change the automatically calculated physical segment position.
Represents a text state of a text fragment.
Definition: TextFragmentState.h:97
Page markup represented by collections of MarkupSection and MarkupParagraph.
Definition: PageMarkup.h:52
Represents image.
Definition: Image.h:66
Abstract base class for text markup annotations.
Definition: TextMarkupAnnotation.h:57
Represents a class to edit PDF file&#39;s content.
Definition: PdfContentEditor.h:89
Class represent XForm
Definition: XForm.h:185
Represents a table that can be added to the page.
Definition: Table.h:86
Represents a abstract base object can be added to the page(doc.Paragraphs.Add()). ...
Definition: BaseParagraph.h:66
MulticastDelegate< void(System::SharedPtr< Object >, TEventArgs)> EventHandler
Represents a method that reacts to and processes an event. This type should be allocated on stack and...
Definition: eventhandler.h:16
Represents an absorber object of table elements. Performs search and provides access to search result...
Definition: TableAbsorber.h:63
Whole PDF file will be submitted.