37typedef std::string::size_type size_type;
41void StringToInt(
const std::string &str,
const std::string &componentName, T &num)
43 for (size_type i = 0,
e = str.length(); i <
e; ++i) {
44 const char symbol = str[i];
45 if (!std::isdigit(symbol))
46 throw std::runtime_error(
"bad symbol while converting component " + componentName +
" into number");
49 std::istringstream in(str);
54size_type GetXLFDNameComponentAsString(
const std::string &
name,
const std::string & componentName,
55 size_type
pos, std::string &component)
58 if (
pos + 1 >= length)
59 throw std::runtime_error(
"Unexpected end of name while parsing " + componentName);
63 throw std::runtime_error(
"Component " + componentName +
" must start from '-'");
81size_type GetXLFDNameComponentAsInteger(
const std::string &
name,
82 const std::string &componentName,
83 size_type
pos, T &component)
86 pos = GetXLFDNameComponentAsString(
name, componentName,
pos, num);
87 StringToInt(num, componentName, component);
94size_type ParseFoundry(
const std::string &
name, size_type
pos,
XLFDName &)
98 return GetXLFDNameComponentAsString(
name,
"foundry",
pos, dummy);
103size_type ParseFamilyName(
const std::string &
name, size_type
pos,
XLFDName &dst)
105 const size_type tokenEnd = GetXLFDNameComponentAsString(
name,
"family name",
pos, dst.fFamilyName);
110 if (dst.fFamilyName ==
"symbol")
111 dst.fFamilyName =
"helvetica";
118size_type ParseWeight(
const std::string &
name, size_type
pos,
XLFDName &dst)
123 pos = GetXLFDNameComponentAsString(
name,
"weight",
pos, weight);
127 else if (weight ==
"bold")
137size_type ParseSlant(
const std::string &
name, size_type
pos,
XLFDName &dst)
141 pos = GetXLFDNameComponentAsString(
name,
"slant",
pos, slant);
146 else if (slant ==
"i" || slant ==
"I" || slant ==
"o" || slant ==
"O")
155size_type ParseSetwidth(
const std::string &
name, size_type
pos,
XLFDName &)
159 return GetXLFDNameComponentAsString(
name,
"setwidth",
pos, dummy);
163size_type ParseAddstyle(
const std::string &
name, size_type
pos,
XLFDName &)
167 return GetXLFDNameComponentAsString(
name,
"addstyle",
pos, dummy);
171size_type ParsePixelSize(
const std::string &
name, size_type
pos,
XLFDName &dst)
177 size_type endOfSize = GetXLFDNameComponentAsString(
name,
"pixel size",
pos, dummy);
184 const size_type pos1 = GetXLFDNameComponentAsInteger(
name,
"pixel size",
pos, dst.fPixelSize);
185 if (dst.fPixelSize < 12)
192size_type ParsePointSize(
const std::string &
name, size_type
pos,
XLFDName &)
196 return GetXLFDNameComponentAsString(
name,
"point size",
pos, dummy);
201size_type ParseHoriz(
const std::string &
name, size_type
pos,
XLFDName &)
205 return GetXLFDNameComponentAsString(
name,
"horizontal",
pos, dummy);
214 return GetXLFDNameComponentAsString(
name,
"vertical",
pos, dummy);
219size_type ParseSpacing(
const std::string &
name, size_type
pos,
XLFDName &)
223 return GetXLFDNameComponentAsString(
name,
"spacing",
pos, dummy);
228size_type ParseAvgwidth(
const std::string &
name, size_type
pos,
XLFDName &)
232 return GetXLFDNameComponentAsString(
name,
"average width",
pos, dummy);
237size_type ParseRgstry(
const std::string &
name, size_type
pos,
XLFDName &dst)
239 return GetXLFDNameComponentAsString(
name,
"language",
pos, dst.fRgstry);
244size_type ParseEncoding(
const std::string &
name, size_type
pos,
XLFDName &dst)
246 return GetXLFDNameComponentAsString(
name,
"encoding",
pos, dst.fRgstry);
262 const size_type nameLength = xlfdName.length();
264 assert(nameLength &&
"XLFD name is a string with a zero length");
267 ::Warning(
"ROOT::MacOSX::X11::ParseXLFDName: ",
"XLFD name is a string with a zero length");
272 if (xlfdName ==
"fixed" || xlfdName ==
"*") {
277 size_type
pos = ParseFoundry(xlfdName, 0, dst);
278 if (
pos + 1 < nameLength)
279 pos = ParseFamilyName(xlfdName,
pos, dst);
281 if (
pos + 1 < nameLength)
282 pos = ParseWeight(xlfdName,
pos, dst);
286 if (
pos + 1 < nameLength)
287 pos = ParseSlant(xlfdName,
pos, dst);
291 if (
pos + 1 < nameLength)
292 pos = ParseSetwidth(xlfdName,
pos, dst);
293 if (
pos + 1 < nameLength)
294 pos = ParseAddstyle(xlfdName,
pos, dst);
295 if (
pos + 1 < nameLength)
296 pos = ParsePixelSize(xlfdName,
pos, dst);
297 if (
pos + 1 < nameLength)
298 pos = ParsePointSize(xlfdName,
pos, dst);
299 if (
pos + 1 < nameLength)
300 pos = ParseHoriz(xlfdName,
pos, dst);
301 if (
pos + 1 < nameLength)
302 pos = ParseVert(xlfdName,
pos, dst);
303 if (
pos + 1 < nameLength)
304 pos = ParseSpacing(xlfdName,
pos, dst);
305 if (
pos + 1 < nameLength)
306 pos = ParseAvgwidth(xlfdName,
pos, dst);
307 if (
pos + 1 < nameLength)
308 pos = ParseRgstry(xlfdName,
pos, dst);
309 if (
pos + 1 < nameLength)
310 pos = ParseEncoding(xlfdName,
pos, dst);
314 }
catch (
const std::exception &
e) {
315 ::Error(
"ROOT::MacOSX::Quartz::ParseXLFDName",
"Failed to parse XLFD name - %s",
e.what());
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
bool ParseXLFDName(const std::string &xlfdName, XLFDName &dst)
BVH_ALWAYS_INLINE T length(const Vec< T, N > &v)