Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: fpdfsdk/fxedit/fxet_ap.cpp

Issue 2142213002: Remove some IFX_* wrappers. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/fsdk_baseform.cpp ('k') | fpdfsdk/fxedit/fxet_edit.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" 7 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
8 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" 8 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h"
9 #include "core/fpdfdoc/include/cpvt_word.h" 9 #include "core/fpdfdoc/include/cpvt_word.h"
10 #include "core/fpdfdoc/include/ipvt_fontmap.h" 10 #include "core/fpdfdoc/include/ipvt_fontmap.h"
11 #include "fpdfsdk/fxedit/include/fx_edit.h" 11 #include "fpdfsdk/fxedit/include/fx_edit.h"
12 #include "fpdfsdk/fxedit/include/fxet_edit.h" 12 #include "fpdfsdk/fxedit/include/fxet_edit.h"
13 13
14 namespace {
15
16 CFX_ByteString GetWordRenderString(const CFX_ByteString& strWords) {
17 if (strWords.GetLength() > 0)
18 return PDF_EncodeString(strWords) + " Tj\n";
19 return CFX_ByteString();
20 }
21
22 CFX_ByteString GetFontSetString(IPVT_FontMap* pFontMap,
23 int32_t nFontIndex,
24 FX_FLOAT fFontSize) {
25 if (!pFontMap)
26 return CFX_ByteString();
27
28 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
29 if (sFontAlias.GetLength() <= 0 || fFontSize <= 0)
30 return CFX_ByteString();
31
32 CFX_ByteTextBuf sRet;
33 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
34 return sRet.MakeString();
35 }
36
37 } // namespace
38
39 CFX_ByteString GetPDFWordString(IPVT_FontMap* pFontMap, 14 CFX_ByteString GetPDFWordString(IPVT_FontMap* pFontMap,
40 int32_t nFontIndex, 15 int32_t nFontIndex,
41 uint16_t Word, 16 uint16_t Word,
42 uint16_t SubWord) { 17 uint16_t SubWord) {
43 CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex); 18 CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex);
44 if (!pPDFFont) 19 if (!pPDFFont)
45 return CFX_ByteString(); 20 return CFX_ByteString();
46 21
47 CFX_ByteString sWord; 22 CFX_ByteString sWord;
48 if (SubWord > 0) { 23 if (SubWord > 0) {
49 Word = SubWord; 24 Word = SubWord;
50 } else { 25 } else {
51 uint32_t dwCharCode = pPDFFont->IsUnicodeCompatible() 26 uint32_t dwCharCode = pPDFFont->IsUnicodeCompatible()
52 ? pPDFFont->CharCodeFromUnicode(Word) 27 ? pPDFFont->CharCodeFromUnicode(Word)
53 : pFontMap->CharCodeFromUnicode(nFontIndex, Word); 28 : pFontMap->CharCodeFromUnicode(nFontIndex, Word);
54 29
55 if (dwCharCode > 0) { 30 if (dwCharCode > 0) {
56 pPDFFont->AppendChar(sWord, dwCharCode); 31 pPDFFont->AppendChar(sWord, dwCharCode);
57 return sWord; 32 return sWord;
58 } 33 }
59 } 34 }
60 35
61 pPDFFont->AppendChar(sWord, Word); 36 pPDFFont->AppendChar(sWord, Word);
62 return sWord; 37 return sWord;
63 } 38 }
64
65 CFX_ByteString IFX_Edit::GetEditAppearanceStream(IFX_Edit* pEdit,
66 const CFX_FloatPoint& ptOffset,
67 const CPVT_WordRange* pRange,
68 FX_BOOL bContinuous,
69 uint16_t SubWord) {
70 IFX_Edit_Iterator* pIterator = pEdit->GetIterator();
71 if (pRange)
72 pIterator->SetAt(pRange->BeginPos);
73 else
74 pIterator->SetAt(0);
75
76 CFX_ByteTextBuf sEditStream;
77 CFX_ByteTextBuf sWords;
78 int32_t nCurFontIndex = -1;
79 CFX_FloatPoint ptOld(0.0f, 0.0f);
80 CFX_FloatPoint ptNew(0.0f, 0.0f);
81 CPVT_WordPlace oldplace;
82 while (pIterator->NextWord()) {
83 CPVT_WordPlace place = pIterator->GetAt();
84
85 if (pRange && place.WordCmp(pRange->EndPos) > 0)
86 break;
87
88 if (bContinuous) {
89 if (place.LineCmp(oldplace) != 0) {
90 if (sWords.GetSize() > 0) {
91 sEditStream << GetWordRenderString(sWords.MakeString());
92 sWords.Clear();
93 }
94
95 CPVT_Word word;
96 if (pIterator->GetWord(word)) {
97 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x,
98 word.ptWord.y + ptOffset.y);
99 } else {
100 CPVT_Line line;
101 pIterator->GetLine(line);
102 ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x,
103 line.ptLine.y + ptOffset.y);
104 }
105
106 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) {
107 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y
108 << " Td\n";
109
110 ptOld = ptNew;
111 }
112 }
113
114 CPVT_Word word;
115 if (pIterator->GetWord(word)) {
116 if (word.nFontIndex != nCurFontIndex) {
117 if (sWords.GetSize() > 0) {
118 sEditStream << GetWordRenderString(sWords.MakeString());
119 sWords.Clear();
120 }
121 sEditStream << GetFontSetString(pEdit->GetFontMap(), word.nFontIndex,
122 word.fFontSize);
123 nCurFontIndex = word.nFontIndex;
124 }
125
126 sWords << GetPDFWordString(pEdit->GetFontMap(), nCurFontIndex,
127 word.Word, SubWord);
128 }
129
130 oldplace = place;
131 } else {
132 CPVT_Word word;
133 if (pIterator->GetWord(word)) {
134 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x,
135 word.ptWord.y + ptOffset.y);
136
137 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) {
138 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y
139 << " Td\n";
140 ptOld = ptNew;
141 }
142
143 if (word.nFontIndex != nCurFontIndex) {
144 sEditStream << GetFontSetString(pEdit->GetFontMap(), word.nFontIndex,
145 word.fFontSize);
146 nCurFontIndex = word.nFontIndex;
147 }
148
149 sEditStream << GetWordRenderString(GetPDFWordString(
150 pEdit->GetFontMap(), nCurFontIndex, word.Word, SubWord));
151 }
152 }
153 }
154
155 if (sWords.GetSize() > 0) {
156 sEditStream << GetWordRenderString(sWords.MakeString());
157 sWords.Clear();
158 }
159
160 CFX_ByteTextBuf sAppStream;
161 if (sEditStream.GetSize() > 0) {
162 int32_t nHorzScale = pEdit->GetHorzScale();
163 if (nHorzScale != 100) {
164 sAppStream << nHorzScale << " Tz\n";
165 }
166
167 FX_FLOAT fCharSpace = pEdit->GetCharSpace();
168 if (!FX_EDIT_IsFloatZero(fCharSpace)) {
169 sAppStream << fCharSpace << " Tc\n";
170 }
171
172 sAppStream << sEditStream;
173 }
174
175 return sAppStream.MakeString();
176 }
177
178 CFX_ByteString IFX_Edit::GetSelectAppearanceStream(
179 IFX_Edit* pEdit,
180 const CFX_FloatPoint& ptOffset,
181 const CPVT_WordRange* pRange) {
182 if (!pRange || !pRange->IsExist())
183 return CFX_ByteString();
184
185 IFX_Edit_Iterator* pIterator = pEdit->GetIterator();
186 pIterator->SetAt(pRange->BeginPos);
187
188 CFX_ByteTextBuf sRet;
189 while (pIterator->NextWord()) {
190 CPVT_WordPlace place = pIterator->GetAt();
191 if (place.WordCmp(pRange->EndPos) > 0)
192 break;
193
194 CPVT_Word word;
195 CPVT_Line line;
196 if (pIterator->GetWord(word) && pIterator->GetLine(line)) {
197 sRet << word.ptWord.x + ptOffset.x << " "
198 << line.ptLine.y + line.fLineDescent << " " << word.fWidth << " "
199 << line.fLineAscent - line.fLineDescent << " re\nf\n";
200 }
201 }
202
203 return sRet.MakeString();
204 }
OLDNEW
« no previous file with comments | « fpdfsdk/fsdk_baseform.cpp ('k') | fpdfsdk/fxedit/fxet_edit.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698