| 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 "../../include/fpdfdoc/fpdf_doc.h" | 7 #include "../../include/fpdfdoc/fpdf_doc.h" |
| 8 #include "../../include/fpdfdoc/fpdf_vt.h" | 8 #include "../../include/fpdfdoc/fpdf_vt.h" |
| 9 #include "pdf_vt.h" | 9 #include "pdf_vt.h" |
| 10 #include "../../include/fpdfdoc/fpdf_ap.h" | 10 #include "../../include/fpdfdoc/fpdf_ap.h" |
| 11 FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) | 11 FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { |
| 12 { | 12 if (!pAnnotDict || |
| 13 if (!pAnnotDict || pAnnotDict->GetConstString("Subtype") != FX_BSTRC("Widget
")) { | 13 pAnnotDict->GetConstString("Subtype") != FX_BSTRC("Widget")) { |
| 14 return FALSE; | 14 return FALSE; |
| 15 } | 15 } |
| 16 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString()
; | 16 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); |
| 17 FX_DWORD flags = FPDF_GetFieldAttr(pAnnotDict, "Ff")? FPDF_GetFieldAttr(pAnn
otDict, "Ff")->GetInteger() : 0; | 17 FX_DWORD flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") |
| 18 if (field_type == "Tx") { | 18 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() |
| 19 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict); | 19 : 0; |
| 20 } | 20 if (field_type == "Tx") { |
| 21 if (field_type == "Ch") { | 21 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict); |
| 22 return (flags & (1 << 17)) ? | 22 } |
| 23 CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict) : | 23 if (field_type == "Ch") { |
| 24 CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict); | 24 return (flags & (1 << 17)) |
| 25 } | 25 ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict) |
| 26 if (field_type == "Btn") { | 26 : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict); |
| 27 if (!(flags & (1 << 16))) { | 27 } |
| 28 if (!pAnnotDict->KeyExist("AS")) { | 28 if (field_type == "Btn") { |
| 29 if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDict("Parent")
) { | 29 if (!(flags & (1 << 16))) { |
| 30 if (pParentDict->KeyExist("AS")) { | 30 if (!pAnnotDict->KeyExist("AS")) { |
| 31 pAnnotDict->SetAtString("AS", pParentDict->GetString("AS
")); | 31 if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDict("Parent")) { |
| 32 } | 32 if (pParentDict->KeyExist("AS")) { |
| 33 pAnnotDict->SetAtString("AS", pParentDict->GetString("AS")); |
| 34 } |
| 35 } |
| 36 } |
| 37 } |
| 38 } |
| 39 return FALSE; |
| 40 } |
| 41 class CPVT_FontMap : public IPVT_FontMap { |
| 42 public: |
| 43 CPVT_FontMap(CPDF_Document* pDoc, |
| 44 CPDF_Dictionary* pResDict, |
| 45 CPDF_Font* pDefFont, |
| 46 const CFX_ByteString& sDefFontAlias); |
| 47 virtual ~CPVT_FontMap(); |
| 48 CPDF_Font* GetPDFFont(int32_t nFontIndex); |
| 49 CFX_ByteString GetPDFFontAlias(int32_t nFontIndex); |
| 50 static void GetAnnotSysPDFFont(CPDF_Document* pDoc, |
| 51 CPDF_Dictionary* pResDict, |
| 52 CPDF_Font*& pSysFont, |
| 53 CFX_ByteString& sSysFontAlias); |
| 54 |
| 55 private: |
| 56 CPDF_Document* m_pDocument; |
| 57 CPDF_Dictionary* m_pResDict; |
| 58 CPDF_Font* m_pDefFont; |
| 59 CFX_ByteString m_sDefFontAlias; |
| 60 CPDF_Font* m_pSysFont; |
| 61 CFX_ByteString m_sSysFontAlias; |
| 62 }; |
| 63 CPVT_FontMap::CPVT_FontMap(CPDF_Document* pDoc, |
| 64 CPDF_Dictionary* pResDict, |
| 65 CPDF_Font* pDefFont, |
| 66 const CFX_ByteString& sDefFontAlias) |
| 67 : m_pDocument(pDoc), |
| 68 m_pResDict(pResDict), |
| 69 m_pDefFont(pDefFont), |
| 70 m_sDefFontAlias(sDefFontAlias), |
| 71 m_pSysFont(NULL), |
| 72 m_sSysFontAlias() {} |
| 73 CPVT_FontMap::~CPVT_FontMap() {} |
| 74 extern CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, |
| 75 CPDF_Document* pDocument, |
| 76 CFX_ByteString& csNameTag); |
| 77 void CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc, |
| 78 CPDF_Dictionary* pResDict, |
| 79 CPDF_Font*& pSysFont, |
| 80 CFX_ByteString& sSysFontAlias) { |
| 81 if (pDoc && pResDict) { |
| 82 CFX_ByteString sFontAlias; |
| 83 CPDF_Dictionary* pFormDict = pDoc->GetRoot()->GetDict("AcroForm"); |
| 84 if (CPDF_Font* pPDFFont = |
| 85 AddNativeInterFormFont(pFormDict, pDoc, sSysFontAlias)) { |
| 86 if (CPDF_Dictionary* pFontList = pResDict->GetDict("Font")) { |
| 87 if (!pFontList->KeyExist(sSysFontAlias)) { |
| 88 pFontList->SetAtReference(sSysFontAlias, pDoc, |
| 89 pPDFFont->GetFontDict()); |
| 90 } |
| 91 } |
| 92 pSysFont = pPDFFont; |
| 93 } |
| 94 } |
| 95 } |
| 96 CPDF_Font* CPVT_FontMap::GetPDFFont(int32_t nFontIndex) { |
| 97 switch (nFontIndex) { |
| 98 case 0: |
| 99 return m_pDefFont; |
| 100 case 1: |
| 101 if (!m_pSysFont) { |
| 102 GetAnnotSysPDFFont(m_pDocument, m_pResDict, m_pSysFont, |
| 103 m_sSysFontAlias); |
| 104 } |
| 105 return m_pSysFont; |
| 106 } |
| 107 return NULL; |
| 108 } |
| 109 CFX_ByteString CPVT_FontMap::GetPDFFontAlias(int32_t nFontIndex) { |
| 110 switch (nFontIndex) { |
| 111 case 0: |
| 112 return m_sDefFontAlias; |
| 113 case 1: |
| 114 if (!m_pSysFont) { |
| 115 GetAnnotSysPDFFont(m_pDocument, m_pResDict, m_pSysFont, |
| 116 m_sSysFontAlias); |
| 117 } |
| 118 return m_sSysFontAlias; |
| 119 } |
| 120 return ""; |
| 121 } |
| 122 CPVT_Provider::CPVT_Provider(IPVT_FontMap* pFontMap) : m_pFontMap(pFontMap) { |
| 123 ASSERT(m_pFontMap != NULL); |
| 124 } |
| 125 CPVT_Provider::~CPVT_Provider() {} |
| 126 int32_t CPVT_Provider::GetCharWidth(int32_t nFontIndex, |
| 127 FX_WORD word, |
| 128 int32_t nWordStyle) { |
| 129 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { |
| 130 FX_DWORD charcode = pPDFFont->CharCodeFromUnicode(word); |
| 131 if (charcode != -1) { |
| 132 return pPDFFont->GetCharWidthF(charcode); |
| 133 } |
| 134 } |
| 135 return 0; |
| 136 } |
| 137 int32_t CPVT_Provider::GetTypeAscent(int32_t nFontIndex) { |
| 138 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { |
| 139 return pPDFFont->GetTypeAscent(); |
| 140 } |
| 141 return 0; |
| 142 } |
| 143 int32_t CPVT_Provider::GetTypeDescent(int32_t nFontIndex) { |
| 144 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { |
| 145 return pPDFFont->GetTypeDescent(); |
| 146 } |
| 147 return 0; |
| 148 } |
| 149 int32_t CPVT_Provider::GetWordFontIndex(FX_WORD word, |
| 150 int32_t charset, |
| 151 int32_t nFontIndex) { |
| 152 if (CPDF_Font* pDefFont = m_pFontMap->GetPDFFont(0)) { |
| 153 if (pDefFont->CharCodeFromUnicode(word) != -1) { |
| 154 return 0; |
| 155 } |
| 156 } |
| 157 if (CPDF_Font* pSysFont = m_pFontMap->GetPDFFont(1)) |
| 158 if (pSysFont->CharCodeFromUnicode(word) != -1) { |
| 159 return 1; |
| 160 } |
| 161 return -1; |
| 162 } |
| 163 FX_BOOL CPVT_Provider::IsLatinWord(FX_WORD word) { |
| 164 if ((word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) || |
| 165 word == 0x2D || word == 0x27) { |
| 166 return TRUE; |
| 167 } |
| 168 return FALSE; |
| 169 } |
| 170 int32_t CPVT_Provider::GetDefaultFontIndex() { |
| 171 return 0; |
| 172 } |
| 173 static CFX_ByteString GetPDFWordString(IPVT_FontMap* pFontMap, |
| 174 int32_t nFontIndex, |
| 175 FX_WORD Word, |
| 176 FX_WORD SubWord) { |
| 177 CFX_ByteString sWord; |
| 178 if (SubWord > 0) { |
| 179 sWord.Format("%c", SubWord); |
| 180 } else { |
| 181 if (pFontMap) { |
| 182 if (CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex)) { |
| 183 if (pPDFFont->GetBaseFont().Compare("Symbol") == 0 || |
| 184 pPDFFont->GetBaseFont().Compare("ZapfDingbats") == 0) { |
| 185 sWord.Format("%c", Word); |
| 186 } else { |
| 187 FX_DWORD dwCharCode = pPDFFont->CharCodeFromUnicode(Word); |
| 188 if (dwCharCode != -1) { |
| 189 pPDFFont->AppendChar(sWord, dwCharCode); |
| 190 } |
| 191 } |
| 192 } |
| 193 } |
| 194 } |
| 195 return sWord; |
| 196 } |
| 197 static CFX_ByteString GetWordRenderString(const CFX_ByteString& strWords) { |
| 198 if (strWords.GetLength() > 0) { |
| 199 return PDF_EncodeString(strWords) + " Tj\n"; |
| 200 } |
| 201 return ""; |
| 202 } |
| 203 static CFX_ByteString GetFontSetString(IPVT_FontMap* pFontMap, |
| 204 int32_t nFontIndex, |
| 205 FX_FLOAT fFontSize) { |
| 206 CFX_ByteTextBuf sRet; |
| 207 if (pFontMap) { |
| 208 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
| 209 if (sFontAlias.GetLength() > 0 && fFontSize > 0) { |
| 210 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
| 211 } |
| 212 } |
| 213 return sRet.GetByteString(); |
| 214 } |
| 215 static CPVT_Color ParseColor(const CFX_ByteString& str) { |
| 216 CPDF_SimpleParser syntax(str); |
| 217 syntax.SetPos(0); |
| 218 if (syntax.FindTagParam("g", 1)) { |
| 219 return CPVT_Color(CT_GRAY, FX_atof(syntax.GetWord())); |
| 220 } |
| 221 syntax.SetPos(0); |
| 222 if (syntax.FindTagParam("rg", 3)) { |
| 223 FX_FLOAT f1 = FX_atof(syntax.GetWord()); |
| 224 FX_FLOAT f2 = FX_atof(syntax.GetWord()); |
| 225 FX_FLOAT f3 = FX_atof(syntax.GetWord()); |
| 226 return CPVT_Color(CT_RGB, f1, f2, f3); |
| 227 } |
| 228 syntax.SetPos(0); |
| 229 if (syntax.FindTagParam("k", 4)) { |
| 230 FX_FLOAT f1 = FX_atof(syntax.GetWord()); |
| 231 FX_FLOAT f2 = FX_atof(syntax.GetWord()); |
| 232 FX_FLOAT f3 = FX_atof(syntax.GetWord()); |
| 233 FX_FLOAT f4 = FX_atof(syntax.GetWord()); |
| 234 return CPVT_Color(CT_CMYK, f1, f2, f3, f4); |
| 235 } |
| 236 return CPVT_Color(CT_TRANSPARENT); |
| 237 } |
| 238 static CPVT_Color ParseColor(const CPDF_Array& array) { |
| 239 CPVT_Color rt; |
| 240 switch (array.GetCount()) { |
| 241 case 1: |
| 242 rt = CPVT_Color(CT_GRAY, array.GetFloat(0)); |
| 243 break; |
| 244 case 3: |
| 245 rt = CPVT_Color(CT_RGB, array.GetFloat(0), array.GetFloat(1), |
| 246 array.GetFloat(2)); |
| 247 break; |
| 248 case 4: |
| 249 rt = CPVT_Color(CT_CMYK, array.GetFloat(0), array.GetFloat(1), |
| 250 array.GetFloat(2), array.GetFloat(3)); |
| 251 break; |
| 252 } |
| 253 return rt; |
| 254 } |
| 255 static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
| 256 CPDF_Dictionary* pAnnotDict, |
| 257 const int32_t& nWidgetType) { |
| 258 CPDF_Dictionary* pFormDict = NULL; |
| 259 if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) { |
| 260 pFormDict = pRootDict->GetDict("AcroForm"); |
| 261 } |
| 262 if (!pFormDict) { |
| 263 return FALSE; |
| 264 } |
| 265 CFX_ByteString DA; |
| 266 if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA")) { |
| 267 DA = pDAObj->GetString(); |
| 268 } |
| 269 if (DA.IsEmpty()) { |
| 270 DA = pFormDict->GetString("DA"); |
| 271 } |
| 272 if (DA.IsEmpty()) { |
| 273 return FALSE; |
| 274 } |
| 275 CPDF_SimpleParser syntax(DA); |
| 276 syntax.FindTagParam("Tf", 2); |
| 277 CFX_ByteString sFontName = syntax.GetWord(); |
| 278 sFontName = PDF_NameDecode(sFontName); |
| 279 if (sFontName.IsEmpty()) { |
| 280 return FALSE; |
| 281 } |
| 282 FX_FLOAT fFontSize = FX_atof(syntax.GetWord()); |
| 283 CPVT_Color crText = ParseColor(DA); |
| 284 FX_BOOL bUseFormRes = FALSE; |
| 285 CPDF_Dictionary* pFontDict = NULL; |
| 286 CPDF_Dictionary* pDRDict = pAnnotDict->GetDict(FX_BSTRC("DR")); |
| 287 if (pDRDict == NULL) { |
| 288 pDRDict = pFormDict->GetDict(FX_BSTRC("DR")); |
| 289 bUseFormRes = TRUE; |
| 290 } |
| 291 CPDF_Dictionary* pDRFontDict = NULL; |
| 292 if (pDRDict && (pDRFontDict = pDRDict->GetDict("Font"))) { |
| 293 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1)); |
| 294 if (!pFontDict && !bUseFormRes) { |
| 295 pDRDict = pFormDict->GetDict(FX_BSTRC("DR")); |
| 296 pDRFontDict = pDRDict->GetDict("Font"); |
| 297 if (pDRFontDict) { |
| 298 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1)); |
| 299 } |
| 300 } |
| 301 } |
| 302 if (!pDRFontDict) { |
| 303 return FALSE; |
| 304 } |
| 305 if (!pFontDict) { |
| 306 pFontDict = CPDF_Dictionary::Create(); |
| 307 if (pFontDict == NULL) { |
| 308 return FALSE; |
| 309 } |
| 310 pFontDict->SetAtName(FX_BSTRC("Type"), "Font"); |
| 311 pFontDict->SetAtName(FX_BSTRC("Subtype"), "Type1"); |
| 312 pFontDict->SetAtName(FX_BSTRC("BaseFont"), "Helvetica"); |
| 313 pFontDict->SetAtName(FX_BSTRC("Encoding"), "WinAnsiEncoding"); |
| 314 pDoc->AddIndirectObject(pFontDict); |
| 315 pDRFontDict->SetAtReference(sFontName.Mid(1), pDoc, pFontDict); |
| 316 } |
| 317 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); |
| 318 if (!pDefFont) { |
| 319 return FALSE; |
| 320 } |
| 321 CPDF_Rect rcAnnot = pAnnotDict->GetRect("Rect"); |
| 322 int32_t nRotate = 0; |
| 323 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDict("MK")) { |
| 324 nRotate = pMKDict->GetInteger("R"); |
| 325 } |
| 326 CPDF_Rect rcBBox; |
| 327 CPDF_Matrix matrix; |
| 328 switch (nRotate % 360) { |
| 329 case 0: |
| 330 rcBBox = CPDF_Rect(0, 0, rcAnnot.right - rcAnnot.left, |
| 331 rcAnnot.top - rcAnnot.bottom); |
| 332 break; |
| 333 case 90: |
| 334 matrix = CPDF_Matrix(0, 1, -1, 0, rcAnnot.right - rcAnnot.left, 0); |
| 335 rcBBox = CPDF_Rect(0, 0, rcAnnot.top - rcAnnot.bottom, |
| 336 rcAnnot.right - rcAnnot.left); |
| 337 break; |
| 338 case 180: |
| 339 matrix = CPDF_Matrix(-1, 0, 0, -1, rcAnnot.right - rcAnnot.left, |
| 340 rcAnnot.top - rcAnnot.bottom); |
| 341 rcBBox = CPDF_Rect(0, 0, rcAnnot.right - rcAnnot.left, |
| 342 rcAnnot.top - rcAnnot.bottom); |
| 343 break; |
| 344 case 270: |
| 345 matrix = CPDF_Matrix(0, -1, 1, 0, 0, rcAnnot.top - rcAnnot.bottom); |
| 346 rcBBox = CPDF_Rect(0, 0, rcAnnot.top - rcAnnot.bottom, |
| 347 rcAnnot.right - rcAnnot.left); |
| 348 break; |
| 349 } |
| 350 int32_t nBorderStyle = PBS_SOLID; |
| 351 FX_FLOAT fBorderWidth = 1; |
| 352 CPVT_Dash dsBorder(3, 0, 0); |
| 353 CPVT_Color crLeftTop, crRightBottom; |
| 354 if (CPDF_Dictionary* pBSDict = pAnnotDict->GetDict("BS")) { |
| 355 if (pBSDict->KeyExist("W")) { |
| 356 fBorderWidth = pBSDict->GetNumber("W"); |
| 357 } |
| 358 if (CPDF_Array* pArray = pBSDict->GetArray("D")) { |
| 359 dsBorder = CPVT_Dash(pArray->GetInteger(0), pArray->GetInteger(1), |
| 360 pArray->GetInteger(2)); |
| 361 } |
| 362 switch (pBSDict->GetString("S").GetAt(0)) { |
| 363 case 'S': |
| 364 nBorderStyle = PBS_SOLID; |
| 365 break; |
| 366 case 'D': |
| 367 nBorderStyle = PBS_DASH; |
| 368 break; |
| 369 case 'B': |
| 370 nBorderStyle = PBS_BEVELED; |
| 371 fBorderWidth *= 2; |
| 372 crLeftTop = CPVT_Color(CT_GRAY, 1); |
| 373 crRightBottom = CPVT_Color(CT_GRAY, 0.5); |
| 374 break; |
| 375 case 'I': |
| 376 nBorderStyle = PBS_INSET; |
| 377 fBorderWidth *= 2; |
| 378 crLeftTop = CPVT_Color(CT_GRAY, 0.5); |
| 379 crRightBottom = CPVT_Color(CT_GRAY, 0.75); |
| 380 break; |
| 381 case 'U': |
| 382 nBorderStyle = PBS_UNDERLINED; |
| 383 break; |
| 384 } |
| 385 } |
| 386 CPVT_Color crBorder, crBG; |
| 387 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDict("MK")) { |
| 388 if (CPDF_Array* pArray = pMKDict->GetArray("BC")) { |
| 389 crBorder = ParseColor(*pArray); |
| 390 } |
| 391 if (CPDF_Array* pArray = pMKDict->GetArray("BG")) { |
| 392 crBG = ParseColor(*pArray); |
| 393 } |
| 394 } |
| 395 CFX_ByteTextBuf sAppStream; |
| 396 CFX_ByteString sBG = CPVT_GenerateAP::GenerateColorAP(crBG, TRUE); |
| 397 if (sBG.GetLength() > 0) { |
| 398 sAppStream << "q\n" << sBG << rcBBox.left << " " << rcBBox.bottom << " " |
| 399 << rcBBox.Width() << " " << rcBBox.Height() << " re f\n" |
| 400 << "Q\n"; |
| 401 } |
| 402 CFX_ByteString sBorderStream = CPVT_GenerateAP::GenerateBorderAP( |
| 403 rcBBox, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, |
| 404 dsBorder); |
| 405 if (sBorderStream.GetLength() > 0) { |
| 406 sAppStream << "q\n" << sBorderStream << "Q\n"; |
| 407 } |
| 408 CPDF_Rect rcBody = |
| 409 CPDF_Rect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth, |
| 410 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth); |
| 411 rcBody.Normalize(); |
| 412 CPDF_Dictionary* pAPDict = pAnnotDict->GetDict("AP"); |
| 413 if (pAPDict == NULL) { |
| 414 pAPDict = CPDF_Dictionary::Create(); |
| 415 if (pAPDict == NULL) { |
| 416 return FALSE; |
| 417 } |
| 418 pAnnotDict->SetAt("AP", pAPDict); |
| 419 } |
| 420 CPDF_Stream* pNormalStream = pAPDict->GetStream("N"); |
| 421 if (pNormalStream == NULL) { |
| 422 pNormalStream = CPDF_Stream::Create(NULL, 0, NULL); |
| 423 if (pNormalStream == NULL) { |
| 424 return FALSE; |
| 425 } |
| 426 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); |
| 427 pAnnotDict->GetDict("AP")->SetAtReference("N", pDoc, objnum); |
| 428 } |
| 429 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); |
| 430 if (pStreamDict) { |
| 431 pStreamDict->SetAtMatrix("Matrix", matrix); |
| 432 pStreamDict->SetAtRect("BBox", rcBBox); |
| 433 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); |
| 434 if (pStreamResList) { |
| 435 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font"); |
| 436 if (!pStreamResFontList) { |
| 437 pStreamResFontList = CPDF_Dictionary::Create(); |
| 438 if (pStreamResFontList == NULL) { |
| 439 return FALSE; |
| 440 } |
| 441 pStreamResList->SetAt("Font", pStreamResFontList); |
| 442 } |
| 443 if (!pStreamResFontList->KeyExist(sFontName)) { |
| 444 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); |
| 445 } |
| 446 } else { |
| 447 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone()); |
| 448 pStreamResList = pStreamDict->GetDict("Resources"); |
| 449 } |
| 450 } |
| 451 switch (nWidgetType) { |
| 452 case 0: { |
| 453 CFX_WideString swValue = |
| 454 FPDF_GetFieldAttr(pAnnotDict, "V") |
| 455 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() |
| 456 : CFX_WideString(); |
| 457 int32_t nAlign = FPDF_GetFieldAttr(pAnnotDict, "Q") |
| 458 ? FPDF_GetFieldAttr(pAnnotDict, "Q")->GetInteger() |
| 459 : 0; |
| 460 FX_DWORD dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff") |
| 461 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() |
| 462 : 0; |
| 463 FX_DWORD dwMaxLen = |
| 464 FPDF_GetFieldAttr(pAnnotDict, "MaxLen") |
| 465 ? FPDF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger() |
| 466 : 0; |
| 467 CPVT_FontMap map(pDoc, |
| 468 pStreamDict ? pStreamDict->GetDict("Resources") : NULL, |
| 469 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
| 470 CPVT_Provider prd(&map); |
| 471 CPDF_VariableText vt; |
| 472 vt.SetProvider(&prd); |
| 473 vt.SetPlateRect(rcBody); |
| 474 vt.SetAlignment(nAlign); |
| 475 if (IsFloatZero(fFontSize)) { |
| 476 vt.SetAutoFontSize(TRUE); |
| 477 } else { |
| 478 vt.SetFontSize(fFontSize); |
| 479 } |
| 480 FX_BOOL bMultiLine = (dwFlags >> 12) & 1; |
| 481 if (bMultiLine) { |
| 482 vt.SetMultiLine(TRUE); |
| 483 vt.SetAutoReturn(TRUE); |
| 484 } |
| 485 FX_WORD subWord = 0; |
| 486 if ((dwFlags >> 13) & 1) { |
| 487 subWord = '*'; |
| 488 vt.SetPasswordChar(subWord); |
| 489 } |
| 490 FX_BOOL bCharArray = (dwFlags >> 24) & 1; |
| 491 if (bCharArray) { |
| 492 vt.SetCharArray(dwMaxLen); |
| 493 } else { |
| 494 vt.SetLimitChar(dwMaxLen); |
| 495 } |
| 496 vt.Initialize(); |
| 497 vt.SetText(swValue.c_str()); |
| 498 vt.RearrangeAll(); |
| 499 CPDF_Rect rcContent = vt.GetContentRect(); |
| 500 CPDF_Point ptOffset(0.0f, 0.0f); |
| 501 if (!bMultiLine) { |
| 502 ptOffset = |
| 503 CPDF_Point(0.0f, (rcContent.Height() - rcBody.Height()) / 2.0f); |
| 504 } |
| 505 CFX_ByteString sBody = CPVT_GenerateAP::GenerateEditAP( |
| 506 &map, vt.GetIterator(), ptOffset, !bCharArray, subWord); |
| 507 if (sBody.GetLength() > 0) { |
| 508 sAppStream << "/Tx BMC\n" |
| 509 << "q\n"; |
| 510 if (rcContent.Width() > rcBody.Width() || |
| 511 rcContent.Height() > rcBody.Height()) { |
| 512 sAppStream << rcBody.left << " " << rcBody.bottom << " " |
| 513 << rcBody.Width() << " " << rcBody.Height() |
| 514 << " re\nW\nn\n"; |
| 515 } |
| 516 sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE) |
| 517 << sBody << "ET\n" |
| 518 << "Q\nEMC\n"; |
| 519 } |
| 520 } break; |
| 521 case 1: { |
| 522 CFX_WideString swValue = |
| 523 FPDF_GetFieldAttr(pAnnotDict, "V") |
| 524 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() |
| 525 : CFX_WideString(); |
| 526 CPVT_FontMap map(pDoc, |
| 527 pStreamDict ? pStreamDict->GetDict("Resources") : NULL, |
| 528 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
| 529 CPVT_Provider prd(&map); |
| 530 CPDF_VariableText vt; |
| 531 vt.SetProvider(&prd); |
| 532 CPDF_Rect rcButton = rcBody; |
| 533 rcButton.left = rcButton.right - 13; |
| 534 rcButton.Normalize(); |
| 535 CPDF_Rect rcEdit = rcBody; |
| 536 rcEdit.right = rcButton.left; |
| 537 rcEdit.Normalize(); |
| 538 vt.SetPlateRect(rcEdit); |
| 539 if (IsFloatZero(fFontSize)) { |
| 540 vt.SetAutoFontSize(TRUE); |
| 541 } else { |
| 542 vt.SetFontSize(fFontSize); |
| 543 } |
| 544 vt.Initialize(); |
| 545 vt.SetText(swValue.c_str()); |
| 546 vt.RearrangeAll(); |
| 547 CPDF_Rect rcContent = vt.GetContentRect(); |
| 548 CPDF_Point ptOffset = |
| 549 CPDF_Point(0.0f, (rcContent.Height() - rcEdit.Height()) / 2.0f); |
| 550 CFX_ByteString sEdit = CPVT_GenerateAP::GenerateEditAP( |
| 551 &map, vt.GetIterator(), ptOffset, TRUE, 0); |
| 552 if (sEdit.GetLength() > 0) { |
| 553 sAppStream << "/Tx BMC\n" |
| 554 << "q\n"; |
| 555 sAppStream << rcEdit.left << " " << rcEdit.bottom << " " |
| 556 << rcEdit.Width() << " " << rcEdit.Height() << " re\nW\nn\n"; |
| 557 sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE) |
| 558 << sEdit << "ET\n" |
| 559 << "Q\nEMC\n"; |
| 560 } |
| 561 CFX_ByteString sButton = CPVT_GenerateAP::GenerateColorAP( |
| 562 CPVT_Color(CT_RGB, 220.0f / 255.0f, 220.0f / 255.0f, 220.0f / 255.0f), |
| 563 TRUE); |
| 564 if (sButton.GetLength() > 0 && !rcButton.IsEmpty()) { |
| 565 sAppStream << "q\n" << sButton; |
| 566 sAppStream << rcButton.left << " " << rcButton.bottom << " " |
| 567 << rcButton.Width() << " " << rcButton.Height() << " re f\n"; |
| 568 sAppStream << "Q\n"; |
| 569 CFX_ByteString sButtonBorder = CPVT_GenerateAP::GenerateBorderAP( |
| 570 rcButton, 2, CPVT_Color(CT_GRAY, 0), CPVT_Color(CT_GRAY, 1), |
| 571 CPVT_Color(CT_GRAY, 0.5), PBS_BEVELED, CPVT_Dash(3, 0, 0)); |
| 572 if (sButtonBorder.GetLength() > 0) { |
| 573 sAppStream << "q\n" << sButtonBorder << "Q\n"; |
| 574 } |
| 575 CPDF_Point ptCenter = CPDF_Point((rcButton.left + rcButton.right) / 2, |
| 576 (rcButton.top + rcButton.bottom) / 2); |
| 577 if (IsFloatBigger(rcButton.Width(), 6) && |
| 578 IsFloatBigger(rcButton.Height(), 6)) { |
| 579 sAppStream << "q\n" |
| 580 << " 0 g\n"; |
| 581 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n"; |
| 582 sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n"; |
| 583 sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n"; |
| 584 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n"; |
| 585 sAppStream << sButton << "Q\n"; |
| 586 } |
| 587 } |
| 588 } break; |
| 589 case 2: { |
| 590 CPVT_FontMap map(pDoc, |
| 591 pStreamDict ? pStreamDict->GetDict("Resources") : NULL, |
| 592 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
| 593 CPVT_Provider prd(&map); |
| 594 CPDF_Array* pOpts = FPDF_GetFieldAttr(pAnnotDict, "Opt") |
| 595 ? FPDF_GetFieldAttr(pAnnotDict, "Opt")->GetArray() |
| 596 : NULL; |
| 597 CPDF_Array* pSels = FPDF_GetFieldAttr(pAnnotDict, "I") |
| 598 ? FPDF_GetFieldAttr(pAnnotDict, "I")->GetArray() |
| 599 : NULL; |
| 600 int32_t nTop = FPDF_GetFieldAttr(pAnnotDict, "TI") |
| 601 ? FPDF_GetFieldAttr(pAnnotDict, "TI")->GetInteger() |
| 602 : 0; |
| 603 CFX_ByteTextBuf sBody; |
| 604 if (pOpts) { |
| 605 FX_FLOAT fy = rcBody.top; |
| 606 for (int32_t i = nTop, sz = pOpts->GetCount(); i < sz; i++) { |
| 607 if (IsFloatSmaller(fy, rcBody.bottom)) { |
| 608 break; |
| 609 } |
| 610 if (CPDF_Object* pOpt = pOpts->GetElementValue(i)) { |
| 611 CFX_WideString swItem; |
| 612 if (pOpt->GetType() == PDFOBJ_STRING) { |
| 613 swItem = pOpt->GetUnicodeText(); |
| 614 } else if (pOpt->GetType() == PDFOBJ_ARRAY) { |
| 615 swItem = |
| 616 ((CPDF_Array*)pOpt)->GetElementValue(1)->GetUnicodeText(); |
| 617 } |
| 618 FX_BOOL bSelected = FALSE; |
| 619 if (pSels) { |
| 620 for (FX_DWORD s = 0, ssz = pSels->GetCount(); s < ssz; s++) { |
| 621 if (i == pSels->GetInteger(s)) { |
| 622 bSelected = TRUE; |
| 623 break; |
| 33 } | 624 } |
| 625 } |
| 34 } | 626 } |
| 35 } | 627 CPDF_VariableText vt; |
| 36 } | 628 vt.SetProvider(&prd); |
| 37 return FALSE; | 629 vt.SetPlateRect(CPDF_Rect(rcBody.left, 0.0f, rcBody.right, 0.0f)); |
| 38 } | 630 if (IsFloatZero(fFontSize)) { |
| 39 class CPVT_FontMap : public IPVT_FontMap | 631 vt.SetFontSize(12.0f); |
| 40 { | 632 } else { |
| 41 public: | 633 vt.SetFontSize(fFontSize); |
| 42 CPVT_FontMap(CPDF_Document * pDoc, CPDF_Dictionary * pResDict, CPDF_Font * p
DefFont, | |
| 43 const CFX_ByteString & sDefFontAlias); | |
| 44 virtual ~CPVT_FontMap(); | |
| 45 CPDF_Font*» » » » » » GetPDFFont(int32_t nFont
Index); | |
| 46 CFX_ByteString» » » » » GetPDFFontAlias(int32_t
nFontIndex); | |
| 47 static void»» » » » » GetAnnotSysPDFFont(CPDF_
Document * pDoc, CPDF_Dictionary * pResDict, | |
| 48 CPDF_Font * & pSysFont, CFX_ByteString & sSysFontAlias); | |
| 49 private: | |
| 50 CPDF_Document*» » » » » m_pDocument; | |
| 51 CPDF_Dictionary*» » » » m_pResDict; | |
| 52 CPDF_Font*» » » » » » m_pDefFont; | |
| 53 CFX_ByteString» » » » » m_sDefFontAlias; | |
| 54 CPDF_Font*» » » » » » m_pSysFont; | |
| 55 CFX_ByteString» » » » » m_sSysFontAlias; | |
| 56 }; | |
| 57 CPVT_FontMap::CPVT_FontMap(CPDF_Document * pDoc, CPDF_Dictionary * pResDict, CPD
F_Font * pDefFont, | |
| 58 const CFX_ByteString & sDefFontAlias) : | |
| 59 m_pDocument(pDoc), | |
| 60 m_pResDict(pResDict), | |
| 61 m_pDefFont(pDefFont), | |
| 62 m_sDefFontAlias(sDefFontAlias), | |
| 63 m_pSysFont(NULL), | |
| 64 m_sSysFontAlias() | |
| 65 { | |
| 66 } | |
| 67 CPVT_FontMap::~CPVT_FontMap() | |
| 68 { | |
| 69 } | |
| 70 extern CPDF_Font*» » AddNativeInterFormFont(CPDF_Dictionary*& pFormDi
ct, CPDF_Document* pDocument, CFX_ByteString& csNameTag); | |
| 71 void CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document * pDoc, CPDF_Dictionary * pR
esDict, | |
| 72 CPDF_Font * & pSysFont, CFX_ByteString & s
SysFontAlias) | |
| 73 { | |
| 74 if (pDoc && pResDict) { | |
| 75 CFX_ByteString sFontAlias; | |
| 76 CPDF_Dictionary* pFormDict = pDoc->GetRoot()->GetDict("AcroForm"); | |
| 77 if (CPDF_Font * pPDFFont = AddNativeInterFormFont(pFormDict, pDoc, sSysF
ontAlias)) { | |
| 78 if (CPDF_Dictionary * pFontList = pResDict->GetDict("Font")) { | |
| 79 if (!pFontList->KeyExist(sSysFontAlias)) { | |
| 80 pFontList->SetAtReference(sSysFontAlias, pDoc, pPDFFont->Get
FontDict()); | |
| 81 } | |
| 82 } | 634 } |
| 83 pSysFont = pPDFFont; | 635 vt.Initialize(); |
| 84 } | 636 vt.SetText(swItem.c_str()); |
| 85 } | 637 vt.RearrangeAll(); |
| 86 } | 638 FX_FLOAT fItemHeight = vt.GetContentRect().Height(); |
| 87 CPDF_Font* CPVT_FontMap::GetPDFFont(int32_t nFontIndex) | 639 if (bSelected) { |
| 88 { | 640 CPDF_Rect rcItem = |
| 89 switch (nFontIndex) { | 641 CPDF_Rect(rcBody.left, fy - fItemHeight, rcBody.right, fy); |
| 90 case 0: | 642 sBody << "q\n" << CPVT_GenerateAP::GenerateColorAP( |
| 91 return m_pDefFont; | 643 CPVT_Color(CT_RGB, 0, 51.0f / 255.0f, |
| 92 case 1: | 644 113.0f / 255.0f), |
| 93 if (!m_pSysFont) { | 645 TRUE) |
| 94 GetAnnotSysPDFFont(m_pDocument, m_pResDict, m_pSysFont, m_sSysFo
ntAlias); | 646 << rcItem.left << " " << rcItem.bottom << " " |
| 647 << rcItem.Width() << " " << rcItem.Height() << " re f\n" |
| 648 << "Q\n"; |
| 649 sBody << "BT\n" << CPVT_GenerateAP::GenerateColorAP( |
| 650 CPVT_Color(CT_GRAY, 1), TRUE) |
| 651 << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), |
| 652 CPDF_Point(0.0f, fy), |
| 653 TRUE, 0) |
| 654 << "ET\n"; |
| 655 } else { |
| 656 sBody << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE) |
| 657 << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), |
| 658 CPDF_Point(0.0f, fy), |
| 659 TRUE, 0) |
| 660 << "ET\n"; |
| 95 } | 661 } |
| 96 return m_pSysFont; | 662 fy -= fItemHeight; |
| 97 } | 663 } |
| 98 return NULL; | 664 } |
| 99 } | 665 } |
| 100 CFX_ByteString CPVT_FontMap::GetPDFFontAlias(int32_t nFontIndex) | 666 if (sBody.GetSize() > 0) { |
| 101 { | 667 sAppStream << "/Tx BMC\n" |
| 102 switch (nFontIndex) { | 668 << "q\n"; |
| 103 case 0: | 669 sAppStream << rcBody.left << " " << rcBody.bottom << " " |
| 104 return m_sDefFontAlias; | 670 << rcBody.Width() << " " << rcBody.Height() << " re\nW\nn\n"; |
| 105 case 1: | 671 sAppStream << sBody.GetByteString() << "Q\nEMC\n"; |
| 106 if (!m_pSysFont) { | 672 } |
| 107 GetAnnotSysPDFFont(m_pDocument, m_pResDict, m_pSysFont, m_sSysFo
ntAlias); | 673 } break; |
| 108 } | 674 } |
| 109 return m_sSysFontAlias; | 675 if (pNormalStream) { |
| 110 } | 676 pNormalStream->SetData((uint8_t*)sAppStream.GetBuffer(), |
| 111 return ""; | 677 sAppStream.GetSize(), FALSE, FALSE); |
| 112 } | 678 pStreamDict = pNormalStream->GetDict(); |
| 113 CPVT_Provider::CPVT_Provider(IPVT_FontMap * pFontMap) : m_pFontMap(pFontMap) | 679 if (pStreamDict) { |
| 114 { | 680 pStreamDict->SetAtMatrix("Matrix", matrix); |
| 115 ASSERT (m_pFontMap != NULL); | 681 pStreamDict->SetAtRect("BBox", rcBBox); |
| 116 } | 682 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); |
| 117 CPVT_Provider::~CPVT_Provider() | 683 if (pStreamResList) { |
| 118 { | 684 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font"); |
| 119 } | 685 if (!pStreamResFontList) { |
| 120 int32_t CPVT_Provider::GetCharWidth(int32_t nFontIndex, FX_WORD word, int32_t nW
ordStyle) | 686 pStreamResFontList = CPDF_Dictionary::Create(); |
| 121 { | 687 if (pStreamResFontList == NULL) { |
| 122 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { | 688 return FALSE; |
| 123 FX_DWORD charcode = pPDFFont->CharCodeFromUnicode(word); | 689 } |
| 124 if (charcode != -1) { | 690 pStreamResList->SetAt("Font", pStreamResFontList); |
| 125 return pPDFFont->GetCharWidthF(charcode); | 691 } |
| 126 } | 692 if (!pStreamResFontList->KeyExist(sFontName)) { |
| 127 } | 693 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); |
| 128 return 0; | 694 } |
| 129 } | 695 } else { |
| 130 int32_t CPVT_Provider::GetTypeAscent(int32_t nFontIndex) | 696 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone()); |
| 131 { | 697 pStreamResList = pStreamDict->GetDict("Resources"); |
| 132 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { | 698 } |
| 133 return pPDFFont->GetTypeAscent(); | 699 } |
| 134 } | 700 } |
| 135 return 0; | 701 return TRUE; |
| 136 } | 702 } |
| 137 int32_t CPVT_Provider::GetTypeDescent(int32_t nFontIndex) | 703 FX_BOOL CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, |
| 138 { | 704 CPDF_Dictionary* pAnnotDict) { |
| 139 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { | 705 return GenerateWidgetAP(pDoc, pAnnotDict, 0); |
| 140 return pPDFFont->GetTypeDescent(); | 706 } |
| 141 } | 707 FX_BOOL CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc, |
| 142 return 0; | 708 CPDF_Dictionary* pAnnotDict) { |
| 143 } | 709 return GenerateWidgetAP(pDoc, pAnnotDict, 1); |
| 144 int32_t CPVT_Provider::GetWordFontIndex(FX_WORD word, int32_t charset, int32_t n
FontIndex) | 710 } |
| 145 { | 711 FX_BOOL CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc, |
| 146 if (CPDF_Font* pDefFont = m_pFontMap->GetPDFFont(0)) { | 712 CPDF_Dictionary* pAnnotDict) { |
| 147 if (pDefFont->CharCodeFromUnicode(word) != -1) { | 713 return GenerateWidgetAP(pDoc, pAnnotDict, 2); |
| 148 return 0; | 714 } |
| 149 } | 715 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( |
| 150 } | 716 IPVT_FontMap* pFontMap, |
| 151 if (CPDF_Font* pSysFont = m_pFontMap->GetPDFFont(1)) | 717 IPDF_VariableText_Iterator* pIterator, |
| 152 if (pSysFont->CharCodeFromUnicode(word) != -1) { | 718 const CPDF_Point& ptOffset, |
| 153 return 1; | 719 FX_BOOL bContinuous, |
| 154 } | 720 FX_WORD SubWord, |
| 155 return -1; | 721 const CPVT_WordRange* pVisible) { |
| 156 } | 722 CFX_ByteTextBuf sEditStream, sLineStream, sWords; |
| 157 FX_BOOL CPVT_Provider::IsLatinWord(FX_WORD word) | 723 CPDF_Point ptOld(0.0f, 0.0f), ptNew(0.0f, 0.0f); |
| 158 { | 724 int32_t nCurFontIndex = -1; |
| 159 if ((word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) || word
== 0x2D || word == 0x27) { | 725 if (pIterator) { |
| 160 return TRUE; | 726 if (pVisible) { |
| 161 } | 727 pIterator->SetAt(pVisible->BeginPos); |
| 162 return FALSE; | |
| 163 } | |
| 164 int32_t CPVT_Provider::GetDefaultFontIndex() | |
| 165 { | |
| 166 return 0; | |
| 167 } | |
| 168 static CFX_ByteString GetPDFWordString(IPVT_FontMap * pFontMap, int32_t nFontInd
ex, FX_WORD Word, FX_WORD SubWord) | |
| 169 { | |
| 170 CFX_ByteString sWord; | |
| 171 if (SubWord > 0) { | |
| 172 sWord.Format("%c", SubWord); | |
| 173 } else { | 728 } else { |
| 174 if (pFontMap) { | 729 pIterator->SetAt(0); |
| 175 if (CPDF_Font * pPDFFont = pFontMap->GetPDFFont(nFontIndex)) { | 730 } |
| 176 if (pPDFFont->GetBaseFont().Compare("Symbol") == 0 || pPDFFont->
GetBaseFont().Compare("ZapfDingbats") == 0) { | 731 CPVT_WordPlace oldplace; |
| 177 sWord.Format("%c", Word); | 732 while (pIterator->NextWord()) { |
| 178 } else { | 733 CPVT_WordPlace place = pIterator->GetAt(); |
| 179 FX_DWORD dwCharCode = pPDFFont->CharCodeFromUnicode(Word); | 734 if (pVisible && place.WordCmp(pVisible->EndPos) > 0) { |
| 180 if (dwCharCode != -1) { | 735 break; |
| 181 pPDFFont->AppendChar(sWord, dwCharCode); | 736 } |
| 182 } | 737 if (bContinuous) { |
| 183 } | 738 if (place.LineCmp(oldplace) != 0) { |
| 184 } | 739 if (sWords.GetSize() > 0) { |
| 185 } | |
| 186 } | |
| 187 return sWord; | |
| 188 } | |
| 189 static CFX_ByteString GetWordRenderString(const CFX_ByteString & strWords) | |
| 190 { | |
| 191 if (strWords.GetLength() > 0) { | |
| 192 return PDF_EncodeString(strWords) + " Tj\n"; | |
| 193 } | |
| 194 return ""; | |
| 195 } | |
| 196 static CFX_ByteString GetFontSetString(IPVT_FontMap * pFontMap, int32_t nFontInd
ex, FX_FLOAT fFontSize) | |
| 197 { | |
| 198 CFX_ByteTextBuf sRet; | |
| 199 if (pFontMap) { | |
| 200 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | |
| 201 if (sFontAlias.GetLength() > 0 && fFontSize > 0 ) { | |
| 202 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | |
| 203 } | |
| 204 } | |
| 205 return sRet.GetByteString(); | |
| 206 } | |
| 207 static CPVT_Color ParseColor(const CFX_ByteString & str) | |
| 208 { | |
| 209 CPDF_SimpleParser syntax(str); | |
| 210 syntax.SetPos(0); | |
| 211 if (syntax.FindTagParam("g", 1)) { | |
| 212 return CPVT_Color(CT_GRAY, FX_atof(syntax.GetWord())); | |
| 213 } | |
| 214 syntax.SetPos(0); | |
| 215 if (syntax.FindTagParam("rg", 3)) { | |
| 216 FX_FLOAT f1 = FX_atof(syntax.GetWord()); | |
| 217 FX_FLOAT f2 = FX_atof(syntax.GetWord()); | |
| 218 FX_FLOAT f3 = FX_atof(syntax.GetWord()); | |
| 219 return CPVT_Color(CT_RGB, f1, f2, f3); | |
| 220 } | |
| 221 syntax.SetPos(0); | |
| 222 if (syntax.FindTagParam("k", 4)) { | |
| 223 FX_FLOAT f1 = FX_atof(syntax.GetWord()); | |
| 224 FX_FLOAT f2 = FX_atof(syntax.GetWord()); | |
| 225 FX_FLOAT f3 = FX_atof(syntax.GetWord()); | |
| 226 FX_FLOAT f4 = FX_atof(syntax.GetWord()); | |
| 227 return CPVT_Color(CT_CMYK, f1, f2, f3, f4); | |
| 228 } | |
| 229 return CPVT_Color(CT_TRANSPARENT); | |
| 230 } | |
| 231 static CPVT_Color ParseColor(const CPDF_Array & array) | |
| 232 { | |
| 233 CPVT_Color rt; | |
| 234 switch (array.GetCount()) { | |
| 235 case 1: | |
| 236 rt = CPVT_Color(CT_GRAY, array.GetFloat(0)); | |
| 237 break; | |
| 238 case 3: | |
| 239 rt = CPVT_Color(CT_RGB, array.GetFloat(0), array.GetFloat(1), array.
GetFloat(2)); | |
| 240 break; | |
| 241 case 4: | |
| 242 rt = CPVT_Color(CT_CMYK, array.GetFloat(0), array.GetFloat(1), array
.GetFloat(2), array.GetFloat(3)); | |
| 243 break; | |
| 244 } | |
| 245 return rt; | |
| 246 } | |
| 247 static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict
, const int32_t & nWidgetType) | |
| 248 { | |
| 249 CPDF_Dictionary* pFormDict = NULL; | |
| 250 if (CPDF_Dictionary * pRootDict = pDoc->GetRoot()) { | |
| 251 pFormDict = pRootDict->GetDict("AcroForm"); | |
| 252 } | |
| 253 if (!pFormDict) { | |
| 254 return FALSE; | |
| 255 } | |
| 256 CFX_ByteString DA; | |
| 257 if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA")) { | |
| 258 DA = pDAObj->GetString(); | |
| 259 } | |
| 260 if (DA.IsEmpty()) { | |
| 261 DA = pFormDict->GetString("DA"); | |
| 262 } | |
| 263 if (DA.IsEmpty()) { | |
| 264 return FALSE; | |
| 265 } | |
| 266 CPDF_SimpleParser syntax(DA); | |
| 267 syntax.FindTagParam("Tf", 2); | |
| 268 CFX_ByteString sFontName = syntax.GetWord(); | |
| 269 sFontName = PDF_NameDecode(sFontName); | |
| 270 if (sFontName.IsEmpty()) { | |
| 271 return FALSE; | |
| 272 } | |
| 273 FX_FLOAT fFontSize = FX_atof(syntax.GetWord()); | |
| 274 CPVT_Color crText = ParseColor(DA); | |
| 275 FX_BOOL bUseFormRes = FALSE; | |
| 276 CPDF_Dictionary * pFontDict = NULL; | |
| 277 CPDF_Dictionary* pDRDict = pAnnotDict->GetDict(FX_BSTRC("DR")); | |
| 278 if (pDRDict == NULL) { | |
| 279 pDRDict = pFormDict->GetDict(FX_BSTRC("DR")); | |
| 280 bUseFormRes = TRUE; | |
| 281 } | |
| 282 CPDF_Dictionary * pDRFontDict = NULL; | |
| 283 if (pDRDict && (pDRFontDict = pDRDict->GetDict("Font"))) { | |
| 284 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1)); | |
| 285 if (!pFontDict && !bUseFormRes) { | |
| 286 pDRDict = pFormDict->GetDict(FX_BSTRC("DR")); | |
| 287 pDRFontDict = pDRDict->GetDict("Font"); | |
| 288 if (pDRFontDict) { | |
| 289 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1)); | |
| 290 } | |
| 291 } | |
| 292 } | |
| 293 if (!pDRFontDict) { | |
| 294 return FALSE; | |
| 295 } | |
| 296 if (!pFontDict) { | |
| 297 pFontDict = CPDF_Dictionary::Create(); | |
| 298 if (pFontDict == NULL) { | |
| 299 return FALSE; | |
| 300 } | |
| 301 pFontDict->SetAtName(FX_BSTRC("Type"), "Font"); | |
| 302 pFontDict->SetAtName(FX_BSTRC("Subtype"), "Type1"); | |
| 303 pFontDict->SetAtName(FX_BSTRC("BaseFont"), "Helvetica"); | |
| 304 pFontDict->SetAtName(FX_BSTRC("Encoding"), "WinAnsiEncoding"); | |
| 305 pDoc->AddIndirectObject(pFontDict); | |
| 306 pDRFontDict->SetAtReference(sFontName.Mid(1), pDoc, pFontDict); | |
| 307 } | |
| 308 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); | |
| 309 if (!pDefFont) { | |
| 310 return FALSE; | |
| 311 } | |
| 312 CPDF_Rect rcAnnot = pAnnotDict->GetRect("Rect"); | |
| 313 int32_t nRotate = 0; | |
| 314 if (CPDF_Dictionary * pMKDict = pAnnotDict->GetDict("MK")) { | |
| 315 nRotate = pMKDict->GetInteger("R"); | |
| 316 } | |
| 317 CPDF_Rect rcBBox; | |
| 318 CPDF_Matrix matrix; | |
| 319 switch (nRotate % 360) { | |
| 320 case 0: | |
| 321 rcBBox = CPDF_Rect(0, 0, rcAnnot.right - rcAnnot.left, rcAnnot.top -
rcAnnot.bottom); | |
| 322 break; | |
| 323 case 90: | |
| 324 matrix = CPDF_Matrix(0, 1, -1, 0, rcAnnot.right - rcAnnot.left, 0); | |
| 325 rcBBox = CPDF_Rect(0, 0, rcAnnot.top - rcAnnot.bottom, rcAnnot.right
- rcAnnot.left); | |
| 326 break; | |
| 327 case 180: | |
| 328 matrix = CPDF_Matrix(-1, 0, 0, -1, rcAnnot.right - rcAnnot.left, rcA
nnot.top - rcAnnot.bottom); | |
| 329 rcBBox = CPDF_Rect(0, 0, rcAnnot.right - rcAnnot.left, rcAnnot.top -
rcAnnot.bottom); | |
| 330 break; | |
| 331 case 270: | |
| 332 matrix = CPDF_Matrix(0, -1, 1, 0, 0, rcAnnot.top - rcAnnot.bottom); | |
| 333 rcBBox = CPDF_Rect(0, 0, rcAnnot.top - rcAnnot.bottom, rcAnnot.right
- rcAnnot.left); | |
| 334 break; | |
| 335 } | |
| 336 int32_t nBorderStyle = PBS_SOLID; | |
| 337 FX_FLOAT fBorderWidth = 1; | |
| 338 CPVT_Dash dsBorder(3, 0, 0); | |
| 339 CPVT_Color crLeftTop, crRightBottom; | |
| 340 if (CPDF_Dictionary * pBSDict = pAnnotDict->GetDict("BS")) { | |
| 341 if (pBSDict->KeyExist("W")) { | |
| 342 fBorderWidth = pBSDict->GetNumber("W"); | |
| 343 } | |
| 344 if (CPDF_Array * pArray = pBSDict->GetArray("D")) { | |
| 345 dsBorder = CPVT_Dash(pArray->GetInteger(0), pArray->GetInteger(1), p
Array->GetInteger(2)); | |
| 346 } | |
| 347 switch (pBSDict->GetString("S").GetAt(0)) { | |
| 348 case 'S': | |
| 349 nBorderStyle = PBS_SOLID; | |
| 350 break; | |
| 351 case 'D': | |
| 352 nBorderStyle = PBS_DASH; | |
| 353 break; | |
| 354 case 'B': | |
| 355 nBorderStyle = PBS_BEVELED; | |
| 356 fBorderWidth *= 2; | |
| 357 crLeftTop = CPVT_Color(CT_GRAY, 1); | |
| 358 crRightBottom = CPVT_Color(CT_GRAY, 0.5); | |
| 359 break; | |
| 360 case 'I': | |
| 361 nBorderStyle = PBS_INSET; | |
| 362 fBorderWidth *= 2; | |
| 363 crLeftTop = CPVT_Color(CT_GRAY, 0.5); | |
| 364 crRightBottom = CPVT_Color(CT_GRAY, 0.75); | |
| 365 break; | |
| 366 case 'U': | |
| 367 nBorderStyle = PBS_UNDERLINED; | |
| 368 break; | |
| 369 } | |
| 370 } | |
| 371 CPVT_Color crBorder, crBG; | |
| 372 if (CPDF_Dictionary * pMKDict = pAnnotDict->GetDict("MK")) { | |
| 373 if (CPDF_Array * pArray = pMKDict->GetArray("BC")) { | |
| 374 crBorder = ParseColor(*pArray); | |
| 375 } | |
| 376 if (CPDF_Array * pArray = pMKDict->GetArray("BG")) { | |
| 377 crBG = ParseColor(*pArray); | |
| 378 } | |
| 379 } | |
| 380 CFX_ByteTextBuf sAppStream; | |
| 381 CFX_ByteString sBG = CPVT_GenerateAP::GenerateColorAP(crBG, TRUE); | |
| 382 if (sBG.GetLength() > 0) { | |
| 383 sAppStream << "q\n" << sBG << rcBBox.left << " " << rcBBox.bottom << " " | |
| 384 << rcBBox.Width() << " " << rcBBox.Height() << " re f\n" << "
Q\n"; | |
| 385 } | |
| 386 CFX_ByteString sBorderStream = CPVT_GenerateAP::GenerateBorderAP(rcBBox, fBo
rderWidth, | |
| 387 crBorder, crLeftTop, crRightBottom, nBorderSt
yle, dsBorder); | |
| 388 if (sBorderStream.GetLength() > 0) { | |
| 389 sAppStream << "q\n" << sBorderStream << "Q\n"; | |
| 390 } | |
| 391 CPDF_Rect rcBody = CPDF_Rect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBo
rderWidth, | |
| 392 rcBBox.right - fBorderWidth, rcBBox.top - fBord
erWidth); | |
| 393 rcBody.Normalize(); | |
| 394 CPDF_Dictionary* pAPDict = pAnnotDict->GetDict("AP"); | |
| 395 if (pAPDict == NULL) { | |
| 396 pAPDict = CPDF_Dictionary::Create(); | |
| 397 if (pAPDict == NULL) { | |
| 398 return FALSE; | |
| 399 } | |
| 400 pAnnotDict->SetAt("AP", pAPDict); | |
| 401 } | |
| 402 CPDF_Stream* pNormalStream = pAPDict->GetStream("N"); | |
| 403 if (pNormalStream == NULL) { | |
| 404 pNormalStream = CPDF_Stream::Create(NULL, 0, NULL); | |
| 405 if (pNormalStream == NULL) { | |
| 406 return FALSE; | |
| 407 } | |
| 408 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); | |
| 409 pAnnotDict->GetDict("AP")->SetAtReference("N", pDoc, objnum); | |
| 410 } | |
| 411 CPDF_Dictionary * pStreamDict = pNormalStream->GetDict(); | |
| 412 if (pStreamDict) { | |
| 413 pStreamDict->SetAtMatrix("Matrix", matrix); | |
| 414 pStreamDict->SetAtRect("BBox", rcBBox); | |
| 415 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); | |
| 416 if (pStreamResList) { | |
| 417 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font"
); | |
| 418 if (!pStreamResFontList) { | |
| 419 pStreamResFontList = CPDF_Dictionary::Create(); | |
| 420 if (pStreamResFontList == NULL) { | |
| 421 return FALSE; | |
| 422 } | |
| 423 pStreamResList->SetAt("Font", pStreamResFontList); | |
| 424 } | |
| 425 if (!pStreamResFontList->KeyExist(sFontName)) { | |
| 426 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); | |
| 427 } | |
| 428 } else { | |
| 429 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone()); | |
| 430 pStreamResList = pStreamDict->GetDict("Resources"); | |
| 431 } | |
| 432 } | |
| 433 switch (nWidgetType) { | |
| 434 case 0: { | |
| 435 CFX_WideString swValue = FPDF_GetFieldAttr(pAnnotDict, "V")? FPD
F_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() : CFX_WideString(); | |
| 436 int32_t nAlign = FPDF_GetFieldAttr(pAnnotDict, "Q")? FPDF_GetFie
ldAttr(pAnnotDict, "Q")->GetInteger() : 0; | |
| 437 FX_DWORD dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff")? FPDF_Get
FieldAttr(pAnnotDict, "Ff")->GetInteger() : 0; | |
| 438 FX_DWORD dwMaxLen = FPDF_GetFieldAttr(pAnnotDict, "MaxLen") ? FP
DF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger() : 0; | |
| 439 CPVT_FontMap map(pDoc, pStreamDict ? pStreamDict->GetDict("Resou
rces") : NULL , pDefFont, sFontName.Right(sFontName.GetLength() - 1)); | |
| 440 CPVT_Provider prd(&map); | |
| 441 CPDF_VariableText vt; | |
| 442 vt.SetProvider(&prd); | |
| 443 vt.SetPlateRect(rcBody); | |
| 444 vt.SetAlignment(nAlign); | |
| 445 if (IsFloatZero(fFontSize)) { | |
| 446 vt.SetAutoFontSize(TRUE); | |
| 447 } else { | |
| 448 vt.SetFontSize(fFontSize); | |
| 449 } | |
| 450 FX_BOOL bMultiLine = (dwFlags >> 12) & 1; | |
| 451 if (bMultiLine) { | |
| 452 vt.SetMultiLine(TRUE); | |
| 453 vt.SetAutoReturn(TRUE); | |
| 454 } | |
| 455 FX_WORD subWord = 0; | |
| 456 if ((dwFlags >> 13) & 1) { | |
| 457 subWord = '*'; | |
| 458 vt.SetPasswordChar(subWord); | |
| 459 } | |
| 460 FX_BOOL bCharArray = (dwFlags >> 24) & 1; | |
| 461 if (bCharArray) { | |
| 462 vt.SetCharArray(dwMaxLen); | |
| 463 } else { | |
| 464 vt.SetLimitChar(dwMaxLen); | |
| 465 } | |
| 466 vt.Initialize(); | |
| 467 vt.SetText(swValue.c_str()); | |
| 468 vt.RearrangeAll(); | |
| 469 CPDF_Rect rcContent = vt.GetContentRect(); | |
| 470 CPDF_Point ptOffset(0.0f, 0.0f); | |
| 471 if (!bMultiLine) { | |
| 472 ptOffset = CPDF_Point(0.0f, (rcContent.Height() - rcBody.Hei
ght()) / 2.0f); | |
| 473 } | |
| 474 CFX_ByteString sBody = CPVT_GenerateAP::GenerateEditAP(&map, vt.
GetIterator(), ptOffset, !bCharArray, subWord); | |
| 475 if (sBody.GetLength() > 0) { | |
| 476 sAppStream << "/Tx BMC\n" << "q\n"; | |
| 477 if (rcContent.Width() > rcBody.Width() || | |
| 478 rcContent.Height() > rcBody.Height()) { | |
| 479 sAppStream << rcBody.left << " " << rcBody.bottom << " " | |
| 480 << rcBody.Width() << " " << rcBody.Height() <
< " re\nW\nn\n"; | |
| 481 } | |
| 482 sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crT
ext, TRUE) << sBody << "ET\n" << "Q\nEMC\n"; | |
| 483 } | |
| 484 } | |
| 485 break; | |
| 486 case 1: { | |
| 487 CFX_WideString swValue = FPDF_GetFieldAttr(pAnnotDict, "V") ? FP
DF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() : CFX_WideString(); | |
| 488 CPVT_FontMap map(pDoc, pStreamDict ? pStreamDict->GetDict("Resou
rces"):NULL, pDefFont, sFontName.Right(sFontName.GetLength() - 1)); | |
| 489 CPVT_Provider prd(&map); | |
| 490 CPDF_VariableText vt; | |
| 491 vt.SetProvider(&prd); | |
| 492 CPDF_Rect rcButton = rcBody; | |
| 493 rcButton.left = rcButton.right - 13; | |
| 494 rcButton.Normalize(); | |
| 495 CPDF_Rect rcEdit = rcBody; | |
| 496 rcEdit.right = rcButton.left; | |
| 497 rcEdit.Normalize(); | |
| 498 vt.SetPlateRect(rcEdit); | |
| 499 if (IsFloatZero(fFontSize)) { | |
| 500 vt.SetAutoFontSize(TRUE); | |
| 501 } else { | |
| 502 vt.SetFontSize(fFontSize); | |
| 503 } | |
| 504 vt.Initialize(); | |
| 505 vt.SetText(swValue.c_str()); | |
| 506 vt.RearrangeAll(); | |
| 507 CPDF_Rect rcContent = vt.GetContentRect(); | |
| 508 CPDF_Point ptOffset = CPDF_Point(0.0f, (rcContent.Height() - rcE
dit.Height()) / 2.0f); | |
| 509 CFX_ByteString sEdit = CPVT_GenerateAP::GenerateEditAP(&map, vt.
GetIterator(), ptOffset, TRUE, 0); | |
| 510 if (sEdit.GetLength() > 0) { | |
| 511 sAppStream << "/Tx BMC\n" << "q\n"; | |
| 512 sAppStream << rcEdit.left << " " << rcEdit.bottom << " " | |
| 513 << rcEdit.Width() << " " << rcEdit.Height() << "
re\nW\nn\n"; | |
| 514 sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crT
ext, TRUE) << sEdit << "ET\n" << "Q\nEMC\n"; | |
| 515 } | |
| 516 CFX_ByteString sButton = CPVT_GenerateAP::GenerateColorAP(CPVT_C
olor(CT_RGB, 220.0f / 255.0f, 220.0f / 255.0f, 220.0f / 255.0f), TRUE); | |
| 517 if (sButton.GetLength() > 0 && !rcButton.IsEmpty()) { | |
| 518 sAppStream << "q\n" << sButton; | |
| 519 sAppStream << rcButton.left << " " << rcButton.bottom << " " | |
| 520 << rcButton.Width() << " " << rcButton.Height() <
< " re f\n"; | |
| 521 sAppStream << "Q\n"; | |
| 522 CFX_ByteString sButtonBorder = CPVT_GenerateAP::GenerateBord
erAP(rcButton, 2, CPVT_Color(CT_GRAY, 0), CPVT_Color(CT_GRAY, 1), CPVT_Color(CT_
GRAY, 0.5), PBS_BEVELED, CPVT_Dash(3, 0, 0)); | |
| 523 if (sButtonBorder.GetLength() > 0) { | |
| 524 sAppStream << "q\n" << sButtonBorder << "Q\n"; | |
| 525 } | |
| 526 CPDF_Point ptCenter = CPDF_Point((rcButton.left + rcButton.r
ight) / 2, (rcButton.top + rcButton.bottom) / 2); | |
| 527 if (IsFloatBigger(rcButton.Width(), 6) && IsFloatBigger(rcBu
tton.Height(), 6)) { | |
| 528 sAppStream << "q\n" << " 0 g\n"; | |
| 529 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f
<< " m\n"; | |
| 530 sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f
<< " l\n"; | |
| 531 sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f <<
" l\n"; | |
| 532 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f
<< " l f\n"; | |
| 533 sAppStream << sButton << "Q\n"; | |
| 534 } | |
| 535 } | |
| 536 } | |
| 537 break; | |
| 538 case 2: { | |
| 539 CPVT_FontMap map(pDoc, pStreamDict ? pStreamDict->GetDict("Resou
rces"):NULL, pDefFont, sFontName.Right(sFontName.GetLength() - 1)); | |
| 540 CPVT_Provider prd(&map); | |
| 541 CPDF_Array * pOpts = FPDF_GetFieldAttr(pAnnotDict, "Opt") ? FPDF
_GetFieldAttr(pAnnotDict, "Opt")->GetArray() : NULL; | |
| 542 CPDF_Array * pSels = FPDF_GetFieldAttr(pAnnotDict, "I") ? FPDF_G
etFieldAttr(pAnnotDict, "I")->GetArray() : NULL; | |
| 543 int32_t nTop = FPDF_GetFieldAttr(pAnnotDict, "TI") ? FPDF_GetFie
ldAttr(pAnnotDict, "TI")->GetInteger() : 0; | |
| 544 CFX_ByteTextBuf sBody; | |
| 545 if (pOpts) { | |
| 546 FX_FLOAT fy = rcBody.top; | |
| 547 for (int32_t i = nTop, sz = pOpts->GetCount(); i < sz; i++)
{ | |
| 548 if (IsFloatSmaller(fy, rcBody.bottom)) { | |
| 549 break; | |
| 550 } | |
| 551 if (CPDF_Object* pOpt = pOpts->GetElementValue(i)) { | |
| 552 CFX_WideString swItem; | |
| 553 if (pOpt->GetType() == PDFOBJ_STRING) { | |
| 554 swItem = pOpt->GetUnicodeText(); | |
| 555 } else if (pOpt->GetType() == PDFOBJ_ARRAY) { | |
| 556 swItem = ((CPDF_Array*)pOpt)->GetElementValue(1)
->GetUnicodeText(); | |
| 557 } | |
| 558 FX_BOOL bSelected = FALSE; | |
| 559 if (pSels) { | |
| 560 for (FX_DWORD s = 0, ssz = pSels->GetCount(); s
< ssz; s++) { | |
| 561 if (i == pSels->GetInteger(s)) { | |
| 562 bSelected = TRUE; | |
| 563 break; | |
| 564 } | |
| 565 } | |
| 566 } | |
| 567 CPDF_VariableText vt; | |
| 568 vt.SetProvider(&prd); | |
| 569 vt.SetPlateRect(CPDF_Rect(rcBody.left, 0.0f, rcBody.
right, 0.0f)); | |
| 570 if (IsFloatZero(fFontSize)) { | |
| 571 vt.SetFontSize(12.0f); | |
| 572 } else { | |
| 573 vt.SetFontSize(fFontSize); | |
| 574 } | |
| 575 vt.Initialize(); | |
| 576 vt.SetText(swItem.c_str()); | |
| 577 vt.RearrangeAll(); | |
| 578 FX_FLOAT fItemHeight = vt.GetContentRect().Height(); | |
| 579 if (bSelected) { | |
| 580 CPDF_Rect rcItem = CPDF_Rect(rcBody.left, fy - f
ItemHeight, rcBody.right, fy); | |
| 581 sBody << "q\n" << CPVT_GenerateAP::GenerateColor
AP(CPVT_Color(CT_RGB, 0, 51.0f / 255.0f, 113.0f / 255.0f), TRUE) | |
| 582 << rcItem.left << " " << rcItem.bottom <<
" " << rcItem.Width() << " " << rcItem.Height() << " re f\n" << "Q\n"; | |
| 583 sBody << "BT\n" << CPVT_GenerateAP::GenerateColo
rAP(CPVT_Color(CT_GRAY, 1), TRUE) << CPVT_GenerateAP::GenerateEditAP(&map, vt.Ge
tIterator(), CPDF_Point(0.0f, fy), TRUE, 0) << "ET\n"; | |
| 584 } else { | |
| 585 sBody << "BT\n" << CPVT_GenerateAP::GenerateColo
rAP(crText, TRUE) << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), CPD
F_Point(0.0f, fy), TRUE, 0) << "ET\n"; | |
| 586 } | |
| 587 fy -= fItemHeight; | |
| 588 } | |
| 589 } | |
| 590 } | |
| 591 if (sBody.GetSize() > 0) { | |
| 592 sAppStream << "/Tx BMC\n" << "q\n"; | |
| 593 sAppStream << rcBody.left << " " << rcBody.bottom << " " | |
| 594 << rcBody.Width() << " " << rcBody.Height() << "
re\nW\nn\n"; | |
| 595 sAppStream << sBody.GetByteString() << "Q\nEMC\n"; | |
| 596 } | |
| 597 } | |
| 598 break; | |
| 599 } | |
| 600 if (pNormalStream) { | |
| 601 pNormalStream->SetData((uint8_t*)sAppStream.GetBuffer(), sAppStream.GetS
ize(), FALSE, FALSE); | |
| 602 pStreamDict = pNormalStream->GetDict(); | |
| 603 if (pStreamDict) { | |
| 604 pStreamDict->SetAtMatrix("Matrix", matrix); | |
| 605 pStreamDict->SetAtRect("BBox", rcBBox); | |
| 606 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); | |
| 607 if (pStreamResList) { | |
| 608 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("F
ont"); | |
| 609 if (!pStreamResFontList) { | |
| 610 pStreamResFontList = CPDF_Dictionary::Create(); | |
| 611 if (pStreamResFontList == NULL) { | |
| 612 return FALSE; | |
| 613 } | |
| 614 pStreamResList->SetAt("Font", pStreamResFontList); | |
| 615 } | |
| 616 if (!pStreamResFontList->KeyExist(sFontName)) { | |
| 617 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDic
t); | |
| 618 } | |
| 619 } else { | |
| 620 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone(
)); | |
| 621 pStreamResList = pStreamDict->GetDict("Resources"); | |
| 622 } | |
| 623 } | |
| 624 } | |
| 625 return TRUE; | |
| 626 } | |
| 627 FX_BOOL CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, CPDF_Dictionar
y* pAnnotDict) | |
| 628 { | |
| 629 return GenerateWidgetAP(pDoc, pAnnotDict, 0); | |
| 630 } | |
| 631 FX_BOOL CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc, CPDF_Dictionary
* pAnnotDict) | |
| 632 { | |
| 633 return GenerateWidgetAP(pDoc, pAnnotDict, 1); | |
| 634 } | |
| 635 FX_BOOL CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc, CPDF_Dictionary*
pAnnotDict) | |
| 636 { | |
| 637 return GenerateWidgetAP(pDoc, pAnnotDict, 2); | |
| 638 } | |
| 639 CFX_ByteString CPVT_GenerateAP::GenerateEditAP(IPVT_FontMap * pFontMap, IPDF_Var
iableText_Iterator* pIterator, const CPDF_Point & ptOffset, FX_BOOL bContinuous,
FX_WORD SubWord, const CPVT_WordRange * pVisible) | |
| 640 { | |
| 641 CFX_ByteTextBuf sEditStream, sLineStream, sWords; | |
| 642 CPDF_Point ptOld(0.0f, 0.0f), ptNew(0.0f, 0.0f); | |
| 643 int32_t nCurFontIndex = -1; | |
| 644 if (pIterator) { | |
| 645 if (pVisible) { | |
| 646 pIterator->SetAt(pVisible->BeginPos); | |
| 647 } else { | |
| 648 pIterator->SetAt(0); | |
| 649 } | |
| 650 CPVT_WordPlace oldplace; | |
| 651 while (pIterator->NextWord()) { | |
| 652 CPVT_WordPlace place = pIterator->GetAt(); | |
| 653 if (pVisible && place.WordCmp(pVisible->EndPos) > 0) { | |
| 654 break; | |
| 655 } | |
| 656 if (bContinuous) { | |
| 657 if (place.LineCmp(oldplace) != 0) { | |
| 658 if (sWords.GetSize() > 0) { | |
| 659 sLineStream << GetWordRenderString(sWords.GetByteString(
)); | |
| 660 sEditStream << sLineStream; | |
| 661 sLineStream.Clear(); | |
| 662 sWords.Clear(); | |
| 663 } | |
| 664 CPVT_Word word; | |
| 665 if (pIterator->GetWord(word)) { | |
| 666 ptNew = CPDF_Point(word.ptWord.x + ptOffset.x, word.ptWo
rd.y + ptOffset.y); | |
| 667 } else { | |
| 668 CPVT_Line line; | |
| 669 pIterator->GetLine(line); | |
| 670 ptNew = CPDF_Point(line.ptLine.x + ptOffset.x, line.ptLi
ne.y + ptOffset.y); | |
| 671 } | |
| 672 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { | |
| 673 sLineStream << ptNew.x - ptOld.x << " " << ptNew.y - ptO
ld.y << " Td\n"; | |
| 674 ptOld = ptNew; | |
| 675 } | |
| 676 } | |
| 677 CPVT_Word word; | |
| 678 if (pIterator->GetWord(word)) { | |
| 679 if (word.nFontIndex != nCurFontIndex) { | |
| 680 if (sWords.GetSize() > 0) { | |
| 681 sLineStream << GetWordRenderString(sWords.GetByteStr
ing()); | |
| 682 sWords.Clear(); | |
| 683 } | |
| 684 sLineStream << GetFontSetString(pFontMap, word.nFontInde
x, word.fFontSize); | |
| 685 nCurFontIndex = word.nFontIndex; | |
| 686 } | |
| 687 sWords << GetPDFWordString(pFontMap, nCurFontIndex, word.Wor
d, SubWord); | |
| 688 } | |
| 689 oldplace = place; | |
| 690 } else { | |
| 691 CPVT_Word word; | |
| 692 if (pIterator->GetWord(word)) { | |
| 693 ptNew = CPDF_Point(word.ptWord.x + ptOffset.x, word.ptWord.y
+ ptOffset.y); | |
| 694 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { | |
| 695 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptO
ld.y << " Td\n"; | |
| 696 ptOld = ptNew; | |
| 697 } | |
| 698 if (word.nFontIndex != nCurFontIndex) { | |
| 699 sEditStream << GetFontSetString(pFontMap, word.nFontInde
x, word.fFontSize); | |
| 700 nCurFontIndex = word.nFontIndex; | |
| 701 } | |
| 702 sEditStream << GetWordRenderString(GetPDFWordString(pFontMap
, nCurFontIndex, word.Word, SubWord)); | |
| 703 } | |
| 704 } | |
| 705 } | |
| 706 if (sWords.GetSize() > 0) { | |
| 707 sLineStream << GetWordRenderString(sWords.GetByteString()); | 740 sLineStream << GetWordRenderString(sWords.GetByteString()); |
| 708 sEditStream << sLineStream; | 741 sEditStream << sLineStream; |
| 742 sLineStream.Clear(); |
| 709 sWords.Clear(); | 743 sWords.Clear(); |
| 710 } | 744 } |
| 711 } | 745 CPVT_Word word; |
| 712 return sEditStream.GetByteString(); | 746 if (pIterator->GetWord(word)) { |
| 713 } | 747 ptNew = CPDF_Point(word.ptWord.x + ptOffset.x, |
| 714 CFX_ByteString CPVT_GenerateAP::GenerateBorderAP(const CPDF_Rect & rect, FX_FLOA
T fWidth, | 748 word.ptWord.y + ptOffset.y); |
| 715 const CPVT_Color & color, const CPVT_Color & crLeftTop, const CPVT_Color
& crRightBottom, | 749 } else { |
| 716 int32_t nStyle, const CPVT_Dash & dash) | 750 CPVT_Line line; |
| 717 { | 751 pIterator->GetLine(line); |
| 718 CFX_ByteTextBuf sAppStream; | 752 ptNew = CPDF_Point(line.ptLine.x + ptOffset.x, |
| 719 CFX_ByteString sColor; | 753 line.ptLine.y + ptOffset.y); |
| 720 FX_FLOAT fLeft = rect.left; | 754 } |
| 721 FX_FLOAT fRight = rect.right; | 755 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { |
| 722 FX_FLOAT fTop = rect.top; | 756 sLineStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y |
| 723 FX_FLOAT fBottom = rect.bottom; | 757 << " Td\n"; |
| 724 if (fWidth > 0.0f) { | 758 ptOld = ptNew; |
| 725 FX_FLOAT fHalfWidth = fWidth / 2.0f; | 759 } |
| 726 switch (nStyle) { | 760 } |
| 727 default: | 761 CPVT_Word word; |
| 728 case PBS_SOLID: | 762 if (pIterator->GetWord(word)) { |
| 729 sColor = GenerateColorAP(color, TRUE); | 763 if (word.nFontIndex != nCurFontIndex) { |
| 730 if (sColor.GetLength() > 0) { | 764 if (sWords.GetSize() > 0) { |
| 731 sAppStream << sColor; | 765 sLineStream << GetWordRenderString(sWords.GetByteString()); |
| 732 sAppStream << fLeft << " " << fBottom << " " << fRight - fLe
ft << " " << fTop - fBottom << " re\n"; | 766 sWords.Clear(); |
| 733 sAppStream << fLeft + fWidth << " " << fBottom + fWidth << "
" | 767 } |
| 734 << fRight - fLeft - fWidth * 2 << " " << fTop - f
Bottom - fWidth * 2 << " re\n"; | 768 sLineStream << GetFontSetString(pFontMap, word.nFontIndex, |
| 735 sAppStream << "f*\n"; | 769 word.fFontSize); |
| 736 } | 770 nCurFontIndex = word.nFontIndex; |
| 737 break; | 771 } |
| 738 case PBS_DASH: | 772 sWords << GetPDFWordString(pFontMap, nCurFontIndex, word.Word, |
| 739 sColor = GenerateColorAP(color, FALSE); | 773 SubWord); |
| 740 if (sColor.GetLength() > 0) { | 774 } |
| 741 sAppStream << sColor; | 775 oldplace = place; |
| 742 sAppStream << fWidth << " w" << " [" << dash.nDash << " " <<
dash.nGap << "] " << dash.nPhase << " d\n"; | 776 } else { |
| 743 sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth
/ 2 << " m\n"; | 777 CPVT_Word word; |
| 744 sAppStream << fLeft + fWidth / 2 << " " << fTop - fWidth / 2
<< " l\n"; | 778 if (pIterator->GetWord(word)) { |
| 745 sAppStream << fRight - fWidth / 2 << " " << fTop - fWidth /
2 << " l\n"; | 779 ptNew = CPDF_Point(word.ptWord.x + ptOffset.x, |
| 746 sAppStream << fRight - fWidth / 2 << " " << fBottom + fWidth
/ 2 << " l\n"; | 780 word.ptWord.y + ptOffset.y); |
| 747 sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth
/ 2 << " l S\n"; | 781 if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) { |
| 748 } | 782 sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y |
| 749 break; | 783 << " Td\n"; |
| 750 case PBS_BEVELED: | 784 ptOld = ptNew; |
| 751 case PBS_INSET: | 785 } |
| 752 sColor = GenerateColorAP(crLeftTop, TRUE); | 786 if (word.nFontIndex != nCurFontIndex) { |
| 753 if (sColor.GetLength() > 0) { | 787 sEditStream << GetFontSetString(pFontMap, word.nFontIndex, |
| 754 sAppStream << sColor; | 788 word.fFontSize); |
| 755 sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWi
dth << " m\n"; | 789 nCurFontIndex = word.nFontIndex; |
| 756 sAppStream << fLeft + fHalfWidth << " " << fTop - fHalfWidth
<< " l\n"; | 790 } |
| 757 sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidt
h << " l\n"; | 791 sEditStream << GetWordRenderString( |
| 758 sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalf
Width * 2 << " l\n"; | 792 GetPDFWordString(pFontMap, nCurFontIndex, word.Word, SubWord)); |
| 759 sAppStream << fLeft + fHalfWidth * 2 << " " << fTop - fHalfW
idth * 2 << " l\n"; | 793 } |
| 760 sAppStream << fLeft + fHalfWidth * 2 << " " << fBottom + fHa
lfWidth * 2 << " l f\n"; | 794 } |
| 761 } | 795 } |
| 762 sColor = GenerateColorAP(crRightBottom, TRUE); | 796 if (sWords.GetSize() > 0) { |
| 763 if (sColor.GetLength() > 0) { | 797 sLineStream << GetWordRenderString(sWords.GetByteString()); |
| 764 sAppStream << sColor; | 798 sEditStream << sLineStream; |
| 765 sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidt
h << " m\n"; | 799 sWords.Clear(); |
| 766 sAppStream << fRight - fHalfWidth << " " << fBottom + fHalfW
idth << " l\n"; | 800 } |
| 767 sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfW
idth << " l\n"; | 801 } |
| 768 sAppStream << fLeft + fHalfWidth * 2 << " " << fBottom + fHa
lfWidth * 2 << " l\n"; | 802 return sEditStream.GetByteString(); |
| 769 sAppStream << fRight - fHalfWidth * 2 << " " << fBottom + fH
alfWidth * 2 << " l\n"; | 803 } |
| 770 sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalf
Width * 2 << " l f\n"; | 804 CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( |
| 771 } | 805 const CPDF_Rect& rect, |
| 772 sColor = GenerateColorAP(color, TRUE); | 806 FX_FLOAT fWidth, |
| 773 if (sColor.GetLength() > 0) { | 807 const CPVT_Color& color, |
| 774 sAppStream << sColor; | 808 const CPVT_Color& crLeftTop, |
| 775 sAppStream << fLeft << " " << fBottom << " " << fRight -
fLeft << " " << fTop - fBottom << " re\n"; | 809 const CPVT_Color& crRightBottom, |
| 776 sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWi
dth << " " | 810 int32_t nStyle, |
| 777 << fRight - fLeft - fHalfWidth * 2 << " " << fTop
- fBottom - fHalfWidth * 2 << " re f*\n"; | 811 const CPVT_Dash& dash) { |
| 778 } | 812 CFX_ByteTextBuf sAppStream; |
| 779 break; | 813 CFX_ByteString sColor; |
| 780 case PBS_UNDERLINED: | 814 FX_FLOAT fLeft = rect.left; |
| 781 sColor = GenerateColorAP(color, FALSE); | 815 FX_FLOAT fRight = rect.right; |
| 782 if (sColor.GetLength() > 0) { | 816 FX_FLOAT fTop = rect.top; |
| 783 sAppStream << sColor; | 817 FX_FLOAT fBottom = rect.bottom; |
| 784 sAppStream << fWidth << " w\n"; | 818 if (fWidth > 0.0f) { |
| 785 sAppStream << fLeft << " " << fBottom + fWidth / 2 << " m\n"
; | 819 FX_FLOAT fHalfWidth = fWidth / 2.0f; |
| 786 sAppStream << fRight << " " << fBottom + fWidth / 2 << " l S
\n"; | 820 switch (nStyle) { |
| 787 } | 821 default: |
| 788 break; | 822 case PBS_SOLID: |
| 789 } | 823 sColor = GenerateColorAP(color, TRUE); |
| 790 } | 824 if (sColor.GetLength() > 0) { |
| 791 return sAppStream.GetByteString(); | 825 sAppStream << sColor; |
| 792 } | 826 sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " |
| 793 CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color & color, const
FX_BOOL & bFillOrStroke) | 827 << fTop - fBottom << " re\n"; |
| 794 { | 828 sAppStream << fLeft + fWidth << " " << fBottom + fWidth << " " |
| 795 CFX_ByteTextBuf sColorStream; | 829 << fRight - fLeft - fWidth * 2 << " " |
| 796 switch (color.nColorType) { | 830 << fTop - fBottom - fWidth * 2 << " re\n"; |
| 797 case CT_RGB: | 831 sAppStream << "f*\n"; |
| 798 sColorStream << color.fColor1 << " " << color.fColor2 << " " << colo
r.fColor3 << " " | 832 } |
| 799 << (bFillOrStroke ? "rg" : "RG") << "\n"; | 833 break; |
| 800 break; | 834 case PBS_DASH: |
| 801 case CT_GRAY: | 835 sColor = GenerateColorAP(color, FALSE); |
| 802 sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G")
<< "\n"; | 836 if (sColor.GetLength() > 0) { |
| 803 break; | 837 sAppStream << sColor; |
| 804 case CT_CMYK: | 838 sAppStream << fWidth << " w" |
| 805 sColorStream << color.fColor1 << " " << color.fColor2 << " " << colo
r.fColor3 << " " << color.fColor4 << " " | 839 << " [" << dash.nDash << " " << dash.nGap << "] " |
| 806 << (bFillOrStroke ? "k" : "K") << "\n"; | 840 << dash.nPhase << " d\n"; |
| 807 break; | 841 sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 |
| 808 } | 842 << " m\n"; |
| 809 return sColorStream.GetByteString(); | 843 sAppStream << fLeft + fWidth / 2 << " " << fTop - fWidth / 2 |
| 810 } | 844 << " l\n"; |
| 845 sAppStream << fRight - fWidth / 2 << " " << fTop - fWidth / 2 |
| 846 << " l\n"; |
| 847 sAppStream << fRight - fWidth / 2 << " " << fBottom + fWidth / 2 |
| 848 << " l\n"; |
| 849 sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 |
| 850 << " l S\n"; |
| 851 } |
| 852 break; |
| 853 case PBS_BEVELED: |
| 854 case PBS_INSET: |
| 855 sColor = GenerateColorAP(crLeftTop, TRUE); |
| 856 if (sColor.GetLength() > 0) { |
| 857 sAppStream << sColor; |
| 858 sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth |
| 859 << " m\n"; |
| 860 sAppStream << fLeft + fHalfWidth << " " << fTop - fHalfWidth |
| 861 << " l\n"; |
| 862 sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth |
| 863 << " l\n"; |
| 864 sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 |
| 865 << " l\n"; |
| 866 sAppStream << fLeft + fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 |
| 867 << " l\n"; |
| 868 sAppStream << fLeft + fHalfWidth * 2 << " " |
| 869 << fBottom + fHalfWidth * 2 << " l f\n"; |
| 870 } |
| 871 sColor = GenerateColorAP(crRightBottom, TRUE); |
| 872 if (sColor.GetLength() > 0) { |
| 873 sAppStream << sColor; |
| 874 sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth |
| 875 << " m\n"; |
| 876 sAppStream << fRight - fHalfWidth << " " << fBottom + fHalfWidth |
| 877 << " l\n"; |
| 878 sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth |
| 879 << " l\n"; |
| 880 sAppStream << fLeft + fHalfWidth * 2 << " " |
| 881 << fBottom + fHalfWidth * 2 << " l\n"; |
| 882 sAppStream << fRight - fHalfWidth * 2 << " " |
| 883 << fBottom + fHalfWidth * 2 << " l\n"; |
| 884 sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 |
| 885 << " l f\n"; |
| 886 } |
| 887 sColor = GenerateColorAP(color, TRUE); |
| 888 if (sColor.GetLength() > 0) { |
| 889 sAppStream << sColor; |
| 890 sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " |
| 891 << fTop - fBottom << " re\n"; |
| 892 sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth << " " |
| 893 << fRight - fLeft - fHalfWidth * 2 << " " |
| 894 << fTop - fBottom - fHalfWidth * 2 << " re f*\n"; |
| 895 } |
| 896 break; |
| 897 case PBS_UNDERLINED: |
| 898 sColor = GenerateColorAP(color, FALSE); |
| 899 if (sColor.GetLength() > 0) { |
| 900 sAppStream << sColor; |
| 901 sAppStream << fWidth << " w\n"; |
| 902 sAppStream << fLeft << " " << fBottom + fWidth / 2 << " m\n"; |
| 903 sAppStream << fRight << " " << fBottom + fWidth / 2 << " l S\n"; |
| 904 } |
| 905 break; |
| 906 } |
| 907 } |
| 908 return sAppStream.GetByteString(); |
| 909 } |
| 910 CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color, |
| 911 const FX_BOOL& bFillOrStroke) { |
| 912 CFX_ByteTextBuf sColorStream; |
| 913 switch (color.nColorType) { |
| 914 case CT_RGB: |
| 915 sColorStream << color.fColor1 << " " << color.fColor2 << " " |
| 916 << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG") |
| 917 << "\n"; |
| 918 break; |
| 919 case CT_GRAY: |
| 920 sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") |
| 921 << "\n"; |
| 922 break; |
| 923 case CT_CMYK: |
| 924 sColorStream << color.fColor1 << " " << color.fColor2 << " " |
| 925 << color.fColor3 << " " << color.fColor4 << " " |
| 926 << (bFillOrStroke ? "k" : "K") << "\n"; |
| 927 break; |
| 928 } |
| 929 return sColorStream.GetByteString(); |
| 930 } |
| OLD | NEW |