1 // Copyright 2014 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_INCLUDE_FPDFAPI_FPDF_RESOURCE_H_ 8 #define CORE_INCLUDE_FPDFAPI_FPDF_RESOURCE_H_ 9 10 #include "../fxge/fx_font.h" 11 #include "fpdf_parser.h" 12 13 class CPDF_Font; 14 class CPDF_Type1Font; 15 class CPDF_TrueTypeFont; 16 class CPDF_CIDFont; 17 class CPDF_Type3Font; 18 class CPDF_FontEncoding; 19 class CPDF_CMap; 20 class CPDF_CID2UnicodeMap; 21 class CPDF_ColorSpace; 22 class CPDF_Color; 23 class CPDF_Function; 24 class CPDF_Pattern; 25 class CPDF_TilingPattern; 26 class CPDF_ShadingPattern; 27 class CPDF_Image; 28 class CPDF_Face; 29 class CPDF_ToUnicodeMap; 30 class CFX_SubstFont; 31 class CFX_Font; 32 class CPDF_RenderContext; 33 class CPDF_Form; 34 class CPDF_ImageObject; 35 class CFX_DIBitmap; 36 typedef struct FT_FaceRec_* FXFT_Face; 37 class CFX_CTTGSUBTable; 38 class CPDF_Page; 39 40 template <class ObjClass> class CPDF_CountedObject 41 { 42 public: 43 ObjClass m_Obj; 44 FX_DWORD m_nCount; 45 }; 46 typedef CPDF_CountedObject<CPDF_Font*> CPDF_CountedFont; 47 typedef CPDF_CountedObject<CPDF_ColorSpace*> CPDF_CountedColorSpace; 48 typedef CPDF_CountedObject<CPDF_Pattern*> CPDF_CountedPattern; 49 typedef CPDF_CountedObject<CPDF_Image*> CPDF_CountedImage; 50 typedef CPDF_CountedObject<CPDF_IccProfile*> CPDF_CountedICCProfile; 51 typedef CPDF_CountedObject<CPDF_StreamAcc*> CPDF_CountedStreamAcc; 52 53 54 typedef CFX_MapPtrTemplate<CPDF_Dictionary*, CPDF_CountedFont*> CPDF_FontMap; 55 typedef CFX_MapPtrTemplate<CPDF_Object*, CPDF_CountedColorSpace*> CPDF_ColorSpaceMap; 56 typedef CFX_MapPtrTemplate<CPDF_Object*, CPDF_CountedPattern*> CPDF_PatternMap; 57 typedef CFX_MapPtrTemplate<FX_DWORD, CPDF_CountedImage*> CPDF_ImageMap; 58 typedef CFX_MapPtrTemplate<CPDF_Stream*, CPDF_CountedICCProfile*> CPDF_IccProfileMap; 59 typedef CFX_MapPtrTemplate<CPDF_Stream*, CPDF_CountedStreamAcc*> CPDF_FontFileMap; 60 61 #define PDFFONT_TYPE1 1 62 #define PDFFONT_TRUETYPE 2 63 #define PDFFONT_TYPE3 3 64 #define PDFFONT_CIDFONT 4 65 #define PDFFONT_FIXEDPITCH 1 66 #define PDFFONT_SERIF 2 67 #define PDFFONT_SYMBOLIC 4 68 #define PDFFONT_SCRIPT 8 69 #define PDFFONT_NONSYMBOLIC 32 70 #define PDFFONT_ITALIC 64 71 #define PDFFONT_ALLCAP 0x10000 72 #define PDFFONT_SMALLCAP 0x20000 73 #define PDFFONT_FORCEBOLD 0x40000 74 #define PDFFONT_USEEXTERNATTR 0x80000 75 FX_WCHAR PDF_UnicodeFromAdobeName(const FX_CHAR* name); 76 CFX_ByteString PDF_AdobeNameFromUnicode(FX_WCHAR unicode); 77 class CPDF_Font 78 { 79 public: 80 static CPDF_Font* CreateFontF(CPDF_Document* pDoc, CPDF_Dictionary* pFontDict); 81 static CPDF_Font* GetStockFont(CPDF_Document* pDoc, FX_BSTR fontname); 82 83 virtual ~CPDF_Font(); 84 IsFontType(int fonttype)85 bool IsFontType(int fonttype) const { return fonttype == m_FontType; } GetFontType()86 int GetFontType() const { return m_FontType; } 87 88 CFX_ByteString GetFontTypeName() const; 89 GetBaseFont()90 const CFX_ByteString& GetBaseFont() const 91 { 92 return m_BaseFont; 93 } 94 GetSubstFont()95 const CFX_SubstFont* GetSubstFont() const 96 { 97 return m_Font.GetSubstFont(); 98 } 99 GetFlags()100 FX_DWORD GetFlags() const 101 { 102 return m_Flags; 103 } 104 105 virtual FX_BOOL IsVertWriting()const; 106 107 108 109 GetType1Font()110 CPDF_Type1Font* GetType1Font() const 111 { 112 return m_FontType == PDFFONT_TYPE1 ? (CPDF_Type1Font*)(void*)this : NULL; 113 } 114 GetTrueTypeFont()115 CPDF_TrueTypeFont* GetTrueTypeFont() const 116 { 117 return m_FontType == PDFFONT_TRUETYPE ? (CPDF_TrueTypeFont*)(void*)this : NULL; 118 } 119 GetCIDFont()120 CPDF_CIDFont* GetCIDFont() const 121 { 122 return (m_FontType == PDFFONT_CIDFONT) ? (CPDF_CIDFont*)(void*)this : NULL; 123 } 124 GetType3Font()125 CPDF_Type3Font* GetType3Font() const 126 { 127 return (m_FontType == PDFFONT_TYPE3) ? (CPDF_Type3Font*)(void*)this : NULL; 128 } 129 130 IsEmbedded()131 FX_BOOL IsEmbedded() const 132 { 133 return m_FontType == PDFFONT_TYPE3 || m_pFontFile != NULL; 134 } 135 IsUnicodeCompatible()136 virtual FX_BOOL IsUnicodeCompatible() const 137 { 138 return FALSE; 139 } 140 GetFontFile()141 CPDF_StreamAcc* GetFontFile() const 142 { 143 return m_pFontFile; 144 } 145 GetFontDict()146 CPDF_Dictionary* GetFontDict() const 147 { 148 return m_pFontDict; 149 } 150 151 FX_BOOL IsStandardFont() const; 152 GetFace()153 FXFT_Face GetFace() const 154 { 155 return m_Font.GetFace(); 156 } 157 GetNextChar(FX_LPCSTR pString,int nStrLen,int & offset)158 virtual FX_DWORD GetNextChar(FX_LPCSTR pString, int nStrLen, int& offset) const 159 { 160 if (offset < 0 || nStrLen < 1) { 161 return 0; 162 } 163 FX_BYTE ch = offset < nStrLen ? pString[offset++] : pString[nStrLen-1]; 164 return static_cast<FX_DWORD>(ch); 165 } 166 CountChar(FX_LPCSTR pString,int size)167 virtual int CountChar(FX_LPCSTR pString, int size) const 168 { 169 return size; 170 } 171 172 void AppendChar(CFX_ByteString& str, FX_DWORD charcode) const; 173 AppendChar(FX_LPSTR buf,FX_DWORD charcode)174 virtual int AppendChar(FX_LPSTR buf, FX_DWORD charcode) const 175 { 176 *buf = (FX_CHAR)charcode; 177 return 1; 178 } 179 GetCharSize(FX_DWORD charcode)180 virtual int GetCharSize(FX_DWORD charcode) const 181 { 182 return 1; 183 } 184 185 186 187 188 virtual int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL *pVertGlyph = NULL) = 0; GlyphFromCharCodeExt(FX_DWORD charcode)189 virtual int GlyphFromCharCodeExt(FX_DWORD charcode) 190 { 191 return GlyphFromCharCode(charcode); 192 } 193 194 CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const; 195 196 FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const; 197 GetCharMap()198 CFX_CharMap* GetCharMap() 199 { 200 return m_pCharMap; 201 } 202 203 CFX_ByteString EncodeString(const CFX_WideString& str) const; 204 205 CFX_WideString DecodeString(const CFX_ByteString& str) const; 206 207 208 209 GetFontBBox(FX_RECT & rect)210 void GetFontBBox(FX_RECT& rect) const 211 { 212 rect = m_FontBBox; 213 } 214 GetTypeAscent()215 int GetTypeAscent() const 216 { 217 return m_Ascent; 218 } 219 GetTypeDescent()220 int GetTypeDescent() const 221 { 222 return m_Descent; 223 } 224 GetItalicAngle()225 int GetItalicAngle() const 226 { 227 return m_ItalicAngle; 228 } 229 GetStemV()230 int GetStemV() const 231 { 232 return m_StemV; 233 } 234 235 int GetStringWidth(const FX_CHAR* pString, int size); 236 237 virtual int GetCharWidthF(FX_DWORD charcode, int level = 0) = 0; 238 239 virtual int GetCharTypeWidth(FX_DWORD charcode); 240 241 virtual void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) = 0; 242 243 244 245 CPDF_Document* m_pDocument; 246 247 class CFX_PathData* LoadGlyphPath(FX_DWORD charcode, int dest_width = 0); 248 249 CFX_Font m_Font; 250 251 protected: 252 explicit CPDF_Font(int fonttype); 253 254 FX_BOOL Initialize(); 255 256 FX_BOOL Load(); 257 258 virtual FX_BOOL _Load() = 0; 259 260 virtual FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const = 0; 261 262 virtual FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const = 0; 263 264 void LoadUnicodeMap(); 265 266 void LoadPDFEncoding(CPDF_Object* pEncoding, int& iBaseEncoding, 267 CFX_ByteString*& pCharNames, FX_BOOL bEmbedded, FX_BOOL bTrueType); 268 269 void LoadFontDescriptor(CPDF_Dictionary*); 270 271 void LoadCharWidths(FX_WORD* pWidths); 272 273 void CheckFontMetrics(); 274 275 CFX_CharMap* m_pCharMap; 276 277 278 279 CFX_ByteString m_BaseFont; 280 281 CPDF_StreamAcc* m_pFontFile; 282 283 CPDF_Dictionary* m_pFontDict; 284 285 CPDF_ToUnicodeMap* m_pToUnicodeMap; 286 287 FX_BOOL m_bToUnicodeLoaded; 288 289 290 291 292 int m_Flags; 293 294 FX_RECT m_FontBBox; 295 296 int m_StemV; 297 298 int m_Ascent; 299 300 int m_Descent; 301 302 int m_ItalicAngle; 303 304 private: 305 const int m_FontType; 306 }; 307 #define PDFFONT_ENCODING_BUILTIN 0 308 #define PDFFONT_ENCODING_WINANSI 1 309 #define PDFFONT_ENCODING_MACROMAN 2 310 #define PDFFONT_ENCODING_MACEXPERT 3 311 #define PDFFONT_ENCODING_STANDARD 4 312 #define PDFFONT_ENCODING_ADOBE_SYMBOL 5 313 #define PDFFONT_ENCODING_ZAPFDINGBATS 6 314 #define PDFFONT_ENCODING_PDFDOC 7 315 #define PDFFONT_ENCODING_MS_SYMBOL 8 316 #define PDFFONT_ENCODING_UNICODE 9 317 class CPDF_FontEncoding 318 { 319 public: 320 321 CPDF_FontEncoding(); 322 323 CPDF_FontEncoding(int PredefinedEncoding); 324 325 void LoadEncoding(CPDF_Object* pEncoding); 326 327 FX_BOOL IsIdentical(CPDF_FontEncoding* pAnother) const; 328 UnicodeFromCharCode(FX_BYTE charcode)329 FX_WCHAR UnicodeFromCharCode(FX_BYTE charcode) const 330 { 331 return m_Unicodes[charcode]; 332 } 333 334 int CharCodeFromUnicode(FX_WCHAR unicode) const; 335 SetUnicode(FX_BYTE charcode,FX_WCHAR unicode)336 void SetUnicode(FX_BYTE charcode, FX_WCHAR unicode) 337 { 338 m_Unicodes[charcode] = unicode; 339 } 340 341 CPDF_Object* Realize(); 342 public: 343 344 FX_WCHAR m_Unicodes[256]; 345 }; 346 class CPDF_SimpleFont : public CPDF_Font 347 { 348 public: 349 explicit CPDF_SimpleFont(int fonttype); 350 ~CPDF_SimpleFont() override; 351 GetEncoding()352 CPDF_FontEncoding* GetEncoding() 353 { 354 return &m_Encoding; 355 } 356 virtual int GetCharWidthF(FX_DWORD charcode, int level = 0); 357 virtual void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0); 358 virtual int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL *pVertGlyph = NULL); 359 virtual FX_BOOL IsUnicodeCompatible() const; 360 protected: 361 362 FX_BOOL LoadCommon(); 363 364 void LoadSubstFont(); 365 366 void LoadFaceMetrics(); 367 368 virtual void LoadGlyphMap() = 0; _UnicodeFromCharCode(FX_DWORD charcode)369 virtual FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const 370 { 371 return m_Encoding.UnicodeFromCharCode((FX_BYTE)charcode); 372 } _CharCodeFromUnicode(FX_WCHAR Unicode)373 virtual FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const 374 { 375 return m_Encoding.CharCodeFromUnicode(Unicode); 376 } 377 378 379 380 CPDF_FontEncoding m_Encoding; 381 382 FX_WORD m_GlyphIndex[256]; 383 FX_WORD m_ExtGID[256]; 384 385 386 387 388 CFX_ByteString* m_pCharNames; 389 390 int m_BaseEncoding; 391 392 393 394 395 FX_WORD m_CharWidth[256]; 396 397 FX_SMALL_RECT m_CharBBox[256]; 398 399 FX_BOOL m_bUseFontWidth; 400 401 void LoadCharMetrics(int charcode); 402 403 }; 404 class CPDF_Type1Font : public CPDF_SimpleFont 405 { 406 public: 407 408 CPDF_Type1Font(); 409 GetBase14Font()410 int GetBase14Font() 411 { 412 return m_Base14Font; 413 } 414 virtual int GlyphFromCharCodeExt(FX_DWORD charcode); 415 protected: 416 virtual FX_BOOL _Load(); 417 418 int m_Base14Font; 419 virtual void LoadGlyphMap(); 420 }; 421 class CPDF_TrueTypeFont : public CPDF_SimpleFont 422 { 423 public: 424 425 CPDF_TrueTypeFont(); 426 protected: 427 virtual FX_BOOL _Load(); 428 virtual void LoadGlyphMap(); 429 }; 430 class CPDF_Type3Char 431 { 432 public: 433 434 CPDF_Type3Char(); 435 436 ~CPDF_Type3Char(); 437 438 FX_BOOL LoadBitmap(CPDF_RenderContext* pContext); 439 440 FX_BOOL m_bColored; 441 442 FX_BOOL m_bPageRequired; 443 444 445 446 CPDF_Form* m_pForm; 447 448 CFX_AffineMatrix m_ImageMatrix; 449 450 CFX_DIBitmap* m_pBitmap; 451 452 453 int m_Width; 454 455 FX_RECT m_BBox; 456 }; 457 class CPDF_Type3Font : public CPDF_SimpleFont 458 { 459 public: 460 CPDF_Type3Font(); 461 ~CPDF_Type3Font() override; SetPageResources(CPDF_Dictionary * pResources)462 void SetPageResources(CPDF_Dictionary* pResources) 463 { 464 m_pPageResources = pResources; 465 } 466 CPDF_Type3Char* LoadChar(FX_DWORD charcode, int level = 0); 467 virtual int GetCharWidthF(FX_DWORD charcode, int level = 0); GetCharTypeWidth(FX_DWORD charcode)468 virtual int GetCharTypeWidth(FX_DWORD charcode) 469 { 470 return GetCharWidthF(charcode); 471 } 472 virtual void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0); GetFontMatrix()473 CFX_AffineMatrix& GetFontMatrix() 474 { 475 return m_FontMatrix; 476 } 477 void CheckType3FontMetrics(); 478 private: 479 virtual FX_BOOL _Load(); LoadGlyphMap()480 virtual void LoadGlyphMap() {} 481 int m_CharWidthL[256]; 482 CPDF_Dictionary* m_pCharProcs; 483 CPDF_Dictionary* m_pPageResources; 484 CPDF_Dictionary* m_pFontResources; 485 CFX_MapPtrToPtr m_CacheMap; 486 CFX_MapPtrToPtr m_DeletedMap; 487 protected: 488 CFX_AffineMatrix m_FontMatrix; 489 }; 490 #define CIDSET_UNKNOWN 0 491 #define CIDSET_GB1 1 492 #define CIDSET_CNS1 2 493 #define CIDSET_JAPAN1 3 494 #define CIDSET_KOREA1 4 495 #define CIDSET_UNICODE 5 496 #define NUMBER_OF_CIDSETS 6 497 498 class CPDF_CIDFont : public CPDF_Font 499 { 500 public: 501 502 CPDF_CIDFont(); 503 504 virtual ~CPDF_CIDFont(); 505 506 FX_BOOL LoadGB2312(); 507 virtual int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL *pVertGlyph = NULL); 508 virtual int GetCharWidthF(FX_DWORD charcode, int level = 0); 509 virtual void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0); 510 FX_WORD CIDFromCharCode(FX_DWORD charcode) const; 511 IsTrueType()512 FX_BOOL IsTrueType() 513 { 514 return !m_bType1; 515 } 516 517 virtual FX_DWORD GetNextChar(FX_LPCSTR pString, int nStrLen, int& offset) const override; 518 virtual int CountChar(FX_LPCSTR pString, int size) const; 519 virtual int AppendChar(FX_LPSTR str, FX_DWORD charcode) const; 520 virtual int GetCharSize(FX_DWORD charcode) const; 521 GetCharset()522 int GetCharset() const 523 { 524 return m_Charset; 525 } 526 527 FX_LPCBYTE GetCIDTransform(FX_WORD CID) const; 528 virtual FX_BOOL IsVertWriting() const; 529 short GetVertWidth(FX_WORD CID) const; 530 void GetVertOrigin(FX_WORD CID, short& vx, short& vy) const; 531 virtual FX_BOOL IsUnicodeCompatible() const; 532 virtual FX_BOOL IsFontStyleFromCharCode(FX_DWORD charcode) const; 533 534 protected: 535 friend class CPDF_Font; 536 virtual FX_BOOL _Load(); 537 virtual FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const; 538 virtual FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const; 539 int GetGlyphIndex(FX_DWORD unicodeb, FX_BOOL *pVertGlyph); 540 541 CPDF_CMap* m_pCMap; 542 CPDF_CMap* m_pAllocatedCMap; 543 CPDF_CID2UnicodeMap* m_pCID2UnicodeMap; 544 int m_Charset; 545 FX_BOOL m_bType1; 546 CPDF_StreamAcc* m_pCIDToGIDMap; 547 FX_BOOL m_bCIDIsGID; 548 FX_WORD m_DefaultWidth; 549 FX_WORD* m_pAnsiWidths; 550 FX_SMALL_RECT m_CharBBox[256]; 551 CFX_DWordArray m_WidthList; 552 short m_DefaultVY; 553 short m_DefaultW1; 554 CFX_DWordArray m_VertMetrics; 555 556 void LoadMetricsArray(CPDF_Array* pArray, CFX_DWordArray& result, int nElements); 557 void LoadSubstFont(); 558 559 FX_BOOL m_bAdobeCourierStd; 560 CFX_CTTGSUBTable* m_pTTGSUBTable; 561 }; 562 563 #define PDFCS_DEVICEGRAY 1 564 #define PDFCS_DEVICERGB 2 565 #define PDFCS_DEVICECMYK 3 566 #define PDFCS_CALGRAY 4 567 #define PDFCS_CALRGB 5 568 #define PDFCS_LAB 6 569 #define PDFCS_ICCBASED 7 570 #define PDFCS_SEPARATION 8 571 #define PDFCS_DEVICEN 9 572 #define PDFCS_INDEXED 10 573 #define PDFCS_PATTERN 11 574 575 class CPDF_ColorSpace 576 { 577 public: 578 579 static CPDF_ColorSpace* GetStockCS(int Family); 580 581 static CPDF_ColorSpace* Load(CPDF_Document* pDoc, CPDF_Object* pCSObj); 582 583 void ReleaseCS(); 584 585 int GetBufSize() const; 586 587 FX_FLOAT* CreateBuf(); 588 589 void GetDefaultColor(FX_FLOAT* buf) const; 590 CountComponents()591 int CountComponents() const 592 { 593 return m_nComponents; 594 } 595 GetFamily()596 int GetFamily() const 597 { 598 return m_Family; 599 } 600 GetDefaultValue(int iComponent,FX_FLOAT & value,FX_FLOAT & min,FX_FLOAT & max)601 virtual void GetDefaultValue(int iComponent, FX_FLOAT& value, FX_FLOAT& min, FX_FLOAT& max) const 602 { 603 value = 0; 604 min = 0; 605 max = 1.0f; 606 } 607 608 FX_BOOL sRGB() const; 609 610 611 612 virtual FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const = 0; 613 SetRGB(FX_FLOAT * pBuf,FX_FLOAT R,FX_FLOAT G,FX_FLOAT B)614 virtual FX_BOOL SetRGB(FX_FLOAT* pBuf, FX_FLOAT R, FX_FLOAT G, FX_FLOAT B) const 615 { 616 return FALSE; 617 } 618 619 620 621 622 FX_BOOL GetCMYK(FX_FLOAT* pBuf, FX_FLOAT& c, FX_FLOAT& m, FX_FLOAT& y, FX_FLOAT& k) const; 623 624 FX_BOOL SetCMYK(FX_FLOAT* pBuf, FX_FLOAT c, FX_FLOAT m, FX_FLOAT y, FX_FLOAT k) const; 625 626 627 virtual void TranslateImageLine(FX_LPBYTE dest_buf, FX_LPCBYTE src_buf, int pixels, 628 int image_width, int image_height, FX_BOOL bTransMask = FALSE) const; 629 GetArray()630 CPDF_Array*& GetArray() 631 { 632 return m_pArray; 633 } 634 635 int GetMaxIndex() const; 636 GetBaseCS()637 virtual CPDF_ColorSpace* GetBaseCS() const 638 { 639 return NULL; 640 } 641 642 virtual void EnableStdConversion(FX_BOOL bEnabled); 643 CPDF_Document* m_pDocument; 644 protected: 645 646 CPDF_ColorSpace(); 647 ~CPDF_ColorSpace()648 virtual ~CPDF_ColorSpace() {} v_Load(CPDF_Document * pDoc,CPDF_Array * pArray)649 virtual FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) 650 { 651 return TRUE; 652 } v_GetCMYK(FX_FLOAT * pBuf,FX_FLOAT & c,FX_FLOAT & m,FX_FLOAT & y,FX_FLOAT & k)653 virtual FX_BOOL v_GetCMYK(FX_FLOAT* pBuf, FX_FLOAT& c, FX_FLOAT& m, FX_FLOAT& y, FX_FLOAT& k) const 654 { 655 return FALSE; 656 } v_SetCMYK(FX_FLOAT * pBuf,FX_FLOAT c,FX_FLOAT m,FX_FLOAT y,FX_FLOAT k)657 virtual FX_BOOL v_SetCMYK(FX_FLOAT* pBuf, FX_FLOAT c, FX_FLOAT m, FX_FLOAT y, FX_FLOAT k) const 658 { 659 return FALSE; 660 } 661 662 int m_Family; 663 664 int m_nComponents; 665 666 CPDF_Array* m_pArray; 667 668 FX_DWORD m_dwStdConversion; 669 }; 670 class CPDF_Color 671 { 672 public: 673 CPDF_Color()674 CPDF_Color() :m_pCS(NULL), m_pBuffer(NULL) 675 { 676 } 677 678 CPDF_Color(int family); 679 680 ~CPDF_Color(); 681 IsNull()682 FX_BOOL IsNull() const 683 { 684 return m_pBuffer == NULL; 685 } 686 687 FX_BOOL IsEqual(const CPDF_Color& other) const; 688 IsPattern()689 FX_BOOL IsPattern() const 690 { 691 return m_pCS && m_pCS->GetFamily() == PDFCS_PATTERN; 692 } 693 694 void Copy(const CPDF_Color* pSrc); 695 696 void SetColorSpace(CPDF_ColorSpace* pCS); 697 698 void SetValue(FX_FLOAT* comp); 699 700 void SetValue(CPDF_Pattern* pPattern, FX_FLOAT* comp, int ncomps); 701 702 FX_BOOL GetRGB(int& R, int& G, int& B) const; 703 704 CPDF_Pattern* GetPattern() const; 705 706 CPDF_ColorSpace* GetPatternCS() const; 707 708 FX_FLOAT* GetPatternColor() const; 709 710 CPDF_ColorSpace* m_pCS; 711 712 protected: 713 void ReleaseBuffer(); 714 void ReleaseColorSpace(); 715 FX_FLOAT* m_pBuffer; 716 }; 717 #define PATTERN_TILING 1 718 #define PATTERN_SHADING 2 719 class CPDF_Pattern 720 { 721 public: 722 723 virtual ~CPDF_Pattern(); SetForceClear(FX_BOOL bForceClear)724 void SetForceClear(FX_BOOL bForceClear) { m_bForceClear = bForceClear; } 725 726 CPDF_Object* m_pPatternObj; 727 728 int m_PatternType; 729 730 CFX_AffineMatrix m_Pattern2Form; 731 CFX_AffineMatrix m_ParentMatrix; 732 733 CPDF_Document* m_pDocument; 734 735 protected: 736 CPDF_Pattern(const CFX_AffineMatrix* pParentMatrix); 737 FX_BOOL m_bForceClear; 738 }; 739 740 class CPDF_TilingPattern : public CPDF_Pattern 741 { 742 public: 743 744 CPDF_TilingPattern(CPDF_Document* pDoc, CPDF_Object* pPatternObj, const CFX_AffineMatrix* parentMatrix); 745 746 virtual ~CPDF_TilingPattern(); 747 748 FX_BOOL Load(); 749 750 751 752 FX_BOOL m_bColored; 753 754 CFX_FloatRect m_BBox; 755 756 FX_FLOAT m_XStep; 757 758 FX_FLOAT m_YStep; 759 760 761 762 CPDF_Form* m_pForm; 763 }; 764 class CPDF_ShadingPattern : public CPDF_Pattern 765 { 766 public: 767 768 CPDF_ShadingPattern(CPDF_Document* pDoc, CPDF_Object* pPatternObj, FX_BOOL bShading, const CFX_AffineMatrix* parentMatrix); 769 770 virtual ~CPDF_ShadingPattern(); 771 772 CPDF_Object* m_pShadingObj; 773 774 FX_BOOL m_bShadingObj; 775 776 FX_BOOL Load(); 777 778 FX_BOOL Reload(); 779 780 int m_ShadingType; 781 782 CPDF_ColorSpace* m_pCS; // Still keep m_pCS as some CPDF_ColorSpace (name object) are not managed as counted objects. Refer to CPDF_DocPageData::GetColorSpace. 783 784 CPDF_CountedColorSpace* m_pCountedCS; 785 786 CPDF_Function* m_pFunctions[4]; 787 788 int m_nFuncs; 789 protected: 790 void Clear(); 791 }; 792 struct CPDF_MeshVertex { 793 FX_FLOAT x, y; 794 FX_FLOAT r, g, b; 795 }; 796 class CPDF_MeshStream 797 { 798 public: 799 800 FX_BOOL Load(CPDF_Stream* pShadingStream, CPDF_Function** pFuncs, int nFuncs, CPDF_ColorSpace* pCS); 801 802 FX_DWORD GetFlag(); 803 804 void GetCoords(FX_FLOAT& x, FX_FLOAT& y); 805 806 void GetColor(FX_FLOAT& r, FX_FLOAT& g, FX_FLOAT& b); 807 808 FX_DWORD GetVertex(CPDF_MeshVertex& vertex, CFX_AffineMatrix* pObject2Bitmap); 809 810 FX_BOOL GetVertexRow(CPDF_MeshVertex* vertex, int count, CFX_AffineMatrix* pObject2Bitmap); 811 CPDF_Function** m_pFuncs; 812 CPDF_ColorSpace* m_pCS; 813 FX_DWORD m_nFuncs, m_nCoordBits, m_nCompBits, m_nFlagBits, m_nComps; 814 FX_DWORD m_CoordMax, m_CompMax; 815 FX_FLOAT m_xmin, m_xmax, m_ymin, m_ymax; 816 FX_FLOAT m_ColorMin[8], m_ColorMax[8]; 817 CPDF_StreamAcc m_Stream; 818 CFX_BitStream m_BitStream; 819 }; 820 #define PDF_IMAGE_NO_COMPRESS 0x0000 821 #define PDF_IMAGE_LOSSY_COMPRESS 0x0001 822 #define PDF_IMAGE_LOSSLESS_COMPRESS 0x0002 823 #define PDF_IMAGE_MASK_LOSSY_COMPRESS 0x0004 824 #define PDF_IMAGE_MASK_LOSSLESS_COMPRESS 0x0008 825 class CPDF_ImageSetParam 826 { 827 public: CPDF_ImageSetParam()828 CPDF_ImageSetParam() 829 : pMatteColor(NULL) 830 , nQuality(80) 831 { 832 } 833 FX_ARGB* pMatteColor; 834 FX_INT32 nQuality; 835 }; 836 class CPDF_Image 837 { 838 public: 839 840 CPDF_Image(CPDF_Document* pDoc); 841 842 ~CPDF_Image(); 843 844 FX_BOOL LoadImageF(CPDF_Stream* pImageStream, FX_BOOL bInline); 845 846 void Release(); 847 848 CPDF_Image* Clone(); 849 IsInline()850 FX_BOOL IsInline() 851 { 852 return m_bInline; 853 } 854 SetInlineDict(CPDF_Dictionary * pDict)855 void SetInlineDict(CPDF_Dictionary* pDict) 856 { 857 m_pInlineDict = pDict; 858 } 859 GetInlineDict()860 CPDF_Dictionary* GetInlineDict() const 861 { 862 return m_pInlineDict; 863 } 864 GetStream()865 CPDF_Stream* GetStream() const 866 { 867 return m_pStream; 868 } 869 GetDict()870 CPDF_Dictionary* GetDict() const 871 { 872 return m_pStream? m_pStream->GetDict(): NULL; 873 } 874 GetOC()875 CPDF_Dictionary* GetOC() const 876 { 877 return m_pOC; 878 } 879 GetDocument()880 CPDF_Document* GetDocument() const 881 { 882 return m_pDocument; 883 } 884 885 886 GetPixelHeight()887 FX_INT32 GetPixelHeight() const 888 { 889 return m_Height; 890 } 891 GetPixelWidth()892 FX_INT32 GetPixelWidth() const 893 { 894 return m_Width; 895 } 896 897 IsMask()898 FX_BOOL IsMask() const 899 { 900 return m_bIsMask; 901 } 902 IsInterpol()903 FX_BOOL IsInterpol() const 904 { 905 return m_bInterpolate; 906 } 907 908 CFX_DIBSource* LoadDIBSource(CFX_DIBSource** ppMask = NULL, FX_DWORD* pMatteColor = NULL, FX_BOOL bStdCS = FALSE, FX_DWORD GroupFamily = 0, FX_BOOL bLoadMask = FALSE) const; 909 910 911 912 void SetImage(const CFX_DIBitmap* pDIBitmap, FX_INT32 iCompress, IFX_FileWrite *pFileWrite = NULL, IFX_FileRead *pFileRead = NULL, const CFX_DIBitmap* pMask = NULL, const CPDF_ImageSetParam* pParam = NULL); 913 914 void SetJpegImage(FX_BYTE* pImageData, FX_DWORD size); 915 916 void SetJpegImage(IFX_FileRead *pFile); 917 918 void ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pDIBitmap); 919 920 public: 921 FX_BOOL StartLoadDIBSource(CPDF_Dictionary* pFormResource, CPDF_Dictionary* pPageResource, FX_BOOL bStdCS = FALSE, FX_DWORD GroupFamily = 0, FX_BOOL bLoadMask = FALSE); 922 FX_BOOL Continue(IFX_Pause* pPause); 923 CFX_DIBSource* DetachBitmap(); 924 CFX_DIBSource* DetachMask(); 925 CFX_DIBSource* m_pDIBSource; 926 CFX_DIBSource* m_pMask; 927 FX_DWORD m_MatteColor; 928 private: 929 930 CPDF_Stream* m_pStream; 931 FX_BOOL m_bInline; 932 CPDF_Dictionary* m_pInlineDict; 933 934 FX_INT32 m_Height; 935 936 FX_INT32 m_Width; 937 938 FX_BOOL m_bIsMask; 939 940 FX_BOOL m_bInterpolate; 941 942 CPDF_Document* m_pDocument; 943 944 CPDF_Dictionary* m_pOC; 945 CPDF_Dictionary* InitJPEG(FX_LPBYTE pData, FX_DWORD size); 946 }; 947 948 #endif // CORE_INCLUDE_FPDFAPI_FPDF_RESOURCE_H_ 949