2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __LP64__
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Toonz includes
|
2016-03-19 06:57:51 +13:00
|
|
|
#include "tvectorimage.h"
|
|
|
|
#include "tstroke.h"
|
|
|
|
#include "trop.h"
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Qt includes
|
2016-03-19 06:57:51 +13:00
|
|
|
#include <QSharedMemory>
|
|
|
|
|
|
|
|
/*
|
|
|
|
なぜか tipc.h の
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
QDataStream& operator>>(QDataStream& ds, std::vector<T>& vec)
|
|
|
|
|
|
|
|
が T=TThickPoint でインスタンス化されようとして曖昧ですエラーになる
|
|
|
|
*/
|
2016-06-15 18:43:10 +12:00
|
|
|
// tipc includes
|
2016-03-19 06:57:51 +13:00
|
|
|
#include "tipc.h"
|
|
|
|
#include "t32bitsrv_wrap.h"
|
|
|
|
|
|
|
|
#include "tfont.h"
|
|
|
|
|
|
|
|
//**************************************************************************
|
|
|
|
// Local namespace stuff
|
|
|
|
//**************************************************************************
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
namespace {
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
QDataStream &operator>>(QDataStream &ds, TThickPoint &p) {
|
|
|
|
return ds >> p.x >> p.y >> p.thick;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void readVImage(TVectorImageP &vi, tipc::Message &msg) {
|
|
|
|
std::vector<TThickPoint> strokeCPs;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Read in all strokes
|
|
|
|
while (!msg.ds().atEnd()) {
|
|
|
|
strokeCPs.clear();
|
|
|
|
msg >> strokeCPs;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
vi->addStroke(new TStroke(strokeCPs));
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
vi->group(0, vi->getStrokeCount());
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
} // namespace
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//**************************************************************************
|
|
|
|
// TFontManager Private stuff
|
|
|
|
//**************************************************************************
|
|
|
|
|
|
|
|
/*
|
|
|
|
The proxied Impl private just caches some data of the actual
|
|
|
|
background counterpart
|
|
|
|
*/
|
|
|
|
struct TFontManager::Impl {
|
2016-06-15 18:43:10 +12:00
|
|
|
int m_ascender;
|
|
|
|
int m_descender;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
Impl() {}
|
|
|
|
~Impl() {}
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//**************************************************************************
|
|
|
|
// TFontManager Proxied implementation
|
|
|
|
//**************************************************************************
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TFontManager::TFontManager() { m_pimpl = new TFontManager::Impl(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TFontManager::~TFontManager() { delete m_pimpl; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TFontManager *TFontManager::instance() {
|
|
|
|
static TFontManager theInstance;
|
|
|
|
return &theInstance;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
//! This function is retained from old 32-bit legacy code.
|
|
|
|
//! Its use is now forbidden - use the TFontManager directly instead.
|
|
|
|
TFont *TFontManager::getCurrentFont() {
|
|
|
|
assert(false);
|
|
|
|
return 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
|
|
|
//!\note Throws TFontLibraryLoadingError if fonts could not be loaded
|
2016-06-15 18:43:10 +12:00
|
|
|
void TFontManager::loadFontNames() {
|
|
|
|
// Connect to the 32-bit background server process
|
|
|
|
QLocalSocket socket;
|
|
|
|
tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
|
|
|
|
t32bitsrv::srvCmdline());
|
|
|
|
|
|
|
|
tipc::Stream stream(&socket);
|
|
|
|
tipc::Message msg;
|
|
|
|
|
|
|
|
stream << (msg << QString("$FNTloadFontNames"));
|
|
|
|
if (tipc::readMessage(stream, msg) != "ok") throw TFontLibraryLoadingError();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
|
|
|
//!\note Throws TFontCreationError if the font could not be created, and
|
2016-06-15 18:43:10 +12:00
|
|
|
//! leaves the old font as current.
|
|
|
|
void TFontManager::setFamily(const std::wstring family) {
|
|
|
|
QLocalSocket socket;
|
|
|
|
tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
|
|
|
|
t32bitsrv::srvCmdline());
|
|
|
|
|
|
|
|
tipc::Stream stream(&socket);
|
|
|
|
tipc::Message msg;
|
|
|
|
|
|
|
|
stream << (msg << QString("$FNTsetFamily") << family);
|
|
|
|
if (tipc::readMessage(stream, msg) != "ok") throw TFontCreationError();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
|
|
|
//!\note Throws TFontCreationError if the font could not be created, and
|
2016-06-15 18:43:10 +12:00
|
|
|
//! leaves the old font as current.
|
|
|
|
void TFontManager::setTypeface(const std::wstring typeface) {
|
|
|
|
QLocalSocket socket;
|
|
|
|
tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
|
|
|
|
t32bitsrv::srvCmdline());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
tipc::Stream stream(&socket);
|
|
|
|
tipc::Message msg;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
stream << (msg << QString("$FNTsetTypeface") << typeface);
|
|
|
|
if (tipc::readMessage(stream, msg) != "ok") throw TFontCreationError();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Also, store the font's ascender and descender
|
|
|
|
msg >> m_pimpl->m_ascender >> m_pimpl->m_descender;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
std::wstring TFontManager::getCurrentFamily() const {
|
|
|
|
QLocalSocket socket;
|
|
|
|
tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
|
|
|
|
t32bitsrv::srvCmdline());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
tipc::Stream stream(&socket);
|
|
|
|
tipc::Message msg;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
stream << (msg << QString("$FNTgetCurrentFamily"));
|
|
|
|
if (tipc::readMessage(stream, msg) != "ok")
|
|
|
|
throw TException("Could not get font family");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
std::wstring family;
|
|
|
|
msg >> family;
|
|
|
|
return family;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
std::wstring TFontManager::getCurrentTypeface() const {
|
|
|
|
QLocalSocket socket;
|
|
|
|
tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
|
|
|
|
t32bitsrv::srvCmdline());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
tipc::Stream stream(&socket);
|
|
|
|
tipc::Message msg;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
stream << (msg << QString("$FNTgetCurrentTypeface"));
|
|
|
|
if (tipc::readMessage(stream, msg) != "ok")
|
|
|
|
throw TException("Could not get font typeface");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
std::wstring typeface;
|
|
|
|
msg >> typeface;
|
|
|
|
return typeface;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TFontManager::getAllFamilies(std::vector<std::wstring> &families) const {
|
|
|
|
QLocalSocket socket;
|
|
|
|
tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
|
|
|
|
t32bitsrv::srvCmdline());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
tipc::Stream stream(&socket);
|
|
|
|
tipc::Message msg;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
stream << (msg << QString("$FNTgetAllFamilies"));
|
|
|
|
if (tipc::readMessage(stream, msg) != "ok")
|
|
|
|
throw TException("Could not get font families");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
msg >> families;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TFontManager::getAllTypefaces(std::vector<std::wstring> &typefaces) const {
|
|
|
|
QLocalSocket socket;
|
|
|
|
tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
|
|
|
|
t32bitsrv::srvCmdline());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
tipc::Stream stream(&socket);
|
|
|
|
tipc::Message msg;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
stream << (msg << QString("$FNTgetAllTypefaces"));
|
|
|
|
if (tipc::readMessage(stream, msg) != "ok")
|
|
|
|
throw TException("Could not get font typefaces");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
msg >> typefaces;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TFontManager::setVertical(bool vertical) {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TFontManager::setSize(int size) {
|
|
|
|
QLocalSocket socket;
|
|
|
|
tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
|
|
|
|
t32bitsrv::srvCmdline());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
tipc::Stream stream(&socket);
|
|
|
|
tipc::Message msg;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
stream << (msg << QString("$FNTsetSize") << size);
|
|
|
|
if (tipc::readMessage(stream, msg) != "ok")
|
|
|
|
throw TException("Unexpected error");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Also, update ascender and descender
|
|
|
|
msg >> m_pimpl->m_ascender >> m_pimpl->m_descender;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TPoint TFontManager::getDistance(wchar_t firstChar, wchar_t secondChar) {
|
|
|
|
QLocalSocket socket;
|
|
|
|
tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
|
|
|
|
t32bitsrv::srvCmdline());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
tipc::Stream stream(&socket);
|
|
|
|
tipc::Message msg;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
stream << (msg << QString("$FNTgetDistance") << firstChar << secondChar);
|
|
|
|
if (tipc::readMessage(stream, msg) != "ok")
|
|
|
|
throw TException("Unexpected error");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TPoint d;
|
|
|
|
msg >> d.x >> d.y;
|
|
|
|
return d;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int TFontManager::getMaxHeight() {
|
|
|
|
return m_pimpl->m_ascender - m_pimpl->m_descender;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int TFontManager::getMaxWidth() {
|
|
|
|
assert(!"not implemented yet");
|
|
|
|
return 100;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool TFontManager::hasVertical() { return false; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool TFontManager::hasKerning() { return true; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int TFontManager::getLineAscender() { return m_pimpl->m_ascender; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int TFontManager::getLineDescender() { return m_pimpl->m_descender; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TPoint TFontManager::drawChar(TVectorImageP &outImage, wchar_t charcode,
|
|
|
|
wchar_t nextCode) {
|
|
|
|
QLocalSocket socket;
|
|
|
|
tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
|
|
|
|
t32bitsrv::srvCmdline());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
tipc::Stream stream(&socket);
|
|
|
|
tipc::Message msg;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
stream << (msg << QString("$FNTdrawCharVI") << charcode << nextCode);
|
|
|
|
if (tipc::readMessage(stream, msg) != "ok")
|
|
|
|
throw TException("Unexpected error");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TPoint ret;
|
|
|
|
msg >> ret.x >> ret.y;
|
|
|
|
::readVImage(outImage, msg);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
return ret;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TPoint TFontManager::drawChar(TRasterGR8P &outImage, TPoint &glyphOrigin,
|
|
|
|
wchar_t charcode, wchar_t nextCode) {
|
|
|
|
QLocalSocket socket;
|
|
|
|
tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
|
|
|
|
t32bitsrv::srvCmdline());
|
|
|
|
|
|
|
|
tipc::Stream stream(&socket);
|
|
|
|
tipc::Message msg;
|
|
|
|
|
|
|
|
QString shMemId(tipc::uniqueId()), res;
|
|
|
|
{
|
|
|
|
// Invoke the appropriate command
|
|
|
|
stream << (msg << QString("$FNTdrawCharGR") << shMemId << charcode
|
|
|
|
<< nextCode);
|
|
|
|
if (tipc::readMessage(stream, msg) != "ok")
|
|
|
|
throw TException("Unexpected error");
|
|
|
|
}
|
|
|
|
|
|
|
|
TDimension dim(0, 0);
|
|
|
|
msg >> dim.lx >> dim.ly;
|
|
|
|
TPoint ret;
|
|
|
|
msg >> ret.x >> ret.y;
|
|
|
|
|
|
|
|
// Create outImage
|
|
|
|
outImage = TRasterGR8P(dim.lx, dim.ly);
|
|
|
|
|
|
|
|
QSharedMemory shmem(shMemId);
|
|
|
|
shmem.attach();
|
|
|
|
shmem.lock();
|
|
|
|
|
|
|
|
// Copy the returned image to outImage
|
|
|
|
TRasterGR8P ras(dim.lx, dim.ly, dim.lx, (TPixelGR8 *)shmem.data());
|
|
|
|
TRop::copy(outImage, ras);
|
|
|
|
|
|
|
|
shmem.unlock();
|
|
|
|
shmem.detach();
|
|
|
|
|
|
|
|
// Release the shared segment
|
|
|
|
stream << (msg << tipc::clr << QString("$shmem_release") << shMemId);
|
|
|
|
if (tipc::readMessage(stream, msg) != "ok")
|
|
|
|
throw TException("Unexpected error");
|
|
|
|
|
|
|
|
return ret;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
|
|
|
|
TPoint TFontManager::drawChar(TRasterCM32P &outImage, TPoint &glyphOrigin,
|
2016-06-15 18:43:10 +12:00
|
|
|
int inkId, wchar_t charcode, wchar_t nextCode) {
|
|
|
|
QLocalSocket socket;
|
|
|
|
tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
|
|
|
|
t32bitsrv::srvCmdline());
|
|
|
|
|
|
|
|
tipc::Stream stream(&socket);
|
|
|
|
tipc::Message msg;
|
|
|
|
|
|
|
|
QString shMemId(tipc::uniqueId()), res;
|
|
|
|
{
|
|
|
|
// Invoke the appropriate command
|
|
|
|
stream << (msg << QString("$FNTdrawCharCM") << inkId << shMemId << charcode
|
|
|
|
<< nextCode);
|
|
|
|
if (tipc::readMessage(stream, msg) != "ok")
|
|
|
|
throw TException("Unexpected error");
|
|
|
|
}
|
|
|
|
|
|
|
|
TDimension dim(0, 0);
|
|
|
|
msg >> dim.lx >> dim.ly;
|
|
|
|
TPoint ret;
|
|
|
|
msg >> ret.x >> ret.y;
|
|
|
|
|
|
|
|
// Create outImage
|
|
|
|
outImage = TRasterCM32P(dim.lx, dim.ly);
|
|
|
|
|
|
|
|
QSharedMemory shmem(shMemId);
|
|
|
|
shmem.attach();
|
|
|
|
shmem.lock();
|
|
|
|
|
|
|
|
// Copy the returned image to outImage
|
|
|
|
TRasterCM32P ras(dim.lx, dim.ly, dim.lx, (TPixelCM32 *)shmem.data());
|
|
|
|
TRop::copy(outImage, ras);
|
|
|
|
|
|
|
|
shmem.unlock();
|
|
|
|
shmem.detach();
|
|
|
|
|
|
|
|
// Release the shared segment
|
|
|
|
stream << (msg << tipc::clr << QString("$shmem_release") << shMemId);
|
|
|
|
if (tipc::readMessage(stream, msg) != "ok")
|
|
|
|
throw TException("Unexpected error");
|
|
|
|
|
|
|
|
return ret;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|