summaryrefslogtreecommitdiffstats
path: root/src/display/control/canvas-item-text.h
blob: c5d5cff97398a06c66c3ebecd5658fff8f247084 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef SEEN_CANVAS_ITEM_TEXT_H
#define SEEN_CANVAS_ITEM_TEXT_H

/**
 * A class to represent on-screen text.
 */

/*
 * Author:
 *   Tavmjong Bah
 *
 * Copyright (C) 2020 Tavmjong Bah
 *
 * Rewrite of SPCanvasText.
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include <glibmm/ustring.h>

#include <2geom/point.h>
#include <2geom/transforms.h>

#include "canvas-item.h"

namespace Inkscape {

namespace UI::Widget {
class Canvas;
}

class CanvasItemGroup; // A canvas control that contains other canvas controls.

class CanvasItemText : public CanvasItem {

public:
    CanvasItemText(CanvasItemGroup *group);
    CanvasItemText(CanvasItemGroup *group, Geom::Point const &p, Glib::ustring text);

    // Geometry
    void set_coord(Geom::Point const &p);
    void set_bg_radius(double const &rad);

    void update(Geom::Affine const &affine) override;
    double closest_distance_to(Geom::Point const &p); // Maybe not needed

    // Selection
    bool contains(Geom::Point const &p, double tolerance = 0) override;

    // Display
    void render(Inkscape::CanvasItemBuffer *buf) override;

    // Properties
    void set_text(Glib::ustring const &text);
    void set_fontsize(double fontsize);
    void set_background(guint32 background);
    void set_anchor(Geom::Point const &anchor_pt);
    void set_adjust(Geom::Point const &adjust_pt);
    void set_fixed_line(bool fixed_line);

protected:
    Geom::Point _p;  // Position of text (not box around text).
    Cairo::TextExtents _text_extent;
    Cairo::TextExtents _text_size;
    Geom::Point _anchor_position;
    Geom::Point _adjust_offset;
    Glib::ustring _text;
    std::string _fontname = "sans-serif";
    double _fontsize = 10;
    double _bg_rad = 0;
    guint32 _background = 0x0000007f;
    bool _use_background = false;
    bool _fixed_line = false; // Correction for font heights
    const double _border = 3; // Must be a const to allow alignment with other text boxes.
};


} // namespace Inkscape

#endif // SEEN_CANVAS_ITEM_TEXT_H

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :