| OLD | NEW |
| 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 "../../include/fxedit/fxet_stub.h" | 7 #include "../../include/fxedit/fxet_stub.h" |
| 8 #include "../../include/fxedit/fx_edit.h" | 8 #include "../../include/fxedit/fx_edit.h" |
| 9 #include "../../include/fxedit/fxet_edit.h" | 9 #include "../../include/fxedit/fxet_edit.h" |
| 10 | 10 |
| 11 CFX_ByteString GetPDFWordString(IFX_Edit_FontMap * pFontMap, int32_t nFontIndex,
FX_WORD Word, FX_WORD SubWord) | 11 CFX_ByteString GetPDFWordString(IFX_Edit_FontMap* pFontMap, |
| 12 { | 12 int32_t nFontIndex, |
| 13 ASSERT (pFontMap != NULL); | 13 FX_WORD Word, |
| 14 | 14 FX_WORD SubWord) { |
| 15 CFX_ByteString sWord; | 15 ASSERT(pFontMap != NULL); |
| 16 | 16 |
| 17 if (CPDF_Font * pPDFFont = pFontMap->GetPDFFont(nFontIndex)) | 17 CFX_ByteString sWord; |
| 18 { | 18 |
| 19 if (SubWord > 0) | 19 if (CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex)) { |
| 20 { | 20 if (SubWord > 0) { |
| 21 Word = SubWord; | 21 Word = SubWord; |
| 22 } | 22 } else { |
| 23 else | 23 FX_DWORD dwCharCode = -1; |
| 24 { | 24 |
| 25 FX_DWORD dwCharCode = -1; | 25 if (pPDFFont->IsUnicodeCompatible()) |
| 26 | 26 dwCharCode = pPDFFont->CharCodeFromUnicode(Word); |
| 27 if (pPDFFont->IsUnicodeCompatible()) | 27 else |
| 28 dwCharCode = pPDFFont->CharCodeFromUnicode(Word)
; | 28 dwCharCode = pFontMap->CharCodeFromUnicode(nFontIndex, Word); |
| 29 else | 29 |
| 30 dwCharCode = pFontMap->CharCodeFromUnicode(nFont
Index, Word); | 30 if (dwCharCode > 0) { |
| 31 | 31 pPDFFont->AppendChar(sWord, dwCharCode); |
| 32 if (dwCharCode > 0 ) | 32 return sWord; |
| 33 { | 33 } |
| 34 pPDFFont->AppendChar(sWord, dwCharCode); | 34 } |
| 35 return sWord; | 35 |
| 36 } | 36 pPDFFont->AppendChar(sWord, Word); |
| 37 } | 37 } |
| 38 | 38 |
| 39 pPDFFont->AppendChar(sWord, Word); | 39 return sWord; |
| 40 } | 40 } |
| 41 | 41 |
| 42 return sWord; | 42 static CFX_ByteString GetWordRenderString(const CFX_ByteString& strWords) { |
| 43 } | 43 if (strWords.GetLength() > 0) |
| 44 | 44 return PDF_EncodeString(strWords) + " Tj\n"; |
| 45 static CFX_ByteString GetWordRenderString(const CFX_ByteString & strWords) | 45 |
| 46 { | 46 return ""; |
| 47 if (strWords.GetLength() > 0) | 47 } |
| 48 return PDF_EncodeString(strWords) + " Tj\n"; | 48 |
| 49 | 49 static CFX_ByteString GetFontSetString(IFX_Edit_FontMap* pFontMap, |
| 50 return ""; | 50 int32_t nFontIndex, |
| 51 } | 51 FX_FLOAT fFontSize) { |
| 52 | 52 CFX_ByteTextBuf sRet; |
| 53 static CFX_ByteString GetFontSetString(IFX_Edit_FontMap * pFontMap, int32_t nFon
tIndex, FX_FLOAT fFontSize) | 53 |
| 54 { | 54 if (pFontMap) { |
| 55 CFX_ByteTextBuf sRet; | 55 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
| 56 | 56 |
| 57 if (pFontMap) | 57 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
| 58 { | 58 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
| 59 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex
); | 59 } |
| 60 | 60 |
| 61 if (sFontAlias.GetLength() > 0 && fFontSize > 0 ) | 61 return sRet.GetByteString(); |
| 62 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"
; | 62 } |
| 63 } | 63 |
| 64 | 64 CFX_ByteString IFX_Edit::GetEditAppearanceStream( |
| 65 return sRet.GetByteString(); | 65 IFX_Edit* pEdit, |
| 66 } | 66 const CPDF_Point& ptOffset, |
| 67 | 67 const CPVT_WordRange* pRange /* = NULL*/, |
| 68 CFX_ByteString IFX_Edit::GetEditAppearanceStream(IFX_Edit* pEdit, const CPDF_Poi
nt & ptOffset, | 68 FX_BOOL bContinuous /* = TRUE*/, |
| 69
const CPVT_WordRange * pRange /* = NULL*/, FX_BOOL bContinuous/
* = TRUE*/, FX_WORD SubWord/* = 0*/) | 69 FX_WORD SubWord /* = 0*/) { |
| 70 { | 70 CFX_ByteTextBuf sEditStream, sWords; |
| 71 CFX_ByteTextBuf sEditStream, sWords; | 71 |
| 72 | 72 CPDF_Point ptOld(0.0f, 0.0f), ptNew(0.0f, 0.0f); |
| 73 CPDF_Point ptOld(0.0f,0.0f),ptNew(0.0f,0.0f); | 73 int32_t nCurFontIndex = -1; |
| 74 int32_t nCurFontIndex = -1; | 74 |
| 75 | 75 if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { |
| 76 if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) | 76 if (pRange) |
| 77 { | 77 pIterator->SetAt(pRange->BeginPos); |
| 78 if (pRange) | 78 else |
| 79 pIterator->SetAt(pRange->BeginPos); | 79 pIterator->SetAt(0); |
| 80 else | 80 |
| 81 pIterator->SetAt(0); | 81 CPVT_WordPlace oldplace; |
| 82 | 82 |
| 83 CPVT_WordPlace oldplace; | 83 while (pIterator->NextWord()) { |
| 84 | 84 CPVT_WordPlace place = pIterator->GetAt(); |
| 85 while (pIterator->NextWord()) | 85 |
| 86 { | 86 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 87 CPVT_WordPlace place = pIterator->GetAt(); | 87 break; |
| 88 | 88 |
| 89 if (pRange && place.WordCmp(pRange->EndPos) > 0) break; | 89 if (bContinuous) { |
| 90 | 90 if (place.LineCmp(oldplace) != 0) { |
| 91 if (bContinuous) | 91 if (sWords.GetSize() > 0) { |
| 92 { | 92 sEditStream << GetWordRenderString(sWords.GetByteString()); |
| 93 if (place.LineCmp(oldplace) != 0) | 93 sWords.Clear(); |
| 94 { | 94 } |
| 95 if (sWords.GetSize() > 0) | 95 |
| 96 { | 96 CPVT_Word word; |
| 97 sEditStream << GetWordRenderStri
ng(sWords.GetByteString()); | 97 if (pIterator->GetWord(word)) { |
| 98 sWords.Clear(); | 98 ptNew = CPDF_Point(word.ptWord.x + ptOffset.x, |
| 99 } | 99 word.ptWord.y + ptOffset.y); |
| 100 | 100 } else { |
| 101 CPVT_Word word; | 101 CPVT_Line line; |
| 102 if (pIterator->GetWord(word)) | 102 pIterator->GetLine(line); |
| 103 { | 103 ptNew = CPDF_Point(line.ptLine.x + ptOffset.x, |
| 104 ptNew = CPDF_Point(word.ptWord.x
+ ptOffset.x, word.ptWord.y + ptOffset.y); | 104 line.ptLine.y + ptOffset.y); |
| 105 } | 105 } |
| 106 else | 106 |
| 107 { | 107 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { |
| 108 CPVT_Line line; | 108 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y |
| 109 pIterator->GetLine(line); | 109 << " Td\n"; |
| 110 ptNew = CPDF_Point(line.ptLine.x
+ ptOffset.x, line.ptLine.y + ptOffset.y); | 110 |
| 111 } | 111 ptOld = ptNew; |
| 112 | 112 } |
| 113 if (ptNew.x != ptOld.x || ptNew.y != ptO
ld.y) | 113 } |
| 114 { | 114 |
| 115 sEditStream << ptNew.x - ptOld.x
<< " " << ptNew.y - ptOld.y << " Td\n"; | 115 CPVT_Word word; |
| 116 | 116 if (pIterator->GetWord(word)) { |
| 117 ptOld = ptNew; | 117 if (word.nFontIndex != nCurFontIndex) { |
| 118 } | 118 if (sWords.GetSize() > 0) { |
| 119 } | 119 sEditStream << GetWordRenderString(sWords.GetByteString()); |
| 120 | 120 sWords.Clear(); |
| 121 CPVT_Word word; | 121 } |
| 122 if (pIterator->GetWord(word)) | 122 sEditStream << GetFontSetString(pEdit->GetFontMap(), |
| 123 { | 123 word.nFontIndex, word.fFontSize); |
| 124 if (word.nFontIndex != nCurFontIndex) | 124 nCurFontIndex = word.nFontIndex; |
| 125 { | 125 } |
| 126 if (sWords.GetSize() > 0) | 126 |
| 127 { | 127 sWords << GetPDFWordString(pEdit->GetFontMap(), nCurFontIndex, |
| 128 sEditStream << GetWordRe
nderString(sWords.GetByteString()); | 128 word.Word, SubWord); |
| 129 sWords.Clear(); | 129 } |
| 130 } | 130 |
| 131 sEditStream << GetFontSetString(
pEdit->GetFontMap(),word.nFontIndex,word.fFontSize); | 131 oldplace = place; |
| 132 nCurFontIndex = word.nFontIndex; | 132 } else { |
| 133 } | 133 CPVT_Word word; |
| 134 | 134 if (pIterator->GetWord(word)) { |
| 135 sWords << GetPDFWordString(pEdit->GetFon
tMap(),nCurFontIndex,word.Word,SubWord); | 135 ptNew = CPDF_Point(word.ptWord.x + ptOffset.x, |
| 136 } | 136 word.ptWord.y + ptOffset.y); |
| 137 | 137 |
| 138 oldplace = place; | 138 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { |
| 139 } | 139 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y |
| 140 else | 140 << " Td\n"; |
| 141 { | 141 ptOld = ptNew; |
| 142 CPVT_Word word; | 142 } |
| 143 if (pIterator->GetWord(word)) | 143 |
| 144 { | 144 if (word.nFontIndex != nCurFontIndex) { |
| 145 ptNew = CPDF_Point(word.ptWord.x + ptOff
set.x, word.ptWord.y + ptOffset.y); | 145 sEditStream << GetFontSetString(pEdit->GetFontMap(), |
| 146 | 146 word.nFontIndex, word.fFontSize); |
| 147 if (ptNew.x != ptOld.x || ptNew.y != ptO
ld.y) | 147 nCurFontIndex = word.nFontIndex; |
| 148 { | 148 } |
| 149 sEditStream << ptNew.x - ptOld.x
<< " " << ptNew.y - ptOld.y << " Td\n"; | 149 |
| 150 ptOld = ptNew; | 150 sEditStream << GetWordRenderString(GetPDFWordString( |
| 151 } | 151 pEdit->GetFontMap(), nCurFontIndex, word.Word, SubWord)); |
| 152 | 152 } |
| 153 if (word.nFontIndex != nCurFontIndex) | 153 } |
| 154 { | 154 } |
| 155 sEditStream << GetFontSetString(
pEdit->GetFontMap(),word.nFontIndex,word.fFontSize); | 155 |
| 156 nCurFontIndex = word.nFontIndex; | 156 if (sWords.GetSize() > 0) { |
| 157 } | 157 sEditStream << GetWordRenderString(sWords.GetByteString()); |
| 158 | 158 sWords.Clear(); |
| 159 sEditStream << GetWordRenderString(GetPD
FWordString(pEdit->GetFontMap(),nCurFontIndex,word.Word,SubWord)); | 159 } |
| 160 } | 160 } |
| 161 } | 161 |
| 162 } | 162 CFX_ByteTextBuf sAppStream; |
| 163 | 163 if (sEditStream.GetSize() > 0) { |
| 164 if (sWords.GetSize() > 0) | 164 int32_t nHorzScale = pEdit->GetHorzScale(); |
| 165 { | 165 if (nHorzScale != 100) { |
| 166 sEditStream << GetWordRenderString(sWords.GetByteString(
)); | 166 sAppStream << nHorzScale << " Tz\n"; |
| 167 sWords.Clear(); | 167 } |
| 168 } | 168 |
| 169 } | 169 FX_FLOAT fCharSpace = pEdit->GetCharSpace(); |
| 170 | 170 if (!FX_EDIT_IsFloatZero(fCharSpace)) { |
| 171 CFX_ByteTextBuf sAppStream; | 171 sAppStream << fCharSpace << " Tc\n"; |
| 172 if (sEditStream.GetSize() > 0) | 172 } |
| 173 { | 173 |
| 174 int32_t nHorzScale = pEdit->GetHorzScale(); | 174 sAppStream << sEditStream; |
| 175 if (nHorzScale != 100) | 175 } |
| 176 { | 176 |
| 177 sAppStream << nHorzScale << " Tz\n"; | 177 return sAppStream.GetByteString(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 FX_FLOAT fCharSpace = pEdit->GetCharSpace(); | 180 CFX_ByteString IFX_Edit::GetSelectAppearanceStream( |
| 181 if (!FX_EDIT_IsFloatZero(fCharSpace)) | 181 IFX_Edit* pEdit, |
| 182 { | 182 const CPDF_Point& ptOffset, |
| 183 sAppStream << fCharSpace << " Tc\n"; | 183 const CPVT_WordRange* pRange /*= NULL*/) { |
| 184 } | 184 CFX_ByteTextBuf sRet; |
| 185 | 185 |
| 186 sAppStream << sEditStream; | 186 if (pRange && pRange->IsExist()) { |
| 187 } | 187 if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { |
| 188 | 188 pIterator->SetAt(pRange->BeginPos); |
| 189 return sAppStream.GetByteString(); | 189 |
| 190 } | 190 while (pIterator->NextWord()) { |
| 191 | 191 CPVT_WordPlace place = pIterator->GetAt(); |
| 192 CFX_ByteString IFX_Edit::GetSelectAppearanceStream(IFX_Edit* pEdit, const CPDF_P
oint & ptOffset, | 192 |
| 193 const CPVT_WordRange * p
Range /*= NULL*/) | 193 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 194 { | 194 break; |
| 195 CFX_ByteTextBuf sRet; | 195 |
| 196 | 196 CPVT_Word word; |
| 197 if (pRange && pRange->IsExist()) | 197 CPVT_Line line; |
| 198 { | 198 if (pIterator->GetWord(word) && pIterator->GetLine(line)) { |
| 199 if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) | 199 // CPDF_Rect rcWordSel = CPDF_Rect(word.ptWord.x,line.ptLine.y + |
| 200 { | 200 // line.fLineDescent, |
| 201 pIterator->SetAt(pRange->BeginPos); | 201 // word.ptWord.x+word.fWidth,line.ptLine.y + |
| 202 | 202 //line.fLineAscent); |
| 203 while (pIterator->NextWord()) | 203 |
| 204 { | 204 sRet << word.ptWord.x + ptOffset.x << " " |
| 205 CPVT_WordPlace place = pIterator->GetAt(); | 205 << line.ptLine.y + line.fLineDescent << " " << word.fWidth << " " |
| 206 | 206 << line.fLineAscent - line.fLineDescent << " re\nf\n"; |
| 207 if (pRange && place.WordCmp(pRange->EndPos) > 0)
break; | 207 } |
| 208 | 208 } |
| 209 CPVT_Word word; | 209 } |
| 210 CPVT_Line line; | 210 } |
| 211 if (pIterator->GetWord(word) && pIterator->GetLi
ne(line)) | 211 |
| 212 { | 212 return sRet.GetByteString(); |
| 213 //CPDF_Rect rcWordSel = CPDF_Rect(word.p
tWord.x,line.ptLine.y + line.fLineDescent, | 213 } |
| 214 // word.ptWord.x+word.fWidt
h,line.ptLine.y + line.fLineAscent); | |
| 215 | |
| 216 sRet << word.ptWord.x + ptOffset.x << "
" << line.ptLine.y + line.fLineDescent | |
| 217 << " " << word.fWidth << " " <<
line.fLineAscent - line.fLineDescent << " re\nf\n"; | |
| 218 } | |
| 219 } | |
| 220 } | |
| 221 } | |
| 222 | |
| 223 return sRet.GetByteString(); | |
| 224 } | |
| 225 | |
| OLD | NEW |