38 typedef std::string::size_type size_type;
42 void StringToInt(
const std::string &str,
const std::string &componentName,
T &num)
44 for (size_type i = 0,
e = str.length(); i <
e; ++i) {
45 const char symbol = str[i];
46 if (!std::isdigit(symbol))
47 throw std::runtime_error(
"bad symbol while converting component " + componentName +
" into number");
50 std::istringstream in(str);
55 size_type GetXLFDNameComponentAsString(
const std::string &
name,
const std::string & componentName,
56 size_type pos, std::string &component)
58 const size_type length = name.length();
59 if (pos + 1 >= length)
60 throw std::runtime_error(
"Unexpected end of name while parsing " + componentName);
64 throw std::runtime_error(
"Component " + componentName +
" must start from '-'");
66 const size_type start = ++pos;
68 while (pos < length && name[pos] !=
'-')
72 component = name.substr(start, pos - start);
82 size_type GetXLFDNameComponentAsInteger(
const std::string &name,
83 const std::string &componentName,
84 size_type pos,
T &component)
87 pos = GetXLFDNameComponentAsString(name, componentName, pos, num);
88 StringToInt(num, componentName, component);
95 size_type ParseFoundry(
const std::string &name, size_type pos, XLFDName &)
99 return GetXLFDNameComponentAsString(name,
"foundry", pos, dummy);
104 size_type ParseFamilyName(
const std::string &name, size_type pos, XLFDName &dst)
106 const size_type tokenEnd = GetXLFDNameComponentAsString(name,
"family name", pos, dst.fFamilyName);
111 if (dst.fFamilyName ==
"symbol")
112 dst.fFamilyName =
"helvetica";
119 size_type ParseWeight(
const std::string &name, size_type pos, XLFDName &dst)
124 pos = GetXLFDNameComponentAsString(name,
"weight", pos, weight);
128 else if (weight ==
"bold")
138 size_type ParseSlant(
const std::string &name, size_type pos, XLFDName &dst)
142 pos = GetXLFDNameComponentAsString(name,
"slant", pos, slant);
147 else if (slant ==
"i" || slant ==
"I" || slant ==
"o" || slant ==
"O")
156 size_type ParseSetwidth(
const std::string &name, size_type pos, XLFDName &)
160 return GetXLFDNameComponentAsString(name,
"setwidth", pos, dummy);
164 size_type ParseAddstyle(
const std::string &name, size_type pos, XLFDName &)
168 return GetXLFDNameComponentAsString(name,
"addstyle", pos, dummy);
172 size_type ParsePixelSize(
const std::string &name, size_type pos, XLFDName &dst)
178 size_type endOfSize = GetXLFDNameComponentAsString(name,
"pixel size", pos, dummy);
185 const size_type pos1 = GetXLFDNameComponentAsInteger(name,
"pixel size", pos, dst.fPixelSize);
186 if (dst.fPixelSize < 12)
193 size_type ParsePointSize(
const std::string &name, size_type pos, XLFDName &)
197 return GetXLFDNameComponentAsString(name,
"point size", pos, dummy);
202 size_type ParseHoriz(
const std::string &name, size_type pos, XLFDName &)
206 return GetXLFDNameComponentAsString(name,
"horizontal", pos, dummy);
211 size_type ParseVert(
const std::string &name, size_type pos, XLFDName &)
215 return GetXLFDNameComponentAsString(name,
"vertical", pos, dummy);
220 size_type ParseSpacing(
const std::string &name, size_type pos, XLFDName &)
224 return GetXLFDNameComponentAsString(name,
"spacing", pos, dummy);
229 size_type ParseAvgwidth(
const std::string &name, size_type pos, XLFDName &)
233 return GetXLFDNameComponentAsString(name,
"average width", pos, dummy);
238 size_type ParseRgstry(
const std::string &name, size_type pos, XLFDName &dst)
240 return GetXLFDNameComponentAsString(name,
"language", pos, dst.fRgstry);
245 size_type ParseEncoding(
const std::string &name, size_type pos, XLFDName &dst)
247 return GetXLFDNameComponentAsString(name,
"encoding", pos, dst.fRgstry);
263 const size_type nameLength = xlfdName.length();
265 assert(nameLength &&
"XLFD name is a string with a zero length");
268 ::Warning(
"ROOT::MacOSX::X11::ParseXLFDName: ",
"XLFD name is a string with a zero length");
273 if (xlfdName ==
"fixed" || xlfdName ==
"*") {
278 size_type pos = ParseFoundry(xlfdName, 0, dst);
279 if (pos + 1 < nameLength)
280 pos = ParseFamilyName(xlfdName, pos, dst);
282 if (pos + 1 < nameLength)
283 pos = ParseWeight(xlfdName, pos, dst);
287 if (pos + 1 < nameLength)
288 pos = ParseSlant(xlfdName, pos, dst);
292 if (pos + 1 < nameLength)
293 pos = ParseSetwidth(xlfdName, pos, dst);
294 if (pos + 1 < nameLength)
295 pos = ParseAddstyle(xlfdName, pos, dst);
296 if (pos + 1 < nameLength)
297 pos = ParsePixelSize(xlfdName, pos, dst);
298 if (pos + 1 < nameLength)
299 pos = ParsePointSize(xlfdName, pos, dst);
300 if (pos + 1 < nameLength)
301 pos = ParseHoriz(xlfdName, pos, dst);
302 if (pos + 1 < nameLength)
303 pos = ParseVert(xlfdName, pos, dst);
304 if (pos + 1 < nameLength)
305 pos = ParseSpacing(xlfdName, pos, dst);
306 if (pos + 1 < nameLength)
307 pos = ParseAvgwidth(xlfdName, pos, dst);
308 if (pos + 1 < nameLength)
309 pos = ParseRgstry(xlfdName, pos, dst);
310 if (pos + 1 < nameLength)
311 pos = ParseEncoding(xlfdName, pos, dst);
315 }
catch (
const std::exception &e) {
316 ::Error(
"ROOT::MacOSX::Quartz::ParseXLFDName",
"Failed to parse XLFD name - %s", e.what());
bool ParseXLFDName(const std::string &xlfdName, XLFDName &dst)
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
void Warning(const char *location, const char *msgfmt,...)
static RooMathCoreReg dummy
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
void Error(ErrorHandler_t func, int code, const char *va_(fmt),...)
Write error message and call a handler, if required.