Browse Source

Gmt module: Add function Convert2PDF.

ObjPtr
Michael Uleysky 8 years ago
parent
commit
64e4613c67
  1. 1
      modules/gmt/modgmt.cpp
  2. 48
      modules/gmt/modgmt_map.cpp
  3. 55
      modules/gmt/modgmt_map.h

1
modules/gmt/modgmt.cpp

@ -45,6 +45,7 @@ int gmt_module_init(void* p)
RegisterFunction("Shift",GMT_LayerShift);
RegisterFunction("DrawFrame",GMT_DrawFrame);
RegisterFunction("Map",GMT_Map);
RegisterFunction("Convert2PDF",GMT_Convert2PDF);
CheckGhostscriptAbilities();
// Calculating bounding box is critical

48
modules/gmt/modgmt_map.cpp

@ -41,6 +41,12 @@ static int gs_bbox_callback(void *caller_handle, char *buf, int len)
}
static inline int eps2pdf(const std::string& eps, std::string* pdf, double res, uint ta=4, uint ga=4)
{
if(!gs_abilities.havepdf) return 1; // No pdf support
return GhostRun("-r"+ToString(res)+" -dEPSCrop -dTextAlphaBits="+ToString(ta)+" -dGraphicAlphaBits="+ToString(ga)+" -dNOPLATFONT -dSubsetFonts=true -dEmbedAllFonts=true -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode -dAutoFilterMonoImages=false -dMonoImageFilter=/CCITTFaxEncode -sDEVICE=pdfwrite -dMaxInlineImageSize=0 -c .setpdfwrite <</NeverEmbed [ ]>> setdistillerparams",eps,0,0,pdf);
}
// Creating eps map from sequence of layers
/*
Input:
@ -217,6 +223,48 @@ ObjectBase* GMT_Map(const ObjectList* input)
return new ObjectGMTMap(eps,bblx,bbly,bbrx,bbry);
}
fail:
return 0;
}
// Creating pdf from eps
/*
Input:
One argument must be GMTMap.
Optionally, resolution can be specified by pair with name resolution, res or r and double value. Default is 720.
*/
ObjectBase* GMT_Convert2PDF(const ObjectList* input)
{
if(!gs_abilities.havepdf) return 0; // No pdf support
double r;
bool suc=true;
const ObjectGMTMap* map=0;
{
SearchParameterWDefO<double,DoubleDefaultVal<720>,false,PMin<1> > res(input,"r","res","resolution");
r=res(&suc);
if(!suc) goto fail; // Error
}
{
for(ObjectList::ListValues::size_type i=0;i<input->Size();i++)
{
OBType<ObjectGMTMap> m(input->At(i));
if(m)
{
if(0!=map) goto fail; // Duplicate
map=m;
}
}
if(0==map) goto fail; // Map not found
}
{
std::string* out=new std::string;
int ret=eps2pdf(*(map->pValue()),out,r);
if(0!=ret) { delete out; goto fail; } // Something wrong
return new ObjectGMTMapPDF(out,map->Bblx(),map->Bbly(),map->Bbrx(),map->Bbry());
}
fail:
return 0;

55
modules/gmt/modgmt_map.h

@ -2,33 +2,70 @@
#define MODGMT_MAP_H
#include "common.h"
class ObjectGMTMap: public ObjectBase
class GMTBlob: public ObjectBase
{
GMTBlob()=delete;
protected:
std::shared_ptr<std::string> data;
int64_t bblx,bbly,bbrx,bbry;
ObjectGMTMap(const ObjectGMTMap* p):data(p->data),bblx(p->bblx),bbly(p->bbly),bbrx(p->bbrx),bbry(p->bbry) {};
public:
ObjectGMTMap(std::string* s, int nbblx, int nbbly, int nbbrx, int nbbry):data(s),bblx(nbblx),bbly(nbbly),bbrx(nbbrx),bbry(nbbry) {};
GMTBlob(const GMTBlob& b)=default;
GMTBlob(GMTBlob&& b)=default;
GMTBlob(const GMTBlob* p):data(p->data) {}
GMTBlob(std::string* s):data(s) {}
public:
// Pure virtual overrides
ObjectBase* Copy() const override {return new ObjectGMTMap(this);}
bool Print() const override
{
COUT(NORMAL)<<std::endl<<"Object type: "<<Type()<<std::endl;
return true;
}
std::string Type() const override {return "GMTMap";}
const int8_t* Blob(size_t* size) const override
{
*size=data->size();
return reinterpret_cast<const int8_t*>(data->data());
}
// Data access
const std::string* pValue() const {return data.get();}
};
class GMTMap: public GMTBlob
{
protected:
int32_t bblx,bbly,bbrx,bbry;
GMTMap(const GMTMap* p):GMTBlob(p),bblx(p->bblx),bbly(p->bbly),bbrx(p->bbrx),bbry(p->bbry) {};
GMTMap(std::string* s, int nbblx, int nbbly, int nbbrx, int nbbry):GMTBlob(s),bblx(nbblx),bbly(nbbly),bbrx(nbbrx),bbry(nbbry) {};
public:
int32_t Bblx() const {return bblx;}
int32_t Bbly() const {return bbly;}
int32_t Bbrx() const {return bbrx;}
int32_t Bbry() const {return bbry;}
};
class ObjectGMTMapPDF: public GMTMap
{
ObjectGMTMapPDF(const ObjectGMTMapPDF* p):GMTMap(p) {};
public:
ObjectGMTMapPDF(std::string* s, int nbblx, int nbbly, int nbbrx, int nbbry):GMTMap(s,nbblx,nbbly,nbbrx,nbbry) {};
// Pure virtual overrides
ObjectBase* Copy() const override {return new ObjectGMTMapPDF(this);}
std::string Type() const override {return "GMTMapPDF";}
};
class ObjectGMTMap: public GMTMap
{
ObjectGMTMap(const ObjectGMTMap* p):GMTMap(p) {};
public:
ObjectGMTMap(std::string* s, int nbblx, int nbbly, int nbbrx, int nbbry):GMTMap(s,nbblx,nbbly,nbbrx,nbbry) {};
// Pure virtual overrides
ObjectBase* Copy() const override {return new ObjectGMTMap(this);}
std::string Type() const override {return "GMTMap";}
};
// Creating eps map from set of layers
ObjectBase* GMT_Map(const ObjectList* input);
// Converting map to pdf
ObjectBase* GMT_Convert2PDF(const ObjectList* input);
#endif

Loading…
Cancel
Save