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