skia2/modules/skparagraph/include/ParagraphBuilder.h
Julia Lavrova 5207f35f33 The current version...
Adding cache
Caching shaped results
Base+Index for referencing arrays
The very first and naive version of cache
Cache measurement, lines and picture
Added text blob cache for lines
Removed Run* from Cluster
Removed const char* from Cluster and Run
Few minor changes

Change-Id: I444a1defa950aed5999cfa1c3545fd83ccb54ce9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/227840
Commit-Queue: Julia Lavrova <jlavrova@google.com>
Reviewed-by: Julia Lavrova <jlavrova@google.com>
Reviewed-by: Mike Reed <reed@google.com>
2019-07-23 13:31:39 +00:00

61 lines
1.9 KiB
C++

// Copyright 2019 Google LLC.
#ifndef ParagraphBuilder_DEFINED
#define ParagraphBuilder_DEFINED
#include <memory>
#include <stack>
#include <string>
#include <tuple>
#include "modules/skparagraph/include/FontCollection.h"
#include "modules/skparagraph/include/Paragraph.h"
#include "modules/skparagraph/include/ParagraphStyle.h"
#include "modules/skparagraph/include/TextStyle.h"
namespace skia {
namespace textlayout {
class ParagraphBuilder {
public:
ParagraphBuilder(const ParagraphStyle& style, sk_sp<FontCollection> fontCollection) { }
virtual ~ParagraphBuilder() = default;
// Push a style to the stack. The corresponding text added with AddText will
// use the top-most style.
virtual void pushStyle(const TextStyle& style) = 0;
// Remove a style from the stack. Useful to apply different styles to chunks
// of text such as bolding.
// Example:
// builder.PushStyle(normal_style);
// builder.AddText("Hello this is normal. ");
//
// builder.PushStyle(bold_style);
// builder.AddText("And this is BOLD. ");
//
// builder.Pop();
// builder.AddText(" Back to normal again.");
virtual void pop() = 0;
virtual TextStyle peekStyle() = 0;
// Adds text to the builder. Forms the proper runs to use the upper-most style
// on the style_stack_;
virtual void addText(const std::u16string& text) = 0;
// Converts to u16string before adding.
virtual void addText(const char* text) = 0;
virtual void setParagraphStyle(const ParagraphStyle& style) = 0;
// Constructs a SkParagraph object that can be used to layout and paint the text to a SkCanvas.
virtual std::unique_ptr<Paragraph> Build() = 0;
static std::unique_ptr<ParagraphBuilder> make(const ParagraphStyle& style,
sk_sp<FontCollection> fontCollection);
};
} // namespace textlayout
} // namespace skia
#endif // ParagraphBuilder_DEFINED