| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/fpdfdoc/cpvt_generateap.h" | 7 #include "core/fpdfdoc/cpvt_generateap.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 FX_BOOL bCharArray = (dwFlags >> 24) & 1; | 230 FX_BOOL bCharArray = (dwFlags >> 24) & 1; |
| 231 if (bCharArray) | 231 if (bCharArray) |
| 232 vt.SetCharArray(dwMaxLen); | 232 vt.SetCharArray(dwMaxLen); |
| 233 else | 233 else |
| 234 vt.SetLimitChar(dwMaxLen); | 234 vt.SetLimitChar(dwMaxLen); |
| 235 | 235 |
| 236 vt.Initialize(); | 236 vt.Initialize(); |
| 237 vt.SetText(swValue); | 237 vt.SetText(swValue); |
| 238 vt.RearrangeAll(); | 238 vt.RearrangeAll(); |
| 239 CFX_FloatRect rcContent = vt.GetContentRect(); | 239 CFX_FloatRect rcContent = vt.GetContentRect(); |
| 240 CFX_FloatPoint ptOffset(0.0f, 0.0f); | 240 CFX_FloatPoint ptOffset; |
| 241 if (!bMultiLine) { | 241 if (!bMultiLine) { |
| 242 ptOffset = | 242 ptOffset = |
| 243 CFX_FloatPoint(0.0f, (rcContent.Height() - rcBody.Height()) / 2.0f); | 243 CFX_FloatPoint(0.0f, (rcContent.Height() - rcBody.Height()) / 2.0f); |
| 244 } | 244 } |
| 245 CFX_ByteString sBody = CPVT_GenerateAP::GenerateEditAP( | 245 CFX_ByteString sBody = CPVT_GenerateAP::GenerateEditAP( |
| 246 &map, vt.GetIterator(), ptOffset, !bCharArray, subWord); | 246 &map, vt.GetIterator(), ptOffset, !bCharArray, subWord); |
| 247 if (sBody.GetLength() > 0) { | 247 if (sBody.GetLength() > 0) { |
| 248 sAppStream << "/Tx BMC\n" | 248 sAppStream << "/Tx BMC\n" |
| 249 << "q\n"; | 249 << "q\n"; |
| 250 if (rcContent.Width() > rcBody.Width() || | 250 if (rcContent.Width() > rcBody.Width() || |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 // Static. | 1076 // Static. |
| 1077 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( | 1077 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( |
| 1078 IPVT_FontMap* pFontMap, | 1078 IPVT_FontMap* pFontMap, |
| 1079 CPDF_VariableText::Iterator* pIterator, | 1079 CPDF_VariableText::Iterator* pIterator, |
| 1080 const CFX_FloatPoint& ptOffset, | 1080 const CFX_FloatPoint& ptOffset, |
| 1081 FX_BOOL bContinuous, | 1081 FX_BOOL bContinuous, |
| 1082 uint16_t SubWord) { | 1082 uint16_t SubWord) { |
| 1083 CFX_ByteTextBuf sEditStream; | 1083 CFX_ByteTextBuf sEditStream; |
| 1084 CFX_ByteTextBuf sLineStream; | 1084 CFX_ByteTextBuf sLineStream; |
| 1085 CFX_ByteTextBuf sWords; | 1085 CFX_ByteTextBuf sWords; |
| 1086 CFX_FloatPoint ptOld(0.0f, 0.0f); | 1086 CFX_FloatPoint ptOld; |
| 1087 CFX_FloatPoint ptNew(0.0f, 0.0f); | 1087 CFX_FloatPoint ptNew; |
| 1088 int32_t nCurFontIndex = -1; | 1088 int32_t nCurFontIndex = -1; |
| 1089 CPVT_WordPlace oldplace; |
| 1089 | 1090 |
| 1090 pIterator->SetAt(0); | 1091 pIterator->SetAt(0); |
| 1091 | |
| 1092 CPVT_WordPlace oldplace; | |
| 1093 while (pIterator->NextWord()) { | 1092 while (pIterator->NextWord()) { |
| 1094 CPVT_WordPlace place = pIterator->GetAt(); | 1093 CPVT_WordPlace place = pIterator->GetAt(); |
| 1095 if (bContinuous) { | 1094 if (bContinuous) { |
| 1096 if (place.LineCmp(oldplace) != 0) { | 1095 if (place.LineCmp(oldplace) != 0) { |
| 1097 if (sWords.GetSize() > 0) { | 1096 if (sWords.GetSize() > 0) { |
| 1098 sLineStream << GetWordRenderString(sWords.MakeString()); | 1097 sLineStream << GetWordRenderString(sWords.MakeString()); |
| 1099 sEditStream << sLineStream; | 1098 sEditStream << sLineStream; |
| 1100 sLineStream.Clear(); | 1099 sLineStream.Clear(); |
| 1101 sWords.Clear(); | 1100 sWords.Clear(); |
| 1102 } | 1101 } |
| 1103 CPVT_Word word; | 1102 CPVT_Word word; |
| 1104 if (pIterator->GetWord(word)) { | 1103 if (pIterator->GetWord(word)) { |
| 1105 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, | 1104 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, |
| 1106 word.ptWord.y + ptOffset.y); | 1105 word.ptWord.y + ptOffset.y); |
| 1107 } else { | 1106 } else { |
| 1108 CPVT_Line line; | 1107 CPVT_Line line; |
| 1109 pIterator->GetLine(line); | 1108 pIterator->GetLine(line); |
| 1110 ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x, | 1109 ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x, |
| 1111 line.ptLine.y + ptOffset.y); | 1110 line.ptLine.y + ptOffset.y); |
| 1112 } | 1111 } |
| 1113 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { | 1112 if (ptNew != ptOld) { |
| 1114 sLineStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y | 1113 sLineStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y |
| 1115 << " Td\n"; | 1114 << " Td\n"; |
| 1116 ptOld = ptNew; | 1115 ptOld = ptNew; |
| 1117 } | 1116 } |
| 1118 } | 1117 } |
| 1119 CPVT_Word word; | 1118 CPVT_Word word; |
| 1120 if (pIterator->GetWord(word)) { | 1119 if (pIterator->GetWord(word)) { |
| 1121 if (word.nFontIndex != nCurFontIndex) { | 1120 if (word.nFontIndex != nCurFontIndex) { |
| 1122 if (sWords.GetSize() > 0) { | 1121 if (sWords.GetSize() > 0) { |
| 1123 sLineStream << GetWordRenderString(sWords.MakeString()); | 1122 sLineStream << GetWordRenderString(sWords.MakeString()); |
| 1124 sWords.Clear(); | 1123 sWords.Clear(); |
| 1125 } | 1124 } |
| 1126 sLineStream << GetFontSetString(pFontMap, word.nFontIndex, | 1125 sLineStream << GetFontSetString(pFontMap, word.nFontIndex, |
| 1127 word.fFontSize); | 1126 word.fFontSize); |
| 1128 nCurFontIndex = word.nFontIndex; | 1127 nCurFontIndex = word.nFontIndex; |
| 1129 } | 1128 } |
| 1130 sWords << GetPDFWordString(pFontMap, nCurFontIndex, word.Word, SubWord); | 1129 sWords << GetPDFWordString(pFontMap, nCurFontIndex, word.Word, SubWord); |
| 1131 } | 1130 } |
| 1132 oldplace = place; | 1131 oldplace = place; |
| 1133 } else { | 1132 } else { |
| 1134 CPVT_Word word; | 1133 CPVT_Word word; |
| 1135 if (pIterator->GetWord(word)) { | 1134 if (pIterator->GetWord(word)) { |
| 1136 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, | 1135 ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x, |
| 1137 word.ptWord.y + ptOffset.y); | 1136 word.ptWord.y + ptOffset.y); |
| 1138 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { | 1137 if (ptNew != ptOld) { |
| 1139 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y | 1138 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y |
| 1140 << " Td\n"; | 1139 << " Td\n"; |
| 1141 ptOld = ptNew; | 1140 ptOld = ptNew; |
| 1142 } | 1141 } |
| 1143 if (word.nFontIndex != nCurFontIndex) { | 1142 if (word.nFontIndex != nCurFontIndex) { |
| 1144 sEditStream << GetFontSetString(pFontMap, word.nFontIndex, | 1143 sEditStream << GetFontSetString(pFontMap, word.nFontIndex, |
| 1145 word.fFontSize); | 1144 word.fFontSize); |
| 1146 nCurFontIndex = word.nFontIndex; | 1145 nCurFontIndex = word.nFontIndex; |
| 1147 } | 1146 } |
| 1148 sEditStream << GetWordRenderString( | 1147 sEditStream << GetWordRenderString( |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 int32_t nFontIndex, | 1333 int32_t nFontIndex, |
| 1335 FX_FLOAT fFontSize) { | 1334 FX_FLOAT fFontSize) { |
| 1336 CFX_ByteTextBuf sRet; | 1335 CFX_ByteTextBuf sRet; |
| 1337 if (pFontMap) { | 1336 if (pFontMap) { |
| 1338 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 1337 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
| 1339 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 1338 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
| 1340 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 1339 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
| 1341 } | 1340 } |
| 1342 return sRet.MakeString(); | 1341 return sRet.MakeString(); |
| 1343 } | 1342 } |
| OLD | NEW |