tahoma2d/toonz/sources/include/tfont.h

162 lines
4.7 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TFONT_H
#define TFONT_H
2016-06-15 18:43:10 +12:00
// Toonz includes
2016-03-19 06:57:51 +13:00
#include "trastercm.h"
#include "texception.h"
2016-06-15 18:43:10 +12:00
// STL includes
2016-03-19 06:57:51 +13:00
#include <string>
#undef DVAPI
#undef DVVAR
#ifdef TVRENDER_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
//-----------------------------------------------------
// Forward declarations
class TVectorImageP;
class TFont;
//=================================================================================================
//! Class to manage loading and rendering of fonts.
2016-06-15 18:43:10 +12:00
class DVAPI TFont {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
struct Impl;
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
friend class TFontManager;
Impl *m_pimpl;
2016-03-19 06:57:51 +13:00
2016-06-17 20:48:03 +12:00
TFont(const std::wstring family, const std::wstring face, int size);
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
~TFont();
TPoint drawChar(TVectorImageP &outImage, wchar_t charcode,
wchar_t nextCode = 0) const;
2017-06-22 14:50:35 +12:00
TPoint drawChar(QImage &outImage, TPoint &glyphOrigin, wchar_t charcode,
2016-06-15 18:43:10 +12:00
wchar_t nextCode = 0) const;
TPoint drawChar(TRasterCM32P &outImage, TPoint &glyphOrigin, int inkId,
wchar_t charcode, wchar_t nextCode = 0) const;
// brief get kerning distance between two characters
TPoint getDistance(wchar_t firstChar, wchar_t secondChar) const;
int getMaxWidth() const;
// void disableKerning();
// void enableKerning();
bool hasKerning() const;
int getLineAscender() const;
int getLineDescender() const;
2017-08-23 17:51:40 +12:00
int getLineSpacing() const;
int getHeight() const;
int getAverageCharWidth() const;
2016-06-15 18:43:10 +12:00
bool hasVertical() const;
std::wstring getFamily() const;
std::wstring getTypeface() const;
// bool isValidCode( wchar_t code ) const;
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
// not implemented
TFont(const TFont &);
TFont &operator=(const TFont &);
2016-03-19 06:57:51 +13:00
};
//-----------------------------------------------------------------------------
class TFontCreationError final : public TException {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TFontCreationError() : TException("E_CanNotUseSelectedFont") {}
2016-03-19 06:57:51 +13:00
};
//-----------------------------------------------------------------------------
class TFontLibraryLoadingError final : public TException {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TFontLibraryLoadingError() : TException("E_CanNotLoadFonts") {}
2016-03-19 06:57:51 +13:00
};
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
// singleton
class DVAPI TFontManager {
struct Impl;
Impl *m_pimpl;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TFontManager();
~TFontManager();
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
static TFontManager *instance();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TFont *getCurrentFont();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//! throws TFontLibraryLoadingError if can not load fonts
void loadFontNames();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//! if can not create font, throws TFontCreationError and leave as current the
//! old one
void setFamily(const std::wstring family);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//! if can not create font, throws TFontCreationError and leave as current the
//! old one
void setTypeface(const std::wstring typeface);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
std::wstring getCurrentFamily() const;
std::wstring getCurrentTypeface() const;
void getAllFamilies(std::vector<std::wstring> &families) const;
void getAllTypefaces(std::vector<std::wstring> &typefaces) const;
void setVertical(bool vertical);
void setSize(int size);
2016-03-19 06:57:51 +13:00
2017-06-22 14:50:35 +12:00
bool isBold(const QString &family, const QString &style);
bool isItalic(const QString &family, const QString &style);
2016-03-19 06:57:51 +13:00
// --------- TFont methods called on current font -----------
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TPoint drawChar(TVectorImageP &outImage, wchar_t charcode,
wchar_t nextCode = 0) {
return getCurrentFont()->drawChar(outImage, charcode, nextCode);
}
2017-06-22 14:50:35 +12:00
TPoint drawChar(QImage &outImage, TPoint &glyphOrigin, wchar_t charcode,
2016-06-15 18:43:10 +12:00
wchar_t nextCode = 0) {
return getCurrentFont()->drawChar(outImage, glyphOrigin, charcode,
nextCode);
}
TPoint drawChar(TRasterCM32P &outImage, TPoint &glyphOrigin, int inkId,
wchar_t charcode, wchar_t nextCode = 0) {
return getCurrentFont()->drawChar(outImage, glyphOrigin, inkId, charcode,
nextCode);
}
TPoint getDistance(wchar_t firstChar, wchar_t secondChar) {
return getCurrentFont()->getDistance(firstChar, secondChar);
}
int getMaxWidth() { return getCurrentFont()->getMaxWidth(); }
bool hasKerning() { return getCurrentFont()->hasKerning(); }
int getLineAscender() { return getCurrentFont()->getLineAscender(); }
int getLineDescender() { return getCurrentFont()->getLineDescender(); }
2017-08-23 17:51:40 +12:00
int getLineSpacing() { return getCurrentFont()->getLineSpacing(); }
int getHeight() { return getCurrentFont()->getHeight(); }
int getAverageCharWidth() { return getCurrentFont()->getAverageCharWidth(); }
2016-06-15 18:43:10 +12:00
bool hasVertical() { return getCurrentFont()->hasVertical(); }
2016-03-19 06:57:51 +13:00
};
//-----------------------------------------------------------------------------
#endif