LibreOffice Module vcl (master) 1
fontsubset.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <osl/diagnose.h>
22#include <sal/log.hxx>
23
24#include <fontsubset.hxx>
25#include <sft.hxx>
26
28 : m_nAscent( 0)
29 , m_nDescent( 0)
30 , m_nCapHeight( 0)
31 , m_nFontType( FontType::NO_FONT)
32 , m_bFilled(false)
33 , mpInFontBytes( nullptr)
34 , mnInByteLength( 0)
35 , meInFontType( FontType::NO_FONT)
36 , mpSftTTFont( nullptr)
37 , mnReqFontTypeMask( FontType::NO_FONT )
38 , mpOutFile(nullptr)
39 , mpReqFontName(nullptr)
40 , mpReqGlyphIds(nullptr)
41 , mpReqEncodedIds(nullptr)
42 , mnReqGlyphCount(0)
43{
44}
45
47{
48}
49
50// prepare subsetting for fonts where the input font file is mapped
52 FontType eInFontType,
53 const unsigned char* pInFontBytes, int nInByteLength)
54{
55 SAL_WARN_IF( (mpSftTTFont != nullptr), "vcl", "Subset from SFT and from mapped font-file requested");
56 meInFontType = eInFontType;
57 mpInFontBytes = pInFontBytes;
58 mnInByteLength = nInByteLength;
59}
60
61// prepare subsetting for fonts that are known to the SFT-parser
63{
64 SAL_WARN_IF( (mpInFontBytes != nullptr), "vcl", "Subset from SFT and from mapped font-file requested");
65 mpSftTTFont = pSftTTFont;
67}
68
70 FontType nReqFontTypeMask,
71 SvStream* pOutFile, const char* pReqFontName,
72 const sal_GlyphId* pReqGlyphIds, const sal_uInt8* pReqEncodedIds, int nReqGlyphCount)
73{
74 // prepare request details needed by all underlying subsetters
75 mnReqFontTypeMask = nReqFontTypeMask;
76 mpOutFile = pOutFile;
77 mpReqFontName = pReqFontName;
78 mpReqGlyphIds = pReqGlyphIds;
79 mpReqEncodedIds = pReqEncodedIds;
80 mnReqGlyphCount = nReqGlyphCount;
81
82 // TODO: move the glyphid/encid/notdef reshuffling from the callers to here
83
84 // dispatch to underlying subsetters
85 bool bOK = false;
86
87 // TODO: better match available input-type to possible subset-types
88 switch( meInFontType) {
93 break;
96 break;
101 default:
102 OSL_FAIL( "unhandled type in CreateFontSubset()");
103 break;
104 }
105
106 return bOK;
107}
108
109// TODO: move function to sft.cxx to replace dummy implementation
111{
112 // handle SFNT_CFF fonts
113 sal_uInt32 nCffLength = 0;
114 const sal_uInt8* pCffBytes = mpSftTTFont->table(vcl::O_CFF, nCffLength);
115 if (pCffBytes)
116 {
117 LoadFont( FontType::CFF_FONT, pCffBytes, nCffLength);
118 const bool bOK = CreateFontSubsetFromCff();
119 return bOK;
120 }
121
122 // handle SFNT_TTF fonts
123 // by forwarding the subset request to AG's sft subsetter
124#if 1 // TODO: remove conversion tp 16bit glyphids when sft-subsetter has been updated
125 std::vector<sal_uInt16> aShortGlyphIds;
126 aShortGlyphIds.reserve(mnReqGlyphCount);
127 for (int i = 0; i < mnReqGlyphCount; ++i)
128 aShortGlyphIds.push_back(static_cast<sal_uInt16>(mpReqGlyphIds[i]));
129 // remove const_cast when sft-subsetter is const-correct
130 sal_uInt8* pEncArray = const_cast<sal_uInt8*>( mpReqEncodedIds );
131#endif
134 {
136 aShortGlyphIds.data(), pEncArray, mnReqGlyphCount );
137 }
139 {
141 aShortGlyphIds.data(), pEncArray, mnReqGlyphCount,
142 0 /* 0 = horizontal, 1 = vertical */ );
143 }
145 {
146 // TODO: use CreateTTFromTTGlyphs()
147 // TODO: move functionality from callers here
148 }
149
150 return (nSFTErr != vcl::SFErrCodes::Ok);
151}
152
153/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvStream * mpOutFile
Definition: fontsubset.hxx:84
const char * mpReqFontName
Definition: fontsubset.hxx:85
unsigned const char * mpInFontBytes
Definition: fontsubset.hxx:77
const sal_GlyphId * mpReqGlyphIds
Definition: fontsubset.hxx:86
bool CreateFontSubsetFromCff()
Definition: cff.cxx:2607
bool CreateFontSubsetFromSfnt()
Definition: fontsubset.cxx:110
void LoadFont(FontType eInFontType, const unsigned char *pFontBytes, int nByteLength)
Definition: fontsubset.cxx:51
vcl::TrueTypeFont * mpSftTTFont
Definition: fontsubset.hxx:80
bool CreateFontSubset(FontType nOutFontTypeMask, SvStream *pOutFile, const char *pOutFontName, const sal_GlyphId *pGlyphIds, const sal_uInt8 *pEncodedIds, int nReqGlyphCount)
Definition: fontsubset.cxx:69
const sal_uInt8 * mpReqEncodedIds
Definition: fontsubset.hxx:87
FontType mnReqFontTypeMask
allowed subset-target font types
Definition: fontsubset.hxx:83
FontType meInFontType
allowed mask of input font-types
Definition: fontsubset.hxx:79
const sal_uInt8 * table(sal_uInt32 ord, sal_uInt32 &size) const override
Definition: sft.hxx:752
FontType
Definition: fontsubset.hxx:34
@ TYPE1_PFB
PSType1 Postscript Font Binary.
@ CFF_FONT
CFF-container with PSType2 glyphs.
@ TYPE1_PFA
PSType1 Postscript Font Ascii.
@ TYPE3_FONT
PSType3 Postscript font.
@ TYPE42_FONT
PSType42 wrapper for an SFNT_TTF.
@ SFNT_CFF
SFNT container with CFF-container.
@ SFNT_TTF
SFNT container with TrueType glyphs.
uint32_t sal_GlyphId
Definition: glyphid.hxx:24
SFErrCodes CreateT42FromTTGlyphs(TrueTypeFont *ttf, SvStream *outf, const char *psname, sal_uInt16 const *glyphArray, sal_uInt8 *encoding, int nGlyphs)
Generates a new PostScript Type42 font and dumps it to outf file.
Definition: sft.cxx:2087
SFErrCodes CreateT3FromTTGlyphs(TrueTypeFont *ttf, SvStream *outf, const char *fname, sal_uInt16 const *glyphArray, sal_uInt8 *encoding, int nGlyphs, int wmode)
Generates a new PostScript Type 3 font and dumps it to outf file.
Definition: sft.cxx:1520
#define SAL_WARN_IF(condition, area, stream)
int i
SFErrCodes
Return value of OpenTTFont() and CreateT3FromTTGlyphs()
Definition: sft.hxx:65
@ BadArg
incorrect arguments
constexpr int O_CFF
Definition: sft.hxx:687
Sun Font Tools.
unsigned char sal_uInt8