Example #1
0
static void
entry_set_rgba (GtkColorEditor *editor,
                const GdkRGBA  *color)
{
  gchar *text;

  text = g_strdup_printf ("#%02X%02X%02X",
                          scale_round (color->red, 255),
                          scale_round (color->green, 255),
                          scale_round (color->blue, 255));
  gtk_entry_set_text (GTK_ENTRY (editor->priv->entry), text);
  editor->priv->text_changed = FALSE;
  g_free (text);
}
Example #2
0
int font::load(int *not_found, int head_only)
{
  char *path;
  FILE *fp;
  if ((fp = open_file(name, &path)) == NULL) {
    if (not_found)
      *not_found = 1;
    else
      error("can't find font file `%1'", name);
    return 0;
  }
  text_file t(fp, path);
  t.skip_comments = 1;
  t.silent = head_only;
  char *p;
  for (;;) {
    if (!t.next()) {
      t.error("missing charset command");
      return 0;
    }
    p = strtok(t.buf, WS);
    if (strcmp(p, "name") == 0) {
    }
    else if (strcmp(p, "spacewidth") == 0) {
      p = strtok(0, WS);
      int n;
      if (p == 0 || sscanf(p, "%d", &n) != 1 || n <= 0) {
	t.error("bad argument for spacewidth command");
	return 0;
      }
      space_width = n;
    }
    else if (strcmp(p, "slant") == 0) {
      p = strtok(0, WS);
      double n;
      if (p == 0 || sscanf(p, "%lf", &n) != 1 || n >= 90.0 || n <= -90.0) {
	t.error("bad argument for slant command", p);
	return 0;
      }
      slant = n;
    }
    else if (strcmp(p, "ligatures") == 0) {
      for (;;) {
	p = strtok(0, WS);
	if (p == 0 || strcmp(p, "0") == 0)
	  break;
	if (strcmp(p, "ff") == 0)
	  ligatures |= LIG_ff;
	else if (strcmp(p, "fi") == 0)
	  ligatures |= LIG_fi;
	else if (strcmp(p, "fl") == 0)
	  ligatures |= LIG_fl;
	else if (strcmp(p, "ffi") == 0)
	  ligatures |= LIG_ffi;
	else if (strcmp(p, "ffl") == 0)
	  ligatures |= LIG_ffl;
	else {
	  t.error("unrecognised ligature `%1'", p);
	  return 0;
	}
      }
    }
    else if (strcmp(p, "internalname") == 0) {
      p = strtok(0, WS);
      if (!p) {
	t.error("`internalname command requires argument");
	return 0;
      }
      internalname = new char[strlen(p) + 1];
      strcpy(internalname, p);
    }
    else if (strcmp(p, "special") == 0) {
      special = 1;
    }
    else if (strcmp(p, "kernpairs") != 0 && strcmp(p, "charset") != 0) {
      char *command = p;
      p = strtok(0, "\n");
      handle_unknown_font_command(command, trim_arg(p), t.path, t.lineno);
    }
    else
      break;
  }
  if (head_only)
    return 1;
  char *command = p;
  int had_charset = 0;
  t.skip_comments = 0;
  while (command) {
    if (strcmp(command, "kernpairs") == 0) {
      for (;;) {
	if (!t.next()) {
	  command = 0;
	  break;
	}
	char *c1 = strtok(t.buf, WS);
	if (c1 == 0)
	  continue;
	char *c2 = strtok(0, WS);
	if (c2 == 0) {
	  command = c1;
	  break;
	}
	p = strtok(0, WS);
	if (p == 0) {
	  t.error("missing kern amount");
	  return 0;
	}
	int n;
	if (sscanf(p, "%d", &n) != 1) {
	  t.error("bad kern amount `%1'", p);
	  return 0;
	}
	int i1 = name_to_index(c1);
	if (i1 < 0) {
	  t.error("invalid character `%1'", c1);
	  return 0;
	}
	int i2 = name_to_index(c2);
	if (i2 < 0) {
	  t.error("invalid character `%1'", c2);
	  return 0;
	}
	add_kern(i1, i2, n);
      }
    }
    else if (strcmp(command, "charset") == 0) {
      had_charset = 1;
      int last_index = -1;
      for (;;) {
	if (!t.next()) {
	  command = 0;
	  break;
	}
	char *nm = strtok(t.buf, WS);
	if (nm == 0)
	  continue;			// I dont think this should happen
	p = strtok(0, WS);
	if (p == 0) {
	  command = nm;
	  break;
	}
	if (p[0] == '"') {
	  if (last_index == -1) {
	    t.error("first charset entry is duplicate");
	    return 0;
	  }
	  if (strcmp(nm, "---") == 0) {
	    t.error("unnamed character cannot be duplicate");
	    return 0;
	  }
	  int idx = name_to_index(nm);
	  if (idx < 0) {
	    t.error("invalid character `%1'", nm);
	    return 0;
	  }
	  copy_entry(idx, last_index);
	}
	else {
	  font_char_metric metric;
	  metric.height = 0;
	  metric.depth = 0;
	  metric.pre_math_space = 0;
	  metric.italic_correction = 0;
	  metric.subscript_correction = 0;
	  int nparms = sscanf(p, "%d,%d,%d,%d,%d,%d",
			      &metric.width, &metric.height, &metric.depth,
			      &metric.italic_correction,
			      &metric.pre_math_space,
			      &metric.subscript_correction);
	  if (nparms < 1) {
	    t.error("bad width for `%1'", nm);
	    return 0;
	  }
	  p = strtok(0, WS);
	  if (p == 0) {
	    t.error("missing character type for `%1'", nm);
	    return 0;
	  }
	  int type;
	  if (sscanf(p, "%d", &type) != 1) {
	    t.error("bad character type for `%1'", nm);
	    return 0;
	  }
	  if (type < 0 || type > 255) {
	    t.error("character type `%1' out of range", type);
	    return 0;
	  }
	  metric.type = type;
	  p = strtok(0, WS);
	  if (p == 0) {
	    t.error("missing code for `%1'", nm);
	    return 0;
	  }
	  char *ptr;
	  metric.code = (int)strtol(p, &ptr, 0);
	  if (metric.code == 0 && ptr == p) {
	    t.error("bad code `%1' for character `%2'", p, nm);
	    return 0;
	  }
	  p = strtok(0, WS);
	  if ((p == NULL) || (strcmp(p, "--") == 0)) {
	    metric.special_device_coding = NULL;
	  }
	  else {
	    char *nam = new char[strlen(p) + 1];
	    strcpy(nam, p);
	    metric.special_device_coding = nam;
	  }
	  if (strcmp(nm, "---") == 0) {
	    last_index = number_to_index(metric.code);
	    add_entry(last_index, metric);
	  }
	  else {
	    last_index = name_to_index(nm);
	    if (last_index < 0) {
	      t.error("invalid character `%1'", nm);
	      return 0;
	    }
	    add_entry(last_index, metric);
	    copy_entry(number_to_index(metric.code), last_index);
	  }
	}
      }
      if (last_index == -1) {
	t.error("I didn't seem to find any characters");
	return 0;
      }
    }
    else {
      t.error("unrecognised command `%1' after `kernpairs' or `charset' command", command);
      return 0;
    }
  }
  if (!had_charset) {
    t.error("missing charset command");
    return 0;
  }
  if (space_width == 0)
    space_width = scale_round(unitwidth, res, 72*3*sizescale);
  compact();
  return 1;
}
Example #3
0
inline int font::scale(int w, int sz)
{
  return sz == unitwidth ? w : scale_round(w, sz, unitwidth);
}