3#ifndef PDFSDK_CXX_TEXT_EDIT_H_INCLUDED_
4#define PDFSDK_CXX_TEXT_EDIT_H_INCLUDED_
6#include <pdfsdk/cxx/element.h>
7#include <pdfsdk/cxx/math.h>
8#include <pdfsdk/cxx/text_run.h>
11#include "forward_declarations.h"
12#include "wrapper_base.h"
25class Layout :
public detail::RefCountedHandle<PDTLayout> {
117 PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(
Layout, PDTLayout)
123class TextBlock :
public detail::RefCountedHandle<PDTTextBlock> {
194 PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(
TextBlock, PDTTextBlock)
391 PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(
CharIterator, PDTCharIterator)
399class TextCommand :
public detail::RefCountedHandle<PDTTextCommand> {
651 PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(
TextCommand, PDTTextCommand)
656 PDF_CHECK_SUCCESS_X(PDPageBuildTextLayout(page.get(), &text_layout));
662 PDF_CHECK_SUCCESS_X(PDEFormXObjectBuildTextLayout(doc.get(), xform.get(), &text_layout));
668 PDF_CHECK_SUCCESS_X(PDTLayoutNewTextBlock(m_handle, index, &text_block));
673 PDF_CHECK_SUCCESS_X(PDTLayoutInsertTextBlock(m_handle, index, text_block.get()));
677 PDF_CHECK_SUCCESS_X(PDTLayoutRemoveTextBlock(m_handle, index));
681 size_t num_blocks = 0;
682 PDF_CHECK_SUCCESS_X(PDTLayoutGetNumTextBlocks(m_handle, &num_blocks));
688 PDF_CHECK_SUCCESS_X(PDTLayoutGetTextBlock(m_handle, index, &text_block));
693 size_t index = kPDPageIndexNull;
694 PDF_CHECK_SUCCESS_X(PDTLayoutGetTextBlockIndex(m_handle, text_block.get(), &index));
700 PDF_CHECK_SUCCESS_X(PDTCharIteratorAtBeginPage(m_handle, &char_begin));
706 PDF_CHECK_SUCCESS_X(PDTCharIteratorAtEndPage(m_handle, &char_end));
712 PDF_CHECK_SUCCESS_X(PDTCharIteratorAtPoint(m_handle, &point, &char_iter));
718 PDF_CHECK_SUCCESS_X(PDTCharIteratorForItem(m_handle, text_run.get(), char_index, &char_iter));
724 PDF_CHECK_SUCCESS_X(PDTCharIteratorForItemAtPoint(m_handle, text_run.get(), &point, &char_iter));
729 return PDTTextBlockEqual(m_handle, that.get());
734 PDF_CHECK_SUCCESS_X(PDTTextBlockGetPosition(m_handle, &position));
740 PDF_CHECK_SUCCESS_X(PDTTextBlockGetSize(m_handle, &size));
745 float rotation = 0.f;
746 PDF_CHECK_SUCCESS_X(PDTTextBlockGetRotate(m_handle, &rotation));
751 bool reflected =
false;
752 PDF_CHECK_SUCCESS_X(PDTTextBlockIsReflected(m_handle, &reflected));
758 PDF_CHECK_SUCCESS_X(PDTTextBlockGetBBox(m_handle, &bbox));
764 PDF_CHECK_SUCCESS_X(PDTTextBlockGetCharBegin(text_layout.get(), m_handle, &char_begin));
770 PDF_CHECK_SUCCESS_X(PDTTextBlockGetCharEnd(text_layout.get(), m_handle, &char_end));
776 PDF_CHECK_SUCCESS_X(PDTTextBlockCreateTextElement(m_handle, &text_object));
782 PDF_CHECK_SUCCESS_X(PDTTextBlockIsExplicitWidth(m_handle, &value));
787 PDF_CHECK_SUCCESS_X(PDTTextBlockSetExplicitWidth(m_handle, value));
792 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetBlockBegin(m_handle, &char_iter));
798 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetBlockEnd(m_handle, &char_iter));
804 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetParaBegin(m_handle, &char_iter));
810 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetParaEnd(m_handle, &char_iter));
816 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetLineBegin(m_handle, &char_iter));
822 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetLineEnd(m_handle, &char_iter));
828 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetWordBegin(m_handle, &char_iter));
834 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetWordEnd(m_handle, &char_iter));
840 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetSpanBegin(m_handle, &char_iter));
846 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetSpanEnd(m_handle, &char_iter));
852 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetAbove(m_handle, &char_iter));
858 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetAboveAtPage(m_handle, prev_page_text_layout.get(), &char_iter));
864 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetBelow(m_handle, &char_iter));
870 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetBelowAtPage(m_handle, next_page_text_layout.get(), &char_iter));
876 PDF_CHECK_SUCCESS_X(PDTCharIteratorCopy(m_handle, ©));
881 PDF_CHECK_SUCCESS_X(PDTCharIteratorIncrement(m_handle));
885 PDF_CHECK_SUCCESS_X(PDTCharIteratorDecrement(m_handle));
889 PDF_CHECK_SUCCESS_X(PDTCharIteratorAdvance(m_handle, n));
894 PDF_CHECK_SUCCESS_X(PDTCharIteratorDistance(m_handle, that.get(), &dist));
900 PDF_CHECK_SUCCESS_X(PDTCharIteratorLess(m_handle, that.get(), &less));
906 PDF_CHECK_SUCCESS_X(PDTCharIteratorEqual(m_handle, that.get(), &equal));
911 return ::PDF::detail::GetWstringProperty(PDTCharIteratorGetUnicode, m_handle);
915 size_t page_index = kPDPageIndexNull;
916 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetPageIndex(m_handle, &page_index));
922 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetQuad(m_handle, &quad));
928 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetOutlineQuad(m_handle, &quad));
934 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetTextBlock(m_handle, &text_block));
940 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetFontAttrs(m_handle, &font_attrs));
946 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetParaAttrs(m_handle, ¶_attrs));
952 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetListAttrs(m_handle, &list_attrs));
958 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetTransform(m_handle, &matrix));
964 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetTextItem(m_handle, &text_run));
970 PDF_CHECK_SUCCESS_X(PDTCreateDeleteTextCommand(doc.get(), beg.get(), end.get(), &text_command));
976 PDF_CHECK_SUCCESS_X(PDTCreateInsertTextCommand(doc.get(), pos.get(), &font_attrs, chars.data(), chars.size(), &text_command));
982 PDF_CHECK_SUCCESS_X(PDTCreateReplaceTextCommand(doc.get(), beg.get(), end.get(), &font_attrs, chars.data(), chars.size(), &text_command));
988 PDF_CHECK_SUCCESS_X(PDTCreateChangeFontCommand(doc.get(), beg.get(), end.get(), font_family, font_format, &text_command));
994 PDF_CHECK_SUCCESS_X(PDTCreateChangeFontStyleCommand(doc.get(), beg.get(), end.get(), font_style, &text_command));
1000 PDF_CHECK_SUCCESS_X(PDTCreateChangeFontSizeCommand(doc.get(), beg.get(), end.get(), font_size, &text_command));
1001 return text_command;
1006 PDF_CHECK_SUCCESS_X(PDTCreateChangeFontColorCommand(doc.get(), beg.get(), end.get(), font_color, &text_command));
1007 return text_command;
1012 PDF_CHECK_SUCCESS_X(PDTCreateChangeEscapementCommand(doc.get(), begin.get(), end.get(), escapment, &text_command));
1013 return text_command;
1018 PDF_CHECK_SUCCESS_X(PDTCreateChangeHorzScalingCommand(doc.get(), begin.get(), end.get(), horz_scaling, &text_command));
1019 return text_command;
1024 PDF_CHECK_SUCCESS_X(PDTCreateChangeCharSpacingCommand(doc.get(), begin.get(), end.get(), char_spacing, &text_command));
1025 return text_command;
1030 PDF_CHECK_SUCCESS_X(PDTCreateChangeParaAttrsCommand(doc.get(), iter.get(), ¶_attrs, &text_command));
1031 return text_command;
1036 PDF_CHECK_SUCCESS_X(PDTCreateNewTextBlockCommand(doc.get(), layout.get(), &page_point, &font_attrs, ¶_attrs, &text_command));
1037 return text_command;
1042 PDF_CHECK_SUCCESS_X(PDTCreateDeleteTextBlockCommand(doc.get(), layout.get(), block.get(), &text_command));
1043 return text_command;
1048 PDF_CHECK_SUCCESS_X(PDTCreateMergeTextBlocksCommand(doc.get(), begin.get(), end.get(), &text_command));
1049 return text_command;
1054 PDF_CHECK_SUCCESS_X(PDTCreateUpdateTextBlocksCommand(doc.get(), layout.get(), &text_command));
1055 return text_command;
1060 PDF_CHECK_SUCCESS_X(PDTCreateMoveTextBlockCommand(doc.get(), layout.get(), block_index, &pos, &text_command));
1061 return text_command;
1066 PDF_CHECK_SUCCESS_X(PDTCreateRotateTextBlockCommand(doc.get(), layout.get(), block_index, radians, &text_command));
1067 return text_command;
1072 PDF_CHECK_SUCCESS_X(PDTCreateScaleTextBlockCommand(doc.get(), layout.get(), block_index, &size, &text_command));
1073 return text_command;
1078 PDF_CHECK_SUCCESS_X(PDTCreateResizeTextBlockCommand(doc.get(), layout.get(), block_index, &size, &text_command));
1079 return text_command;
1084 PDF_CHECK_SUCCESS_X(PDTCreateSyncWithContentCommand(doc.get(), layout.get(), block_index, on_top, &text_command));
1085 return text_command;
1090 PDF_CHECK_SUCCESS_X(PDTCreateChangeListStyleCommand(doc.get(), begin.get(), end.get(), &style, &text_command));
1091 return text_command;
1096 PDF_CHECK_SUCCESS_X(PDTCreateChangeListLevelCommand(doc.get(), begin.get(), end.get(), change, &text_command));
1097 return text_command;
1101 PDF_CHECK_SUCCESS_X(PDTTextCommandDo(m_handle));
1105 PDF_CHECK_SUCCESS_X(PDTTextCommandUndo(m_handle));
1109 bool fontSubstituted =
false;
1110 PDF_CHECK_SUCCESS_X(PDTTextCommandIsFontSubstituted(m_handle, &fontSubstituted));
1111 return fontSubstituted;
Represents a PDF document.
Definition document.h:22
Represents a PDF content element.
Definition element.h:19
Represents a leaf node (Page Object).
Definition page.h:20
The CharIterator class represents an iterator to a character in a Layout.
Definition text_edit.h:200
size_t GetPageIndex() const
Gets the page index of the current iterator.
Definition text_edit.h:914
CharIterator GetLineBegin() const
Gets the iterator to the beginning of the current line.
Definition text_edit.h:814
PDTListAttrs GetListAttrs() const
Gets the list attributes of the current character.
Definition text_edit.h:950
int Distance(const CharIterator &that) const
Calculates the distance between the current iterator and another iterator.
Definition text_edit.h:892
CharIterator GetWordEnd() const
Gets the iterator to the end of the current word.
Definition text_edit.h:832
PDTParaAttrs GetParaAttrs() const
Gets the paragraph attributes of the current character.
Definition text_edit.h:944
CharIterator GetAboveAtPage(const Layout &prev_page_text_layout) const
Gets the iterator to the character above the current character on the previous page.
Definition text_edit.h:856
CharIterator GetBelowAtPage(const Layout &next_page_text_layout) const
Gets the iterator to the character below the current character on the next page.
Definition text_edit.h:868
Matrix GetTransform() const
Gets the transformation matrix of the current character.
Definition text_edit.h:956
void Move(int n)
Moves the iterator by the specified number of characters.
Definition text_edit.h:888
CharIterator GetLineEnd() const
Gets the iterator to the end of the current line.
Definition text_edit.h:820
void MoveNext()
Moves the iterator to the next character.
Definition text_edit.h:880
bool Less(const CharIterator &that) const
Checks if the current iterator is less than another iterator.
Definition text_edit.h:898
void MovePrev()
Moves the iterator to the previous character.
Definition text_edit.h:884
CharIterator GetParaBegin() const
Gets the iterator to the beginning of the current paragraph.
Definition text_edit.h:802
CharIterator GetBlockEnd() const
Gets the iterator to the end of the current block.
Definition text_edit.h:796
Quad GetOutlineQuad() const
Gets the quad representing the outline of the current character.
Definition text_edit.h:926
CharIterator GetParaEnd() const
Gets the iterator to the end of the current paragraph.
Definition text_edit.h:808
CharIterator GetSpanBegin() const
Gets the iterator to the beginning of the current span.
Definition text_edit.h:838
std::wstring GetUnicodeChar() const
Gets the Unicode character at the current iterator position.
Definition text_edit.h:910
CharIterator GetBlockBegin() const
Gets the iterator to the beginning of the current block.
Definition text_edit.h:790
Quad GetQuad() const
Gets the quad representing the bounding box of the current character.
Definition text_edit.h:920
TextRun GetTextRun() const
Gets the TextRun containing the current character.
Definition text_edit.h:962
CharIterator GetBelow() const
Gets the iterator to the character below the current character.
Definition text_edit.h:862
CharIterator Copy() const
Creates a copy of the current iterator.
Definition text_edit.h:874
CharIterator GetAbove() const
Gets the iterator to the character above the current character.
Definition text_edit.h:850
CharIterator GetSpanEnd() const
Gets the iterator to the end of the current span.
Definition text_edit.h:844
CharIterator GetWordBegin() const
Gets the iterator to the beginning of the current word.
Definition text_edit.h:826
PDTFontAttrs GetFontAttrs() const
Gets the font attributes of the current character.
Definition text_edit.h:938
TextBlock GetTextBlock() const
Gets the TextBlock containing the current character.
Definition text_edit.h:932
bool Equal(const CharIterator &that) const
Checks if the current iterator is equal to another iterator.
Definition text_edit.h:904
The Layout class represents a text layout in a PDF document.
Definition text_edit.h:25
TextBlock GetTextBlock(size_t index) const
Gets the TextBlock at the specified index.
Definition text_edit.h:686
static Layout BuildForPage(const Page &page)
Builds a Layout object for a specific page.
Definition text_edit.h:654
CharIterator GetCharIterAtPoint(const PointF &point) const
Gets an iterator to the character at the specified point in the Layout.
Definition text_edit.h:710
TextBlock NewTextBlock(size_t index)
Creates a new TextBlock at the specified index.
Definition text_edit.h:666
size_t FindTextBlockIndex(const TextBlock &text_block) const
Finds the index of the specified TextBlock in the Layout.
Definition text_edit.h:692
void InsertTextBlock(size_t index, const TextBlock &text_block)
Inserts a TextBlock at the specified index.
Definition text_edit.h:672
void RemoveTextBlock(size_t index)
Removes the TextBlock at the specified index.
Definition text_edit.h:676
CharIterator GetCharIterForItem(const TextRun &text_run, size_t char_index) const
Gets an iterator to the character at the specified index within a TextRun in the Layout.
Definition text_edit.h:716
CharIterator GetCharsEnd() const
Gets an iterator to the end of the characters in the Layout.
Definition text_edit.h:704
size_t GetNumTextBlocks() const
Gets the number of TextBlocks in the Layout.
Definition text_edit.h:680
CharIterator GetCharsBegin() const
Gets an iterator to the beginning of the characters in the Layout.
Definition text_edit.h:698
CharIterator GetCharIterForItemAtPoint(const TextRun &text_run, const PointF &point) const
Gets an iterator to the character at the specified point within a TextRun in the Layout.
Definition text_edit.h:722
static Layout BuildForFormXObject(const Document &doc, const XObject &xform)
Builds a Layout object for a specific form XObject.
Definition text_edit.h:660
The TextBlock class represents a block of text in a Layout.
Definition text_edit.h:123
CharIterator GetCharEnd(const Layout &text_layout) const
Gets an iterator to the end of the characters in the TextBlock.
Definition text_edit.h:768
bool IsExplicitWidth() const
Checks if the TextBlock has an explicit width.
Definition text_edit.h:780
Element CreateTextElement() const
Creates a TextElement from the TextBlock.
Definition text_edit.h:774
bool Equals(const TextBlock &that) const
Checks if the current TextBlock is equal to another TextBlock.
Definition text_edit.h:728
bool IsReflected() const
Checks if the TextBlock is reflected.
Definition text_edit.h:750
void SetExplicitWidth(bool value)
Sets whether the TextBlock has an explicit width.
Definition text_edit.h:786
PointF GetPosition() const
Gets the position of the TextBlock.
Definition text_edit.h:732
float GetRotation() const
Gets the rotation angle of the TextBlock.
Definition text_edit.h:744
RectF GetBBox() const
Gets the bounding box of the TextBlock.
Definition text_edit.h:756
SizeF GetSize() const
Gets the size of the TextBlock.
Definition text_edit.h:738
CharIterator GetCharBegin(const Layout &text_layout) const
Gets an iterator to the beginning of the characters in the TextBlock.
Definition text_edit.h:762
The TextCommand class represents a command that can be performed on text in a Layout....
Definition text_edit.h:399
static TextCommand RotateTextBlock(Document doc, Layout layout, size_t block_index, float radians)
Rotates a text block by a specified angle and returns the command.
Definition text_edit.h:1064
static TextCommand ChangeCharSpacing(Document doc, CharIterator begin, CharIterator end, float char_spacing)
Changes the character spacing of text within a specified range and returns the command.
Definition text_edit.h:1022
static TextCommand ChangeFontStyle(Document doc, CharIterator beg, CharIterator end, PDFontStyle font_style)
Changes the font style of text within a specified range and returns the command.
Definition text_edit.h:992
static TextCommand ChangeFont(Document doc, CharIterator beg, CharIterator end, PDAtom font_family, PDAtom font_format)
Changes the font of text within a specified range and returns the command.
Definition text_edit.h:986
static TextCommand DeleteText(Document doc, CharIterator beg, CharIterator end)
Deletes the text within a specified range and returns the command.
Definition text_edit.h:968
static TextCommand ChangeListStyle(Document doc, CharIterator begin, CharIterator end, const PDTListLevelStyle &style)
Changes the list style of text within a specified range and returns the command.
Definition text_edit.h:1088
static TextCommand InsertText(Document doc, CharIterator pos, const PDTFontAttrs &font_attrs, const std::wstring &chars)
Inserts the specified text at the position and returns the command.
Definition text_edit.h:974
void Undo()
Undoes the applied text command.
Definition text_edit.h:1104
static TextCommand SyncWithContent(Document doc, Layout layout, size_t block_index, bool on_top)
Synchronizes a text block with its content and returns the command.
Definition text_edit.h:1082
static TextCommand ChangeFontColor(Document doc, CharIterator beg, CharIterator end, PDColorValue font_color)
Changes the font color of text within a specified range and returns the command.
Definition text_edit.h:1004
bool IsFontSubstituted() const
Checks if the font was substituted during the text command.
Definition text_edit.h:1108
static TextCommand NewTextBlock(Document doc, Layout layout, const PointF &page_point, const PDTFontAttrs &font_attrs, const PDTParaAttrs ¶_attrs)
Creates a new text block at a specified position and returns the command.
Definition text_edit.h:1034
static TextCommand UpdateTextBlocks(Document doc, Layout layout)
Updates all text blocks in a Layout and returns the command.
Definition text_edit.h:1052
void Redo()
Redoes the applied text command.
Definition text_edit.h:1100
static TextCommand MoveTextBlock(Document doc, Layout layout, size_t block_index, const PointF &pos)
Moves a text block to a new position and returns the command.
Definition text_edit.h:1058
static TextCommand ResizeTextBlock(Document doc, Layout layout, size_t block_index, const SizeF &size)
Resizes a text block to a new size and returns the command.
Definition text_edit.h:1076
static TextCommand ScaleTextBlock(Document doc, Layout layout, size_t block_index, const SizeF &size)
Scales a text block to a new size and returns the command.
Definition text_edit.h:1070
static TextCommand ChangeEscapement(Document doc, CharIterator begin, CharIterator end, PDTEscapement escapment)
Changes the escapement (vertical location relative to the baseline, also known as superscript or subs...
Definition text_edit.h:1010
static TextCommand MergeTextBlocks(Document doc, CharIterator begin, CharIterator end)
Merges multiple text blocks into a single text block and returns the command.
Definition text_edit.h:1046
static TextCommand ChangeListLevel(Document doc, CharIterator begin, CharIterator end, int change)
Changes the list level of text within a specified range and returns the command. This refers to adjus...
Definition text_edit.h:1094
static TextCommand ChangeParaAttrs(Document doc, CharIterator iter, const PDTParaAttrs ¶_attrs)
Changes the paragraph attributes of text for a specific paragraph and returns the command.
Definition text_edit.h:1028
static TextCommand ChangeHorzScaling(Document doc, CharIterator begin, CharIterator end, float horz_scaling)
Changes the horizontal scaling (horizontal stretch) of text within a specified range and returns the ...
Definition text_edit.h:1016
static TextCommand ChangeFontSize(Document doc, CharIterator beg, CharIterator end, float font_size)
Changes the font size of text within a specified range and returns the command.
Definition text_edit.h:998
static TextCommand DeleteTextBlock(Document doc, Layout layout, const TextBlock &block)
Deletes a text block from a Layout and returns the command.
Definition text_edit.h:1040
static TextCommand ReplaceText(Document doc, CharIterator beg, CharIterator end, const PDTFontAttrs &font_attrs, const std::wstring &chars)
Replaces text within a specified range and returns the command.
Definition text_edit.h:980
Represents a text run in a PDF document.
Definition text_run.h:19
Represents an XObject in a PDF document.
Definition xobject.h:22
Definition text_edit.h:42
Definition text_edit.h:109
Definition text_edit.h:90
Definition text_edit.h:68
PDTEscapement
Defines the vertical position of text relative to the baseline.
Definition text_edit.h:36