PDF SDK Documentation

Comprehensive Guide for Developers: Features, Integration, and API Reference

Loading...
Searching...
No Matches
text_edit.h
1// Copyright (c) 2009-2025 Avanquest Software. All rights reserved.
2
3#ifndef PDFSDK_CXX_TEXT_EDIT_H_INCLUDED_
4#define PDFSDK_CXX_TEXT_EDIT_H_INCLUDED_
5
6#include <pdfsdk/cxx/element.h>
7#include <pdfsdk/cxx/math.h>
8#include <pdfsdk/cxx/text_run.h>
9#include <pdfsdk/text_edit.h>
10
11#include "forward_declarations.h"
12#include "wrapper_base.h"
13
14namespace PDF {
15namespace TextEdit {
16
17class CharIterator;
18class Layout;
19class TextBlock;
20class TextCommand;
21
25class Layout : public detail::RefCountedHandle<PDTLayout> {
26public:
32 static Layout BuildForPage(const Page& page);
33
40 static Layout BuildForFormXObject(const Document& doc, const XObject& xform);
41
47 TextBlock NewTextBlock(size_t index);
48
54 void InsertTextBlock(size_t index, const TextBlock& text_block);
55
60 void RemoveTextBlock(size_t index);
61
66 size_t GetNumTextBlocks() const;
67
73 TextBlock GetTextBlock(size_t index) const;
74
80 size_t FindTextBlockIndex(const TextBlock& text_block) const;
81
87
93
99 CharIterator GetCharIterAtPoint(const PointF& point) const;
100
107 CharIterator GetCharIterForItem(const TextRun& text_run, size_t char_index) const;
108
115 CharIterator GetCharIterForItemAtPoint(const TextRun& text_run, const PointF& point) const;
116
117 PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(Layout, PDTLayout)
118};
119
123class TextBlock : public detail::RefCountedHandle<PDTTextBlock> {
124public:
130 bool Equals(const TextBlock& that) const;
131
136 PointF GetPosition() const;
137
142 SizeF GetSize() const;
143
148 float GetRotation() const;
149
154 bool IsReflected() const;
155
160 RectF GetBBox() const;
161
167 CharIterator GetCharBegin(const Layout& text_layout) const;
168
174 CharIterator GetCharEnd(const Layout& text_layout) const;
175
182 CharIterator GetCharByIndex(const Layout& text_layout, size_t char_index) const;
183
189
194 bool IsExplicitWidth() const;
195
200 void SetExplicitWidth(bool value);
201
202 PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(TextBlock, PDTTextBlock)
203};
204
208class CharIterator : public detail::RefCountedHandle<PDTCharIterator> {
209public:
215
221
227
232 CharIterator GetParaEnd() const;
233
239
244 CharIterator GetLineEnd() const;
245
251
256 CharIterator GetWordEnd() const;
257
263
268 CharIterator GetSpanEnd() const;
269
274 CharIterator GetAbove() const;
275
281 CharIterator GetAboveAtPage(const Layout& prev_page_text_layout) const;
282
287 CharIterator GetBelow() const;
288
294 CharIterator GetBelowAtPage(const Layout& next_page_text_layout) const;
295
300 CharIterator Copy() const;
301
305 void MoveNext();
306
310 void MovePrev();
311
316 void Move(int n);
317
323 int Distance(const CharIterator& that) const;
324
330 bool Less(const CharIterator& that) const;
331
337 bool Equal(const CharIterator& that) const;
338
343 std::wstring GetUnicodeChar() const;
344
349 size_t GetPageIndex() const;
350
355 Quad GetQuad() const;
356
361 Quad GetOutlineQuad() const;
362
367 TextBlock GetTextBlock() const;
368
374
380
386
391 Matrix GetTransform() const;
392
397 TextRun GetTextRun() const;
398
399 PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(CharIterator, PDTCharIterator)
400};
401
407class TextCommand : public detail::RefCountedHandle<PDTTextCommand> {
408public:
417
427 static TextCommand InsertText(Document doc, CharIterator pos, const PDTFontAttrs& font_attrs, const std::wstring& chars);
428
439 static TextCommand ReplaceText(Document doc, CharIterator beg, CharIterator end, const PDTFontAttrs& font_attrs, const std::wstring& chars);
440
450 static TextCommand ChangeFont(Document doc, CharIterator beg, CharIterator end, PDAtom font_family, PDAtom font_format);
451
461
470 static TextCommand ChangeFontSize(Document doc, CharIterator beg, CharIterator end, float font_size);
471
480 static TextCommand ChangeFontColor(Document doc, CharIterator beg, CharIterator end, PDColorValue font_color);
481
492
503 static TextCommand ChangeHorzScaling(Document doc, CharIterator begin, CharIterator end, float horz_scaling);
504
514 static TextCommand ChangeCharSpacing(Document doc, CharIterator begin, CharIterator end, float char_spacing);
515
524 static TextCommand ChangeHighlightColor(Document doc, CharIterator begin, CharIterator end, PDColorValue fontColor);
525
534 static TextCommand ChangeStrikeoutColor(Document doc, CharIterator begin, CharIterator end, PDColorValue fontColor);
535
544 static TextCommand ChangeUnderlineColor(Document doc, CharIterator begin, CharIterator end, PDColorValue fontColor);
545
554 static TextCommand ChangeParaAttrs(Document doc, CharIterator iter, const PDTParaAttrs& para_attrs);
555
567 static TextCommand NewTextBlock(Document doc, Layout layout, const PointF& page_point, const PDTFontAttrs& font_attrs, const PDTParaAttrs& para_attrs);
568
576 static TextCommand DeleteTextBlock(Document doc, Layout layout, const TextBlock& block);
577
586
593 static TextCommand UpdateTextBlocks(Document doc, Layout layout);
594
603 static TextCommand MoveTextBlock(Document doc, Layout layout, size_t block_index, const PointF& pos);
604
615 static TextCommand RotateTextBlock(Document doc, Layout layout, size_t block_index, float radians);
616
626 static TextCommand ScaleTextBlock(Document doc, Layout layout, size_t block_index, const SizeF& size);
627
637 static TextCommand ResizeTextBlock(Document doc, Layout layout, size_t block_index, const SizeF& size);
638
648 static TextCommand SyncWithContent(Document doc, Layout layout, size_t block_index, bool on_top);
649
660
671 static TextCommand ChangeListLevel(Document doc, CharIterator begin, CharIterator end, int change);
672
676 void Redo();
677
681 void Undo();
682
687 bool IsFontSubstituted() const;
688
689 PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(TextCommand, PDTTextCommand)
690};
691
692inline Layout Layout::BuildForPage(const Page& page) {
693 Layout text_layout;
694 PDF_CHECK_SUCCESS_X(PDPageBuildTextLayout(page.get(), &text_layout));
695 return text_layout;
696}
697
698inline Layout Layout::BuildForFormXObject(const Document& doc, const XObject& xform) {
699 Layout text_layout;
700 PDF_CHECK_SUCCESS_X(PDEFormXObjectBuildTextLayout(doc.get(), xform.get(), &text_layout));
701 return text_layout;
702}
703
704inline TextBlock Layout::NewTextBlock(size_t index) {
705 TextBlock text_block;
706 PDF_CHECK_SUCCESS_X(PDTLayoutNewTextBlock(m_handle, index, &text_block));
707 return text_block;
708}
709
710inline void Layout::InsertTextBlock(size_t index, const TextBlock& text_block) {
711 PDF_CHECK_SUCCESS_X(PDTLayoutInsertTextBlock(m_handle, index, text_block.get()));
712}
713
714inline void Layout::RemoveTextBlock(size_t index) {
715 PDF_CHECK_SUCCESS_X(PDTLayoutRemoveTextBlock(m_handle, index));
716}
717
718inline size_t Layout::GetNumTextBlocks() const {
719 size_t num_blocks = 0;
720 PDF_CHECK_SUCCESS_X(PDTLayoutGetNumTextBlocks(m_handle, &num_blocks));
721 return num_blocks;
722}
723
724inline TextBlock Layout::GetTextBlock(size_t index) const {
725 TextBlock text_block;
726 PDF_CHECK_SUCCESS_X(PDTLayoutGetTextBlock(m_handle, index, &text_block));
727 return text_block;
728}
729
730inline size_t Layout::FindTextBlockIndex(const TextBlock& text_block) const {
731 size_t index = kPDPageIndexNull;
732 PDF_CHECK_SUCCESS_X(PDTLayoutGetTextBlockIndex(m_handle, text_block.get(), &index));
733 return index;
734}
735
737 CharIterator char_begin;
738 PDF_CHECK_SUCCESS_X(PDTCharIteratorAtBeginPage(m_handle, &char_begin));
739 return char_begin;
740}
741
743 CharIterator char_end;
744 PDF_CHECK_SUCCESS_X(PDTCharIteratorAtEndPage(m_handle, &char_end));
745 return char_end;
746}
747
749 CharIterator char_iter;
750 PDF_CHECK_SUCCESS_X(PDTCharIteratorAtPoint(m_handle, &point, &char_iter));
751 return char_iter;
752}
753
754inline CharIterator Layout::GetCharIterForItem(const TextRun& text_run, size_t char_index) const {
755 CharIterator char_iter;
756 PDF_CHECK_SUCCESS_X(PDTCharIteratorForItem(m_handle, text_run.get(), char_index, &char_iter));
757 return char_iter;
758}
759
760inline CharIterator Layout::GetCharIterForItemAtPoint(const TextRun& text_run, const PointF& point) const {
761 CharIterator char_iter;
762 PDF_CHECK_SUCCESS_X(PDTCharIteratorForItemAtPoint(m_handle, text_run.get(), &point, &char_iter));
763 return char_iter;
764}
765
766inline bool TextBlock::Equals(const TextBlock& that) const {
767 return PDTTextBlockEqual(m_handle, that.get());
768}
769
771 PointF position;
772 PDF_CHECK_SUCCESS_X(PDTTextBlockGetPosition(m_handle, &position));
773 return position;
774}
775
776inline SizeF TextBlock::GetSize() const {
777 SizeF size;
778 PDF_CHECK_SUCCESS_X(PDTTextBlockGetSize(m_handle, &size));
779 return size;
780}
781
782inline float TextBlock::GetRotation() const {
783 float rotation = 0.f;
784 PDF_CHECK_SUCCESS_X(PDTTextBlockGetRotate(m_handle, &rotation));
785 return rotation;
786}
787
788inline bool TextBlock::IsReflected() const {
789 bool reflected = false;
790 PDF_CHECK_SUCCESS_X(PDTTextBlockIsReflected(m_handle, &reflected));
791 return reflected;
792}
793
794inline RectF TextBlock::GetBBox() const {
795 RectF bbox;
796 PDF_CHECK_SUCCESS_X(PDTTextBlockGetBBox(m_handle, &bbox));
797 return bbox;
798}
799
800inline CharIterator TextBlock::GetCharBegin(const Layout& text_layout) const {
801 CharIterator char_begin;
802 PDF_CHECK_SUCCESS_X(PDTTextBlockGetCharBegin(text_layout.get(), m_handle, &char_begin));
803 return char_begin;
804}
805
806inline CharIterator TextBlock::GetCharEnd(const Layout& text_layout) const {
807 CharIterator char_end;
808 PDF_CHECK_SUCCESS_X(PDTTextBlockGetCharEnd(text_layout.get(), m_handle, &char_end));
809 return char_end;
810}
811
812inline CharIterator TextBlock::GetCharByIndex(const Layout& text_layout, size_t char_index) const {
813 CharIterator char_iter = GetCharBegin(text_layout);
814 CharIterator end_iter = GetCharEnd(text_layout);
815
816 PDF_CHECK(char_iter.Distance(end_iter) >= static_cast<int>(char_index), kPDErrOutOfRange, "Character index out of bounds.");
817 char_iter.Move(static_cast<int>(char_index));
818
819 return char_iter;
820}
821
823 Element text_object;
824 PDF_CHECK_SUCCESS_X(PDTTextBlockCreateTextElement(m_handle, &text_object));
825 return text_object;
826}
827
828inline bool TextBlock::IsExplicitWidth() const {
829 bool value = false;
830 PDF_CHECK_SUCCESS_X(PDTTextBlockIsExplicitWidth(m_handle, &value));
831 return value;
832}
833
834inline void TextBlock::SetExplicitWidth(bool value) {
835 PDF_CHECK_SUCCESS_X(PDTTextBlockSetExplicitWidth(m_handle, value));
836}
837
839 CharIterator char_iter;
840 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetBlockBegin(m_handle, &char_iter));
841 return char_iter;
842}
843
845 CharIterator char_iter;
846 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetBlockEnd(m_handle, &char_iter));
847 return char_iter;
848}
849
851 CharIterator char_iter;
852 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetParaBegin(m_handle, &char_iter));
853 return char_iter;
854}
855
857 CharIterator char_iter;
858 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetParaEnd(m_handle, &char_iter));
859 return char_iter;
860}
861
863 CharIterator char_iter;
864 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetLineBegin(m_handle, &char_iter));
865 return char_iter;
866}
867
869 CharIterator char_iter;
870 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetLineEnd(m_handle, &char_iter));
871 return char_iter;
872}
873
875 CharIterator char_iter;
876 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetWordBegin(m_handle, &char_iter));
877 return char_iter;
878}
879
881 CharIterator char_iter;
882 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetWordEnd(m_handle, &char_iter));
883 return char_iter;
884}
885
887 CharIterator char_iter;
888 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetSpanBegin(m_handle, &char_iter));
889 return char_iter;
890}
891
893 CharIterator char_iter;
894 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetSpanEnd(m_handle, &char_iter));
895 return char_iter;
896}
897
899 CharIterator char_iter;
900 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetAbove(m_handle, &char_iter));
901 return char_iter;
902}
903
904inline CharIterator CharIterator::GetAboveAtPage(const Layout& prev_page_text_layout) const {
905 CharIterator char_iter;
906 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetAboveAtPage(m_handle, prev_page_text_layout.get(), &char_iter));
907 return char_iter;
908}
909
911 CharIterator char_iter;
912 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetBelow(m_handle, &char_iter));
913 return char_iter;
914}
915
916inline CharIterator CharIterator::GetBelowAtPage(const Layout& next_page_text_layout) const {
917 CharIterator char_iter;
918 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetBelowAtPage(m_handle, next_page_text_layout.get(), &char_iter));
919 return char_iter;
920}
921
923 CharIterator copy;
924 PDF_CHECK_SUCCESS_X(PDTCharIteratorCopy(m_handle, &copy));
925 return copy;
926}
927
929 PDF_CHECK_SUCCESS_X(PDTCharIteratorIncrement(m_handle));
930}
931
933 PDF_CHECK_SUCCESS_X(PDTCharIteratorDecrement(m_handle));
934}
935
936inline void CharIterator::Move(int n) {
937 PDF_CHECK_SUCCESS_X(PDTCharIteratorAdvance(m_handle, n));
938}
939
940inline int CharIterator::Distance(const CharIterator& that) const {
941 int dist = 0;
942 PDF_CHECK_SUCCESS_X(PDTCharIteratorDistance(m_handle, that.get(), &dist));
943 return dist;
944}
945
946inline bool CharIterator::Less(const CharIterator& that) const {
947 bool less = false;
948 PDF_CHECK_SUCCESS_X(PDTCharIteratorLess(m_handle, that.get(), &less));
949 return less;
950}
951
952inline bool CharIterator::Equal(const CharIterator& that) const {
953 bool equal = false;
954 PDF_CHECK_SUCCESS_X(PDTCharIteratorEqual(m_handle, that.get(), &equal));
955 return equal;
956}
957
958inline std::wstring CharIterator::GetUnicodeChar() const {
959 return ::PDF::detail::GetWstringProperty(PDTCharIteratorGetUnicode, m_handle);
960}
961
962inline size_t CharIterator::GetPageIndex() const {
963 size_t page_index = kPDPageIndexNull;
964 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetPageIndex(m_handle, &page_index));
965 return page_index;
966}
967
969 Quad quad;
970 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetQuad(m_handle, &quad));
971 return quad;
972}
973
975 Quad quad;
976 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetOutlineQuad(m_handle, &quad));
977 return quad;
978}
979
981 TextBlock text_block;
982 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetTextBlock(m_handle, &text_block));
983 return text_block;
984}
985
987 PDTFontAttrs font_attrs;
988 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetFontAttrs(m_handle, &font_attrs));
989 return font_attrs;
990}
991
993 PDTParaAttrs para_attrs;
994 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetParaAttrs(m_handle, &para_attrs));
995 return para_attrs;
996}
997
999 PDTListAttrs list_attrs;
1000 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetListAttrs(m_handle, &list_attrs));
1001 return list_attrs;
1002}
1003
1005 Matrix matrix;
1006 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetTransform(m_handle, &matrix));
1007 return matrix;
1008}
1009
1011 TextRun text_run;
1012 PDF_CHECK_SUCCESS_X(PDTCharIteratorGetTextItem(m_handle, &text_run));
1013 return text_run;
1014}
1015
1017 TextCommand text_command;
1018 PDF_CHECK_SUCCESS_X(PDTCreateDeleteTextCommand(doc.get(), beg.get(), end.get(), &text_command));
1019 return text_command;
1020}
1021
1022inline TextCommand TextCommand::InsertText(Document doc, CharIterator pos, const PDTFontAttrs& font_attrs, const std::wstring& chars) {
1023 TextCommand text_command;
1024 PDF_CHECK_SUCCESS_X(PDTCreateInsertTextCommand(doc.get(), pos.get(), &font_attrs, chars.data(), chars.size(), &text_command));
1025 return text_command;
1026}
1027
1028inline TextCommand TextCommand::ReplaceText(Document doc, CharIterator beg, CharIterator end, const PDTFontAttrs& font_attrs, const std::wstring& chars) {
1029 TextCommand text_command;
1030 PDF_CHECK_SUCCESS_X(PDTCreateReplaceTextCommand(doc.get(), beg.get(), end.get(), &font_attrs, chars.data(), chars.size(), &text_command));
1031 return text_command;
1032}
1033
1034inline TextCommand TextCommand::ChangeFont(Document doc, CharIterator beg, CharIterator end, PDAtom font_family, PDAtom font_format) {
1035 TextCommand text_command;
1036 PDF_CHECK_SUCCESS_X(PDTCreateChangeFontCommand(doc.get(), beg.get(), end.get(), font_family, font_format, &text_command));
1037 return text_command;
1038}
1039
1041 TextCommand text_command;
1042 PDF_CHECK_SUCCESS_X(PDTCreateChangeFontStyleCommand(doc.get(), beg.get(), end.get(), font_style, &text_command));
1043 return text_command;
1044}
1045
1047 TextCommand text_command;
1048 PDF_CHECK_SUCCESS_X(PDTCreateChangeFontSizeCommand(doc.get(), beg.get(), end.get(), font_size, &text_command));
1049 return text_command;
1050}
1051
1052inline TextCommand TextCommand::ChangeFontColor(Document doc, CharIterator beg, CharIterator end, PDColorValue font_color) {
1053 TextCommand text_command;
1054 PDF_CHECK_SUCCESS_X(PDTCreateChangeFontColorCommand(doc.get(), beg.get(), end.get(), font_color, &text_command));
1055 return text_command;
1056}
1057
1059 TextCommand text_command;
1060 PDF_CHECK_SUCCESS_X(PDTCreateChangeEscapementCommand(doc.get(), begin.get(), end.get(), escapment, &text_command));
1061 return text_command;
1062}
1063
1065 TextCommand text_command;
1066 PDF_CHECK_SUCCESS_X(PDTCreateChangeHorzScalingCommand(doc.get(), begin.get(), end.get(), horz_scaling, &text_command));
1067 return text_command;
1068}
1069
1071 TextCommand text_command;
1072 PDF_CHECK_SUCCESS_X(PDTCreateChangeCharSpacingCommand(doc.get(), begin.get(), end.get(), char_spacing, &text_command));
1073 return text_command;
1074}
1075
1076inline TextCommand TextCommand::ChangeHighlightColor(Document doc, CharIterator begin, CharIterator end, PDColorValue fontColor) {
1077 TextCommand text_command;
1078 PDF_CHECK_SUCCESS_X(PDTCreateChangeFontHighlightColorCommand(doc.get(), begin.get(), end.get(), fontColor, &text_command));
1079 return text_command;
1080}
1081
1082inline TextCommand TextCommand::ChangeStrikeoutColor(Document doc, CharIterator begin, CharIterator end, PDColorValue fontColor) {
1083 TextCommand text_command;
1084 PDF_CHECK_SUCCESS_X(PDTCreateChangeFontStrikeoutColorCommand(doc.get(), begin.get(), end.get(), fontColor, &text_command));
1085 return text_command;
1086}
1087
1088inline TextCommand TextCommand::ChangeUnderlineColor(Document doc, CharIterator begin, CharIterator end, PDColorValue fontColor) {
1089 TextCommand text_command;
1090 PDF_CHECK_SUCCESS_X(PDTCreateChangeFontUnderlineColorCommand(doc.get(), begin.get(), end.get(), fontColor, &text_command));
1091 return text_command;
1092}
1093
1095 TextCommand text_command;
1096 PDF_CHECK_SUCCESS_X(PDTCreateChangeParaAttrsCommand(doc.get(), iter.get(), &para_attrs, &text_command));
1097 return text_command;
1098}
1099
1100inline TextCommand TextCommand::NewTextBlock(Document doc, Layout layout, const PointF& page_point, const PDTFontAttrs& font_attrs, const PDTParaAttrs& para_attrs) {
1101 TextCommand text_command;
1102 PDF_CHECK_SUCCESS_X(PDTCreateNewTextBlockCommand(doc.get(), layout.get(), &page_point, &font_attrs, &para_attrs, &text_command));
1103 return text_command;
1104}
1105
1107 TextCommand text_command;
1108 PDF_CHECK_SUCCESS_X(PDTCreateDeleteTextBlockCommand(doc.get(), layout.get(), block.get(), &text_command));
1109 return text_command;
1110}
1111
1113 TextCommand text_command;
1114 PDF_CHECK_SUCCESS_X(PDTCreateMergeTextBlocksCommand(doc.get(), begin.get(), end.get(), &text_command));
1115 return text_command;
1116}
1117
1119 TextCommand text_command;
1120 PDF_CHECK_SUCCESS_X(PDTCreateUpdateTextBlocksCommand(doc.get(), layout.get(), &text_command));
1121 return text_command;
1122}
1123
1124inline TextCommand TextCommand::MoveTextBlock(Document doc, Layout layout, size_t block_index, const PointF& pos) {
1125 TextCommand text_command;
1126 PDF_CHECK_SUCCESS_X(PDTCreateMoveTextBlockCommand(doc.get(), layout.get(), block_index, &pos, &text_command));
1127 return text_command;
1128}
1129
1130inline TextCommand TextCommand::RotateTextBlock(Document doc, Layout layout, size_t block_index, float radians) {
1131 TextCommand text_command;
1132 PDF_CHECK_SUCCESS_X(PDTCreateRotateTextBlockCommand(doc.get(), layout.get(), block_index, radians, &text_command));
1133 return text_command;
1134}
1135
1136inline TextCommand TextCommand::ScaleTextBlock(Document doc, Layout layout, size_t block_index, const SizeF& size) {
1137 TextCommand text_command;
1138 PDF_CHECK_SUCCESS_X(PDTCreateScaleTextBlockCommand(doc.get(), layout.get(), block_index, &size, &text_command));
1139 return text_command;
1140}
1141
1142inline TextCommand TextCommand::ResizeTextBlock(Document doc, Layout layout, size_t block_index, const SizeF& size) {
1143 TextCommand text_command;
1144 PDF_CHECK_SUCCESS_X(PDTCreateResizeTextBlockCommand(doc.get(), layout.get(), block_index, &size, &text_command));
1145 return text_command;
1146}
1147
1148inline TextCommand TextCommand::SyncWithContent(Document doc, Layout layout, size_t block_index, bool on_top) {
1149 TextCommand text_command;
1150 PDF_CHECK_SUCCESS_X(PDTCreateSyncWithContentCommand(doc.get(), layout.get(), block_index, on_top, &text_command));
1151 return text_command;
1152}
1153
1155 TextCommand text_command;
1156 PDF_CHECK_SUCCESS_X(PDTCreateChangeListStyleCommand(doc.get(), begin.get(), end.get(), &style, &text_command));
1157 return text_command;
1158}
1159
1161 TextCommand text_command;
1162 PDF_CHECK_SUCCESS_X(PDTCreateChangeListLevelCommand(doc.get(), begin.get(), end.get(), change, &text_command));
1163 return text_command;
1164}
1165
1166inline void TextCommand::Redo() {
1167 PDF_CHECK_SUCCESS_X(PDTTextCommandDo(m_handle));
1168}
1169
1170inline void TextCommand::Undo() {
1171 PDF_CHECK_SUCCESS_X(PDTTextCommandUndo(m_handle));
1172}
1173
1175 bool fontSubstituted = false;
1176 PDF_CHECK_SUCCESS_X(PDTTextCommandIsFontSubstituted(m_handle, &fontSubstituted));
1177 return fontSubstituted;
1178}
1179
1180} // namespace TextEdit
1181} // namespace PDF
1182
1183#endif // PDFSDK_CXX_TEXT_EDIT_H_INCLUDED_
Represents a PDF document.
Definition document.h:22
Represents an element of the content array.
Definition element.h:29
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:208
size_t GetPageIndex() const
Gets the page index of the current iterator.
Definition text_edit.h:962
CharIterator GetLineBegin() const
Gets the iterator to the beginning of the current line.
Definition text_edit.h:862
PDTListAttrs GetListAttrs() const
Gets the list attributes of the current character.
Definition text_edit.h:998
int Distance(const CharIterator &that) const
Calculates the distance between the current iterator and another iterator.
Definition text_edit.h:940
CharIterator GetWordEnd() const
Gets the iterator to the end of the current word.
Definition text_edit.h:880
PDTParaAttrs GetParaAttrs() const
Gets the paragraph attributes of the current character.
Definition text_edit.h:992
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:904
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:916
Matrix GetTransform() const
Gets the transformation matrix of the current character.
Definition text_edit.h:1004
void Move(int n)
Moves the iterator by the specified number of characters.
Definition text_edit.h:936
CharIterator GetLineEnd() const
Gets the iterator to the end of the current line.
Definition text_edit.h:868
void MoveNext()
Moves the iterator to the next character.
Definition text_edit.h:928
bool Less(const CharIterator &that) const
Checks if the current iterator is less than another iterator.
Definition text_edit.h:946
void MovePrev()
Moves the iterator to the previous character.
Definition text_edit.h:932
CharIterator GetParaBegin() const
Gets the iterator to the beginning of the current paragraph.
Definition text_edit.h:850
CharIterator GetBlockEnd() const
Gets the iterator to the end of the current block.
Definition text_edit.h:844
Quad GetOutlineQuad() const
Gets the quad representing the outline of the current character.
Definition text_edit.h:974
CharIterator GetParaEnd() const
Gets the iterator to the end of the current paragraph.
Definition text_edit.h:856
CharIterator GetSpanBegin() const
Gets the iterator to the beginning of the current span.
Definition text_edit.h:886
std::wstring GetUnicodeChar() const
Gets the Unicode character at the current iterator position.
Definition text_edit.h:958
CharIterator GetBlockBegin() const
Gets the iterator to the beginning of the current block.
Definition text_edit.h:838
Quad GetQuad() const
Gets the quad representing the bounding box of the current character.
Definition text_edit.h:968
TextRun GetTextRun() const
Gets the TextRun containing the current character.
Definition text_edit.h:1010
CharIterator GetBelow() const
Gets the iterator to the character below the current character.
Definition text_edit.h:910
CharIterator Copy() const
Creates a copy of the current iterator.
Definition text_edit.h:922
CharIterator GetAbove() const
Gets the iterator to the character above the current character.
Definition text_edit.h:898
CharIterator GetSpanEnd() const
Gets the iterator to the end of the current span.
Definition text_edit.h:892
CharIterator GetWordBegin() const
Gets the iterator to the beginning of the current word.
Definition text_edit.h:874
PDTFontAttrs GetFontAttrs() const
Gets the font attributes of the current character.
Definition text_edit.h:986
TextBlock GetTextBlock() const
Gets the TextBlock containing the current character.
Definition text_edit.h:980
bool Equal(const CharIterator &that) const
Checks if the current iterator is equal to another iterator.
Definition text_edit.h:952
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:724
static Layout BuildForPage(const Page &page)
Builds a Layout object for a specific page.
Definition text_edit.h:692
CharIterator GetCharIterAtPoint(const PointF &point) const
Gets an iterator to the character at the specified point in the Layout.
Definition text_edit.h:748
TextBlock NewTextBlock(size_t index)
Creates a new TextBlock at the specified index.
Definition text_edit.h:704
size_t FindTextBlockIndex(const TextBlock &text_block) const
Finds the index of the specified TextBlock in the Layout.
Definition text_edit.h:730
void InsertTextBlock(size_t index, const TextBlock &text_block)
Inserts a TextBlock at the specified index.
Definition text_edit.h:710
void RemoveTextBlock(size_t index)
Removes the TextBlock at the specified index.
Definition text_edit.h:714
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:754
CharIterator GetCharsEnd() const
Gets an iterator to the end of the characters in the Layout.
Definition text_edit.h:742
size_t GetNumTextBlocks() const
Gets the number of TextBlocks in the Layout.
Definition text_edit.h:718
CharIterator GetCharsBegin() const
Gets an iterator to the beginning of the characters in the Layout.
Definition text_edit.h:736
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:760
static Layout BuildForFormXObject(const Document &doc, const XObject &xform)
Builds a Layout object for a specific form XObject.
Definition text_edit.h:698
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:806
bool IsExplicitWidth() const
Checks if the TextBlock has an explicit width.
Definition text_edit.h:828
Element CreateTextElement() const
Creates a TextElement from the TextBlock.
Definition text_edit.h:822
bool Equals(const TextBlock &that) const
Checks if the current TextBlock is equal to another TextBlock.
Definition text_edit.h:766
bool IsReflected() const
Checks if the TextBlock is reflected.
Definition text_edit.h:788
void SetExplicitWidth(bool value)
Sets whether the TextBlock has an explicit width.
Definition text_edit.h:834
CharIterator GetCharByIndex(const Layout &text_layout, size_t char_index) const
Gets an iterator to the character at the specified index in the TextBlock.
Definition text_edit.h:812
PointF GetPosition() const
Gets the position of the TextBlock.
Definition text_edit.h:770
float GetRotation() const
Gets the rotation angle of the TextBlock.
Definition text_edit.h:782
RectF GetBBox() const
Gets the bounding box of the TextBlock.
Definition text_edit.h:794
SizeF GetSize() const
Gets the size of the TextBlock.
Definition text_edit.h:776
CharIterator GetCharBegin(const Layout &text_layout) const
Gets an iterator to the beginning of the characters in the TextBlock.
Definition text_edit.h:800
The TextCommand class represents a command that can be performed on text in a Layout....
Definition text_edit.h:407
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:1130
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:1070
static TextCommand ChangeHighlightColor(Document doc, CharIterator begin, CharIterator end, PDColorValue fontColor)
Changes the highlight color of text within a specified range and returns the command.
Definition text_edit.h:1076
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:1040
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:1034
static TextCommand DeleteText(Document doc, CharIterator beg, CharIterator end)
Deletes the text within a specified range and returns the command.
Definition text_edit.h:1016
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:1154
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:1022
void Undo()
Undoes the applied text command.
Definition text_edit.h:1170
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:1148
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:1052
bool IsFontSubstituted() const
Checks if the font was substituted during the text command.
Definition text_edit.h:1174
static TextCommand NewTextBlock(Document doc, Layout layout, const PointF &page_point, const PDTFontAttrs &font_attrs, const PDTParaAttrs &para_attrs)
Creates a new text block at a specified position and returns the command.
Definition text_edit.h:1100
static TextCommand UpdateTextBlocks(Document doc, Layout layout)
Updates all text blocks in a Layout and returns the command.
Definition text_edit.h:1118
void Redo()
Redoes the applied text command.
Definition text_edit.h:1166
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:1124
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:1142
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:1136
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:1058
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:1112
static TextCommand ChangeUnderlineColor(Document doc, CharIterator begin, CharIterator end, PDColorValue fontColor)
Changes the underline color of text within a specified range and returns the command.
Definition text_edit.h:1088
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:1160
static TextCommand ChangeParaAttrs(Document doc, CharIterator iter, const PDTParaAttrs &para_attrs)
Changes the paragraph attributes of text for a specific paragraph and returns the command.
Definition text_edit.h:1094
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:1064
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:1046
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:1106
static TextCommand ChangeStrikeoutColor(Document doc, CharIterator begin, CharIterator end, PDColorValue fontColor)
Changes the strikeout color of text within a specified range and returns the command.
Definition text_edit.h:1082
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:1028
Represents a text run in a PDF document.
Definition text_run.h:19
Represents an XObject in a PDF document.
Definition xobject.h:22
@ kPDErrOutOfRange
Value out of range.
Definition errors.h:22
PDFontStyle
Specifies the styling to apply to a font.
Definition fonts.h:24
Definition math.h:1271
Definition math.h:154
Definition math.h:1029
Definition math.h:749
Definition math.h:500
Definition text_edit.h:42
Definition text_edit.h:109
Definition text_edit.h:90
Definition text_edit.h:68
Text Edit API.
PDTEscapement
Defines the vertical position of text relative to the baseline.
Definition text_edit.h:36