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 class  FontRights {
  ViewingAllowed ,
  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, std::u16string_view 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, std::u16string_view 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

◆ FontRights

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::~EmbeddedFontsHelper ( )
inline

Definition at line 102 of file embeddedfontshelper.hxx.

Member Function Documentation

◆ activateFont()

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().

◆ 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(), and m_aAccumulatedFonts.

◆ addEmbeddedFont()

bool EmbeddedFontsHelper::addEmbeddedFont ( const css::uno::Reference< css::io::XInputStream > &  stream,
const OUString &  fontName,
std::u16string_view  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 68 of file embeddedfontshelper.cxx.

References EditingAllowed, fileUrlForTemporaryFont(), m_aAccumulatedFonts, pos, SAL_INFO, SAL_WARN, stream, and sufficientTTFRights().

◆ clearTemporaryFontFiles()

void EmbeddedFontsHelper::clearTemporaryFontFiles ( )
static

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

Definition at line 59 of file embeddedfontshelper.cxx.

References clearDir(), and SAL_CONFIGFILE.

Referenced by DeInitVCL(), and InitVCL().

◆ fileUrlForTemporaryFont()

OUString EmbeddedFontsHelper::fileUrlForTemporaryFont ( const OUString &  fontName,
std::u16string_view  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, and u.

Referenced by addEmbeddedFont().

◆ fontFileUrl()

OUString EmbeddedFontsHelper::fontFileUrl ( std::u16string_view  familyName,
FontFamily  family,
FontItalic  italic,
FontWeight  weight,
FontPitch  pitch,
FontRights  rights 
)
static

◆ sufficientTTFRights()

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(), EditingAllowed, vcl::GetTTGlobalFontInfo(), vcl::OpenTTFontBuffer(), size, vcl::TTGlobalFontInfo_::typeFlags, and ViewingAllowed.

Referenced by addEmbeddedFont(), and fontFileUrl().

Member Data Documentation

◆ m_aAccumulatedFonts

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

Definition at line 32 of file embeddedfontshelper.hxx.

Referenced by activateFonts(), and addEmbeddedFont().


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