| 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" |
| 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" |
| 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
| 14 #include "core/fpdfdoc/cpvt_color.h" | 14 #include "core/fpdfdoc/cpvt_color.h" |
| 15 #include "core/fpdfdoc/cpvt_fontmap.h" | 15 #include "core/fpdfdoc/cpvt_fontmap.h" |
| 16 #include "core/fpdfdoc/cpvt_provider.h" | 16 #include "core/fpdfdoc/include/cpvt_word.h" |
| 17 #include "core/fpdfdoc/pdf_vt.h" | 17 #include "core/fpdfdoc/pdf_vt.h" |
| 18 #include "core/include/fpdfdoc/fpdf_doc.h" | 18 #include "core/include/fpdfdoc/fpdf_doc.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, | 22 FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
| 23 CPDF_Dictionary* pAnnotDict, | 23 CPDF_Dictionary* pAnnotDict, |
| 24 const int32_t& nWidgetType) { | 24 const int32_t& nWidgetType) { |
| 25 CPDF_Dictionary* pFormDict = nullptr; | 25 CPDF_Dictionary* pFormDict = nullptr; |
| 26 if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) | 26 if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 uint32_t dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff") | 210 uint32_t dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff") |
| 211 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() | 211 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() |
| 212 : 0; | 212 : 0; |
| 213 uint32_t dwMaxLen = | 213 uint32_t dwMaxLen = |
| 214 FPDF_GetFieldAttr(pAnnotDict, "MaxLen") | 214 FPDF_GetFieldAttr(pAnnotDict, "MaxLen") |
| 215 ? FPDF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger() | 215 ? FPDF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger() |
| 216 : 0; | 216 : 0; |
| 217 CPVT_FontMap map( | 217 CPVT_FontMap map( |
| 218 pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr, | 218 pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr, |
| 219 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); | 219 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
| 220 CPVT_Provider prd(&map); | 220 CPDF_VariableText::Provider prd(&map); |
| 221 CPDF_VariableText vt; | 221 CPDF_VariableText vt; |
| 222 vt.SetProvider(&prd); | 222 vt.SetProvider(&prd); |
| 223 vt.SetPlateRect(rcBody); | 223 vt.SetPlateRect(rcBody); |
| 224 vt.SetAlignment(nAlign); | 224 vt.SetAlignment(nAlign); |
| 225 if (IsFloatZero(fFontSize)) | 225 if (IsFloatZero(fFontSize)) |
| 226 vt.SetAutoFontSize(TRUE); | 226 vt.SetAutoFontSize(TRUE); |
| 227 else | 227 else |
| 228 vt.SetFontSize(fFontSize); | 228 vt.SetFontSize(fFontSize); |
| 229 | 229 |
| 230 FX_BOOL bMultiLine = (dwFlags >> 12) & 1; | 230 FX_BOOL bMultiLine = (dwFlags >> 12) & 1; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 269 } |
| 270 } break; | 270 } break; |
| 271 case 1: { | 271 case 1: { |
| 272 CFX_WideString swValue = | 272 CFX_WideString swValue = |
| 273 FPDF_GetFieldAttr(pAnnotDict, "V") | 273 FPDF_GetFieldAttr(pAnnotDict, "V") |
| 274 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() | 274 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() |
| 275 : CFX_WideString(); | 275 : CFX_WideString(); |
| 276 CPVT_FontMap map( | 276 CPVT_FontMap map( |
| 277 pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr, | 277 pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr, |
| 278 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); | 278 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
| 279 CPVT_Provider prd(&map); | 279 CPDF_VariableText::Provider prd(&map); |
| 280 CPDF_VariableText vt; | 280 CPDF_VariableText vt; |
| 281 vt.SetProvider(&prd); | 281 vt.SetProvider(&prd); |
| 282 CFX_FloatRect rcButton = rcBody; | 282 CFX_FloatRect rcButton = rcBody; |
| 283 rcButton.left = rcButton.right - 13; | 283 rcButton.left = rcButton.right - 13; |
| 284 rcButton.Normalize(); | 284 rcButton.Normalize(); |
| 285 CFX_FloatRect rcEdit = rcBody; | 285 CFX_FloatRect rcEdit = rcBody; |
| 286 rcEdit.right = rcButton.left; | 286 rcEdit.right = rcButton.left; |
| 287 rcEdit.Normalize(); | 287 rcEdit.Normalize(); |
| 288 vt.SetPlateRect(rcEdit); | 288 vt.SetPlateRect(rcEdit); |
| 289 if (IsFloatZero(fFontSize)) | 289 if (IsFloatZero(fFontSize)) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n"; | 337 sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n"; |
| 338 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n"; | 338 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n"; |
| 339 sAppStream << sButton << "Q\n"; | 339 sAppStream << sButton << "Q\n"; |
| 340 } | 340 } |
| 341 } | 341 } |
| 342 } break; | 342 } break; |
| 343 case 2: { | 343 case 2: { |
| 344 CPVT_FontMap map( | 344 CPVT_FontMap map( |
| 345 pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr, | 345 pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr, |
| 346 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); | 346 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
| 347 CPVT_Provider prd(&map); | 347 CPDF_VariableText::Provider prd(&map); |
| 348 CPDF_Array* pOpts = FPDF_GetFieldAttr(pAnnotDict, "Opt") | 348 CPDF_Array* pOpts = FPDF_GetFieldAttr(pAnnotDict, "Opt") |
| 349 ? FPDF_GetFieldAttr(pAnnotDict, "Opt")->GetArray() | 349 ? FPDF_GetFieldAttr(pAnnotDict, "Opt")->GetArray() |
| 350 : nullptr; | 350 : nullptr; |
| 351 CPDF_Array* pSels = FPDF_GetFieldAttr(pAnnotDict, "I") | 351 CPDF_Array* pSels = FPDF_GetFieldAttr(pAnnotDict, "I") |
| 352 ? FPDF_GetFieldAttr(pAnnotDict, "I")->GetArray() | 352 ? FPDF_GetFieldAttr(pAnnotDict, "I")->GetArray() |
| 353 : nullptr; | 353 : nullptr; |
| 354 int32_t nTop = FPDF_GetFieldAttr(pAnnotDict, "TI") | 354 int32_t nTop = FPDF_GetFieldAttr(pAnnotDict, "TI") |
| 355 ? FPDF_GetFieldAttr(pAnnotDict, "TI")->GetInteger() | 355 ? FPDF_GetFieldAttr(pAnnotDict, "TI")->GetInteger() |
| 356 : 0; | 356 : 0; |
| 357 CFX_ByteTextBuf sBody; | 357 CFX_ByteTextBuf sBody; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 | 495 |
| 496 // Static. | 496 // Static. |
| 497 FX_BOOL CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc, | 497 FX_BOOL CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc, |
| 498 CPDF_Dictionary* pAnnotDict) { | 498 CPDF_Dictionary* pAnnotDict) { |
| 499 return GenerateWidgetAP(pDoc, pAnnotDict, 2); | 499 return GenerateWidgetAP(pDoc, pAnnotDict, 2); |
| 500 } | 500 } |
| 501 | 501 |
| 502 // Static. | 502 // Static. |
| 503 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( | 503 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( |
| 504 IPVT_FontMap* pFontMap, | 504 IPVT_FontMap* pFontMap, |
| 505 IPDF_VariableText::Iterator* pIterator, | 505 CPDF_VariableText::Iterator* pIterator, |
| 506 const CFX_FloatPoint& ptOffset, | 506 const CFX_FloatPoint& ptOffset, |
| 507 FX_BOOL bContinuous, | 507 FX_BOOL bContinuous, |
| 508 uint16_t SubWord, | 508 uint16_t SubWord, |
| 509 const CPVT_WordRange* pVisible) { | 509 const CPVT_WordRange* pVisible) { |
| 510 CFX_ByteTextBuf sEditStream, sLineStream, sWords; | 510 CFX_ByteTextBuf sEditStream, sLineStream, sWords; |
| 511 CFX_FloatPoint ptOld(0.0f, 0.0f), ptNew(0.0f, 0.0f); | 511 CFX_FloatPoint ptOld(0.0f, 0.0f), ptNew(0.0f, 0.0f); |
| 512 int32_t nCurFontIndex = -1; | 512 int32_t nCurFontIndex = -1; |
| 513 if (pIterator) { | 513 if (pIterator) { |
| 514 if (pVisible) | 514 if (pVisible) |
| 515 pIterator->SetAt(pVisible->BeginPos); | 515 pIterator->SetAt(pVisible->BeginPos); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 int32_t nFontIndex, | 763 int32_t nFontIndex, |
| 764 FX_FLOAT fFontSize) { | 764 FX_FLOAT fFontSize) { |
| 765 CFX_ByteTextBuf sRet; | 765 CFX_ByteTextBuf sRet; |
| 766 if (pFontMap) { | 766 if (pFontMap) { |
| 767 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 767 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
| 768 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 768 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
| 769 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 769 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
| 770 } | 770 } |
| 771 return sRet.GetByteString(); | 771 return sRet.GetByteString(); |
| 772 } | 772 } |
| OLD | NEW |