| 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/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" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 IFX_Edit* pEdit, | 63 IFX_Edit* pEdit, |
| 64 const CFX_FloatPoint& ptOffset, | 64 const CFX_FloatPoint& ptOffset, |
| 65 const CPVT_WordRange* pRange /* = NULL*/, | 65 const CPVT_WordRange* pRange /* = NULL*/, |
| 66 FX_BOOL bContinuous /* = TRUE*/, | 66 FX_BOOL bContinuous /* = TRUE*/, |
| 67 uint16_t SubWord /* = 0*/) { | 67 uint16_t SubWord /* = 0*/) { |
| 68 CFX_ByteTextBuf sEditStream, sWords; | 68 CFX_ByteTextBuf sEditStream, sWords; |
| 69 | 69 |
| 70 CFX_FloatPoint ptOld(0.0f, 0.0f), ptNew(0.0f, 0.0f); | 70 CFX_FloatPoint ptOld(0.0f, 0.0f), ptNew(0.0f, 0.0f); |
| 71 int32_t nCurFontIndex = -1; | 71 int32_t nCurFontIndex = -1; |
| 72 | 72 |
| 73 if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { | 73 IFX_Edit_Iterator* pIterator = pEdit->GetIterator(); |
| 74 if (pRange) | 74 if (pRange) |
| 75 pIterator->SetAt(pRange->BeginPos); | 75 pIterator->SetAt(pRange->BeginPos); |
| 76 else | 76 else |
| 77 pIterator->SetAt(0); | 77 pIterator->SetAt(0); |
| 78 | 78 |
| 79 CPVT_WordPlace oldplace; | 79 CPVT_WordPlace oldplace; |
| 80 | 80 |
| 81 while (pIterator->NextWord()) { | 81 while (pIterator->NextWord()) { |
| 82 CPVT_WordPlace place = pIterator->GetAt(); | 82 CPVT_WordPlace place = pIterator->GetAt(); |
| 83 | 83 |
| 84 if (pRange && place.WordCmp(pRange->EndPos) > 0) | 84 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 85 break; | 85 break; |
| 86 | 86 |
| 87 if (bContinuous) { | 87 if (bContinuous) { |
| 88 if (place.LineCmp(oldplace) != 0) { | 88 if (place.LineCmp(oldplace) != 0) { |
| 89 if (sWords.GetSize() > 0) { |
| 90 sEditStream << GetWordRenderString(sWords.AsStringC()); |
| 91 sWords.Clear(); |
| 92 } |
| 93 |
| 94 CPVT_Word word; |
| 95 if (pIterator->GetWord(word)) { |
| 96 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, |
| 97 word.ptWord.y + ptOffset.y); |
| 98 } else { |
| 99 CPVT_Line line; |
| 100 pIterator->GetLine(line); |
| 101 ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x, |
| 102 line.ptLine.y + ptOffset.y); |
| 103 } |
| 104 |
| 105 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { |
| 106 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y |
| 107 << " Td\n"; |
| 108 |
| 109 ptOld = ptNew; |
| 110 } |
| 111 } |
| 112 |
| 113 CPVT_Word word; |
| 114 if (pIterator->GetWord(word)) { |
| 115 if (word.nFontIndex != nCurFontIndex) { |
| 89 if (sWords.GetSize() > 0) { | 116 if (sWords.GetSize() > 0) { |
| 90 sEditStream << GetWordRenderString(sWords.AsStringC()); | 117 sEditStream << GetWordRenderString(sWords.AsStringC()); |
| 91 sWords.Clear(); | 118 sWords.Clear(); |
| 92 } | 119 } |
| 93 | 120 sEditStream << GetFontSetString(pEdit->GetFontMap(), word.nFontIndex, |
| 94 CPVT_Word word; | 121 word.fFontSize); |
| 95 if (pIterator->GetWord(word)) { | 122 nCurFontIndex = word.nFontIndex; |
| 96 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, | |
| 97 word.ptWord.y + ptOffset.y); | |
| 98 } else { | |
| 99 CPVT_Line line; | |
| 100 pIterator->GetLine(line); | |
| 101 ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x, | |
| 102 line.ptLine.y + ptOffset.y); | |
| 103 } | |
| 104 | |
| 105 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { | |
| 106 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y | |
| 107 << " Td\n"; | |
| 108 | |
| 109 ptOld = ptNew; | |
| 110 } | |
| 111 } | 123 } |
| 112 | 124 |
| 113 CPVT_Word word; | 125 sWords << GetPDFWordString(pEdit->GetFontMap(), nCurFontIndex, |
| 114 if (pIterator->GetWord(word)) { | 126 word.Word, SubWord); |
| 115 if (word.nFontIndex != nCurFontIndex) { | 127 } |
| 116 if (sWords.GetSize() > 0) { | |
| 117 sEditStream << GetWordRenderString(sWords.AsStringC()); | |
| 118 sWords.Clear(); | |
| 119 } | |
| 120 sEditStream << GetFontSetString(pEdit->GetFontMap(), | |
| 121 word.nFontIndex, word.fFontSize); | |
| 122 nCurFontIndex = word.nFontIndex; | |
| 123 } | |
| 124 | 128 |
| 125 sWords << GetPDFWordString(pEdit->GetFontMap(), nCurFontIndex, | 129 oldplace = place; |
| 126 word.Word, SubWord); | 130 } else { |
| 131 CPVT_Word word; |
| 132 if (pIterator->GetWord(word)) { |
| 133 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, |
| 134 word.ptWord.y + ptOffset.y); |
| 135 |
| 136 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { |
| 137 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y |
| 138 << " Td\n"; |
| 139 ptOld = ptNew; |
| 127 } | 140 } |
| 128 | 141 |
| 129 oldplace = place; | 142 if (word.nFontIndex != nCurFontIndex) { |
| 130 } else { | 143 sEditStream << GetFontSetString(pEdit->GetFontMap(), word.nFontIndex, |
| 131 CPVT_Word word; | 144 word.fFontSize); |
| 132 if (pIterator->GetWord(word)) { | 145 nCurFontIndex = word.nFontIndex; |
| 133 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, | 146 } |
| 134 word.ptWord.y + ptOffset.y); | |
| 135 | 147 |
| 136 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { | 148 sEditStream << GetWordRenderString(GetPDFWordString( |
| 137 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y | 149 pEdit->GetFontMap(), nCurFontIndex, word.Word, SubWord)); |
| 138 << " Td\n"; | |
| 139 ptOld = ptNew; | |
| 140 } | |
| 141 | |
| 142 if (word.nFontIndex != nCurFontIndex) { | |
| 143 sEditStream << GetFontSetString(pEdit->GetFontMap(), | |
| 144 word.nFontIndex, word.fFontSize); | |
| 145 nCurFontIndex = word.nFontIndex; | |
| 146 } | |
| 147 | |
| 148 sEditStream << GetWordRenderString(GetPDFWordString( | |
| 149 pEdit->GetFontMap(), nCurFontIndex, word.Word, SubWord)); | |
| 150 } | |
| 151 } | 150 } |
| 152 } | 151 } |
| 153 | |
| 154 if (sWords.GetSize() > 0) { | |
| 155 sEditStream << GetWordRenderString(sWords.AsStringC()); | |
| 156 sWords.Clear(); | |
| 157 } | |
| 158 } | 152 } |
| 159 | 153 |
| 154 if (sWords.GetSize() > 0) { |
| 155 sEditStream << GetWordRenderString(sWords.AsStringC()); |
| 156 sWords.Clear(); |
| 157 } |
| 158 |
| 160 CFX_ByteTextBuf sAppStream; | 159 CFX_ByteTextBuf sAppStream; |
| 161 if (sEditStream.GetSize() > 0) { | 160 if (sEditStream.GetSize() > 0) { |
| 162 int32_t nHorzScale = pEdit->GetHorzScale(); | 161 int32_t nHorzScale = pEdit->GetHorzScale(); |
| 163 if (nHorzScale != 100) { | 162 if (nHorzScale != 100) { |
| 164 sAppStream << nHorzScale << " Tz\n"; | 163 sAppStream << nHorzScale << " Tz\n"; |
| 165 } | 164 } |
| 166 | 165 |
| 167 FX_FLOAT fCharSpace = pEdit->GetCharSpace(); | 166 FX_FLOAT fCharSpace = pEdit->GetCharSpace(); |
| 168 if (!FX_EDIT_IsFloatZero(fCharSpace)) { | 167 if (!FX_EDIT_IsFloatZero(fCharSpace)) { |
| 169 sAppStream << fCharSpace << " Tc\n"; | 168 sAppStream << fCharSpace << " Tc\n"; |
| 170 } | 169 } |
| 171 | 170 |
| 172 sAppStream << sEditStream; | 171 sAppStream << sEditStream; |
| 173 } | 172 } |
| 174 | 173 |
| 175 return sAppStream.AsStringC(); | 174 return sAppStream.AsStringC(); |
| 176 } | 175 } |
| 177 | 176 |
| 178 CFX_ByteString IFX_Edit::GetSelectAppearanceStream( | 177 CFX_ByteString IFX_Edit::GetSelectAppearanceStream( |
| 179 IFX_Edit* pEdit, | 178 IFX_Edit* pEdit, |
| 180 const CFX_FloatPoint& ptOffset, | 179 const CFX_FloatPoint& ptOffset, |
| 181 const CPVT_WordRange* pRange) { | 180 const CPVT_WordRange* pRange) { |
| 182 CFX_ByteTextBuf sRet; | 181 CFX_ByteTextBuf sRet; |
| 183 | 182 |
| 184 if (pRange && pRange->IsExist()) { | 183 if (pRange && pRange->IsExist()) { |
| 185 if (IFX_Edit_Iterator* pIterator = pEdit->GetIterator()) { | 184 IFX_Edit_Iterator* pIterator = pEdit->GetIterator(); |
| 186 pIterator->SetAt(pRange->BeginPos); | 185 pIterator->SetAt(pRange->BeginPos); |
| 187 | 186 |
| 188 while (pIterator->NextWord()) { | 187 while (pIterator->NextWord()) { |
| 189 CPVT_WordPlace place = pIterator->GetAt(); | 188 CPVT_WordPlace place = pIterator->GetAt(); |
| 190 | 189 |
| 191 if (pRange && place.WordCmp(pRange->EndPos) > 0) | 190 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 192 break; | 191 break; |
| 193 | 192 |
| 194 CPVT_Word word; | 193 CPVT_Word word; |
| 195 CPVT_Line line; | 194 CPVT_Line line; |
| 196 if (pIterator->GetWord(word) && pIterator->GetLine(line)) { | 195 if (pIterator->GetWord(word) && pIterator->GetLine(line)) { |
| 197 sRet << word.ptWord.x + ptOffset.x << " " | 196 sRet << word.ptWord.x + ptOffset.x << " " |
| 198 << line.ptLine.y + line.fLineDescent << " " << word.fWidth << " " | 197 << line.ptLine.y + line.fLineDescent << " " << word.fWidth << " " |
| 199 << line.fLineAscent - line.fLineDescent << " re\nf\n"; | 198 << line.fLineAscent - line.fLineDescent << " re\nf\n"; |
| 200 } | |
| 201 } | 199 } |
| 202 } | 200 } |
| 203 } | 201 } |
| 204 | 202 |
| 205 return sRet.AsStringC(); | 203 return sRet.AsStringC(); |
| 206 } | 204 } |
| OLD | NEW |