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 OString aPSName = m_aPSName.toUtf8();
83 if (!mpReqFontName)
84 mpReqFontName = aPSName.getStr();
85
86 // TODO: move the glyphid/encid/notdef reshuffling from the callers to here
87
88 // dispatch to underlying subsetters
89 bool bOK = false;
90
91 // TODO: better match available input-type to possible subset-types
92 switch( meInFontType) {
97 break;
100 break;
105 default:
106 OSL_FAIL( "unhandled type in CreateFontSubset()");
107 break;
108 }
109
110 return bOK;
111}
112
113// TODO: move function to sft.cxx to replace dummy implementation
115{
116 // handle SFNT_CFF fonts
117 sal_uInt32 nCffLength = 0;
118 const sal_uInt8* pCffBytes = mpSftTTFont->table(vcl::O_CFF, nCffLength);
119 if (pCffBytes)
120 {
121 LoadFont( FontType::CFF_FONT, pCffBytes, nCffLength);
122 const bool bOK = CreateFontSubsetFromCff();
123 return bOK;
124 }
125
126 // handle SFNT_TTF fonts
127 // by forwarding the subset request to AG's sft subsetter
128#if 1 // TODO: remove conversion tp 16bit glyphids when sft-subsetter has been updated
129 std::vector<sal_uInt16> aShortGlyphIds;
130 aShortGlyphIds.reserve(mnReqGlyphCount);
131 for (int i = 0; i < mnReqGlyphCount; ++i)
132 aShortGlyphIds.push_back(static_cast<sal_uInt16>(mpReqGlyphIds[i]));
133 // remove const_cast when sft-subsetter is const-correct
134 sal_uInt8* pEncArray = const_cast<sal_uInt8*>( mpReqEncodedIds );
135#endif
138 {
140 aShortGlyphIds.data(), pEncArray, mnReqGlyphCount );
141 }
143 {
145 aShortGlyphIds.data(), pEncArray, mnReqGlyphCount,
146 0 /* 0 = horizontal, 1 = vertical */ );
147 }
149 {
150 // TODO: use CreateTTFromTTGlyphs()
151 // TODO: move functionality from callers here
152 }
153
154 return (nSFTErr != vcl::SFErrCodes::Ok);
155}
156
157/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvStream * mpOutFile
Definition: fontsubset.hxx:84
OUString m_aPSName
Definition: fontsubset.hxx:67
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:114
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:2131
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:1564
#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