xref: /trunk/main/vcl/inc/fontsubset.hxx (revision 248a599f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SV_FONTSUBSET_HXX
25 #define _SV_FONTSUBSET_HXX
26 
27 #include <tools/gen.hxx>
28 #include <tools/string.hxx>
29 #include <cstdio>
30 
31 #include "salglyphid.hxx"
32 #include "vcl/dllapi.h"
33 
34 namespace vcl { struct _TrueTypeFont; } // SFT's idea of a TTF font
35 
36 class VCL_DLLPUBLIC FontSubsetInfo
37 {
38 public:
39 	explicit	FontSubsetInfo( void );
40 	virtual		~FontSubsetInfo( void );
41 
42 	enum FontType {
43 		NO_FONT		= 0,
44 		SFNT_TTF	= 1<<1,		// SFNT container with TrueType glyphs
45 		SFNT_CFF	= 1<<2,		// SFNT container with CFF-container
46 		TYPE1_PFA	= 1<<3,		// PSType1 Postscript Font Ascii
47 		TYPE1_PFB	= 1<<4,		// PSType1 Postscript Font Binary
48 		CFF_FONT	= 1<<5,		// CFF-container with PSType2 glyphs
49 		TYPE3_FONT	= 1<<6,		// PSType3 Postscript font
50 		TYPE42_FONT	= 1<<7,		// PSType42 wrapper for an SFNT_TTF
51 		ANY_SFNT	= SFNT_TTF | SFNT_CFF,
52 		ANY_TYPE1	= TYPE1_PFA | TYPE1_PFB,
53 		ANY_FONT	= 0xFF
54 	};
55 
56 	bool		LoadFont( FontType eInFontType,
57 					const unsigned char* pFontBytes, int nByteLength );
58 	bool		LoadFont( vcl::_TrueTypeFont* pSftTrueTypeFont );
59 
60 	bool		CreateFontSubset( int nOutFontTypeMask,
61 					FILE* pOutFile, const char* pOutFontName,
62 					const sal_GlyphId* pGlyphIds, const sal_uInt8* pEncodedIds,
63 					int nReqGlyphCount, sal_Int32* pOutGlyphWidths = NULL );
64 
65 public: // TODO: make subsetter results private and provide accessor methods instead
66 	// subsetter-provided subset details needed by e.g. Postscript or PDF
67 	String		m_aPSName;
68 	int			m_nAscent; // all metrics in PS font units
69 	int			m_nDescent;
70 	int			m_nCapHeight;
71 	Rectangle	m_aFontBBox;
72 	FontType	m_nFontType;	// font-type of subset result
73 
74 private:
75 	// input-font-specific details
76 	unsigned const char*	mpInFontBytes;
77 	int						mnInByteLength;
78 	FontType				meInFontType;	// allowed mask of input font-types
79 	vcl::_TrueTypeFont*		mpSftTTFont;
80 
81 	// subset-request details
82 	int						mnReqFontTypeMask;	// allowed subset-target font types
83 	FILE*					mpOutFile;
84 	const char*				mpReqFontName;
85 	const sal_GlyphId*		mpReqGlyphIds;
86 	const sal_uInt8*		mpReqEncodedIds;
87 	int						mnReqGlyphCount;
88 
89 protected:
90 	bool	CreateFontSubsetFromCff( sal_Int32* pOutGlyphWidths = NULL );
91 	bool	CreateFontSubsetFromSfnt( sal_Int32* pOutGlyphWidths = NULL );
92 	bool	CreateFontSubsetFromType1( sal_Int32* pOutGlyphWidths = NULL );
93 };
94 
95 #endif // _SV_FONTSUBSET_HXX
96 
97