| 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/cpdf_array.h" | 8 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" |
| 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
| 12 #include "core/fpdfdoc/doc_utils.h" | 12 #include "core/fpdfdoc/doc_utils.h" |
| 13 #include "core/fpdfdoc/pdf_vt.h" | 13 #include "core/fpdfdoc/pdf_vt.h" |
| 14 #include "core/include/fpdfdoc/fpdf_ap.h" | 14 #include "core/include/fpdfdoc/fpdf_ap.h" |
| 15 #include "core/include/fpdfdoc/fpdf_doc.h" | 15 #include "core/include/fpdfdoc/fpdf_doc.h" |
| 16 #include "core/include/fpdfdoc/fpdf_vt.h" | 16 #include "core/include/fpdfdoc/fpdf_vt.h" |
| 17 | 17 |
| 18 #define PBS_SOLID 0 | 18 #define PBS_SOLID 0 |
| 19 #define PBS_DASH 1 | 19 #define PBS_DASH 1 |
| 20 #define PBS_BEVELED 2 | 20 #define PBS_BEVELED 2 |
| 21 #define PBS_INSET 3 | 21 #define PBS_INSET 3 |
| 22 #define PBS_UNDERLINED 4 | 22 #define PBS_UNDERLINED 4 |
| 23 | 23 |
| 24 FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { | 24 FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { |
| 25 if (!pAnnotDict || pAnnotDict->GetConstStringBy("Subtype") != "Widget") { | 25 if (!pAnnotDict || pAnnotDict->GetConstStringBy("Subtype") != "Widget") { |
| 26 return FALSE; | 26 return FALSE; |
| 27 } | 27 } |
| 28 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); | 28 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); |
| 29 FX_DWORD flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") | 29 uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") |
| 30 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() | 30 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() |
| 31 : 0; | 31 : 0; |
| 32 if (field_type == "Tx") { | 32 if (field_type == "Tx") { |
| 33 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict); | 33 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict); |
| 34 } | 34 } |
| 35 if (field_type == "Ch") { | 35 if (field_type == "Ch") { |
| 36 return (flags & (1 << 17)) | 36 return (flags & (1 << 17)) |
| 37 ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict) | 37 ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict) |
| 38 : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict); | 38 : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict); |
| 39 } | 39 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 return ""; | 134 return ""; |
| 135 } | 135 } |
| 136 CPVT_Provider::CPVT_Provider(IPVT_FontMap* pFontMap) : m_pFontMap(pFontMap) { | 136 CPVT_Provider::CPVT_Provider(IPVT_FontMap* pFontMap) : m_pFontMap(pFontMap) { |
| 137 ASSERT(m_pFontMap); | 137 ASSERT(m_pFontMap); |
| 138 } | 138 } |
| 139 CPVT_Provider::~CPVT_Provider() {} | 139 CPVT_Provider::~CPVT_Provider() {} |
| 140 int32_t CPVT_Provider::GetCharWidth(int32_t nFontIndex, | 140 int32_t CPVT_Provider::GetCharWidth(int32_t nFontIndex, |
| 141 uint16_t word, | 141 uint16_t word, |
| 142 int32_t nWordStyle) { | 142 int32_t nWordStyle) { |
| 143 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { | 143 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { |
| 144 FX_DWORD charcode = pPDFFont->CharCodeFromUnicode(word); | 144 uint32_t charcode = pPDFFont->CharCodeFromUnicode(word); |
| 145 if (charcode != CPDF_Font::kInvalidCharCode) { | 145 if (charcode != CPDF_Font::kInvalidCharCode) { |
| 146 return pPDFFont->GetCharWidthF(charcode); | 146 return pPDFFont->GetCharWidthF(charcode); |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 return 0; | 149 return 0; |
| 150 } | 150 } |
| 151 int32_t CPVT_Provider::GetTypeAscent(int32_t nFontIndex) { | 151 int32_t CPVT_Provider::GetTypeAscent(int32_t nFontIndex) { |
| 152 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { | 152 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { |
| 153 return pPDFFont->GetTypeAscent(); | 153 return pPDFFont->GetTypeAscent(); |
| 154 } | 154 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 197 } |
| 198 | 198 |
| 199 if (!pFontMap) | 199 if (!pFontMap) |
| 200 return sWord; | 200 return sWord; |
| 201 | 201 |
| 202 if (CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex)) { | 202 if (CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex)) { |
| 203 if (pPDFFont->GetBaseFont().Compare("Symbol") == 0 || | 203 if (pPDFFont->GetBaseFont().Compare("Symbol") == 0 || |
| 204 pPDFFont->GetBaseFont().Compare("ZapfDingbats") == 0) { | 204 pPDFFont->GetBaseFont().Compare("ZapfDingbats") == 0) { |
| 205 sWord.Format("%c", Word); | 205 sWord.Format("%c", Word); |
| 206 } else { | 206 } else { |
| 207 FX_DWORD dwCharCode = pPDFFont->CharCodeFromUnicode(Word); | 207 uint32_t dwCharCode = pPDFFont->CharCodeFromUnicode(Word); |
| 208 if (dwCharCode != CPDF_Font::kInvalidCharCode) { | 208 if (dwCharCode != CPDF_Font::kInvalidCharCode) { |
| 209 pPDFFont->AppendChar(sWord, dwCharCode); | 209 pPDFFont->AppendChar(sWord, dwCharCode); |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 return sWord; | 213 return sWord; |
| 214 } | 214 } |
| 215 | 215 |
| 216 static CFX_ByteString GetWordRenderString(const CFX_ByteString& strWords) { | 216 static CFX_ByteString GetWordRenderString(const CFX_ByteString& strWords) { |
| 217 if (strWords.GetLength() > 0) { | 217 if (strWords.GetLength() > 0) { |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 } | 455 } |
| 456 switch (nWidgetType) { | 456 switch (nWidgetType) { |
| 457 case 0: { | 457 case 0: { |
| 458 CFX_WideString swValue = | 458 CFX_WideString swValue = |
| 459 FPDF_GetFieldAttr(pAnnotDict, "V") | 459 FPDF_GetFieldAttr(pAnnotDict, "V") |
| 460 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() | 460 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() |
| 461 : CFX_WideString(); | 461 : CFX_WideString(); |
| 462 int32_t nAlign = FPDF_GetFieldAttr(pAnnotDict, "Q") | 462 int32_t nAlign = FPDF_GetFieldAttr(pAnnotDict, "Q") |
| 463 ? FPDF_GetFieldAttr(pAnnotDict, "Q")->GetInteger() | 463 ? FPDF_GetFieldAttr(pAnnotDict, "Q")->GetInteger() |
| 464 : 0; | 464 : 0; |
| 465 FX_DWORD dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff") | 465 uint32_t dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff") |
| 466 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() | 466 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() |
| 467 : 0; | 467 : 0; |
| 468 FX_DWORD dwMaxLen = | 468 uint32_t dwMaxLen = |
| 469 FPDF_GetFieldAttr(pAnnotDict, "MaxLen") | 469 FPDF_GetFieldAttr(pAnnotDict, "MaxLen") |
| 470 ? FPDF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger() | 470 ? FPDF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger() |
| 471 : 0; | 471 : 0; |
| 472 CPVT_FontMap map(pDoc, | 472 CPVT_FontMap map(pDoc, |
| 473 pStreamDict ? pStreamDict->GetDictBy("Resources") : NULL, | 473 pStreamDict ? pStreamDict->GetDictBy("Resources") : NULL, |
| 474 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); | 474 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
| 475 CPVT_Provider prd(&map); | 475 CPVT_Provider prd(&map); |
| 476 CPDF_VariableText vt; | 476 CPDF_VariableText vt; |
| 477 vt.SetProvider(&prd); | 477 vt.SetProvider(&prd); |
| 478 vt.SetPlateRect(rcBody); | 478 vt.SetPlateRect(rcBody); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 } | 618 } |
| 619 if (CPDF_Object* pOpt = pOpts->GetElementValue(i)) { | 619 if (CPDF_Object* pOpt = pOpts->GetElementValue(i)) { |
| 620 CFX_WideString swItem; | 620 CFX_WideString swItem; |
| 621 if (pOpt->IsString()) | 621 if (pOpt->IsString()) |
| 622 swItem = pOpt->GetUnicodeText(); | 622 swItem = pOpt->GetUnicodeText(); |
| 623 else if (CPDF_Array* pArray = pOpt->AsArray()) | 623 else if (CPDF_Array* pArray = pOpt->AsArray()) |
| 624 swItem = pArray->GetElementValue(1)->GetUnicodeText(); | 624 swItem = pArray->GetElementValue(1)->GetUnicodeText(); |
| 625 | 625 |
| 626 FX_BOOL bSelected = FALSE; | 626 FX_BOOL bSelected = FALSE; |
| 627 if (pSels) { | 627 if (pSels) { |
| 628 for (FX_DWORD s = 0, ssz = pSels->GetCount(); s < ssz; s++) { | 628 for (uint32_t s = 0, ssz = pSels->GetCount(); s < ssz; s++) { |
| 629 if (i == pSels->GetIntegerAt(s)) { | 629 if (i == pSels->GetIntegerAt(s)) { |
| 630 bSelected = TRUE; | 630 bSelected = TRUE; |
| 631 break; | 631 break; |
| 632 } | 632 } |
| 633 } | 633 } |
| 634 } | 634 } |
| 635 CPDF_VariableText vt; | 635 CPDF_VariableText vt; |
| 636 vt.SetProvider(&prd); | 636 vt.SetProvider(&prd); |
| 637 vt.SetPlateRect( | 637 vt.SetPlateRect( |
| 638 CFX_FloatRect(rcBody.left, 0.0f, rcBody.right, 0.0f)); | 638 CFX_FloatRect(rcBody.left, 0.0f, rcBody.right, 0.0f)); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 case CPVT_Color::kCMYK: | 929 case CPVT_Color::kCMYK: |
| 930 sColorStream << color.fColor1 << " " << color.fColor2 << " " | 930 sColorStream << color.fColor1 << " " << color.fColor2 << " " |
| 931 << color.fColor3 << " " << color.fColor4 << " " | 931 << color.fColor3 << " " << color.fColor4 << " " |
| 932 << (bFillOrStroke ? "k" : "K") << "\n"; | 932 << (bFillOrStroke ? "k" : "K") << "\n"; |
| 933 break; | 933 break; |
| 934 case CPVT_Color::kTransparent: | 934 case CPVT_Color::kTransparent: |
| 935 break; | 935 break; |
| 936 } | 936 } |
| 937 return sColorStream.GetByteString(); | 937 return sColorStream.GetByteString(); |
| 938 } | 938 } |
| OLD | NEW |