Bump version to 21.06.18.1
[LibreOffice.git] / include / vcl / embeddedfontshelper.hxx
blob7f8c1f3094cf04a4e5f9ecab5b3365ce3d79c297
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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>
18 #include <vector>
20 namespace com::sun::star::io { class XInputStream; }
21 namespace com::sun::star::uno { template <typename > class Reference; }
23 /**
24 Helper functions for handling embedded fonts in documents.
27 class VCL_DLLPUBLIC EmbeddedFontsHelper
29 private:
30 std::vector<std::pair<OUString, OUString>> m_aAccumulatedFonts;
32 /**
33 Adds the given font to the list of known fonts. The font is used only until application
34 exit.
36 @param fontName name of the font (e.g. 'Times New Roman')
37 @param fileUrl URL of the font file
39 static void activateFont( const OUString& fontName, const OUString& fileUrl );
41 public:
42 /// Specification of what kind of operation is allowed when embedding a font
43 enum class FontRights
45 ViewingAllowed, ///< Font may be embedded for viewing the document (but not editing)
46 EditingAllowed ///< Font may be embedded for editing document (implies viewing)
49 /**
50 Returns URL for a font file for the given font, or empty if it does not exist.
52 static OUString fontFileUrl( const OUString& familyName, FontFamily family, FontItalic italic,
53 FontWeight weight, FontPitch pitch, FontRights rights );
55 /**
56 Reads a font from the input stream, saves it to a temporary font file and adds it to the list of
57 fonts that activateFonts will activate.
58 @param stream stream of font data
59 @param fontName name of the font (e.g. 'Times New Roman')
60 @param extra additional text to use for name (e.g. to distinguish regular from bold, italic,...), "?" for unique
61 @param key key to xor the data with, from the start until the key's length (not repeated)
62 @param eot whether the data is compressed in Embedded OpenType format
64 bool addEmbeddedFont( const css::uno::Reference< css::io::XInputStream >& stream,
65 const OUString& fontName, const char* extra,
66 std::vector< unsigned char > key, bool eot = false);
68 /**
69 Returns a URL for a file where to store contents of a given temporary font.
70 The file may or not may not exist yet, and will be cleaned up automatically as appropriate.
71 Use activateTemporaryFont() to actually enable usage of the font.
73 @param fontName name of the font (e.g. 'Times New Roman')
74 @param extra additional text to use for name (e.g. to distinguish regular from bold, italic,...), "?" for unique
76 static OUString fileUrlForTemporaryFont( const OUString& fontName, const char* extra );
78 /**
79 Adds the accumulated fonts to the list of known fonts. The fonts are used only until application
80 exit.
82 void activateFonts();
84 /**
85 Returns if the restrictions specified in the font (if present) allow embedding
86 the font for a particular purpose.
87 @param data font data
88 @param size size of the font data
89 @param rights type of operation to be allowed for the font
91 static bool sufficientTTFRights( const void* data, tools::Long size, FontRights rights );
93 /**
94 Removes all temporary fonts in the path used by fileUrlForTemporaryFont().
95 @internal
97 static void clearTemporaryFontFiles();
99 ~EmbeddedFontsHelper() COVERITY_NOEXCEPT_FALSE
101 activateFonts();
105 #endif
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */