1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/*
* Copyright © 2016-2020 Hayaki Saito <saitoha@me.com>
* Copyright © 2020 Hans Petter Jansson <hpj@cl.no>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <glib.h>
#include <stdio.h>
#include "vteinternal.hh"
#include "image.hh"
namespace vte {
namespace image {
/* Paint the image with provided cairo context */
void
Image::paint(cairo_t* cr,
int offset_x,
int offset_y,
int cell_width,
int cell_height) const noexcept
{
auto scale_x = 1.0;
auto scale_y = 1.0;
auto real_offset_x = double(offset_x);
auto real_offset_y = double(offset_y);
if (cell_width != m_cell_width || cell_height != m_cell_height) {
scale_x = cell_width / (double) m_cell_width;
scale_y = cell_height / (double) m_cell_height;
real_offset_x /= scale_x;
real_offset_y /= scale_y;
}
cairo_save(cr);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
if (!(_vte_double_equal (scale_x, 1.0) && _vte_double_equal (scale_y, 1.0)))
cairo_scale (cr, scale_x, scale_y);
cairo_rectangle(cr, real_offset_x, real_offset_y, m_width_pixels, m_height_pixels);
cairo_clip(cr);
cairo_set_source_surface(cr, m_surface.get(), real_offset_x, real_offset_y);
cairo_paint(cr);
cairo_restore(cr);
}
} // namespace image
} // namespace vte
|