Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TFONT_H
Toshihiro Shimizu 890ddd
#define TFONT_H
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// Toonz includes
Toshihiro Shimizu 890ddd
#include "trastercm.h"
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// STL includes
Toshihiro Shimizu 890ddd
#include <string></string>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TVRENDER_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//  Forward declarations
Toshihiro Shimizu 890ddd
class TVectorImageP;
Toshihiro Shimizu 890ddd
class TFont;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// TFont declaration. The class is currently not directly available under 64-bit
Shinya Kitaoka 120a6e
// MAC OSX.
Toshihiro Shimizu 890ddd
Campbell Barton deffae
#if !defined(__LP64__) || !defined(MACOSX)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef MACOSX
Toshihiro Shimizu 890ddd
#include <applicationservices applicationservices.h=""></applicationservices>
Toshihiro Shimizu 890ddd
#include <carbon carbon.h=""></carbon>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=================================================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! Class to manage loading and rendering of fonts.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TFont {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  struct Impl;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  friend class TFontManager;
Shinya Kitaoka 120a6e
  Impl *m_pimpl;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
  TFont(const LOGFONTW &, HDC hdc);
Campbell Barton deffae
#elif defined(MACOSX)
Shinya Kitaoka 120a6e
  TFont(ATSUFontID, int size);
Campbell Barton deffae
#else
Campbell Barton deffae
  TFont(const std::wstring family, const std::wstring face, int size);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  ~TFont();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPoint drawChar(TVectorImageP &outImage, wchar_t charcode,
Shinya Kitaoka 120a6e
                  wchar_t nextCode = 0) const;
Shinya Kitaoka 120a6e
  TPoint drawChar(TRasterGR8P &outImage, TPoint &glyphOrigin, wchar_t charcode,
Shinya Kitaoka 120a6e
                  wchar_t nextCode = 0) const;
Shinya Kitaoka 120a6e
  TPoint drawChar(TRasterCM32P &outImage, TPoint &glyphOrigin, int inkId,
Shinya Kitaoka 120a6e
                  wchar_t charcode, wchar_t nextCode = 0) const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // brief  get kerning distance between two characters
Shinya Kitaoka 120a6e
  TPoint getDistance(wchar_t firstChar, wchar_t secondChar) const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int getMaxHeight() const;
Shinya Kitaoka 120a6e
  int getMaxWidth() const;
Shinya Kitaoka 120a6e
  // void disableKerning();
Shinya Kitaoka 120a6e
  // void enableKerning();
Shinya Kitaoka 120a6e
  bool hasKerning() const;
Shinya Kitaoka 120a6e
  int getLineAscender() const;
Shinya Kitaoka 120a6e
  int getLineDescender() const;
Shinya Kitaoka 120a6e
  bool hasVertical() const;
Shinya Kitaoka 120a6e
  std::wstring getFamily() const;
Shinya Kitaoka 120a6e
  std::wstring getTypeface() const;
Shinya Kitaoka 120a6e
  // bool isValidCode( wchar_t code ) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  TFont(const TFont &);
Shinya Kitaoka 120a6e
  TFont &operator=(const TFont &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Campbell Barton deffae
#endif  //!__LP64__ || !MACOSX
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TFontCreationError final : public TException {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TFontCreationError() : TException("E_CanNotUseSelectedFont") {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TFontLibraryLoadingError final : public TException {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TFontLibraryLoadingError() : TException("E_CanNotLoadFonts") {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// singleton
Shinya Kitaoka 120a6e
class DVAPI TFontManager {
Shinya Kitaoka 120a6e
  struct Impl;
Shinya Kitaoka 120a6e
  Impl *m_pimpl;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFontManager();
Shinya Kitaoka 120a6e
  ~TFontManager();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  static TFontManager *instance();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFont *getCurrentFont();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! throws TFontLibraryLoadingError if can not load fonts
Shinya Kitaoka 120a6e
  void loadFontNames();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! if can not create font, throws TFontCreationError and leave as current the
Shinya Kitaoka 120a6e
  //! old one
Shinya Kitaoka 120a6e
  void setFamily(const std::wstring family);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! if can not create font, throws TFontCreationError and leave as current the
Shinya Kitaoka 120a6e
  //! old one
Shinya Kitaoka 120a6e
  void setTypeface(const std::wstring typeface);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::wstring getCurrentFamily() const;
Shinya Kitaoka 120a6e
  std::wstring getCurrentTypeface() const;
Shinya Kitaoka 120a6e
  void getAllFamilies(std::vector<std::wstring> &families) const;</std::wstring>
Shinya Kitaoka 120a6e
  void getAllTypefaces(std::vector<std::wstring> &typefaces) const;</std::wstring>
Shinya Kitaoka 120a6e
  void setVertical(bool vertical);
Shinya Kitaoka 120a6e
  void setSize(int size);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// --------- TFont methods  called on curren font -----------
Toshihiro Shimizu 890ddd
Campbell Barton deffae
#if !defined(__LP64__) || defined(LINUX)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPoint drawChar(TVectorImageP &outImage, wchar_t charcode,
Shinya Kitaoka 120a6e
                  wchar_t nextCode = 0) {
Shinya Kitaoka 120a6e
    return getCurrentFont()->drawChar(outImage, charcode, nextCode);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPoint drawChar(TRasterGR8P &outImage, TPoint &glyphOrigin, wchar_t charcode,
Shinya Kitaoka 120a6e
                  wchar_t nextCode = 0) {
Shinya Kitaoka 120a6e
    return getCurrentFont()->drawChar(outImage, glyphOrigin, charcode,
Shinya Kitaoka 120a6e
                                      nextCode);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPoint drawChar(TRasterCM32P &outImage, TPoint &glyphOrigin, int inkId,
Shinya Kitaoka 120a6e
                  wchar_t charcode, wchar_t nextCode = 0) {
Shinya Kitaoka 120a6e
    return getCurrentFont()->drawChar(outImage, glyphOrigin, inkId, charcode,
Shinya Kitaoka 120a6e
                                      nextCode);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPoint getDistance(wchar_t firstChar, wchar_t secondChar) {
Shinya Kitaoka 120a6e
    return getCurrentFont()->getDistance(firstChar, secondChar);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int getMaxHeight() { return getCurrentFont()->getMaxHeight(); }
Shinya Kitaoka 120a6e
  int getMaxWidth() { return getCurrentFont()->getMaxWidth(); }
Shinya Kitaoka 120a6e
  bool hasKerning() { return getCurrentFont()->hasKerning(); }
Shinya Kitaoka 120a6e
  int getLineAscender() { return getCurrentFont()->getLineAscender(); }
Shinya Kitaoka 120a6e
  int getLineDescender() { return getCurrentFont()->getLineDescender(); }
Shinya Kitaoka 120a6e
  bool hasVertical() { return getCurrentFont()->hasVertical(); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
#else  //__LP64__
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPoint drawChar(TVectorImageP &outImage, wchar_t charcode,
Shinya Kitaoka 120a6e
                  wchar_t nextCode = 0);
Shinya Kitaoka 120a6e
  TPoint drawChar(TRasterGR8P &outImage, TPoint &glyphOrigin, wchar_t charcode,
Shinya Kitaoka 120a6e
                  wchar_t nextCode = 0);
Shinya Kitaoka 120a6e
  TPoint drawChar(TRasterCM32P &outImage, TPoint &glyphOrigin, int inkId,
Shinya Kitaoka 120a6e
                  wchar_t charcode, wchar_t nextCode = 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPoint getDistance(wchar_t firstChar, wchar_t secondChar);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int getMaxHeight();
Shinya Kitaoka 120a6e
  int getMaxWidth();
Shinya Kitaoka 120a6e
  bool hasKerning();
Shinya Kitaoka 120a6e
  int getLineAscender();
Shinya Kitaoka 120a6e
  int getLineDescender();
Shinya Kitaoka 120a6e
  bool hasVertical();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
#endif  //__LP64__
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif