Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
sp-text.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef SEEN_SP_TEXT_H
3#define SEEN_SP_TEXT_H
4
5/*
6 * SVG <text> and <tspan> implementation
7 *
8 * Author:
9 * Lauris Kaplinski <lauris@kaplinski.com>
10 *
11 * Copyright (C) 1999-2002 Lauris Kaplinski
12 * Copyright (C) 2000-2001 Ximian, Inc.
13 *
14 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
15 */
16
17#include <cstddef>
18#include <sigc++/sigc++.h>
19
20#include "desktop.h"
21#include "sp-item.h"
22#include "sp-string.h" // Provides many other headers with is<SPString>
23#include "text-tag-attributes.h"
24#include "display/curve.h"
25
28
29#include <memory>
30
31/* Text specific flags */
32#define SP_TEXT_CONTENT_MODIFIED_FLAG SP_OBJECT_USER_MODIFIED_FLAG_A
33#define SP_TEXT_LAYOUT_MODIFIED_FLAG SP_OBJECT_USER_MODIFIED_FLAG_A
34
35class SPShape;
36
37/* SPText */
38class SPText final : public SPItem {
39public:
40 SPText();
41 ~SPText() override;
42 int tag() const override { return tag_of<decltype(*this)>; }
43
46
48 void rebuildLayout();
49
50 //semiprivate: (need to be accessed by the C-style functions still)
53 std::unordered_map<unsigned, Inkscape::Text::StyleAttachments> view_style_attachments;
54
61 static void _adjustCoordsRecursive(SPItem *item, Geom::Affine const &m, double ex, bool is_root = true);
62 static void _adjustFontsizeRecursive(SPItem *item, double ex, bool is_root = true);
67 void show_shape_inside();
68 void hide_shape_inside();
69
71 void _clearFlow(Inkscape::DrawingGroup *in_arena);
72
74
76 std::unique_ptr<Shape> getExclusionShape() const;
78 std::unique_ptr<Shape> getInclusionShape(SPShape *shape) const;
85 std::vector<std::unique_ptr<Shape>> makeEffectiveShapes() const;
86
87 std::optional<Geom::Point> getBaselinePoint() const;
88
89private:
90
92 void _buildLayoutInit();
93
99 unsigned _buildLayoutInput(SPObject *object, Inkscape::Text::Layout::OptionalTextTagAttrs const &parent_optional_attrs, unsigned parent_attrs_offset, bool in_textpath);
100
105
106 public:
109
110 void build(SPDocument* doc, Inkscape::XML::Node* repr) override;
111 void release() override;
113 void remove_child(Inkscape::XML::Node* child) override;
114 void set(SPAttr key, const char* value) override;
115 void update(SPCtx* ctx, unsigned int flags) override;
116 void modified(unsigned int flags) override;
117 Inkscape::XML::Node* write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, unsigned int flags) override;
118
119 Geom::OptRect bbox(Geom::Affine const &transform, SPItem::BBoxType type) const override;
120 void print(SPPrintContext *ctx) override;
121 const char* typeName() const override;
122 const char* displayName() const override;
123 char* description() const override;
124 Inkscape::DrawingItem* show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) override;
125 void hide(unsigned int key) override;
126 void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) const override;
128 void getLinked(std::vector<SPObject *> &objects, LinkedObjectNature direction = LinkedObjectNature::ANY) const override;
129
130 // For 'inline-size', need to also remove any 'x' and 'y' added by SVG 1.1 fallback.
132
133 void newline_to_sodipodi(); // 'inline-size' to Inkscape multi-line text.
134 void sodipodi_to_newline(); // Inkscape mult-line text to SVG 2 text.
135
136 bool is_horizontal() const;
137 bool has_inline_size() const;
138 bool has_shape_inside() const;
139 Geom::OptRect get_frame(); // Gets inline-size or shape-inside frame.
140 Inkscape::XML::Node* get_first_rectangle(); // Gets first shape-inside rectangle (if it exists).
142 const std::vector<SPItem *> get_all_shape_dependencies() const;
143 void remove_newlines(); // Removes newlines in text.
144};
145
148
149#endif
150
151/*
152 Local Variables:
153 mode:c++
154 c-file-style:"stroustrup"
155 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
156 indent-tabs-mode:nil
157 fill-column:99
158 End:
159*/
160// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
SPAttr
Definition attributes.h:27
constexpr int tag_of
Convenience function to retrieve the tag (class id) of a given type.
Definition cast.h:26
3x3 matrix representing an affine transformation.
Definition affine.h:70
Axis-aligned rectangle that can be empty.
Definition rect.h:203
Two-dimensional point that doubles as a vector.
Definition point.h:66
SVG drawing item for display.
Storing of snapping preferences.
Generates the layout for either wrapped or non-wrapped text and stores the result.
Definition Layout-TNG.h:144
Interface for refcounted XML nodes.
Definition node.h:80
Wrapper around a Geom::PathVector object.
Definition curve.h:28
To do: update description of desktop.
Definition desktop.h:149
Typed SVG document implementation.
Definition document.h:101
Base class for visual SVG elements.
Definition sp-item.h:109
Geom::Affine transform
Definition sp-item.h:138
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
Inkscape::XML::Node * repr
Definition sp-object.h:193
LinkedObjectNature
Definition sp-object.h:168
Base class for shapes, including <path> element.
Definition sp-shape.h:38
void getLinked(std::vector< SPObject * > &objects, LinkedObjectNature direction=LinkedObjectNature::ANY) const override
Get objects which are linked to this object as either a source or a target.
Definition sp-text.cpp:1195
bool has_inline_size() const
Definition sp-text.cpp:1115
void child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) override
Definition sp-text.cpp:134
std::unique_ptr< Shape > getInclusionShape(SPShape *shape) const
Add a single inclusion shape with padding.
Definition sp-text.cpp:759
~SPText() override
Definition sp-text.cpp:77
void newline_to_sodipodi()
Convert new lines in 'inline-size' text to tspans with sodipodi:role="tspan".
Definition sp-text.cpp:1051
void optimizeTextpathText()
Optimize textpath text on next set_transform.
Definition sp-text.h:108
void sodipodi_to_newline()
Convert tspans with sodipodi:role="tspans" to ' '.
Definition sp-text.cpp:1077
void print(SPPrintContext *ctx) override
Definition sp-text.cpp:480
SVGLength * _getFirstYLength()
Definition sp-text.cpp:861
SPItem * get_first_shape_dependency()
Get the first shape reference which affects the position and layout of this text item.
Definition sp-text.cpp:1210
void release() override
Definition sp-text.cpp:99
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
Definition sp-text.cpp:84
Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags) override
Definition sp-text.cpp:257
std::unique_ptr< Shape > getExclusionShape() const
Union all exclusion shapes.
Definition sp-text.cpp:713
static void _adjustCoordsRecursive(SPItem *item, Geom::Affine const &m, double ex, bool is_root=true)
when the object is transformed it's nicer to change the font size and coordinates when we can,...
Definition sp-text.cpp:1009
void _buildLayoutInit()
Initializes layout from <text> (i.e.
Definition sp-text.cpp:495
std::optional< Geom::Point > getBaselinePoint() const
Get the position of the baseline point for this text object.
Definition sp-text.cpp:955
SPCurve getNormalizedBpath() const
Converts the text object to its component curves.
Definition sp-text.cpp:878
SPText()
Definition sp-text.cpp:74
void _clearFlow(Inkscape::DrawingGroup *in_arena)
discards the drawing objects representing this text.
Definition sp-text.cpp:1032
bool has_shape_inside() const
Definition sp-text.cpp:1121
std::unordered_map< unsigned, Inkscape::Text::StyleAttachments > view_style_attachments
Definition sp-text.h:53
void hide_shape_inside()
Definition sp-text.cpp:395
SPCSSAttr * css
Definition sp-text.h:104
void update(SPCtx *ctx, unsigned int flags) override
Definition sp-text.cpp:147
std::vector< std::unique_ptr< Shape > > makeEffectiveShapes() const
Compute the final effective shapes: All inclusion shapes shrunk by the padding, from which we subtrac...
Definition sp-text.cpp:810
static void _adjustFontsizeRecursive(SPItem *item, double ex, bool is_root=true)
Definition sp-text.cpp:924
Inkscape::DrawingItem * show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) override
Definition sp-text.cpp:315
void remove_child(Inkscape::XML::Node *child) override
Definition sp-text.cpp:140
void show_shape_inside()
This two functions are useful because layout calculations need text visible for example Calculating a...
Definition sp-text.cpp:410
int tag() const override
Definition sp-text.h:42
Geom::Affine set_transform(Geom::Affine const &transform) override
Definition sp-text.cpp:417
Geom::OptRect get_frame()
Definition sp-text.cpp:1127
const char * displayName() const override
The item's type name as a translated human string.
Definition sp-text.cpp:344
Geom::OptRect bbox(Geom::Affine const &transform, SPItem::BBoxType type) const override
Definition sp-text.cpp:311
void rebuildLayout()
Completely recalculates the layout.
Definition sp-text.cpp:883
SVGLength * _getFirstXLength()
Find first x/y values which may be in a descendent element.
Definition sp-text.cpp:842
void remove_newlines()
Definition sp-text.cpp:1001
Inkscape::Text::Layout layout
Definition sp-text.h:52
bool is_horizontal() const
Definition sp-text.cpp:1109
void modified(unsigned int flags) override
Definition sp-text.cpp:216
void snappoints(std::vector< Inkscape::SnapCandidatePoint > &p, Inkscape::SnapPreferences const *snapprefs) const override
Definition sp-text.cpp:379
const char * typeName() const override
The item's type name, not node tag name.
Definition sp-text.cpp:338
TextTagAttributes attributes
Definition sp-text.h:51
bool _optimizeTextpathText
Definition sp-text.h:73
Inkscape::XML::Node * get_first_rectangle()
Definition sp-text.cpp:1177
void hide(unsigned int key) override
Definition sp-text.cpp:327
void remove_svg11_fallback()
Remove 'x' and 'y' values on children (lines) or they will be interpreted as absolute positions when ...
Definition sp-text.cpp:1041
unsigned _buildLayoutInput(SPObject *object, Inkscape::Text::Layout::OptionalTextTagAttrs const &parent_optional_attrs, unsigned parent_attrs_offset, bool in_textpath)
Recursively walks the xml tree adding tags and their contents.
Definition sp-text.cpp:561
const std::vector< SPItem * > get_all_shape_dependencies() const
Definition sp-text.cpp:1218
char * description() const override
Definition sp-text.cpp:354
SVG length type.
Definition svg-length.h:22
Editable view implementation.
SPItem * item
static cairo_user_data_key_t key
Ocnode * child[8]
Definition quantize.cpp:33
Ocnode ** ref
Definition quantize.cpp:32
Some things pertinent to all visible shapes: SPItem, SPItemView, SPItemCtx.
TODO: insert short description here.
SPItem * create_text_with_rectangle(SPDesktop *desktop, Geom::Point p0, Geom::Point p1)
Definition sp-text.cpp:1276
SPItem * create_text_with_inline_size(SPDesktop *desktop, Geom::Point p0, Geom::Point p1)
Definition sp-text.cpp:1234
The optional attributes which can be applied to a SVG text or related tag.
Definition Layout-TNG.h:184
Interface for XML documents.
Definition document.h:43
Unused.
Definition sp-object.h:94
Creates and maintains display tree needed for text styling.
SPDesktop * desktop
contains and manages the attributes common to all types of text tag