2019-05-30 20:12:56 +00:00
|
|
|
// Copyright 2019 Google LLC.
|
|
|
|
#ifndef Paragraph_DEFINED
|
|
|
|
#define Paragraph_DEFINED
|
|
|
|
|
|
|
|
#include "modules/skparagraph/include/FontCollection.h"
|
2019-09-05 18:35:17 +00:00
|
|
|
#include "modules/skparagraph/include/Metrics.h"
|
2019-05-30 20:12:56 +00:00
|
|
|
#include "modules/skparagraph/include/ParagraphStyle.h"
|
|
|
|
#include "modules/skparagraph/include/TextStyle.h"
|
|
|
|
|
|
|
|
class SkCanvas;
|
|
|
|
|
|
|
|
namespace skia {
|
|
|
|
namespace textlayout {
|
|
|
|
|
|
|
|
class Paragraph {
|
|
|
|
|
|
|
|
public:
|
|
|
|
Paragraph(ParagraphStyle style, sk_sp<FontCollection> fonts)
|
|
|
|
: fFontCollection(std::move(fonts)), fParagraphStyle(std::move(style)) {}
|
|
|
|
|
|
|
|
virtual ~Paragraph() = default;
|
|
|
|
|
|
|
|
SkScalar getMaxWidth() { return fWidth; }
|
|
|
|
|
|
|
|
SkScalar getHeight() { return fHeight; }
|
|
|
|
|
|
|
|
SkScalar getMinIntrinsicWidth() { return fMinIntrinsicWidth; }
|
|
|
|
|
|
|
|
SkScalar getMaxIntrinsicWidth() { return fMaxIntrinsicWidth; }
|
|
|
|
|
|
|
|
SkScalar getAlphabeticBaseline() { return fAlphabeticBaseline; }
|
|
|
|
|
|
|
|
SkScalar getIdeographicBaseline() { return fIdeographicBaseline; }
|
|
|
|
|
2019-09-05 18:35:17 +00:00
|
|
|
SkScalar getLongestLine() { return fLongestLine; }
|
|
|
|
|
|
|
|
bool didExceedMaxLines() { return fExceededMaxLines; }
|
2019-05-30 20:12:56 +00:00
|
|
|
|
|
|
|
virtual void layout(SkScalar width) = 0;
|
|
|
|
|
|
|
|
virtual void paint(SkCanvas* canvas, SkScalar x, SkScalar y) = 0;
|
|
|
|
|
|
|
|
// Returns a vector of bounding boxes that enclose all text between
|
|
|
|
// start and end glyph indexes, including start and excluding end
|
|
|
|
virtual std::vector<TextBox> getRectsForRange(unsigned start,
|
|
|
|
unsigned end,
|
|
|
|
RectHeightStyle rectHeightStyle,
|
|
|
|
RectWidthStyle rectWidthStyle) = 0;
|
|
|
|
|
2019-09-05 18:35:17 +00:00
|
|
|
virtual std::vector<TextBox> getRectsForPlaceholders() = 0;
|
2019-08-08 20:51:27 +00:00
|
|
|
|
2019-05-30 20:12:56 +00:00
|
|
|
// Returns the index of the glyph that corresponds to the provided coordinate,
|
|
|
|
// with the top left corner as the origin, and +y direction as down
|
|
|
|
virtual PositionWithAffinity getGlyphPositionAtCoordinate(SkScalar dx, SkScalar dy) = 0;
|
|
|
|
|
|
|
|
// Finds the first and last glyphs that define a word containing
|
|
|
|
// the glyph at index offset
|
|
|
|
virtual SkRange<size_t> getWordBoundary(unsigned offset) = 0;
|
|
|
|
|
2019-09-05 18:35:17 +00:00
|
|
|
virtual void getLineMetrics(std::vector<LineMetrics>&) = 0;
|
|
|
|
|
2019-05-30 20:12:56 +00:00
|
|
|
virtual size_t lineNumber() = 0;
|
|
|
|
|
2019-06-19 17:32:01 +00:00
|
|
|
virtual void markDirty() = 0;
|
|
|
|
|
2019-12-02 16:32:25 +00:00
|
|
|
// This function will return the number of unresolved glyphs or
|
|
|
|
// -1 if not applicable (has not been shaped yet - valid case)
|
|
|
|
virtual int32_t unresolvedGlyphs() = 0;
|
|
|
|
|
2019-09-05 18:35:17 +00:00
|
|
|
// Experimental API that allows fast way to update "immutable" paragraph
|
|
|
|
virtual void updateTextAlign(TextAlign textAlign) = 0;
|
|
|
|
virtual void updateText(size_t from, SkString text) = 0;
|
|
|
|
virtual void updateFontSize(size_t from, size_t to, SkScalar fontSize) = 0;
|
|
|
|
virtual void updateForegroundPaint(size_t from, size_t to, SkPaint paint) = 0;
|
|
|
|
virtual void updateBackgroundPaint(size_t from, size_t to, SkPaint paint) = 0;
|
|
|
|
|
2019-05-30 20:12:56 +00:00
|
|
|
protected:
|
|
|
|
sk_sp<FontCollection> fFontCollection;
|
|
|
|
ParagraphStyle fParagraphStyle;
|
|
|
|
|
|
|
|
// Things for Flutter
|
|
|
|
SkScalar fAlphabeticBaseline;
|
|
|
|
SkScalar fIdeographicBaseline;
|
|
|
|
SkScalar fHeight;
|
|
|
|
SkScalar fWidth;
|
|
|
|
SkScalar fMaxIntrinsicWidth;
|
|
|
|
SkScalar fMinIntrinsicWidth;
|
2019-09-05 18:35:17 +00:00
|
|
|
SkScalar fLongestLine;
|
|
|
|
bool fExceededMaxLines;
|
2019-05-30 20:12:56 +00:00
|
|
|
};
|
|
|
|
} // namespace textlayout
|
|
|
|
} // namespace skia
|
|
|
|
|
|
|
|
#endif // Paragraph_DEFINED
|