xref: /AOO41X/main/vcl/inc/fontsubset.hxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
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 "vcl/dllapi.h"
32 
33 namespace vcl { struct _TrueTypeFont; } // SFT's idea of a TTF font
34 
35 class VCL_DLLPUBLIC FontSubsetInfo
36 {
37 public:
38     explicit    FontSubsetInfo( void );
39     virtual     ~FontSubsetInfo( void );
40 
41     enum FontType {
42         NO_FONT     = 0,
43         SFNT_TTF    = 1<<1,     // SFNT container with TrueType glyphs
44         SFNT_CFF    = 1<<2,     // SFNT container with CFF-container
45         TYPE1_PFA   = 1<<3,     // PSType1 Postscript Font Ascii
46         TYPE1_PFB   = 1<<4,     // PSType1 Postscript Font Binary
47         CFF_FONT    = 1<<5,     // CFF-container with PSType2 glyphs
48         TYPE3_FONT  = 1<<6,     // PSType3 Postscript font
49         TYPE42_FONT = 1<<7,     // PSType42 wrapper for an SFNT_TTF
50         ANY_SFNT    = SFNT_TTF | SFNT_CFF,
51         ANY_TYPE1   = TYPE1_PFA | TYPE1_PFB,
52         ANY_FONT    = 0xFF
53     };
54 
55     bool        LoadFont( FontType eInFontType,
56                     const unsigned char* pFontBytes, int nByteLength );
57     bool        LoadFont( vcl::_TrueTypeFont* pSftTrueTypeFont );
58 
59     bool        CreateFontSubset( int nOutFontTypeMask,
60                     FILE* pOutFile, const char* pOutFontName,
61                     const long* pReqGlyphIds, const sal_uInt8* pEncodedIds,
62                     int nReqGlyphCount, sal_Int32* pOutGlyphWidths = NULL );
63 
64 public: // TODO: make subsetter results private and provide accessor methods instead
65     // subsetter-provided subset details needed by e.g. Postscript or PDF
66     String      m_aPSName;
67     int         m_nAscent; // all metrics in PS font units
68     int         m_nDescent;
69     int         m_nCapHeight;
70     Rectangle   m_aFontBBox;
71     FontType    m_nFontType;    // font-type of subset result
72 
73 private:
74     // input-font-specific details
75     unsigned const char*    mpInFontBytes;
76     int                     mnInByteLength;
77     FontType                meInFontType;   // allowed mask of input font-types
78     vcl::_TrueTypeFont*     mpSftTTFont;
79 
80     // subset-request details
81     int                     mnReqFontTypeMask;  // allowed subset-target font types
82     FILE*                   mpOutFile;
83     const char*             mpReqFontName;
84     const long*             mpReqGlyphIds;
85     const sal_uInt8*        mpReqEncodedIds;
86     int                     mnReqGlyphCount;
87 
88 protected:
89     bool    CreateFontSubsetFromCff( sal_Int32* pOutGlyphWidths = NULL );
90     bool    CreateFontSubsetFromSfnt( sal_Int32* pOutGlyphWidths = NULL );
91     bool    CreateFontSubsetFromType1( sal_Int32* pOutGlyphWidths = NULL );
92 };
93 
94 #endif // _SV_FONTSUBSET_HXX
95 
96