2016-06-23 22:40:37 +12:00
|
|
|
|
|
|
|
|
|
|
|
// character_manager.cpp: implementation of the TFont class
|
|
|
|
// for FreeType 2.
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QFont>
|
|
|
|
#include <QFontDatabase>
|
|
|
|
#include <QFontMetrics>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QPainterPath>
|
2017-06-22 14:50:35 +12:00
|
|
|
#include <QPainter>
|
2016-06-23 22:40:37 +12:00
|
|
|
#include <QRawFont>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "tpixelgr.h"
|
|
|
|
#include "tfont.h"
|
|
|
|
#include "tstroke.h"
|
|
|
|
#include "tcurves.h"
|
|
|
|
#include "traster.h"
|
|
|
|
#include "tmathutil.h"
|
|
|
|
#include "tvectorimage.h"
|
2022-01-28 11:06:59 +13:00
|
|
|
#include "trasterimage.h"
|
|
|
|
#include "toonz/trasterimageutils.h"
|
|
|
|
|
|
|
|
#include "trop.h"
|
|
|
|
|
2016-06-23 22:40:37 +12:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
struct TFont::Impl {
|
|
|
|
bool m_hasKerning;
|
|
|
|
int m_hasVertical;
|
|
|
|
QFont m_font;
|
|
|
|
// XXX:cache a QFontMetrics m_metrics; ?
|
|
|
|
// XXX:cache a QRawFont m_raw; ?
|
|
|
|
|
|
|
|
// KerningPairs m_kerningPairs;
|
|
|
|
|
|
|
|
Impl(const QString &family, const QString &style, int size);
|
|
|
|
~Impl();
|
|
|
|
|
|
|
|
// void getChar();
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
TFont::TFont(const wstring family, const wstring face, int size) {
|
|
|
|
m_pimpl = new Impl(QString::fromStdWString(family),
|
|
|
|
QString::fromStdWString(face), size);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
TFont::~TFont() { delete m_pimpl; }
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
TFont::Impl::Impl(const QString &family, const QString &style, int size) {
|
|
|
|
m_font = QFont(family, size);
|
2017-06-22 14:50:35 +12:00
|
|
|
m_font.setBold(TFontManager::instance()->isBold(family, style));
|
|
|
|
m_font.setItalic(TFontManager::instance()->isItalic(family, style));
|
2016-06-23 22:40:37 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
TFont::Impl::~Impl() {}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-08-23 17:51:40 +12:00
|
|
|
// returns the offset (advance of the cursor) for the current character
|
2016-06-23 22:40:37 +12:00
|
|
|
TPoint TFont::drawChar(TVectorImageP &image, wchar_t charcode,
|
|
|
|
wchar_t nextCharCode) const {
|
|
|
|
QRawFont raw(QRawFont::fromFont(m_pimpl->m_font));
|
|
|
|
|
|
|
|
QChar chars[2] = {charcode, nextCharCode};
|
|
|
|
quint32 indices[2];
|
|
|
|
int count = 2;
|
|
|
|
|
|
|
|
if (!raw.glyphIndexesForChars(chars, 2, indices, &count) || count < 1)
|
|
|
|
return TPoint(0, 0);
|
|
|
|
QPainterPath path = raw.pathForGlyph(indices[0]);
|
|
|
|
|
|
|
|
// empty glyph, nothing to do
|
|
|
|
if (path.elementCount() < 1) return getDistance(charcode, nextCharCode);
|
|
|
|
|
|
|
|
// force closing the last path
|
2016-06-29 18:17:12 +12:00
|
|
|
if (path.elementAt(path.elementCount() - 1).type !=
|
|
|
|
QPainterPath::MoveToElement) {
|
2016-06-23 22:40:37 +12:00
|
|
|
path.moveTo(0.0, 0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int i, n = path.elementCount();
|
|
|
|
int strokes = 0;
|
|
|
|
std::vector<TThickPoint> points;
|
|
|
|
|
|
|
|
TThickPoint pts[4];
|
|
|
|
int nCubicPts = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
QPainterPath::Element e = path.elementAt(i);
|
|
|
|
e.y = -e.y;
|
|
|
|
|
|
|
|
switch (e.type) {
|
|
|
|
case QPainterPath::MoveToElement:
|
|
|
|
if (!points.empty()) {
|
|
|
|
if (points.back() != points.front()) {
|
|
|
|
points.push_back(0.5 * (points.back() + points.front()));
|
|
|
|
points.push_back(points.front());
|
|
|
|
}
|
|
|
|
|
|
|
|
TStroke *stroke = new TStroke(points);
|
|
|
|
stroke->setSelfLoop(true);
|
|
|
|
image->addStroke(stroke);
|
|
|
|
strokes++;
|
|
|
|
points.clear();
|
|
|
|
}
|
|
|
|
points.push_back(TThickPoint(e.x, e.y, 0));
|
|
|
|
break;
|
|
|
|
case QPainterPath::LineToElement: {
|
|
|
|
TThickPoint p0 = points.back();
|
|
|
|
TThickPoint p1 = TThickPoint(e.x, e.y, 0);
|
|
|
|
points.push_back((p0 + p1) * 0.5);
|
|
|
|
points.push_back(p1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QPainterPath::CurveToElement:
|
|
|
|
pts[0] = points.back();
|
|
|
|
pts[1] = TThickPoint(e.x, e.y, 0);
|
|
|
|
nCubicPts = 2;
|
|
|
|
break;
|
|
|
|
case QPainterPath::CurveToDataElement:
|
|
|
|
pts[nCubicPts++] = TThickPoint(e.x, e.y, 0);
|
|
|
|
if (nCubicPts == 4) {
|
|
|
|
vector<TThickQuadratic *> chunkArray;
|
|
|
|
computeQuadraticsFromCubic(pts[0], pts[1], pts[2], pts[3], 0.09,
|
|
|
|
chunkArray);
|
|
|
|
|
|
|
|
for (int j = 0; j < chunkArray.size(); j++) {
|
|
|
|
points.push_back(chunkArray[j]->getP1());
|
|
|
|
points.push_back(chunkArray[j]->getP2());
|
|
|
|
}
|
|
|
|
nCubicPts = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strokes > 1) image->group(0, strokes);
|
|
|
|
|
|
|
|
return getDistance(charcode, nextCharCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2017-06-22 14:50:35 +12:00
|
|
|
TPoint TFont::drawChar(QImage &outImage, TPoint &unused, wchar_t charcode,
|
2016-06-23 22:40:37 +12:00
|
|
|
wchar_t nextCharCode) const {
|
|
|
|
QRawFont raw(QRawFont::fromFont(m_pimpl->m_font));
|
|
|
|
|
|
|
|
QChar chars[2] = {charcode, nextCharCode};
|
|
|
|
quint32 indices[2];
|
|
|
|
int count = 2;
|
|
|
|
|
|
|
|
if (!raw.glyphIndexesForChars(chars, 2, indices, &count) || count < 1) {
|
|
|
|
return TPoint(0, 0);
|
|
|
|
}
|
|
|
|
|
2021-02-21 05:33:16 +13:00
|
|
|
// Workaround for unix when the user using the space character:
|
|
|
|
// alphaMapForGlyph with a space character returns an invalid
|
|
|
|
// QImage for some reason.
|
|
|
|
// Bug 3604: https://github.com/opentoonz/opentoonz/issues/3604
|
2022-01-21 16:15:28 +13:00
|
|
|
// (21/1/2022) Use this workaround for all platforms as the crash also occured
|
|
|
|
// in windows when the display is scaled up.
|
|
|
|
if (chars[0].isSpace()) {
|
2022-03-17 01:25:38 +13:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
2022-01-21 16:15:28 +13:00
|
|
|
int w = QFontMetrics(m_pimpl->m_font).horizontalAdvance(chars[0]);
|
2022-02-21 05:55:24 +13:00
|
|
|
#else
|
|
|
|
int w = raw.averageCharWidth();
|
|
|
|
#endif
|
|
|
|
|
2022-01-21 16:15:28 +13:00
|
|
|
outImage =
|
|
|
|
QImage(w, raw.ascent() + raw.descent(), QImage::Format_Grayscale8);
|
|
|
|
outImage.fill(255);
|
|
|
|
return getDistance(charcode, nextCharCode);
|
2021-02-21 05:33:16 +13:00
|
|
|
}
|
2017-06-22 14:50:35 +12:00
|
|
|
QImage image = raw.alphaMapForGlyph(indices[0], QRawFont::PixelAntialiasing);
|
|
|
|
if (image.format() != QImage::Format_Indexed8 &&
|
|
|
|
image.format() != QImage::Format_Alpha8)
|
2016-06-23 22:40:37 +12:00
|
|
|
throw TException(L"bad QImage format " + image.format());
|
|
|
|
|
2017-06-22 14:50:35 +12:00
|
|
|
QRectF boundingRect = raw.boundingRect(indices[0]);
|
2016-06-23 22:40:37 +12:00
|
|
|
|
2017-06-22 14:50:35 +12:00
|
|
|
outImage = QImage(image.width(), raw.ascent() + raw.descent(),
|
|
|
|
QImage::Format_Grayscale8);
|
|
|
|
outImage.fill(255);
|
|
|
|
QPainter painter(&outImage);
|
|
|
|
painter.drawImage(0, boundingRect.top() + raw.ascent(), image);
|
2016-06-23 22:40:37 +12:00
|
|
|
|
|
|
|
return getDistance(charcode, nextCharCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
TPoint TFont::drawChar(TRasterCM32P &outImage, TPoint &unused, int inkId,
|
|
|
|
wchar_t charcode, wchar_t nextCharCode) const {
|
2017-06-22 14:50:35 +12:00
|
|
|
QImage grayAppImage;
|
2016-06-23 22:40:37 +12:00
|
|
|
this->drawChar(grayAppImage, unused, charcode, nextCharCode);
|
|
|
|
|
2017-06-22 14:50:35 +12:00
|
|
|
int lx = grayAppImage.width();
|
|
|
|
int ly = grayAppImage.height();
|
2016-06-23 22:40:37 +12:00
|
|
|
|
|
|
|
outImage = TRasterCM32P(lx, ly);
|
2017-06-22 14:50:35 +12:00
|
|
|
outImage->lock();
|
2016-06-23 22:40:37 +12:00
|
|
|
|
|
|
|
assert(TPixelCM32::getMaxTone() == 255);
|
|
|
|
TPixelCM32 bgColor(0, 0, TPixelCM32::getMaxTone());
|
|
|
|
int ty = 0;
|
2017-06-22 14:50:35 +12:00
|
|
|
|
2016-06-23 22:40:37 +12:00
|
|
|
for (int gy = ly - 1; gy >= 0; --gy, ++ty) {
|
2017-06-22 14:50:35 +12:00
|
|
|
uchar *srcPix = grayAppImage.scanLine(gy);
|
2016-06-23 22:40:37 +12:00
|
|
|
TPixelCM32 *tarPix = outImage->pixels(ty);
|
|
|
|
for (int x = 0; x < lx; ++x) {
|
2017-06-22 14:50:35 +12:00
|
|
|
int tone = (int)(*srcPix);
|
2016-06-23 22:40:37 +12:00
|
|
|
|
|
|
|
if (tone == 255)
|
|
|
|
*tarPix = bgColor;
|
|
|
|
else
|
|
|
|
*tarPix = TPixelCM32(inkId, 0, tone);
|
|
|
|
|
|
|
|
++srcPix;
|
|
|
|
++tarPix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
outImage->unlock();
|
|
|
|
|
|
|
|
return getDistance(charcode, nextCharCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-01-28 11:06:59 +13:00
|
|
|
|
|
|
|
TPoint TFont::drawChar(TRaster32P &outImage, TPoint &unused, TPixel32 color,
|
|
|
|
wchar_t charcode, wchar_t nextCharCode) const {
|
|
|
|
QImage grayAppImage;
|
|
|
|
this->drawChar(grayAppImage, unused, charcode, nextCharCode);
|
|
|
|
|
|
|
|
int lx = grayAppImage.width();
|
|
|
|
int ly = grayAppImage.height();
|
|
|
|
|
|
|
|
TRaster32P ras(lx, ly, lx, (TPixelRGBM32 *)grayAppImage.bits(), false);
|
|
|
|
|
|
|
|
outImage = TRaster32P(lx, ly);
|
|
|
|
outImage->lock();
|
|
|
|
|
|
|
|
TPixel32 bgColor(0, 0, 0, 0);
|
|
|
|
int ty = 0;
|
|
|
|
|
|
|
|
for (int gy = ly - 1; gy >= 0; --gy, ++ty) {
|
|
|
|
uchar *srcPix = grayAppImage.scanLine(gy);
|
|
|
|
TPixel32 *tarPix = outImage->pixels(ty);
|
|
|
|
for (int x = 0; x < lx; ++x) {
|
|
|
|
int m = (int)(*srcPix);
|
|
|
|
|
|
|
|
if (m == 255)
|
|
|
|
*tarPix = bgColor;
|
|
|
|
else
|
|
|
|
*tarPix = color;
|
|
|
|
|
|
|
|
++srcPix;
|
|
|
|
++tarPix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
outImage->unlock();
|
|
|
|
|
|
|
|
return getDistance(charcode, nextCharCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2016-06-23 22:40:37 +12:00
|
|
|
|
|
|
|
TPoint TFont::getDistance(wchar_t firstChar, wchar_t secondChar) const {
|
2017-08-23 17:51:40 +12:00
|
|
|
QFontMetrics metrics(m_pimpl->m_font);
|
|
|
|
return TPoint(metrics.width(QChar(firstChar)), 0);
|
|
|
|
}
|
2016-06-23 22:40:37 +12:00
|
|
|
|
2017-08-23 17:51:40 +12:00
|
|
|
//-----------------------------------------------------------------------------
|
2016-06-23 22:40:37 +12:00
|
|
|
|
2017-08-23 17:51:40 +12:00
|
|
|
int TFont::getMaxWidth() const {
|
|
|
|
QFontMetrics metrics(m_pimpl->m_font);
|
|
|
|
return metrics.maxWidth();
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
2016-06-23 22:40:37 +12:00
|
|
|
|
2017-08-23 17:51:40 +12:00
|
|
|
int TFont::getLineAscender() const {
|
|
|
|
QFontMetrics metrics(m_pimpl->m_font);
|
|
|
|
return metrics.ascent();
|
2016-06-23 22:40:37 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2017-08-23 17:51:40 +12:00
|
|
|
int TFont::getLineDescender() const {
|
2016-06-23 22:40:37 +12:00
|
|
|
QFontMetrics metrics(m_pimpl->m_font);
|
2017-08-23 17:51:40 +12:00
|
|
|
return metrics.descent();
|
2016-06-23 22:40:37 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2017-08-23 17:51:40 +12:00
|
|
|
int TFont::getLineSpacing() const {
|
2016-06-23 22:40:37 +12:00
|
|
|
QFontMetrics metrics(m_pimpl->m_font);
|
2017-08-23 17:51:40 +12:00
|
|
|
return metrics.lineSpacing();
|
2016-06-23 22:40:37 +12:00
|
|
|
}
|
2017-08-23 17:51:40 +12:00
|
|
|
|
2016-06-23 22:40:37 +12:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2017-08-23 17:51:40 +12:00
|
|
|
int TFont::getHeight() const {
|
2016-06-23 22:40:37 +12:00
|
|
|
QFontMetrics metrics(m_pimpl->m_font);
|
2017-08-23 17:51:40 +12:00
|
|
|
return metrics.height();
|
2016-06-23 22:40:37 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2017-08-23 17:51:40 +12:00
|
|
|
int TFont::getAverageCharWidth() const {
|
2016-06-23 22:40:37 +12:00
|
|
|
QFontMetrics metrics(m_pimpl->m_font);
|
2017-08-23 17:51:40 +12:00
|
|
|
return metrics.averageCharWidth();
|
2016-06-23 22:40:37 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool TFont::hasKerning() const { return m_pimpl->m_font.kerning(); }
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool TFont::hasVertical() const {
|
|
|
|
// FIXME
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//==================== TFontManager =====================================
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
struct TFontManager::Impl {
|
|
|
|
QFontDatabase *m_qfontdb;
|
|
|
|
bool m_loaded;
|
|
|
|
|
|
|
|
TFont *m_currentFont;
|
|
|
|
wstring m_currentFamily;
|
|
|
|
wstring m_currentTypeface;
|
|
|
|
int m_size;
|
|
|
|
|
|
|
|
// this option is set by library user when he wants to write vertically.
|
|
|
|
// In this implementation, if m_vertical is true and the font
|
|
|
|
// has the @-version, the library use it.
|
|
|
|
bool m_vertical;
|
|
|
|
|
|
|
|
Impl()
|
|
|
|
: m_qfontdb(NULL)
|
|
|
|
, m_loaded(false)
|
|
|
|
, m_currentFont(0)
|
|
|
|
, m_size(0)
|
|
|
|
, m_vertical(false) {}
|
|
|
|
~Impl() { delete m_qfontdb; }
|
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
TFontManager::TFontManager() { m_pimpl = new TFontManager::Impl(); }
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
TFontManager::~TFontManager() { delete m_pimpl; }
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
TFontManager *TFontManager::instance() {
|
|
|
|
static TFontManager theManager;
|
|
|
|
return &theManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TFontManager::loadFontNames() {
|
|
|
|
if (m_pimpl->m_loaded) return;
|
|
|
|
|
|
|
|
m_pimpl->m_qfontdb = new QFontDatabase;
|
|
|
|
|
|
|
|
if (m_pimpl->m_qfontdb->families().empty()) throw TFontLibraryLoadingError();
|
|
|
|
|
|
|
|
m_pimpl->m_loaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TFontManager::setFamily(const wstring family) {
|
|
|
|
if (m_pimpl->m_currentFamily == family) return;
|
|
|
|
|
|
|
|
QString qFamily = QString::fromStdWString(family);
|
|
|
|
QStringList families = m_pimpl->m_qfontdb->families();
|
|
|
|
if (!families.contains(qFamily)) throw TFontCreationError();
|
|
|
|
|
|
|
|
m_pimpl->m_currentFamily = family;
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
// XXX: if current style is not valid for family, reset it?
|
2021-07-08 13:39:28 +12:00
|
|
|
// doing so asserts when choosing a font in the GUI
|
2016-06-23 22:40:37 +12:00
|
|
|
#if 0
|
|
|
|
QStringList styles = m_pimpl->m_qfontdb->styles(qFamily);
|
|
|
|
if (styles.contains(QString::fromStdWString(m_pimpl->m_currentTypeface))) {
|
|
|
|
m_pimpl->m_currentTypeface = L"";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
delete m_pimpl->m_currentFont;
|
|
|
|
m_pimpl->m_currentFont = new TFont(
|
|
|
|
m_pimpl->m_currentFamily, m_pimpl->m_currentTypeface, m_pimpl->m_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TFontManager::setTypeface(const wstring typeface) {
|
|
|
|
if (m_pimpl->m_currentTypeface == typeface) return;
|
|
|
|
|
|
|
|
QString qTypeface = QString::fromStdWString(typeface);
|
|
|
|
QStringList styles = m_pimpl->m_qfontdb->styles(
|
|
|
|
QString::fromStdWString(m_pimpl->m_currentFamily));
|
|
|
|
if (!styles.contains(qTypeface)) {
|
|
|
|
throw TFontCreationError();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pimpl->m_currentTypeface = typeface;
|
|
|
|
|
|
|
|
delete m_pimpl->m_currentFont;
|
|
|
|
m_pimpl->m_currentFont = new TFont(
|
|
|
|
m_pimpl->m_currentFamily, m_pimpl->m_currentTypeface, m_pimpl->m_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TFontManager::setSize(int size) {
|
|
|
|
if (m_pimpl->m_size == size) return;
|
|
|
|
m_pimpl->m_size = size;
|
|
|
|
delete m_pimpl->m_currentFont;
|
|
|
|
m_pimpl->m_currentFont = new TFont(
|
|
|
|
m_pimpl->m_currentFamily, m_pimpl->m_currentTypeface, m_pimpl->m_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
wstring TFontManager::getCurrentFamily() const {
|
|
|
|
return m_pimpl->m_currentFamily;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
wstring TFontManager::getCurrentTypeface() const {
|
|
|
|
return m_pimpl->m_currentTypeface;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
TFont *TFontManager::getCurrentFont() {
|
|
|
|
if (m_pimpl->m_currentFont) {
|
|
|
|
return m_pimpl->m_currentFont;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_pimpl->m_currentFont) {
|
|
|
|
loadFontNames();
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(!m_pimpl->m_qfontdb->families().empty());
|
|
|
|
setFamily(m_pimpl->m_qfontdb->families().first().toStdWString());
|
|
|
|
|
|
|
|
return m_pimpl->m_currentFont;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TFontManager::getAllFamilies(vector<wstring> &families) const {
|
|
|
|
QStringList qFamilies = m_pimpl->m_qfontdb->families();
|
|
|
|
|
|
|
|
families.clear();
|
|
|
|
families.reserve(qFamilies.count());
|
|
|
|
|
|
|
|
QStringList::const_iterator it = qFamilies.begin();
|
|
|
|
for (; it != qFamilies.end(); ++it) {
|
2018-08-06 18:46:52 +12:00
|
|
|
if (!m_pimpl->m_qfontdb->isPrivateFamily(*it))
|
|
|
|
families.push_back(it->toStdWString());
|
2016-06-23 22:40:37 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TFontManager::getAllTypefaces(vector<wstring> &typefaces) const {
|
|
|
|
typefaces.clear();
|
|
|
|
|
|
|
|
QStringList qStyles = m_pimpl->m_qfontdb->styles(
|
|
|
|
QString::fromStdWString(m_pimpl->m_currentFamily));
|
|
|
|
|
|
|
|
if (qStyles.empty()) return;
|
|
|
|
|
|
|
|
typefaces.reserve(qStyles.count());
|
|
|
|
QStringList::const_iterator it_typeface = qStyles.begin();
|
|
|
|
for (; it_typeface != qStyles.end(); ++it_typeface) {
|
|
|
|
typefaces.push_back(it_typeface->toStdWString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void TFontManager::setVertical(bool vertical) {}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2017-06-22 14:50:35 +12:00
|
|
|
|
|
|
|
bool TFontManager::isBold(const QString &family, const QString &style) {
|
|
|
|
return m_pimpl->m_qfontdb->bold(family, style);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
bool TFontManager::isItalic(const QString &family, const QString &style) {
|
|
|
|
return m_pimpl->m_qfontdb->italic(family, style);
|
|
|
|
}
|