|
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>
|
|
shun_iwasawa |
df21fa |
#include <qpainter></qpainter>
|
|
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);
|
|
shun_iwasawa |
df21fa |
m_font.setBold(TFontManager::instance()->isBold(family, style));
|
|
shun_iwasawa |
df21fa |
m_font.setItalic(TFontManager::instance()->isItalic(family, 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 |
//-----------------------------------------------------------------------------
|
|
shun_iwasawa |
6c2748 |
// returns the offset (advance of the cursor) for the current character
|
|
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 |
|
|
shun_iwasawa |
df21fa |
TPoint TFont::drawChar(QImage &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 |
|
|
shun_iwasawa |
df21fa |
QImage image = raw.alphaMapForGlyph(indices[0], QRawFont::PixelAntialiasing);
|
|
shun_iwasawa |
df21fa |
if (image.format() != QImage::Format_Indexed8 &&
|
|
shun_iwasawa |
df21fa |
image.format() != QImage::Format_Alpha8)
|
|
Campbell Barton |
747d5c |
throw TException(L"bad QImage format " + image.format());
|
|
Campbell Barton |
747d5c |
|
|
shun_iwasawa |
df21fa |
QRectF boundingRect = raw.boundingRect(indices[0]);
|
|
Campbell Barton |
747d5c |
|
|
shun_iwasawa |
df21fa |
outImage = QImage(image.width(), raw.ascent() + raw.descent(),
|
|
shun_iwasawa |
df21fa |
QImage::Format_Grayscale8);
|
|
shun_iwasawa |
df21fa |
outImage.fill(255);
|
|
shun_iwasawa |
df21fa |
QPainter painter(&outImage);
|
|
shun_iwasawa |
df21fa |
painter.drawImage(0, boundingRect.top() + raw.ascent(), image);
|
|
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 {
|
|
shun_iwasawa |
df21fa |
QImage grayAppImage;
|
|
Campbell Barton |
747d5c |
this->drawChar(grayAppImage, unused, charcode, nextCharCode);
|
|
Campbell Barton |
747d5c |
|
|
shun_iwasawa |
df21fa |
int lx = grayAppImage.width();
|
|
shun_iwasawa |
df21fa |
int ly = grayAppImage.height();
|
|
Campbell Barton |
747d5c |
|
|
Campbell Barton |
747d5c |
outImage = TRasterCM32P(lx, ly);
|
|
shun_iwasawa |
df21fa |
outImage->lock();
|
|
Campbell Barton |
747d5c |
|
|
Campbell Barton |
747d5c |
assert(TPixelCM32::getMaxTone() == 255);
|
|
Campbell Barton |
747d5c |
TPixelCM32 bgColor(0, 0, TPixelCM32::getMaxTone());
|
|
Campbell Barton |
747d5c |
int ty = 0;
|
|
shun_iwasawa |
df21fa |
|
|
Campbell Barton |
747d5c |
for (int gy = ly - 1; gy >= 0; --gy, ++ty) {
|
|
shun_iwasawa |
df21fa |
uchar *srcPix = grayAppImage.scanLine(gy);
|
|
Campbell Barton |
747d5c |
TPixelCM32 *tarPix = outImage->pixels(ty);
|
|
Campbell Barton |
747d5c |
for (int x = 0; x < lx; ++x) {
|
|
shun_iwasawa |
df21fa |
int tone = (int)(*srcPix);
|
|
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 |
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 {
|
|
shun_iwasawa |
6c2748 |
QFontMetrics metrics(m_pimpl->m_font);
|
|
shun_iwasawa |
6c2748 |
return TPoint(metrics.width(QChar(firstChar)), 0);
|
|
shun_iwasawa |
6c2748 |
}
|
|
Campbell Barton |
747d5c |
|
|
shun_iwasawa |
6c2748 |
//-----------------------------------------------------------------------------
|
|
Campbell Barton |
747d5c |
|
|
shun_iwasawa |
6c2748 |
int TFont::getMaxWidth() const {
|
|
shun_iwasawa |
6c2748 |
QFontMetrics metrics(m_pimpl->m_font);
|
|
shun_iwasawa |
6c2748 |
return metrics.maxWidth();
|
|
shun_iwasawa |
6c2748 |
}
|
|
shun_iwasawa |
6c2748 |
//-----------------------------------------------------------------------------
|
|
Campbell Barton |
747d5c |
|
|
shun_iwasawa |
6c2748 |
int TFont::getLineAscender() const {
|
|
shun_iwasawa |
6c2748 |
QFontMetrics metrics(m_pimpl->m_font);
|
|
shun_iwasawa |
6c2748 |
return metrics.ascent();
|
|
Campbell Barton |
747d5c |
}
|
|
Campbell Barton |
747d5c |
|
|
Campbell Barton |
747d5c |
//-----------------------------------------------------------------------------
|
|
Campbell Barton |
747d5c |
|
|
shun_iwasawa |
6c2748 |
int TFont::getLineDescender() const {
|
|
Campbell Barton |
747d5c |
QFontMetrics metrics(m_pimpl->m_font);
|
|
shun_iwasawa |
6c2748 |
return metrics.descent();
|
|
Campbell Barton |
747d5c |
}
|
|
Campbell Barton |
747d5c |
|
|
Campbell Barton |
747d5c |
//-----------------------------------------------------------------------------
|
|
Campbell Barton |
747d5c |
|
|
shun_iwasawa |
6c2748 |
int TFont::getLineSpacing() const {
|
|
Campbell Barton |
747d5c |
QFontMetrics metrics(m_pimpl->m_font);
|
|
shun_iwasawa |
6c2748 |
return metrics.lineSpacing();
|
|
Campbell Barton |
747d5c |
}
|
|
shun_iwasawa |
6c2748 |
|
|
Campbell Barton |
747d5c |
//-----------------------------------------------------------------------------
|
|
Campbell Barton |
747d5c |
|
|
shun_iwasawa |
6c2748 |
int TFont::getHeight() const {
|
|
Campbell Barton |
747d5c |
QFontMetrics metrics(m_pimpl->m_font);
|
|
shun_iwasawa |
6c2748 |
return metrics.height();
|
|
Campbell Barton |
747d5c |
}
|
|
Campbell Barton |
747d5c |
|
|
Campbell Barton |
747d5c |
//-----------------------------------------------------------------------------
|
|
Campbell Barton |
747d5c |
|
|
shun_iwasawa |
6c2748 |
int TFont::getAverageCharWidth() const {
|
|
Campbell Barton |
747d5c |
QFontMetrics metrics(m_pimpl->m_font);
|
|
shun_iwasawa |
6c2748 |
return metrics.averageCharWidth();
|
|
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) {
|
|
manongjohn |
b66bc4 |
if (!m_pimpl->m_qfontdb->isPrivateFamily(*it))
|
|
manongjohn |
b66bc4 |
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 |
//---------------------------------------------------------
|
|
shun_iwasawa |
df21fa |
|
|
shun_iwasawa |
df21fa |
bool TFontManager::isBold(const QString &family, const QString &style) {
|
|
shun_iwasawa |
df21fa |
return m_pimpl->m_qfontdb->bold(family, style);
|
|
shun_iwasawa |
df21fa |
}
|
|
shun_iwasawa |
df21fa |
|
|
shun_iwasawa |
df21fa |
//---------------------------------------------------------
|
|
shun_iwasawa |
df21fa |
|
|
shun_iwasawa |
df21fa |
bool TFontManager::isItalic(const QString &family, const QString &style) {
|
|
shun_iwasawa |
df21fa |
return m_pimpl->m_qfontdb->italic(family, style);
|
|
shun_iwasawa |
df21fa |
}
|