Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef MACOSX
Toshihiro Shimizu 890ddd
#ifndef __LP64__
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// Toonz stuff
Toshihiro Shimizu 890ddd
#include "tvectorimage.h"
Toshihiro Shimizu 890ddd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
#include "traster.h"
Toshihiro Shimizu 890ddd
#include "tfont.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// Qt stuff
Toshihiro Shimizu 890ddd
#include <qstring></qstring>
Toshihiro Shimizu 890ddd
#include <qsharedmemory></qsharedmemory>
Toshihiro Shimizu 890ddd
#include <qdebug></qdebug>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// tipc includes
Toshihiro Shimizu 890ddd
#include "tipc.h"
Toshihiro Shimizu 890ddd
#include "tipcmsg.h"
Toshihiro Shimizu 890ddd
#include "tipcsrv.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "t32fontmsg.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//  Local namespace stuff
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QDataStream &operator<<(QDataStream &ds, const TThickPoint &p) {
Shinya Kitaoka 120a6e
  ds << p.x << p.y << p.thick;
Shinya Kitaoka 120a6e
  return ds;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace tipc;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace font_io {
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void addParsers(tipc::Server *srv) {
Shinya Kitaoka 120a6e
  srv->addParser(new LoadFontNamesParser);
Shinya Kitaoka 120a6e
  srv->addParser(new GetAllFamiliesParser);
Shinya Kitaoka 120a6e
  srv->addParser(new GetAllTypefacesParser);
Shinya Kitaoka 120a6e
  srv->addParser(new SetFamilyParser);
Shinya Kitaoka 120a6e
  srv->addParser(new SetTypefaceParser);
Shinya Kitaoka 120a6e
  srv->addParser(new SetSizeParser);
Shinya Kitaoka 120a6e
  srv->addParser(new GetCurrentFamilyParser);
Shinya Kitaoka 120a6e
  srv->addParser(new GetCurrentTypefaceParser);
Shinya Kitaoka 120a6e
  srv->addParser(new GetDistanceParser);
Shinya Kitaoka 120a6e
  srv->addParser(new DrawCharVIParser);
Shinya Kitaoka 120a6e
  srv->addParser(new DrawCharGRParser);
Shinya Kitaoka 120a6e
  srv->addParser(new DrawCharCMParser);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    LoadFontNames Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LoadFontNamesParser::operator()(Message &msg) {
Shinya Kitaoka 120a6e
  TFontManager::instance()->loadFontNames();
Shinya Kitaoka 120a6e
  msg << clr << QString("ok");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    GetAllFamilies Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void GetAllFamiliesParser::operator()(Message &msg) {
Shinya Kitaoka 120a6e
  std::vector<std::wstring> families;</std::wstring>
Shinya Kitaoka 120a6e
  TFontManager::instance()->getAllFamilies(families);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  msg << clr << QString("ok") << families;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    GetAllTypefaces Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void GetAllTypefacesParser::operator()(Message &msg) {
Shinya Kitaoka 120a6e
  std::vector<std::wstring> typefaces;</std::wstring>
Shinya Kitaoka 120a6e
  TFontManager::instance()->getAllTypefaces(typefaces);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  msg << clr << QString("ok") << typefaces;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    SetFamily Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SetFamilyParser::operator()(Message &msg) {
Shinya Kitaoka 120a6e
  std::wstring family;
Shinya Kitaoka 120a6e
  msg >> family >> clr;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFontManager::instance()->setFamily(family);
Shinya Kitaoka 120a6e
  msg << QString("ok");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    SetTypeface Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SetTypefaceParser::operator()(Message &msg) {
Shinya Kitaoka 120a6e
  std::wstring typeface;
Shinya Kitaoka 120a6e
  msg >> typeface >> clr;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFontManager *fm = TFontManager::instance();
Shinya Kitaoka 120a6e
  fm->setTypeface(typeface);
Shinya Kitaoka 120a6e
  msg << QString("ok") << fm->getLineAscender() << fm->getLineDescender();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    SetSize Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SetSizeParser::operator()(Message &msg) {
Shinya Kitaoka 120a6e
  int size;
Shinya Kitaoka 120a6e
  msg >> size >> clr;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFontManager *fm = TFontManager::instance();
Shinya Kitaoka 120a6e
  fm->setSize(size);
Shinya Kitaoka 120a6e
  msg << QString("ok") << fm->getLineAscender() << fm->getLineDescender();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    GetCurrentFamily Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void GetCurrentFamilyParser::operator()(Message &msg) {
Shinya Kitaoka 120a6e
  std::wstring family(TFontManager::instance()->getCurrentFamily());
Shinya Kitaoka 120a6e
  msg << clr << QString("ok") << family;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    GetCurrentTypeface Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void GetCurrentTypefaceParser::operator()(Message &msg) {
Shinya Kitaoka 120a6e
  std::wstring typeface(TFontManager::instance()->getCurrentTypeface());
Shinya Kitaoka 120a6e
  msg << clr << QString("ok") << typeface;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    GetDistance Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void GetDistanceParser::operator()(Message &msg) {
Shinya Kitaoka 120a6e
  wchar_t firstChar, secondChar;
Shinya Kitaoka 120a6e
  msg >> firstChar >> secondChar >> clr;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPoint dist = TFontManager::instance()->getDistance(firstChar, secondChar);
Shinya Kitaoka 120a6e
  msg << QString("ok") << dist.x << dist.y;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    DrawCharVI Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DrawCharVIParser::operator()(Message &msg) {
Shinya Kitaoka 120a6e
  wchar_t charCode, nextCode;
Shinya Kitaoka 120a6e
  msg >> charCode >> nextCode >> clr;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TVectorImageP vi(new TVectorImage);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPoint p = TFontManager::instance()->drawChar(vi, charCode, nextCode);
Shinya Kitaoka 120a6e
  msg << QString("ok") << p.x << p.y;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Write the vector image
Shinya Kitaoka 120a6e
  std::vector<tthickpoint> cps;</tthickpoint>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  unsigned int i, strokesCount = vi->getStrokeCount();
Shinya Kitaoka 120a6e
  for (i = 0; i < strokesCount; ++i) {
Shinya Kitaoka 120a6e
    TStroke *stroke = vi->getStroke(i);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    cps.clear();
Shinya Kitaoka 120a6e
    stroke->getControlPoints(cps);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    msg << cps;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    DrawCharGR Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DrawCharGRParser::operator()(Message &msg) {
Shinya Kitaoka 120a6e
  int ink;
Shinya Kitaoka 120a6e
  QString shMemId;
Shinya Kitaoka 120a6e
  wchar_t charCode, nextCode;
Shinya Kitaoka 120a6e
  msg >> ink >> shMemId >> charCode >> nextCode >> clr;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Build the character
Shinya Kitaoka 120a6e
  TRasterGR8P charRas;
Shinya Kitaoka 120a6e
  TPoint unused;
Shinya Kitaoka 120a6e
  TPoint p =
Shinya Kitaoka 120a6e
      TFontManager::instance()->drawChar(charRas, unused, charCode, nextCode);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Retrieve the raster size
Shinya Kitaoka 120a6e
  int lx = charRas->getLx(), ly = charRas->getLy();
Shinya Kitaoka 120a6e
  int size = lx * ly * sizeof(TPixelGR8);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Request a shared memory segment of that size
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    tipc::DefaultMessageParser<shmem_request> msgParser;</shmem_request>
Shinya Kitaoka 120a6e
    Message shMsg;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    shMsg << shMemId << size << reset;
Shinya Kitaoka 120a6e
    msgParser(shMsg);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QString str;
Shinya Kitaoka 120a6e
    shMsg >> reset >> str;
Shinya Kitaoka 120a6e
    if (str != QString("ok")) {
Shinya Kitaoka 120a6e
      msg << QString("err");
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Copy charRas to the shared segment
Shinya Kitaoka 120a6e
  QSharedMemory shmem(shMemId);
Shinya Kitaoka 120a6e
  shmem.attach();
Shinya Kitaoka 120a6e
  shmem.lock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  memcpy(shmem.data(), charRas->getRawData(), size);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  shmem.unlock();
Shinya Kitaoka 120a6e
  shmem.detach();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  msg << QString("ok") << lx << ly << p.x << p.y;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    DrawCharCM Parser
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void DrawCharCMParser::operator()(Message &msg) {
Shinya Kitaoka 120a6e
  int ink;
Shinya Kitaoka 120a6e
  QString shMemId;
Shinya Kitaoka 120a6e
  wchar_t charCode, nextCode;
Shinya Kitaoka 120a6e
  msg >> ink >> shMemId >> charCode >> nextCode >> clr;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Build the character
Shinya Kitaoka 120a6e
  TRasterCM32P charRas;
Shinya Kitaoka 120a6e
  TPoint unused;
Shinya Kitaoka 120a6e
  TPoint p = TFontManager::instance()->drawChar(charRas, unused, ink, charCode,
Shinya Kitaoka 120a6e
                                                nextCode);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Retrieve the raster size
Shinya Kitaoka 120a6e
  int lx = charRas->getLx(), ly = charRas->getLy();
Shinya Kitaoka 120a6e
  int size = lx * ly * sizeof(TPixelCM32);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Request a shared memory segment of that size
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    tipc::DefaultMessageParser<shmem_request> msgParser;</shmem_request>
Shinya Kitaoka 120a6e
    Message shMsg;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    shMsg << shMemId << size << reset;
Shinya Kitaoka 120a6e
    msgParser(shMsg);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QString str;
Shinya Kitaoka 120a6e
    shMsg >> reset >> str;
Shinya Kitaoka 120a6e
    if (str != QString("ok")) {
Shinya Kitaoka 120a6e
      msg << QString("err");
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Copy charRas to the shared segment
Shinya Kitaoka 120a6e
  QSharedMemory shmem(shMemId);
Shinya Kitaoka 120a6e
  shmem.attach();
Shinya Kitaoka 120a6e
  shmem.lock();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  memcpy(shmem.data(), charRas->getRawData(), size);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  shmem.unlock();
Shinya Kitaoka 120a6e
  shmem.detach();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  msg << QString("ok") << lx << ly << p.x << p.y;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace font_io
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // !__LP64
Shinya Kitaoka 120a6e
#endif  // MACOSX