int draw_text (unsigned char *image, int startx, int starty, int width, const char *text, unsigned short int factor) { int num_nl = 0; const char *end, *begin; const int line_space = (factor + 1) * 9; /* Count the number of newlines in "text" so we scroll it up the image */ end = text; while ((end = strstr(end, NEWLINE))) { num_nl++; end += sizeof(NEWLINE)-1; } starty -= line_space * num_nl; begin = end = text; while ((end = strstr(end, NEWLINE))) { int len = end-begin; draw_textn(image, startx, starty, width, begin, len, factor); end += sizeof(NEWLINE)-1; begin = end; starty += line_space; } draw_textn(image, startx, starty, width, begin, strlen(begin), factor); return 0; }
/** * draw_text */ int draw_text(unsigned char *image, int width, int height, int startx, int starty, const char *text, int factor) { int num_nl = 0; const char *end, *begin; int line_space, txtlen; /* Count the number of newlines in "text" so we scroll it up the image. */ begin = end = text; txtlen = 0; while ((end = strstr(end, NEWLINE))) { if ((end - begin)>txtlen) txtlen = (end - begin); num_nl++; end += sizeof(NEWLINE)-1; } if (txtlen == 0) txtlen = strlen(text); /* Adjust the factor if it is out of bounds * txtlen at this point is the approx length of longest line */ if ((txtlen * 7 * factor) > width){ factor = (width / (txtlen * 7)); if (factor <= 0) factor = 1; } if (((num_nl+1) * 8 * factor) > height){ factor = (height / ((num_nl+1) * 8)); if (factor <= 0) factor = 1; } line_space = factor * 9; starty -= line_space * num_nl; begin = end = text; while ((end = strstr(end, NEWLINE))) { int len = end-begin; draw_textn(image, startx, starty, width, begin, len, factor); end += sizeof(NEWLINE)-1; begin = end; starty += line_space; } draw_textn(image, startx, starty, width, begin, strlen(begin), factor); return 0; }
bool view_column_draw(struct view *view, struct line *line, unsigned int lineno) { struct view_column *column = view->columns; struct view_column_data column_data = {0}; if (!view->ops->get_column_data(view, line, &column_data)) return true; if (column_data.section) column = column_data.section; for (; column; column = column->next) { mode_t mode = column_data.mode ? *column_data.mode : 0; if (column->hidden) continue; switch (column->type) { case VIEW_COLUMN_DATE: if (draw_date(view, column, column_data.date)) return true; continue; case VIEW_COLUMN_AUTHOR: if (draw_author(view, column, column_data.author)) return true; continue; case VIEW_COLUMN_REF: if (draw_ref(view, column, column_data.ref)) return true; continue; case VIEW_COLUMN_ID: if (draw_id(view, column, column_data.reflog ? column_data.reflog : column_data.id)) return true; continue; case VIEW_COLUMN_LINE_NUMBER: if (draw_lineno(view, column, column_data.line_number ? *column_data.line_number : lineno)) return true; continue; case VIEW_COLUMN_MODE: if (draw_mode(view, column, mode)) return true; continue; case VIEW_COLUMN_FILE_SIZE: if (draw_file_size(view, column, column_data.file_size ? *column_data.file_size : 0, mode)) return true; continue; case VIEW_COLUMN_COMMIT_TITLE: if (draw_commit_title(view, column, column_data.graph, column_data.graph_canvas, column_data.refs, column_data.commit_title)) return true; continue; case VIEW_COLUMN_FILE_NAME: if (draw_filename(view, column, column_data.file_name, mode)) return true; continue; case VIEW_COLUMN_SECTION: if (draw_text(view, column->opt.section.type, column->opt.section.text)) return true; continue; case VIEW_COLUMN_STATUS: if (draw_status(view, column, line->type, column_data.status)) return true; continue; case VIEW_COLUMN_TEXT: { enum line_type type = line->type; const char *text = column_data.text; if (line->wrapped && draw_text(view, LINE_DELIMITER, "+")) return true; if (line->graph_indent) { size_t indent = get_graph_indent(text); if (draw_text_expanded(view, LINE_DEFAULT, text, -1, indent, false)) return true; text += indent; } if (line->commit_title) { if (draw_text_overflow(view, text, LINE_DEFAULT, column->opt.text.commit_title_overflow, 4)) return true; } else if (column_data.box) { const struct box *box = column_data.box; const char *text = box->text; size_t i; for (i = 0; i < box->cells; i++) { const struct box_cell *cell = &box->cell[i]; if (draw_textn(view, cell->type, text, cell->length)) return true; text += cell->length; } } else if (draw_text(view, type, text)) { return true; } } continue; } } return true; }
bool draw_text(struct view *view, enum line_type type, const char *string) { return draw_textn(view, type, string, -1); }