fl_help_view.cxx
来自「SRI international 发布的OAA框架软件」· CXX 代码 · 共 2,703 行 · 第 1/5 页
CXX
2,703 行
strcasecmp(buf, "DT") == 0 ||
strcasecmp(buf, "PRE") == 0)
{
width = 0;
needspace = 0;
if (tolower(buf[0]) == 'h' && isdigit(buf[1]))
{
font = FL_HELVETICA_BOLD;
fsize = (uchar)(textsize_ + '7' - buf[1]);
}
else if (strcasecmp(buf, "DT") == 0)
{
font = (uchar)(textfont_ | FL_ITALIC);
fsize = textsize_;
}
else if (strcasecmp(buf, "PRE") == 0)
{
font = FL_COURIER;
fsize = textsize_;
pre = 1;
}
else if (strcasecmp(buf, "LI") == 0)
{
width += 4 * fsize;
font = textfont_;
fsize = textsize_;
}
else
{
font = textfont_;
fsize = textsize_;
}
pushfont(font, fsize);
}
else if (strcasecmp(buf, "/CENTER") == 0 ||
strcasecmp(buf, "/P") == 0 ||
strcasecmp(buf, "/H1") == 0 ||
strcasecmp(buf, "/H2") == 0 ||
strcasecmp(buf, "/H3") == 0 ||
strcasecmp(buf, "/H4") == 0 ||
strcasecmp(buf, "/H5") == 0 ||
strcasecmp(buf, "/H6") == 0 ||
strcasecmp(buf, "/PRE") == 0 ||
strcasecmp(buf, "/UL") == 0 ||
strcasecmp(buf, "/OL") == 0 ||
strcasecmp(buf, "/DL") == 0)
{
width = 0;
needspace = 0;
popfont(font, fsize);
}
else if (strcasecmp(buf, "TR") == 0 || strcasecmp(buf, "/TR") == 0 ||
strcasecmp(buf, "/TABLE") == 0)
{
// printf("%s column = %d, colspan = %d, num_columns = %d\n",
// buf, column, colspan, num_columns);
if (column >= 0)
{
// This is a hack to support COLSPAN...
max_width /= colspan;
while (colspan > 0)
{
if (max_width > columns[column])
columns[column] = max_width;
column ++;
colspan --;
}
}
if (strcasecmp(buf, "/TABLE") == 0)
break;
needspace = 0;
column = -1;
width = 0;
max_width = 0;
incell = 0;
}
else if (strcasecmp(buf, "TD") == 0 ||
strcasecmp(buf, "TH") == 0)
{
// printf("BEFORE column = %d, colspan = %d, num_columns = %d\n",
// column, colspan, num_columns);
if (column >= 0)
{
// This is a hack to support COLSPAN...
max_width /= colspan;
while (colspan > 0)
{
if (max_width > columns[column])
columns[column] = max_width;
column ++;
colspan --;
}
}
else
column ++;
if (get_attr(attrs, "COLSPAN", attr, sizeof(attr)) != NULL)
colspan = atoi(attr);
else
colspan = 1;
// printf("AFTER column = %d, colspan = %d, num_columns = %d\n",
// column, colspan, num_columns);
if ((column + colspan) >= num_columns)
num_columns = column + colspan;
needspace = 0;
width = 0;
incell = 1;
if (strcasecmp(buf, "TH") == 0)
font = (uchar)(textfont_ | FL_BOLD);
else
font = textfont_;
fsize = textsize_;
pushfont(font, fsize);
if (get_attr(attrs, "WIDTH", attr, sizeof(attr)) != NULL)
max_width = get_length(attr);
else
max_width = 0;
// printf("max_width = %d\n", max_width);
}
else if (strcasecmp(buf, "/TD") == 0 ||
strcasecmp(buf, "/TH") == 0)
{
incell = 0;
popfont(font, fsize);
}
else if (strcasecmp(buf, "B") == 0 ||
strcasecmp(buf, "STRONG") == 0)
pushfont(font |= FL_BOLD, fsize);
else if (strcasecmp(buf, "I") == 0 ||
strcasecmp(buf, "EM") == 0)
pushfont(font |= FL_ITALIC, fsize);
else if (strcasecmp(buf, "CODE") == 0 ||
strcasecmp(buf, "TT") == 0)
pushfont(font = FL_COURIER, fsize);
else if (strcasecmp(buf, "KBD") == 0)
pushfont(font = FL_COURIER_BOLD, fsize);
else if (strcasecmp(buf, "VAR") == 0)
pushfont(font = FL_COURIER_ITALIC, fsize);
else if (strcasecmp(buf, "/B") == 0 ||
strcasecmp(buf, "/STRONG") == 0 ||
strcasecmp(buf, "/I") == 0 ||
strcasecmp(buf, "/EM") == 0 ||
strcasecmp(buf, "/CODE") == 0 ||
strcasecmp(buf, "/TT") == 0 ||
strcasecmp(buf, "/KBD") == 0 ||
strcasecmp(buf, "/VAR") == 0)
popfont(font, fsize);
else if (strcasecmp(buf, "IMG") == 0 && incell)
{
Fl_Shared_Image *img = 0;
int iwidth, iheight;
get_attr(attrs, "WIDTH", wattr, sizeof(wattr));
get_attr(attrs, "HEIGHT", hattr, sizeof(hattr));
iwidth = get_length(wattr);
iheight = get_length(hattr);
if (get_attr(attrs, "SRC", attr, sizeof(attr))) {
img = get_image(attr, iwidth, iheight);
iwidth = img->w();
iheight = img->h();
}
if (iwidth > minwidths[column])
minwidths[column] = iwidth;
width += iwidth;
if (needspace)
width += (int)fl_width(' ');
if (width > max_width)
max_width = width;
needspace = 0;
}
}
else if (*ptr == '\n' && pre)
{
width = 0;
needspace = 0;
ptr ++;
}
else if (isspace(*ptr))
{
needspace = 1;
ptr ++;
}
else if (*ptr == '&' && s < (buf + sizeof(buf) - 1))
{
ptr ++;
int qch = quote_char(ptr);
if (qch < 0)
*s++ = '&';
else {
*s++ = qch;
ptr = strchr(ptr, ';') + 1;
}
}
else
{
if (s < (buf + sizeof(buf) - 1))
*s++ = *ptr++;
else
ptr ++;
}
}
// Now that we have scanned the entire table, adjust the table and
// cell widths to fit on the screen...
if (get_attr(table + 6, "WIDTH", attr, sizeof(attr)))
*table_width = get_length(attr);
else
*table_width = 0;
#ifdef DEBUG
printf("num_columns = %d, table_width = %d\n", num_columns, *table_width);
#endif // DEBUG
if (num_columns == 0)
return;
// Add up the widths...
for (column = 0, width = 0; column < num_columns; column ++)
width += columns[column];
#ifdef DEBUG
printf("width = %d, w() = %d\n", width, w());
for (column = 0; column < num_columns; column ++)
printf(" columns[%d] = %d, minwidths[%d] = %d\n", column, columns[column],
column, minwidths[column]);
#endif // DEBUG
// Adjust the width if needed...
int scale_width = *table_width;
if (scale_width == 0) {
if (width > hsize_) scale_width = hsize_;
else scale_width = width;
}
if (width < scale_width) {
#ifdef DEBUG
printf("Scaling table up to %d from %d...\n", scale_width, width);
#endif // DEBUG
*table_width = 0;
scale_width = (scale_width - width) / num_columns;
#ifdef DEBUG
printf("adjusted scale_width = %d\n", scale_width);
#endif // DEBUG
for (column = 0; column < num_columns; column ++) {
columns[column] += scale_width;
(*table_width) += columns[column];
}
}
else if (width > scale_width) {
#ifdef DEBUG
printf("Scaling table down to %d from %d...\n", scale_width, width);
#endif // DEBUG
for (column = 0; column < num_columns; column ++) {
width -= minwidths[column];
scale_width -= minwidths[column];
}
#ifdef DEBUG
printf("adjusted width = %d, scale_width = %d\n", width, scale_width);
#endif // DEBUG
if (width > 0) {
for (column = 0; column < num_columns; column ++) {
columns[column] -= minwidths[column];
columns[column] = scale_width * columns[column] / width;
columns[column] += minwidths[column];
}
}
*table_width = 0;
for (column = 0; column < num_columns; column ++) {
(*table_width) += columns[column];
}
}
else if (*table_width == 0)
*table_width = width;
#ifdef DEBUG
printf("FINAL table_width = %d\n", *table_width);
for (column = 0; column < num_columns; column ++)
printf(" columns[%d] = %d\n", column, columns[column]);
#endif // DEBUG
}
//
// 'Fl_Help_View::get_align()' - Get an alignment attribute.
//
int // O - Alignment
Fl_Help_View::get_align(const char *p, // I - Pointer to start of attrs
int a) // I - Default alignment
{
char buf[255]; // Alignment value
if (get_attr(p, "ALIGN", buf, sizeof(buf)) == NULL)
return (a);
if (strcasecmp(buf, "CENTER") == 0)
return (CENTER);
else if (strcasecmp(buf, "RIGHT") == 0)
return (RIGHT);
else
return (LEFT);
}
//
// 'Fl_Help_View::get_attr()' - Get an attribute value from the string.
//
const char * // O - Pointer to buf or NULL
Fl_Help_View::get_attr(const char *p, // I - Pointer to start of attributes
const char *n, // I - Name of attribute
char *buf, // O - Buffer for attribute value
int bufsize) // I - Size of buffer
{
char name[255], // Name from string
*ptr, // Pointer into name or value
quote; // Quote
buf[0] = '\0';
while (*p && *p != '>')
{
while (isspace(*p))
p ++;
if (*p == '>' || !*p)
return (NULL);
for (ptr = name; *p && !isspace(*p) && *p != '=' && *p != '>';)
if (ptr < (name + sizeof(name) - 1))
*ptr++ = *p++;
else
p ++;
*ptr = '\0';
if (isspace(*p) || !*p || *p == '>')
buf[0] = '\0';
else
{
if (*p == '=')
p ++;
for (ptr = buf; *p && !isspace(*p) && *p != '>';)
if (*p == '\'' || *p == '\"')
{
quote = *p++;
while (*p && *p != quote)
if ((ptr - buf + 1) < bufsize)
*ptr++ = *p++;
else
p ++;
if (*p == quote)
p ++;
}
else if ((ptr - buf + 1) < bufsize)
*ptr++ = *p++;
else
p ++;
*ptr = '\0';
}
if (strcasecmp(n, name) == 0)
return (buf);
else
buf[0] = '\0';
if (*p == '>')
return (NULL);
}
return (NULL);
}
//
// 'Fl_Help_View::get_color()' - Get an alignment attribute.
//
Fl_Color // O - Color value
Fl_Help_View::get_color(const char *n, // I - Color name
Fl_Color c) // I - Default color value
{
int rgb, r, g, b; // RGB values
if (!n || !n[0])
return (c);
if (n[0] == '#')
{
// Do hex color lookup
rgb = strtol(n + 1, NULL, 16);
r = rgb >> 16;
g = (rgb >> 8) & 255;
b = rgb & 255;
return (fl_rgb_color((uchar)r, (uchar)g, (uchar)b));
}
else if (strcasecmp(n, "black") == 0)
return (FL_BLACK);
else if (strcasecmp(n, "red") == 0)
return (FL_RED);
#ifdef __BORLANDC__ // Workaround for compiler bug...
else if (strcasecmp(n, "green") == 0) {
r = 0;
g = 0x80;
b = 0;
return (fl_rgb_color(r, g, b));
}
#else
else if (strcasecmp(n, "green") == 0)
return (fl_rgb_color(0, 0x80, 0));
#endif // __BORLANDC__
else if (strcasecmp(n, "yellow") == 0)
return (FL_YELLOW);
else if (strcasecmp(n, "blue") == 0)
return (FL_BLUE);
else if (strcasecmp(n, "magenta") == 0 || strcasecmp(n, "fuchsia") == 0)
return (FL_MAGENTA);
else if (strcasecmp(n, "cyan") == 0 || strcasecmp(n, "aqua") == 0)
return (FL_CYAN);
else if (strcasecmp(n, "white") == 0)
return (FL_WHITE);
else if (strcasecmp(n, "gray") == 0 || strcasecmp(n, "grey") == 0)
return (fl_rgb_color(0x80, 0x80, 0x80));
else if (strcasecmp(n, "lime") == 0)
return (FL_GREEN);
else if (strcasecmp(n, "maroon") == 0)
return (fl_rgb_color(0x80, 0, 0));
else if (strcasecmp(n, "navy") == 0)
return (fl_rgb_color(0, 0, 0x80));
else if (strcasecmp(n, "olive") == 0)
return (fl_rgb_color(0x80, 0x80, 0));
else if (strcasecmp(n, "purple") == 0)
return (fl_rgb_color(0x80, 0, 0x80));
else if (strcasecmp(n, "silver") == 0)
return (fl_rgb_color(0xc0, 0xc0, 0xc0));
else if (strcasecmp(n, "teal") == 0)
return (fl_rgb_color(0, 0x80, 0x80));
else
return (c);
}
//
// 'Fl_Help_View::get_image()' - Get an inline image.
//
Fl_Shared_Image *
Fl_Help_View::get_image(const char *name, int W, int H) {
const char *localname; // Local filename
char dir[1024]; // Current directory
char temp[1024], // Temporary filename
*tempptr; // Pointer into temporary name
Fl_Shared_Image *ip; // Image pointer...
// See if the image can be found...
if (strchr(directory_, ':') != NULL && strchr(name, ':') == NULL) {
if (name[0] == '/') {
strlcpy(temp, directory_, sizeof(temp));
if ((tempptr = strrchr(strchr(directory_, ':') + 3, '/')) != NULL) {
strlcpy(tempptr, name, sizeof(temp) - (tempptr - temp));
} else {
strlcat(temp, name, sizeof(temp));
}
} else {
snprintf(temp, sizeof(temp), "%s/%s", directory_, name);
}
if (link_) localname = (*link_)(this, temp);
else localname = temp;
} else if (name[0] != '/' && strchr(name, ':') == NULL) {
if (directory_[0]) snprintf(temp, sizeof(temp), "%s/%s", directory_, name);
else {
getcwd(dir, sizeof(dir));
snprintf(temp, sizeof(temp), "file:%s/%s", dir, name);
}
if (link_) localname = (*link_)(this, temp);
else localname = temp;
} else if (link_) localname = (*link_)(this, name);
else localname = name;
if (!localname) return 0;
if (strncmp(localname, "file:", 5) == 0) localname += 5;
if ((ip = Fl_Shared_Image::get(localname, W, H)) == NULL)
ip = (Fl_Shared_Image *)&broken_image;
return ip;
}
//
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?