| 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 "core/include/fpdfapi/fpdf_resource.h" | 7 #include "core/include/fpdfapi/fpdf_resource.h" |
| 8 #include "fpdfsdk/include/fxedit/fx_edit.h" | 8 #include "fpdfsdk/include/fxedit/fx_edit.h" |
| 9 #include "fpdfsdk/include/fxedit/fxet_edit.h" | 9 #include "fpdfsdk/include/fxedit/fxet_edit.h" |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 54 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
| 55 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 55 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
| 56 } | 56 } |
| 57 | 57 |
| 58 return sRet.GetByteString(); | 58 return sRet.GetByteString(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 CFX_ByteString IFX_Edit::GetEditAppearanceStream( | 61 CFX_ByteString IFX_Edit::GetEditAppearanceStream( |
| 62 IFX_Edit* pEdit, | 62 IFX_Edit* pEdit, |
| 63 const CFX_FloatPoint& ptOffset, | 63 const CPDF_Point& ptOffset, |
| 64 const CPVT_WordRange* pRange /* = NULL*/, | 64 const CPVT_WordRange* pRange /* = NULL*/, |
| 65 FX_BOOL bContinuous /* = TRUE*/, | 65 FX_BOOL bContinuous /* = TRUE*/, |
| 66 FX_WORD SubWord /* = 0*/) { | 66 FX_WORD SubWord /* = 0*/) { |
| 67 CFX_ByteTextBuf sEditStream, sWords; | 67 CFX_ByteTextBuf sEditStream, sWords; |
| 68 | 68 |
| 69 CFX_FloatPoint ptOld(0.0f, 0.0f), ptNew(0.0f, 0.0f); | 69 CPDF_Point ptOld(0.0f, 0.0f), ptNew(0.0f, 0.0f); |
| 70 int32_t nCurFontIndex = -1; | 70 int32_t nCurFontIndex = -1; |
| 71 | 71 |
| 72 if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { | 72 if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { |
| 73 if (pRange) | 73 if (pRange) |
| 74 pIterator->SetAt(pRange->BeginPos); | 74 pIterator->SetAt(pRange->BeginPos); |
| 75 else | 75 else |
| 76 pIterator->SetAt(0); | 76 pIterator->SetAt(0); |
| 77 | 77 |
| 78 CPVT_WordPlace oldplace; | 78 CPVT_WordPlace oldplace; |
| 79 | 79 |
| 80 while (pIterator->NextWord()) { | 80 while (pIterator->NextWord()) { |
| 81 CPVT_WordPlace place = pIterator->GetAt(); | 81 CPVT_WordPlace place = pIterator->GetAt(); |
| 82 | 82 |
| 83 if (pRange && place.WordCmp(pRange->EndPos) > 0) | 83 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 84 break; | 84 break; |
| 85 | 85 |
| 86 if (bContinuous) { | 86 if (bContinuous) { |
| 87 if (place.LineCmp(oldplace) != 0) { | 87 if (place.LineCmp(oldplace) != 0) { |
| 88 if (sWords.GetSize() > 0) { | 88 if (sWords.GetSize() > 0) { |
| 89 sEditStream << GetWordRenderString(sWords.GetByteString()); | 89 sEditStream << GetWordRenderString(sWords.GetByteString()); |
| 90 sWords.Clear(); | 90 sWords.Clear(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 CPVT_Word word; | 93 CPVT_Word word; |
| 94 if (pIterator->GetWord(word)) { | 94 if (pIterator->GetWord(word)) { |
| 95 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, | 95 ptNew = CPDF_Point(word.ptWord.x + ptOffset.x, |
| 96 word.ptWord.y + ptOffset.y); | 96 word.ptWord.y + ptOffset.y); |
| 97 } else { | 97 } else { |
| 98 CPVT_Line line; | 98 CPVT_Line line; |
| 99 pIterator->GetLine(line); | 99 pIterator->GetLine(line); |
| 100 ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x, | 100 ptNew = CPDF_Point(line.ptLine.x + ptOffset.x, |
| 101 line.ptLine.y + ptOffset.y); | 101 line.ptLine.y + ptOffset.y); |
| 102 } | 102 } |
| 103 | 103 |
| 104 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { | 104 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { |
| 105 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y | 105 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y |
| 106 << " Td\n"; | 106 << " Td\n"; |
| 107 | 107 |
| 108 ptOld = ptNew; | 108 ptOld = ptNew; |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 122 } | 122 } |
| 123 | 123 |
| 124 sWords << GetPDFWordString(pEdit->GetFontMap(), nCurFontIndex, | 124 sWords << GetPDFWordString(pEdit->GetFontMap(), nCurFontIndex, |
| 125 word.Word, SubWord); | 125 word.Word, SubWord); |
| 126 } | 126 } |
| 127 | 127 |
| 128 oldplace = place; | 128 oldplace = place; |
| 129 } else { | 129 } else { |
| 130 CPVT_Word word; | 130 CPVT_Word word; |
| 131 if (pIterator->GetWord(word)) { | 131 if (pIterator->GetWord(word)) { |
| 132 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, | 132 ptNew = CPDF_Point(word.ptWord.x + ptOffset.x, |
| 133 word.ptWord.y + ptOffset.y); | 133 word.ptWord.y + ptOffset.y); |
| 134 | 134 |
| 135 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { | 135 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { |
| 136 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y | 136 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y |
| 137 << " Td\n"; | 137 << " Td\n"; |
| 138 ptOld = ptNew; | 138 ptOld = ptNew; |
| 139 } | 139 } |
| 140 | 140 |
| 141 if (word.nFontIndex != nCurFontIndex) { | 141 if (word.nFontIndex != nCurFontIndex) { |
| 142 sEditStream << GetFontSetString(pEdit->GetFontMap(), | 142 sEditStream << GetFontSetString(pEdit->GetFontMap(), |
| 143 word.nFontIndex, word.fFontSize); | 143 word.nFontIndex, word.fFontSize); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 169 } | 169 } |
| 170 | 170 |
| 171 sAppStream << sEditStream; | 171 sAppStream << sEditStream; |
| 172 } | 172 } |
| 173 | 173 |
| 174 return sAppStream.GetByteString(); | 174 return sAppStream.GetByteString(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 CFX_ByteString IFX_Edit::GetSelectAppearanceStream( | 177 CFX_ByteString IFX_Edit::GetSelectAppearanceStream( |
| 178 IFX_Edit* pEdit, | 178 IFX_Edit* pEdit, |
| 179 const CFX_FloatPoint& ptOffset, | 179 const CPDF_Point& ptOffset, |
| 180 const CPVT_WordRange* pRange) { | 180 const CPVT_WordRange* pRange) { |
| 181 CFX_ByteTextBuf sRet; | 181 CFX_ByteTextBuf sRet; |
| 182 | 182 |
| 183 if (pRange && pRange->IsExist()) { | 183 if (pRange && pRange->IsExist()) { |
| 184 if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { | 184 if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { |
| 185 pIterator->SetAt(pRange->BeginPos); | 185 pIterator->SetAt(pRange->BeginPos); |
| 186 | 186 |
| 187 while (pIterator->NextWord()) { | 187 while (pIterator->NextWord()) { |
| 188 CPVT_WordPlace place = pIterator->GetAt(); | 188 CPVT_WordPlace place = pIterator->GetAt(); |
| 189 | 189 |
| 190 if (pRange && place.WordCmp(pRange->EndPos) > 0) | 190 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 191 break; | 191 break; |
| 192 | 192 |
| 193 CPVT_Word word; | 193 CPVT_Word word; |
| 194 CPVT_Line line; | 194 CPVT_Line line; |
| 195 if (pIterator->GetWord(word) && pIterator->GetLine(line)) { | 195 if (pIterator->GetWord(word) && pIterator->GetLine(line)) { |
| 196 sRet << word.ptWord.x + ptOffset.x << " " | 196 sRet << word.ptWord.x + ptOffset.x << " " |
| 197 << line.ptLine.y + line.fLineDescent << " " << word.fWidth << " " | 197 << line.ptLine.y + line.fLineDescent << " " << word.fWidth << " " |
| 198 << line.fLineAscent - line.fLineDescent << " re\nf\n"; | 198 << line.fLineAscent - line.fLineDescent << " re\nf\n"; |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 | 203 |
| 204 return sRet.GetByteString(); | 204 return sRet.GetByteString(); |
| 205 } | 205 } |
| OLD | NEW |