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/.
10 #ifndef INCLUDED_VCL_EMBEDDEDFONTSHELPER_HXX
11 #define INCLUDED_VCL_EMBEDDEDFONTSHELPER_HXX
13 #include <vcl/dllapi.h>
15 #include <rtl/ustring.hxx>
16 #include <tools/fontenum.hxx>
17 #include <tools/long.hxx>
19 #include <string_view>
22 namespace com::sun::star::io
{ class XInputStream
; }
23 namespace com::sun::star::uno
{ template <typename
> class Reference
; }
26 Helper functions for handling embedded fonts in documents.
29 class VCL_DLLPUBLIC EmbeddedFontsHelper
32 std::vector
<std::pair
<OUString
, OUString
>> m_aAccumulatedFonts
;
35 Adds the given font to the list of known fonts. The font is used only until application
38 @param fontName name of the font (e.g. 'Times New Roman')
39 @param fileUrl URL of the font file
41 static void activateFont( const OUString
& fontName
, const OUString
& fileUrl
);
44 /// Specification of what kind of operation is allowed when embedding a font
47 ViewingAllowed
, ///< Font may be embedded for viewing the document (but not editing)
48 EditingAllowed
///< Font may be embedded for editing document (implies viewing)
52 Returns URL for a font file for the given font, or empty if it does not exist.
54 static OUString
fontFileUrl(
55 std::u16string_view familyName
, FontFamily family
, FontItalic italic
,
56 FontWeight weight
, FontPitch pitch
, FontRights rights
);
59 Reads a font from the input stream, saves it to a temporary font file and adds it to the list of
60 fonts that activateFonts will activate.
61 @param stream stream of font data
62 @param fontName name of the font (e.g. 'Times New Roman')
63 @param extra additional text to use for name (e.g. to distinguish regular from bold, italic,...), "?" for unique
64 @param key key to xor the data with, from the start until the key's length (not repeated)
65 @param eot whether the data is compressed in Embedded OpenType format
67 bool addEmbeddedFont( const css::uno::Reference
< css::io::XInputStream
>& stream
,
68 const OUString
& fontName
, std::u16string_view extra
,
69 std::vector
< unsigned char > const & key
, bool eot
= false);
72 Returns a URL for a file where to store contents of a given temporary font.
73 The file may or not may not exist yet, and will be cleaned up automatically as appropriate.
74 Use activateTemporaryFont() to actually enable usage of the font.
76 @param fontName name of the font (e.g. 'Times New Roman')
77 @param extra additional text to use for name (e.g. to distinguish regular from bold, italic,...), "?" for unique
79 static OUString
fileUrlForTemporaryFont( const OUString
& fontName
, std::u16string_view extra
);
82 Adds the accumulated fonts to the list of known fonts. The fonts are used only until application
88 Returns if the restrictions specified in the font (if present) allow embedding
89 the font for a particular purpose.
91 @param size size of the font data
92 @param rights type of operation to be allowed for the font
94 static bool sufficientTTFRights( const void* data
, tools::Long size
, FontRights rights
);
97 Removes all temporary fonts in the path used by fileUrlForTemporaryFont().
100 static void clearTemporaryFontFiles();
102 ~EmbeddedFontsHelper() COVERITY_NOEXCEPT_FALSE
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */