diff --git a/modules/gmt/modgmt_func.h b/modules/gmt/modgmt_func.h index 36817a3..a69a46e 100644 --- a/modules/gmt/modgmt_func.h +++ b/modules/gmt/modgmt_func.h @@ -176,6 +176,7 @@ using Base2Proj =Base2Struct; using Base2Color =Base2Struct; using Base2Dash =Base2Struct; using Base2Pen =Base2Struct; +using Base2Font =Base2Struct; // Simple aliases of convertors with default values using Base2StringD=Base2StructD; @@ -982,90 +983,52 @@ class Convert2Struct { 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 + // Case 6 and 7 { - bool casevalid=false; - bool upd; - { - BaseMT2Font updarg(input,"font"); - bool suc=true; - f=updarg(&upd,&suc); - if(upd && !suc) goto fail; // Conversion failed or too many arguments - } + OPosPar size("size",gmt_font::default_size); + OPosPar color("color",0.0); + OPosPar 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()) - { - bool suc=true; - f.size=s(&suc); - if(!suc) goto fail; // Parsing error - casevalid=true; - } - } + // Case 3 + case3: + { + ONFPar font("f[on]t"); + ONFPar color("color",0); + ONFPar family("f[a]m[i]ly",gmt_font::default_family); + ONFPar 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: