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