LibreOffice Module vcl (master)  1
Public Types | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
EmbeddedFontsHelper Class Reference

Helper functions for handling embedded fonts in documents. More...

#include <embeddedfontshelper.hxx>

Public Types

enum  FontRights {
  FontRights::ViewingAllowed,
  FontRights::EditingAllowed
}
 Specification of what kind of operation is allowed when embedding a font. More...
 

Public Member Functions

bool addEmbeddedFont (const css::uno::Reference< css::io::XInputStream > &stream, const OUString &fontName, const char *extra, std::vector< unsigned char > const &key, bool eot=false)
 Reads a font from the input stream, saves it to a temporary font file and adds it to the list of fonts that activateFonts will activate. More...
 
void activateFonts ()
 Adds the accumulated fonts to the list of known fonts. More...
 
 ~EmbeddedFontsHelper () COVERITY_NOEXCEPT_FALSE
 

Static Public Member Functions

static OUString fontFileUrl (std::u16string_view familyName, FontFamily family, FontItalic italic, FontWeight weight, FontPitch pitch, FontRights rights)
 Returns URL for a font file for the given font, or empty if it does not exist. More...
 
static OUString fileUrlForTemporaryFont (const OUString &fontName, const char *extra)
 Returns a URL for a file where to store contents of a given temporary font. More...
 
static bool sufficientTTFRights (const void *data, tools::Long size, FontRights rights)
 Returns if the restrictions specified in the font (if present) allow embedding the font for a particular purpose. More...
 
static void clearTemporaryFontFiles ()
 Removes all temporary fonts in the path used by fileUrlForTemporaryFont(). More...
 

Static Private Member Functions

static void activateFont (const OUString &fontName, const OUString &fileUrl)
 Adds the given font to the list of known fonts. More...
 

Private Attributes

std::vector< std::pair< OUString, OUString > > m_aAccumulatedFonts
 

Detailed Description

Helper functions for handling embedded fonts in documents.

Definition at line 29 of file embeddedfontshelper.hxx.

Member Enumeration Documentation

Specification of what kind of operation is allowed when embedding a font.

Enumerator
ViewingAllowed 

Font may be embedded for viewing the document (but not editing)

EditingAllowed 

Font may be embedded for editing document (implies viewing)

Definition at line 45 of file embeddedfontshelper.hxx.

Constructor & Destructor Documentation

EmbeddedFontsHelper::~EmbeddedFontsHelper ( )
inline

Definition at line 102 of file embeddedfontshelper.hxx.

Member Function Documentation

void EmbeddedFontsHelper::activateFont ( const OUString &  fontName,
const OUString &  fileUrl 
)
staticprivate

Adds the given font to the list of known fonts.

The font is used only until application exit.

Parameters
fontNamename of the font (e.g. 'Times New Roman')
fileUrlURL of the font file

Definition at line 208 of file embeddedfontshelper.cxx.

References OutputDevice::AddTempDevFont(), and Application::GetDefaultDevice().

Referenced by activateFonts().

void EmbeddedFontsHelper::activateFonts ( )

Adds the accumulated fonts to the list of known fonts.

The fonts are used only until application exit.

Definition at line 182 of file embeddedfontshelper.cxx.

References activateFont().

bool EmbeddedFontsHelper::addEmbeddedFont ( const css::uno::Reference< css::io::XInputStream > &  stream,
const OUString &  fontName,
const char *  extra,
std::vector< unsigned char > const &  key,
bool  eot = false 
)

Reads a font from the input stream, saves it to a temporary font file and adds it to the list of fonts that activateFonts will activate.

Parameters
streamstream of font data
fontNamename of the font (e.g. 'Times New Roman')
extraadditional text to use for name (e.g. to distinguish regular from bold, italic,...), "?" for unique
keykey to xor the data with, from the start until the key's length (not repeated)
eotwhether the data is compressed in Embedded OpenType format

Definition at line 69 of file embeddedfontshelper.cxx.

References fileUrlForTemporaryFont(), pos, SAL_INFO, and SAL_WARN.

void EmbeddedFontsHelper::clearTemporaryFontFiles ( )
static

Removes all temporary fonts in the path used by fileUrlForTemporaryFont().

Definition at line 60 of file embeddedfontshelper.cxx.

References clearDir(), and SAL_CONFIGFILE.

Referenced by DeInitVCL(), and InitVCL().

OUString EmbeddedFontsHelper::fileUrlForTemporaryFont ( const OUString &  fontName,
const char *  extra 
)
static

Returns a URL for a file where to store contents of a given temporary font.

The file may or not may not exist yet, and will be cleaned up automatically as appropriate. Use activateTemporaryFont() to actually enable usage of the font.

Parameters
fontNamename of the font (e.g. 'Times New Roman')
extraadditional text to use for name (e.g. to distinguish regular from bold, italic,...), "?" for unique

Definition at line 192 of file embeddedfontshelper.cxx.

References SAL_CONFIGFILE.

Referenced by addEmbeddedFont().

OUString EmbeddedFontsHelper::fontFileUrl ( std::u16string_view  familyName,
FontFamily  family,
FontItalic  italic,
FontWeight  weight,
FontPitch  pitch,
FontRights  rights 
)
static
bool EmbeddedFontsHelper::sufficientTTFRights ( const void data,
tools::Long  size,
FontRights  rights 
)
static

Returns if the restrictions specified in the font (if present) allow embedding the font for a particular purpose.

Parameters
datafont data
sizesize of the font data
rightstype of operation to be allowed for the font

Definition at line 219 of file embeddedfontshelper.cxx.

References vcl::CloseTTFont(), vcl::GetTTGlobalFontInfo(), vcl::OpenTTFontBuffer(), and vcl::TTGlobalFontInfo_::typeFlags.

Member Data Documentation

std::vector<std::pair<OUString, OUString> > EmbeddedFontsHelper::m_aAccumulatedFonts
private

Definition at line 32 of file embeddedfontshelper.hxx.


The documentation for this class was generated from the following files: