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