Browse Source

Gmt module: Conversion function for GMTFont now using new parameter reading scheme and error reporting.

gmtdatadir
Michael Uleysky 8 years ago
parent
commit
c27463ba62
  1. 95
      modules/gmt/modgmt_func.h

95
modules/gmt/modgmt_func.h

@ -176,6 +176,7 @@ using Base2Proj =Base2Struct<struct gmt_projection>;
using Base2Color =Base2Struct<struct gmt_color>;
using Base2Dash =Base2Struct<struct gmt_dash>;
using Base2Pen =Base2Struct<struct gmt_pen>;
using Base2Font =Base2Struct<struct gmt_font>;
// Simple aliases of convertors with default values
using Base2StringD=Base2StructD<std::string>;
@ -982,90 +983,52 @@ class Convert2Struct<struct gmt_font, ObjectList>
{
public:
struct gmt_font operator()(const ObjectList* input, bool* issuc) const
struct gmt_font operator()(const ObjectList* input, bool* issuc, std::string& err) const
{
struct gmt_font f;
auto size=input->Size();
if(1==size) // Cases 1, 2, 4 and 5
if(1==input->Size()) // Cases 1, 2, 4 and 5
{
Base2Font font(input,0);
Base2Font font;
bool suc=true;
f=font(&suc);
f=font.Convert(input->At(0),&suc,err);
if(!suc) goto fail; // Conversion failed
return f;
}
// Case 3
{
bool casevalid=false;
bool upd;
// Case 6 and 7
{
BaseMT2Font updarg(input,"font");
bool suc=true;
f=updarg(&upd,&suc);
if(upd && !suc) goto fail; // Conversion failed or too many arguments
}
OPosPar<Base2PosD> size("size",gmt_font::default_size);
OPosPar<Base2ColorD> color("color",0.0);
OPosPar<Base2StringD> family("family",gmt_font::default_family);
if(!upd)
{
// default font is Times-Roman, 12pt, black
f.size=gmt_font::default_size;
f.color.Convert(0);
f.family=gmt_font::default_family;
ParsePositionalParameters params(input,size,family,color);
if(!params) goto case3; // May be case3 will work
f.color=color;
f.size=size;
f.family=family;
return f;
}
// Size
{
BaseM2Width s(input,"s","size");
if(s.Exist())
// Case 3
case3:
{
bool suc=true;
f.size=s(&suc);
if(!suc) goto fail; // Parsing error
casevalid=true;
}
}
ONFPar<Base2Font,ObjectGMTFont> font("f[on]t");
ONFPar<Base2ColorD,ObjectGMTColor> color("color",0);
ONFPar<Base2StringD,ObjectString> family("f[a]m[i]ly",gmt_font::default_family);
ONFPar<Base2PosD,ObjectReal> size("size",gmt_font::default_size);
// Family
{
BaseM2String family(input,"family","f");
if(family.Exist())
{
bool suc=true;
f.family=family(&suc);
if(!suc) goto fail; // Parsing error
casevalid=true;
}
}
{ParseNamedParameters params(input,font,color,family,size); if(!params) {err=params.Error(); goto fail;} } // Fail to parse by variant 3
// Color
{
BaseMT2Color color(input,"color","c");
if(color.Exist())
{
bool suc=true;
f.color=color(&suc);
if(!suc) goto fail; // Parsing error
casevalid=true;
}
}
bool upd=font.Exist();
if(upd) f=font;
if(color.Exist() || !upd) f.color =color;
if(family.Exist() || !upd) f.family=family;
if(size.Exist() || !upd) f.size =size;
if(casevalid || upd) return f; // Pen created or updated
}
// Case 6 and 7
if(2==size || 3==size)
{
Base2Width s(input,0);
Base2String fam(input,1);
Base2Color c(input,2);
bool suc=true;
f.size=s(&suc);
f.family=fam(&suc);
f.color=c(&suc);
if(!suc) goto fail; // Something wrong
return f;
if(color.Exist() || family.Exist() || size.Exist() || upd) return f; // Font created or updated
err="Specify at least one of size, family or color";
}
fail:

Loading…
Cancel
Save