Campbell Barton 747d5c
Campbell Barton 747d5c
Campbell Barton 747d5c
// character_manager.cpp: implementation of the TFont class
Campbell Barton 747d5c
// for FreeType 2.
Campbell Barton 747d5c
//
Campbell Barton 747d5c
//////////////////////////////////////////////////////////////////////
Campbell Barton 747d5c
Campbell Barton 747d5c
#include <qstringlist></qstringlist>
Campbell Barton 747d5c
#include <qfont></qfont>
Campbell Barton 747d5c
#include <qfontdatabase></qfontdatabase>
Campbell Barton 747d5c
#include <qfontmetrics></qfontmetrics>
Campbell Barton 747d5c
#include <qimage></qimage>
Campbell Barton 747d5c
#include <qpainterpath></qpainterpath>
Campbell Barton 747d5c
#include <qrawfont></qrawfont>
Campbell Barton 747d5c
Campbell Barton 747d5c
#include <vector></vector>
Campbell Barton 747d5c
#include <iostream></iostream>
Campbell Barton 747d5c
#include <string></string>
Campbell Barton 747d5c
Campbell Barton 747d5c
#include "tpixelgr.h"
Campbell Barton 747d5c
#include "tfont.h"
Campbell Barton 747d5c
#include "tstroke.h"
Campbell Barton 747d5c
#include "tcurves.h"
Campbell Barton 747d5c
#include "traster.h"
Campbell Barton 747d5c
#include "tmathutil.h"
Campbell Barton 747d5c
#include "tvectorimage.h"
Campbell Barton 747d5c
using namespace std;
Campbell Barton 747d5c
Campbell Barton 747d5c
//=============================================================================
Campbell Barton 747d5c
Campbell Barton 747d5c
struct TFont::Impl {
Campbell Barton 747d5c
  bool m_hasKerning;
Campbell Barton 747d5c
  int m_hasVertical;
Campbell Barton 747d5c
  QFont m_font;
Campbell Barton 747d5c
  // XXX:cache a QFontMetrics m_metrics; ?
Campbell Barton 747d5c
  // XXX:cache a QRawFont m_raw; ?
Campbell Barton 747d5c
Campbell Barton 747d5c
  //  KerningPairs m_kerningPairs;
Campbell Barton 747d5c
Campbell Barton 747d5c
  Impl(const QString &family, const QString &style, int size);
Campbell Barton 747d5c
  ~Impl();
Campbell Barton 747d5c
Campbell Barton 747d5c
  // void getChar();
Campbell Barton 747d5c
};
Campbell Barton 747d5c
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
TFont::TFont(const wstring family, const wstring face, int size) {
Campbell Barton 747d5c
  m_pimpl = new Impl(QString::fromStdWString(family),
Campbell Barton 747d5c
                     QString::fromStdWString(face), size);
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
TFont::~TFont() { delete m_pimpl; }
Campbell Barton 747d5c
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
TFont::Impl::Impl(const QString &family, const QString &style, int size) {
Campbell Barton 747d5c
  m_font = QFont(family, size);
Campbell Barton 747d5c
  m_font.setStyleName(style);
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
TFont::Impl::~Impl() {}
Campbell Barton 747d5c
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
TPoint TFont::drawChar(TVectorImageP &image, wchar_t charcode,
Campbell Barton 747d5c
                       wchar_t nextCharCode) const {
Campbell Barton 747d5c
  QRawFont raw(QRawFont::fromFont(m_pimpl->m_font));
Campbell Barton 747d5c
Campbell Barton 747d5c
  QChar chars[2] = {charcode, nextCharCode};
Campbell Barton 747d5c
  quint32 indices[2];
Campbell Barton 747d5c
  int count = 2;
Campbell Barton 747d5c
Campbell Barton 747d5c
  if (!raw.glyphIndexesForChars(chars, 2, indices, &count) || count < 1)
Campbell Barton 747d5c
    return TPoint(0, 0);
Campbell Barton 747d5c
  QPainterPath path = raw.pathForGlyph(indices[0]);
Campbell Barton 747d5c
Campbell Barton 747d5c
  // empty glyph, nothing to do
Campbell Barton 747d5c
  if (path.elementCount() < 1) return getDistance(charcode, nextCharCode);
Campbell Barton 747d5c
Campbell Barton 747d5c
  // force closing the last path
Shinya Kitaoka d1f6c4
  if (path.elementAt(path.elementCount() - 1).type !=
Shinya Kitaoka d1f6c4
      QPainterPath::MoveToElement) {
Campbell Barton 747d5c
    path.moveTo(0.0, 0.0);
Campbell Barton 747d5c
  }
Campbell Barton 747d5c
Campbell Barton 747d5c
  int i, n = path.elementCount();
Campbell Barton 747d5c
  int strokes = 0;
Campbell Barton 747d5c
  std::vector<tthickpoint> points;</tthickpoint>
Campbell Barton 747d5c
Campbell Barton 747d5c
  TThickPoint pts[4];
Campbell Barton 747d5c
  int nCubicPts = 0;
Campbell Barton 747d5c
Campbell Barton 747d5c
  for (i = 0; i < n; i++) {
Campbell Barton 747d5c
    QPainterPath::Element e = path.elementAt(i);
Campbell Barton 747d5c
    e.y                     = -e.y;
Campbell Barton 747d5c
Campbell Barton 747d5c
    switch (e.type) {
Campbell Barton 747d5c
    case QPainterPath::MoveToElement:
Campbell Barton 747d5c
      if (!points.empty()) {
Campbell Barton 747d5c
        if (points.back() != points.front()) {
Campbell Barton 747d5c
          points.push_back(0.5 * (points.back() + points.front()));
Campbell Barton 747d5c
          points.push_back(points.front());
Campbell Barton 747d5c
        }
Campbell Barton 747d5c
Campbell Barton 747d5c
        TStroke *stroke = new TStroke(points);
Campbell Barton 747d5c
        stroke->setSelfLoop(true);
Campbell Barton 747d5c
        image->addStroke(stroke);
Campbell Barton 747d5c
        strokes++;
Campbell Barton 747d5c
        points.clear();
Campbell Barton 747d5c
      }
Campbell Barton 747d5c
      points.push_back(TThickPoint(e.x, e.y, 0));
Campbell Barton 747d5c
      break;
Campbell Barton 747d5c
    case QPainterPath::LineToElement: {
Campbell Barton 747d5c
      TThickPoint p0 = points.back();
Campbell Barton 747d5c
      TThickPoint p1 = TThickPoint(e.x, e.y, 0);
Campbell Barton 747d5c
      points.push_back((p0 + p1) * 0.5);
Campbell Barton 747d5c
      points.push_back(p1);
Campbell Barton 747d5c
      break;
Campbell Barton 747d5c
    }
Campbell Barton 747d5c
    case QPainterPath::CurveToElement:
Campbell Barton 747d5c
      pts[0]    = points.back();
Campbell Barton 747d5c
      pts[1]    = TThickPoint(e.x, e.y, 0);
Campbell Barton 747d5c
      nCubicPts = 2;
Campbell Barton 747d5c
      break;
Campbell Barton 747d5c
    case QPainterPath::CurveToDataElement:
Campbell Barton 747d5c
      pts[nCubicPts++] = TThickPoint(e.x, e.y, 0);
Campbell Barton 747d5c
      if (nCubicPts == 4) {
Campbell Barton 747d5c
        vector<tthickquadratic *=""> chunkArray;</tthickquadratic>
Campbell Barton 747d5c
        computeQuadraticsFromCubic(pts[0], pts[1], pts[2], pts[3], 0.09,
Campbell Barton 747d5c
                                   chunkArray);
Campbell Barton 747d5c
Campbell Barton 747d5c
        for (int j = 0; j < chunkArray.size(); j++) {
Campbell Barton 747d5c
          points.push_back(chunkArray[j]->getP1());
Campbell Barton 747d5c
          points.push_back(chunkArray[j]->getP2());
Campbell Barton 747d5c
        }
Campbell Barton 747d5c
        nCubicPts = 0;
Campbell Barton 747d5c
      }
Campbell Barton 747d5c
      break;
Campbell Barton 747d5c
    }
Campbell Barton 747d5c
  }
Campbell Barton 747d5c
Campbell Barton 747d5c
  if (strokes > 1) image->group(0, strokes);
Campbell Barton 747d5c
Campbell Barton 747d5c
  return getDistance(charcode, nextCharCode);
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
TPoint TFont::drawChar(TRasterGR8P &outImage, TPoint &unused, wchar_t charcode,
Campbell Barton 747d5c
                       wchar_t nextCharCode) const {
Campbell Barton 747d5c
  QRawFont raw(QRawFont::fromFont(m_pimpl->m_font));
Campbell Barton 747d5c
Campbell Barton 747d5c
  QChar chars[2] = {charcode, nextCharCode};
Campbell Barton 747d5c
  quint32 indices[2];
Campbell Barton 747d5c
  int count = 2;
Campbell Barton 747d5c
Campbell Barton 747d5c
  if (!raw.glyphIndexesForChars(chars, 2, indices, &count) || count < 1) {
Campbell Barton 747d5c
    return TPoint(0, 0);
Campbell Barton 747d5c
  }
Campbell Barton 747d5c
Campbell Barton 747d5c
  QImage image(raw.alphaMapForGlyph(indices[0], QRawFont::PixelAntialiasing));
Campbell Barton 747d5c
Campbell Barton 747d5c
  if (image.format() != QImage::Format_Indexed8)
Campbell Barton 747d5c
    throw TException(L"bad QImage format " + image.format());
Campbell Barton 747d5c
Campbell Barton 747d5c
  int height = image.height();
Campbell Barton 747d5c
  int width  = image.width();
Campbell Barton 747d5c
Campbell Barton 747d5c
  outImage = TRasterGR8P(width, height);
Campbell Barton 747d5c
Campbell Barton 747d5c
#if 0
Campbell Barton 747d5c
  TPixelGR8 bgp;
Campbell Barton 747d5c
  bgp.value = 255;
Campbell Barton 747d5c
  outImage->fill(bgp);
Campbell Barton 747d5c
#endif
Campbell Barton 747d5c
  void *data = outImage->getRawData();
Campbell Barton 747d5c
Campbell Barton 747d5c
  memcpy(data, image.bits(), image.byteCount());
Campbell Barton 747d5c
Campbell Barton 747d5c
  return getDistance(charcode, nextCharCode);
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
TPoint TFont::drawChar(TRasterCM32P &outImage, TPoint &unused, int inkId,
Campbell Barton 747d5c
                       wchar_t charcode, wchar_t nextCharCode) const {
Campbell Barton 747d5c
  TRasterGR8P grayAppImage;
Campbell Barton 747d5c
  this->drawChar(grayAppImage, unused, charcode, nextCharCode);
Campbell Barton 747d5c
Campbell Barton 747d5c
  int lx = grayAppImage->getLx();
Campbell Barton 747d5c
  int ly = grayAppImage->getLy();
Campbell Barton 747d5c
Campbell Barton 747d5c
  outImage = TRasterCM32P(lx, ly);
Campbell Barton 747d5c
Campbell Barton 747d5c
  assert(TPixelCM32::getMaxTone() == 255);
Campbell Barton 747d5c
  TPixelCM32 bgColor(0, 0, TPixelCM32::getMaxTone());
Campbell Barton 747d5c
  grayAppImage->lock();
Campbell Barton 747d5c
  outImage->lock();
Campbell Barton 747d5c
  int ty = 0;
Campbell Barton 747d5c
  for (int gy = ly - 1; gy >= 0; --gy, ++ty) {
Campbell Barton 747d5c
    TPixelGR8 *srcPix  = grayAppImage->pixels(gy);
Campbell Barton 747d5c
    TPixelCM32 *tarPix = outImage->pixels(ty);
Campbell Barton 747d5c
    for (int x = 0; x < lx; ++x) {
Campbell Barton 747d5c
      int tone = srcPix->value;
Campbell Barton 747d5c
Campbell Barton 747d5c
      if (tone == 255)
Campbell Barton 747d5c
        *tarPix = bgColor;
Campbell Barton 747d5c
      else
Campbell Barton 747d5c
        *tarPix = TPixelCM32(inkId, 0, tone);
Campbell Barton 747d5c
Campbell Barton 747d5c
      ++srcPix;
Campbell Barton 747d5c
      ++tarPix;
Campbell Barton 747d5c
    }
Campbell Barton 747d5c
  }
Campbell Barton 747d5c
  grayAppImage->unlock();
Campbell Barton 747d5c
  outImage->unlock();
Campbell Barton 747d5c
Campbell Barton 747d5c
  return getDistance(charcode, nextCharCode);
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
TPoint TFont::getDistance(wchar_t firstChar, wchar_t secondChar) const {
Campbell Barton 747d5c
  QRawFont raw(QRawFont::fromFont(m_pimpl->m_font));
Campbell Barton 747d5c
  QChar chars[2] = {firstChar, secondChar};
Campbell Barton 747d5c
  quint32 indices[2];
Campbell Barton 747d5c
  QPointF advances[2];
Campbell Barton 747d5c
  int count = 2;
Campbell Barton 747d5c
Campbell Barton 747d5c
  if (!raw.glyphIndexesForChars(chars, 2, indices, &count) || count != 2) {
Campbell Barton 747d5c
    return TPoint(0, 0);
Campbell Barton 747d5c
  }
Campbell Barton 747d5c
Shinya Kitaoka d1f6c4
  if (!raw.advancesForGlyphIndexes(indices, advances, 2,
Shinya Kitaoka d1f6c4
                                   QRawFont::KernedAdvances)) {
Campbell Barton 747d5c
    return TPoint(0, 0);
Campbell Barton 747d5c
  }
Campbell Barton 747d5c
Campbell Barton 747d5c
  int advance = (int)(advances[0].x());
Campbell Barton 747d5c
Campbell Barton 747d5c
  return TPoint(advance, 0);
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
int TFont::getMaxHeight() const {
Campbell Barton 747d5c
  QFontMetrics metrics(m_pimpl->m_font);
Campbell Barton 747d5c
  return metrics.ascent() - metrics.descent();
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
int TFont::getMaxWidth() const {
Campbell Barton 747d5c
  QFontMetrics metrics(m_pimpl->m_font);
Campbell Barton 747d5c
  return metrics.maxWidth();
Campbell Barton 747d5c
}
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
int TFont::getLineAscender() const {
Campbell Barton 747d5c
  QFontMetrics metrics(m_pimpl->m_font);
Campbell Barton 747d5c
  return metrics.ascent();
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
int TFont::getLineDescender() const {
Campbell Barton 747d5c
  QFontMetrics metrics(m_pimpl->m_font);
Campbell Barton 747d5c
  return metrics.descent();
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
bool TFont::hasKerning() const { return m_pimpl->m_font.kerning(); }
Campbell Barton 747d5c
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
bool TFont::hasVertical() const {
Campbell Barton 747d5c
  // FIXME
Campbell Barton 747d5c
  return false;
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//-----------------------------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
//=============================================================================
Campbell Barton 747d5c
//====================      TFontManager  =====================================
Campbell Barton 747d5c
//=============================================================================
Campbell Barton 747d5c
Campbell Barton 747d5c
//---------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
struct TFontManager::Impl {
Campbell Barton 747d5c
  QFontDatabase *m_qfontdb;
Campbell Barton 747d5c
  bool m_loaded;
Campbell Barton 747d5c
Campbell Barton 747d5c
  TFont *m_currentFont;
Campbell Barton 747d5c
  wstring m_currentFamily;
Campbell Barton 747d5c
  wstring m_currentTypeface;
Campbell Barton 747d5c
  int m_size;
Campbell Barton 747d5c
Campbell Barton 747d5c
  // this option is set by library user when he wants to write vertically.
Campbell Barton 747d5c
  // In this implementation, if m_vertical is true and the font
Campbell Barton 747d5c
  // has the @-version, the library use it.
Campbell Barton 747d5c
  bool m_vertical;
Campbell Barton 747d5c
Campbell Barton 747d5c
  Impl()
Campbell Barton 747d5c
      : m_qfontdb(NULL)
Campbell Barton 747d5c
      , m_loaded(false)
Campbell Barton 747d5c
      , m_currentFont(0)
Campbell Barton 747d5c
      , m_size(0)
Campbell Barton 747d5c
      , m_vertical(false) {}
Campbell Barton 747d5c
  ~Impl() { delete m_qfontdb; }
Campbell Barton 747d5c
};
Campbell Barton 747d5c
Campbell Barton 747d5c
//---------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
TFontManager::TFontManager() { m_pimpl = new TFontManager::Impl(); }
Campbell Barton 747d5c
Campbell Barton 747d5c
//---------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
TFontManager::~TFontManager() { delete m_pimpl; }
Campbell Barton 747d5c
Campbell Barton 747d5c
//---------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
TFontManager *TFontManager::instance() {
Campbell Barton 747d5c
  static TFontManager theManager;
Campbell Barton 747d5c
  return &theManager;
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//---------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
void TFontManager::loadFontNames() {
Campbell Barton 747d5c
  if (m_pimpl->m_loaded) return;
Campbell Barton 747d5c
Campbell Barton 747d5c
  m_pimpl->m_qfontdb = new QFontDatabase;
Campbell Barton 747d5c
Campbell Barton 747d5c
  if (m_pimpl->m_qfontdb->families().empty()) throw TFontLibraryLoadingError();
Campbell Barton 747d5c
Campbell Barton 747d5c
  m_pimpl->m_loaded = true;
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//---------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
void TFontManager::setFamily(const wstring family) {
Campbell Barton 747d5c
  if (m_pimpl->m_currentFamily == family) return;
Campbell Barton 747d5c
Campbell Barton 747d5c
  QString qFamily      = QString::fromStdWString(family);
Campbell Barton 747d5c
  QStringList families = m_pimpl->m_qfontdb->families();
Campbell Barton 747d5c
  if (!families.contains(qFamily)) throw TFontCreationError();
Campbell Barton 747d5c
Campbell Barton 747d5c
  m_pimpl->m_currentFamily = family;
Campbell Barton 747d5c
Shinya Kitaoka d1f6c4
// XXX: if current style is not valid for family, reset it?
Shinya Kitaoka d1f6c4
// doing so asserts when chosing a font in the GUI
Campbell Barton 747d5c
#if 0
Campbell Barton 747d5c
  QStringList styles = m_pimpl->m_qfontdb->styles(qFamily);
Campbell Barton 747d5c
  if (styles.contains(QString::fromStdWString(m_pimpl->m_currentTypeface))) {
Campbell Barton 747d5c
    m_pimpl->m_currentTypeface = L"";
Campbell Barton 747d5c
  }
Campbell Barton 747d5c
#endif
Campbell Barton 747d5c
  delete m_pimpl->m_currentFont;
Campbell Barton 747d5c
  m_pimpl->m_currentFont = new TFont(
Campbell Barton 747d5c
      m_pimpl->m_currentFamily, m_pimpl->m_currentTypeface, m_pimpl->m_size);
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//---------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
void TFontManager::setTypeface(const wstring typeface) {
Campbell Barton 747d5c
  if (m_pimpl->m_currentTypeface == typeface) return;
Campbell Barton 747d5c
Campbell Barton 747d5c
  QString qTypeface  = QString::fromStdWString(typeface);
Campbell Barton 747d5c
  QStringList styles = m_pimpl->m_qfontdb->styles(
Campbell Barton 747d5c
      QString::fromStdWString(m_pimpl->m_currentFamily));
Campbell Barton 747d5c
  if (!styles.contains(qTypeface)) {
Campbell Barton 747d5c
    throw TFontCreationError();
Campbell Barton 747d5c
  }
Campbell Barton 747d5c
Campbell Barton 747d5c
  m_pimpl->m_currentTypeface = typeface;
Campbell Barton 747d5c
Campbell Barton 747d5c
  delete m_pimpl->m_currentFont;
Campbell Barton 747d5c
  m_pimpl->m_currentFont = new TFont(
Campbell Barton 747d5c
      m_pimpl->m_currentFamily, m_pimpl->m_currentTypeface, m_pimpl->m_size);
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//---------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
void TFontManager::setSize(int size) {
Campbell Barton 747d5c
  if (m_pimpl->m_size == size) return;
Campbell Barton 747d5c
  m_pimpl->m_size = size;
Campbell Barton 747d5c
  delete m_pimpl->m_currentFont;
Campbell Barton 747d5c
  m_pimpl->m_currentFont = new TFont(
Campbell Barton 747d5c
      m_pimpl->m_currentFamily, m_pimpl->m_currentTypeface, m_pimpl->m_size);
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//---------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
wstring TFontManager::getCurrentFamily() const {
Campbell Barton 747d5c
  return m_pimpl->m_currentFamily;
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//---------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
wstring TFontManager::getCurrentTypeface() const {
Campbell Barton 747d5c
  return m_pimpl->m_currentTypeface;
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//---------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
TFont *TFontManager::getCurrentFont() {
Campbell Barton 747d5c
  if (m_pimpl->m_currentFont) {
Campbell Barton 747d5c
    return m_pimpl->m_currentFont;
Campbell Barton 747d5c
  }
Campbell Barton 747d5c
Campbell Barton 747d5c
  if (!m_pimpl->m_currentFont) {
Campbell Barton 747d5c
    loadFontNames();
Campbell Barton 747d5c
  }
Campbell Barton 747d5c
Campbell Barton 747d5c
  assert(!m_pimpl->m_qfontdb->families().empty());
Campbell Barton 747d5c
  setFamily(m_pimpl->m_qfontdb->families().first().toStdWString());
Campbell Barton 747d5c
Campbell Barton 747d5c
  return m_pimpl->m_currentFont;
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//---------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
void TFontManager::getAllFamilies(vector<wstring> &families) const {</wstring>
Campbell Barton 747d5c
  QStringList qFamilies = m_pimpl->m_qfontdb->families();
Campbell Barton 747d5c
Campbell Barton 747d5c
  families.clear();
Campbell Barton 747d5c
  families.reserve(qFamilies.count());
Campbell Barton 747d5c
Campbell Barton 747d5c
  QStringList::const_iterator it = qFamilies.begin();
Campbell Barton 747d5c
  for (; it != qFamilies.end(); ++it) {
Campbell Barton 747d5c
    families.push_back(it->toStdWString());
Campbell Barton 747d5c
  }
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//---------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
void TFontManager::getAllTypefaces(vector<wstring> &typefaces) const {</wstring>
Campbell Barton 747d5c
  typefaces.clear();
Campbell Barton 747d5c
Campbell Barton 747d5c
  QStringList qStyles = m_pimpl->m_qfontdb->styles(
Campbell Barton 747d5c
      QString::fromStdWString(m_pimpl->m_currentFamily));
Campbell Barton 747d5c
Campbell Barton 747d5c
  if (qStyles.empty()) return;
Campbell Barton 747d5c
Campbell Barton 747d5c
  typefaces.reserve(qStyles.count());
Campbell Barton 747d5c
  QStringList::const_iterator it_typeface = qStyles.begin();
Campbell Barton 747d5c
  for (; it_typeface != qStyles.end(); ++it_typeface) {
Campbell Barton 747d5c
    typefaces.push_back(it_typeface->toStdWString());
Campbell Barton 747d5c
  }
Campbell Barton 747d5c
}
Campbell Barton 747d5c
Campbell Barton 747d5c
//---------------------------------------------------------
Campbell Barton 747d5c
Campbell Barton 747d5c
void TFontManager::setVertical(bool vertical) {}
Campbell Barton 747d5c
Campbell Barton 747d5c
//---------------------------------------------------------