12#ifndef SEEN_LAYOUT_TNG_H
13#define SEEN_LAYOUT_TNG_H
20#include <glibmm/ustring.h>
23#include <pango/pango-break.h>
28#include <sigc++/scoped_connection.h>
50class StyleAttachments;
185 std::vector<SVGLength>
x;
186 std::vector<SVGLength>
y;
187 std::vector<SVGLength>
dx;
188 std::vector<SVGLength>
dy;
258 void appendText(Glib::ustring
const &text,
SPStyle *style,
SPObject *source, OptionalTextTagAttrs
const *optional_attributes,
unsigned optional_attributes_offset, Glib::ustring::const_iterator text_begin, Glib::ustring::const_iterator text_end);
260 {
appendText(text, style, source, optional_attributes, optional_attributes_offset, text.begin(), text.end());}
396#if DEBUG_TEXTLAYOUT_DUMPASTEXT
438 inline iterator
begin()
const;
442 inline iterator
end()
const;
501 inline unsigned lineIndex(iterator
const &it)
const;
505 inline unsigned shapeIndex(iterator
const &it)
const;
516 bool isHidden(iterator
const &it)
const;
711 std::vector<SVGLength>
x;
712 std::vector<SVGLength>
y;
713 std::vector<SVGLength>
dx;
714 std::vector<SVGLength>
dy;
751 static void _copyInputVector(std::vector<SVGLength>
const &input_vector,
unsigned input_offset, std::vector<SVGLength> *output_vector,
size_t max_length);
826 std::vector<gunichar>
ret;
857 std::shared_ptr<FontInstance>
font;
913 return std::distance(
_spans.begin(),
914 std::lower_bound(
_spans.begin(),
_spans.end(), line_index, [
this] (
auto &span,
unsigned index) {
915 return _chunks[span.in_chunk].in_line < index;
924 return _chunks[_spans[character.in_span].in_chunk].in_line < index;
933 return character.in_span < index;
942 return _spans[character.in_span].in_input_stream_item < index;
1122 if (char_index < 0)
return begin();
1195 _cursor_moving_vertically =
false;
1196 if (_glyph_index == 0)
return false;
1197 _char_index = _parent_layout->_glyphs[--_glyph_index].in_character;
1203 _cursor_moving_vertically =
false;
1204 if (_char_index + 1 >= _parent_layout->_characters.size()) {
1205 if (_char_index == _parent_layout->_characters.size())
return false;
1206 _char_index = _parent_layout->_characters.size();
1207 _glyph_index = _parent_layout->_glyphs.size();
1209 else _glyph_index = _parent_layout->_characters[++_char_index].in_glyph;
1215 _cursor_moving_vertically =
false;
1216 if (_char_index == 0)
return false;
1217 _glyph_index = _parent_layout->_characters[--_char_index].in_glyph;
_PangoFontDescription PangoFontDescription
TODO: insert short description here.
3x3 affine transformation matrix.
FontInstance provides metrics, OpenType data, and glyph curves/pixbufs for a font.
3x3 matrix representing an affine transformation.
Axis-aligned rectangle that can be empty.
Sequence of contiguous curves, aka spline.
Two-dimensional point that doubles as a vector.
Axis aligned, non-empty rectangle.
Keep track of font metrics.
double getTypoDescent() const
double getXHeight() const
double getMaxAscent() const
double getTypoAscent() const
FontMetrics & operator*=(double x)
void computeEffective(const double &line_height)
Calculate the effective ascent and descent including half "leading".
double getMaxDescent() const
Represents a control code item in the input stream.
InputStreamItemType Type() const override
virtual ~InputStreamItem()=default
virtual InputStreamItemType Type() const =0
Represents a text item in the input stream.
LengthAdjust lengthAdjust
InputStreamItemType Type() const override
SPCSSBaseline styleGetDominantBaseline() const
std::vector< SVGLength > y
SPCSSTextOrientation styleGetTextOrientation() const
std::vector< SVGLength > dy
Alignment styleGetAlignment(Direction para_direction, bool try_text_align) const
Glib::ustring::const_iterator text_begin
owned by the caller
std::vector< SVGLength > rotate
std::vector< SVGLength > x
These vectors can (often will) be shorter than the text in this source, but never longer.
std::vector< SVGLength > dx
PangoFontDescription * styleGetFontDescription() const
The return value must be freed with pango_font_description_free()
Glib::ustring::const_iterator text_end
std::shared_ptr< FontInstance > styleGetFontInstance() const
SPStyle * style
in characters, from text_start to text_end only
~InputStreamTextSource() override
Direction styleGetBlockProgression() const
sigc::scoped_connection style_conn
Glib::ustring const * text
Holds a position within the glyph output of Layout.
bool prevStartOfSentence()
iterator(Layout const *p, unsigned c, int g)
bool cursorLeftWithControl()
bool prevLineCursor(int n=1)
bool operator!=(iterator const &other) const
bool _cursorLeftOrRightLocalX(Direction direction)
stores the current x coordinate so that the cursor won't drift. See _x_coordinate
bool operator<(iterator const &other) const
bool nextStartOfParagraph()
bool _cursor_moving_vertically
index into Layout::character
bool nextCursorPosition()
bool nextLineCursor(int n=1)
bool cursorDownWithControl()
bool prevStartOfParagraph()
unsigned _char_index
index into Layout::glyphs, or -1
bool operator>=(iterator const &other) const
bool thisStartOfParagraph()
bool cursorRightWithControl()
iterator(Layout const *p, unsigned c)
Layout const * _parent_layout
bool nextStartOfSentence()
bool operator>(iterator const &other) const
bool prevCursorPosition()
bool cursorUpWithControl()
bool operator<=(iterator const &other) const
double _x_coordinate
for cursor up/down movement we must maintain the x position where we started so the cursor doesn't 'd...
bool _cursorLeftOrRightLocalXByWord(Direction direction)
moves forward or backwards by until the next character with is_word_start according to the directiona...
Generates the layout for either wrapped or non-wrapped text and stores the result.
iterator getLetterAt(double x, double y) const
Returns an iterator pointing to the letter whose bounding box contains the given coordinates.
void transform(Geom::Affine const &transform)
Apply the given transform to all the output presently stored in this object.
std::vector< Geom::Point > createSelectionShape(iterator const &it_start, iterator const &it_end, Geom::Affine const &transform) const
Basically uses characterBoundingBox() on all the characters from start to end and returns the union o...
void clear()
Empties everything stored in this class and resets it to its original state, like when it was created...
SPCSSBaseline _blockBaseline() const
The overall text-orientation of the whole flow.
void simulateLayoutUsingKerning(iterator const &from, iterator const &to, OptionalTextTagAttrs *result) const
Returns kerning information which could cause the current output to be exactly reproduced if the lett...
unsigned _spanToCharacter(unsigned span_index) const
LengthAdjust lengthAdjust
How do we meet textLength if specified: by letterspacing or by scaling horizontally.
SPCSSTextOrientation _blockTextOrientation() const
The overall text-orientation of the whole flow.
std::vector< Geom::LineSegment > getBaselines() const
Returns all the baselines of a text element.
std::vector< Line > _lines
iterator charIndexToIterator(int char_index) const
Returns an iterator pointing at the given character index.
void queryCursorShape(iterator const &it, Geom::Point &position, double &height, double &rotation) const
Gets the ideal cursor shape for a given iterator.
std::vector< Layout::Glyph > const & glyphs() const
Publically allow access to the Layout::show logic outside of the Layout engine.
bool inputTruncated() const
unsigned shapeIndex(iterator const &it) const
Returns the zero-based number of the shape which contains the character pointed to by it.
Alignment
For expressing paragraph alignment.
double getTextLengthMultiplierDue() const
Get the actual scale multiplier if it's due with the current values of above stuff,...
unsigned lineIndex(iterator const &it) const
Returns the zero-based line number of the character pointed to by it.
void validateIterator(iterator *it) const
Checks the validity of the given iterator over the current layout.
static const double LINE_HEIGHT_NORMAL
The CSS spec allows line-height:normal to be whatever the user agent thinks will look good.
void appendControlCode(TextControlCode code, SPObject *source, double width=0.0, double ascent=0.0, double descent=0.0)
Control codes are metadata in the text stream to signify items that occupy real space (unlike style c...
std::vector< Glyph > _glyphs
iterator sourceToIterator(SPObject *source) const
Returns an iterator pointing to the first character in the output which was created from the given so...
bool inputExists() const
Queries whether any calls have been made to appendText() or appendControlCode() since the object was ...
bool isCursorPosition(iterator const &it) const
Returns true if it points to a character which is a valid cursor position, as defined by Pango.
void _clearInputObjects()
Erases all the stuff set by the owner as input, ie _input_stream and _input_wrap_shapes.
bool isHidden(iterator const &it) const
Returns true if the text at it is hidden (i.e.
unsigned _lineToSpan(unsigned line_index) const
Geom::Path baseline() const
std::vector< Chunk > _chunks
void appendText(Glib::ustring const &text, SPStyle *style, SPObject *source, OptionalTextTagAttrs const *optional_attributes=nullptr, unsigned optional_attributes_offset=0)
Geom::Point characterAnchorPoint(iterator const &it) const
For latin text, the left side of the character, on the baseline.
iterator _cursorXOnLineToIterator(unsigned line_index, double local_x, double local_y=0) const
given an x and y coordinate and a line number, returns an iterator pointing to the closest cursor pos...
void _clearOutputObjects()
Erases all the stuff output by computeFlow().
std::vector< Geom::LineSegment > _baselines
Direction _blockProgression() const
The overall block-progression of the whole flow.
struct Inkscape::Text::Layout::CursorShape _empty_cursor_shape
bool isEndOfWord(iterator const &it) const
Returns true if it points to a character which is a the end of a word, as defined by Pango.
double textLengthIncrement
This one is used by letterspacing strategy: to each glyph width, this is added.
Glib::ustring dumpAsText() const
debug and unit test method.
std::optional< Geom::Point > baselineAnchorPoint() const
For left aligned text, the leftmost end of the baseline For rightmost text, the rightmost....
void show(DrawingGroup *in_arena, StyleAttachments &style_attachments, Geom::OptRect const &paintbox) const
Adds all the output glyphs to in_arena using the given paintbox.
void _calculateBaselines()
static void _copyInputVector(std::vector< SVGLength > const &input_vector, unsigned input_offset, std::vector< SVGLength > *output_vector, size_t max_length)
The parameters to appendText() are allowed to be a little bit complex.
Glib::ustring getFontFamily(unsigned span_index) const
Returns the font family of the indexed span.
void fitToPathAlign(SVGLength const &startOffset, Path const &path)
Moves all the glyphs in the structure so that the baseline of all the characters sits neatly along th...
unsigned _sourceToCharacter(unsigned source_index) const
gunichar characterAt(iterator const &it) const
Returns character pointed to by it.
Geom::Point chunkAnchorPoint(iterator const &it) const
This is that value to apply to the x,y attributes of tspan role=line elements, and hence it takes ali...
std::vector< InputStreamItem * > const & input_stream() const
std::vector< Paragraph > _paragraphs
void _calculateCursorShapeForEmpty()
If the output is empty callers still want to be able to call queryCursorShape() and get a valid answe...
static bool _directions_are_orthogonal(Direction d1, Direction d2)
so that LEFT_TO_RIGHT == RIGHT_TO_LEFT but != TOP_TO_BOTTOM
int iteratorToCharIndex(iterator const &it) const
Returns the character index from the start of the flow represented by the given iterator.
bool isEndOfSentence(iterator const &it) const
Returns true if it points to a character which is a the end of a sentence, as defined by Pango.
iterator end() const
Returns an iterator pointing just past the end of the last glyph, which is also just past the end of ...
Geom::Rect characterBoundingBox(iterator const &it, double *rotation=nullptr) const
Returns the box extents (not ink extents) of the given character.
double textLengthMultiplier
By how much each character needs to be wider or narrower, using the specified lengthAdjust strategy,...
double getActualLength() const
Get actual length of layout, by summing span lengths.
void appendWrapShape(std::unique_ptr< Shape > shape, DisplayAlign display_align=DISPLAY_ALIGN_BEFORE)
Stores another shape inside which to flow the text.
void getSourceOfCharacter(iterator const &it, SPObject **source, Glib::ustring::iterator *text_iterator=nullptr) const
Discovers where the character pointed to by it came from, by retrieving the object that was passed to...
bool isStartOfSentence(iterator const &it) const
Returns true if it points to a character which is a the start of a sentence, as defined by Pango.
Alignment paragraphAlignment(iterator const &it) const
Returns the actual alignment used for the paragraph containing the character pointed to by it.
unsigned paragraphIndex(iterator const &it) const
Returns the zero-based number of the paragraph containing the character pointed to by it.
double getTextLengthIncrementDue() const
Get the actual spacing increment if it's due with the current values of above stuff,...
enum Inkscape::Text::Layout::WrapMode wrap_mode
bool outputExists() const
Returns true if there are some glyphs in this object, ie whether computeFlow() has been called on a n...
void appendText(Glib::ustring const &text, SPStyle *style, SPObject *source, OptionalTextTagAttrs const *optional_attributes, unsigned optional_attributes_offset, Glib::ustring::const_iterator text_begin, Glib::ustring::const_iterator text_end)
adds a new piece of text to the end of the current list of text to be processed.
bool isWhitespace(iterator const &it) const
Returns true if the character at it is a whitespace, as defined by Pango.
FontMetrics strut
The strut is the minimum value used in calculating line height.
SVGLength textLength
Gives the length target of this layout, as given by textLength attribute.
std::vector< InputStreamItem * > _input_stream
This is our internal storage for all the stuff passed to the appendText() and appendControlCode() fun...
void print(SPPrintContext *ctx, Geom::OptRect const &pbox, Geom::OptRect const &dbox, Geom::OptRect const &bbox, Geom::Affine const &ctm) const
Sends all the glyphs to the given print context.
unsigned _lineToCharacter(unsigned line_index) const
double _getChunkWidth(unsigned chunk_index) const
calculates the width of a chunk, which is the largest x coordinate (start or end) of the spans contai...
SPCurve convertToCurves() const
std::vector< Character > _characters
DisplayAlign
Display alignment for shapes.
std::vector< InputWrapShape > _input_wrap_shapes
void showGlyphs(CairoRenderContext *ctx) const
Renders all the glyphs to the given Cairo rendering context.
Geom::OptRect glyphBoundingBox(iterator const &it, double *rotation) const
Returns the bounding box of the given glyph, and its rotation.
bool calculateFlow()
Takes all the stuff you set with the members above here and creates a load of glyphs for use with the...
Direction
Used to specify any particular text direction required.
TextControlCode
Control codes which can be embedded in the text to be flowed.
@ ARBITRARY_GAP
forces the flow to ignore the remainder of the current shape (from #flow_inside_shapes) and continue ...
@ SHAPE_BREAK
forces the flow to move on to the next line
Orientation
Used to specify orientation of glyphs in vertical text.
Path const * _path_fitted
as passed to fitToPathAlign()
LengthAdjust
lengthAdjust values
@ LENGTHADJUST_SPACINGANDGLYPHS
static const gunichar UNICODE_SOFT_HYPHEN
iterator getNearestCursorPositionTo(double x, double y) const
Returns an iterator pointing to the cursor position for a mouse click at the given coordinates.
std::vector< Layout::Span > const & spans() const
bool isStartOfWord(iterator const &it) const
Returns true if it points to a character which is a the start of a word, as defined by Pango.
iterator begin() const
Returns an iterator pointing at the first glyph of the flowed output.
std::vector< Span > _spans
Path and its polyline approximation.
Wrapper around a Geom::PathVector object.
SPObject is an abstract base class of all of the document nodes at the SVG document level.
A class to store/manipulate directed graphs.
Lifts one dimensional objects into 2D.
Helper class to stream background task notifications as a series of messages.
Chunk const & chunk(Layout const *l) const
PangoLogAttr char_attributes
relative to the start of the span (so we can do block-progression)
Line const & line(Layout const *l) const
Paragraph const & paragraph(Layout const *l) const
Span const & span(Layout const *l) const
will be -1 if this character has no visual representation
std::vector< gunichar > const characters(Layout const *l) const
to implement lengthAdjust="spacingAndGlyphs" that must scale glyphs only horizontally; instead we cha...
float vertical_scale
for positioning next glyph
Line const & line(Layout const *l) const
float advance
Orientation of glyph in vertical text.
float y
relative to the start of the chunk
Span const & span(Layout const *l) const
Geom::Affine transform(Layout const &layout) const
Chunk const & chunk(Layout const *l) const
float rotation
relative to the current line's baseline
Orientation orientation
absolute, modulo any object transforms, which we don't know about
DisplayAlign display_align
as passed to Layout::appendWrapShape()
std::unique_ptr< Shape > shape
as passed to Layout::appendWrapShape()
The optional attributes which can be applied to a SVG text or related tag.
std::vector< SVGLength > y
std::vector< SVGLength > rotate
std::vector< SVGLength > x
std::vector< SVGLength > dy
std::vector< SVGLength > dx
LengthAdjust lengthAdjust
Alignment alignment
can be overridden by child Span objects
unsigned in_input_stream_item
See CSS3 section 3.2. The direction in which lines go.
Chunk const & chunk(Layout const *l) const
float y_offset
relative to the start of the chunk
float width() const
relative to line baseline (without baseline shift)
std::shared_ptr< FontInstance > font
Glib::ustring::const_iterator input_stream_first_character
Direction block_progression
See CSS3 section 3.2. Either rtl or ltr.
float x_end
relative to the start of the chunk
Paragraph const & paragraph(Layout const *l) const
Line const & line(Layout const *l) const
SPCSSTextOrientation text_orientation
relative to the line's baseline (CSS)
SPStyle enums: named public enums that correspond to SVG property values.
@ SP_CSS_TEXT_ORIENTATION_MIXED