1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
31 #include <vcl/fontsubset.hxx>
33 #include <tools/debug.hxx>
35 // ====================================================================
37 FontSubsetInfo::FontSubsetInfo()
41 , m_nFontType( FontSubsetInfo::NO_FONT
)
42 , mpInFontBytes( NULL
)
44 , meInFontType( FontSubsetInfo::NO_FONT
)
48 // --------------------------------------------------------------------
50 FontSubsetInfo::~FontSubsetInfo()
53 // --------------------------------------------------------------------
55 // prepare subsetting for fonts where the input font file is mapped
56 bool FontSubsetInfo::LoadFont(
57 FontSubsetInfo::FontType eInFontType
,
58 const unsigned char* pInFontBytes
, int nInByteLength
)
60 DBG_ASSERT( (mpSftTTFont
== NULL
), "Subset from SFT and from mapped font-file requested");
61 meInFontType
= eInFontType
;
62 mpInFontBytes
= pInFontBytes
;
63 mnInByteLength
= nInByteLength
;
64 return (mnInByteLength
> 0);
67 // --------------------------------------------------------------------
69 // prepare subsetting for fonts that are known to the SFT-parser
70 bool FontSubsetInfo::LoadFont( vcl::_TrueTypeFont
* pSftTTFont
)
72 DBG_ASSERT( (mpInFontBytes
== NULL
), "Subset from SFT and from mapped font-file requested");
73 mpSftTTFont
= pSftTTFont
;
74 meInFontType
= ANY_SFNT
;
75 return (mpSftTTFont
== NULL
);
78 // --------------------------------------------------------------------
80 bool FontSubsetInfo::CreateFontSubset(
82 FILE* pOutFile
, const char* pReqFontName
,
83 const long* pReqGlyphIds
, const sal_uInt8
* pReqEncodedIds
, int nReqGlyphCount
,
84 sal_Int32
* pOutGlyphWidths
)
86 // prepare request details needed by all underlying subsetters
87 mnReqFontTypeMask
= nReqFontTypeMask
;
89 mpReqFontName
= pReqFontName
;
90 mpReqGlyphIds
= pReqGlyphIds
;
91 mpReqEncodedIds
= pReqEncodedIds
;
92 mnReqGlyphCount
= nReqGlyphCount
;
94 // TODO: move the glyphid/encid/notdef reshuffling from the callers to here
96 // dispatch to underlying subsetters
99 // TODO: better match available input-type to possible subset-types
100 switch( meInFontType
) {
104 bOK
= CreateFontSubsetFromSfnt( pOutGlyphWidths
);
107 bOK
= CreateFontSubsetFromCff( pOutGlyphWidths
);
112 bOK
= CreateFontSubsetFromType1( pOutGlyphWidths
);
118 DBG_ERROR( "unhandled type in CreateFontSubset()");
125 // --------------------------------------------------------------------
127 // TODO: move function to sft.cxx to replace dummy implementation
128 bool FontSubsetInfo::CreateFontSubsetFromSfnt( sal_Int32
* pOutGlyphWidths
)
130 // handle SFNT_CFF fonts
132 const sal_uInt8
* pCffBytes
= NULL
;
133 if( GetSfntTable( mpSftTTFont
, O_CFF
, &pCffBytes
, &nCffLength
))
135 LoadFont( CFF_FONT
, pCffBytes
, nCffLength
);
136 const bool bOK
= CreateFontSubsetFromCff( pOutGlyphWidths
);
140 // handle SFNT_TTF fonts
141 // by forwarding the subset request to AG's sft subsetter
142 #if 1 // TODO: remove conversion tp 16bit glyphids when sft-subsetter has been updated
143 sal_uInt16 aShortGlyphIds
[256];
144 for( int i
= 0; i
< mnReqGlyphCount
; ++i
)
145 aShortGlyphIds
[i
] = (sal_uInt16
)mpReqGlyphIds
[i
];
146 // remove const_cast when sft-subsetter is const-correct
147 sal_uInt8
* pEncArray
= const_cast<sal_uInt8
*>( mpReqEncodedIds
);
149 int nSFTErr
= vcl::SF_BADARG
;
150 if( (mnReqFontTypeMask
& TYPE42_FONT
) != 0 )
152 nSFTErr
= CreateT42FromTTGlyphs( mpSftTTFont
, mpOutFile
, mpReqFontName
,
153 aShortGlyphIds
, pEncArray
, mnReqGlyphCount
);
155 else if( (mnReqFontTypeMask
& TYPE3_FONT
) != 0 )
157 nSFTErr
= CreateT3FromTTGlyphs( mpSftTTFont
, mpOutFile
, mpReqFontName
,
158 aShortGlyphIds
, pEncArray
, mnReqGlyphCount
,
159 0 /* 0 = horizontal, 1 = vertical */ );
161 else if( (mnReqFontTypeMask
& SFNT_TTF
) != 0 )
163 // TODO: use CreateTTFromTTGlyphs()
164 // TODO: move functionality from callers here
167 return (nSFTErr
!= vcl::SF_OK
);
170 // --------------------------------------------------------------------
172 // TODO: replace dummy implementation
173 bool FontSubsetInfo::CreateFontSubsetFromType1( sal_Int32
* pOutGlyphWidths
)
176 // TODO: replace dummy implementation when someone needs this
178 (void)pOutGlyphWidths
;
179 fprintf(stderr
,"CreateFontSubsetFromType1: replace dummy implementation\n");
184 // ====================================================================