1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/debug.hxx>
22 #include <osl/diagnose.h>
24 #include <fontsubset.hxx>
27 FontSubsetInfo::FontSubsetInfo()
31 , m_nFontType( FontSubsetInfo::NO_FONT
)
32 , mpInFontBytes( nullptr)
34 , meInFontType( FontSubsetInfo::NO_FONT
)
35 , mpSftTTFont( nullptr)
36 , mnReqFontTypeMask(0)
38 , mpReqFontName(nullptr)
39 , mpReqGlyphIds(nullptr)
40 , mpReqEncodedIds(nullptr)
45 FontSubsetInfo::~FontSubsetInfo()
49 // prepare subsetting for fonts where the input font file is mapped
50 bool FontSubsetInfo::LoadFont(
51 FontSubsetInfo::FontType eInFontType
,
52 const unsigned char* pInFontBytes
, int nInByteLength
)
54 SAL_WARN_IF( (mpSftTTFont
!= nullptr), "vcl", "Subset from SFT and from mapped font-file requested");
55 meInFontType
= eInFontType
;
56 mpInFontBytes
= pInFontBytes
;
57 mnInByteLength
= nInByteLength
;
58 return (mnInByteLength
> 0);
61 // prepare subsetting for fonts that are known to the SFT-parser
62 bool FontSubsetInfo::LoadFont( vcl::TrueTypeFont
* pSftTTFont
)
64 SAL_WARN_IF( (mpInFontBytes
!= nullptr), "vcl", "Subset from SFT and from mapped font-file requested");
65 mpSftTTFont
= pSftTTFont
;
66 meInFontType
= ANY_SFNT
;
67 return (mpSftTTFont
== nullptr);
70 bool FontSubsetInfo::CreateFontSubset(
72 FILE* pOutFile
, const char* pReqFontName
,
73 const sal_GlyphId
* pReqGlyphIds
, const sal_uInt8
* pReqEncodedIds
, int nReqGlyphCount
,
74 sal_Int32
* pOutGlyphWidths
)
76 // prepare request details needed by all underlying subsetters
77 mnReqFontTypeMask
= nReqFontTypeMask
;
79 mpReqFontName
= pReqFontName
;
80 mpReqGlyphIds
= pReqGlyphIds
;
81 mpReqEncodedIds
= pReqEncodedIds
;
82 mnReqGlyphCount
= nReqGlyphCount
;
84 // TODO: move the glyphid/encid/notdef reshuffling from the callers to here
86 // dispatch to underlying subsetters
89 // TODO: better match available input-type to possible subset-types
90 switch( meInFontType
) {
94 bOK
= CreateFontSubsetFromSfnt( pOutGlyphWidths
);
97 bOK
= CreateFontSubsetFromCff( pOutGlyphWidths
);
102 bOK
= CreateFontSubsetFromType1( pOutGlyphWidths
);
108 OSL_FAIL( "unhandled type in CreateFontSubset()");
115 // TODO: move function to sft.cxx to replace dummy implementation
116 bool FontSubsetInfo::CreateFontSubsetFromSfnt( sal_Int32
* pOutGlyphWidths
)
118 // handle SFNT_CFF fonts
120 const sal_uInt8
* pCffBytes
= nullptr;
121 if( GetSfntTable( mpSftTTFont
, O_CFF
, &pCffBytes
, &nCffLength
))
123 LoadFont( CFF_FONT
, pCffBytes
, nCffLength
);
124 const bool bOK
= CreateFontSubsetFromCff( pOutGlyphWidths
);
128 // handle SFNT_TTF fonts
129 // by forwarding the subset request to AG's sft subsetter
130 #if 1 // TODO: remove conversion tp 16bit glyphids when sft-subsetter has been updated
131 sal_uInt16 aShortGlyphIds
[256];
132 for( int i
= 0; i
< mnReqGlyphCount
; ++i
)
133 aShortGlyphIds
[i
] = (sal_uInt16
)mpReqGlyphIds
[i
];
134 // remove const_cast when sft-subsetter is const-correct
135 sal_uInt8
* pEncArray
= const_cast<sal_uInt8
*>( mpReqEncodedIds
);
137 int nSFTErr
= vcl::SF_BADARG
;
138 if( (mnReqFontTypeMask
& TYPE42_FONT
) != 0 )
140 nSFTErr
= CreateT42FromTTGlyphs( mpSftTTFont
, mpOutFile
, mpReqFontName
,
141 aShortGlyphIds
, pEncArray
, mnReqGlyphCount
);
143 else if( (mnReqFontTypeMask
& TYPE3_FONT
) != 0 )
145 nSFTErr
= CreateT3FromTTGlyphs( mpSftTTFont
, mpOutFile
, mpReqFontName
,
146 aShortGlyphIds
, pEncArray
, mnReqGlyphCount
,
147 0 /* 0 = horizontal, 1 = vertical */ );
149 else if( (mnReqFontTypeMask
& SFNT_TTF
) != 0 )
151 // TODO: use CreateTTFromTTGlyphs()
152 // TODO: move functionality from callers here
155 return (nSFTErr
!= vcl::SF_OK
);
158 // TODO: replace dummy implementation
159 bool FontSubsetInfo::CreateFontSubsetFromType1( sal_Int32
* pOutGlyphWidths
)
161 (void)pOutGlyphWidths
;
162 fprintf(stderr
,"CreateFontSubsetFromType1: replace dummy implementation\n");
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */