예제 #1
0
파일: label.hpp 프로젝트: diosmosis/iris
nyx::point text_extents(F const& fnt, std::string const& x, size_t maxx, size_t maxy)
{
    if (!maxx || !maxy)
    {
        return text_extents(fnt, x);
    }

    return nyx::point(maxx * average_char_width(fnt), maxy * line_length(fnt));
}
예제 #2
0
static void
sushi_font_widget_size_request (GtkWidget *drawing_area,
                                gint *width,
                                gint *height,
                                gint *min_height)
{
  SushiFontWidget *self = SUSHI_FONT_WIDGET (drawing_area);
  SushiFontWidgetPrivate *priv = self->priv;
  gint i, pixmap_width, pixmap_height;
  cairo_text_extents_t extents;
  cairo_font_extents_t font_extents;
  cairo_font_face_t *font;
  gint *sizes = NULL, n_sizes, alpha_size, title_size;
  cairo_t *cr;
  cairo_surface_t *surface;
  FT_Face face = priv->face;
  GtkStyleContext *context;
  GtkStateFlags state;
  GtkBorder padding;

  if (face == NULL) {
    if (width != NULL)
      *width = 1;
    if (height != NULL)
      *height = 1;
    if (min_height != NULL)
      *min_height = 1;

    return;
  }

  if (min_height != NULL)
    *min_height = -1;

  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                        SURFACE_SIZE, SURFACE_SIZE);
  cr = cairo_create (surface);
  context = gtk_widget_get_style_context (drawing_area);
  state = gtk_style_context_get_state (context);
  gtk_style_context_get_padding (context, state, &padding);

  sizes = build_sizes_table (face, &n_sizes, &alpha_size, &title_size);

  /* calculate size of pixmap to use */
  pixmap_width = padding.left + padding.right;
  pixmap_height = padding.top + padding.bottom;

  font = cairo_ft_font_face_create_for_ft_face (face, 0);
  cairo_set_font_face (cr, font);
  cairo_font_face_destroy (font);

  if (self->priv->font_name != NULL) {
      cairo_set_font_size (cr, title_size);
      cairo_font_extents (cr, &font_extents);
      text_extents (cr, self->priv->font_name, &extents);
      pixmap_height += font_extents.ascent + font_extents.descent +
        extents.y_advance + LINE_SPACING;
      pixmap_width = MAX (pixmap_width, extents.width + padding.left + padding.right);
  }

  pixmap_height += SECTION_SPACING / 2;
  cairo_set_font_size (cr, alpha_size);
  cairo_font_extents (cr, &font_extents);

  if (self->priv->lowercase_text != NULL) {
    text_extents (cr, self->priv->lowercase_text, &extents);
    pixmap_height += font_extents.ascent + font_extents.descent + 
      extents.y_advance + LINE_SPACING;
    pixmap_width = MAX (pixmap_width, extents.width + padding.left + padding.right);
  }

  if (self->priv->uppercase_text != NULL) {
    text_extents (cr, self->priv->uppercase_text, &extents);
    pixmap_height += font_extents.ascent + font_extents.descent +
      extents.y_advance + LINE_SPACING;
    pixmap_width = MAX (pixmap_width, extents.width + padding.left + padding.right);
  }

  if (self->priv->punctuation_text != NULL) {
    text_extents (cr, self->priv->punctuation_text, &extents);
    pixmap_height += font_extents.ascent + font_extents.descent +
      extents.y_advance + LINE_SPACING;
    pixmap_width = MAX (pixmap_width, extents.width + padding.left + padding.right);
  }

  if (self->priv->sample_string != NULL) {
    pixmap_height += SECTION_SPACING;

    for (i = 0; i < n_sizes; i++) {
      cairo_set_font_size (cr, sizes[i]);
      cairo_font_extents (cr, &font_extents);
      text_extents (cr, self->priv->sample_string, &extents);
      pixmap_height += font_extents.ascent + font_extents.descent +
        extents.y_advance + LINE_SPACING;
      pixmap_width = MAX (pixmap_width, extents.width + padding.left + padding.right);

      if ((i == 7) && (min_height != NULL))
        *min_height = pixmap_height;
    }
  }

  pixmap_height += padding.bottom + SECTION_SPACING;

  if (min_height != NULL && *min_height == -1)
    *min_height = pixmap_height;

  if (width != NULL)
    *width = pixmap_width;

  if (height != NULL)
    *height = pixmap_height;

  cairo_destroy (cr);
  cairo_surface_destroy (surface);
  g_free (sizes);
}
예제 #3
0
int main(int argc, char *argv[]) {     
    int fd;                      /* fd to Erlang node */
    unsigned char buf[BUFSIZE];  /* Buffer for incoming message */
    ErlMessage emsg;             /* Incoming message */
    int c_node;                   /* C-Node number */
    char cookie[EI_MAX_COOKIE_SIZE+1];  /* Shared cookie */
    short creation;              /* ?? */
    char *erlang_node;           /* Erlang node to connect to */
	 char *cookie_opt;				/* Where to source our cookie */
	 char *cookie_data;				/* Either the filename or literal cookie */
    ETERM *fromp, *msgp, *fnp, *argp, *resp;
    int received, loop = 1;
    
    if (argc < 5) {
        quit_with_error("invalid_args");
    }
    
    c_node = atoi(argv[1]);
    cookie_opt = argv[2];
	 cookie_data = argv[3];
    creation = 0;
    erlang_node = argv[4];
    
    erl_init(NULL, 0);

	 get_cookie(cookie_opt, cookie_data, cookie);
    
    if (!erl_connect_init(c_node, cookie, creation)) {
        quit_with_error("erl_connect_init");
    }
    
    if ((fd = erl_connect(erlang_node)) < 0) {
        quit_with_error("erl_connect"); 
    }
       
    while (loop) {
        received = erl_receive_msg(fd, buf, BUFSIZE, &emsg);

    if (received == ERL_TICK) {
        /* ignore */    
    } else if (received == ERL_ERROR) {
        loop = 0;
    } else {
        if (emsg.type == ERL_REG_SEND) {          
            fromp = erl_element(2, emsg.msg);
            msgp = erl_element(3, emsg.msg);
            fnp = erl_element(1, msgp);
            argp = erl_element(2, msgp);  
            
            if (is_function(fnp, "stop")) {
                loop = 0;
                resp = erl_format("{c_node, ~i, ok}", c_node);
            } else if (is_function(fnp, "new_image_blank")) { 
                resp = new_image_blank(argp, c_node); 
            } else if (is_function(fnp, "write_to_png")) {
                resp = write_to_png(argp, c_node);
            } else if (is_function(fnp, "close_image")) {
                resp = close_image(argp, c_node);
            } else if (is_function(fnp, "save")) {
                resp = save(argp, c_node);
            } else if (is_function(fnp, "restore")) {
                resp = restore(argp, c_node);
            } else if (is_function(fnp, "set_line_width")) {
                resp = set_line_width(argp, c_node);
            } else if (is_function(fnp, "set_source_rgba")) {
                resp = set_source_rgba(argp, c_node);	
	        } else if (is_function(fnp, "set_operator")) {
                resp = set_operator(argp, c_node);
            } else if (is_function(fnp, "move_to")) {
                resp = move_to(argp, c_node);
            } else if (is_function(fnp, "line_to")) {
                resp = line_to(argp, c_node);
            } else if (is_function(fnp, "curve_to")) {
                resp = curve_to(argp, c_node);
            } else if (is_function(fnp, "rel_move_to")) {
                resp = rel_move_to(argp, c_node);
            } else if (is_function(fnp, "rel_line_to")) {
                resp = rel_line_to(argp, c_node);
            } else if (is_function(fnp, "rel_curve_to")) {
                resp = rel_curve_to(argp, c_node);
            } else if (is_function(fnp, "rectangle")) {
                resp = rectangle(argp, c_node);
            } else if (is_function(fnp, "arc")) {
                resp = arc(argp, c_node);
            } else if (is_function(fnp, "arc_negative")) {
                resp = arc_negative(argp, c_node);
            } else if (is_function(fnp, "close_path")) {
                resp = close_path(argp, c_node);
            } else if (is_function(fnp, "paint")) {
                resp = paint(argp, c_node);
            } else if (is_function(fnp, "fill")) {
                resp = fill(argp, c_node);
            } else if (is_function(fnp, "fill_preserve")) {
                resp = fill_preserve(argp, c_node);
            } else if (is_function(fnp, "stroke")) {
                resp = stroke(argp, c_node);
            } else if (is_function(fnp, "stroke_preserve")) {
                resp = stroke_preserve(argp, c_node);
            } else if (is_function(fnp, "translate")) {
                resp = translate(argp, c_node);
            } else if (is_function(fnp, "scale")) {
                resp = scale(argp, c_node);
            } else if (is_function(fnp, "rotate")) {
                resp = rotate(argp, c_node);
            } else if (is_function(fnp, "select_font")) {
                resp = select_font_face(argp, c_node);
            } else if (is_function(fnp, "set_font_size")) {
                resp = set_font_size(argp, c_node);
            } else if (is_function(fnp, "show_text")) {
                resp = show_text(argp, c_node);
            } else if (is_function(fnp, "text_extents")) {
                resp = text_extents(argp, c_node);          
            } else if (is_function(fnp, "surface_create_from_png")) {
                resp = surface_create_from_png(argp, c_node);
            } else if (is_function(fnp, "surface_create_from_png_stream")) {
                resp = surface_create_from_png_stream(argp, c_node);
            } else if (is_function(fnp, "surface_get_width")) {
                resp = surface_get_width(argp, c_node);          
            } else if (is_function(fnp, "surface_get_height")) {
                resp = surface_get_height(argp, c_node);          
            } else if (is_function(fnp, "surface_destroy")) {
                resp = surface_destroy(argp, c_node);          
            } else if (is_function(fnp, "set_source_surface")) {
                resp = set_source_surface(argp, c_node);          
            } else if (is_function(fnp, "write_to_png_stream")) {
                resp = write_to_png_stream(argp, c_node);          
            } else {
                resp = erl_format("{c_node, ~i, {error, '~s'}}", c_node, "unknown command");
            }         
            erl_send(fd, fromp, resp);           
            erl_free_term(emsg.from); 
            erl_free_term(emsg.msg);
            erl_free_term(fromp); 
            erl_free_term(msgp);
            erl_free_term(fnp); 
            erl_free_term(argp);
            erl_free_term(resp);
      }
    }
  }
  exit(EXIT_SUCCESS);
}