Commit b0ef5036 authored by Christian Persch's avatar Christian Persch

draw: Use attr in public functions instead of font style

Move public function to the only file it is used from, and
pass the attr directly to draw_text etc instead of the
bold/italc style.
parent 39ea41b9
...@@ -25,10 +25,6 @@ ...@@ -25,10 +25,6 @@
#include "drawing-cairo.hh" #include "drawing-cairo.hh"
#include "fonts-pangocairo.hh" #include "fonts-pangocairo.hh"
#define VTE_DRAW_NORMAL 0
#define VTE_DRAW_BOLD 1
#define VTE_DRAW_ITALIC 2
/* cairo_show_glyphs accepts runs up to 102 glyphs before it allocates a /* cairo_show_glyphs accepts runs up to 102 glyphs before it allocates a
* temporary array. * temporary array.
* *
...@@ -37,11 +33,18 @@ ...@@ -37,11 +33,18 @@
*/ */
#define MAX_RUN_LENGTH 100 #define MAX_RUN_LENGTH 100
guint _vte_draw_get_style(gboolean bold, gboolean italic) { #define VTE_DRAW_NORMAL 0
guint style = 0; #define VTE_DRAW_BOLD 1
if (bold) #define VTE_DRAW_ITALIC 2
#define VTE_DRAW_BOLD_ITALIC 3
static unsigned
attr_to_style(uint32_t attr)
{
auto style = unsigned{0};
if (attr & VTE_ATTR_BOLD)
style |= VTE_DRAW_BOLD; style |= VTE_DRAW_BOLD;
if (italic) if (attr & VTE_ATTR_ITALIC)
style |= VTE_DRAW_ITALIC; style |= VTE_DRAW_ITALIC;
return style; return style;
} }
...@@ -226,7 +229,7 @@ DrawingContext::get_text_metrics(int* cell_width, ...@@ -226,7 +229,7 @@ DrawingContext::get_text_metrics(int* cell_width,
void void
DrawingContext::get_char_edges(vteunistr c, DrawingContext::get_char_edges(vteunistr c,
int columns, int columns,
guint style, uint32_t attr,
int& left, int& left,
int& right) int& right)
{ {
...@@ -244,7 +247,7 @@ DrawingContext::get_char_edges(vteunistr c, ...@@ -244,7 +247,7 @@ DrawingContext::get_char_edges(vteunistr c,
return; return;
} }
w = m_fonts[style]->get_unistr_info(c)->width; w = m_fonts[attr_to_style(attr)]->get_unistr_info(c)->width;
normal_width = m_fonts[VTE_DRAW_NORMAL]->width() * columns; normal_width = m_fonts[VTE_DRAW_NORMAL]->width() * columns;
fits_width = m_cell_width * columns; fits_width = m_cell_width * columns;
...@@ -270,14 +273,13 @@ DrawingContext::draw_text_internal(TextRequest* requests, ...@@ -270,14 +273,13 @@ DrawingContext::draw_text_internal(TextRequest* requests,
gsize n_requests, gsize n_requests,
uint32_t attr, uint32_t attr,
vte::color::rgb const* color, vte::color::rgb const* color,
double alpha, double alpha)
guint style)
{ {
gsize i; gsize i;
cairo_scaled_font_t *last_scaled_font = nullptr; cairo_scaled_font_t *last_scaled_font = nullptr;
int n_cr_glyphs = 0; int n_cr_glyphs = 0;
cairo_glyph_t cr_glyphs[MAX_RUN_LENGTH]; cairo_glyph_t cr_glyphs[MAX_RUN_LENGTH];
auto font = m_fonts[style]; auto font = m_fonts[attr_to_style(attr)];
g_return_if_fail (font != nullptr); g_return_if_fail (font != nullptr);
...@@ -306,7 +308,7 @@ DrawingContext::draw_text_internal(TextRequest* requests, ...@@ -306,7 +308,7 @@ DrawingContext::draw_text_internal(TextRequest* requests,
auto ufi = &uinfo->m_ufi; auto ufi = &uinfo->m_ufi;
int x, y, ye; int x, y, ye;
get_char_edges(c, requests[i].columns, style, x, ye /* unused */); get_char_edges(c, requests[i].columns, attr, x, ye /* unused */);
x += requests[i].x; x += requests[i].x;
/* Bold/italic versions might have different ascents. In order to align their /* Bold/italic versions might have different ascents. In order to align their
* baselines, we offset by the normal font's ascent here. (Bug 137.) */ * baselines, we offset by the normal font's ascent here. (Bug 137.) */
...@@ -360,8 +362,7 @@ DrawingContext::draw_text(TextRequest* requests, ...@@ -360,8 +362,7 @@ DrawingContext::draw_text(TextRequest* requests,
gsize n_requests, gsize n_requests,
uint32_t attr, uint32_t attr,
vte::color::rgb const* color, vte::color::rgb const* color,
double alpha, double alpha)
guint style)
{ {
g_assert(m_cr); g_assert(m_cr);
...@@ -375,12 +376,12 @@ DrawingContext::draw_text(TextRequest* requests, ...@@ -375,12 +376,12 @@ DrawingContext::draw_text(TextRequest* requests,
str = g_string_free (string, FALSE); str = g_string_free (string, FALSE);
g_printerr ("draw_text (\"%s\", len=%" G_GSIZE_FORMAT ", color=(%d,%d,%d,%.3f), %s - %s)\n", g_printerr ("draw_text (\"%s\", len=%" G_GSIZE_FORMAT ", color=(%d,%d,%d,%.3f), %s - %s)\n",
str, n_requests, color->red, color->green, color->blue, alpha, str, n_requests, color->red, color->green, color->blue, alpha,
(style & VTE_DRAW_BOLD) ? "bold" : "normal", (attr & VTE_ATTR_BOLD) ? "bold" : "normal",
(style & VTE_DRAW_ITALIC) ? "italic" : "regular"); (attr & VTE_ATTR_ITALIC) ? "italic" : "regular");
g_free (str); g_free (str);
} }
draw_text_internal(requests, n_requests, attr, color, alpha, style); draw_text_internal(requests, n_requests, attr, color, alpha);
} }
/* The following two functions are unused since commit 154abade902850afb44115cccf8fcac51fc082f0, /* The following two functions are unused since commit 154abade902850afb44115cccf8fcac51fc082f0,
...@@ -388,12 +389,13 @@ DrawingContext::draw_text(TextRequest* requests, ...@@ -388,12 +389,13 @@ DrawingContext::draw_text(TextRequest* requests,
*/ */
bool bool
DrawingContext::has_char(vteunistr c, DrawingContext::has_char(vteunistr c,
guint style) uint32_t attr)
{ {
_vte_debug_print (VTE_DEBUG_DRAW, "draw_has_char ('0x%04X', %s - %s)\n", c, _vte_debug_print (VTE_DEBUG_DRAW, "draw_has_char ('0x%04X', %s - %s)\n", c,
(style & VTE_DRAW_BOLD) ? "bold" : "normal", (attr & VTE_ATTR_BOLD) ? "bold" : "normal",
(style & VTE_DRAW_ITALIC) ? "italic" : "regular"); (attr & VTE_ATTR_ITALIC) ? "italic" : "regular");
auto const style = attr_to_style(attr);
g_return_val_if_fail(m_fonts[style], false); g_return_val_if_fail(m_fonts[style], false);
auto uinfo = m_fonts[style]->get_unistr_info(c); auto uinfo = m_fonts[style]->get_unistr_info(c);
...@@ -404,20 +406,19 @@ bool ...@@ -404,20 +406,19 @@ bool
DrawingContext::draw_char(TextRequest* request, DrawingContext::draw_char(TextRequest* request,
uint32_t attr, uint32_t attr,
vte::color::rgb const* color, vte::color::rgb const* color,
double alpha, double alpha)
guint style)
{ {
_vte_debug_print (VTE_DEBUG_DRAW, _vte_debug_print (VTE_DEBUG_DRAW,
"draw_char ('%c', color=(%d,%d,%d,%.3f), %s, %s)\n", "draw_char ('%c', color=(%d,%d,%d,%.3f), %s, %s)\n",
request->c, request->c,
color->red, color->green, color->blue, color->red, color->green, color->blue,
alpha, alpha,
(style & VTE_DRAW_BOLD) ? "bold" : "normal", (attr & VTE_ATTR_BOLD) ? "bold" : "normal",
(style & VTE_DRAW_ITALIC) ? "italic" : "regular"); (attr & VTE_ATTR_ITALIC) ? "italic" : "regular");
auto const have_char = has_char(request->c, style); auto const have_char = has_char(request->c, attr);
if (have_char) if (have_char)
draw_text(request, 1, attr, color, alpha, style); draw_text(request, 1, attr, color, alpha);
return have_char; return have_char;
} }
......
...@@ -85,24 +85,20 @@ public: ...@@ -85,24 +85,20 @@ public:
GtkBorder* char_spacing); GtkBorder* char_spacing);
void get_char_edges(vteunistr c, void get_char_edges(vteunistr c,
int columns, int columns,
guint style, uint32_t attr,
int& left, int& left,
int& right); int& right);
bool has_bold(guint style);
void draw_text(TextRequest* requests, void draw_text(TextRequest* requests,
gsize n_requests, gsize n_requests,
uint32_t attr, uint32_t attr,
vte::color::rgb const* color, vte::color::rgb const* color,
double alpha, double alpha);
guint style);
bool draw_char(TextRequest* request, bool draw_char(TextRequest* request,
uint32_t attr, uint32_t attr,
vte::color::rgb const* color, vte::color::rgb const* color,
double alpha, double alpha);
guint style);
bool has_char(vteunistr c, bool has_char(vteunistr c,
guint style); uint32_t attr);
void fill_rectangle(int x, void fill_rectangle(int x,
int y, int y,
int width, int width,
...@@ -148,8 +144,7 @@ private: ...@@ -148,8 +144,7 @@ private:
gsize n_requests, gsize n_requests,
uint32_t attr, uint32_t attr,
vte::color::rgb const* color, vte::color::rgb const* color,
double alpha, double alpha);
guint style);
// std::array<vte::base::RefPtr<FontInfo>, 4> m_fonts{}; // std::array<vte::base::RefPtr<FontInfo>, 4> m_fonts{};
FontInfo* m_fonts[4]{nullptr, nullptr, nullptr, nullptr}; FontInfo* m_fonts[4]{nullptr, nullptr, nullptr, nullptr};
...@@ -168,8 +163,6 @@ private: ...@@ -168,8 +163,6 @@ private:
} // namespace view } // namespace view
} // namespace vte } // namespace vte
guint _vte_draw_get_style(gboolean bold, gboolean italic);
double double
_vte_draw_get_undercurl_height(gint width, double line_width); _vte_draw_get_undercurl_height(gint width, double line_width);
......
...@@ -8351,9 +8351,7 @@ Terminal::draw_cells(vte::view::DrawingContext::TextRequest* items, ...@@ -8351,9 +8351,7 @@ Terminal::draw_cells(vte::view::DrawingContext::TextRequest* items,
m_draw.draw_text( m_draw.draw_text(
items, n, items, n,
attr, attr,
&fg, VTE_DRAW_OPAQUE, &fg, VTE_DRAW_OPAQUE);
_vte_draw_get_style(attr & VTE_ATTR_BOLD,
attr & VTE_ATTR_ITALIC));
} }
/* FIXME: we don't have a way to tell GTK+ what the default text attributes /* FIXME: we don't have a way to tell GTK+ what the default text attributes
...@@ -8933,7 +8931,6 @@ Terminal::paint_cursor() ...@@ -8933,7 +8931,6 @@ Terminal::paint_cursor()
vte::grid::row_t drow; vte::grid::row_t drow;
vte::grid::column_t lcol, vcol; vte::grid::column_t lcol, vcol;
int width, height, cursor_width; int width, height, cursor_width;
guint style = 0;
guint fore, back, deco; guint fore, back, deco;
vte::color::rgb bg; vte::color::rgb bg;
int x, y; int x, y;
...@@ -8984,9 +8981,7 @@ Terminal::paint_cursor() ...@@ -8984,9 +8981,7 @@ Terminal::paint_cursor()
item.y = row_to_pixel(drow); item.y = row_to_pixel(drow);
item.mirror = bidirow->vis_is_rtl(vcol); item.mirror = bidirow->vis_is_rtl(vcol);
item.box_mirror = (row_data && (row_data->attr.bidi_flags & VTE_BIDI_FLAG_BOX_MIRROR)); item.box_mirror = (row_data && (row_data->attr.bidi_flags & VTE_BIDI_FLAG_BOX_MIRROR));
if (cell && cell->c != 0) { auto const attr = cell && cell->c ? cell->attr.attr : 0;
style = _vte_draw_get_style(cell->attr.bold(), cell->attr.italic());
}
selected = cell_is_selected_log(lcol, drow); selected = cell_is_selected_log(lcol, drow);
determine_cursor_colors(cell, selected, &fore, &back, &deco); determine_cursor_colors(cell, selected, &fore, &back, &deco);
...@@ -9049,7 +9044,7 @@ Terminal::paint_cursor() ...@@ -9049,7 +9044,7 @@ Terminal::paint_cursor()
if (cell && cell->c != 0 && cell->c != ' ' && cell->c != '\t') { if (cell && cell->c != 0 && cell->c != ' ' && cell->c != '\t') {
int l, r; int l, r;
m_draw.get_char_edges(cell->c, cell->attr.columns(), style, l, r); m_draw.get_char_edges(cell->c, cell->attr.columns(), attr, l, r);
left = MIN(left, l); left = MIN(left, l);
right = MAX(right, r); right = MAX(right, r);
} }
...@@ -9068,7 +9063,7 @@ Terminal::paint_cursor() ...@@ -9068,7 +9063,7 @@ Terminal::paint_cursor()
cursor_width = item.columns * width; cursor_width = item.columns * width;
if (cell && cell->c != 0 && cell->c != ' ' && cell->c != '\t') { if (cell && cell->c != 0 && cell->c != ' ' && cell->c != '\t') {
int l, r; int l, r;
m_draw.get_char_edges(cell->c, cell->attr.columns(), style, l /* unused */, r); m_draw.get_char_edges(cell->c, cell->attr.columns(), attr, l /* unused */, r);
cursor_width = MAX(cursor_width, r); cursor_width = MAX(cursor_width, r);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment