| 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 30 matching lines...) Expand all Loading... |
| 41 if (strWords.GetLength() > 0) | 41 if (strWords.GetLength() > 0) |
| 42 return PDF_EncodeString(strWords) + " Tj\n"; | 42 return PDF_EncodeString(strWords) + " Tj\n"; |
| 43 | 43 |
| 44 return ""; | 44 return ""; |
| 45 } | 45 } |
| 46 | 46 |
| 47 static CFX_ByteString GetFontSetString(IPVT_FontMap* pFontMap, | 47 static CFX_ByteString GetFontSetString(IPVT_FontMap* pFontMap, |
| 48 int32_t nFontIndex, | 48 int32_t nFontIndex, |
| 49 FX_FLOAT fFontSize) { | 49 FX_FLOAT fFontSize) { |
| 50 CFX_ByteTextBuf sRet; | 50 CFX_ByteTextBuf sRet; |
| 51 | |
| 52 if (pFontMap) { | 51 if (pFontMap) { |
| 53 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 52 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
| 54 | |
| 55 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 53 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
| 56 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 54 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
| 57 } | 55 } |
| 58 | 56 return sRet.MakeString(); |
| 59 return sRet.AsStringC(); | |
| 60 } | 57 } |
| 61 | 58 |
| 62 CFX_ByteString IFX_Edit::GetEditAppearanceStream( | 59 CFX_ByteString IFX_Edit::GetEditAppearanceStream( |
| 63 IFX_Edit* pEdit, | 60 IFX_Edit* pEdit, |
| 64 const CFX_FloatPoint& ptOffset, | 61 const CFX_FloatPoint& ptOffset, |
| 65 const CPVT_WordRange* pRange /* = NULL*/, | 62 const CPVT_WordRange* pRange /* = NULL*/, |
| 66 FX_BOOL bContinuous /* = TRUE*/, | 63 FX_BOOL bContinuous /* = TRUE*/, |
| 67 uint16_t SubWord /* = 0*/) { | 64 uint16_t SubWord /* = 0*/) { |
| 68 CFX_ByteTextBuf sEditStream, sWords; | 65 CFX_ByteTextBuf sEditStream, sWords; |
| 69 | 66 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 80 | 77 |
| 81 while (pIterator->NextWord()) { | 78 while (pIterator->NextWord()) { |
| 82 CPVT_WordPlace place = pIterator->GetAt(); | 79 CPVT_WordPlace place = pIterator->GetAt(); |
| 83 | 80 |
| 84 if (pRange && place.WordCmp(pRange->EndPos) > 0) | 81 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 85 break; | 82 break; |
| 86 | 83 |
| 87 if (bContinuous) { | 84 if (bContinuous) { |
| 88 if (place.LineCmp(oldplace) != 0) { | 85 if (place.LineCmp(oldplace) != 0) { |
| 89 if (sWords.GetSize() > 0) { | 86 if (sWords.GetSize() > 0) { |
| 90 sEditStream << GetWordRenderString(sWords.AsStringC()); | 87 sEditStream << GetWordRenderString(sWords.MakeString()); |
| 91 sWords.Clear(); | 88 sWords.Clear(); |
| 92 } | 89 } |
| 93 | 90 |
| 94 CPVT_Word word; | 91 CPVT_Word word; |
| 95 if (pIterator->GetWord(word)) { | 92 if (pIterator->GetWord(word)) { |
| 96 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, | 93 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, |
| 97 word.ptWord.y + ptOffset.y); | 94 word.ptWord.y + ptOffset.y); |
| 98 } else { | 95 } else { |
| 99 CPVT_Line line; | 96 CPVT_Line line; |
| 100 pIterator->GetLine(line); | 97 pIterator->GetLine(line); |
| 101 ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x, | 98 ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x, |
| 102 line.ptLine.y + ptOffset.y); | 99 line.ptLine.y + ptOffset.y); |
| 103 } | 100 } |
| 104 | 101 |
| 105 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { | 102 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { |
| 106 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y | 103 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y |
| 107 << " Td\n"; | 104 << " Td\n"; |
| 108 | 105 |
| 109 ptOld = ptNew; | 106 ptOld = ptNew; |
| 110 } | 107 } |
| 111 } | 108 } |
| 112 | 109 |
| 113 CPVT_Word word; | 110 CPVT_Word word; |
| 114 if (pIterator->GetWord(word)) { | 111 if (pIterator->GetWord(word)) { |
| 115 if (word.nFontIndex != nCurFontIndex) { | 112 if (word.nFontIndex != nCurFontIndex) { |
| 116 if (sWords.GetSize() > 0) { | 113 if (sWords.GetSize() > 0) { |
| 117 sEditStream << GetWordRenderString(sWords.AsStringC()); | 114 sEditStream << GetWordRenderString(sWords.MakeString()); |
| 118 sWords.Clear(); | 115 sWords.Clear(); |
| 119 } | 116 } |
| 120 sEditStream << GetFontSetString(pEdit->GetFontMap(), word.nFontIndex, | 117 sEditStream << GetFontSetString(pEdit->GetFontMap(), word.nFontIndex, |
| 121 word.fFontSize); | 118 word.fFontSize); |
| 122 nCurFontIndex = word.nFontIndex; | 119 nCurFontIndex = word.nFontIndex; |
| 123 } | 120 } |
| 124 | 121 |
| 125 sWords << GetPDFWordString(pEdit->GetFontMap(), nCurFontIndex, | 122 sWords << GetPDFWordString(pEdit->GetFontMap(), nCurFontIndex, |
| 126 word.Word, SubWord); | 123 word.Word, SubWord); |
| 127 } | 124 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 145 nCurFontIndex = word.nFontIndex; | 142 nCurFontIndex = word.nFontIndex; |
| 146 } | 143 } |
| 147 | 144 |
| 148 sEditStream << GetWordRenderString(GetPDFWordString( | 145 sEditStream << GetWordRenderString(GetPDFWordString( |
| 149 pEdit->GetFontMap(), nCurFontIndex, word.Word, SubWord)); | 146 pEdit->GetFontMap(), nCurFontIndex, word.Word, SubWord)); |
| 150 } | 147 } |
| 151 } | 148 } |
| 152 } | 149 } |
| 153 | 150 |
| 154 if (sWords.GetSize() > 0) { | 151 if (sWords.GetSize() > 0) { |
| 155 sEditStream << GetWordRenderString(sWords.AsStringC()); | 152 sEditStream << GetWordRenderString(sWords.MakeString()); |
| 156 sWords.Clear(); | 153 sWords.Clear(); |
| 157 } | 154 } |
| 158 | 155 |
| 159 CFX_ByteTextBuf sAppStream; | 156 CFX_ByteTextBuf sAppStream; |
| 160 if (sEditStream.GetSize() > 0) { | 157 if (sEditStream.GetSize() > 0) { |
| 161 int32_t nHorzScale = pEdit->GetHorzScale(); | 158 int32_t nHorzScale = pEdit->GetHorzScale(); |
| 162 if (nHorzScale != 100) { | 159 if (nHorzScale != 100) { |
| 163 sAppStream << nHorzScale << " Tz\n"; | 160 sAppStream << nHorzScale << " Tz\n"; |
| 164 } | 161 } |
| 165 | 162 |
| 166 FX_FLOAT fCharSpace = pEdit->GetCharSpace(); | 163 FX_FLOAT fCharSpace = pEdit->GetCharSpace(); |
| 167 if (!FX_EDIT_IsFloatZero(fCharSpace)) { | 164 if (!FX_EDIT_IsFloatZero(fCharSpace)) { |
| 168 sAppStream << fCharSpace << " Tc\n"; | 165 sAppStream << fCharSpace << " Tc\n"; |
| 169 } | 166 } |
| 170 | 167 |
| 171 sAppStream << sEditStream; | 168 sAppStream << sEditStream; |
| 172 } | 169 } |
| 173 | 170 |
| 174 return sAppStream.AsStringC(); | 171 return sAppStream.MakeString(); |
| 175 } | 172 } |
| 176 | 173 |
| 177 CFX_ByteString IFX_Edit::GetSelectAppearanceStream( | 174 CFX_ByteString IFX_Edit::GetSelectAppearanceStream( |
| 178 IFX_Edit* pEdit, | 175 IFX_Edit* pEdit, |
| 179 const CFX_FloatPoint& ptOffset, | 176 const CFX_FloatPoint& ptOffset, |
| 180 const CPVT_WordRange* pRange) { | 177 const CPVT_WordRange* pRange) { |
| 181 CFX_ByteTextBuf sRet; | 178 CFX_ByteTextBuf sRet; |
| 182 | 179 |
| 183 if (pRange && pRange->IsExist()) { | 180 if (pRange && pRange->IsExist()) { |
| 184 IFX_Edit_Iterator* pIterator = pEdit->GetIterator(); | 181 IFX_Edit_Iterator* pIterator = pEdit->GetIterator(); |
| 185 pIterator->SetAt(pRange->BeginPos); | 182 pIterator->SetAt(pRange->BeginPos); |
| 186 | 183 |
| 187 while (pIterator->NextWord()) { | 184 while (pIterator->NextWord()) { |
| 188 CPVT_WordPlace place = pIterator->GetAt(); | 185 CPVT_WordPlace place = pIterator->GetAt(); |
| 189 | 186 |
| 190 if (pRange && place.WordCmp(pRange->EndPos) > 0) | 187 if (pRange && place.WordCmp(pRange->EndPos) > 0) |
| 191 break; | 188 break; |
| 192 | 189 |
| 193 CPVT_Word word; | 190 CPVT_Word word; |
| 194 CPVT_Line line; | 191 CPVT_Line line; |
| 195 if (pIterator->GetWord(word) && pIterator->GetLine(line)) { | 192 if (pIterator->GetWord(word) && pIterator->GetLine(line)) { |
| 196 sRet << word.ptWord.x + ptOffset.x << " " | 193 sRet << word.ptWord.x + ptOffset.x << " " |
| 197 << line.ptLine.y + line.fLineDescent << " " << word.fWidth << " " | 194 << line.ptLine.y + line.fLineDescent << " " << word.fWidth << " " |
| 198 << line.fLineAscent - line.fLineDescent << " re\nf\n"; | 195 << line.fLineAscent - line.fLineDescent << " re\nf\n"; |
| 199 } | 196 } |
| 200 } | 197 } |
| 201 } | 198 } |
| 202 | 199 |
| 203 return sRet.AsStringC(); | 200 return sRet.MakeString(); |
| 204 } | 201 } |
| OLD | NEW |