+++ /dev/null
-// filtercxf.cpp
-//
-// Part of the Architektonas Project
-// Originally part of QCad Community Edition by Andrew Mustun
-// Extensively rewritten and refactored by James L. Hammons
-// Portions copyright (C) 2001-2003 RibbonSoft
-// Copyright (C) 2010 Underground Software
-// See the README and GPLv2 files for licensing and warranty information
-//
-// JLH = James L. Hammons <jlhamm@acm.org>
-//
-// Who When What
-// --- ---------- -----------------------------------------------------------
-// JLH 05/28/2010 Added this text. :-)
-//
-
-#include "filtercxf.h"
-
-#include <iostream>
-#include <fstream>
-#include <QtCore>
-
-#include "font.h"
-#include "utility.h"
-#include "system.h"
-
-/**
- * Default constructor.
- */
-FilterCXF::FilterCXF(): FilterInterface()
-{
- DEBUG->print("Setting up CXF filter...");
-
- addImportFormat(RS2::FormatCXF);
- addExportFormat(RS2::FormatCXF);
-}
-
-FilterCXF::~FilterCXF()
-{
-}
-
-/**
- * Implementation of the method used for RS_Import to communicate
- * with this filter.
- *
- * @param g The graphic in which the entities from the file
- * will be created or the graphics from which the entities are
- * taken to be stored in a file.
- */
-bool FilterCXF::fileImport(Drawing & g, const QString & file, RS2::FormatType /*type*/)
-{
- DEBUG->print("CXF Filter: importing file '%s'...", file.toLatin1().data());
-
- //this->graphic = &g;
- bool success = false;
-
- // Load font file as we normally do, but the font doesn't own the
- // letters (we'll add them to the graphic instead. Hence 'false').
- Font font(file, false);
- success = font.loadFont();
-
- if (!success)
- {
- DEBUG->print(Debug::D_WARNING, "Cannot open CXF file '%s'.", file.toLatin1().data());
- return false;
- }
-
- g.addVariable("Names", font.getNames().join(","), 0);
- g.addVariable("LetterSpacing", font.getLetterSpacing(), 0);
- g.addVariable("WordSpacing", font.getWordSpacing(), 0);
- g.addVariable("LineSpacingFactor", font.getLineSpacingFactor(), 0);
- g.addVariable("Authors", font.getAuthors().join(","), 0);
-
- if (!font.getEncoding().isEmpty())
- g.addVariable("Encoding", font.getEncoding(), 0);
-
- BlockList * letterList = font.getLetterList();
-
- for(uint i=0; i<font.countLetters(); i++)
- {
- Block * ch = font.letterAt(i);
-
- QString uCode;
- uCode.setNum(ch->getName().at(0).unicode(), 16);
-
- while (uCode.length() < 4)
- uCode = "0" + uCode;
-
- //ch->setName("[" + uCode + "] " + ch->getName());
- //letterList->rename(ch, QString("[%1]").arg(ch->getName()));
- letterList->rename(ch, QString("[%1] %2").arg(uCode).arg(ch->getName().at(0)));
-
- g.addBlock(ch, false);
- ch->reparent(&g);
- }
-
- g.addBlockNotification();
-
- return true;
-}
-
-/**
- * Implementation of the method used for RS_Export to communicate
- * with this filter.
- *
- * @param file Full path to the CXF file that will be written.
- */
-bool FilterCXF::fileExport(Drawing & g, const QString & file, RS2::FormatType /*type*/)
-{
- DEBUG->print("CXF Filter: exporting file '%s'...", file.toAscii().data());
-
- // crashes under windoze xp:
- //std::ofstream fout;
-
- DEBUG->print("FilterCXF::fileExport: open");
- //fout.open((const char*)file.local8Bit());
- FILE * fp;
-
- if ((fp = fopen((const char *)file.toLocal8Bit(), "wt")) != NULL)
- {
- DEBUG->print("FilterCXF::fileExport: open: OK");
- DEBUG->print("FilterCXF::fileExport: header");
-
- // header:
- fprintf(fp, "# Format: QCad II Font\n");
- fprintf(fp, "# Creator: %s\n", (const char *)SYSTEM->getAppName().toLocal8Bit());
- fprintf(fp, "# Version: %s\n", (const char *)SYSTEM->getAppVersion().toLocal8Bit());
-
- DEBUG->print("001");
- QString ns = g.getVariableString("Names", "");
-
- if (!ns.isEmpty())
- {
- QStringList names = ns.split(',');
- DEBUG->print("002");
-
- for(QStringList::Iterator it=names.begin(); it!=names.end(); ++it)
- {
- fprintf(fp, "# Name: %s\n", (const char*)((*it).toLocal8Bit()));
- }
- }
-
- DEBUG->print("003");
-
- QString es = g.getVariableString("Encoding", "");
-
- if (!es.isEmpty())
- fprintf(fp, "# Encoding: %s\n", (const char *)es.toLocal8Bit());
-
- DEBUG->print("004a");
-
- fprintf(fp, "# LetterSpacing: %f\n", g.getVariableDouble("LetterSpacing", 3.0));
- fprintf(fp, "# WordSpacing: %f\n", g.getVariableDouble("WordSpacing", 6.75));
- fprintf(fp, "# LineSpacingFactor: %f\n", g.getVariableDouble("LineSpacingFactor", 1.0));
-
- QString sa = g.getVariableString("Authors", "");
- DEBUG->print("authors: %s", (const char *)sa.toLocal8Bit());
-
- if (!sa.isEmpty())
- {
- QStringList authors = sa.split(',');
- DEBUG->print("006");
- DEBUG->print("count: %d", authors.count());
-
- QString a;
-
- for(QStringList::Iterator it2=authors.begin(); it2!=authors.end(); ++it2)
- {
- DEBUG->print("006a");
- a = QString(*it2);
- DEBUG->print("006b");
- DEBUG->print("string is: %s", a.toAscii().data());
- DEBUG->print("006b0");
- fprintf(fp, "# Author: ");
- DEBUG->print("006b1");
- fprintf(fp, "%s\n", a.toAscii().data());
- //fout << "# Author: " << a.ascii() << "\n";
- }
-
- DEBUG->print("007");
- }
-
- DEBUG->print("FilterCXF::fileExport: header: OK");
-
- DEBUG->print("008");
- // iterate through blocks (=letters of font)
- for(uint i=0; i<g.countBlocks(); ++i)
- {
- Block * blk = g.blockAt(i);
-
- DEBUG->print("block: %d", i);
- DEBUG->print("001");
-
- if (blk != NULL)
- {
- DEBUG->print("002");
- DEBUG->print("002a: %s", (const char *)(blk->getName().toLocal8Bit()));
-
- fprintf(fp, "\n%s\n", (const char *)(blk->getName().toLocal8Bit()));
-
- // iterate through entities of this letter:
- for(Entity * e=blk->firstEntity(RS2::ResolveAll); e!=NULL;
- e=blk->nextEntity(RS2::ResolveAll))
- {
- if (!e->isUndone())
- {
- DEBUG->print("004");
-
- // lines:
- if (e->rtti() == RS2::EntityLine)
- {
- Line * l = (Line *)e;
-
- fprintf(fp, "L %f,%f,%f,%f\n", l->getStartpoint().x, l->getStartpoint().y,
- l->getEndpoint().x, l->getEndpoint().y);
- }
- // arcs:
- else if (e->rtti() == RS2::EntityArc)
- {
- Arc * a = (Arc *)e;
-
- if (!a->isReversed())
- {
- fprintf(fp, "A ");
- }
- else
- {
- fprintf(fp, "AR ");
- }
-
- fprintf(fp, "%f,%f,%f,%f,%f\n", a->getCenter().x, a->getCenter().y,
- a->getRadius(), a->getAngle1() * ARAD, a->getAngle2() * ARAD);
- }
- // Ignore entities other than arcs / lines
- else
- {
- }
- }
-
- DEBUG->print("005");
- }
- DEBUG->print("006");
- }
- DEBUG->print("007");
- }
-
- //fout.close();
- fclose(fp);
- DEBUG->print("CXF Filter: exporting file: OK");
- return true;
- }
- else
- {
- DEBUG->print("CXF Filter: exporting file failed");
- }
-
- return false;
-}
-
-/**
- * Streams a double value to the given stream cutting away trailing 0's.
- *
- * @param value A double value. e.g. 2.700000
- */
-void FilterCXF::stream(std::ofstream & fs, double value)
-{
- fs << (const char *)Utility::doubleToString(value).toAscii().data();
-}